index.js 4.6 KB

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