index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.search()
  91. wx.hideLoading()
  92. },
  93. async searchUser() {
  94. const that = this;
  95. wx.getStorage({
  96. key: 'user',
  97. async success(res) {
  98. that.setData({ user: res.data })
  99. },
  100. fail(err) {
  101. // // console.log(err);
  102. }
  103. })
  104. },
  105. // 查询其他信息
  106. async searchOther() {
  107. const that = this;
  108. let res;
  109. res = await app.$api('dictData', 'GET', { type: 'match_status', is_use: '0' })
  110. if (res.errcode == '0') that.setData({ statusList: res.data })
  111. },
  112. // 查询通知
  113. async search() {
  114. const that = this;
  115. let info = { skip: that.data.skip, limit: that.data.limit, status: '2' };
  116. let res = await app.$api('match', 'GET', { ...info, ...that.data.searchInfo })
  117. if (res.errcode == '0') {
  118. let list = [...that.data.list, ...res.data]
  119. for (const val of list) {
  120. val.status_name = that.getDict(val.status, 'status')
  121. }
  122. that.setData({ list })
  123. that.setData({ total: res.total })
  124. }
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady() {
  130. },
  131. /**
  132. * 生命周期函数--监听页面隐藏
  133. */
  134. onHide() {
  135. },
  136. /**
  137. * 生命周期函数--监听页面卸载
  138. */
  139. onUnload() {
  140. },
  141. /**
  142. * 页面相关事件处理函数--监听用户下拉动作
  143. */
  144. onPullDownRefresh() {
  145. },
  146. /**
  147. * 页面上拉触底事件的处理函数
  148. */
  149. onReachBottom() {
  150. },
  151. /**
  152. * 用户点击右上角分享
  153. */
  154. onShareAppMessage() {
  155. }
  156. })