index.js 4.9 KB

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