137 lines
5.8 KiB
JavaScript
137 lines
5.8 KiB
JavaScript
/**
|
||
* Soul创业派对 - 超级个体/会员详情页
|
||
* 接口:优先 /api/miniprogram/vip/members?id=xx(VIP),回退 /api/miniprogram/users?id=xx(任意用户)
|
||
* 字段映射:name/vipName, avatar/vipAvatar, contact/vipContact/phone, wechatId, project/vipProject/projectIntro,
|
||
* mbti, region, industry, position, businessScale, skills,
|
||
* storyBestMonth→bestMonth, storyAchievement→achievement, storyTurning→turningPoint,
|
||
* helpOffer→canHelp, helpNeed→needHelp
|
||
*/
|
||
const app = getApp()
|
||
|
||
Page({
|
||
data: { statusBarHeight: 44, member: null, loading: true },
|
||
|
||
onLoad(options) {
|
||
wx.showShareMenu({ withShareTimeline: true })
|
||
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
|
||
if (options.id) this.loadMember(options.id)
|
||
},
|
||
|
||
async loadMember(id) {
|
||
try {
|
||
const res = await app.request({ url: `/api/miniprogram/vip/members?id=${id}`, silent: true })
|
||
if (res?.success && res.data) {
|
||
const d = Array.isArray(res.data) ? res.data[0] : res.data
|
||
if (d) { this.setData({ member: this.enrichAndFormat(d), loading: false }); return }
|
||
}
|
||
} catch (e) {}
|
||
|
||
try {
|
||
const dbRes = await app.request({ url: `/api/miniprogram/users?id=${id}`, silent: true })
|
||
if (dbRes?.success && dbRes.data) {
|
||
const u = Array.isArray(dbRes.data) ? dbRes.data[0] : dbRes.data
|
||
if (u) {
|
||
this.setData({ member: this.enrichAndFormat({
|
||
id: u.id, name: u.vipName || u.vip_name || u.nickname || '创业者',
|
||
avatar: u.vipAvatar || u.vip_avatar || u.avatar || '', isVip: !!(u.is_vip),
|
||
contactRaw: u.vipContact || u.vip_contact || u.phone || '',
|
||
wechatId: u.wechatId || u.wechat_id,
|
||
project: u.vipProject || u.vip_project || u.projectIntro || u.project_intro || '',
|
||
industry: u.industry, position: u.position, businessScale: u.businessScale || u.business_scale,
|
||
skills: u.skills, mbti: u.mbti, region: u.region,
|
||
storyBestMonth: u.storyBestMonth || u.story_best_month,
|
||
storyAchievement: u.storyAchievement || u.story_achievement,
|
||
storyTurning: u.storyTurning || u.story_turning,
|
||
helpOffer: u.helpOffer || u.help_offer,
|
||
helpNeed: u.helpNeed || u.help_need,
|
||
}), loading: false })
|
||
return
|
||
}
|
||
}
|
||
} catch (e) {}
|
||
this.setData({ loading: false })
|
||
},
|
||
|
||
// 将空值、「未填写」、纯空格均视为未填写(用于隐藏对应项)
|
||
_emptyIfPlaceholder(v) {
|
||
if (v == null || v === undefined) return ''
|
||
const s = String(v).trim()
|
||
return (s === '' || s === '未填写') ? '' : s
|
||
},
|
||
|
||
enrichAndFormat(raw) {
|
||
const e = (v) => this._emptyIfPlaceholder(v)
|
||
const merged = {
|
||
id: raw.id,
|
||
name: raw.name || raw.vipName || raw.vip_name || raw.nickname || '创业者',
|
||
avatar: raw.avatar || raw.vipAvatar || raw.vip_avatar || '',
|
||
isVip: !!(raw.isVip || raw.is_vip),
|
||
mbti: e(raw.mbti),
|
||
region: e(raw.region),
|
||
industry: e(raw.industry),
|
||
position: e(raw.position),
|
||
businessScale: e(raw.businessScale || raw.business_scale),
|
||
skills: e(raw.skills),
|
||
contactRaw: raw.contactRaw || raw.vipContact || raw.vip_contact || raw.phone || '',
|
||
wechatRaw: raw.wechatRaw || raw.wechatId || raw.wechat_id || '',
|
||
bestMonth: e(raw.bestMonth || raw.storyBestMonth || raw.story_best_month),
|
||
achievement: e(raw.achievement || raw.storyAchievement || raw.story_achievement),
|
||
turningPoint: e(raw.turningPoint || raw.storyTurning || raw.story_turning),
|
||
canHelp: e(raw.canHelp || raw.helpOffer || raw.help_offer),
|
||
needHelp: e(raw.needHelp || raw.helpNeed || raw.help_need),
|
||
project: e(raw.project || raw.vipProject || raw.vip_project || raw.projectIntro || raw.project_intro)
|
||
}
|
||
|
||
const contact = merged.contactRaw || ''
|
||
const wechat = merged.wechatRaw || ''
|
||
const isMatched = (app.globalData.matchedUsers || []).includes(merged.id)
|
||
merged.contactDisplay = contact ? (contact.slice(0, 3) + '****' + (contact.length > 7 ? contact.slice(-2) : '')) : ''
|
||
merged.contactUnlocked = isMatched
|
||
merged.contactFull = contact
|
||
merged.wechatDisplay = wechat ? (wechat.slice(0, 4) + '****' + (wechat.length > 8 ? wechat.slice(-3) : '')) : ''
|
||
merged.wechatUnlocked = isMatched
|
||
merged.wechatFull = wechat
|
||
return merged
|
||
},
|
||
|
||
unlockContact() {
|
||
wx.showModal({
|
||
title: '解锁完整联系方式', content: '成为VIP会员并完成匹配后,即可查看完整联系方式',
|
||
confirmText: '去匹配', cancelText: '知道了',
|
||
success: (res) => { if (res.confirm) wx.switchTab({ url: '/pages/match/match' }) }
|
||
})
|
||
},
|
||
|
||
copyContact() {
|
||
const c = this.data.member?.contactFull
|
||
if (!c) return
|
||
wx.setClipboardData({ data: c, success: () => wx.showToast({ title: '已复制', icon: 'success' }) })
|
||
},
|
||
|
||
copyWechat() {
|
||
const w = this.data.member?.wechatFull
|
||
if (!w) return
|
||
wx.setClipboardData({ data: w, success: () => wx.showToast({ title: '已复制', icon: 'success' }) })
|
||
},
|
||
|
||
goToMatch() { wx.switchTab({ url: '/pages/match/match' }) },
|
||
goToVip() { wx.navigateTo({ url: '/pages/vip/vip' }) },
|
||
goBack() { wx.navigateBack() },
|
||
|
||
onShareAppMessage() {
|
||
const ref = app.getMyReferralCode()
|
||
const id = this.data.member?.id
|
||
return {
|
||
title: 'Soul创业派对 - 创业者详情',
|
||
path: id && ref ? `/pages/member-detail/member-detail?id=${id}&ref=${ref}` : id ? `/pages/member-detail/member-detail?id=${id}` : ref ? `/pages/member-detail/member-detail?ref=${ref}` : '/pages/member-detail/member-detail'
|
||
}
|
||
},
|
||
|
||
onShareTimeline() {
|
||
const ref = app.getMyReferralCode()
|
||
const id = this.data.member?.id
|
||
const q = id ? (ref ? `id=${id}&ref=${ref}` : `id=${id}`) : (ref ? `ref=${ref}` : '')
|
||
return { title: 'Soul创业派对 - 创业者详情', query: q }
|
||
}
|
||
})
|