index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.search()
  111. wx.hideLoading()
  112. },
  113. async searchUser() {
  114. const that = this;
  115. wx.getStorage({
  116. key: 'user',
  117. async success(res) {
  118. that.setData({ user: res.data })
  119. },
  120. fail(err) {
  121. // console.log(err);
  122. }
  123. })
  124. },
  125. // 查询其他信息
  126. async searchOther() {
  127. const that = this;
  128. let res;
  129. res = await app.$api('dictData', 'GET', { type: 'match_status', is_use: '0' })
  130. if (res.errcode == '0') that.setData({ statusList: res.data })
  131. },
  132. // 查询通知
  133. async search() {
  134. const that = this;
  135. let status = ''
  136. if (that.data.active == 3) status = '-1'
  137. else status = that.data.active
  138. let info = { skip: that.data.skip, limit: that.data.limit, status: status };
  139. let res = await app.$api('match', 'GET', { ...info, ...that.data.searchInfo })
  140. if (res.errcode == '0') {
  141. let list = [...that.data.list, ...res.data]
  142. for (const val of list) {
  143. val.status_name = that.getDict(val.status, 'status')
  144. }
  145. that.setData({ list })
  146. that.setData({ total: res.total })
  147. }
  148. },
  149. /**
  150. * 生命周期函数--监听页面初次渲染完成
  151. */
  152. onReady() {
  153. },
  154. /**
  155. * 生命周期函数--监听页面隐藏
  156. */
  157. onHide() {
  158. },
  159. /**
  160. * 生命周期函数--监听页面卸载
  161. */
  162. onUnload() {
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh() {
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. onReachBottom() {
  173. },
  174. /**
  175. * 用户点击右上角分享
  176. */
  177. onShareAppMessage() {
  178. }
  179. })