index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. const _Http = getApp().globalData.http;
  2. let downCount = null;
  3. Component({
  4. properties: {
  5. },
  6. options: {
  7. addGlobalClass: true,
  8. },
  9. data: {},
  10. methods: {
  11. init() {
  12. this.queryUserMsg();
  13. let pathList = [{
  14. name: "修改登录密码",
  15. icon: "icon-a-wodeguanyuyingyong",
  16. color: "var(--warning)",
  17. path: `/pages/index/userCenter/changePassword/index`
  18. }]
  19. this.setData({
  20. pathList
  21. });
  22. return true;
  23. },
  24. /* 查询用户信息 */
  25. queryUserMsg() {
  26. _Http.basic({
  27. "classname": "common.usercenter.usercenter",
  28. "method": "queryUserMsg",
  29. "content": {
  30. "nocache": true
  31. }
  32. }).then(res => {
  33. console.log("查询用户信息", res)
  34. if (res.msg != '成功') {
  35. wx.showToast({
  36. title: res.msg,
  37. icon: "none"
  38. })
  39. } else {
  40. this.setData({
  41. userMsg: res.data
  42. })
  43. }
  44. })
  45. },
  46. /* 退出登录 */
  47. outLogin() {
  48. clearTimeout(downCount);
  49. wx.showLoading({
  50. title: '正在退出...',
  51. })
  52. downCount = setTimeout(() => {
  53. _Http.logout().then(res => {
  54. getApp().globalData.SocketTask.close()
  55. wx.showToast({
  56. title: '退出成功',
  57. mask: true
  58. });
  59. let loginMsg = wx.getStorageSync("loginMsg");
  60. wx.clearStorageSync();
  61. wx.setStorageSync('loginMsg', loginMsg)
  62. wx.setStorageSync('isAgree', true)
  63. setTimeout(() => {
  64. wx.reLaunch({
  65. url: '/pages/login/phone',
  66. })
  67. }, 300)
  68. })
  69. }, 300);
  70. },
  71. /* 去修改用户信息 */
  72. changeUserMsg() {
  73. let {
  74. name,
  75. phonenumber,
  76. attinfos,
  77. hr
  78. } = this.data.userMsg;
  79. wx.navigateTo({
  80. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}&email=${hr.email}`
  81. })
  82. },
  83. /* 绑定或解绑微信 */
  84. bindingWechat(e) {
  85. if (this.data.userMsg.iswechatbinding) {
  86. let that = this;
  87. wx.showModal({
  88. title: "提示",
  89. content: "是否解除绑定",
  90. success: (res) => {
  91. if (res.confirm) that.handleBDWechat(0);
  92. }
  93. })
  94. } else {
  95. this.handleBDWechat(1);
  96. }
  97. },
  98. handleBDWechat(isbinging) {
  99. let that = this;
  100. wx.getUserProfile({
  101. desc: '用于完善用户资料',
  102. success: ({
  103. userInfo
  104. }) => {
  105. wx.login({
  106. success(res) {
  107. if (res.code) _Http.basic({
  108. "classname": "common.usercenter.usercenter",
  109. "method": "WechatBinding",
  110. content: {
  111. "wechat_code": res.code,
  112. isbinging, // 0解绑 1绑定
  113. wechatuserinfo: userInfo
  114. }
  115. }).then(s => {
  116. if (s.msg != '成功') return wx.showToast({
  117. title: s.data,
  118. icon: "none"
  119. });
  120. setTimeout(() => {
  121. wx.showToast({
  122. title: isbinging == 0 ? '解除成功' : '绑定成功',
  123. icon: "none"
  124. })
  125. }, 100);
  126. that.queryUserMsg();
  127. })
  128. }
  129. })
  130. },
  131. fail: () => {
  132. wx.showToast({
  133. title: '操作失败,未获得授权',
  134. icon: "none"
  135. })
  136. }
  137. })
  138. },
  139. /* 前去查询 */
  140. bindingOfficialAccounts() {
  141. wx.navigateTo({
  142. url: '/pages/associatedPublicNumber/webView',
  143. })
  144. }
  145. }
  146. })