index.js 4.4 KB

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