index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. const _Http = getApp().globalData.http;
  2. let downCount = null;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. userMsg: {},
  9. pathList: [], //功能权限
  10. },
  11. onLoad(options) {
  12. this.queryUserMsg();
  13. //美大关闭团队管理
  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[0].apps.some(v => v.name == "teamManagement")) {
  22. this.data.pathList.unshift({
  23. name: "团队管理",
  24. icon: "icon-a-wodetuanduiguanli",
  25. color: "var(--assist)",
  26. path: `/pages/teams/index`
  27. });
  28. this.setData({
  29. pathList: this.data.pathList
  30. })
  31. }
  32. },
  33. /* 查询用户信息 */
  34. queryUserMsg() {
  35. _Http.basic({
  36. "classname": "common.usercenter.usercenter",
  37. "method": "queryUserMsg",
  38. "content": {
  39. "nochace": true
  40. }
  41. }).then(res => {
  42. if (res.msg != '成功') return wx.showToast({
  43. title: res.msg,
  44. icon: "none"
  45. });
  46. switch (res.data.usertype) {
  47. case 1:
  48. res.data.usertype = '企业职员'
  49. break;
  50. case 21:
  51. res.data.usertype = '负责人'
  52. break;
  53. case 22:
  54. res.data.usertype = '员工'
  55. break;
  56. default:
  57. res.data.usertype = ''
  58. break;
  59. }
  60. this.setData({
  61. userMsg: res.data
  62. })
  63. })
  64. },
  65. onShow() {
  66. this.getTabBar().init();
  67. },
  68. /* 退出登录 */
  69. outLogin() {
  70. clearTimeout(downCount);
  71. wx.showLoading({
  72. title: '正在退出...',
  73. })
  74. downCount = setTimeout(() => {
  75. _Http.logout().then(res => {
  76. wx.showToast({
  77. title: '退出成功'
  78. });
  79. let loginMsg = wx.getStorageSync("loginMsg");
  80. wx.clearStorageSync();
  81. wx.setStorageSync('loginMsg', loginMsg)
  82. setTimeout(() => {
  83. wx.reLaunch({
  84. url: '/pages/login/phone',
  85. })
  86. }, 300)
  87. })
  88. }, 300);
  89. },
  90. /* 去修改用户信息 */
  91. changeUserMsg() {
  92. let {
  93. name,
  94. phonenumber,
  95. attinfos,
  96. hr
  97. } = this.data.userMsg;
  98. wx.navigateTo({
  99. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}&email=${hr.email}`
  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. }
  134. }).then(s => {
  135. if (s.msg != '成功') return wx.showToast({
  136. title: s.data,
  137. icon: "none"
  138. });
  139. setTimeout(() => {
  140. wx.showToast({
  141. title: isbinging == 0 ? '解除成功' : '绑定成功',
  142. icon: "none"
  143. })
  144. }, 100);
  145. that.queryUserMsg();
  146. })
  147. }
  148. })
  149. },
  150. fail: () => {
  151. wx.showToast({
  152. title: '操作失败,未获得授权',
  153. icon: "none"
  154. })
  155. }
  156. })
  157. },
  158. onShareAppMessage() {}
  159. })