index.js 4.7 KB

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