eliminate.js 5.0 KB

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