init: 初始化
This commit is contained in:
@@ -1,84 +1,61 @@
|
||||
<template>
|
||||
<view class="card-shop">
|
||||
<!-- Section header -->
|
||||
<view class="section-header">
|
||||
<text class="section-title">会员卡</text>
|
||||
<text class="section-subtitle">选择适合您的套餐</text>
|
||||
<text class="section-action" @tap="goToAllCards">全部</text>
|
||||
</view>
|
||||
|
||||
<!-- Loading skeleton -->
|
||||
<scroll-view
|
||||
v-if="loading"
|
||||
scroll-x
|
||||
class="cards-scroll"
|
||||
:show-scrollbar="false"
|
||||
>
|
||||
<view class="cards-row">
|
||||
<view
|
||||
v-for="i in 3"
|
||||
:key="i"
|
||||
class="card-item skeleton-card"
|
||||
/>
|
||||
<view v-if="loading" class="card-list">
|
||||
<view
|
||||
v-for="i in 3"
|
||||
:key="i"
|
||||
class="card-row skeleton-row"
|
||||
>
|
||||
<view class="skeleton-thumb" />
|
||||
<view class="skeleton-info">
|
||||
<view class="skeleton-line skeleton-line--title" />
|
||||
<view class="skeleton-line skeleton-line--sub" />
|
||||
<view class="skeleton-line skeleton-line--price" />
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- Card list -->
|
||||
<scroll-view
|
||||
v-else-if="cardTypes.length"
|
||||
scroll-x
|
||||
class="cards-scroll"
|
||||
:show-scrollbar="false"
|
||||
>
|
||||
<view class="cards-row">
|
||||
<view
|
||||
v-for="card in cardTypes"
|
||||
:key="card.id"
|
||||
class="card-item"
|
||||
:class="cardItemClass(card)"
|
||||
@tap="goToDetail(card.id)"
|
||||
>
|
||||
<!-- Card header band -->
|
||||
<view class="card-header" :class="cardHeaderClass(card)">
|
||||
<text class="card-type-label">{{ typeLabel(card) }}</text>
|
||||
<view v-else-if="cardTypes.length" class="card-list">
|
||||
<view
|
||||
v-for="card in cardTypes"
|
||||
:key="card.id"
|
||||
class="card-row"
|
||||
@tap="goToDetail(card.id)"
|
||||
>
|
||||
<!-- Thumbnail -->
|
||||
<view class="card-thumb" :class="thumbClass(card)">
|
||||
<view class="thumb-fallback">
|
||||
<text class="thumb-name">{{ truncate(card.name, 8) }}</text>
|
||||
<text class="thumb-price">¥{{ formatPrice(card.price) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Card name -->
|
||||
<!-- Card info -->
|
||||
<view class="card-info">
|
||||
<text class="card-name">{{ card.name }}</text>
|
||||
|
||||
<!-- Pricing -->
|
||||
<text class="card-validity">有效期:{{ card.durationDays }} 天</text>
|
||||
<view class="price-row">
|
||||
<text class="price-current">¥{{ formatPrice(card.price) }}</text>
|
||||
<text class="price-label">价格:</text>
|
||||
<text class="price-symbol">¥</text>
|
||||
<text class="price-current">{{ formatPrice(card.price) }}</text>
|
||||
<text
|
||||
v-if="card.originalPrice && card.originalPrice > card.price"
|
||||
class="price-original"
|
||||
>
|
||||
¥{{ formatPrice(card.originalPrice) }}
|
||||
原价:¥{{ formatPrice(card.originalPrice) }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<!-- Description -->
|
||||
<text v-if="card.description" class="card-desc">
|
||||
{{ truncate(card.description, 40) }}
|
||||
</text>
|
||||
|
||||
<!-- Duration / Times -->
|
||||
<view class="card-meta">
|
||||
<view v-if="card.totalTimes" class="meta-item">
|
||||
<text class="meta-value">{{ card.totalTimes }}</text>
|
||||
<text class="meta-label">次</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-value">{{ card.durationDays }}</text>
|
||||
<text class="meta-label">天有效</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Buy button -->
|
||||
<view class="buy-btn">
|
||||
<text class="buy-btn-text">立即购买</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- Empty -->
|
||||
<view v-else class="empty-state">
|
||||
@@ -120,25 +97,15 @@ function goToDetail(id: string) {
|
||||
uni.navigateTo({ url: `/pages/card/detail?id=${id}` })
|
||||
}
|
||||
|
||||
function typeLabel(card: CardType): string {
|
||||
const map: Record<CardTypeCategory, string> = {
|
||||
[CardTypeCategory.TIMES]: '次卡',
|
||||
[CardTypeCategory.DURATION]: '月卡',
|
||||
[CardTypeCategory.TRIAL]: '体验',
|
||||
}
|
||||
return map[card.type] ?? '会员卡'
|
||||
function goToAllCards() {
|
||||
// Navigate to all cards page or scroll behavior
|
||||
uni.navigateTo({ url: '/pages/card/detail?showAll=1' })
|
||||
}
|
||||
|
||||
function cardItemClass(card: CardType): string {
|
||||
if (card.type === CardTypeCategory.TRIAL) return 'card-item--trial'
|
||||
if (card.type === CardTypeCategory.DURATION) return 'card-item--duration'
|
||||
return ''
|
||||
}
|
||||
|
||||
function cardHeaderClass(card: CardType): string {
|
||||
if (card.type === CardTypeCategory.TRIAL) return 'header--trial'
|
||||
if (card.type === CardTypeCategory.DURATION) return 'header--duration'
|
||||
return 'header--times'
|
||||
function thumbClass(card: CardType): string {
|
||||
if (card.type === CardTypeCategory.TRIAL) return 'thumb--trial'
|
||||
if (card.type === CardTypeCategory.DURATION) return 'thumb--duration'
|
||||
return 'thumb--times'
|
||||
}
|
||||
|
||||
function truncate(str: string, maxLen: number): string {
|
||||
@@ -148,166 +115,208 @@ function truncate(str: string, maxLen: number): string {
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.card-shop {
|
||||
margin: 24rpx 0 0;
|
||||
padding-bottom: 40rpx;
|
||||
background: #ffffff;
|
||||
margin-top: 16rpx;
|
||||
padding-bottom: 20rpx;
|
||||
}
|
||||
|
||||
/* ── Section header ── */
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 16rpx;
|
||||
padding: 0 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 32rpx 32rpx 20rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-size: 36rpx;
|
||||
font-weight: 700;
|
||||
color: #1a1a2e;
|
||||
color: #222;
|
||||
}
|
||||
|
||||
.section-subtitle {
|
||||
font-size: 24rpx;
|
||||
.section-action {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
padding: 8rpx 24rpx;
|
||||
border: 1rpx solid #ddd;
|
||||
border-radius: 24rpx;
|
||||
}
|
||||
|
||||
.cards-scroll {
|
||||
width: 100%;
|
||||
/* ── Card list ── */
|
||||
.card-list {
|
||||
padding: 0 32rpx;
|
||||
}
|
||||
|
||||
.cards-row {
|
||||
.card-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 20rpx;
|
||||
padding: 8rpx 24rpx 16rpx;
|
||||
width: max-content;
|
||||
align-items: center;
|
||||
gap: 24rpx;
|
||||
padding: 24rpx 0;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* --- Individual Card --- */
|
||||
.card-item {
|
||||
width: 280rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 16rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.10);
|
||||
/* ── Thumbnail ── */
|
||||
.card-thumb {
|
||||
width: 200rpx;
|
||||
height: 140rpx;
|
||||
border-radius: 12rpx;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.thumb-fallback {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-shrink: 0;
|
||||
|
||||
&--trial {
|
||||
border: 2rpx solid #c9a87c;
|
||||
}
|
||||
|
||||
&--duration {
|
||||
border: 2rpx solid #9b59b6;
|
||||
}
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8rpx;
|
||||
padding: 12rpx;
|
||||
}
|
||||
|
||||
.skeleton-card {
|
||||
height: 360rpx;
|
||||
.thumb--times .thumb-fallback {
|
||||
background: linear-gradient(135deg, #3a3a3a, #555);
|
||||
}
|
||||
|
||||
.thumb--duration .thumb-fallback {
|
||||
background: linear-gradient(135deg, #6c3483, #9b59b6);
|
||||
}
|
||||
|
||||
.thumb--trial .thumb-fallback {
|
||||
background: linear-gradient(135deg, #7d6608, #c9a87c);
|
||||
}
|
||||
|
||||
.thumb-name {
|
||||
font-size: 22rpx;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
text-align: center;
|
||||
line-height: 1.3;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.thumb-price {
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
/* ── Card info ── */
|
||||
.card-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.card-name {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: #222;
|
||||
margin-bottom: 8rpx;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.card-validity {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.price-row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 4rpx;
|
||||
}
|
||||
|
||||
.price-label {
|
||||
font-size: 24rpx;
|
||||
color: #e53935;
|
||||
}
|
||||
|
||||
.price-symbol {
|
||||
font-size: 24rpx;
|
||||
color: #e53935;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.price-current {
|
||||
font-size: 40rpx;
|
||||
font-weight: 800;
|
||||
color: #e53935;
|
||||
}
|
||||
|
||||
.price-original {
|
||||
font-size: 22rpx;
|
||||
color: #bbb;
|
||||
text-decoration: line-through;
|
||||
margin-left: 12rpx;
|
||||
}
|
||||
|
||||
/* ── Skeleton ── */
|
||||
.skeleton-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 24rpx;
|
||||
padding: 24rpx 0;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.skeleton-thumb {
|
||||
width: 200rpx;
|
||||
height: 140rpx;
|
||||
border-radius: 12rpx;
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 400% 100%;
|
||||
animation: shimmer 1.4s infinite;
|
||||
}
|
||||
|
||||
.skeleton-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.skeleton-line {
|
||||
height: 24rpx;
|
||||
border-radius: 6rpx;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 400% 100%;
|
||||
animation: shimmer 1.4s infinite;
|
||||
|
||||
&--title {
|
||||
width: 70%;
|
||||
height: 30rpx;
|
||||
}
|
||||
|
||||
&--sub {
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
&--price {
|
||||
width: 50%;
|
||||
height: 36rpx;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% { background-position: 100% 0; }
|
||||
100% { background-position: -100% 0; }
|
||||
}
|
||||
|
||||
.card-header {
|
||||
padding: 12rpx 20rpx;
|
||||
}
|
||||
|
||||
.header--times { background: linear-gradient(90deg, #1a1a2e, #2d2d5e); }
|
||||
.header--duration { background: linear-gradient(90deg, #6c3483, #9b59b6); }
|
||||
.header--trial { background: linear-gradient(90deg, #7d6608, #c9a87c); }
|
||||
|
||||
.card-type-label {
|
||||
font-size: 22rpx;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
letter-spacing: 2rpx;
|
||||
}
|
||||
|
||||
.card-name {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #1a1a2e;
|
||||
padding: 20rpx 20rpx 8rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.price-row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 12rpx;
|
||||
padding: 0 20rpx 12rpx;
|
||||
}
|
||||
|
||||
.price-current {
|
||||
font-size: 40rpx;
|
||||
font-weight: 800;
|
||||
color: #c9a87c;
|
||||
}
|
||||
|
||||
.price-original {
|
||||
font-size: 24rpx;
|
||||
color: #bbb;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.card-desc {
|
||||
font-size: 22rpx;
|
||||
color: #888;
|
||||
padding: 0 20rpx 16rpx;
|
||||
line-height: 1.5;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.card-meta {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
padding: 0 20rpx 20rpx;
|
||||
flex: 1;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.meta-item {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 4rpx;
|
||||
}
|
||||
|
||||
.meta-value {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.meta-label {
|
||||
font-size: 22rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.buy-btn {
|
||||
margin: 0 20rpx 24rpx;
|
||||
background: #1a1a2e;
|
||||
border-radius: 40rpx;
|
||||
padding: 16rpx 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.buy-btn-text {
|
||||
font-size: 26rpx;
|
||||
font-weight: 600;
|
||||
color: #c9a87c;
|
||||
}
|
||||
|
||||
/* ── Empty state ── */
|
||||
.empty-state {
|
||||
padding: 60rpx;
|
||||
padding: 80rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
Reference in New Issue
Block a user