group.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. that.setData({ info: item })
  25. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  26. },
  27. // 更换场地
  28. toChange: async function (e) {
  29. const that = this;
  30. const { item } = e.currentTarget.dataset;
  31. wx.showModal({
  32. title: '提示',
  33. content: '您是否确定要更换场地吗?',
  34. async success(res) {
  35. if (res.confirm) {
  36. const arr = await app.$post(`/newCourt/api/race/${item._id}`, { is_change: '1' });
  37. if (arr.errcode == '0') {
  38. wx.showToast({ title: `更换场地完成`, icon: 'error', duration: 2000 })
  39. that.watchLogin()
  40. } else {
  41. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  42. }
  43. }
  44. }
  45. })
  46. },
  47. // 赛事管理
  48. toScore: async function (e) {
  49. const that = this;
  50. const { item } = e.currentTarget.dataset;
  51. const arr = await app.$get(`/newCourt/api/race/${item._id}`);
  52. if (arr.errcode == '0') { that.setData({ form: arr.data }) }
  53. that.setData({ dialog: { title: '赛事管理', show: true, type: '2' } });
  54. },
  55. // 选择比赛状态
  56. statusChange: function (e) {
  57. const that = this;
  58. let data = that.data.statusList[e.detail.value];
  59. if (data) { that.setData({ 'form.status': data.value }) }
  60. },
  61. // 提交保存
  62. onSubmit: async function (e) {
  63. const that = this;
  64. const params = e.detail.value;
  65. const arr = await app.$post(`/newCourt/api/race/${params._id}`, params);
  66. if (arr.errcode == '0') {
  67. wx.showToast({ title: `上分成功`, icon: 'error', duration: 2000 })
  68. that.toClose()
  69. } else {
  70. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  71. }
  72. },
  73. // 关闭弹框
  74. toClose: function () {
  75. const that = this;
  76. that.setData({ info: {} })
  77. that.setData({ form: {} })
  78. that.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  79. that.watchLogin();
  80. },
  81. /**
  82. * 生命周期函数--监听页面加载
  83. */
  84. onLoad: function (options) {
  85. const that = this;
  86. },
  87. /**
  88. * 生命周期函数--监听页面初次渲染完成
  89. */
  90. onReady: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面显示
  94. */
  95. onShow: function () {
  96. const that = this;
  97. that.watchLogin()
  98. },
  99. watchLogin: function () {
  100. const that = this;
  101. let searchInfo = that.data.searchInfo;
  102. wx.getStorage({
  103. key: 'user',
  104. success: async (res) => {
  105. let info = { skip: 0, limit: 1000, referee_id: res.data.openid };
  106. // if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  107. const arr = await app.$get(`/newCourt/api/race`, { ...info });
  108. if (arr.errcode == '0') {
  109. that.setData({ list: arr.data })
  110. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  111. },
  112. fail: async (res) => {
  113. wx.redirectTo({ url: '/pages/index/index' });
  114. },
  115. });
  116. },
  117. /**
  118. * 生命周期函数--监听页面隐藏
  119. */
  120. onHide: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面卸载
  124. */
  125. onUnload: function () {
  126. },
  127. /**
  128. * 页面相关事件处理函数--监听用户下拉动作
  129. */
  130. onPullDownRefresh: function () {
  131. },
  132. /**
  133. * 页面上拉触底事件的处理函数
  134. */
  135. onReachBottom: function () {
  136. },
  137. /**
  138. * 用户点击右上角分享
  139. */
  140. onShareAppMessage: function () {
  141. }
  142. })