index.js 4.4 KB

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