Files
JayuCloud/YumiNail-Frontend/src/views/VipCenterView.vue
T

192 lines
8.3 KiB
Vue
Raw Normal View History

<template>
<div class="vip-center">
<header class="vip-header">
<button class="back-btn" type="button" @click="router.back()">‹</button>
<div>
<p>VIP 中心</p>
<h1>{{ asset?.vipLevel || '普通' }}</h1>
</div>
</header>
<main class="vip-main">
<section class="balance-panel">
<div>
<span>当前余额</span>
<strong>¥{{ money(asset?.balance) }}</strong>
</div>
<div>
<span>累计充值</span>
<strong>¥{{ money(asset?.totalRechargeAmount) }}</strong>
</div>
</section>
<a-button type="primary" size="large" block @click="rechargeOpen = true">
去充值 / 查看充值说明
</a-button>
<section class="vip-section">
<h2>会员信息</h2>
<div class="info-grid">
<div>
<span>等级</span>
<strong>{{ asset?.vipLevel || '普通' }}</strong>
</div>
<div>
<span>最近充值</span>
<strong>{{ formatTime(asset?.lastRechargeTime) }}</strong>
</div>
<div>
<span>生效时间</span>
<strong>{{ formatTime(asset?.vipStartTime) }}</strong>
</div>
<div>
<span>等级来源</span>
<strong>{{ asset?.manualOverride ? '后台指定' : '自动计算' }}</strong>
</div>
</div>
<p class="benefit">{{ asset?.benefitInfo || '暂无额外权益说明' }}</p>
</section>
<section class="vip-section">
<h2>余额变动</h2>
<a-spin :spinning="loading">
<div v-if="history.length" class="history-list">
<article v-for="item in history" :key="String(item.id)" class="history-row">
<div>
<strong>{{ sceneText(item.changeScene || item.type) }}</strong>
<span>{{ formatTime(item.changeTime) }}</span>
<em v-if="item.remark">{{ item.remark }}</em>
</div>
<b :class="{ income: Number(item.amount) > 0 }">
{{ Number(item.amount) > 0 ? '+' : '' }}¥{{ money(item.amount) }}
</b>
</article>
</div>
<a-empty v-else description="暂无余额变动" />
</a-spin>
</section>
</main>
<a-modal v-model:open="rechargeOpen" title="充值档位展示" :footer="null">
<div v-if="plans.length" class="plan-list">
<article v-for="plan in plans" :key="String(plan.id)" class="plan-card">
<div>
<strong>{{ plan.title }}</strong>
<span>{{ plan.vipLevel }}</span>
</div>
<b>充 {{ money(plan.rechargeAmount) }} 送 {{ money(plan.giftAmount) }}</b>
<p>{{ plan.description || '该档位仅展示,暂不发起支付。' }}</p>
</article>
</div>
<a-empty v-else description="暂无可展示充值档位" />
</a-modal>
</div>
</template>
<script setup lang="ts">
/**
* VipCenterView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
2026-05-23 18:44:57 +08:00
/**
* Purpose: BalanceHistoryItem supports VipCenterView.vue by holding or executing the balance history item page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { userApi, type BalanceHistoryItem, type UserAssetVO, type VipRechargePlanVO } from '@/api/user'
2026-05-23 18:44:57 +08:00
/**
* Purpose: router supports VipCenterView.vue by holding or executing the router page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const router = useRouter()
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
2026-05-23 18:44:57 +08:00
/**
* Purpose: asset supports VipCenterView.vue by holding or executing the asset page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const asset = ref<UserAssetVO | null>(null)
2026-05-23 18:44:57 +08:00
/**
* Purpose: history supports VipCenterView.vue by holding or executing the history page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const history = ref<BalanceHistoryItem[]>([])
2026-05-23 18:44:57 +08:00
/**
* Purpose: plans supports VipCenterView.vue by holding or executing the plans page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const plans = ref<VipRechargePlanVO[]>([])
/** rechargeOpen is a reactive state variable used by the template and event handlers. */
const rechargeOpen = ref(false)
/** money is a local helper used by this page script. */
const money = (value?: number | string) => Number(value || 0).toFixed(2)
/** formatTime is a local helper used by this page script. */
const formatTime = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : '--'
/** sceneText is a local helper used by this page script. */
const sceneText = (scene?: string) => {
const map: Record<string, string> = {
MANUAL_RECHARGE: '手工充值',
MANUAL_DEDUCT: '手工扣减',
ORDER_PAY: '订单消费',
ORDER_REFUND: '订单退款',
RECHARGE: '充值',
CONSUME: '消费'
}
return map[scene || ''] || scene || '余额变动'
}
/** loadData is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadData = async () => {
loading.value = true
try {
const [assetRes, historyRes] = await Promise.all([
userApi.getMyAsset(),
userApi.getMyBalanceHistory()
])
asset.value = assetRes
history.value = historyRes || []
plans.value = await userApi.listMyVipRechargePlans().catch(() => [])
} catch (error: any) {
message.error(error?.message || '获取 VIP 信息失败')
} finally {
loading.value = false
}
}
onMounted(loadData)
</script>
<style scoped>
.vip-center { min-height: 100vh; background: #f6f7f9; color: #24242a; }
.vip-header { display: flex; gap: 16px; align-items: center; padding: 18px 18px 28px; color: #fff; background: linear-gradient(135deg, #2b2522, #896b48); }
.vip-header p { margin: 0 0 4px; opacity: .78; }
.vip-header h1 { margin: 0; font-size: 30px; font-weight: 700; }
.back-btn { width: 36px; height: 36px; border: 0; border-radius: 18px; background: rgba(255,255,255,.18); color: #fff; font-size: 28px; line-height: 1; }
.vip-main { padding: 16px; display: grid; gap: 14px; }
.balance-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; overflow: hidden; border-radius: 8px; background: #e5e0d7; }
.balance-panel > div { padding: 18px; background: #fff; }
.balance-panel span, .info-grid span, .history-row span { display: block; color: #7a7d85; font-size: 12px; }
.balance-panel strong { display: block; margin-top: 8px; font-size: 24px; }
.vip-section { padding: 18px; border-radius: 8px; background: #fff; }
.vip-section h2 { margin: 0 0 14px; font-size: 17px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.info-grid strong { display: block; margin-top: 5px; font-size: 14px; }
.benefit { margin: 16px 0 0; padding-top: 14px; border-top: 1px solid #eef0f3; color: #5f626a; }
.history-list { display: grid; gap: 12px; }
.history-row { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid #f0f1f3; }
.history-row:last-child { border-bottom: 0; padding-bottom: 0; }
.history-row em { display: block; margin-top: 4px; color: #9699a1; font-style: normal; font-size: 12px; }
.history-row b { color: #2f333a; white-space: nowrap; }
.history-row b.income { color: #0f8f63; }
.plan-list { display: grid; gap: 12px; }
.plan-card { padding: 14px; border-radius: 8px; border: 1px solid #eee2d6; background: #fffaf5; }
.plan-card div { display: flex; justify-content: space-between; gap: 12px; }
.plan-card span { color: #9a6a3b; }
.plan-card b { display: block; margin-top: 8px; font-size: 18px; }
.plan-card p { margin: 8px 0 0; color: #777; }
</style>