2026-01-21 15:49:12 +08:00
|
|
|
|
/**
|
2026-01-25 19:37:59 +08:00
|
|
|
|
* Soul创业派对 - 找伙伴页
|
2026-01-21 15:49:12 +08:00
|
|
|
|
* 按H5网页端完全重构
|
|
|
|
|
|
* 开发: 卡若
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2026-01-14 12:50:00 +08:00
|
|
|
|
const app = getApp()
|
|
|
|
|
|
|
2026-01-23 16:31:54 +08:00
|
|
|
|
// 默认匹配类型配置
|
|
|
|
|
|
let MATCH_TYPES = [
|
2026-01-21 15:49:12 +08:00
|
|
|
|
{ id: 'partner', label: '创业合伙', matchLabel: '创业伙伴', icon: '⭐', matchFromDB: true, showJoinAfterMatch: false },
|
|
|
|
|
|
{ id: 'investor', label: '资源对接', matchLabel: '资源对接', icon: '👥', matchFromDB: false, showJoinAfterMatch: true },
|
|
|
|
|
|
{ id: 'mentor', label: '导师顾问', matchLabel: '商业顾问', icon: '❤️', matchFromDB: false, showJoinAfterMatch: true },
|
|
|
|
|
|
{ id: 'team', label: '团队招募', matchLabel: '加入项目', icon: '🎮', matchFromDB: false, showJoinAfterMatch: true }
|
|
|
|
|
|
]
|
|
|
|
|
|
|
2026-01-23 16:31:54 +08:00
|
|
|
|
let FREE_MATCH_LIMIT = 3 // 每日免费匹配次数
|
2026-01-21 15:49:12 +08:00
|
|
|
|
|
2026-01-14 12:50:00 +08:00
|
|
|
|
Page({
|
|
|
|
|
|
data: {
|
2026-01-21 15:49:12 +08:00
|
|
|
|
statusBarHeight: 44,
|
|
|
|
|
|
|
|
|
|
|
|
// 匹配类型
|
|
|
|
|
|
matchTypes: MATCH_TYPES,
|
|
|
|
|
|
selectedType: 'partner',
|
|
|
|
|
|
currentTypeLabel: '创业合伙',
|
|
|
|
|
|
|
|
|
|
|
|
// 用户状态
|
|
|
|
|
|
isLoggedIn: false,
|
|
|
|
|
|
hasPurchased: false,
|
|
|
|
|
|
hasFullBook: false,
|
|
|
|
|
|
|
|
|
|
|
|
// 匹配次数
|
|
|
|
|
|
todayMatchCount: 0,
|
|
|
|
|
|
totalMatchesAllowed: FREE_MATCH_LIMIT,
|
|
|
|
|
|
matchesRemaining: FREE_MATCH_LIMIT,
|
|
|
|
|
|
needPayToMatch: false,
|
|
|
|
|
|
|
|
|
|
|
|
// 匹配状态
|
2026-01-14 12:50:00 +08:00
|
|
|
|
isMatching: false,
|
|
|
|
|
|
matchAttempts: 0,
|
2026-01-21 15:49:12 +08:00
|
|
|
|
currentMatch: null,
|
|
|
|
|
|
|
|
|
|
|
|
// 加入弹窗
|
|
|
|
|
|
showJoinModal: false,
|
|
|
|
|
|
joinType: null,
|
|
|
|
|
|
joinTypeLabel: '',
|
|
|
|
|
|
contactType: 'phone',
|
|
|
|
|
|
phoneNumber: '',
|
|
|
|
|
|
wechatId: '',
|
|
|
|
|
|
userPhone: '',
|
|
|
|
|
|
isJoining: false,
|
|
|
|
|
|
joinSuccess: false,
|
|
|
|
|
|
joinError: '',
|
2026-01-25 09:27:32 +08:00
|
|
|
|
needBindFirst: false,
|
2026-01-21 15:49:12 +08:00
|
|
|
|
|
|
|
|
|
|
// 解锁弹窗
|
2026-01-25 19:37:59 +08:00
|
|
|
|
showUnlockModal: false,
|
|
|
|
|
|
|
|
|
|
|
|
// 匹配价格(可配置)
|
|
|
|
|
|
matchPrice: 1,
|
|
|
|
|
|
extraMatches: 0
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onLoad() {
|
2026-01-21 15:49:12 +08:00
|
|
|
|
this.setData({
|
|
|
|
|
|
statusBarHeight: app.globalData.statusBarHeight || 44
|
|
|
|
|
|
})
|
2026-01-23 16:31:54 +08:00
|
|
|
|
this.loadMatchConfig()
|
2026-01-21 15:49:12 +08:00
|
|
|
|
this.loadStoredContact()
|
|
|
|
|
|
this.loadTodayMatchCount()
|
|
|
|
|
|
this.initUserStatus()
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
onShow() {
|
|
|
|
|
|
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
|
|
|
|
|
this.getTabBar().setData({ selected: 2 })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
2026-01-21 15:49:12 +08:00
|
|
|
|
this.initUserStatus()
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-23 16:31:54 +08:00
|
|
|
|
// 加载匹配配置
|
|
|
|
|
|
async loadMatchConfig() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await app.request('/api/match/config', {
|
|
|
|
|
|
method: 'GET'
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (res.success && res.data) {
|
|
|
|
|
|
// 更新全局配置
|
|
|
|
|
|
MATCH_TYPES = res.data.matchTypes || MATCH_TYPES
|
|
|
|
|
|
FREE_MATCH_LIMIT = res.data.freeMatchLimit || FREE_MATCH_LIMIT
|
2026-01-25 19:37:59 +08:00
|
|
|
|
const matchPrice = res.data.matchPrice || 1
|
2026-01-23 16:31:54 +08:00
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
matchTypes: MATCH_TYPES,
|
2026-01-25 19:37:59 +08:00
|
|
|
|
totalMatchesAllowed: FREE_MATCH_LIMIT,
|
|
|
|
|
|
matchPrice: matchPrice
|
2026-01-23 16:31:54 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
console.log('[Match] 加载匹配配置成功:', {
|
|
|
|
|
|
types: MATCH_TYPES.length,
|
2026-01-25 19:37:59 +08:00
|
|
|
|
freeLimit: FREE_MATCH_LIMIT,
|
|
|
|
|
|
price: matchPrice
|
2026-01-23 16:31:54 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log('[Match] 加载匹配配置失败,使用默认配置:', e)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 加载本地存储的联系方式
|
|
|
|
|
|
loadStoredContact() {
|
|
|
|
|
|
const phone = wx.getStorageSync('user_phone') || ''
|
|
|
|
|
|
const wechat = wx.getStorageSync('user_wechat') || ''
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
phoneNumber: phone,
|
|
|
|
|
|
wechatId: wechat,
|
|
|
|
|
|
userPhone: phone
|
|
|
|
|
|
})
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 加载今日匹配次数
|
|
|
|
|
|
loadTodayMatchCount() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const today = new Date().toISOString().split('T')[0]
|
|
|
|
|
|
const stored = wx.getStorageSync('match_count_data')
|
|
|
|
|
|
if (stored) {
|
|
|
|
|
|
const data = typeof stored === 'string' ? JSON.parse(stored) : stored
|
|
|
|
|
|
if (data.date === today) {
|
|
|
|
|
|
this.setData({ todayMatchCount: data.count })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-21 15:49:12 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error('加载匹配次数失败:', e)
|
|
|
|
|
|
}
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 保存今日匹配次数
|
|
|
|
|
|
saveTodayMatchCount(count) {
|
|
|
|
|
|
const today = new Date().toISOString().split('T')[0]
|
|
|
|
|
|
wx.setStorageSync('match_count_data', { date: today, count })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 初始化用户状态
|
|
|
|
|
|
initUserStatus() {
|
|
|
|
|
|
const { isLoggedIn, hasFullBook, purchasedSections } = app.globalData
|
|
|
|
|
|
|
2026-01-23 16:31:54 +08:00
|
|
|
|
// 获取额外购买的匹配次数
|
|
|
|
|
|
const extraMatches = wx.getStorageSync('extra_match_count') || 0
|
|
|
|
|
|
|
|
|
|
|
|
// 总匹配次数 = 每日免费(3) + 额外购买次数
|
|
|
|
|
|
// 全书用户无限制
|
|
|
|
|
|
const totalMatchesAllowed = hasFullBook ? 999999 : FREE_MATCH_LIMIT + extraMatches
|
2026-01-21 15:49:12 +08:00
|
|
|
|
const matchesRemaining = hasFullBook ? 999999 : Math.max(0, totalMatchesAllowed - this.data.todayMatchCount)
|
|
|
|
|
|
const needPayToMatch = !hasFullBook && matchesRemaining <= 0
|
2026-01-14 12:50:00 +08:00
|
|
|
|
|
|
|
|
|
|
this.setData({
|
2026-01-21 15:49:12 +08:00
|
|
|
|
isLoggedIn,
|
|
|
|
|
|
hasFullBook,
|
2026-01-23 16:31:54 +08:00
|
|
|
|
hasPurchased: true, // 所有用户都可以使用匹配功能
|
2026-01-21 15:49:12 +08:00
|
|
|
|
totalMatchesAllowed,
|
|
|
|
|
|
matchesRemaining,
|
2026-01-23 16:31:54 +08:00
|
|
|
|
needPayToMatch,
|
|
|
|
|
|
extraMatches
|
2026-01-14 12:50:00 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 选择匹配类型
|
|
|
|
|
|
selectType(e) {
|
|
|
|
|
|
const typeId = e.currentTarget.dataset.type
|
|
|
|
|
|
const type = MATCH_TYPES.find(t => t.id === typeId)
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
selectedType: typeId,
|
|
|
|
|
|
currentTypeLabel: type?.matchLabel || type?.label || '创业伙伴'
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2026-01-14 12:50:00 +08:00
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 点击匹配按钮
|
|
|
|
|
|
handleMatchClick() {
|
|
|
|
|
|
const currentType = MATCH_TYPES.find(t => t.id === this.data.selectedType)
|
|
|
|
|
|
|
2026-01-25 09:27:32 +08:00
|
|
|
|
// 如果是需要填写联系方式的类型(资源对接、导师顾问、团队招募)
|
2026-01-21 15:49:12 +08:00
|
|
|
|
if (currentType && currentType.showJoinAfterMatch) {
|
2026-01-25 09:27:32 +08:00
|
|
|
|
// 先检查是否已绑定联系方式
|
|
|
|
|
|
const hasPhone = !!this.data.phoneNumber
|
|
|
|
|
|
const hasWechat = !!this.data.wechatId
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasPhone && !hasWechat) {
|
|
|
|
|
|
// 没有绑定联系方式,先显示绑定提示
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
showJoinModal: true,
|
|
|
|
|
|
joinType: currentType.id,
|
|
|
|
|
|
joinTypeLabel: currentType.matchLabel || currentType.label,
|
|
|
|
|
|
joinSuccess: false,
|
|
|
|
|
|
joinError: '',
|
|
|
|
|
|
needBindFirst: true
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 已绑定联系方式,先显示匹配动画1-3秒,再弹出确认
|
|
|
|
|
|
this.startMatchingAnimation(currentType)
|
2026-01-21 15:49:12 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创业合伙类型 - 真正的匹配功能
|
|
|
|
|
|
if (this.data.needPayToMatch) {
|
|
|
|
|
|
this.setData({ showUnlockModal: true })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.startMatch()
|
|
|
|
|
|
},
|
2026-01-25 09:27:32 +08:00
|
|
|
|
|
|
|
|
|
|
// 匹配动画后弹出加入确认
|
|
|
|
|
|
startMatchingAnimation(currentType) {
|
|
|
|
|
|
// 显示匹配中状态
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
isMatching: true,
|
|
|
|
|
|
matchAttempts: 0,
|
|
|
|
|
|
currentMatch: null
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 动画计时
|
|
|
|
|
|
const timer = setInterval(() => {
|
|
|
|
|
|
this.setData({ matchAttempts: this.data.matchAttempts + 1 })
|
|
|
|
|
|
}, 500)
|
|
|
|
|
|
|
|
|
|
|
|
// 1-3秒随机延迟后显示弹窗
|
|
|
|
|
|
const delay = Math.random() * 2000 + 1000
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
clearInterval(timer)
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
isMatching: false,
|
|
|
|
|
|
showJoinModal: true,
|
|
|
|
|
|
joinType: currentType.id,
|
|
|
|
|
|
joinTypeLabel: currentType.matchLabel || currentType.label,
|
|
|
|
|
|
joinSuccess: false,
|
|
|
|
|
|
joinError: '',
|
|
|
|
|
|
needBindFirst: false
|
|
|
|
|
|
})
|
|
|
|
|
|
}, delay)
|
|
|
|
|
|
},
|
2026-01-14 12:50:00 +08:00
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 显示购买提示
|
|
|
|
|
|
showPurchaseTip() {
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title: '需要购买书籍',
|
2026-01-25 19:37:59 +08:00
|
|
|
|
content: '购买《Soul创业派对》后即可使用匹配功能,仅需9.9元',
|
2026-01-21 15:49:12 +08:00
|
|
|
|
confirmText: '去购买',
|
2026-01-14 12:50:00 +08:00
|
|
|
|
success: (res) => {
|
2026-01-21 15:49:12 +08:00
|
|
|
|
if (res.confirm) {
|
|
|
|
|
|
this.goToChapters()
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 开始匹配
|
|
|
|
|
|
async startMatch() {
|
2026-01-14 12:50:00 +08:00
|
|
|
|
this.setData({
|
2026-01-21 15:49:12 +08:00
|
|
|
|
isMatching: true,
|
|
|
|
|
|
matchAttempts: 0,
|
|
|
|
|
|
currentMatch: null
|
2026-01-14 12:50:00 +08:00
|
|
|
|
})
|
2026-01-21 15:49:12 +08:00
|
|
|
|
|
|
|
|
|
|
// 匹配动画计时器
|
|
|
|
|
|
const timer = setInterval(() => {
|
|
|
|
|
|
this.setData({ matchAttempts: this.data.matchAttempts + 1 })
|
|
|
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
|
|
|
|
// 尝试从API获取真实用户
|
|
|
|
|
|
let matchedUser = null
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await app.request('/api/ckb/match', {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: {
|
|
|
|
|
|
matchType: this.data.selectedType,
|
|
|
|
|
|
userId: app.globalData.userInfo?.id || '',
|
|
|
|
|
|
phone: this.data.phoneNumber,
|
|
|
|
|
|
wechat: this.data.wechatId
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (res.success && res.data) {
|
|
|
|
|
|
matchedUser = res.data
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log('API匹配失败,使用模拟数据')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果API没返回,使用模拟数据
|
|
|
|
|
|
if (!matchedUser) {
|
|
|
|
|
|
matchedUser = this.generateMockMatch()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 延迟显示结果(模拟匹配过程)
|
|
|
|
|
|
const delay = Math.random() * 2000 + 2000
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
clearInterval(timer)
|
|
|
|
|
|
|
|
|
|
|
|
// 增加今日匹配次数
|
|
|
|
|
|
const newCount = this.data.todayMatchCount + 1
|
|
|
|
|
|
const matchesRemaining = this.data.hasFullBook ? 999999 : Math.max(0, this.data.totalMatchesAllowed - newCount)
|
|
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
isMatching: false,
|
|
|
|
|
|
currentMatch: matchedUser,
|
|
|
|
|
|
todayMatchCount: newCount,
|
|
|
|
|
|
matchesRemaining,
|
|
|
|
|
|
needPayToMatch: !this.data.hasFullBook && matchesRemaining <= 0
|
|
|
|
|
|
})
|
|
|
|
|
|
this.saveTodayMatchCount(newCount)
|
|
|
|
|
|
|
|
|
|
|
|
// 上报匹配行为
|
|
|
|
|
|
this.reportMatch(matchedUser)
|
|
|
|
|
|
|
|
|
|
|
|
}, delay)
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 生成模拟匹配数据
|
|
|
|
|
|
generateMockMatch() {
|
|
|
|
|
|
const nicknames = ['创业先锋', '资源整合者', '私域专家', '商业导师', '连续创业者']
|
2026-01-14 12:50:00 +08:00
|
|
|
|
const concepts = [
|
2026-01-21 15:49:12 +08:00
|
|
|
|
'专注私域流量运营5年,帮助100+品牌实现从0到1的增长。',
|
|
|
|
|
|
'连续创业者,擅长商业模式设计和资源整合。',
|
|
|
|
|
|
'在Soul分享真实创业故事,希望找到志同道合的合作伙伴。'
|
2026-01-14 12:50:00 +08:00
|
|
|
|
]
|
2026-01-21 15:49:12 +08:00
|
|
|
|
const wechats = ['soul_partner_1', 'soul_business_2024', 'soul_startup_fan']
|
|
|
|
|
|
|
|
|
|
|
|
const index = Math.floor(Math.random() * nicknames.length)
|
|
|
|
|
|
const currentType = MATCH_TYPES.find(t => t.id === this.data.selectedType)
|
2026-01-14 12:50:00 +08:00
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
id: `user_${Date.now()}`,
|
2026-01-21 15:49:12 +08:00
|
|
|
|
nickname: nicknames[index],
|
|
|
|
|
|
avatar: `https://picsum.photos/200/200?random=${Date.now()}`,
|
|
|
|
|
|
tags: ['创业者', '私域运营', currentType?.label || '创业合伙'],
|
2026-01-14 12:50:00 +08:00
|
|
|
|
matchScore: Math.floor(Math.random() * 20) + 80,
|
2026-01-21 15:49:12 +08:00
|
|
|
|
concept: concepts[index % concepts.length],
|
|
|
|
|
|
wechat: wechats[index % wechats.length],
|
2026-01-14 12:50:00 +08:00
|
|
|
|
commonInterests: [
|
2026-01-25 19:37:59 +08:00
|
|
|
|
{ icon: '📚', text: '都在读《创业派对》' },
|
2026-01-14 12:50:00 +08:00
|
|
|
|
{ icon: '💼', text: '对私域运营感兴趣' },
|
2026-01-21 15:49:12 +08:00
|
|
|
|
{ icon: '🎯', text: '相似的创业方向' }
|
2026-01-14 12:50:00 +08:00
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 上报匹配行为
|
|
|
|
|
|
async reportMatch(matchedUser) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await app.request('/api/ckb/match', {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: {
|
|
|
|
|
|
matchType: this.data.selectedType,
|
|
|
|
|
|
phone: this.data.phoneNumber,
|
|
|
|
|
|
wechat: this.data.wechatId,
|
|
|
|
|
|
userId: app.globalData.userInfo?.id || '',
|
|
|
|
|
|
nickname: app.globalData.userInfo?.nickname || '',
|
|
|
|
|
|
matchedUser: {
|
|
|
|
|
|
id: matchedUser.id,
|
|
|
|
|
|
nickname: matchedUser.nickname,
|
|
|
|
|
|
matchScore: matchedUser.matchScore
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log('上报匹配失败:', e)
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 取消匹配
|
|
|
|
|
|
cancelMatch() {
|
2026-01-21 15:49:12 +08:00
|
|
|
|
this.setData({ isMatching: false, matchAttempts: 0 })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 重置匹配(返回)
|
|
|
|
|
|
resetMatch() {
|
|
|
|
|
|
this.setData({ currentMatch: null })
|
|
|
|
|
|
},
|
2026-01-14 12:50:00 +08:00
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 添加微信好友
|
|
|
|
|
|
handleAddWechat() {
|
|
|
|
|
|
if (!this.data.currentMatch) return
|
|
|
|
|
|
|
2026-01-14 12:50:00 +08:00
|
|
|
|
wx.setClipboardData({
|
2026-01-21 15:49:12 +08:00
|
|
|
|
data: this.data.currentMatch.wechat,
|
2026-01-14 12:50:00 +08:00
|
|
|
|
success: () => {
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title: '微信号已复制',
|
2026-01-21 15:49:12 +08:00
|
|
|
|
content: `微信号:${this.data.currentMatch.wechat}\n\n请打开微信添加好友,备注"创业合作"即可`,
|
2026-01-14 12:50:00 +08:00
|
|
|
|
showCancel: false,
|
2026-01-21 15:49:12 +08:00
|
|
|
|
confirmText: '知道了'
|
2026-01-14 12:50:00 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 切换联系方式类型
|
|
|
|
|
|
switchContactType(e) {
|
|
|
|
|
|
const type = e.currentTarget.dataset.type
|
|
|
|
|
|
this.setData({ contactType: type, joinError: '' })
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 手机号输入
|
|
|
|
|
|
onPhoneInput(e) {
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
phoneNumber: e.detail.value.replace(/\D/g, '').slice(0, 11),
|
|
|
|
|
|
joinError: ''
|
2026-01-14 12:50:00 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 微信号输入
|
|
|
|
|
|
onWechatInput(e) {
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
wechatId: e.detail.value,
|
|
|
|
|
|
joinError: ''
|
2026-01-14 12:50:00 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 提交加入
|
|
|
|
|
|
async handleJoinSubmit() {
|
|
|
|
|
|
const { contactType, phoneNumber, wechatId, joinType, isJoining } = this.data
|
|
|
|
|
|
|
|
|
|
|
|
if (isJoining) return
|
|
|
|
|
|
|
|
|
|
|
|
// 验证
|
|
|
|
|
|
if (contactType === 'phone') {
|
|
|
|
|
|
if (!phoneNumber || phoneNumber.length !== 11) {
|
|
|
|
|
|
this.setData({ joinError: '请输入正确的11位手机号' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (!wechatId || wechatId.length < 6) {
|
|
|
|
|
|
this.setData({ joinError: '请输入正确的微信号(至少6位)' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.setData({ isJoining: true, joinError: '' })
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await app.request('/api/ckb/join', {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: {
|
|
|
|
|
|
type: joinType,
|
|
|
|
|
|
phone: contactType === 'phone' ? phoneNumber : '',
|
|
|
|
|
|
wechat: contactType === 'wechat' ? wechatId : '',
|
|
|
|
|
|
userId: app.globalData.userInfo?.id || ''
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
2026-01-21 15:49:12 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 保存联系方式到本地
|
|
|
|
|
|
if (phoneNumber) wx.setStorageSync('user_phone', phoneNumber)
|
|
|
|
|
|
if (wechatId) wx.setStorageSync('user_wechat', wechatId)
|
|
|
|
|
|
|
|
|
|
|
|
if (res.success) {
|
|
|
|
|
|
this.setData({ joinSuccess: true })
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.setData({ showJoinModal: false, joinSuccess: false })
|
|
|
|
|
|
}, 2000)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 即使API返回失败,也模拟成功(因为已保存本地)
|
|
|
|
|
|
this.setData({ joinSuccess: true })
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.setData({ showJoinModal: false, joinSuccess: false })
|
|
|
|
|
|
}, 2000)
|
2026-01-14 12:50:00 +08:00
|
|
|
|
}
|
2026-01-21 15:49:12 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
// 网络错误时也模拟成功
|
|
|
|
|
|
this.setData({ joinSuccess: true })
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.setData({ showJoinModal: false, joinSuccess: false })
|
|
|
|
|
|
}, 2000)
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
this.setData({ isJoining: false })
|
|
|
|
|
|
}
|
2026-01-14 12:50:00 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 关闭加入弹窗
|
|
|
|
|
|
closeJoinModal() {
|
|
|
|
|
|
if (this.data.isJoining) return
|
|
|
|
|
|
this.setData({ showJoinModal: false, joinError: '' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-23 16:31:54 +08:00
|
|
|
|
// 显示解锁弹窗
|
|
|
|
|
|
showUnlockModal() {
|
|
|
|
|
|
this.setData({ showUnlockModal: true })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 关闭解锁弹窗
|
|
|
|
|
|
closeUnlockModal() {
|
|
|
|
|
|
this.setData({ showUnlockModal: false })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-23 16:31:54 +08:00
|
|
|
|
// 购买匹配次数
|
|
|
|
|
|
async buyMatchCount() {
|
|
|
|
|
|
this.setData({ showUnlockModal: false })
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 获取openId
|
|
|
|
|
|
let openId = app.globalData.openId || wx.getStorageSync('openId')
|
|
|
|
|
|
if (!openId) {
|
|
|
|
|
|
openId = await app.getOpenId()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!openId) {
|
|
|
|
|
|
wx.showToast({ title: '请先登录', icon: 'none' })
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 调用支付接口购买匹配次数
|
|
|
|
|
|
const res = await app.request('/api/miniprogram/pay', {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: {
|
|
|
|
|
|
openId,
|
|
|
|
|
|
productType: 'match',
|
|
|
|
|
|
productId: 'match_1',
|
|
|
|
|
|
amount: 1,
|
|
|
|
|
|
description: '匹配次数x1',
|
|
|
|
|
|
userId: app.globalData.userInfo?.id || ''
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (res.success && res.data?.payParams) {
|
|
|
|
|
|
// 调用微信支付
|
|
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
|
|
wx.requestPayment({
|
|
|
|
|
|
...res.data.payParams,
|
|
|
|
|
|
success: resolve,
|
|
|
|
|
|
fail: reject
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 支付成功,增加匹配次数
|
|
|
|
|
|
const extraMatches = (wx.getStorageSync('extra_match_count') || 0) + 1
|
|
|
|
|
|
wx.setStorageSync('extra_match_count', extraMatches)
|
|
|
|
|
|
|
|
|
|
|
|
wx.showToast({ title: '购买成功', icon: 'success' })
|
|
|
|
|
|
this.initUserStatus()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new Error(res.error || '创建订单失败')
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if (e.errMsg && e.errMsg.includes('cancel')) {
|
|
|
|
|
|
wx.showToast({ title: '已取消', icon: 'none' })
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 测试模式
|
|
|
|
|
|
wx.showModal({
|
|
|
|
|
|
title: '支付服务暂不可用',
|
|
|
|
|
|
content: '是否使用测试模式购买?',
|
|
|
|
|
|
success: (res) => {
|
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
|
const extraMatches = (wx.getStorageSync('extra_match_count') || 0) + 1
|
|
|
|
|
|
wx.setStorageSync('extra_match_count', extraMatches)
|
|
|
|
|
|
wx.showToast({ title: '测试购买成功', icon: 'success' })
|
|
|
|
|
|
this.initUserStatus()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
|
// 跳转到目录页购买
|
|
|
|
|
|
goToChapters() {
|
|
|
|
|
|
this.setData({ showUnlockModal: false })
|
|
|
|
|
|
wx.switchTab({ url: '/pages/chapters/chapters' })
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 打开设置
|
|
|
|
|
|
openSettings() {
|
2026-01-23 16:31:54 +08:00
|
|
|
|
wx.navigateTo({ url: '/pages/settings/settings' })
|
2026-01-21 15:49:12 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 阻止事件冒泡
|
|
|
|
|
|
preventBubble() {}
|
2026-01-14 12:50:00 +08:00
|
|
|
|
})
|