index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. list: [],
  10. dialog: { title: '赛程信息', show: false, type: '1' },
  11. form: {},
  12. // 赛事信息
  13. matchList: [],
  14. // 组别
  15. groupingList: [],
  16. //组内项目
  17. projectList: [],
  18. statusList: race_status,
  19. },
  20. // 跳转菜单
  21. back(e) {
  22. wx.navigateBack({ delta: 1 })
  23. },
  24. // 赛事管理
  25. toScore: async function (e) {
  26. const that = this;
  27. const { item } = e.currentTarget.dataset;
  28. const arr = await app.$get(`/newCourt/api/eliminateRace/${item._id}`);
  29. if (arr.errcode == '0') { that.setData({ form: arr.data }) }
  30. that.setData({ dialog: { title: '赛事管理', show: true, type: '2' } });
  31. },
  32. // 选择比赛状态
  33. statusChange: function (e) {
  34. const that = this;
  35. let data = that.data.statusList[e.detail.value];
  36. if (data) { that.setData({ 'form.status': data.value }) }
  37. },
  38. // 提交保存
  39. scoreSubmit: async function (e) {
  40. const that = this;
  41. const params = e.detail.value;
  42. const arr = await app.$post(`/newCourt/api/eliminateRace/${params._id}`, params);
  43. if (arr.errcode == '0') {
  44. wx.showToast({ title: `上分成功`, icon: 'error', duration: 2000 })
  45. that.toClose()
  46. } else {
  47. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  48. }
  49. },
  50. // 删除
  51. toDel: function (e) {
  52. const that = this;
  53. const { item } = e.currentTarget.dataset;
  54. wx.showModal({
  55. title: '提示',
  56. content: '是否确认删除该条数据?',
  57. async success(res) {
  58. if (res.confirm) {
  59. const arr = await app.$delete(`/newCourt/api/eliminateRace/${item._id}`);
  60. if (arr.errcode == '0') {
  61. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  62. that.watchLogin()
  63. } else {
  64. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  65. }
  66. }
  67. }
  68. })
  69. },
  70. // 添加
  71. toAdd: function () {
  72. const that = this;
  73. that.setData({ dialog: { title: '赛程信息', show: true, type: '1' } })
  74. },
  75. // 关闭弹框
  76. toClose: function () {
  77. const that = this;
  78. that.setData({ form: {} })
  79. that.setData({ dialog: { title: '赛程信息', show: false, type: '1' } })
  80. },
  81. // 选择赛事
  82. matchChange: function (e) {
  83. const that = this;
  84. let data = that.data.matchList[e.detail.value];
  85. if (data) {
  86. that.setData({ 'form.match_id': data._id });
  87. that.setData({ 'form.match_name': data.name });
  88. if (data.grouping && data.grouping.length > 0) {
  89. that.setData({ groupingList: data.grouping })
  90. }
  91. }
  92. },
  93. // 选择赛事组别
  94. grpupChange: async function (e) {
  95. const that = this;
  96. let data = that.data.groupingList[e.detail.value];
  97. if (data) {
  98. that.setData({ 'form.grouping_id': data._id });
  99. that.setData({ 'form.grouping_name': data.name });
  100. if (data.project && data.project.length > 0) {
  101. let projectList = [];
  102. for (const val of data.project) {
  103. const arr = await app.$get(`/newCourt/api/matchProject/${val}`)
  104. if (arr.errcode == '0') projectList.push(arr.data);
  105. that.setData({ projectList: projectList })
  106. }
  107. }
  108. }
  109. },
  110. // 选择组内项目
  111. projectChange: function (e) {
  112. const that = this;
  113. let data = that.data.projectList[e.detail.value];
  114. if (data) {
  115. that.setData({ 'form.project_id': data._id });
  116. that.setData({ 'form.project_name': data.name });
  117. }
  118. },
  119. // 赛程信息
  120. onSubmit: function (e) {
  121. const that = this;
  122. const params = e.detail.value;
  123. if (params.match_id && params.grouping_id && params.project_id) {
  124. wx.navigateTo({ url: `/pages/eliminate/add?match_id=${params.match_id}&grouping_id=${params.grouping_id}&project_id=${params.project_id}` })
  125. } else {
  126. wx.showToast({ title: `缺少必要信息`, icon: 'error', duration: 2000 })
  127. }
  128. },
  129. /**
  130. * 生命周期函数--监听页面加载
  131. */
  132. onLoad: function (options) { },
  133. /**
  134. * 生命周期函数--监听页面初次渲染完成
  135. */
  136. onReady: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面显示
  140. */
  141. onShow: function () {
  142. const that = this;
  143. that.watchLogin();
  144. },
  145. // 监听用户是否登录
  146. watchLogin: async function () {
  147. const that = this;
  148. wx.getStorage({
  149. key: 'user',
  150. success: async res => {
  151. let arr;
  152. // 比赛信息
  153. arr = await app.$get(`/newCourt/api/match`, { status: '0' });
  154. if (arr.errcode == '0') { that.setData({ matchList: arr.data }) };
  155. // 淘汰赛信息
  156. arr = await app.$get(`/newCourt/api/eliminateRace`);
  157. if (arr.errcode == '0') { that.setData({ list: arr.data }) };
  158. },
  159. fail: res => {
  160. wx.redirectTo({ url: '/pages/index/index', })
  161. }
  162. })
  163. },
  164. /**
  165. * 生命周期函数--监听页面隐藏
  166. */
  167. onHide: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面卸载
  171. */
  172. onUnload: function () {
  173. },
  174. /**
  175. * 页面相关事件处理函数--监听用户下拉动作
  176. */
  177. onPullDownRefresh: function () {
  178. },
  179. /**
  180. * 页面上拉触底事件的处理函数
  181. */
  182. onReachBottom: function () {
  183. },
  184. /**
  185. * 用户点击右上角分享
  186. */
  187. onShareAppMessage: function () {
  188. }
  189. })