index.js 4.3 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. that.setData({ 'searchInfo.name': e.detail.value })
  25. that.clearPage();
  26. that.search()
  27. },
  28. // 查看详情
  29. toView(e) {
  30. const that = this;
  31. if (that.data.user._id) {
  32. const item = e.currentTarget.dataset.item
  33. wx.navigateTo({ url: '/pagesTeam/apply/index?id=' + item._id })
  34. } else {
  35. wx.navigateTo({ url: '/pagesCommon/login/index' })
  36. }
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. async onLoad(options) {
  42. const that = this;
  43. wx.showLoading({ title: '加载中', mask: true })
  44. await that.searchConfig()
  45. await that.searchOther()
  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. that.setData({ list })
  83. that.setData({ total: res.total })
  84. }
  85. },
  86. // 分页-触底
  87. toLower() {
  88. const that = this;
  89. let list = that.data.list;
  90. let limit = that.data.limit;
  91. if (that.data.total > list.length) {
  92. wx.showLoading({ title: '加载中', mask: true })
  93. let page = that.data.page + 1;
  94. that.setData({ page })
  95. let skip = page * limit
  96. that.setData({ skip })
  97. that.search()
  98. wx.hideLoading()
  99. } else {
  100. wx.showToast({ title: `到底了没数据了`, icon: 'none' });
  101. }
  102. },
  103. // 分页-滚动
  104. toScroll() {
  105. // console.log('滚动');
  106. },
  107. // 字典
  108. getDict(value, model) {
  109. const that = this;
  110. if (model == 'status') {
  111. if (value) {
  112. let data = that.data.statusList.find(i => i.value == value)
  113. if (data) return data.label
  114. else return '暂无'
  115. }
  116. }
  117. },
  118. // 查询其他信息
  119. async searchOther() {
  120. const that = this;
  121. },
  122. // 清空列表
  123. clearPage() {
  124. const that = this;
  125. that.setData({ list: [] })
  126. that.setData({ skip: 0 })
  127. that.setData({ limit: 5 })
  128. that.setData({ total: 0 })
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady() {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow() {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide() {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload() {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh() {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom() {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage() {
  164. }
  165. })