adminmanage.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // pages/adminmanage/adminmanage.js
  2. const app = getApp();
  3. const api = require('../../api/api');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. navbarData: {
  10. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  11. title: '管理员管理', //导航栏 中间的标题
  12. capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页)
  13. },
  14. Administrators_list: [], //管理员列表
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad(options) {
  20. this.getAdministrators_list()
  21. },
  22. /**
  23. * 生命周期函数--监听页面初次渲染完成
  24. */
  25. onReady() {
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow() {
  31. },
  32. /**
  33. * 生命周期函数--监听页面隐藏
  34. */
  35. onHide() {
  36. },
  37. /**
  38. * 生命周期函数--监听页面卸载
  39. */
  40. onUnload() {
  41. },
  42. /**
  43. * 页面相关事件处理函数--监听用户下拉动作
  44. */
  45. onPullDownRefresh() {
  46. },
  47. /**
  48. * 页面上拉触底事件的处理函数
  49. */
  50. onReachBottom() {
  51. },
  52. /**
  53. * 用户点击右上角分享
  54. */
  55. onShareAppMessage() {
  56. let user_id = wx.getStorageSync('userinfo').id; //邀请人ID
  57. let user_name = wx.getStorageSync('userinfo').name; //邀请人姓名
  58. let user_avatar = wx.getStorageSync('userinfo').headimg; //邀请人头像
  59. return {
  60. title: '邀请您成为我的管理员',
  61. path: '/pages/bindadmin/bindadmin?user_id=' + user_id + '&user_name=' + user_name + '&user_avatar=' + user_avatar,
  62. imageUrl: 'https://s4.ax1x.com/2021/12/29/TccgfK.jpg'
  63. }
  64. },
  65. getAdministrators_list() {
  66. let that = this;
  67. // 管理员列表
  68. wx.showLoading({
  69. title: '加载中',
  70. mask: true
  71. })
  72. wx.request({
  73. url: api.Administrators_list,
  74. header: {
  75. 'Authorization': wx.getStorageSync('token')
  76. },
  77. method: 'POST',
  78. success(res) {
  79. console.log(res);
  80. if (res.data.code === 1) {
  81. that.setData({
  82. Administrators_list: res.data.data
  83. })
  84. } else {
  85. wx.showToast({
  86. title: res.data.msg,
  87. mask: true,
  88. icon: 'none'
  89. })
  90. }
  91. },
  92. fail(err) {
  93. wx.showToast({
  94. title: '发起网络请求失败',
  95. icon: 'none',
  96. mask: true
  97. })
  98. },
  99. complete() {
  100. wx.hideLoading()
  101. }
  102. })
  103. },
  104. deleteAdmin(e) {
  105. let that = this;
  106. let admin_id = e.currentTarget.dataset.id;
  107. wx.showLoading({
  108. title: '删除中',
  109. mask: true
  110. })
  111. wx.request({
  112. url: api.Administrators_delete,
  113. header: {
  114. 'Authorization': wx.getStorageSync('token')
  115. },
  116. data: {
  117. id: admin_id
  118. },
  119. method: 'POST',
  120. success(res) {
  121. wx.hideLoading()
  122. console.log(res);
  123. if (res.data.code === 1) {
  124. wx.showToast({
  125. title: '删除成功',
  126. mask: true,
  127. success() {
  128. setTimeout(()=>{
  129. that.getAdministrators_list()
  130. }, 1500)
  131. }
  132. })
  133. } else {
  134. wx.showToast({
  135. title: res.data.msg,
  136. mask: true,
  137. icon: 'none'
  138. })
  139. }
  140. },
  141. fail(err) {
  142. wx.hideLoading()
  143. wx.showToast({
  144. title: '发起网络请求失败',
  145. icon: 'none',
  146. mask: true
  147. })
  148. },
  149. complete() {
  150. // wx.hideLoading()
  151. }
  152. })
  153. }
  154. })