2026-02-23 14:07:41 +08:00
|
|
|
|
const app = getApp()
|
|
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
|
data: {
|
|
|
|
|
|
statusBarHeight: 44,
|
|
|
|
|
|
isVip: false,
|
|
|
|
|
|
daysRemaining: 0,
|
|
|
|
|
|
expireDateStr: '',
|
|
|
|
|
|
price: 1980,
|
2026-02-24 14:35:58 +08:00
|
|
|
|
originalPrice: 6980,
|
2026-02-28 15:16:23 +08:00
|
|
|
|
/* 按 premium_membership_landing_v1 设计稿 */
|
2026-02-24 14:35:58 +08:00
|
|
|
|
contentRights: [
|
2026-02-28 15:16:23 +08:00
|
|
|
|
{ title: '解锁全部章节', desc: '365天全案精读', icon: '📖' },
|
|
|
|
|
|
{ title: '案例库', desc: '100+创业实战案例', icon: '📚' },
|
|
|
|
|
|
{ title: '智能纪要', desc: 'AI每日精华推送', icon: '💡' },
|
|
|
|
|
|
{ title: '会议纪要库', desc: '往期完整沉淀', icon: '📁' }
|
2026-02-24 14:35:58 +08:00
|
|
|
|
],
|
|
|
|
|
|
socialRights: [
|
2026-02-28 15:16:23 +08:00
|
|
|
|
{ title: '匹配创业伙伴', desc: '精准人脉匹配', icon: '👥' },
|
|
|
|
|
|
{ title: '创业老板排行', desc: '项目曝光展示', icon: '📊' },
|
|
|
|
|
|
{ title: '链接资源', desc: '深度私域资源池', icon: '🔗' },
|
|
|
|
|
|
{ title: '专属VIP标识', desc: '金色尊享光圈', icon: '✓' }
|
2026-02-24 14:35:58 +08:00
|
|
|
|
],
|
2026-02-27 14:22:58 +08:00
|
|
|
|
profile: { vipName: '', vipProject: '', vipContact: '', vipAvatar: '', vipBio: '' },
|
2026-02-23 14:07:41 +08:00
|
|
|
|
purchasing: false
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onLoad() {
|
2026-02-27 14:22:58 +08:00
|
|
|
|
wx.showShareMenu({ withShareTimeline: true })
|
2026-02-23 14:07:41 +08:00
|
|
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
|
|
|
|
|
|
this.loadVipInfo()
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async loadVipInfo() {
|
|
|
|
|
|
const userId = app.globalData.userInfo?.id
|
|
|
|
|
|
if (!userId) return
|
|
|
|
|
|
try {
|
2026-02-25 11:50:07 +08:00
|
|
|
|
const res = await app.request({ url: `/api/miniprogram/vip/status?userId=${userId}`, silent: true })
|
2026-02-23 14:07:41 +08:00
|
|
|
|
if (res?.success) {
|
|
|
|
|
|
const d = res.data
|
|
|
|
|
|
let expStr = ''
|
|
|
|
|
|
if (d.expireDate) {
|
|
|
|
|
|
const dt = new Date(d.expireDate)
|
|
|
|
|
|
expStr = `${dt.getFullYear()}-${String(dt.getMonth()+1).padStart(2,'0')}-${String(dt.getDate()).padStart(2,'0')}`
|
|
|
|
|
|
}
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
isVip: d.isVip,
|
|
|
|
|
|
daysRemaining: d.daysRemaining,
|
|
|
|
|
|
expireDateStr: expStr,
|
2026-02-24 14:35:58 +08:00
|
|
|
|
price: d.price || 1980
|
2026-02-23 14:07:41 +08:00
|
|
|
|
})
|
|
|
|
|
|
if (d.isVip) this.loadProfile(userId)
|
|
|
|
|
|
}
|
2026-02-24 14:35:58 +08:00
|
|
|
|
} catch (e) { console.log('[VIP] 加载失败', e) }
|
2026-02-23 14:07:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async loadProfile(userId) {
|
|
|
|
|
|
try {
|
2026-02-25 11:50:07 +08:00
|
|
|
|
const res = await app.request(`/api/miniprogram/vip/profile?userId=${userId}`)
|
2026-02-27 14:22:58 +08:00
|
|
|
|
if (res?.success) {
|
|
|
|
|
|
const p = res.data
|
|
|
|
|
|
// 头像若为相对路径则补全
|
|
|
|
|
|
if (p.vipAvatar && !p.vipAvatar.startsWith('http')) {
|
|
|
|
|
|
p.vipAvatar = app.globalData.baseUrl.replace(/\/$/, '') + (p.vipAvatar.startsWith('/') ? p.vipAvatar : '/' + p.vipAvatar)
|
|
|
|
|
|
}
|
|
|
|
|
|
this.setData({ profile: p })
|
|
|
|
|
|
}
|
2026-02-23 14:07:41 +08:00
|
|
|
|
} catch (e) { console.log('[VIP] 资料加载失败', e) }
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-27 14:22:58 +08:00
|
|
|
|
async onChooseVipAvatar() {
|
|
|
|
|
|
wx.chooseMedia({
|
|
|
|
|
|
count: 1,
|
|
|
|
|
|
mediaType: ['image'],
|
|
|
|
|
|
sourceType: ['album', 'camera'],
|
|
|
|
|
|
success: async (res) => {
|
|
|
|
|
|
const tempPath = res.tempFiles[0].tempFilePath
|
|
|
|
|
|
wx.showLoading({ title: '上传中...', mask: true })
|
|
|
|
|
|
try {
|
|
|
|
|
|
const uploadRes = await new Promise((resolve, reject) => {
|
|
|
|
|
|
wx.uploadFile({
|
|
|
|
|
|
url: app.globalData.baseUrl + '/api/miniprogram/upload',
|
|
|
|
|
|
filePath: tempPath,
|
|
|
|
|
|
name: 'file',
|
|
|
|
|
|
formData: { folder: 'avatars' },
|
|
|
|
|
|
success: (r) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const d = JSON.parse(r.data)
|
|
|
|
|
|
d.success ? resolve(d) : reject(new Error(d.error || '上传失败'))
|
|
|
|
|
|
} catch { reject(new Error('解析失败')) }
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: reject
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
const path = uploadRes.url || uploadRes.data?.url || ''
|
|
|
|
|
|
const avatarUrl = path.startsWith('http') ? path : (app.globalData.baseUrl.replace(/\/$/, '') + (path.startsWith('/') ? path : '/' + path))
|
|
|
|
|
|
this.setData({ 'profile.vipAvatar': avatarUrl })
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
wx.showToast({ title: '头像已更新', icon: 'success' })
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
wx.showToast({ title: e.message || '上传失败', icon: 'none' })
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-23 14:07:41 +08:00
|
|
|
|
async handlePurchase() {
|
2026-02-24 14:35:58 +08:00
|
|
|
|
let userId = app.globalData.userInfo?.id
|
|
|
|
|
|
let openId = app.globalData.openId || app.globalData.userInfo?.open_id
|
|
|
|
|
|
if (!userId || !openId) {
|
|
|
|
|
|
wx.showLoading({ title: '登录中...', mask: true })
|
|
|
|
|
|
try {
|
|
|
|
|
|
await app.login()
|
|
|
|
|
|
userId = app.globalData.userInfo?.id
|
|
|
|
|
|
openId = app.globalData.openId || app.globalData.userInfo?.open_id
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
if (!userId || !openId) {
|
|
|
|
|
|
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
|
wx.showToast({ title: '登录失败', icon: 'none' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-23 14:07:41 +08:00
|
|
|
|
this.setData({ purchasing: true })
|
|
|
|
|
|
try {
|
2026-02-24 14:35:58 +08:00
|
|
|
|
const payRes = await app.request('/api/miniprogram/pay', {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: {
|
|
|
|
|
|
openId,
|
|
|
|
|
|
userId,
|
|
|
|
|
|
productType: 'vip',
|
|
|
|
|
|
productId: 'vip_annual',
|
|
|
|
|
|
amount: this.data.price,
|
|
|
|
|
|
description: '卡若创业派对VIP年度会员(365天)'
|
2026-02-23 14:07:41 +08:00
|
|
|
|
}
|
2026-02-24 14:35:58 +08:00
|
|
|
|
})
|
|
|
|
|
|
if (payRes?.success && payRes.data?.payParams) {
|
|
|
|
|
|
wx.requestPayment({
|
|
|
|
|
|
...payRes.data.payParams,
|
|
|
|
|
|
success: () => {
|
|
|
|
|
|
wx.showToast({ title: 'VIP开通成功', icon: 'success' })
|
|
|
|
|
|
this.loadVipInfo()
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: () => wx.showToast({ title: '支付取消', icon: 'none' })
|
|
|
|
|
|
})
|
2026-02-23 14:07:41 +08:00
|
|
|
|
} else {
|
2026-02-24 14:35:58 +08:00
|
|
|
|
wx.showToast({ title: payRes?.error || '支付参数获取失败', icon: 'none' })
|
2026-02-23 14:07:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error('[VIP] 购买失败', e)
|
2026-02-24 14:35:58 +08:00
|
|
|
|
wx.showToast({ title: '购买失败,请稍后重试', icon: 'none' })
|
2026-02-23 14:07:41 +08:00
|
|
|
|
} finally { this.setData({ purchasing: false }) }
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-27 14:22:58 +08:00
|
|
|
|
onVipNameInput(e) { this.setData({ 'profile.vipName': e.detail.value }) },
|
|
|
|
|
|
onVipProjectInput(e) { this.setData({ 'profile.vipProject': e.detail.value }) },
|
|
|
|
|
|
onVipContactInput(e) { this.setData({ 'profile.vipContact': e.detail.value }) },
|
|
|
|
|
|
onVipBioInput(e) { this.setData({ 'profile.vipBio': e.detail.value }) },
|
2026-02-23 14:07:41 +08:00
|
|
|
|
|
|
|
|
|
|
async saveProfile() {
|
|
|
|
|
|
const userId = app.globalData.userInfo?.id
|
|
|
|
|
|
if (!userId) return
|
|
|
|
|
|
const p = this.data.profile
|
|
|
|
|
|
try {
|
2026-02-25 11:50:07 +08:00
|
|
|
|
const res = await app.request('/api/miniprogram/vip/profile', {
|
2026-02-27 14:22:58 +08:00
|
|
|
|
method: 'POST', data: { userId, vipName: p.vipName, vipProject: p.vipProject, vipContact: p.vipContact, vipAvatar: p.vipAvatar, vipBio: p.vipBio }
|
2026-02-23 14:07:41 +08:00
|
|
|
|
})
|
|
|
|
|
|
if (res?.success) wx.showToast({ title: '资料已保存', icon: 'success' })
|
|
|
|
|
|
else wx.showToast({ title: res?.error || '保存失败', icon: 'none' })
|
|
|
|
|
|
} catch (e) { wx.showToast({ title: '保存失败', icon: 'none' }) }
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-02-25 11:47:36 +08:00
|
|
|
|
goBack() { wx.navigateBack() },
|
|
|
|
|
|
|
|
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
const ref = app.getMyReferralCode()
|
|
|
|
|
|
return {
|
|
|
|
|
|
title: 'Soul创业派对 - VIP会员',
|
|
|
|
|
|
path: ref ? `/pages/vip/vip?ref=${ref}` : '/pages/vip/vip'
|
|
|
|
|
|
}
|
2026-02-27 14:22:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onShareTimeline() {
|
|
|
|
|
|
const ref = app.getMyReferralCode()
|
|
|
|
|
|
return { title: 'Soul创业派对 - VIP会员', query: ref ? `ref=${ref}` : '' }
|
2026-02-25 11:47:36 +08:00
|
|
|
|
}
|
2026-02-23 14:07:41 +08:00
|
|
|
|
})
|