53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
import { request } from '../../utils/requestPromise'
|
|
|
|
const app = getApp<{ globalData: { apiBase: string; token: string } }>()
|
|
|
|
Page({
|
|
data: {
|
|
topics: [
|
|
{ title: '沟通与期望', description: '表达需求、倾听差异,形成共同约定', iconAsset: '/assets/icons/home/counseling.png' },
|
|
{ title: '家庭与责任', description: '讨论家庭角色与双方家庭关系', iconAsset: '/assets/icons/home/premarital.png' },
|
|
{ title: '财务与规划', description: '了解消费习惯并讨论未来安排', iconAsset: '/assets/icons/home/classroom.png' },
|
|
{ title: '冲突与修复', description: '学习处理分歧并建立修复方式', iconAsset: '/assets/icons/home/anti-fraud.png' },
|
|
],
|
|
loading: true,
|
|
serviceEnabled: false,
|
|
disabledReason: '',
|
|
},
|
|
|
|
onLoad() {
|
|
this.loadAvailability()
|
|
},
|
|
|
|
async loadAvailability() {
|
|
try {
|
|
const res = await request<any>({
|
|
url: `${app.globalData.apiBase}/counseling/services/intro`,
|
|
header: { Authorization: `Bearer ${app.globalData.token}` },
|
|
})
|
|
const services = res.statusCode === 200 && res.data.success ? (res.data.data || []) : []
|
|
const serviceEnabled = services.some((item: any) => item.type === 'premarital_guidance')
|
|
this.setData({
|
|
loading: false,
|
|
serviceEnabled,
|
|
disabledReason: serviceEnabled ? '' : (res.data?.message || '服务暂不可用'),
|
|
})
|
|
} catch (error) {
|
|
console.error('加载婚前辅导服务状态失败', error)
|
|
this.setData({ loading: false, serviceEnabled: false, disabledReason: '暂时无法获取服务状态' })
|
|
}
|
|
},
|
|
|
|
onApply() {
|
|
if (!this.data.serviceEnabled) {
|
|
wx.showToast({ title: this.data.disabledReason || '服务暂不可用', icon: 'none' })
|
|
return
|
|
}
|
|
wx.navigateTo({ url: '/pages/premarital-request/premarital-request?type=premarital_guidance' })
|
|
},
|
|
|
|
onMyServices() {
|
|
wx.navigateTo({ url: '/pages/my-counseling/my-counseling' })
|
|
},
|
|
})
|