index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. console.log("查询用户信息", res)
  52. if (res.msg != '成功') return wx.showToast({
  53. title: res.msg,
  54. icon: "none"
  55. })
  56. this.setData({
  57. userMsg: res.data
  58. })
  59. })
  60. },
  61. onShow() {
  62. this.getTabBar().init();
  63. },
  64. /* 退出登录 */
  65. outLogin() {
  66. clearTimeout(downCount);
  67. wx.showLoading({
  68. title: '正在退出...',
  69. })
  70. downCount = setTimeout(() => {
  71. _Http.logout().then(res => {
  72. wx.showToast({
  73. title: '退出成功'
  74. });
  75. let loginMsg = wx.getStorageSync("loginMsg");
  76. wx.clearStorageSync();
  77. wx.setStorageSync('loginMsg', loginMsg)
  78. wx.setStorageSync('isAgree', true)
  79. setTimeout(() => {
  80. wx.reLaunch({
  81. url: '/pages/login/phone',
  82. })
  83. }, 300)
  84. })
  85. }, 300);
  86. },
  87. /* 去修改用户信息 */
  88. changeUserMsg() {
  89. let {
  90. name,
  91. phonenumber,
  92. attinfos,
  93. hr,
  94. accountno
  95. } = this.data.userMsg;
  96. wx.navigateTo({
  97. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}&email=${hr.email}&accountno=${accountno}`
  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. if (res.confirm) that.handleBDWechat(0);
  109. }
  110. })
  111. } else {
  112. this.handleBDWechat(1);
  113. }
  114. },
  115. handleBDWechat(isbinging) {
  116. let that = this;
  117. wx.getUserProfile({
  118. desc: '用于完善用户资料',
  119. success: ({
  120. userInfo
  121. }) => {
  122. wx.login({
  123. success(res) {
  124. if (res.code) _Http.basic({
  125. "classname": "common.usercenter.usercenter",
  126. "method": "WechatBinding",
  127. content: {
  128. "wechat_code": res.code,
  129. isbinging, // 0解绑 1绑定
  130. wechatuserinfo: userInfo,
  131. "appid": "wx197f219a82a89d7b"
  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. /* 前去查询 */
  158. bindingOfficialAccounts() {
  159. wx.navigateTo({
  160. url: './webView',
  161. })
  162. }
  163. })