2026-09-10 16:06:11 +08:00
|
|
|
import { request } from '../../utils/requestPromise'
|
|
|
|
|
const app = getApp<{ globalData: { apiBase: string; token: string } }>()
|
2026-09-09 22:05:00 +08:00
|
|
|
Page({
|
|
|
|
|
data: {
|
2026-09-14 08:51:26 +08:00
|
|
|
services: [] as Array<{ type: string; name: string; description: string; iconAsset: string }>,
|
|
|
|
|
loading: true,
|
|
|
|
|
serviceEnabled: false,
|
|
|
|
|
disabledReason: '',
|
2026-09-09 22:05:00 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad() {
|
|
|
|
|
this.loadServices();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async loadServices() {
|
|
|
|
|
try {
|
2026-09-10 16:06:11 +08:00
|
|
|
const res = await request<any>({
|
2026-09-09 22:05:00 +08:00
|
|
|
url: `${app.globalData.apiBase}/counseling/services/intro`,
|
|
|
|
|
header: { 'Authorization': `Bearer ${app.globalData.token}` }
|
|
|
|
|
});
|
|
|
|
|
if (res.statusCode === 200 && res.data.success) {
|
2026-09-14 08:51:26 +08:00
|
|
|
const iconMap: Record<string, string> = {
|
|
|
|
|
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;
|
2026-09-09 22:05:00 +08:00
|
|
|
}
|
2026-09-14 08:51:26 +08:00
|
|
|
this.setData({ loading: false, serviceEnabled: false, disabledReason: res.data?.message || '服务暂不可用' });
|
2026-09-09 22:05:00 +08:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error('加载咨询介绍失败', e);
|
2026-09-14 08:51:26 +08:00
|
|
|
this.setData({ loading: false, serviceEnabled: false, disabledReason: '暂时无法获取服务状态' });
|
2026-09-09 22:05:00 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onSelectService(e: any) {
|
2026-09-14 08:51:26 +08:00
|
|
|
if (!this.data.serviceEnabled) {
|
|
|
|
|
wx.showToast({ title: this.data.disabledReason || '服务暂不可用', icon: 'none' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-09-09 22:05:00 +08:00
|
|
|
const type = e.currentTarget.dataset.type;
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: `/pages/counseling-request/counseling-request?type=${type}`
|
|
|
|
|
});
|
2026-09-14 08:51:26 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onBook() {
|
|
|
|
|
const type = this.data.services[0]?.type || 'relationship_guidance';
|
|
|
|
|
this.onSelectService({ currentTarget: { dataset: { type } } });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onMyServices() {
|
|
|
|
|
wx.navigateTo({ url: '/pages/my-counseling/my-counseling' });
|
2026-09-09 22:05:00 +08:00
|
|
|
}
|
|
|
|
|
});
|