index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import { match_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. fileUrl: app.globalData.fileUrl,
  10. user: {},
  11. id: '',
  12. info: {},
  13. // 选项卡
  14. tabs: {
  15. active: 'a',
  16. list: [
  17. { title: '规程', name: 'a' },
  18. { title: '选手', name: 'b' },
  19. { title: '秩序册', name: 'c' },
  20. { title: '赛况', name: 'd' },
  21. { title: '成绩册', name: 'e' },
  22. ],
  23. },
  24. // 选手
  25. bActive: '0',
  26. groupList: [],
  27. // 秩序册
  28. cType: '0',
  29. cList: [],
  30. raceList: [],
  31. raceteamList: [],
  32. // 赛况
  33. dtabs: { active: 0, list: [] }
  34. },
  35. // 跳转菜单
  36. back(e) {
  37. wx.navigateBack({ delta: 1 })
  38. },
  39. // 选项卡
  40. tabsChange: function (e) {
  41. const that = this;
  42. const { name } = e.detail;
  43. that.setData({ 'tabs.active': e.detail.name });
  44. },
  45. // 更多
  46. toCommon: function (e) {
  47. const { route } = e.currentTarget.dataset;
  48. wx.redirectTo({ url: `/pages/${route}/index` })
  49. },
  50. // 报名
  51. toSign: function (e) {
  52. const { item } = e.currentTarget.dataset;
  53. wx.navigateTo({ url: `/pages/matchInfo/sign?id=${item._id}` })
  54. },
  55. // 选择手风琴
  56. bChange: function (e) {
  57. const that = this;
  58. that.setData({ bActive: e.detail })
  59. },
  60. // 秩序册
  61. orderChange: function (e) {
  62. const that = this;
  63. const { ctype } = e.currentTarget.dataset;
  64. that.setData({ cType: ctype == '0' ? '1' : '0' })
  65. that.setData({ cList: that.data.cType == '0' ? that.data.raceList : that.data.raceteamList })
  66. },
  67. // 赛况
  68. dtabsChange: async function (e) {
  69. const that = this;
  70. let info = that.data.info;
  71. const { name } = e.detail;
  72. that.setData({ 'dtabs.active': name });
  73. let data = that.data.dtabs.list[name];
  74. let searchInfo = { match_id: info._id, limit: 1000 };
  75. if (data._id) { searchInfo.ground_id = data._id }
  76. const arr = await app.$get(`/newCourt/api/race`, { ...searchInfo });
  77. if (arr.errcode == '0') { that.setData({ raceList: arr.data }) }
  78. },
  79. // 赛况
  80. toAchieve: function (e) {
  81. const that = this;
  82. let type = that.data.cType;
  83. const { item } = e.currentTarget.dataset;
  84. if (type == '1') {
  85. wx.navigateTo({ url: `/pages/matchInfo/achieve?match_id=${item.match_id}&grouping_id=${item.grouping_id}&project_id=${item.project_id}` })
  86. }
  87. },
  88. /**
  89. * 生命周期函数--监听页面加载
  90. */
  91. onLoad: function (options) {
  92. const that = this;
  93. that.setData({ id: options.id || '62e388d4fd61d871861b80af' });
  94. // 监听用户是否登录
  95. that.watchLogin();
  96. },
  97. watchLogin: function () {
  98. const that = this;
  99. wx.getStorage({
  100. key: 'user',
  101. success: async (res) => {
  102. that.setData({ user: res.data })
  103. if (that.data.id) {
  104. let arr;
  105. // 比赛信息
  106. arr = await app.$get(`/newCourt/api/match/${that.data.id}`);
  107. if (arr.errcode == '0') {
  108. arr.data.statusZh = that.getStatusZh(arr.data.status);
  109. that.setData({ info: arr.data })
  110. } else { wx.showToast({ title: `${res.errmsg}`, icon: 'fail', duration: 2000 }); }
  111. // 选手信息
  112. arr = await app.$get(`/newCourt/api/view/groupProjectUser?match_id=${that.data.id}`);
  113. if (arr.errcode == '0') { that.setData({ groupList: arr.data }) };
  114. // 查询场地信息
  115. arr = await app.$get(`/newCourt/api/ground`, { is_use: '0' });
  116. let ground = [{ title: '全部场地', name: 0 }]
  117. if (arr.errcode == '0') {
  118. for (const [index, val] of arr.data.entries()) {
  119. ground.push({ title: val.name, name: index + 1, _id: val._id })
  120. }
  121. }
  122. that.setData({ 'dtabs.list': ground })
  123. // 赛程信息
  124. that.searchOrder();
  125. }
  126. },
  127. fail: async (res) => {
  128. wx.redirectTo({ url: '/pages/index/index' });
  129. },
  130. });
  131. },
  132. // 查询赛程信息
  133. searchOrder: async function () {
  134. wx.showLoading({ title: '加载中', mask: true })
  135. const that = this;
  136. let type = that.data.cType;
  137. let info = that.data.info;
  138. let arr;
  139. // 赛程信息
  140. arr = await app.$get(`/newCourt/api/race`, { match_id: info._id, limit: 1000 });
  141. if (arr.errcode == '0') { that.setData({ raceList: arr.data }); }
  142. else wx.showToast({ title: `${arr.errmsg}`, icon: 'fail', duration: 2000 });
  143. // 组信息
  144. arr = await app.$get(`/newCourt/api/raceTeam`, { match: info._id });
  145. if (arr.errcode == '0') { that.setData({ raceteamList: arr.data }); }
  146. else wx.showToast({ title: `${arr.errmsg}`, icon: 'fail', duration: 2000 });
  147. // 合并信息
  148. that.setData({ cList: type == '0' ? that.data.raceList : that.data.raceteamList })
  149. wx.hideLoading();
  150. },
  151. getStatusZh(status) {
  152. let word = "未知"
  153. let data = match_status.find((i) => i.label == status);
  154. if (data) word = data.value;
  155. return word;
  156. },
  157. /**
  158. * 生命周期函数--监听页面初次渲染完成
  159. */
  160. onReady: function () {
  161. },
  162. /**
  163. * 生命周期函数--监听页面显示
  164. */
  165. onShow: function () {
  166. },
  167. /**
  168. * 生命周期函数--监听页面隐藏
  169. */
  170. onHide: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面卸载
  174. */
  175. onUnload: function () {
  176. },
  177. /**
  178. * 页面相关事件处理函数--监听用户下拉动作
  179. */
  180. onPullDownRefresh: function () {
  181. },
  182. /**
  183. * 页面上拉触底事件的处理函数
  184. */
  185. onReachBottom: function () {
  186. },
  187. /**
  188. * 用户点击右上角分享
  189. */
  190. onShareAppMessage: function () {
  191. }
  192. })