logic.js 3.9 KB

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