index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. wusercenter: false, //个人中心权限
  8. userMsg: {},
  9. pathList: [], //功能权限
  10. bdWeChat: false, //绑定微信权限
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. this.queryUserMsg();
  17. let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心'])[0].apps;
  18. let wusercenter = false, //个人中心
  19. bdWeChat = false; //绑定微信
  20. let pathList = [];
  21. auth.forEach(v => {
  22. switch (v.name) {
  23. case "wusercenter":
  24. wusercenter = true;
  25. break;
  26. case "teamManagement":
  27. pathList.push({
  28. name: "团队管理",
  29. icon: "icon-a-wodetuanduiguanli",
  30. color: "var(--assist)",
  31. path: `/${v.path}`
  32. })
  33. break;
  34. case "changePassword":
  35. pathList.push({
  36. name: "修改登录密码",
  37. icon: "icon-a-wodeguanyuyingyong",
  38. color: "var(--warning)",
  39. path: `/${v.path}`
  40. })
  41. break;
  42. case "wechatAgreement":
  43. bdWeChat = true;
  44. break;
  45. }
  46. });
  47. this.setData({
  48. wusercenter,
  49. bdWeChat,
  50. pathList
  51. })
  52. },
  53. /* 查询用户信息 */
  54. queryUserMsg() {
  55. _Http.basic({
  56. "classname": "common.usercenter.usercenter",
  57. "method": "queryUserMsg",
  58. "content": {}
  59. }).then(res => {
  60. console.log("个人信息", res)
  61. if (res.msg != '成功') return wx.showToast({
  62. title: res.data,
  63. icon: "none"
  64. })
  65. this.setData({
  66. userMsg: res.data
  67. })
  68. })
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow() {
  74. this.getTabBar().init();
  75. },
  76. /* 退出登录 */
  77. outLogin() {
  78. _Http.logout().then(res => {
  79. wx.showToast({
  80. title: '退出成功'
  81. });
  82. setTimeout(() => {
  83. wx.reLaunch({
  84. url: '/pages/login/phone',
  85. })
  86. }, 300)
  87. })
  88. },
  89. /* 去修改用户信息 */
  90. changeUserMsg() {
  91. let {
  92. name,
  93. phonenumber,
  94. attinfos
  95. } = this.data.userMsg;
  96. wx.navigateTo({
  97. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}`
  98. })
  99. },
  100. /* 绑定或解绑微信 */
  101. bindingWechat(e) {
  102. if (this.data.userMsg.iswechatbinding) {
  103. let that = this;
  104. wx.showModal({
  105. title: "提示",
  106. content: "是否解除绑定",
  107. success: (res) => {
  108. console.log(res)
  109. if (res.confirm) that.handleBDWechat(0);
  110. }
  111. })
  112. } else {
  113. this.handleBDWechat(1);
  114. }
  115. },
  116. handleBDWechat(isbinging) {
  117. let that = this;
  118. wx.getUserProfile({
  119. desc: '用于完善用户资料',
  120. success: ({
  121. userInfo
  122. }) => {
  123. wx.login({
  124. success(res) {
  125. if (res.code) _Http.basic({
  126. "classname": "common.usercenter.usercenter",
  127. "method": "WechatBinding",
  128. content: {
  129. "wechat_code": res.code,
  130. isbinging, // 0解绑 1绑定
  131. wechatuserinfo: userInfo
  132. }
  133. }).then(s => {
  134. if (s.msg != '成功') return wx.showToast({
  135. title: s.data,
  136. icon: "none"
  137. });
  138. setTimeout(() => {
  139. wx.showToast({
  140. title: isbinging == 0 ? '解除成功' : '绑定成功',
  141. icon: "none"
  142. })
  143. }, 100);
  144. that.queryUserMsg();
  145. })
  146. }
  147. })
  148. },
  149. fail: () => {
  150. wx.showToast({
  151. title: '操作失败,未获得授权',
  152. icon: "none"
  153. })
  154. }
  155. })
  156. },
  157. })