/** * 公益红娘服务页 U33 * * 重构要点(遵循 AGENTS.md 不变量): * - 数据:MatchmakerStore.fetchMyServices + activeService 派生 * - 展示:ui-matchmaker-card 展示当前进行中的服务,"查看红娘推荐"按钮触发跳转 * - 申请:跳转 matchmaker-apply 页,不在本页填写(AGENTS 第 1 条:用户永久免费) * - 推荐:红娘推荐列表跳 fate-center 页(AGENTS 第 5 条:红娘不可替用户操作) */ import { matchmakerStore, appStore } from '../../stores'; import { ROUTE, to, buildPath, MATCHMAKER_SERVICE_STATUS, MATCHMAKER_SERVICE_STATUS_LABEL } from '../../constants'; Page({ data: { statusBarHeight: 20, navBarHeight: 44, loading: false, firstLoaded: false, activeService: null as any, historyServices: [] as any[], showRecommendations: false, capabilities: [ '推荐合适对象(基于你的择偶条件)', '调整择偶条件的专业建议', '协助联系你感兴趣的意向对象', '推荐参加合适的相亲活动', '聊天沟通的方法指导', ], emptyActions: [{ text: '申请红娘帮助', event: 'apply', variant: 'primary' }], }, onLoad() { try { const sysInfo = wx.getSystemInfoSync ? wx.getSystemInfoSync() : null; if (sysInfo) { this.setData({ statusBarHeight: sysInfo.statusBarHeight || 20, navBarHeight: 44 }); } } catch (e) { /* 默认值 */ } (this as any)._unsub = matchmakerStore.bindToPage(this, { activeService: 'activeService' }); this.fetchServices(); }, onShow() { if (this.data.firstLoaded) this.fetchServices(); }, onUnload() { if ((this as any)._unsub) (this as any)._unsub(); }, async fetchServices() { if (this.data.loading) return; this.setData({ loading: true }); try { await matchmakerStore.fetchMyServices(); const { activeService, myServices } = matchmakerStore.state; const showRecommendations = !!activeService && ( activeService.status === MATCHMAKER_SERVICE_STATUS.IN_SERVICE || activeService.status === MATCHMAKER_SERVICE_STATUS.WAITING_USER ); const withStatusText = (s: any) => ({ ...s, statusText: MATCHMAKER_SERVICE_STATUS_LABEL[s.status] || s.statusText || s.status || '', }) const historyServices = (activeService ? myServices.filter((s: any) => s.serviceId !== activeService.serviceId) : myServices).map(withStatusText) const activeServiceWithText = activeService ? { ...activeService, statusText: MATCHMAKER_SERVICE_STATUS_LABEL[activeService.status] || activeService.statusText || activeService.status || '' } : null this.setData({ loading: false, firstLoaded: true, activeService: activeServiceWithText, historyServices, showRecommendations }); } catch (err: any) { this.setData({ loading: false, firstLoaded: true }); appStore.toastError(err, '加载红娘服务失败'); } }, onBack() { wx.navigateBack(); }, onApplyService() { wx.navigateTo({ url: ROUTE.DETAIL.MATCHMAKER_APPLY }); }, onViewService(e: any) { const serviceId = e.detail.serviceId; if (!serviceId) return; wx.navigateTo({ url: to.matchmakerProgress(serviceId) }); }, onViewRecommendations(e: any) { const serviceId = e.detail.serviceId; if (!serviceId) return; wx.navigateTo({ url: buildPath(ROUTE.MAIN.FATE_CENTER, { id: serviceId }) }); }, onHistoryTap(e: any) { const serviceId = e.currentTarget.dataset.serviceId; if (!serviceId) return; wx.navigateTo({ url: to.matchmakerProgress(serviceId) }); }, onEmptyAction(e: any) { if (e.detail.event === 'apply') this.onApplyService(); }, });