index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 {
  48. wx.navigateTo({ url: '/pagesCommon/login/index' })
  49. }
  50. },
  51. // 查询
  52. async toSearch(e) {
  53. const that = this;
  54. if (e.detail.value) that.setData({ 'searchInfo.name': e.detail.value })
  55. else that.setData({ searchInfo: {} })
  56. that.clearPage();
  57. that.search()
  58. },
  59. // 分页-触底
  60. toLower() {
  61. const that = this;
  62. let list = that.data.list;
  63. let limit = that.data.limit;
  64. if (that.data.total > list.length) {
  65. wx.showLoading({ title: '加载中', mask: true })
  66. let page = that.data.page + 1;
  67. that.setData({ page })
  68. let skip = page * limit
  69. that.setData({ skip })
  70. that.search()
  71. wx.hideLoading()
  72. } else {
  73. wx.showToast({ title: `到底了没数据了`, icon: 'none' });
  74. }
  75. },
  76. // 分页-滚动
  77. toScroll() {
  78. // console.log('滚动');
  79. },
  80. // 字典
  81. getDict(value, model) {
  82. const that = this;
  83. if (model == 'status') {
  84. if (value) {
  85. let data = that.data.statusList.find(i => i.value == value)
  86. if (data) return data.label
  87. else return '暂无'
  88. }
  89. }
  90. },
  91. // 清空列表
  92. clearPage() {
  93. const that = this;
  94. that.setData({ list: [] })
  95. that.setData({ skip: 0 })
  96. that.setData({ limit: 5 })
  97. that.setData({ total: 0 })
  98. },
  99. /**
  100. * 生命周期函数--监听页面加载
  101. */
  102. async onLoad(options) {
  103. const that = this;
  104. wx.showLoading({ title: '加载中', mask: true })
  105. await that.searchUser()
  106. await that.searchOther()
  107. await that.search()
  108. wx.hideLoading()
  109. },
  110. async searchUser() {
  111. const that = this;
  112. wx.getStorage({
  113. key: 'token',
  114. async success(res) {
  115. that.setData({ user: res.data })
  116. },
  117. fail(err) {
  118. console.log(err);
  119. }
  120. })
  121. },
  122. // 查询其他信息
  123. async searchOther() {
  124. const that = this;
  125. let res;
  126. res = await app.$api('dictData', 'GET', { type: 'match_status', is_use: '0' })
  127. if (res.errcode == '0') that.setData({ statusList: res.data })
  128. },
  129. // 查询通知
  130. async search() {
  131. const that = this;
  132. let status = ''
  133. if (that.data.active == 3) status = '-1'
  134. else status = that.data.active
  135. let info = { skip: that.data.skip, limit: that.data.limit, status: status };
  136. let res = await app.$api('match', 'GET', { ...info, ...that.data.searchInfo })
  137. if (res.errcode == '0') {
  138. let list = [...that.data.list, ...res.data]
  139. for (const val of list) {
  140. val.status_name = that.getDict(val.status, 'status')
  141. }
  142. that.setData({ list })
  143. that.setData({ total: res.total })
  144. }
  145. },
  146. /**
  147. * 生命周期函数--监听页面初次渲染完成
  148. */
  149. onReady() {
  150. },
  151. /**
  152. * 生命周期函数--监听页面显示
  153. */
  154. onShow() {
  155. },
  156. /**
  157. * 生命周期函数--监听页面隐藏
  158. */
  159. onHide() {
  160. },
  161. /**
  162. * 生命周期函数--监听页面卸载
  163. */
  164. onUnload() {
  165. },
  166. /**
  167. * 页面相关事件处理函数--监听用户下拉动作
  168. */
  169. onPullDownRefresh() {
  170. },
  171. /**
  172. * 页面上拉触底事件的处理函数
  173. */
  174. onReachBottom() {
  175. },
  176. /**
  177. * 用户点击右上角分享
  178. */
  179. onShareAppMessage() {
  180. }
  181. })