index.js 6.3 KB

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