index.js 6.2 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. that.watchLogin()
  81. },
  82. // 选择赛事
  83. matchChange: function (e) {
  84. const that = this;
  85. let data = that.data.matchList[e.detail.value];
  86. if (data) {
  87. that.setData({ 'form.match_id': data._id });
  88. that.setData({ 'form.match_name': data.name });
  89. if (data.grouping && data.grouping.length > 0) {
  90. that.setData({ groupingList: data.grouping })
  91. }
  92. }
  93. },
  94. // 选择赛事组别
  95. grpupChange: async function (e) {
  96. const that = this;
  97. let data = that.data.groupingList[e.detail.value];
  98. if (data) {
  99. that.setData({ 'form.grouping_id': data._id });
  100. that.setData({ 'form.grouping_name': data.name });
  101. if (data.project && data.project.length > 0) {
  102. let projectList = [];
  103. for (const val of data.project) {
  104. const arr = await app.$get(`/newCourt/api/matchProject/${val}`)
  105. if (arr.errcode == '0') projectList.push(arr.data);
  106. that.setData({ projectList: projectList })
  107. }
  108. }
  109. }
  110. },
  111. // 选择组内项目
  112. projectChange: function (e) {
  113. const that = this;
  114. let data = that.data.projectList[e.detail.value];
  115. if (data) {
  116. that.setData({ 'form.project_id': data._id });
  117. that.setData({ 'form.project_name': data.name });
  118. }
  119. },
  120. // 赛程信息
  121. onSubmit: function (e) {
  122. const that = this;
  123. const params = e.detail.value;
  124. if (params.match_id && params.grouping_id && params.project_id) {
  125. wx.navigateTo({ url: `/pages/eliminate/add?match_id=${params.match_id}&grouping_id=${params.grouping_id}&project_id=${params.project_id}` })
  126. } else {
  127. wx.showToast({ title: `缺少必要信息`, icon: 'error', duration: 2000 })
  128. }
  129. },
  130. /**
  131. * 生命周期函数--监听页面加载
  132. */
  133. onLoad: function (options) { },
  134. /**
  135. * 生命周期函数--监听页面初次渲染完成
  136. */
  137. onReady: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function () {
  143. const that = this;
  144. that.watchLogin();
  145. },
  146. // 监听用户是否登录
  147. watchLogin: async function () {
  148. const that = this;
  149. wx.getStorage({
  150. key: 'user',
  151. success: async res => {
  152. let arr;
  153. // 比赛信息
  154. arr = await app.$get(`/newCourt/api/match`, { status: '0' });
  155. if (arr.errcode == '0') { that.setData({ matchList: arr.data }) };
  156. // 淘汰赛信息
  157. arr = await app.$get(`/newCourt/api/eliminateRace`);
  158. if (arr.errcode == '0') { that.setData({ list: arr.data }) };
  159. },
  160. fail: res => {
  161. wx.redirectTo({ url: '/pages/index/index', })
  162. }
  163. })
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function () {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh: function () {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function () {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function () {
  189. }
  190. })