mess.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. console.log(item);
  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 that = this;
  61. const { item } = e.currentTarget.dataset;
  62. wx.navigateTo({ url: `/pages/match/matchgroup?id=${item._id}` })
  63. },
  64. // 赛事状态
  65. toStatus: function (e) {
  66. const that = this;
  67. const { item } = e.currentTarget.dataset;
  68. that.setData({ form: item });
  69. that.setData({ dialog: { title: '赛事状态', show: true, type: '1' } });
  70. },
  71. // 选择状态
  72. statusChange: function (e) {
  73. const that = this;
  74. let data = that.data.statusList[e.detail.value];
  75. that.setData({ 'form.status': data.label })
  76. that.setData({ 'form.status_name': data.value })
  77. },
  78. // 提交
  79. onSubmit: async function (e) {
  80. const that = this;
  81. const arr = await app.$post(`/newCourt/api/match/${e.detail.value._id}`, e.detail.value)
  82. if (arr.errcode == '0') {
  83. wx.showToast({ title: `信息维护成功`, icon: 'success', duration: 2000 });
  84. that.watchLogin();
  85. that.toClose();
  86. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  87. },
  88. // 关闭弹框
  89. toClose: function () {
  90. const that = this;
  91. that.setData({ dialog: { title: '赛事状态', show: false, type: '1' } })
  92. },
  93. /**
  94. * 生命周期函数--监听页面加载
  95. */
  96. onLoad: function (options) {
  97. const that = this;
  98. // 监听用户是否登录
  99. that.watchLogin();
  100. },
  101. watchLogin: function () {
  102. const that = this;
  103. let searchInfo = that.data.searchInfo;
  104. wx.getStorage({
  105. key: 'user',
  106. success: async (res) => {
  107. let info = {};
  108. if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  109. const arr = await app.$get(`/newCourt/api/match`, { ...info });
  110. if (arr.errcode == '0') {
  111. that.setData({ list: arr.data })
  112. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  113. },
  114. fail: async (res) => {
  115. wx.redirectTo({ url: '/pages/index/index' });
  116. },
  117. });
  118. },
  119. /**
  120. * 生命周期函数--监听页面初次渲染完成
  121. */
  122. onReady: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面显示
  126. */
  127. onShow: function () {
  128. const that = this;
  129. // 监听用户是否登录
  130. that.watchLogin();
  131. },
  132. /**
  133. * 生命周期函数--监听页面隐藏
  134. */
  135. onHide: function () {
  136. },
  137. /**
  138. * 生命周期函数--监听页面卸载
  139. */
  140. onUnload: function () {
  141. },
  142. /**
  143. * 页面相关事件处理函数--监听用户下拉动作
  144. */
  145. onPullDownRefresh: function () {
  146. },
  147. /**
  148. * 页面上拉触底事件的处理函数
  149. */
  150. onReachBottom: function () {
  151. },
  152. /**
  153. * 用户点击右上角分享
  154. */
  155. onShareAppMessage: function () {
  156. }
  157. })