index.js 5.8 KB

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