import { logout as logoutApi } from '@/api/auth' import { getMyProfile } from '@/api/fulfiller/fulfiller' import { listAllLevelConfigs } from '@/api/fulfiller/levelConfig' import { getCustomerServiceSetting } from '@/api/system/customerServiceSetting' import { clearAuth, isLoggedIn } from '@/utils/auth' import customTabbar from '@/components/custom-tabbar/index.vue' export default { components: { customTabbar }, data() { return { showServicePopup: false, showLogoutPopup: false, profile: null, profileLoading: false, levelConfigs: [], // 等级配置列表 customerSetting: { wechatAccount: '', phoneNumber: '400-123-4567', qrCodeUrl: '/static/logo.png', enterpriseWechatLink: '', startServiceTime: '', endServiceTime: '' } } }, computed: { // 根据 profile.level 匹配对应的等级名称 displayLevelName() { if (!this.profile || !this.levelConfigs.length) return '普通履约者' const config = this.levelConfigs.find(c => c.lvNo === this.profile.level) return config ? config.name : (this.profile.levelName || '普通履约者') } }, onShow() { uni.hideTabBar() if (isLoggedIn()) { this.loadProfile() this.loadLevelConfigs() this.fetchCustomerServiceSetting() } }, methods: { async loadProfile() { if (this.profileLoading) return this.profileLoading = true try { const res = await getMyProfile() this.profile = res.data || null } catch (err) { console.error('获取个人信息失败:', err) } finally { this.profileLoading = false } }, async loadLevelConfigs() { try { const res = await listAllLevelConfigs() this.levelConfigs = res.data || [] } catch (err) { console.error('加载等级配置失败:', err) } }, async fetchCustomerServiceSetting() { try { const res = await getCustomerServiceSetting(1) if (res.code === 200 && res.data) { this.customerSetting = { ...this.customerSetting, ...res.data } } } catch (err) { console.error('获取客服配置失败:', err) } }, navToSettings() { uni.navigateTo({ url: '/pages/mine/settings/index' }); }, navToProfile() { uni.navigateTo({ url: '/pages/mine/settings/profile/index' }); }, navToLevel() { uni.navigateTo({ url: '/pages/mine/level/index' }); }, navToNotification() { uni.navigateTo({ url: '/pages/mine/message/index' }); }, navToWallet() { uni.navigateTo({ url: '/pages/mine/wallet/index' }); }, navToPoints() { uni.navigateTo({ url: '/pages/mine/points/index' }); }, navToOrderStats() { uni.navigateTo({ url: '/pages/mine/order-stats' }); }, navToRewards() { uni.navigateTo({ url: '/pages/mine/rewards' }); }, openServicePopup() { this.showServicePopup = true; }, closeServicePopup() { this.showServicePopup = false; }, previewQRCode() { if (!this.customerSetting.qrCodeUrl) return; uni.previewImage({ urls: [this.customerSetting.qrCodeUrl] }); }, openOnlineService() { // 如果有企业微信链接,则打开 if (this.customerSetting.enterpriseWechatLink) { // #ifdef H5 window.location.href = this.customerSetting.enterpriseWechatLink; // #endif // #ifndef H5 uni.setClipboardData({ data: this.customerSetting.wechatAccount || this.customerSetting.enterpriseWechatLink, success: () => { uni.showToast({ title: '链接已复制,请在浏览器或微信打开', icon: 'none' }); } }); // #endif } else { uni.showToast({ title: '在线客服暂未配置', icon: 'none' }); } }, callServicePhone() { if (!this.customerSetting.phoneNumber) { uni.showToast({ title: '暂无联系电话', icon: 'none' }); return; } uni.makePhoneCall({ phoneNumber: this.customerSetting.phoneNumber }); }, logout() { this.showLogoutPopup = true; }, cancelLogout() { this.showLogoutPopup = false; }, async confirmLogout() { this.showLogoutPopup = false; try { await logoutApi() } catch (e) { // 即使后端退出失败,也清除本地登录态 } clearAuth() uni.reLaunch({ url: '/pages/login/login' }); } } }