/** * 联系授权确认页(C 端用户,ZC-MM-003 / B1 例外通道) * * PIPL 单独同意契约: * - 授权目的 / 渠道 / 有效期窗口逐条明示后才可操作; * - 同意与拒绝是两个独立按钮,无预勾选、无捆绑(后端亦为独立 POST 端点, * 守卫 MatchmakerContactGuardTest ④ 锁定); * - 数据源 GET /contact-authorizations/my(pendingConsent 待同意队列 + 全部记录)。 */ const api = require('../../utils/api'); const CHANNEL_LABELS = { phone: '电话联系', offline_meeting: '线下见面', full_contact: '完整联系方式', }; Page({ data: { loading: true, pendingConsent: [], history: [], }, onShow() { this.loadAuthorizations(); }, async loadAuthorizations() { this.setData({ loading: true }); try { const res = await api.get('/contact-authorizations/my'); if (res.success) { const pending = (res.data.pendingConsent || []).map((item) => this.decorate(item)); const history = (res.data.list || []).map((item) => this.decorate(item)); this.setData({ pendingConsent: pending, history }); } } catch (err) { console.error('加载联系授权失败:', err); } finally { this.setData({ loading: false }); } }, /** 渠道/状态/有效期 → 中文展示(枚举码不上屏) */ decorate(item) { const labels = { pending_approval: '待审批', pending_consent: '待你确认', active: '生效中', rejected: '已拒绝', expired: '已过期', revoked: '已撤销', }; return Object.assign({}, item, { channelLabel: CHANNEL_LABELS[item.channel] || item.channel, statusLabel: labels[item.status] || item.status, expireText: item.expiresAt ? this.formatTime(item.expiresAt) : '', }); }, formatTime(timeStr) { if (!timeStr) return ''; const d = new Date(timeStr); return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()} ${d.getHours()}:${String(d.getMinutes()).padStart(2, '0')}`; }, /** 独立同意(单独明示动作,无捆绑参数) */ async onConsent(e) { const id = e.currentTarget.dataset.id; const item = this.data.pendingConsent.find((a) => a.id === id); if (!item) return; wx.showModal({ title: '确认同意联系授权', content: `同意「${item.channelLabel}」:${item.purpose}。同意后红娘可在有效期内通过该方式联系你。`, confirmText: '同意', cancelText: '再想想', success: async (res) => { if (!res.confirm) return; try { const resp = await api.post(`/contact-authorizations/${id}/consent`); if (resp.success) { wx.showToast({ title: '已同意', icon: 'success' }); this.loadAuthorizations(); } } catch (err) { wx.showToast({ title: '操作失败', icon: 'none' }); } }, }); }, /** 独立拒绝 */ async onDecline(e) { const id = e.currentTarget.dataset.id; try { const resp = await api.post(`/contact-authorizations/${id}/decline`); if (resp.success) { wx.showToast({ title: '已拒绝', icon: 'none' }); this.loadAuthorizations(); } } catch (err) { wx.showToast({ title: '操作失败', icon: 'none' }); } }, });