Files
soul-yongping/miniprogram/pages/referral/referral.js

105 lines
2.8 KiB
JavaScript
Raw Normal View History

const app = getApp()
Page({
data: {
statusBarHeight: 44,
2026-02-02 18:27:48 +08:00
navBarHeight: 88,
isLoggedIn: false,
user: null,
totalEarnings: '0.00',
pendingEarnings: '0.00',
referralCode: '',
distributorShare: 90,
canWithdraw: false
},
2026-02-02 18:27:48 +08:00
onLoad() {
const statusBarHeight = app.globalData.statusBarHeight || 44
const navBarHeight = app.globalData.navBarHeight || (statusBarHeight + 44)
this.setData({ statusBarHeight, navBarHeight })
2026-02-02 18:27:48 +08:00
this.syncUser()
},
onShow() {
2026-02-02 18:27:48 +08:00
this.syncUser()
},
2026-02-02 18:27:48 +08:00
syncUser() {
const isLoggedIn = !!app.globalData.isLoggedIn
const user = app.globalData.userInfo || null
if (!user) {
this.setData({ isLoggedIn: false, user: null })
return
}
const total = Number(user.earnings != null ? user.earnings : 0)
const totalEarnings = total.toFixed(2)
const pendingEarnings = Number(user.pendingEarnings != null ? user.pendingEarnings : 0).toFixed(2)
const referralCode = user.referralCode || ''
this.setData({
isLoggedIn: true,
user,
totalEarnings,
pendingEarnings,
referralCode,
canWithdraw: total >= 10
})
},
2026-02-02 18:27:48 +08:00
goBack() {
wx.navigateBack({ fail: () => wx.switchTab({ url: '/pages/my/my' }) })
},
2026-02-02 18:27:48 +08:00
copyLink() {
const user = app.globalData.userInfo
if (!user || !user.referralCode) {
wx.showToast({ title: '请先登录', icon: 'none' })
return
}
const baseUrl = app.globalData.baseUrl || 'https://soul.quwanzhi.com'
const link = baseUrl + '?ref=' + user.referralCode
wx.setClipboardData({
data: link,
success: () => wx.showToast({ title: '链接已复制', icon: 'success' })
})
},
2026-02-02 18:27:48 +08:00
shareToMoments() {
const user = app.globalData.userInfo
if (!user || !user.referralCode) {
wx.showToast({ title: '请先登录', icon: 'none' })
return
}
const baseUrl = app.globalData.baseUrl || 'https://soul.quwanzhi.com'
const link = baseUrl + '?ref=' + user.referralCode
const text = `📖 推荐一本好书《一场SOUL的创业实验场》
这是卡若每天早上6-9点在Soul派对房分享的真实商业故事55个真实案例讲透创业的底层逻辑
👉 点击阅读: ${link}
#创业 #商业思维 #Soul派对`
wx.setClipboardData({
data: text,
success: () => wx.showToast({ title: '朋友圈文案已复制', icon: 'success' })
})
},
2026-02-02 18:27:48 +08:00
applyWithdraw() {
const user = app.globalData.userInfo
if (!user) {
wx.showToast({ title: '请先登录', icon: 'none' })
return
}
const total = Number(user.earnings != null ? user.earnings : 0)
if (total < 10) {
wx.showToast({ title: '满10元可提现', icon: 'none' })
return
}
wx.showToast({
title: '请在小程序内联系客服或使用提现功能',
icon: 'none',
duration: 2500
})
}
2026-02-02 18:27:48 +08:00
})