index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '比赛管理', leftArrow: false, useBar: true },
  5. user: {},
  6. searchInfo: {},
  7. statusList: [],
  8. typeList: [],
  9. list: [],
  10. total: 0,
  11. page: 0,
  12. skip: 0,
  13. limit: 5,
  14. },
  15. // 跳转菜单
  16. tabPath(e) {
  17. let { route } = e.detail.detail;
  18. if (route) wx.redirectTo({ url: `/${route}` })
  19. },
  20. // 进入系统
  21. toJoin: function () {
  22. const that = this;
  23. wx.getStorage({
  24. key: 'user',
  25. success: async res => {
  26. if (res.data.type == '10') {
  27. wx.showModal({ title: '提示', content: '游客不能进入比赛系统,请注册成为正式用户' })
  28. } else {
  29. const arr = await app.$post(`/user/login`, { openid: res.data.openid }, 'race');
  30. if (arr.errcode == '0') {
  31. wx.setStorageSync('raceuser', arr.data);
  32. that.setData({ skip: 0, page: 0, list: [] })
  33. wx.navigateTo({ url: `/pagesMatch/system/index` })
  34. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
  35. }
  36. },
  37. fail: async res => {
  38. wx.redirectTo({ url: '/pages/index/index' })
  39. }
  40. })
  41. },
  42. // 详情
  43. toView: function (e) {
  44. const { item } = e.currentTarget.dataset;
  45. wx.navigateTo({ url: `/pagesMatch/match/info?id=${item._id}` })
  46. },
  47. // 选择类型
  48. typeChange: function (e) {
  49. const that = this;
  50. let data = that.data.typeList[e.detail.value];
  51. if (data) that.setData({ 'searchInfo.type': data.value, 'searchInfo.zhType': data.label })
  52. that.setData({ skip: 0, page: 0, list: [] })
  53. that.watchLogin();
  54. },
  55. // 状态选择
  56. statusChange: function (e) {
  57. const that = this;
  58. let data = that.data.statusList[e.detail.value];
  59. that.setData({ 'searchInfo.status': data.value, 'searchInfo.zhStatus': data.label });
  60. that.setData({ skip: 0, page: 0, list: [] })
  61. that.watchLogin();
  62. },
  63. // 分页
  64. toPage: function () {
  65. const that = this;
  66. let list = that.data.list;
  67. let limit = that.data.limit;
  68. if (that.data.total > list.length) {
  69. wx.showLoading({ title: '加载中', mask: true })
  70. let page = that.data.page + 1;
  71. that.setData({ page: page })
  72. let skip = page * limit;
  73. that.setData({ skip: skip })
  74. that.watchLogin();
  75. wx.hideLoading()
  76. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. onLoad: function (options) { },
  82. /**
  83. * 生命周期函数--监听页面初次渲染完成
  84. */
  85. onReady: function () { },
  86. /**
  87. * 生命周期函数--监听页面显示
  88. */
  89. onShow: async function () {
  90. const that = this;
  91. // 查询其他信息
  92. await that.searchOther();
  93. // 监听用户是否登录
  94. await that.watchLogin();
  95. },
  96. searchOther: async function () {
  97. const that = this;
  98. let arr;
  99. // 状态
  100. arr = await app.$get(`/dict`, { code: "match_status" });
  101. if (arr.errcode == '0' && arr.total > 0) {
  102. let list = arr.data[0].list;
  103. list.unshift({ label: '全部', value: '100' });
  104. that.setData({ statusList: list });
  105. }
  106. // 赛事类别
  107. arr = await app.$get(`/dict`, { code: "match_type" });
  108. if (arr.errcode == '0' && arr.total > 0) {
  109. let list = arr.data[0].list;
  110. list.unshift({ label: '全部', value: '100' });
  111. that.setData({ typeList: list });
  112. }
  113. },
  114. // 监听用户是否登录
  115. watchLogin: async function () {
  116. const that = this;
  117. const searchInfo = that.data.searchInfo;
  118. const statusList = that.data.statusList;
  119. const typeList = that.data.typeList;
  120. wx.getStorage({
  121. key: 'user',
  122. success: async res => {
  123. that.setData({ user: res.data })
  124. let info = { skip: that.data.skip, limit: that.data.limit };
  125. if (searchInfo.status && searchInfo.status != '100') info.status = searchInfo.status;
  126. if (searchInfo.type && searchInfo.type != '100') info.type = searchInfo.type;
  127. const arr = await app.$get(`/match`, { ...info }, 'race');
  128. if (arr.errcode == '0') {
  129. for (const val of arr.data) {
  130. let status = statusList.find(i => i.value == val.status)
  131. if (status) val.zhStatus = status.label;
  132. let type = typeList.find(i => i.value == val.type)
  133. if (type) val.zhType = type.label;
  134. }
  135. that.setData({ list: [...that.data.list, ...arr.data] });
  136. that.setData({ total: arr.total });
  137. }
  138. },
  139. fail: async res => {
  140. wx.redirectTo({ url: '/pages/index/index' })
  141. }
  142. })
  143. },
  144. /**
  145. * 页面上拉触底事件的处理函数
  146. */
  147. /**
  148. * 生命周期函数--监听页面隐藏
  149. */
  150. onHide: function () {
  151. const that = this;
  152. that.setData({ skip: 0, page: 0, list: [] })
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function () {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function () {
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage: function () {
  168. }
  169. })