logic.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { logout as logoutApi } from '@/api/auth'
  2. import { getMyProfile, listAllLevelConfigs } from '@/api/fulfiller'
  3. import { clearAuth, isLoggedIn } from '@/utils/auth'
  4. import customTabbar from '@/components/custom-tabbar/index.vue'
  5. export default {
  6. components: {
  7. customTabbar
  8. },
  9. data() {
  10. return {
  11. showServicePopup: false,
  12. showLogoutPopup: false,
  13. profile: null,
  14. profileLoading: false,
  15. levelConfigs: [] // 等级配置列表
  16. }
  17. },
  18. computed: {
  19. // 根据 profile.level 匹配对应的等级名称
  20. displayLevelName() {
  21. if (!this.profile || !this.levelConfigs.length) return '普通履约者'
  22. const config = this.levelConfigs.find(c => c.lvNo === this.profile.level)
  23. return config ? config.name : (this.profile.levelName || '普通履约者')
  24. }
  25. },
  26. onShow() {
  27. uni.hideTabBar()
  28. if (isLoggedIn()) {
  29. this.loadProfile()
  30. this.loadLevelConfigs()
  31. }
  32. },
  33. methods: {
  34. async loadProfile() {
  35. if (this.profileLoading) return
  36. this.profileLoading = true
  37. try {
  38. const res = await getMyProfile()
  39. this.profile = res.data || null
  40. } catch (err) {
  41. console.error('获取个人信息失败:', err)
  42. } finally {
  43. this.profileLoading = false
  44. }
  45. },
  46. async loadLevelConfigs() {
  47. try {
  48. const res = await listAllLevelConfigs()
  49. this.levelConfigs = res.data || []
  50. } catch (err) {
  51. console.error('加载等级配置失败:', err)
  52. }
  53. },
  54. navToSettings() {
  55. uni.navigateTo({
  56. url: '/pages/mine/settings/index'
  57. });
  58. },
  59. navToProfile() {
  60. uni.navigateTo({
  61. url: '/pages/mine/settings/profile/index'
  62. });
  63. },
  64. navToLevel() {
  65. uni.navigateTo({
  66. url: '/pages/mine/level/index'
  67. });
  68. },
  69. navToNotification() {
  70. uni.navigateTo({
  71. url: '/pages/mine/message/index'
  72. });
  73. },
  74. navToWallet() {
  75. uni.navigateTo({
  76. url: '/pages/mine/wallet/index'
  77. });
  78. },
  79. navToPoints() {
  80. uni.navigateTo({
  81. url: '/pages/mine/points/index'
  82. });
  83. },
  84. navToOrderStats() {
  85. uni.navigateTo({
  86. url: '/pages/mine/order-stats'
  87. });
  88. },
  89. navToRewards() {
  90. uni.navigateTo({
  91. url: '/pages/mine/rewards'
  92. });
  93. },
  94. openServicePopup() {
  95. this.showServicePopup = true;
  96. },
  97. closeServicePopup() {
  98. this.showServicePopup = false;
  99. },
  100. previewQRCode() {
  101. uni.previewImage({
  102. urls: ['/static/logo.png']
  103. });
  104. },
  105. openOnlineService() {
  106. // 模拟跳转企业微信客服
  107. uni.showToast({
  108. title: '正在跳转企业微信客服...',
  109. icon: 'none'
  110. });
  111. },
  112. callServicePhone() {
  113. uni.makePhoneCall({
  114. phoneNumber: '400-123-4567'
  115. });
  116. },
  117. logout() {
  118. this.showLogoutPopup = true;
  119. },
  120. cancelLogout() {
  121. this.showLogoutPopup = false;
  122. },
  123. async confirmLogout() {
  124. this.showLogoutPopup = false;
  125. try {
  126. await logoutApi()
  127. } catch (e) {
  128. // 即使后端退出失败,也清除本地登录态
  129. }
  130. clearAuth()
  131. uni.reLaunch({
  132. url: '/pages/login/login'
  133. });
  134. }
  135. }
  136. }