logic.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import { logout as logoutApi } from '@/api/auth'
  2. import { getMyProfile } from '@/api/fulfiller/fulfiller'
  3. import { listAllLevelConfigs } from '@/api/fulfiller/levelConfig'
  4. import { getCustomerServiceSetting } from '@/api/system/customerServiceSetting'
  5. import { clearAuth, isLoggedIn } from '@/utils/auth'
  6. import customTabbar from '@/components/custom-tabbar/index.vue'
  7. export default {
  8. components: {
  9. customTabbar
  10. },
  11. data() {
  12. return {
  13. showServicePopup: false,
  14. showLogoutPopup: false,
  15. profile: null,
  16. profileLoading: false,
  17. levelConfigs: [], // 等级配置列表
  18. customerSetting: {
  19. wechatAccount: '',
  20. phoneNumber: '400-123-4567',
  21. qrCodeUrl: '/static/logo.png',
  22. enterpriseWechatLink: '',
  23. startServiceTime: '',
  24. endServiceTime: ''
  25. }
  26. }
  27. },
  28. computed: {
  29. // 根据 profile.level 匹配对应的等级名称
  30. displayLevelName() {
  31. if (!this.profile || !this.levelConfigs.length) return '普通履约者'
  32. const config = this.levelConfigs.find(c => c.lvNo === this.profile.level)
  33. return config ? config.name : (this.profile.levelName || '普通履约者')
  34. }
  35. },
  36. onShow() {
  37. uni.hideTabBar()
  38. if (isLoggedIn()) {
  39. this.loadProfile()
  40. this.loadLevelConfigs()
  41. this.fetchCustomerServiceSetting()
  42. }
  43. },
  44. methods: {
  45. async loadProfile() {
  46. if (this.profileLoading) return
  47. this.profileLoading = true
  48. try {
  49. const res = await getMyProfile()
  50. this.profile = res.data || null
  51. } catch (err) {
  52. console.error('获取个人信息失败:', err)
  53. } finally {
  54. this.profileLoading = false
  55. }
  56. },
  57. async loadLevelConfigs() {
  58. try {
  59. const res = await listAllLevelConfigs()
  60. this.levelConfigs = res.data || []
  61. } catch (err) {
  62. console.error('加载等级配置失败:', err)
  63. }
  64. },
  65. async fetchCustomerServiceSetting() {
  66. try {
  67. const res = await getCustomerServiceSetting(1)
  68. if (res.code === 200 && res.data) {
  69. this.customerSetting = { ...this.customerSetting, ...res.data }
  70. }
  71. } catch (err) {
  72. console.error('获取客服配置失败:', err)
  73. }
  74. },
  75. navToSettings() {
  76. uni.navigateTo({
  77. url: '/pages/mine/settings/index'
  78. });
  79. },
  80. navToProfile() {
  81. uni.navigateTo({
  82. url: '/pages/mine/settings/profile/index'
  83. });
  84. },
  85. navToLevel() {
  86. uni.navigateTo({
  87. url: '/pages/mine/level/index'
  88. });
  89. },
  90. navToNotification() {
  91. uni.navigateTo({
  92. url: '/pages/mine/message/index'
  93. });
  94. },
  95. navToWallet() {
  96. uni.navigateTo({
  97. url: '/pages/mine/wallet/index'
  98. });
  99. },
  100. navToPoints() {
  101. uni.navigateTo({
  102. url: '/pages/mine/points/index'
  103. });
  104. },
  105. navToOrderStats() {
  106. uni.navigateTo({
  107. url: '/pages/mine/order-stats'
  108. });
  109. },
  110. navToRewards() {
  111. uni.navigateTo({
  112. url: '/pages/mine/rewards'
  113. });
  114. },
  115. openServicePopup() {
  116. this.showServicePopup = true;
  117. },
  118. closeServicePopup() {
  119. this.showServicePopup = false;
  120. },
  121. previewQRCode() {
  122. if (!this.customerSetting.qrCodeUrl) return;
  123. uni.previewImage({
  124. urls: [this.customerSetting.qrCodeUrl]
  125. });
  126. },
  127. openOnlineService() {
  128. // 如果有企业微信链接,则打开
  129. if (this.customerSetting.enterpriseWechatLink) {
  130. // #ifdef H5
  131. window.location.href = this.customerSetting.enterpriseWechatLink;
  132. // #endif
  133. // #ifndef H5
  134. uni.setClipboardData({
  135. data: this.customerSetting.wechatAccount || this.customerSetting.enterpriseWechatLink,
  136. success: () => {
  137. uni.showToast({ title: '链接已复制,请在浏览器或微信打开', icon: 'none' });
  138. }
  139. });
  140. // #endif
  141. } else {
  142. uni.showToast({
  143. title: '在线客服暂未配置',
  144. icon: 'none'
  145. });
  146. }
  147. },
  148. callServicePhone() {
  149. if (!this.customerSetting.phoneNumber) {
  150. uni.showToast({ title: '暂无联系电话', icon: 'none' });
  151. return;
  152. }
  153. uni.makePhoneCall({
  154. phoneNumber: this.customerSetting.phoneNumber
  155. });
  156. },
  157. logout() {
  158. this.showLogoutPopup = true;
  159. },
  160. cancelLogout() {
  161. this.showLogoutPopup = false;
  162. },
  163. async confirmLogout() {
  164. this.showLogoutPopup = false;
  165. try {
  166. await logoutApi()
  167. } catch (e) {
  168. // 即使后端退出失败,也清除本地登录态
  169. }
  170. clearAuth()
  171. uni.reLaunch({
  172. url: '/pages/login/login'
  173. });
  174. }
  175. }
  176. }