同步数据
This commit is contained in:
@@ -1,68 +1,104 @@
|
||||
// pages/referral/referral.js
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
statusBarHeight: 44,
|
||||
navBarHeight: 88
|
||||
navBarHeight: 88,
|
||||
isLoggedIn: false,
|
||||
user: null,
|
||||
totalEarnings: '0.00',
|
||||
pendingEarnings: '0.00',
|
||||
referralCode: '',
|
||||
distributorShare: 90,
|
||||
canWithdraw: false
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
onLoad() {
|
||||
const statusBarHeight = app.globalData.statusBarHeight || 44
|
||||
const navBarHeight = app.globalData.navBarHeight || (statusBarHeight + 44)
|
||||
this.setData({ statusBarHeight, navBarHeight })
|
||||
this.syncUser()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.syncUser()
|
||||
},
|
||||
|
||||
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
|
||||
})
|
||||
},
|
||||
|
||||
goBack() {
|
||||
wx.navigateBack({ fail: () => wx.switchTab({ url: '/pages/my/my' }) })
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
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' })
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
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' })
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,5 +4,59 @@
|
||||
<view class="nav-back" bindtap="goBack">← 返回</view>
|
||||
<text class="header-title">推广中心</text>
|
||||
</view>
|
||||
<view class="placeholder-body">待开发</view>
|
||||
|
||||
<block wx:if="{{!isLoggedIn}}">
|
||||
<view class="empty-wrap">
|
||||
<text class="empty-desc">请先登录</text>
|
||||
<view class="btn-primary" bindtap="goBack">返回我的</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<block wx:else>
|
||||
<view class="earnings-card">
|
||||
<view class="earnings-head">
|
||||
<view class="earnings-title-row">
|
||||
<text class="earnings-icon">💰</text>
|
||||
<view>
|
||||
<text class="earnings-label">累计收益</text>
|
||||
<text class="earnings-rate">{{distributorShare}}% 返利</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="earnings-right">
|
||||
<text class="earnings-total">¥{{totalEarnings}}</text>
|
||||
<text class="earnings-pending">待结算: ¥{{pendingEarnings}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="btn-withdraw {{canWithdraw ? '' : 'disabled'}}" bindtap="applyWithdraw">
|
||||
{{canWithdraw ? '申请提现' : '满10元可提现'}}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="code-card">
|
||||
<view class="code-row">
|
||||
<text class="code-label">我的邀请码</text>
|
||||
<text class="code-value">{{referralCode}}</text>
|
||||
</view>
|
||||
<text class="code-desc">好友通过你的链接购买立省5%,你获得{{distributorShare}}%收益</text>
|
||||
</view>
|
||||
|
||||
<view class="action-list">
|
||||
<view class="action-item" bindtap="copyLink">
|
||||
<view class="action-icon">🔗</view>
|
||||
<view class="action-text">
|
||||
<text class="action-title">复制邀请链接</text>
|
||||
<text class="action-desc">分享给好友购买</text>
|
||||
</view>
|
||||
<text class="action-arrow">›</text>
|
||||
</view>
|
||||
<view class="action-item" bindtap="shareToMoments">
|
||||
<view class="action-icon wechat">💬</view>
|
||||
<view class="action-text">
|
||||
<text class="action-title">分享到朋友圈</text>
|
||||
<text class="action-desc">复制文案发朋友圈</text>
|
||||
</view>
|
||||
<text class="action-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
@@ -1,8 +1,38 @@
|
||||
page { background: #000; color: #fff; }
|
||||
.page { min-height: 100vh; }
|
||||
.page { min-height: 100vh; padding-bottom: 80rpx; box-sizing: border-box; }
|
||||
.nav-placeholder { width: 100%; }
|
||||
.header { display: flex; align-items: center; padding: 24rpx 32rpx; border-bottom: 2rpx solid rgba(255,255,255,0.05); }
|
||||
.nav-back { font-size: 32rpx; color: #00CED1; margin-right: 24rpx; }
|
||||
.header-title { flex: 1; text-align: center; font-size: 34rpx; color: #00CED1; }
|
||||
.placeholder-body { padding: 48rpx; text-align: center; color: rgba(255,255,255,0.4); font-size: 28rpx; }
|
||||
.container { padding: 32rpx; }
|
||||
|
||||
.empty-wrap { padding: 80rpx 48rpx; text-align: center; }
|
||||
.empty-desc { font-size: 28rpx; color: rgba(255,255,255,0.5); display: block; margin-bottom: 32rpx; }
|
||||
.btn-primary { display: inline-block; padding: 24rpx 64rpx; border-radius: 48rpx; background: linear-gradient(135deg, #00CED1 0%, #20B2AA 100%); color: #000; font-size: 30rpx; font-weight: 600; }
|
||||
|
||||
.earnings-card { margin: 32rpx; padding: 32rpx; border-radius: 32rpx; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%); border: 2rpx solid rgba(0,206,209,0.2); box-sizing: border-box; }
|
||||
.earnings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24rpx; gap: 24rpx; min-width: 0; }
|
||||
.earnings-title-row { display: flex; align-items: center; gap: 16rpx; min-width: 0; }
|
||||
.earnings-icon { font-size: 40rpx; flex-shrink: 0; }
|
||||
.earnings-label { font-size: 24rpx; color: rgba(255,255,255,0.5); display: block; }
|
||||
.earnings-rate { font-size: 24rpx; color: #00CED1; display: block; margin-top: 4rpx; }
|
||||
.earnings-right { text-align: right; flex-shrink: 0; }
|
||||
.earnings-total { font-size: 56rpx; font-weight: 700; color: #fff; display: block; }
|
||||
.earnings-pending { font-size: 24rpx; color: rgba(255,255,255,0.5); }
|
||||
.btn-withdraw { width: 100%; padding: 24rpx; border-radius: 24rpx; background: linear-gradient(90deg, #00CED1 0%, #20B2AA 100%); color: #000; font-size: 30rpx; font-weight: 600; text-align: center; margin-top: 16rpx; box-sizing: border-box; }
|
||||
.btn-withdraw.disabled { opacity: 0.5; background: #2c2c2e; color: rgba(255,255,255,0.5); }
|
||||
|
||||
.code-card { margin: 32rpx; padding: 32rpx; border-radius: 24rpx; background: #1c1c1e; border: 2rpx solid rgba(255,255,255,0.05); }
|
||||
.code-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16rpx; }
|
||||
.code-label { font-size: 30rpx; color: #fff; font-weight: 500; }
|
||||
.code-value { font-size: 28rpx; color: #00CED1; font-family: monospace; background: rgba(0,206,209,0.1); padding: 12rpx 24rpx; border-radius: 16rpx; }
|
||||
.code-desc { font-size: 24rpx; color: rgba(255,255,255,0.5); }
|
||||
|
||||
.action-list { margin: 32rpx; border-radius: 24rpx; background: #1c1c1e; border: 2rpx solid rgba(255,255,255,0.05); overflow: hidden; }
|
||||
.action-item { display: flex; align-items: center; padding: 32rpx; border-bottom: 2rpx solid rgba(255,255,255,0.05); }
|
||||
.action-item:last-child { border-bottom: none; }
|
||||
.action-icon { width: 80rpx; height: 80rpx; border-radius: 20rpx; background: rgba(0,206,209,0.15); display: flex; align-items: center; justify-content: center; font-size: 40rpx; margin-right: 24rpx; flex-shrink: 0; }
|
||||
.action-icon.wechat { background: rgba(7,193,96,0.15); }
|
||||
.action-text { flex: 1; min-width: 0; }
|
||||
.action-title { font-size: 30rpx; color: #fff; font-weight: 500; display: block; }
|
||||
.action-desc { font-size: 24rpx; color: rgba(255,255,255,0.4); display: block; margin-top: 8rpx; }
|
||||
.action-arrow { font-size: 32rpx; color: rgba(255,255,255,0.3); }
|
||||
|
||||
Reference in New Issue
Block a user