index.js 4.2 KB

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