index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. languagecode = wx.getStorageSync("languagecode");
  77. wx.clearStorageSync();
  78. wx.setStorageSync('loginMsg', loginMsg)
  79. wx.setStorageSync('isAgree', true)
  80. wx.setStorageSync('languagecode', languagecode)
  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. accountno
  97. } = this.data.userMsg;
  98. wx.navigateTo({
  99. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}&email=${hr.email}&accountno=${accountno}`
  100. })
  101. },
  102. /* 绑定或解绑微信 */
  103. bindingWechat(e) {
  104. if (this.data.userMsg.iswechatbinding) {
  105. let that = this;
  106. wx.showModal({
  107. title: "提示",
  108. content: "是否解除绑定",
  109. success: (res) => {
  110. if (res.confirm) that.handleBDWechat(0);
  111. }
  112. })
  113. } else {
  114. this.handleBDWechat(1);
  115. }
  116. },
  117. handleBDWechat(isbinging) {
  118. let that = this;
  119. wx.getUserProfile({
  120. desc: '用于完善用户资料',
  121. success: ({
  122. userInfo
  123. }) => {
  124. wx.login({
  125. success(res) {
  126. if (res.code) _Http.basic({
  127. "classname": "common.usercenter.usercenter",
  128. "method": "WechatBinding",
  129. content: {
  130. "wechat_code": res.code,
  131. isbinging, // 0解绑 1绑定
  132. wechatuserinfo: userInfo,
  133. "appid": "wx197f219a82a89d7b"
  134. }
  135. }).then(s => {
  136. console.log("微信绑定", isbinging, s)
  137. if (s.msg != '成功') return wx.showToast({
  138. title: s.data,
  139. icon: "none"
  140. });
  141. setTimeout(() => {
  142. wx.showToast({
  143. title: isbinging == 0 ? '解除成功' : '绑定成功',
  144. icon: "none"
  145. })
  146. }, 100);
  147. that.queryUserMsg();
  148. })
  149. }
  150. })
  151. },
  152. fail: () => {
  153. wx.showToast({
  154. title: '操作失败,未获得授权',
  155. icon: "none"
  156. })
  157. }
  158. })
  159. },
  160. /* 前去查询 */
  161. bindingOfficialAccounts() {
  162. wx.navigateTo({
  163. url: './webView',
  164. })
  165. }
  166. })