index.js 4.5 KB

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