Files
JayuCloud/JY-Artist-Frontend/src/views/VipCenterView.vue
T

953 lines
22 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed, onMounted, ref, shallowRef } from 'vue'
import { useRouter } from 'vue-router'
import {
CreditCardOutlined,
CrownOutlined,
GiftOutlined,
HistoryOutlined,
LeftOutlined,
PayCircleOutlined,
PercentageOutlined,
SafetyCertificateOutlined,
ScissorOutlined,
ShoppingOutlined,
StarFilled,
TrophyOutlined
} from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { userApi, type BalanceHistoryItem, type UserAssetVO, type VipRechargePlanVO } from '@/api/user'
const router = useRouter()
const loading = shallowRef(false)
const rechargeOpen = shallowRef(false)
const visibleHistoryCount = shallowRef(3)
const asset = ref<UserAssetVO | null>(null)
const history = ref<BalanceHistoryItem[]>([])
const plans = ref<VipRechargePlanVO[]>([])
const selectedPlan = ref<VipRechargePlanVO | null>(null)
const rechargeSectionRef = ref<HTMLElement | null>(null)
interface LevelStep {
name: string
amount: number
}
const levelSteps: [LevelStep, ...LevelStep[]] = [
{ name: '普通会员', amount: 0 },
{ name: '玫瑰金会员', amount: 1000 },
{ name: '钻石会员', amount: 5000 }
]
const money = (value?: number | string) => {
const amount = Number(value || 0)
return Number.isFinite(amount)
? amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
: '0.00'
}
const formatTime = (value?: string) => value ? value.replace('T', ' ').slice(0, 16) : '--'
const sceneText = (scene?: string) => {
const map: Record<string, string> = {
MANUAL_RECHARGE: '手工充值',
MANUAL_DEDUCT: '手工扣减',
ORDER_PAY: '订单消费',
ORDER_REFUND: '订单退款',
RECHARGE: '会员充值',
CONSUME: '余额消费'
}
return map[scene || ''] || scene || '余额变动'
}
const sceneIcon = (item: BalanceHistoryItem) => {
const scene = item.changeScene || item.type || ''
if (Number(item.amount) > 0 || scene.includes('RECHARGE') || scene.includes('REFUND')) {
return PayCircleOutlined
}
if (scene.includes('ORDER') || scene.includes('CONSUME')) {
return ScissorOutlined
}
return HistoryOutlined
}
const memberLevel = computed(() => asset.value?.vipLevel || '普通会员')
const totalRecharge = computed(() => Number(asset.value?.totalRechargeAmount || 0))
const balanceAmount = computed(() => Number(asset.value?.balance || 0))
const sortedPlans = computed(() => [...plans.value].sort((left, right) => {
const sortDelta = Number(left.sortOrder || 0) - Number(right.sortOrder || 0)
return sortDelta || Number(left.rechargeAmount || 0) - Number(right.rechargeAmount || 0)
}))
const visibleHistory = computed(() => history.value.slice(0, visibleHistoryCount.value))
const canLoadMoreHistory = computed(() => visibleHistoryCount.value < history.value.length)
const currentStep = computed(() => {
return [...levelSteps].reverse().find(step => totalRecharge.value >= step.amount) || levelSteps[0]
})
const nextStep = computed(() => levelSteps.find(step => step.amount > totalRecharge.value))
const levelProgress = computed(() => {
const next = nextStep.value
if (!next) return 100
const current = currentStep.value
const range = Math.max(next.amount - current.amount, 1)
return Math.min(100, Math.max(8, ((totalRecharge.value - current.amount) / range) * 100))
})
const nextLevelText = computed(() => nextStep.value ? `下一等级:${nextStep.value.name}` : '已达最高等级')
const remainingAmountText = computed(() => {
const next = nextStep.value
if (!next) return '继续保持你的专属礼遇'
return `再充值 ¥${money(Math.max(next.amount - totalRecharge.value, 0))} 可升级`
})
const validityText = computed(() => {
const start = formatTime(asset.value?.vipStartTime)
const expire = formatTime(asset.value?.vipExpireTime)
if (start === '--' && expire === '--') return '长期有效'
if (expire === '--') return `${start} 起生效`
return `${start} - ${expire}`
})
const benefitCards = computed(() => [
{
icon: GiftOutlined,
title: '生日礼遇',
desc: '生日月专属美甲套装',
tone: 'rose'
},
{
icon: SafetyCertificateOutlined,
title: '优先预约',
desc: '热门时段优先锁定档期',
tone: 'gold'
},
{
icon: PercentageOutlined,
title: '专属优惠',
desc: asset.value?.benefitInfo || '会员专属折扣权益',
tone: 'slate'
},
{
icon: CrownOutlined,
title: '护理礼遇',
desc: '精选护理权益持续更新',
tone: 'cream'
}
])
const planTag = (index: number) => {
if (index === 0) return '超值'
if (index === 1) return '最佳选择'
return '尊享'
}
const openPlan = (plan: VipRechargePlanVO) => {
selectedPlan.value = plan
rechargeOpen.value = true
}
const scrollToRecharge = () => {
rechargeSectionRef.value?.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
const loadMoreHistory = () => {
visibleHistoryCount.value += 3
}
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>
<template>
<div class="vip-center">
<header class="vip-topbar">
<button class="topbar-button" type="button" aria-label="返回" @click="router.back()">
<LeftOutlined />
</button>
<h1>VIP中心</h1>
<button class="topbar-button" type="button" aria-label="购物车" @click="router.push('/cart')">
<ShoppingOutlined />
</button>
</header>
<a-spin :spinning="loading">
<main class="vip-main">
<section class="vip-hero-card">
<div class="hero-glow hero-glow--top"></div>
<div class="hero-glow hero-glow--bottom"></div>
<div class="hero-content">
<div class="hero-head">
<div>
<span class="vip-kicker">当前会员等级</span>
<h2>{{ memberLevel }} <StarFilled /></h2>
</div>
<div class="fingerprint-badge">
<CrownOutlined />
</div>
</div>
<div class="hero-stats">
<div>
<span>可用余额</span>
<strong><small>¥</small>{{ money(balanceAmount) }}</strong>
</div>
<div>
<span>累计充值</span>
<strong><small>¥</small>{{ money(totalRecharge) }}</strong>
</div>
</div>
<div class="level-progress">
<div>
<span>等级进度</span>
<span>{{ nextLevelText }}</span>
</div>
<div class="progress-track">
<i :style="{ width: `${levelProgress}%` }"></i>
</div>
<p>{{ remainingAmountText }}</p>
</div>
</div>
<TrophyOutlined class="hero-watermark" />
</section>
<section class="vip-section">
<div class="section-head">
<h3>会员特权</h3>
<button type="button" @click="scrollToRecharge">查看全部</button>
</div>
<div class="benefit-grid">
<article
v-for="item in benefitCards"
:key="item.title"
class="benefit-card"
:class="`benefit-card--${item.tone}`"
>
<span class="benefit-icon">
<component :is="item.icon" />
</span>
<strong>{{ item.title }}</strong>
<p>{{ item.desc }}</p>
</article>
</div>
</section>
<section class="vip-section member-info-section">
<div class="section-head">
<h3>会员信息</h3>
</div>
<div class="info-grid">
<article>
<span>生效周期</span>
<strong>{{ validityText }}</strong>
</article>
<article>
<span>最近充值</span>
<strong>{{ formatTime(asset?.lastRechargeTime) }}</strong>
</article>
<article>
<span>等级来源</span>
<strong>{{ asset?.manualOverride ? '后台指定' : '自动计算' }}</strong>
</article>
<article>
<span>当前权益</span>
<strong>{{ asset?.benefitInfo || '暂无额外权益说明' }}</strong>
</article>
</div>
</section>
<section ref="rechargeSectionRef" class="vip-section recharge-section">
<div class="section-head">
<h3>快速充值</h3>
</div>
<div v-if="sortedPlans.length" class="plan-grid">
<article
v-for="(plan, index) in sortedPlans"
:key="String(plan.id)"
class="plan-card"
:class="{ 'plan-card--featured': index === 1 }"
>
<div class="plan-tag" :class="{ 'plan-tag--featured': index === 1 }">
{{ planTag(index) }}
</div>
<span class="plan-title">{{ plan.title || plan.vipLevel }}</span>
<div class="plan-price">
<small>¥</small>
<strong>{{ money(plan.rechargeAmount).replace('.00', '') }}</strong>
</div>
<p>赠送 <b>¥{{ money(plan.giftAmount) }}</b> 奖励金</p>
<button type="button" @click="openPlan(plan)">立即充值</button>
</article>
</div>
<a-empty v-else description="暂无可展示充值档位" />
</section>
<section class="vip-section history-section">
<div class="section-head">
<h3>最近动态</h3>
</div>
<div v-if="visibleHistory.length" class="history-card">
<article
v-for="item in visibleHistory"
:key="String(item.id)"
class="history-row"
>
<span class="history-icon" :class="{ 'history-icon--income': Number(item.amount) > 0 }">
<component :is="sceneIcon(item)" />
</span>
<div class="history-copy">
<strong>{{ sceneText(item.changeScene || item.type) }}</strong>
<span>{{ formatTime(item.changeTime) }}</span>
<em v-if="item.remark">{{ item.remark }}</em>
</div>
<div class="history-amount">
<strong :class="{ income: Number(item.amount) > 0 }">
{{ Number(item.amount) > 0 ? '+' : '' }}¥{{ money(item.amount) }}
</strong>
<span v-if="item.afterBalance !== undefined">余额: ¥{{ money(item.afterBalance) }}</span>
</div>
</article>
</div>
<a-empty v-else description="暂无余额变动" />
<button v-if="canLoadMoreHistory" class="load-more-button" type="button" @click="loadMoreHistory">
加载更多交易记录
</button>
</section>
</main>
</a-spin>
<a-modal v-model:open="rechargeOpen" title="充值档位说明" :footer="null">
<div class="plan-modal" v-if="selectedPlan">
<span class="modal-icon"><CreditCardOutlined /></span>
<h3>{{ selectedPlan.title || selectedPlan.vipLevel }}</h3>
<p>充值 ¥{{ money(selectedPlan.rechargeAmount) }},赠送 ¥{{ money(selectedPlan.giftAmount) }} 奖励金。</p>
<p>{{ selectedPlan.description || '该档位仅展示,暂不发起支付。' }}</p>
</div>
</a-modal>
</div>
</template>
<style scoped>
.vip-center {
--vip-bg: #fff8f4;
--vip-surface: rgba(255, 255, 255, 0.82);
--vip-surface-strong: rgba(255, 255, 255, 0.94);
--vip-surface-low: #fcf2ea;
--vip-surface-mid: #f6ece5;
--vip-surface-high: #f1e6df;
--vip-text: #1f1b17;
--vip-muted: #504444;
--vip-outline: #d4c2c3;
--vip-outline-soft: rgba(212, 194, 195, 0.54);
--vip-primary: #7c5357;
--vip-blush: #e8b4b8;
--vip-blush-soft: #ffdadc;
--vip-blush-dim: #eeb9bd;
--vip-gold: #775a19;
--vip-gold-soft: #fed488;
--vip-neutral: #5e5e5d;
--vip-neutral-soft: #c2c1bf;
--vip-hero-text: #fff8f4;
--vip-shadow: rgba(74, 68, 63, 0.1);
min-height: 100vh;
color: var(--vip-text);
background:
radial-gradient(circle at 84% 0%, rgba(232, 180, 184, 0.38), transparent 34%),
radial-gradient(circle at 4% 18%, rgba(254, 212, 136, 0.34), transparent 30%),
linear-gradient(180deg, var(--vip-bg) 0%, var(--vip-surface-low) 46%, var(--vip-bg) 100%);
}
.vip-topbar {
position: sticky;
top: 0;
z-index: 30;
display: grid;
grid-template-columns: 42px minmax(0, 1fr) 42px;
align-items: center;
width: min(100%, var(--app-mobile-max-width, 480px));
min-height: 64px;
margin: 0 auto;
padding: 8px 20px;
background: rgba(255, 248, 244, 0.86);
box-shadow: 0 8px 28px rgba(74, 68, 63, 0.06);
backdrop-filter: blur(18px);
}
.vip-topbar h1 {
margin: 0;
color: var(--vip-primary);
font-family: Georgia, 'Times New Roman', serif;
font-size: 24px;
font-weight: 700;
line-height: 1.15;
text-align: center;
}
.topbar-button {
display: inline-flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
padding: 0;
border: 0;
border-radius: 999px;
color: var(--vip-primary);
background: var(--vip-surface-strong);
box-shadow: 0 12px 24px rgba(74, 68, 63, 0.08);
cursor: pointer;
}
.topbar-button :deep(.anticon) {
font-size: 21px;
}
.vip-main {
display: grid;
gap: 32px;
width: min(100%, var(--app-mobile-max-width, 480px));
margin: 0 auto;
padding: 22px 20px 42px;
}
.vip-hero-card {
position: relative;
overflow: hidden;
padding: 28px;
border-radius: 32px;
color: var(--vip-hero-text);
background:
linear-gradient(135deg, var(--vip-primary) 0%, var(--vip-blush) 55%, var(--vip-gold-soft) 100%);
box-shadow: 0 26px 54px rgba(124, 83, 87, 0.22);
}
.hero-glow {
position: absolute;
width: 210px;
height: 210px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.13);
filter: blur(18px);
}
.hero-glow--top {
top: -74px;
right: -78px;
}
.hero-glow--bottom {
bottom: -118px;
left: -86px;
background: rgba(254, 212, 136, 0.24);
}
.hero-content {
position: relative;
z-index: 1;
display: grid;
gap: 22px;
}
.hero-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
}
.vip-kicker,
.section-head button,
.plan-title {
font-size: 12px;
font-weight: 800;
line-height: 1.2;
letter-spacing: 0;
text-transform: uppercase;
}
.vip-kicker {
display: block;
margin-bottom: 6px;
opacity: 0.78;
}
.hero-head h2 {
display: flex;
align-items: center;
gap: 8px;
margin: 0;
font-family: Georgia, 'Times New Roman', serif;
font-size: 28px;
font-weight: 700;
line-height: 1.15;
}
.hero-head h2 :deep(.anticon) {
color: var(--vip-gold-soft);
font-size: 18px;
}
.fingerprint-badge {
display: grid;
flex: 0 0 auto;
width: 52px;
height: 52px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.28);
border-radius: 18px;
background: rgba(255, 255, 255, 0.18);
backdrop-filter: blur(12px);
}
.fingerprint-badge :deep(.anticon) {
font-size: 28px;
}
.hero-stats {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
}
.hero-stats > div {
min-width: 0;
padding: 14px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 16px;
background: rgba(255, 255, 255, 0.12);
backdrop-filter: blur(10px);
}
.hero-stats span,
.level-progress span,
.level-progress p {
color: rgba(255, 255, 255, 0.74);
font-size: 12px;
line-height: 1.35;
}
.hero-stats strong {
display: flex;
align-items: baseline;
gap: 3px;
min-width: 0;
margin-top: 6px;
overflow-wrap: anywhere;
color: var(--vip-hero-text);
font-family: Georgia, 'Times New Roman', serif;
font-size: 22px;
line-height: 1.1;
}
.hero-stats small,
.plan-price small {
font-family: inherit;
font-size: 13px;
}
.level-progress {
display: grid;
gap: 8px;
}
.level-progress > div:first-child {
display: flex;
justify-content: space-between;
gap: 10px;
}
.progress-track {
height: 6px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.2);
}
.progress-track i {
display: block;
height: 100%;
border-radius: inherit;
background: var(--vip-hero-text);
box-shadow: 0 0 14px rgba(255, 255, 255, 0.5);
}
.level-progress p {
margin: 0;
}
.hero-watermark {
position: absolute;
right: 20px;
bottom: -26px;
color: rgba(255, 255, 255, 0.1);
font-size: 118px;
}
.vip-section {
display: grid;
gap: 18px;
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.section-head h3 {
margin: 0;
color: var(--vip-text);
font-family: Georgia, 'Times New Roman', serif;
font-size: 24px;
font-weight: 700;
line-height: 1.2;
}
.section-head button {
border: 0;
color: var(--vip-primary);
background: transparent;
cursor: pointer;
}
.benefit-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16px;
}
.benefit-card,
.member-info-section,
.plan-card,
.history-card {
border: 1px solid rgba(212, 194, 195, 0.5);
background: var(--vip-surface);
box-shadow: 0 20px 40px var(--vip-shadow);
backdrop-filter: blur(16px);
}
.benefit-card {
display: grid;
justify-items: center;
gap: 10px;
min-height: 164px;
padding: 20px 14px;
border-radius: 18px;
text-align: center;
}
.benefit-icon {
display: grid;
width: 50px;
height: 50px;
place-items: center;
border-radius: 999px;
font-size: 24px;
}
.benefit-card--rose .benefit-icon {
color: var(--vip-primary);
background: var(--vip-blush-soft);
}
.benefit-card--gold .benefit-icon {
color: var(--vip-gold);
background: rgba(254, 212, 136, 0.72);
}
.benefit-card--slate .benefit-icon {
color: var(--vip-neutral);
background: rgba(194, 193, 191, 0.48);
}
.benefit-card--cream .benefit-icon {
color: var(--vip-primary);
background: var(--vip-surface-high);
}
.benefit-card strong {
color: var(--vip-text);
font-size: 14px;
font-weight: 850;
}
.benefit-card p {
display: -webkit-box;
margin: 0;
overflow: hidden;
color: var(--vip-muted);
font-size: 12px;
line-height: 1.45;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
.member-info-section {
padding: 18px;
border-radius: 24px;
}
.info-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
}
.info-grid article {
min-width: 0;
padding: 13px;
border: 1px solid var(--vip-outline-soft);
border-radius: 16px;
background: rgba(252, 242, 234, 0.78);
}
.info-grid span,
.history-copy span,
.history-copy em,
.history-amount span {
display: block;
color: var(--vip-muted);
font-size: 12px;
line-height: 1.35;
}
.info-grid strong {
display: block;
margin-top: 6px;
overflow-wrap: anywhere;
color: var(--vip-text);
font-size: 13px;
font-weight: 800;
line-height: 1.35;
}
.plan-grid {
display: grid;
gap: 16px;
}
.plan-card {
position: relative;
display: grid;
gap: 13px;
padding: 24px;
border-radius: 24px;
}
.plan-card--featured {
border-color: rgba(119, 90, 25, 0.24);
background: linear-gradient(135deg, rgba(255, 250, 240, 0.92), rgba(254, 212, 136, 0.28));
}
.plan-tag {
justify-self: start;
padding: 5px 11px;
border-radius: 999px;
color: var(--vip-primary);
background: var(--vip-blush-soft);
font-size: 10px;
font-weight: 900;
}
.plan-tag--featured {
position: absolute;
top: -11px;
right: 22px;
color: var(--vip-hero-text);
background: var(--vip-gold);
}
.plan-title {
color: var(--vip-muted);
}
.plan-price {
display: flex;
align-items: baseline;
gap: 5px;
color: var(--vip-primary);
}
.plan-price strong {
font-family: Georgia, 'Times New Roman', serif;
font-size: 40px;
line-height: 1;
}
.plan-card p {
margin: 0;
color: var(--vip-muted);
font-size: 14px;
}
.plan-card p b {
color: var(--vip-primary);
}
.plan-card button {
width: 100%;
min-height: 46px;
border: 0;
border-radius: 999px;
color: var(--vip-hero-text);
background: var(--vip-primary);
font-size: 14px;
font-weight: 850;
cursor: pointer;
box-shadow: 0 14px 28px rgba(124, 83, 87, 0.2);
}
.plan-card--featured button {
background: var(--vip-gold);
}
.history-card {
overflow: hidden;
border-radius: 24px;
}
.history-row {
display: grid;
grid-template-columns: 42px minmax(0, 1fr) auto;
gap: 12px;
align-items: center;
padding: 16px;
border-bottom: 1px solid var(--vip-outline-soft);
}
.history-row:last-child {
border-bottom: 0;
}
.history-icon {
display: grid;
width: 40px;
height: 40px;
place-items: center;
border-radius: 999px;
color: var(--vip-muted);
background: var(--vip-surface-high);
}
.history-icon--income {
color: var(--vip-primary);
background: var(--vip-blush-soft);
}
.history-copy {
min-width: 0;
}
.history-copy strong {
display: block;
overflow: hidden;
color: var(--vip-text);
font-size: 14px;
font-weight: 850;
text-overflow: ellipsis;
white-space: nowrap;
}
.history-copy em {
margin-top: 3px;
overflow: hidden;
font-style: normal;
text-overflow: ellipsis;
white-space: nowrap;
}
.history-amount {
min-width: 88px;
text-align: right;
}
.history-amount strong {
display: block;
color: var(--vip-text);
font-size: 13px;
font-weight: 900;
white-space: nowrap;
}
.history-amount strong.income {
color: var(--vip-gold);
}
.load-more-button {
width: 100%;
min-height: 44px;
border: 0;
border-radius: 16px;
color: var(--vip-primary);
background: rgba(232, 180, 184, 0.22);
font-weight: 850;
cursor: pointer;
}
.plan-modal {
display: grid;
gap: 10px;
text-align: center;
}
.modal-icon {
display: grid;
width: 54px;
height: 54px;
margin: 0 auto;
place-items: center;
border-radius: 999px;
color: var(--vip-primary);
background: var(--vip-blush-soft);
font-size: 25px;
}
.plan-modal h3 {
margin: 4px 0 0;
font-size: 18px;
font-weight: 850;
}
.plan-modal p {
margin: 0;
color: var(--vip-muted);
line-height: 1.65;
}
@media (max-width: 370px) {
.vip-main {
padding-right: 14px;
padding-left: 14px;
}
.vip-hero-card {
padding: 22px;
}
.hero-stats,
.benefit-grid,
.info-grid {
grid-template-columns: 1fr;
}
}
@media (min-width: 768px) {
.plan-grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
</style>