index.js 4.1 KB

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