import { request } from '../../utils/requestPromise' const app = getApp<{ globalData: { apiBase: string; token: string } }>() Page({ data: { services: [] as Array<{ type: string; name: string; description: string; iconAsset: string }>, loading: true, serviceEnabled: false, disabledReason: '', }, onLoad() { this.loadServices(); }, async loadServices() { try { const res = await request({ url: `${app.globalData.apiBase}/counseling/services/intro`, header: { 'Authorization': `Bearer ${app.globalData.token}` } }); if (res.statusCode === 200 && res.data.success) { const iconMap: Record = { relationship_guidance: '/assets/icons/home/counseling.png', emotional_support: '/assets/icons/home/matchmaker.png', premarital_guidance: '/assets/icons/home/premarital.png', anti_fraud_guidance: '/assets/icons/home/anti-fraud.png', }; this.setData({ services: (res.data.data || []).map((item: any) => ({ ...item, iconAsset: iconMap[item.type] || '/assets/icons/home/counseling.png', })), loading: false, serviceEnabled: true, }); return; } this.setData({ loading: false, serviceEnabled: false, disabledReason: res.data?.message || '服务暂不可用' }); } catch (e) { console.error('加载咨询介绍失败', e); this.setData({ loading: false, serviceEnabled: false, disabledReason: '暂时无法获取服务状态' }); } }, onSelectService(e: any) { if (!this.data.serviceEnabled) { wx.showToast({ title: this.data.disabledReason || '服务暂不可用', icon: 'none' }); return; } const type = e.currentTarget.dataset.type; wx.navigateTo({ url: `/pages/counseling-request/counseling-request?type=${type}` }); }, onBook() { const type = this.data.services[0]?.type || 'relationship_guidance'; this.onSelectService({ currentTarget: { dataset: { type } } }); }, onMyServices() { wx.navigateTo({ url: '/pages/my-counseling/my-counseling' }); } });