index.js 4.3 KB

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