index.js 5.0 KB

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