adminlist.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // pages/adminlist/adminlist.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. },
  57. getAdministrators_list() {
  58. let that = this;
  59. // 管理员列表
  60. wx.showLoading({
  61. title: '加载中',
  62. mask: true
  63. })
  64. wx.request({
  65. url: api.Administrators_list,
  66. header: {
  67. 'Authorization': wx.getStorageSync('token')
  68. },
  69. method: 'POST',
  70. success(res) {
  71. console.log(res);
  72. if (res.data.code === 1) {
  73. that.setData({
  74. Administrators_list: res.data.data
  75. })
  76. } else {
  77. wx.showToast({
  78. title: res.data.msg,
  79. mask: true,
  80. icon: 'none'
  81. })
  82. }
  83. },
  84. fail(err) {
  85. wx.showToast({
  86. title: '发起网络请求失败',
  87. icon: 'none',
  88. mask: true
  89. })
  90. },
  91. complete() {
  92. wx.hideLoading()
  93. }
  94. })
  95. },
  96. // 切换账号
  97. switchAccount(e) {
  98. let that = this;
  99. let admin_id = Number(e.currentTarget.dataset.id);
  100. wx.showLoading({
  101. title: '切换中',
  102. mask: true
  103. })
  104. wx.request({
  105. url: api.get_token,
  106. data: {
  107. id: admin_id
  108. },
  109. method: 'POST',
  110. success(res) {
  111. console.log(res);
  112. if (res.data.code === 1) {
  113. wx.setStorageSync('token', res.data.data);
  114. // 获取用户个人信息-开始
  115. wx.showLoading({
  116. title: '登录中',
  117. mask: true
  118. })
  119. wx.request({
  120. url: api.user_info,
  121. header: {
  122. 'Authorization': wx.getStorageSync('token')
  123. },
  124. data: {
  125. id: admin_id
  126. },
  127. success(res) {
  128. wx.hideLoading()
  129. console.log(res);
  130. if (res.data.code === 1) {
  131. wx.setStorageSync('login', true);
  132. wx.setStorageSync('userinfo', res.data.data);
  133. wx.showToast({
  134. title: '切换成功',
  135. icon: 'success',
  136. mask: true,
  137. success() {
  138. setTimeout(() => {
  139. wx.reLaunch({
  140. url: '/pages/mine/mine',
  141. })
  142. }, 1500)
  143. }
  144. })
  145. } else {
  146. wx.showToast({
  147. title: res.data.msg,
  148. mask: true,
  149. icon: 'none'
  150. })
  151. }
  152. },
  153. fail(err) {
  154. wx.hideLoading()
  155. wx.showToast({
  156. title: '发起网络请求失败',
  157. icon: 'none',
  158. mask: true
  159. })
  160. },
  161. complete() {
  162. // wx.hideLoading()
  163. }
  164. // 获取用户个人信息-结束
  165. })
  166. } else {
  167. wx.showToast({
  168. title: res.data.msg,
  169. mask: true,
  170. icon: 'none'
  171. })
  172. }
  173. },
  174. fail(err) {
  175. wx.showToast({
  176. title: '发起网络请求失败',
  177. icon: 'none',
  178. mask: true
  179. })
  180. },
  181. complete() {
  182. wx.hideLoading()
  183. }
  184. })
  185. }
  186. })