mess.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import { match_status } from '../../utils/dict';
  2. const app = getApp()
  3. import QRCode from '../../utils/weapp-qrcode.js';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
  10. list: [],
  11. searchInfo: {},
  12. dialog: { title: '赛事状态', show: false, type: '1' },
  13. form: {},
  14. statusList: match_status,
  15. },
  16. // 跳转菜单
  17. back(e) {
  18. wx.navigateBack({ delta: 1 })
  19. },
  20. // 查询
  21. search: function (e) {
  22. const that = this;
  23. that.setData({ 'searchInfo.name': e.detail.value });
  24. that.watchLogin()
  25. },
  26. // 添加
  27. toAdd: function () {
  28. wx.navigateTo({ url: `/pages/match/matchadd` })
  29. },
  30. // 详情
  31. toView: function (e) {
  32. const { item } = e.currentTarget.dataset;
  33. wx.navigateTo({ url: `/pages/matchInfo/index?id=${item._id}` })
  34. },
  35. // 分享
  36. toShare: function (e) {
  37. const that = this;
  38. const { item } = e.currentTarget.dataset;
  39. that.setData({ form: item });
  40. // 生成二维码
  41. that.makeQRCode();
  42. that.setData({ dialog: { title: '赛事分享', show: true, type: '2' } });
  43. },
  44. makeQRCode(template = 0) {
  45. const that = this;
  46. const url = `${app.globalData.publicUrl}/courtapp?id=${that.data.form.id}`;
  47. var qrcode = new QRCode(`myQrcode`, {
  48. text: url,
  49. width: 110,
  50. height: 110,
  51. padding: 3,
  52. colorDark: "#000000",
  53. colorLight: "#ffffff",
  54. correctLevel: QRCode.CorrectLevel.L,
  55. });
  56. },
  57. // 修改
  58. toEdit: function (e) {
  59. const { item } = e.currentTarget.dataset;
  60. wx.navigateTo({ url: `/pages/match/matchadd?id=${item._id}` })
  61. },
  62. // 删除
  63. toDel: async function (e) {
  64. const { item } = e.currentTarget.dataset;
  65. wx.showModal({
  66. title: '提示',
  67. content: '您确定要删除该条数据吗?',
  68. async success(res) {
  69. if (res.confirm) {
  70. const arr = await app.$delete(`/newCourt/api/match/${item._id}`);
  71. if (arr.errcode == '0') {
  72. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 });
  73. that.watchLogin()
  74. } else {
  75. wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 });
  76. }
  77. }
  78. }
  79. })
  80. },
  81. // 赛事组别
  82. toGroup: function (e) {
  83. const { item } = e.currentTarget.dataset;
  84. wx.navigateTo({ url: `/pages/match/matchgroup?id=${item._id}` })
  85. },
  86. // 赛事状态
  87. toStatus: function (e) {
  88. const that = this;
  89. const { item } = e.currentTarget.dataset;
  90. that.setData({ form: item });
  91. that.setData({ dialog: { title: '赛事状态', show: true, type: '1' } });
  92. },
  93. // 选择状态
  94. statusChange: function (e) {
  95. const that = this;
  96. let data = that.data.statusList[e.detail.value];
  97. that.setData({ 'form.status': data.label })
  98. that.setData({ 'form.status_name': data.value })
  99. },
  100. // 提交
  101. onSubmit: async function (e) {
  102. const that = this;
  103. const arr = await app.$post(`/newCourt/api/match/${e.detail.value._id}`, e.detail.value)
  104. if (arr.errcode == '0') {
  105. wx.showToast({ title: `信息维护成功`, icon: 'success', duration: 2000 });
  106. that.watchLogin();
  107. that.toClose();
  108. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  109. },
  110. // 关闭弹框
  111. toClose: function () {
  112. const that = this;
  113. that.setData({ dialog: { title: '赛事状态', show: false, type: '1' } })
  114. },
  115. /**
  116. * 生命周期函数--监听页面加载
  117. */
  118. onLoad: function (options) {
  119. const that = this;
  120. // 监听用户是否登录
  121. that.watchLogin();
  122. },
  123. watchLogin: function () {
  124. const that = this;
  125. let searchInfo = that.data.searchInfo;
  126. wx.getStorage({
  127. key: 'user',
  128. success: async (res) => {
  129. let info = { skip: 0, limit: 1000 };
  130. if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  131. const arr = await app.$get(`/newCourt/api/match`, { ...info });
  132. if (arr.errcode == '0') {
  133. that.setData({ list: arr.data })
  134. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  135. },
  136. fail: async (res) => {
  137. wx.redirectTo({ url: '/pages/index/index' });
  138. },
  139. });
  140. },
  141. /**
  142. * 生命周期函数--监听页面初次渲染完成
  143. */
  144. onReady: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面显示
  148. */
  149. onShow: function () {
  150. const that = this;
  151. // 监听用户是否登录
  152. that.watchLogin();
  153. },
  154. /**
  155. * 生命周期函数--监听页面隐藏
  156. */
  157. onHide: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面卸载
  161. */
  162. onUnload: function () {
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh: function () {
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. onReachBottom: function () {
  173. },
  174. /**
  175. * 用户点击右上角分享
  176. */
  177. onShareAppMessage: function () {
  178. }
  179. })