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