index.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. // 选项卡
  13. tabs: {
  14. active: 'a',
  15. list: [
  16. { title: '管理员', name: 'a' },
  17. { title: '团队创建人', name: 'b' },
  18. { title: '个人用户', name: 'c' },
  19. ],
  20. },
  21. list: [],
  22. // 弹框
  23. dialog: { title: '详细信息', show: false, type: '1' },
  24. form: {},
  25. statusList: [{ label: '待审核', value: '0' }, { label: '审核通过', value: '1' }, { label: '审核拒绝', value: '-1' }]
  26. },
  27. initValidate() {
  28. const rules = { status: { required: true } }
  29. // 验证字段的提示信息,若不传则调用默认的信息
  30. const messages = { status: { required: '请选择状态', } };
  31. this.WxValidate = new WxValidate(rules, messages)
  32. },
  33. back: function () {
  34. wx.navigateBack({ url: '/pages/me/index' })
  35. },
  36. // 选项卡
  37. tabsChange: function (e) {
  38. const that = this;
  39. that.setData({ 'tabs.active': e.detail.name })
  40. that.watchLogin()
  41. },
  42. // 添加用户
  43. toAdd: function () {
  44. wx.navigateTo({ url: `/pages/user/detail` })
  45. },
  46. // 查看
  47. toView: async function (e) {
  48. const that = this;
  49. let { id } = e.currentTarget.dataset;
  50. const arr = await app.$get(`/courtAdmin/api/user/${id}`);
  51. if (arr.errcode == '0') {
  52. that.setData({ form: arr.data })
  53. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  54. }
  55. },
  56. // 修改
  57. toEdit: function (e) {
  58. const that = this;
  59. let { id } = e.currentTarget.dataset;
  60. wx.navigateTo({ url: `/pages/user/detail?id=${id}` })
  61. },
  62. // 审核
  63. toCheck: async function (e) {
  64. const that = this;
  65. let { id } = e.currentTarget.dataset;
  66. const arr = await app.$get(`/courtAdmin/api/user/${id}`);
  67. if (arr.errcode == '0') {
  68. that.setData({ form: arr.data })
  69. that.setData({ dialog: { title: '信息审核', show: true, type: '2' } })
  70. }
  71. },
  72. // 删除
  73. toDel: async function (e) {
  74. const that = this;
  75. const { id } = e.currentTarget.dataset;
  76. wx.showModal({
  77. title: '提示',
  78. content: '是否确认删除该条数据?',
  79. async success(res) {
  80. if (res.confirm) {
  81. const arr = await app.$delete(`/courtAdmin/api/user/${id}`);
  82. if (arr.errcode == '0') {
  83. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  84. that.watchLogin()
  85. } else {
  86. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  87. }
  88. }
  89. }
  90. })
  91. },
  92. // 选择状态
  93. statusChange: function (e) {
  94. const that = this;
  95. const { value } = e.detail;
  96. that.setData({ 'form.status': value })
  97. },
  98. // 提交审核
  99. onSubmit: async function (e) {
  100. const that = this;
  101. const data = that.data.form;
  102. const params = e.detail.value;
  103. if (!this.WxValidate.checkForm(params)) {
  104. const error = this.WxValidate.errorList[0];
  105. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  106. return false
  107. } else {
  108. const arr = await app.$post(`/courtAdmin/api/user/${data.id}`, params);
  109. if (arr.errcode == '0') {
  110. wx.showToast({ title: `审核信息成功`, icon: 'error', duration: 2000 });
  111. that.toClose();
  112. that.watchLogin();
  113. } else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  114. }
  115. },
  116. // 关闭弹框
  117. toClose: function () {
  118. this.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  119. },
  120. /**
  121. * 生命周期函数--监听页面加载
  122. */
  123. onLoad: function (options) {
  124. //验证规则函数
  125. this.initValidate();
  126. // 计算高度
  127. this.searchHeight();
  128. // 监听用户是否登录
  129. this.watchLogin();
  130. },
  131. // 监听用户是否登录
  132. watchLogin: function () {
  133. const that = this;
  134. let active = that.data.tabs.active;
  135. let type = active == 'a' ? '0' : active == 'b' ? '1' : '2';
  136. wx.getStorage({
  137. key: 'token',
  138. success: async res => {
  139. const arr = await app.$get(`/courtAdmin/api/user`, { type: type });
  140. if (arr.errcode == '0') {
  141. that.setData({ list: arr.data })
  142. }
  143. },
  144. fail: res => {
  145. wx.redirectTo({ url: '/pages/login/index', })
  146. }
  147. })
  148. },
  149. // 计算高度
  150. searchHeight: function () {
  151. let frameStyle = this.data.frameStyle;
  152. let client = app.globalData.client;
  153. let infoHeight = client.windowHeight;
  154. // 是否去掉状态栏
  155. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  156. // 是否减去底部菜单
  157. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  158. if (infoHeight) this.setData({ infoHeight: infoHeight })
  159. },
  160. /**
  161. * 生命周期函数--监听页面初次渲染完成
  162. */
  163. onReady: function () {
  164. },
  165. /**
  166. * 生命周期函数--监听页面显示
  167. */
  168. onShow: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面隐藏
  172. */
  173. onHide: function () {
  174. },
  175. /**
  176. * 生命周期函数--监听页面卸载
  177. */
  178. onUnload: function () {
  179. },
  180. /**
  181. * 页面相关事件处理函数--监听用户下拉动作
  182. */
  183. onPullDownRefresh: function () {
  184. },
  185. /**
  186. * 页面上拉触底事件的处理函数
  187. */
  188. onReachBottom: function () {
  189. },
  190. /**
  191. * 用户点击右上角分享
  192. */
  193. onShareAppMessage: function () {
  194. }
  195. })