index.js 4.5 KB

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