group.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { race_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. searchInfo: {},
  10. list: [],
  11. dialog: { title: '详细信息', show: false, type: '1' },
  12. info: {},
  13. form: {},
  14. statusList: race_status
  15. },
  16. // 跳转菜单
  17. back(e) {
  18. wx.navigateBack({ delta: 1 })
  19. },
  20. // 查看
  21. toView: async function (e) {
  22. const that = this;
  23. const { item } = e.currentTarget.dataset;
  24. if (item.winner) {
  25. const arr = await app.$get(`/newCourt/api/user/${item.winner}`);
  26. if (arr.errcode == '0') {
  27. item.winner_name = arr.data.name
  28. }
  29. }
  30. that.setData({ info: item })
  31. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  32. },
  33. // 更换场地
  34. toChange: async function (e) {
  35. const that = this;
  36. const { item } = e.currentTarget.dataset;
  37. wx.showModal({
  38. title: '提示',
  39. content: '您是否确定要更换场地吗?',
  40. async success(res) {
  41. if (res.confirm) {
  42. const arr = await app.$post(`/newCourt/api/race/${item._id}`, { is_change: '1' });
  43. if (arr.errcode == '0') {
  44. wx.showToast({ title: `更换场地完成`, icon: 'error', duration: 2000 })
  45. that.watchLogin()
  46. } else {
  47. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  48. }
  49. }
  50. }
  51. })
  52. },
  53. // 赛事管理
  54. toScore: async function (e) {
  55. const that = this;
  56. const { item } = e.currentTarget.dataset;
  57. const arr = await app.$get(`/newCourt/api/race/${item._id}`);
  58. if (arr.errcode == '0') { that.setData({ form: arr.data }) }
  59. that.setData({ dialog: { title: '赛事管理', show: true, type: '2' } });
  60. },
  61. // 选择比赛状态
  62. statusChange: function (e) {
  63. const that = this;
  64. let data = that.data.statusList[e.detail.value];
  65. if (data) { that.setData({ 'form.status': data.value }) }
  66. },
  67. // 提交保存
  68. onSubmit: async function (e) {
  69. const that = this;
  70. const params = e.detail.value;
  71. const arr = await app.$post(`/newCourt/api/race/${params._id}`, params);
  72. if (arr.errcode == '0') {
  73. wx.showToast({ title: `上分成功`, icon: 'error', duration: 2000 })
  74. that.toClose()
  75. } else {
  76. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  77. }
  78. },
  79. // 关闭弹框
  80. toClose: function () {
  81. const that = this;
  82. that.setData({ info: {} })
  83. that.setData({ form: {} })
  84. that.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  85. that.watchLogin();
  86. },
  87. /**
  88. * 生命周期函数--监听页面加载
  89. */
  90. onLoad: function (options) {
  91. const that = this;
  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. let searchInfo = that.data.searchInfo;
  108. wx.getStorage({
  109. key: 'user',
  110. success: async (res) => {
  111. let info = { skip: 0, limit: 1000, referee_id: res.data.openid, status: '2' };
  112. // if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  113. const arr = await app.$get(`/newCourt/api/race`, { ...info });
  114. if (arr.errcode == '0') {
  115. that.setData({ list: 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. })