| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- <template>
- <view class="container">
- <!-- 未登录 -->
- <template v-if="!isLoggedIn">
- <view class="empty-state">
- <text class="empty-icon">💎</text>
- <text class="empty-title">登录以查看家庭CF值</text>
- <text class="empty-desc">CF值是家庭共享的平台积分,购买商品、参与活动即可获得</text>
- <button class="login-btn" @click="goLogin">去登录</button>
- </view>
- </template>
- <!-- 已登录 -->
- <template v-else>
- <!-- 余额卡片 -->
- <view class="balance-card">
- <view class="balance-label">家庭CF值余额</view>
- <view class="balance-value">{{ balance.available }}</view>
- <view class="balance-unit">CF值(1元=1积分)</view>
- <view class="balance-row">
- <view class="balance-item">
- <text class="balance-item-label">累计获得</text>
- <text class="balance-item-value">{{ balance.totalEarned }}</text>
- </view>
- <view class="balance-item">
- <text class="balance-item-label">已消费</text>
- <text class="balance-item-value">{{ balance.exchanged }}</text>
- </view>
- </view>
- </view>
- <!-- 操作按钮 -->
- <view class="action-row">
- <view class="action-btn" @click="refreshData">
- <text class="action-icon">🔄</text>
- <text class="action-text">刷新</text>
- </view>
- <view class="action-btn" @click="openExchangeModal" v-if="balance.available > 0">
- <text class="action-icon">🎫</text>
- <text class="action-text">兑换优惠券</text>
- </view>
- </view>
- <!-- 流水列表 -->
- <view class="section">
- <view class="section-header">
- <text class="section-title">流水记录</text>
- <text class="section-more" @click="loadMoreLogs" v-if="hasMore">加载更多</text>
- </view>
- <view class="log-list" v-if="logs.length > 0">
- <view class="log-item" v-for="log in logs" :key="log.id">
- <view class="log-left">
- <text class="log-type">{{ logTypeLabel(log.type) }}</text>
- <text class="log-remark">{{ log.remark || log.refType }}</text>
- </view>
- <view class="log-right">
- <text class="log-amount" :class="log.amount > 0 ? 'log-plus' : 'log-minus'">
- {{ log.amount > 0 ? '+' : '' }}{{ log.amount }}
- </text>
- <text class="log-time">{{ formatTime(log.createdAt) }}</text>
- </view>
- </view>
- </view>
- <view class="empty-logs" v-else>
- <text>暂无流水记录</text>
- </view>
- </view>
- </template>
- <!-- 兑换优惠券弹窗 -->
- <view class="modal-mask" v-if="showExchangeModal" @click="showExchangeModal = false">
- <view class="exchange-modal" @click.stop>
- <view class="modal-header">
- <text class="modal-title">兑换优惠券</text>
- <text class="modal-close" @click="showExchangeModal = false">×</text>
- </view>
- <view class="modal-body">
- <view class="coupon-list" v-if="exchangeableCoupons.length > 0">
- <view class="coupon-item" v-for="coupon in exchangeableCoupons" :key="coupon.id" @click="doExchange(coupon)">
- <view class="coupon-info">
- <text class="coupon-name">{{ coupon.name }}</text>
- <text class="coupon-desc">{{ couponDesc(coupon) }}</text>
- </view>
- <view class="coupon-price">{{ coupon.pointsPrice }} CF值</view>
- </view>
- </view>
- <view class="empty-coupons" v-else>
- <text>暂无可兑换优惠券</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { getFamilyPlatformBalance, getFamilyPlatformLogs, getExchangeableCoupons, exchangeCouponByCf } from '@/utils/api.js'
- export default {
- data() {
- return {
- isLoggedIn: false,
- balance: { available: 0, totalEarned: 0, exchanged: 0, frozen: 0 },
- logs: [],
- page: 1,
- size: 20,
- hasMore: false,
- exchangeRecords: [],
- showExchangeModal: false,
- exchangeableCoupons: []
- }
- },
- onLoad() {
- this.checkLogin()
- this.loadBalance()
- this.loadLogs()
- },
- onShow() {
- if (this.isLoggedIn) this.loadBalance()
- },
- methods: {
- checkLogin() {
- const token = uni.getStorageSync('token')
- this.isLoggedIn = !!token
- },
- goLogin() {
- uni.navigateTo({ url: '/pages/login/login' })
- },
- async loadBalance() {
- try {
- const res = await getFamilyPlatformBalance()
- if (res.code === 200 && res.data) {
- this.balance = res.data
- }
- } catch (e) {
- console.error('加载余额失败', e)
- }
- },
- async loadLogs() {
- try {
- const res = await getFamilyPlatformLogs({ page: this.page, size: this.size })
- if (res.code === 200 && res.data) {
- if (this.page === 1) {
- this.logs = res.data.records || []
- } else {
- this.logs = this.logs.concat(res.data.records || [])
- }
- this.hasMore = this.logs.length < (res.data.total || 0)
- }
- } catch (e) {
- console.error('加载流水失败', e)
- }
- },
- loadMoreLogs() {
- if (this.hasMore) {
- this.page++
- this.loadLogs()
- }
- },
- async loadExchangeRecords() {
- try {
- const res = await getFamilyPlatformLogs({ page: 1, size: 50, type: 'coupon_exchange' })
- if (res.code === 200) {
- this.exchangeRecords = res.data?.records || []
- }
- } catch (e) { console.error(e) }
- },
- refreshData() {
- this.page = 1
- this.loadBalance()
- this.loadLogs()
- },
- async openExchangeModal() {
- this.showExchangeModal = true
- try {
- const res = await getExchangeableCoupons()
- if (res.code === 200) {
- this.exchangeableCoupons = res.data || []
- }
- } catch (e) {
- console.error('加载可兑换优惠券失败', e)
- }
- },
- async doExchange(coupon) {
- if (coupon.pointsPrice > this.balance.available) {
- uni.showToast({ title: 'CF值不足', icon: 'none' })
- return
- }
- uni.showLoading({ title: '兑换中...' })
- try {
- const res = await exchangeCouponByCf({ couponId: coupon.id })
- uni.hideLoading()
- if (res.code === 200) {
- uni.showToast({ title: '兑换成功', icon: 'success' })
- this.showExchangeModal = false
- this.loadBalance()
- } else {
- uni.showToast({ title: res.message || '兑换失败', icon: 'none' })
- }
- } catch (e) {
- uni.hideLoading()
- uni.showToast({ title: '兑换失败', icon: 'none' })
- }
- },
- logTypeLabel(type) {
- const map = {
- earn: '获得', spend: '消费', freeze: '冻结',
- unfreeze: '解冻', withdraw: '提现', adjust: '调整', migration: '迁移'
- }
- return map[type] || type
- },
- couponDesc(coupon) {
- if (coupon.type === 'DISCOUNT') {
- return (coupon.discountRate / 100).toFixed(1) + '折'
- }
- return '立减' + (coupon.value / 100).toFixed(2) + '元'
- },
- formatTime(dateStr) {
- if (!dateStr) return ''
- const d = new Date(dateStr)
- const m = d.getMonth() + 1
- const day = d.getDate()
- const h = d.getHours()
- const min = String(d.getMinutes()).padStart(2, '0')
- return m + '/' + day + ' ' + h + ':' + min
- }
- }
- }
- </script>
- <style scoped>
- .container {
- min-height: 100vh;
- background: #f5f6fa;
- padding-bottom: 40rpx;
- }
- .empty-state {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 200rpx 40rpx;
- }
- .empty-icon {
- font-size: 100rpx;
- margin-bottom: 20rpx;
- }
- .empty-title {
- font-size: 32rpx;
- color: #333;
- font-weight: 600;
- margin-bottom: 12rpx;
- }
- .empty-desc {
- font-size: 26rpx;
- color: #999;
- margin-bottom: 40rpx;
- text-align: center;
- }
- .login-btn {
- width: 280rpx;
- height: 80rpx;
- line-height: 80rpx;
- background: linear-gradient(135deg, #667eea, #764ba2);
- color: #fff;
- border-radius: 40rpx;
- font-size: 28rpx;
- border: none;
- }
- .balance-card {
- margin: 30rpx;
- padding: 40rpx 30rpx;
- background: linear-gradient(135deg, #667eea, #764ba2);
- border-radius: 24rpx;
- color: #fff;
- }
- .balance-label {
- font-size: 26rpx;
- opacity: 0.8;
- margin-bottom: 10rpx;
- }
- .balance-value {
- font-size: 72rpx;
- font-weight: 700;
- line-height: 1;
- margin-bottom: 8rpx;
- }
- .balance-unit {
- font-size: 22rpx;
- opacity: 0.7;
- margin-bottom: 30rpx;
- }
- .balance-row {
- display: flex;
- justify-content: space-around;
- border-top: 1rpx solid rgba(255,255,255,0.2);
- padding-top: 20rpx;
- }
- .balance-item {
- text-align: center;
- }
- .balance-item-label {
- font-size: 22rpx;
- opacity: 0.7;
- display: block;
- margin-bottom: 6rpx;
- }
- .balance-item-value {
- font-size: 28rpx;
- font-weight: 600;
- }
- .action-row {
- display: flex;
- margin: 0 30rpx 20rpx;
- gap: 20rpx;
- }
- .action-btn {
- flex: 1;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 24rpx;
- background: #fff;
- border-radius: 16rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .action-icon {
- font-size: 36rpx;
- margin-bottom: 8rpx;
- }
- .action-text {
- font-size: 26rpx;
- color: #333;
- }
- .section {
- margin: 20rpx 30rpx;
- }
- .section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 16rpx;
- }
- .section-title {
- font-size: 30rpx;
- font-weight: 600;
- color: #333;
- }
- .section-more {
- font-size: 24rpx;
- color: #667eea;
- }
- .log-list {
- background: #fff;
- border-radius: 16rpx;
- overflow: hidden;
- }
- .log-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 24rpx 30rpx;
- border-bottom: 1rpx solid #f0f0f0;
- }
- .log-item:last-child {
- border-bottom: none;
- }
- .log-left {
- flex: 1;
- margin-right: 20rpx;
- }
- .log-type {
- font-size: 26rpx;
- font-weight: 600;
- color: #333;
- display: block;
- margin-bottom: 4rpx;
- }
- .log-remark {
- font-size: 22rpx;
- color: #999;
- }
- .log-right {
- text-align: right;
- }
- .log-amount {
- font-size: 28rpx;
- font-weight: 600;
- display: block;
- }
- .log-plus { color: #52c41a; }
- .log-minus { color: #ff4d4f; }
- .log-time {
- font-size: 20rpx;
- color: #bbb;
- margin-top: 4rpx;
- display: block;
- }
- .empty-logs {
- text-align: center;
- padding: 60rpx;
- color: #999;
- font-size: 26rpx;
- background: #fff;
- border-radius: 16rpx;
- }
- .exchange-modal {
- background: #fff;
- border-radius: 24rpx 24rpx 0 0;
- max-height: 80vh;
- display: flex;
- flex-direction: column;
- }
- .modal-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx;
- border-bottom: 1rpx solid #f0f0f0;
- }
- .modal-title {
- font-size: 32rpx;
- font-weight: 600;
- color: #333;
- }
- .modal-close {
- font-size: 40rpx;
- color: #999;
- line-height: 1;
- }
- .modal-body {
- flex: 1;
- overflow-y: auto;
- padding: 20rpx 30rpx;
- }
- .coupon-list {
- display: flex;
- flex-direction: column;
- gap: 20rpx;
- }
- .coupon-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 24rpx;
- background: #f8f9ff;
- border-radius: 16rpx;
- border: 1rpx solid #e8eaff;
- }
- .coupon-info {
- flex: 1;
- margin-right: 20rpx;
- }
- .coupon-name {
- font-size: 28rpx;
- font-weight: 600;
- color: #333;
- display: block;
- }
- .coupon-desc {
- font-size: 22rpx;
- color: #999;
- margin-top: 4rpx;
- display: block;
- }
- .coupon-price {
- font-size: 26rpx;
- color: #667eea;
- font-weight: 600;
- white-space: nowrap;
- }
- .empty-coupons {
- text-align: center;
- padding: 60rpx;
- color: #999;
- font-size: 26rpx;
- }
- </style>
|