mess.js 4.8 KB

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