index.js 4.2 KB

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