index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '审核队员', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. list: [],
  13. // 团队信息
  14. teamInfo: {},
  15. // 弹框
  16. dialog: { title: '详细信息', show: false, type: '1' },
  17. form: {},
  18. statusList: [{ label: '待审核', value: '0' }, { label: '审核通过', value: '1' }, { label: '审核拒绝', value: '-1' }],
  19. },
  20. initValidate() {
  21. const rules = { status: { required: true } }
  22. // 验证字段的提示信息,若不传则调用默认的信息
  23. const messages = { status: { required: '请选择状态', } };
  24. this.WxValidate = new WxValidate(rules, messages)
  25. },
  26. back: function () {
  27. wx.navigateBack({ url: '/pages/me/index' })
  28. },
  29. // 查看
  30. toView: async function (e) {
  31. const that = this;
  32. let { id } = e.currentTarget.dataset;
  33. const arr = await app.$get(`/courtAdmin/api/user/${id}`);
  34. if (arr.errcode == '0') {
  35. that.setData({ form: arr.data })
  36. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  37. }
  38. },
  39. // 审核
  40. toCheck: async function (e) {
  41. const that = this;
  42. let { id } = e.currentTarget.dataset;
  43. const arr = await app.$get(`/courtAdmin/api/joinapply/${id}`);
  44. if (arr.errcode == '0') {
  45. that.setData({ form: arr.data })
  46. that.setData({ dialog: { title: '信息审核', show: true, type: '2' } })
  47. }
  48. },
  49. // 选择状态
  50. statusChange: function (e) {
  51. const that = this;
  52. const { value } = e.detail;
  53. that.setData({ 'form.status': value })
  54. },
  55. // 提交审核
  56. onSubmit: async function (e) {
  57. const that = this;
  58. const data = that.data.form;
  59. const teamInfo = that.data.teamInfo;
  60. const params = e.detail.value;
  61. if (!this.WxValidate.checkForm(params)) {
  62. const error = this.WxValidate.errorList[0];
  63. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  64. return false
  65. } else {
  66. let arr;
  67. arr = await app.$post(`/courtAdmin/api/joinapply/${data.id}`, params);
  68. if (arr.errcode == '0') {
  69. if (params.status == '1') {
  70. arr = await app.$get(`/courtAdmin/api/user/${data.apply_id}`);
  71. if (arr.errcode == '0') {
  72. teamInfo.members.push({ user_id: arr.data.id, nickname: arr.data.nickname, icon: arr.data.icon })
  73. arr = await app.$post(`/courtAdmin/api/team/${teamInfo._id}`, teamInfo);
  74. if (arr.errcode == '0') {
  75. wx.showToast({ title: `审核信息成功`, icon: 'error', duration: 2000 });
  76. that.toClose();
  77. that.watchLogin();
  78. } else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  79. }
  80. }
  81. } else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  82. }
  83. },
  84. // 关闭弹框
  85. toClose: function () {
  86. this.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  87. },
  88. /**
  89. * 生命周期函数--监听页面加载
  90. */
  91. onLoad: function (options) {
  92. //验证规则函数
  93. this.initValidate();
  94. // 计算高度
  95. this.searchHeight();
  96. // 监听用户是否登录
  97. this.watchLogin();
  98. },
  99. // 监听用户是否登录
  100. watchLogin: function () {
  101. const that = this;
  102. wx.getStorage({
  103. key: 'token',
  104. success: async res => {
  105. let arr;
  106. arr = await app.$get(`/courtAdmin/api/team`, { create_id: res.data._id });
  107. if (arr.errcode == '0') {
  108. let teamInfo = arr.data[0];
  109. that.setData({ teamInfo: teamInfo })
  110. arr = await app.$get(`/courtAdmin/api/joinapply`, { team_id: teamInfo._id });
  111. if (arr.errcode == '0') that.setData({ list: arr.data })
  112. }
  113. },
  114. fail: res => {
  115. wx.redirectTo({ url: '/pages/login/index', })
  116. }
  117. })
  118. },
  119. // 计算高度
  120. searchHeight: function () {
  121. let frameStyle = this.data.frameStyle;
  122. let client = app.globalData.client;
  123. let infoHeight = client.windowHeight;
  124. // 是否去掉状态栏
  125. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  126. // 是否减去底部菜单
  127. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  128. if (infoHeight) this.setData({ infoHeight: infoHeight })
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })