index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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: 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. * 生命周期函数--监听页面加载
  81. */
  82. onLoad: function (options) {
  83. const that = this;
  84. that.setData({ id: options.id || '62e388d4fd61d871861b80af' });
  85. // 监听用户是否登录
  86. that.watchLogin();
  87. },
  88. watchLogin: function () {
  89. const that = this;
  90. wx.getStorage({
  91. key: 'user',
  92. success: async (res) => {
  93. that.setData({ user: res.data })
  94. if (that.data.id) {
  95. let arr;
  96. // 比赛信息
  97. arr = await app.$get(`/newCourt/api/match/${that.data.id}`);
  98. if (arr.errcode == '0') {
  99. arr.data.statusZh = that.getStatusZh(arr.data.status);
  100. that.setData({ info: arr.data })
  101. } else { wx.showToast({ title: `${res.errmsg}`, icon: 'fail', duration: 2000 }); }
  102. // 选手信息
  103. arr = await app.$get(`/newCourt/api/view/groupProjectUser?match_id=${that.data.id}`);
  104. if (arr.errcode == '0') { that.setData({ groupList: arr.data }) };
  105. // 查询场地信息
  106. arr = await app.$get(`/newCourt/api/ground`, { is_use: '0' });
  107. let ground = [{ title: '全部场地', name: 0 }]
  108. if (arr.errcode == '0') {
  109. for (const [index, val] of arr.data.entries()) {
  110. ground.push({ title: val.name, name: index + 1, _id: val._id })
  111. }
  112. }
  113. that.setData({ 'dtabs.list': ground })
  114. // 赛程信息
  115. that.searchOrder();
  116. }
  117. },
  118. fail: async (res) => {
  119. wx.redirectTo({ url: '/pages/index/index' });
  120. },
  121. });
  122. },
  123. // 查询赛程信息
  124. searchOrder: async function () {
  125. wx.showLoading({ title: '加载中' })
  126. const that = this;
  127. let type = that.data.cType;
  128. let info = that.data.info;
  129. let arr;
  130. // 赛程信息
  131. arr = await app.$get(`/newCourt/api/race`, { match_id: info._id, limit: 1000 });
  132. if (arr.errcode == '0') { that.setData({ raceList: arr.data }); }
  133. else wx.showToast({ title: `${arr.errmsg}`, icon: 'fail', duration: 2000 });
  134. // 组信息
  135. arr = await app.$get(`/newCourt/api/raceTeam`, { match: info._id });
  136. if (arr.errcode == '0') { that.setData({ raceteamList: arr.data }); }
  137. else wx.showToast({ title: `${arr.errmsg}`, icon: 'fail', duration: 2000 });
  138. // 合并信息
  139. that.setData({ cList: type == '0' ? that.data.raceList : that.data.raceteamList })
  140. wx.hideLoading();
  141. },
  142. getStatusZh(status) {
  143. let word = "未知"
  144. let data = match_status.find((i) => i.label == status);
  145. if (data) word = data.value;
  146. return word;
  147. },
  148. /**
  149. * 生命周期函数--监听页面初次渲染完成
  150. */
  151. onReady: function () {
  152. },
  153. /**
  154. * 生命周期函数--监听页面显示
  155. */
  156. onShow: function () {
  157. },
  158. /**
  159. * 生命周期函数--监听页面隐藏
  160. */
  161. onHide: function () {
  162. },
  163. /**
  164. * 生命周期函数--监听页面卸载
  165. */
  166. onUnload: function () {
  167. },
  168. /**
  169. * 页面相关事件处理函数--监听用户下拉动作
  170. */
  171. onPullDownRefresh: function () {
  172. },
  173. /**
  174. * 页面上拉触底事件的处理函数
  175. */
  176. onReachBottom: function () {
  177. },
  178. /**
  179. * 用户点击右上角分享
  180. */
  181. onShareAppMessage: function () {
  182. }
  183. })