index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. that.setData({ 'searchInfo.name': e.detail.value })
  35. that.clearPage();
  36. that.search()
  37. },
  38. // 分页-触底
  39. toLower() {
  40. const that = this;
  41. let list = that.data.list;
  42. let limit = that.data.limit;
  43. if (that.data.total > list.length) {
  44. wx.showLoading({ title: '加载中', mask: true })
  45. let page = that.data.page + 1;
  46. that.setData({ page })
  47. let skip = page * limit
  48. that.setData({ skip })
  49. that.search()
  50. wx.hideLoading()
  51. } else {
  52. wx.showToast({ title: `到底了没数据了`, icon: 'none' });
  53. }
  54. },
  55. // 分页-滚动
  56. toScroll() {
  57. // console.log('滚动');
  58. },
  59. // 字典
  60. getDict(value, model) {
  61. const that = this;
  62. if (model == 'status') {
  63. if (value) {
  64. let data = that.data.statusList.find(i => i.value == value)
  65. if (data) return data.label
  66. else return '暂无'
  67. }
  68. }
  69. },
  70. // 清空列表
  71. clearPage() {
  72. const that = this;
  73. that.setData({ list: [] })
  74. that.setData({ skip: 0 })
  75. that.setData({ limit: 5 })
  76. that.setData({ total: 0 })
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. async onLoad(options) {
  82. const that = this;
  83. wx.showLoading({ title: '加载中', mask: true })
  84. await that.searchUser()
  85. await that.searchOther()
  86. await that.search()
  87. wx.hideLoading()
  88. },
  89. async searchUser() {
  90. const that = this;
  91. wx.getStorage({
  92. key: 'token',
  93. async success(res) {
  94. that.setData({ user: res.data })
  95. },
  96. fail(err) {
  97. console.log(err);
  98. }
  99. })
  100. },
  101. // 查询其他信息
  102. async searchOther() {
  103. const that = this;
  104. let res;
  105. res = await app.$api('dictData', 'GET', { type: 'match_status', is_use: '0' })
  106. if (res.errcode == '0') that.setData({ statusList: res.data })
  107. },
  108. // 查询通知
  109. async search() {
  110. const that = this;
  111. let info = { skip: that.data.skip, limit: that.data.limit, status: '2' };
  112. let res = await app.$api('match', 'GET', { ...info, ...that.data.searchInfo })
  113. if (res.errcode == '0') {
  114. let list = [...that.data.list, ...res.data]
  115. for (const val of list) {
  116. val.status_name = that.getDict(val.status, 'status')
  117. }
  118. that.setData({ list })
  119. that.setData({ total: res.total })
  120. }
  121. },
  122. /**
  123. * 生命周期函数--监听页面初次渲染完成
  124. */
  125. onReady() {
  126. },
  127. /**
  128. * 生命周期函数--监听页面显示
  129. */
  130. onShow() {
  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. })