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