info-menu.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const WXAPI = require('apifm-wxapi')
  2. const AUTH = require('../../utils/auth')
  3. Page({
  4. data: {
  5. },
  6. onLoad: function (options) {
  7. },
  8. onShow: function () {
  9. AUTH.wxaCode().then(code => {
  10. this.data.code = code
  11. })
  12. this.getUserApiInfo()
  13. },
  14. async getUserApiInfo() {
  15. const res = await WXAPI.userDetail(wx.getStorageSync('token'))
  16. if (res.code == 0) {
  17. let _data = {}
  18. _data.apiUserInfoMap = res.data
  19. if (res.data.base.mobile) {
  20. _data.userMobile = res.data.base.mobile
  21. }
  22. if (this.data.order_hx_uids && this.data.order_hx_uids.indexOf(res.data.base.id) != -1) {
  23. _data.canHX = true // 具有扫码核销的权限
  24. }
  25. const adminUserIds = wx.getStorageSync('adminUserIds')
  26. if (adminUserIds && adminUserIds.indexOf(res.data.base.id) != -1) {
  27. _data.isAdmin = true
  28. }
  29. if (res.data.peisongMember && res.data.peisongMember.status == 1) {
  30. _data.memberChecked = false
  31. } else {
  32. _data.memberChecked = true
  33. }
  34. this.setData(_data);
  35. }
  36. },
  37. getPhoneNumber: function(e) {
  38. if (!e.detail.errMsg || e.detail.errMsg != "getPhoneNumber:ok") {
  39. wx.showModal({
  40. title: '提示',
  41. content: e.detail.errMsg,
  42. showCancel: false
  43. })
  44. return;
  45. }
  46. this._getPhoneNumber(e)
  47. },
  48. async _getPhoneNumber(e) {
  49. let res
  50. const extConfigSync = wx.getExtConfigSync()
  51. if (extConfigSync.subDomain) {
  52. // 服务商模式
  53. res = await WXAPI.wxappServiceBindMobile({
  54. token: wx.getStorageSync('token'),
  55. code: this.data.code,
  56. encryptedData: e.detail.encryptedData,
  57. iv: e.detail.iv,
  58. })
  59. } else {
  60. res = await WXAPI.bindMobileWxapp(wx.getStorageSync('token'), this.data.code, e.detail.encryptedData, e.detail.iv)
  61. }
  62. AUTH.wxaCode().then(code => {
  63. this.data.code = code
  64. })
  65. if (res.code === 10002) {
  66. AUTH.login(this)
  67. return
  68. }
  69. if (res.code == 0) {
  70. wx.showToast({
  71. title: '绑定成功',
  72. icon: 'success',
  73. duration: 2000
  74. })
  75. this.getUserApiInfo();
  76. } else {
  77. wx.showModal({
  78. title: '提示',
  79. content: res.msg,
  80. showCancel: false
  81. })
  82. }
  83. }
  84. })