index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. const app = getApp()
  2. Page({
  3. data: {
  4. // 用户信息
  5. user: {},
  6. searchInfo: {},
  7. list: [],
  8. total: 0,
  9. page: 0,
  10. skip: 0,
  11. limit: 5,
  12. statusList: []
  13. },
  14. // 查询
  15. async toSearch(e) {
  16. const that = this;
  17. if (e.detail.value) that.setData({ 'searchInfo.name': e.detail.value })
  18. else that.setData({ searchInfo: {} })
  19. that.clearPage();
  20. that.search()
  21. },
  22. // 查看
  23. toView(e) {
  24. let item = e.currentTarget.dataset.item
  25. wx.navigateTo({ url: '/pagesTeam/apply/index?id=' + item._id })
  26. },
  27. // 赛程信息
  28. toCourse(e) {
  29. let item = e.currentTarget.dataset.item
  30. wx.navigateTo({ url: '/pagesMy/course/index?id=' + item.match_id + '&team_id=' + item.team_id })
  31. },
  32. // 排名
  33. toRank(e) {
  34. let item = e.currentTarget.dataset.item
  35. wx.navigateTo({ url: '/pagesMy/ranking/index?id=' + item.match_id })
  36. },
  37. // 修改
  38. toEdit(e) {
  39. let item = e.currentTarget.dataset.item
  40. wx.navigateTo({ url: '/pagesMatch/enroll/index?id=' + item._id })
  41. },
  42. // 分页-触底
  43. toLower() {
  44. const that = this;
  45. let list = that.data.list;
  46. let limit = that.data.limit;
  47. if (that.data.total > list.length) {
  48. wx.showLoading({ title: '加载中', mask: true })
  49. let page = that.data.page + 1;
  50. that.setData({ page })
  51. let skip = page * limit
  52. that.setData({ skip })
  53. that.search()
  54. wx.hideLoading()
  55. } else {
  56. wx.showToast({ title: `到底了没数据了`, icon: 'none' });
  57. }
  58. },
  59. // 分页-滚动
  60. toScroll() {
  61. // console.log('滚动');
  62. },
  63. // 字典
  64. getDict(value, model) {
  65. const that = this;
  66. if (model == 'status') {
  67. if (value) {
  68. let data = that.data.statusList.find(i => i.value == value)
  69. if (data) return data.label
  70. else return '暂无'
  71. }
  72. }
  73. },
  74. // 清空列表
  75. clearPage() {
  76. const that = this;
  77. that.setData({ list: [] })
  78. that.setData({ skip: 0 })
  79. that.setData({ limit: 5 })
  80. that.setData({ total: 0 })
  81. },
  82. /**
  83. * 生命周期函数--监听页面加载
  84. */
  85. async onLoad(options) {
  86. },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. async onShow() {
  91. const that = this;
  92. wx.showLoading({ title: '加载中', mask: true })
  93. await that.searchUser()
  94. await that.searchOther()
  95. await that.clearPage()
  96. await that.search()
  97. wx.hideLoading()
  98. },
  99. async searchUser() {
  100. const that = this;
  101. wx.getStorage({
  102. key: 'user',
  103. async success(res) {
  104. that.setData({ user: res.data })
  105. },
  106. fail(err) {
  107. // console.log(err);
  108. }
  109. })
  110. },
  111. // 查询其他信息
  112. async searchOther() {
  113. const that = this;
  114. let res;
  115. res = await app.$api('dictData', 'GET', { type: 'status', is_use: '0' })
  116. if (res.errcode == '0') that.setData({ statusList: res.data })
  117. },
  118. // 查询通知
  119. async search() {
  120. const that = this;
  121. let info = { skip: that.data.skip, limit: that.data.limit };
  122. info.user = that.data.user._id
  123. let res = await app.$api('application', 'GET', { ...info, ...that.data.searchInfo })
  124. if (res.errcode == '0') {
  125. let list = [...that.data.list, ...res.data]
  126. for (const val of list) {
  127. const match = await app.$api(`match/${val.match_id}`, 'GET', {})
  128. if (match.errcode == '0') val.match_status = match.data.status
  129. val.status_name = that.getDict(val.status, 'status')
  130. }
  131. that.setData({ list })
  132. that.setData({ total: res.total })
  133. }
  134. },
  135. /**
  136. * 生命周期函数--监听页面初次渲染完成
  137. */
  138. onReady() {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide() {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload() {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh() {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom() {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage() {
  164. }
  165. })