| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <template>
- <view class="container">
- <!-- 邀请码展示 -->
- <view class="code-card">
- <text class="code-title">我的邀请码</text>
- <text class="code-value">{{ referralCode || '加载中...' }}</text>
- <view class="code-actions">
- <button class="action-btn" @click="copyCode">复制邀请码</button>
- <button class="action-btn share" @click="shareInvite">分享给好友</button>
- </view>
- </view>
- <!-- 绑定推荐人 -->
- <view class="bind-card">
- <text class="bind-title">我有推荐人</text>
- <view class="bind-row">
- <input v-model="bindCode" type="text" placeholder="输入推荐人的邀请码" class="bind-input" />
- <button class="bind-btn" @click="bindReferral">绑定</button>
- </view>
- </view>
- <!-- 已邀请列表 -->
- <view class="list-section">
- <text class="section-title">已邀请好友 ({{ total || 0 }})</text>
- <view class="empty-state" v-if="!loading && list.length === 0">
- <text>还没有邀请好友,快去分享吧</text>
- </view>
- <view class="invite-item" v-for="item in list" :key="item.id">
- <text class="invite-avatar">👤</text>
- <view class="invite-info">
- <text class="invite-name">{{ item.nickname || '好友' }}</text>
- <text class="invite-time">{{ formatTime(item.createdAt) }}</text>
- </view>
- </view>
- <view class="loading-state" v-if="loading">
- <text>加载中...</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { getReferralCode, bindReferral, getReferralList } from '../../utils/api.js'
- export default {
- data() {
- return {
- referralCode: '',
- bindCode: '',
- list: [],
- total: 0,
- page: 1,
- loading: false,
- hasMore: true
- }
- },
- onLoad() {
- this.loadCode()
- this.loadList()
- },
- onReachBottom() {
- if (this.hasMore && !this.loading) {
- this.page++
- this.loadList()
- }
- },
- methods: {
- async loadCode() {
- try {
- const res = await getReferralCode()
- if (res.data) {
- this.referralCode = res.data.referralCode || res.data.code || ''
- }
- } catch (e) {
- console.error('获取邀请码失败', e)
- }
- },
- async loadList() {
- this.loading = true
- try {
- const res = await getReferralList(this.page)
- if (res.data) {
- if (res.data.records) {
- this.list = this.page === 1 ? res.data.records : [...this.list, ...res.data.records]
- }
- this.total = res.data.total || 0
- if (res.data.records) {
- this.hasMore = res.data.records.length >= 10
- } else {
- this.hasMore = false
- }
- }
- } catch (e) {
- console.error('获取邀请列表失败', e)
- }
- this.loading = false
- },
- copyCode() {
- if (!this.referralCode) return
- uni.setClipboardData({
- data: this.referralCode,
- success: () => {
- uni.showToast({ title: '已复制邀请码', icon: 'success' })
- }
- })
- },
- shareInvite() {
- uni.showToast({ title: '即将上线', icon: 'none' })
- },
- async bindReferral() {
- if (!this.bindCode) {
- uni.showToast({ title: '请输入邀请码', icon: 'none' })
- return
- }
- if (this.bindCode === this.referralCode) {
- uni.showToast({ title: '不能绑定自己的邀请码', icon: 'none' })
- return
- }
- try {
- await bindReferral(this.bindCode)
- uni.showToast({ title: '绑定成功', icon: 'success' })
- this.bindCode = ''
- } catch (e) {
- uni.showToast({ title: e.message || '绑定失败', icon: 'none' })
- }
- },
- formatTime(time) {
- if (!time) return ''
- const t = new Date(time)
- return t.getFullYear() + '-' + String(t.getMonth()+1).padStart(2,'0') + '-' + String(t.getDate()).padStart(2,'0')
- }
- }
- }
- </script>
- <style scoped>
- .container {
- padding: 30rpx;
- min-height: 100vh;
- background: #f5f7fa;
- }
- .code-card {
- background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
- border-radius: 20rpx;
- padding: 40rpx;
- text-align: center;
- color: #fff;
- margin-bottom: 30rpx;
- }
- .code-title {
- font-size: 26rpx;
- opacity: 0.9;
- }
- .code-value {
- font-size: 48rpx;
- font-weight: bold;
- letter-spacing: 6rpx;
- margin: 20rpx 0 30rpx;
- display: block;
- }
- .code-actions {
- display: flex;
- gap: 20rpx;
- }
- .action-btn {
- flex: 1;
- background: rgba(255,255,255,0.2);
- color: #fff;
- font-size: 26rpx;
- border-radius: 40rpx;
- height: 64rpx;
- line-height: 64rpx;
- border: 1rpx solid rgba(255,255,255,0.3);
- }
- .action-btn::after { border: none; }
- .bind-card {
- background: #fff;
- border-radius: 20rpx;
- padding: 30rpx;
- margin-bottom: 30rpx;
- }
- .bind-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- display: block;
- margin-bottom: 16rpx;
- }
- .bind-row {
- display: flex;
- gap: 20rpx;
- }
- .bind-input {
- flex: 1;
- border: 1rpx solid #ddd;
- border-radius: 10rpx;
- padding: 20rpx;
- font-size: 28rpx;
- }
- .bind-btn {
- background: #3A7CC4;
- color: #fff;
- font-size: 26rpx;
- border-radius: 10rpx;
- height: 64rpx;
- line-height: 64rpx;
- padding: 0 30rpx;
- }
- .bind-btn::after { border: none; }
- .list-section {
- background: #fff;
- border-radius: 20rpx;
- padding: 30rpx;
- }
- .section-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- display: block;
- margin-bottom: 20rpx;
- }
- .invite-item {
- display: flex;
- align-items: center;
- padding: 20rpx 0;
- border-bottom: 1rpx solid #f0f0f0;
- }
- .invite-item:last-child { border-bottom: none; }
- .invite-avatar {
- font-size: 48rpx;
- margin-right: 20rpx;
- }
- .invite-info { flex: 1; }
- .invite-name {
- font-size: 28rpx;
- color: #333;
- display: block;
- }
- .invite-time {
- font-size: 22rpx;
- color: #999;
- margin-top: 4rpx;
- }
- .empty-state, .loading-state {
- text-align: center;
- padding: 60rpx;
- color: #999;
- font-size: 28rpx;
- }
- </style>
|