const api = require('../../utils/api'); Page({ data: { serviceId: '', detail: null, followups: [], followupTypes: ['followup', '需求了解', '候选建议', '活动协助', '其他'], loading: true, submitting: false, form: { followupType: 'followup', content: '', nextFollowupAt: '' }, }, onLoad(options) { const serviceId = options && options.id; if (!serviceId) { wx.showToast({ title: '服务记录不存在', icon: 'none' }); wx.navigateBack(); return; } this.setData({ serviceId }); this.loadDetail(); }, onShow() { if (this.data.serviceId && !this.data.loading) this.loadDetail(); }, tokenHeaders() { const token = wx.getStorageSync('operatorToken'); return token ? { Authorization: `Bearer ${token}` } : {}; }, async loadDetail() { this.setData({ loading: true }); try { const detail = await api.get(`/operator/matchmaker/services/${this.data.serviceId}`, {}, this.tokenHeaders()); this.setData({ detail: detail || null, followups: (detail && detail.followups) || [] }); } catch (error) { if (error && (error.code === 'FORBIDDEN' || error.code === 'NOT_FOUND' || error.code === 'DATA_SCOPE_DENIED')) { wx.showModal({ title: '服务权限已变更', content: '该服务对象已结束或不再属于当前服务范围。', showCancel: false, success: () => wx.navigateBack() }); } else { wx.showToast({ title: (error && error.message) || '加载失败', icon: 'none' }); } } finally { this.setData({ loading: false }); } }, onTypeChange(e) { this.setData({ 'form.followupType': this.data.followupTypes[Number(e.detail.value)] || 'followup' }); }, onContentInput(e) { this.setData({ 'form.content': e.detail.value }); }, onNextFollowupInput(e) { this.setData({ 'form.nextFollowupAt': e.detail.value }); }, async submitFollowup() { if (this.data.submitting) return; const content = (this.data.form.content || '').trim(); if (!content) { wx.showToast({ title: '请填写服务摘要', icon: 'none' }); return; } this.setData({ submitting: true }); try { await api.post(`/operator/matchmaker/services/${this.data.serviceId}/followup`, { followupType: this.data.form.followupType, content, nextFollowupAt: this.data.form.nextFollowupAt || undefined, }, this.tokenHeaders(), api.idempotencyKey('matchmaker-followup', this.data.serviceId)); wx.showToast({ title: '已记录服务', icon: 'success' }); this.setData({ 'form.content': '', 'form.nextFollowupAt': '' }); await this.loadDetail(); } catch (error) { wx.showToast({ title: (error && error.message) || '提交失败,请重试', icon: 'none' }); } finally { this.setData({ submitting: false }); } }, });