2026-04-17 10:49:14 +08:00
|
|
|
const request = require('../../utils/request')
|
2026-05-18 14:24:55 +08:00
|
|
|
const { resolveImageUrl } = require('../../utils/media')
|
2026-04-17 10:49:14 +08:00
|
|
|
|
2026-06-28 13:56:56 +08:00
|
|
|
const EDUCATION_MAP = {
|
|
|
|
|
1: '高中',
|
|
|
|
|
2: '大专',
|
|
|
|
|
3: '本科',
|
|
|
|
|
4: '硕士',
|
|
|
|
|
5: '博士'
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-17 10:49:14 +08:00
|
|
|
Page({
|
|
|
|
|
data: {
|
2026-05-17 10:23:02 +08:00
|
|
|
activityId: null,
|
|
|
|
|
activeTab: 'my_choices',
|
|
|
|
|
activityTitle: '',
|
|
|
|
|
tabs: [
|
|
|
|
|
{ key: 'my_choices', label: '我的选择' },
|
|
|
|
|
{ key: 'liked_me', label: '谁选了我' },
|
|
|
|
|
{ key: 'mutual_matches', label: '匹配成功' }
|
|
|
|
|
],
|
|
|
|
|
matches: [],
|
2026-06-18 23:06:40 +08:00
|
|
|
loading: false,
|
|
|
|
|
cancelling: false
|
2026-05-17 10:23:02 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad(options) {
|
2026-05-21 10:50:48 +08:00
|
|
|
const storedEntry = wx.getStorageSync('match_entry_context') || {}
|
|
|
|
|
const activityId = options.activity_id
|
|
|
|
|
? Number(options.activity_id)
|
|
|
|
|
: storedEntry.activity_id
|
|
|
|
|
? Number(storedEntry.activity_id)
|
|
|
|
|
: null
|
|
|
|
|
|
2026-05-17 10:23:02 +08:00
|
|
|
this.setData({
|
2026-05-21 10:50:48 +08:00
|
|
|
activityId
|
2026-05-17 10:23:02 +08:00
|
|
|
})
|
2026-05-21 10:50:48 +08:00
|
|
|
|
|
|
|
|
if (storedEntry.activity_id) {
|
|
|
|
|
wx.removeStorageSync('match_entry_context')
|
|
|
|
|
}
|
2026-06-18 23:06:40 +08:00
|
|
|
|
|
|
|
|
if (activityId) {
|
|
|
|
|
this.loadActivityTitle(activityId)
|
|
|
|
|
}
|
2026-04-17 10:49:14 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
|
this.loadMatches()
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-18 23:06:40 +08:00
|
|
|
async loadActivityTitle(activityId) {
|
|
|
|
|
try {
|
|
|
|
|
const activity = await request({ url: `/activities/${activityId}` })
|
|
|
|
|
if (activity && activity.title) {
|
|
|
|
|
this.setData({ activityTitle: activity.title })
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.warn('Load activity title failed:', err)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-17 10:23:02 +08:00
|
|
|
switchTab(e) {
|
|
|
|
|
const tab = e.currentTarget.dataset.tab
|
|
|
|
|
if (!tab || tab === this.data.activeTab) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.setData({ activeTab: tab })
|
|
|
|
|
this.loadMatches()
|
|
|
|
|
},
|
|
|
|
|
|
2026-04-17 21:28:56 +08:00
|
|
|
normalizeMatch(item) {
|
2026-05-17 10:23:02 +08:00
|
|
|
const hobbies = Array.isArray(item.hobbies) ? item.hobbies : Array.isArray(item.other_user && item.other_user.hobbies) ? item.other_user.hobbies : []
|
2026-06-28 13:56:56 +08:00
|
|
|
const nickname = item.real_name || item.nickname || (item.other_user && (item.other_user.real_name || item.other_user.nickname)) || ''
|
2026-05-18 14:24:55 +08:00
|
|
|
const avatarUrl = resolveImageUrl(item.avatar_url || (item.other_user && item.other_user.avatar_url) || '')
|
2026-05-17 10:23:02 +08:00
|
|
|
const city = item.city || (item.other_user && item.other_user.city) || ''
|
2026-06-28 13:56:56 +08:00
|
|
|
const educationRaw = item.education || (item.other_user && item.other_user.education) || ''
|
|
|
|
|
const education = EDUCATION_MAP[educationRaw] || ''
|
2026-04-17 21:28:56 +08:00
|
|
|
const statusMap = {
|
|
|
|
|
success: { text: '匹配成功', statusClass: 'success-badge', itemClass: 'success-item' },
|
2026-05-17 10:23:02 +08:00
|
|
|
pending: { text: '待回应', statusClass: 'pending-badge', itemClass: 'pending-item' }
|
2026-04-17 21:28:56 +08:00
|
|
|
}
|
2026-05-17 10:23:02 +08:00
|
|
|
const matchStatus = item.match_status || 'pending'
|
2026-04-17 21:28:56 +08:00
|
|
|
const statusConfig = statusMap[matchStatus] || statusMap.pending
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
|
|
|
|
match_status: matchStatus,
|
|
|
|
|
match_status_text: item.match_status_text || statusConfig.text,
|
|
|
|
|
match_status_class: statusConfig.statusClass,
|
|
|
|
|
match_item_class: statusConfig.itemClass,
|
2026-05-17 10:23:02 +08:00
|
|
|
nicknameText: nickname || '匿名用户',
|
|
|
|
|
avatar_url: avatarUrl,
|
|
|
|
|
cityText: city || '城市未知',
|
|
|
|
|
educationText: education || '学历未知',
|
|
|
|
|
hobbiesText: hobbies.length ? hobbies.join('、') : '未填写爱好',
|
|
|
|
|
timeText: item.matched_at || item.selected_at || ''
|
2026-04-17 21:28:56 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2026-04-17 10:49:14 +08:00
|
|
|
async loadMatches() {
|
2026-05-17 10:23:02 +08:00
|
|
|
this.setData({ loading: true })
|
2026-04-17 10:49:14 +08:00
|
|
|
try {
|
2026-05-17 10:23:02 +08:00
|
|
|
let remoteMatches = []
|
|
|
|
|
if (this.data.activityId) {
|
|
|
|
|
const endpointMap = {
|
|
|
|
|
my_choices: 'my-choices',
|
|
|
|
|
liked_me: 'liked-me',
|
|
|
|
|
mutual_matches: 'mutual-matches'
|
|
|
|
|
}
|
|
|
|
|
remoteMatches = await request({ url: `/activities/${this.data.activityId}/${endpointMap[this.data.activeTab]}` })
|
|
|
|
|
} else {
|
|
|
|
|
remoteMatches = await request({ url: '/matches/my' })
|
2026-04-17 21:28:56 +08:00
|
|
|
}
|
2026-05-17 10:23:02 +08:00
|
|
|
const normalizedMatches = Array.isArray(remoteMatches) ? remoteMatches.map((item) => this.normalizeMatch(item)) : []
|
|
|
|
|
this.setData({ matches: normalizedMatches })
|
2026-04-17 10:49:14 +08:00
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Load my matches failed:', err)
|
2026-05-17 10:23:02 +08:00
|
|
|
wx.showToast({ title: err.message || '加载失败', icon: 'none' })
|
|
|
|
|
this.setData({ matches: [] })
|
|
|
|
|
} finally {
|
|
|
|
|
this.setData({ loading: false })
|
2026-04-17 10:49:14 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
viewDetail(e) {
|
2026-05-17 10:23:02 +08:00
|
|
|
const userId = e.currentTarget.dataset.userId
|
2026-04-17 21:28:56 +08:00
|
|
|
const status = e.currentTarget.dataset.status
|
2026-05-17 10:23:02 +08:00
|
|
|
if (!userId) {
|
2026-04-17 10:49:14 +08:00
|
|
|
return
|
|
|
|
|
}
|
2026-05-17 10:23:02 +08:00
|
|
|
if (status !== 'success') {
|
|
|
|
|
wx.showToast({ title: '互选成功后才可查看完整资料', icon: 'none' })
|
2026-04-17 21:28:56 +08:00
|
|
|
return
|
|
|
|
|
}
|
2026-05-17 10:23:02 +08:00
|
|
|
if (this.data.activityId) {
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: `/pages/match-detail/match-detail?activity_id=${this.data.activityId}&target_user_id=${userId}`
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-06-18 23:06:40 +08:00
|
|
|
const match = this.data.matches.find((item) => item.userId === userId)
|
|
|
|
|
if (match && match.matchId) {
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: `/pages/match-detail/match-detail?match_id=${match.matchId}`
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
wx.showToast({ title: '无法获取匹配详情', icon: 'none' })
|
|
|
|
|
}
|
2026-05-17 10:23:02 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async cancelChoice(e) {
|
|
|
|
|
const userId = e.currentTarget.dataset.userId
|
2026-06-18 23:06:40 +08:00
|
|
|
if (!this.data.activityId || !userId || this.data.cancelling) {
|
2026-05-17 10:23:02 +08:00
|
|
|
return
|
|
|
|
|
}
|
2026-06-18 23:06:40 +08:00
|
|
|
this.setData({ cancelling: true })
|
2026-05-17 10:23:02 +08:00
|
|
|
try {
|
|
|
|
|
await request({
|
|
|
|
|
url: `/activities/${this.data.activityId}/choices/${userId}`,
|
|
|
|
|
method: 'DELETE'
|
|
|
|
|
})
|
|
|
|
|
wx.showToast({ title: '已撤销选择', icon: 'success' })
|
|
|
|
|
this.loadMatches()
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Cancel choice failed:', err)
|
|
|
|
|
wx.showToast({ title: err.message || '撤销失败', icon: 'none' })
|
2026-06-18 23:06:40 +08:00
|
|
|
} finally {
|
|
|
|
|
this.setData({ cancelling: false })
|
2026-05-17 10:23:02 +08:00
|
|
|
}
|
2026-04-17 10:49:14 +08:00
|
|
|
}
|
|
|
|
|
})
|