index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. if (e.detail.value) that.setData({ 'searchInfo.name': e.detail.value })
  58. else that.setData({ searchInfo: {} })
  59. that.clearPage();
  60. that.search()
  61. },
  62. // 分页-触底
  63. toLower() {
  64. const that = this;
  65. let list = that.data.list;
  66. let limit = that.data.limit;
  67. if (that.data.total > list.length) {
  68. wx.showLoading({ title: '加载中', mask: true })
  69. let page = that.data.page + 1;
  70. that.setData({ page })
  71. let skip = page * limit
  72. that.setData({ skip })
  73. that.search()
  74. wx.hideLoading()
  75. } else {
  76. wx.showToast({ title: `到底了没数据了`, icon: 'none' });
  77. }
  78. },
  79. // 分页-滚动
  80. toScroll() {
  81. // console.log('滚动');
  82. },
  83. // 字典
  84. getDict(value, model) {
  85. const that = this;
  86. if (model == 'status') {
  87. if (value) {
  88. let data = that.data.statusList.find(i => i.value == value)
  89. if (data) return data.label
  90. else return '暂无'
  91. }
  92. }
  93. },
  94. // 清空列表
  95. clearPage() {
  96. const that = this;
  97. that.setData({ list: [] })
  98. that.setData({ skip: 0 })
  99. that.setData({ limit: 5 })
  100. that.setData({ total: 0 })
  101. },
  102. /**
  103. * 生命周期函数--监听页面加载
  104. */
  105. async onLoad(options) {
  106. const that = this;
  107. that.setData({ team_id: options.id });
  108. wx.showLoading({ title: '加载中', mask: true })
  109. await that.searchConfig()
  110. await that.searchOther()
  111. await that.search()
  112. wx.hideLoading()
  113. },
  114. async searchConfig() {
  115. const that = this;
  116. wx.getStorage({
  117. key: 'config',
  118. async success(res) {
  119. // logo
  120. if (res.data && res.data.logo_url && res.data.logo_url.length > 0) {
  121. let logo = res.data.logo_url[0].url
  122. that.setData({ logo })
  123. }
  124. },
  125. fail(err) {
  126. // console.log(err);
  127. }
  128. })
  129. },
  130. // 查询其他信息
  131. async searchOther() {
  132. const that = this;
  133. let res;
  134. res = await app.$api('dictData', 'GET', { type: 'status', is_use: '0' })
  135. if (res.errcode == '0') that.setData({ statusList: res.data })
  136. res = await app.$api('dictData', 'GET', { type: 'gender', is_use: '0' })
  137. if (res.errcode == '0') that.setData({ genderList: res.data })
  138. },
  139. // 查询通知
  140. async search() {
  141. const that = this;
  142. let info = { skip: that.data.skip, limit: that.data.limit, team_id: that.data.team_id };
  143. let res = await app.$api('teamApply', 'GET', { ...info, ...that.data.searchInfo })
  144. if (res.errcode == '0') {
  145. let list = [...that.data.list, ...res.data]
  146. for (const val of list) {
  147. let arr = await app.$api(`user/${val.apply_id}`, 'GET', {})
  148. if (arr.errcode == '0') {
  149. let data = that.data.genderList.find(i => i.value == arr.data.gender)
  150. if (data) arr.data.gender_name = data.label
  151. val.userInfo = arr.data
  152. }
  153. val.status_name = that.getDict(val.status, 'status')
  154. }
  155. that.setData({ list })
  156. that.setData({ total: res.total })
  157. }
  158. },
  159. /**
  160. * 生命周期函数--监听页面初次渲染完成
  161. */
  162. onReady() {
  163. },
  164. /**
  165. * 生命周期函数--监听页面显示
  166. */
  167. onShow() {
  168. },
  169. /**
  170. * 生命周期函数--监听页面隐藏
  171. */
  172. onHide() {
  173. },
  174. /**
  175. * 生命周期函数--监听页面卸载
  176. */
  177. onUnload() {
  178. },
  179. /**
  180. * 页面相关事件处理函数--监听用户下拉动作
  181. */
  182. onPullDownRefresh() {
  183. },
  184. /**
  185. * 页面上拉触底事件的处理函数
  186. */
  187. onReachBottom() {
  188. },
  189. /**
  190. * 用户点击右上角分享
  191. */
  192. onShareAppMessage() {
  193. }
  194. })