index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. const _Http = getApp().globalData.http;
  2. let downCount = null;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. site: getApp().globalData.site,
  9. userMsg: {},
  10. pathList: [], //功能权限
  11. teamAuth: '', //团队管理权限列表 JSON字符串 用于传递
  12. },
  13. onLoad(options) {
  14. this.queryUserMsg();
  15. //美大关闭团队管理
  16. if (!['美大'].includes(this.data.site)) {
  17. let authlist = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心']);
  18. let pathList = [{
  19. name: "修改登录密码",
  20. icon: "icon-a-wodeguanyuyingyong",
  21. color: "var(--warning)",
  22. path: `/pages/tabbar/mine/changePassword/index`
  23. }]
  24. if (authlist.length) {
  25. authlist[0].apps.forEach(v => {
  26. switch (v.name) {
  27. case "teamManagement":
  28. pathList.unshift({
  29. name: "团队管理",
  30. icon: "icon-a-wodetuanduiguanli",
  31. color: "var(--assist)",
  32. path: `/${v.path}`
  33. })
  34. this.setData({
  35. teamAuth: JSON.stringify(v.meta.auth)
  36. })
  37. break;
  38. }
  39. });
  40. this.setData({
  41. pathList
  42. })
  43. }
  44. };
  45. },
  46. /* 查询用户信息 */
  47. queryUserMsg() {
  48. _Http.basic({
  49. "classname": "common.usercenter.usercenter",
  50. "method": "queryUserMsg",
  51. "content": {
  52. "nochace": true
  53. }
  54. }).then(res => {
  55. if (res.msg != '成功') return wx.showToast({
  56. title: res.msg,
  57. icon: "none"
  58. })
  59. this.setData({
  60. userMsg: res.data
  61. })
  62. })
  63. },
  64. onShow() {
  65. this.getTabBar().init();
  66. },
  67. /* 退出登录 */
  68. outLogin() {
  69. clearTimeout(downCount);
  70. wx.showLoading({
  71. title: '正在退出...',
  72. })
  73. downCount = setTimeout(() => {
  74. _Http.logout().then(res => {
  75. wx.showToast({
  76. title: '退出成功'
  77. });
  78. let loginMsg = wx.getStorageSync("loginMsg");
  79. wx.clearStorageSync();
  80. wx.setStorageSync('loginMsg', loginMsg)
  81. setTimeout(() => {
  82. wx.reLaunch({
  83. url: '/pages/login/phone',
  84. })
  85. }, 300)
  86. })
  87. }, 300);
  88. },
  89. /* 去修改用户信息 */
  90. changeUserMsg() {
  91. let {
  92. name,
  93. phonenumber,
  94. attinfos,
  95. hr
  96. } = this.data.userMsg;
  97. wx.navigateTo({
  98. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}&email=${hr.email}`
  99. })
  100. },
  101. /* 绑定或解绑微信 */
  102. bindingWechat(e) {
  103. if (this.data.userMsg.iswechatbinding) {
  104. let that = this;
  105. wx.showModal({
  106. title: "提示",
  107. content: "是否解除绑定",
  108. success: (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. onShareAppMessage() {}
  158. })