index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. getApp().globalData.Language.getLanguagePackage(this)
  15. let authlist = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心']);
  16. let pathList = [{
  17. name: "修改登录密码",
  18. icon: "icon-a-wodeguanyuyingyong",
  19. color: "var(--warning)",
  20. path: `/pages/tabbar/mine/changePassword/index`
  21. }]
  22. if (authlist.length) {
  23. authlist[0].apps.forEach(v => {
  24. switch (v.name) {
  25. case "teamManagement":
  26. pathList.unshift({
  27. name: "团队管理",
  28. icon: "icon-a-wodetuanduiguanli",
  29. color: "var(--assist)",
  30. path: `/${v.path}`
  31. })
  32. this.setData({
  33. teamAuth: JSON.stringify(v.meta.auth)
  34. })
  35. break;
  36. }
  37. });
  38. this.setData({
  39. pathList
  40. })
  41. };
  42. },
  43. /* 查询用户信息 */
  44. queryUserMsg() {
  45. _Http.basic({
  46. "classname": "common.usercenter.usercenter",
  47. "method": "queryUserMsg",
  48. "content": {
  49. "nocache": true
  50. }
  51. }).then(res => {
  52. console.log("查询用户信息", res)
  53. if (res.code != '1') return wx.showToast({
  54. title: res.msg,
  55. icon: "none"
  56. })
  57. this.setData({
  58. userMsg: res.data
  59. })
  60. })
  61. },
  62. onShow() {
  63. this.getTabBar().init();
  64. },
  65. /* 退出登录 */
  66. outLogin() {
  67. clearTimeout(downCount);
  68. wx.showLoading({
  69. title: getApp().globalData.Language.getMapText('加载中') + '...',
  70. })
  71. downCount = setTimeout(() => {
  72. _Http.logout().then(res => {
  73. wx.showToast({
  74. title: getApp().globalData.Language.getMapText('退出成功')
  75. });
  76. let loginMsg = wx.getStorageSync("loginMsg"),
  77. languagecode = wx.getStorageSync("languagecode");
  78. wx.clearStorageSync();
  79. wx.setStorageSync('loginMsg', loginMsg)
  80. wx.setStorageSync('isAgree', true)
  81. wx.removeStorageSync('languagecode');
  82. wx.setStorageSync('languagecode', languagecode)
  83. setTimeout(() => {
  84. wx.reLaunch({
  85. url: '/pages/login/phone',
  86. })
  87. }, 300)
  88. })
  89. }, 300);
  90. },
  91. /* 去修改用户信息 */
  92. changeUserMsg() {
  93. let {
  94. name,
  95. phonenumber,
  96. attinfos,
  97. hr,
  98. accountno
  99. } = this.data.userMsg;
  100. wx.navigateTo({
  101. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}&email=${hr.email}&accountno=${accountno}`
  102. })
  103. },
  104. /* 绑定或解绑微信 */
  105. bindingWechat(e) {
  106. if (this.data.userMsg.iswechatbinding) {
  107. let that = this;
  108. wx.showModal({
  109. title: getApp().globalData.Language.getMapText('提示'),
  110. content: getApp().globalData.Language.getMapText('是否解除绑定'),
  111. cancelText: getApp().globalData.Language.getMapText('取消'),
  112. confirmText: getApp().globalData.Language.getMapText('确定'),
  113. success: (res) => {
  114. if (res.confirm) that.handleBDWechat(0);
  115. }
  116. })
  117. } else {
  118. this.handleBDWechat(1);
  119. }
  120. },
  121. handleBDWechat(isbinging) {
  122. let that = this;
  123. wx.getUserProfile({
  124. desc: getApp().globalData.Language.getMapText('用于完善用户资料'),
  125. success: ({
  126. userInfo
  127. }) => {
  128. wx.login({
  129. success(res) {
  130. if (res.code) _Http.basic({
  131. "classname": "common.usercenter.usercenter",
  132. "method": "WechatBinding",
  133. content: {
  134. "wechat_code": res.code,
  135. isbinging, // 0解绑 1绑定
  136. wechatuserinfo: userInfo,
  137. "appid": "wx197f219a82a89d7b"
  138. }
  139. }).then(s => {
  140. console.log("微信绑定", isbinging, s)
  141. if (s.code != '1') return wx.showToast({
  142. title: s.data,
  143. icon: "none"
  144. });
  145. setTimeout(() => {
  146. wx.showToast({
  147. title: isbinging == 0 ? getApp().globalData.Language.getMapText('解绑成功') : getApp().globalData.Language.getMapText('绑定成功'),
  148. icon: "none"
  149. })
  150. }, 100);
  151. that.queryUserMsg();
  152. })
  153. }
  154. })
  155. },
  156. fail: () => {
  157. wx.showToast({
  158. title: getApp().globalData.Language.getMapText('未获取授权'),
  159. icon: "none"
  160. })
  161. }
  162. })
  163. },
  164. /* 前去查询 */
  165. bindingOfficialAccounts() {
  166. wx.navigateTo({
  167. url: './webView',
  168. })
  169. }
  170. })