const { referralService } = require('../../services'); const STATUS_LABEL = { submitted: '待您确认', pending_confirmation: '待您确认', confirmed: '已确认', cancelled: '已取消', completed: '已完成', }; Page({ data: { loading: true, error: '', referrals: [], confirmingId: '' }, onShow() { this.load(); }, async load() { this.setData({ loading: true, error: '' }); try { const list = await referralService.getMyReferralHistory(); this.setData({ referrals: (list || []).map((item) => ({ id: item.id, referralDisplayId: item.referralDisplayId, targetType: item.type, title: item.type === 'activity' ? '公益活动转介' : '服务站转介', detail: item.type === 'activity' ? (item.activityDisplayId || '公益活动') : (item.serviceType || '公益服务'), status: item.userConfirmedAt ? 'confirmed' : (item.status || 'pending_confirmation'), statusText: item.userConfirmedAt ? '已确认' : (STATUS_LABEL[item.status] || '待您确认'), createdAt: item.createdAt || item.registeredAt || '', })), loading: false, }); } catch (error) { this.setData({ loading: false, error: (error && error.message) || '加载失败,请稍后重试' }); } }, async confirm(e) { const item = this.data.referrals[Number(e.currentTarget.dataset.index)]; if (!item || item.status === 'confirmed' || this.data.confirmingId) return; this.setData({ confirmingId: item.id }); try { await referralService.confirmReferral(item.id, item.targetType); wx.showToast({ title: '已确认', icon: 'success' }); await this.load(); } catch (error) { wx.showToast({ title: (error && error.message) || '确认失败,请重试', icon: 'none' }); } finally { this.setData({ confirmingId: '' }); } }, });