eliminate.js 4.7 KB

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