Files
danyang-match/miniapp/pages/matchmaker-recommendations/matchmaker-recommendations.js
T
WorkBuddy 8b505d9133
CI/CD Pipeline / Test Shell Guard (Phase 23 Gate) (push) Canceled after 0s
CI/CD Pipeline / Backend Build & Test (push) Canceled after 0s
CI/CD Pipeline / Admin Web Build (push) Canceled after 0s
CI/CD Pipeline / Mini Program Compile Check (push) Canceled after 0s
CI/CD Pipeline / Migration Validation (push) Canceled after 0s
CI/CD Pipeline / UI Contracts (source-structure gates) (push) Canceled after 0s
CI/CD Pipeline / E2E (live stack) (push) Canceled after 0s
feat: disable user messaging and retain公益 service guidance
2026-10-15 13:38:17 +08:00

64 lines
2.2 KiB
JavaScript

const { matchmakerStore, matchStore, appStore } = require('../../stores');
const { matchmakerService } = require('../../services');
const { ROUTE, to } = require('../../constants');
Page({
data: { loading: true, actionLoadingId: '', recommendations: [] },
onShow() { this.load(); },
async load() {
this.setData({ loading: true });
try {
const result = await matchmakerStore.fetchRecommendations();
const items = (result && Array.isArray(result) ? result : matchmakerStore.state.recommendations || [])
.map((item) => ({
...item,
userId: item.userId || item.targetUserId,
displayName: item.displayName || '红娘推荐对象',
recommendationReasons: item.reason ? [item.reason] : [],
}));
this.setData({ recommendations: items, loading: false });
items.filter((item) => item.status === 'pending_view' && item.id).forEach((item) => {
matchmakerService.markRecommendationViewed(item.id).catch(() => {});
});
} catch (error) {
this.setData({ loading: false });
appStore.toastError(error, '加载红娘推荐失败');
}
},
onView(e) {
const userId = e.detail && e.detail.userId;
if (userId) wx.navigateTo({ url: to.detail(userId) });
},
async onLike(e) {
await this.respond(e.detail && e.detail.userId, 'like');
},
async onPass(e) {
await this.respond(e.detail && e.detail.userId, 'pass');
},
async respond(userId, action) {
if (!userId || this.data.actionLoadingId) return;
this.setData({ actionLoadingId: userId });
try {
const result = action === 'like' ? await matchStore.like(userId) : await matchStore.pass(userId);
this.setData({ recommendations: this.data.recommendations.filter((item) => item.userId !== userId) });
if (action === 'like' && result && result.mutualMatch) {
appStore.toastSuccess('双向意向匹配成功,可查看公益服务');
} else {
appStore.toastSuccess(action === 'like' ? '已表达喜欢' : '已暂不考虑');
}
} catch (error) {
appStore.toastError(error);
} finally {
this.setData({ actionLoadingId: '' });
}
},
onBack() { wx.navigateBack(); },
});