286 lines
6.0 KiB
Vue
286 lines
6.0 KiB
Vue
<template>
|
|
<div class="mobile-container">
|
|
<header class="header">
|
|
<a-button type="text" class="back-btn" @click="router.back()">
|
|
<LeftOutlined />
|
|
</a-button>
|
|
<h1>我的优惠券</h1>
|
|
<div class="placeholder"></div>
|
|
</header>
|
|
|
|
<div class="coupon-section">
|
|
<a-card :bordered="false" class="filter-card">
|
|
<a-segmented
|
|
v-model:value="activeFilter"
|
|
:options="filterOptions"
|
|
class="filter-segmented"
|
|
/>
|
|
</a-card>
|
|
|
|
<a-card v-if="loading" :bordered="false" class="content-card">
|
|
<a-skeleton :paragraph="{ rows: 3 }" />
|
|
</a-card>
|
|
|
|
<a-card v-else-if="coupons.length === 0" :bordered="false" class="content-card">
|
|
<a-empty description="暂无优惠券">
|
|
<a-button type="primary">去领取</a-button>
|
|
</a-empty>
|
|
</a-card>
|
|
|
|
<div v-else class="coupon-list">
|
|
<a-card
|
|
v-for="coupon in filteredCoupons"
|
|
:key="coupon.id"
|
|
class="coupon-card"
|
|
:class="{ 'expired': coupon.status === 3 }"
|
|
>
|
|
<div class="coupon-content">
|
|
<div class="coupon-value">
|
|
{{ coupon.couponType === 1 ? `${coupon.discountValue}折` : `¥${coupon.reduceAmount}` }}
|
|
</div>
|
|
<div class="coupon-info">
|
|
<div class="coupon-name">{{ coupon.couponName }}</div>
|
|
<div class="coupon-condition" v-if="coupon.couponType === 2">
|
|
满{{ coupon.minAmount }}元可用
|
|
</div>
|
|
<div class="coupon-time">
|
|
{{ formatDate(coupon.startTime) }} 至 {{ formatDate(coupon.endTime) }}
|
|
</div>
|
|
<div :class="['coupon-status', getStatusClass(coupon.status)]">
|
|
{{ coupon.statusName }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</a-card>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, computed, onMounted } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { LeftOutlined } from '@ant-design/icons-vue'
|
|
import { message } from 'ant-design-vue'
|
|
import { couponApi } from '@/api/coupon'
|
|
|
|
const router = useRouter()
|
|
|
|
const loading = ref(false)
|
|
const coupons = ref<any[]>([])
|
|
const activeFilter = ref('all')
|
|
|
|
const filterOptions = [
|
|
{ label: '全部', value: 'all' },
|
|
{ label: '未使用', value: 'available' },
|
|
{ label: '已使用', value: 'used' },
|
|
{ label: '已过期', value: 'expired' }
|
|
]
|
|
|
|
const filteredCoupons = computed(() => {
|
|
if (activeFilter.value === 'all') {
|
|
return coupons.value
|
|
} else if (activeFilter.value === 'available') {
|
|
return coupons.value.filter(coupon => coupon.status === 1)
|
|
} else if (activeFilter.value === 'used') {
|
|
return coupons.value.filter(coupon => coupon.status === 2)
|
|
} else if (activeFilter.value === 'expired') {
|
|
return coupons.value.filter(coupon => coupon.status === 3)
|
|
}
|
|
return coupons.value
|
|
})
|
|
|
|
const loadCoupons = async () => {
|
|
loading.value = true
|
|
try {
|
|
const response = await couponApi.listUserCoupons() as any
|
|
coupons.value = response || []
|
|
} catch (error) {
|
|
console.error('获取优惠券列表失败:', error)
|
|
message.error('获取优惠券列表失败')
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
const getStatusClass = (status: number) => {
|
|
switch (status) {
|
|
case 1:
|
|
return 'available'
|
|
case 2:
|
|
return 'used'
|
|
case 3:
|
|
return 'expired'
|
|
default:
|
|
return ''
|
|
}
|
|
}
|
|
|
|
const formatDate = (dateString: string) => {
|
|
if (!dateString) return ''
|
|
const date = new Date(dateString)
|
|
return date.toLocaleDateString('zh-CN', {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit'
|
|
})
|
|
}
|
|
|
|
onMounted(() => {
|
|
loadCoupons()
|
|
})
|
|
</script>
|
|
|
|
<style scoped>
|
|
.mobile-container {
|
|
padding-top: 60px;
|
|
min-height: 100vh;
|
|
background: #f5f5f5;
|
|
}
|
|
|
|
.header {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
z-index: 100;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 10px 15px;
|
|
background: white;
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 18px;
|
|
font-weight: bold;
|
|
margin: 0;
|
|
color: #1a1a2e;
|
|
}
|
|
|
|
.back-btn {
|
|
width: 40px;
|
|
height: 40px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: #1a1a2e;
|
|
}
|
|
|
|
.placeholder {
|
|
width: 40px;
|
|
}
|
|
|
|
.coupon-section {
|
|
padding: 15px;
|
|
}
|
|
|
|
.filter-card {
|
|
border-radius: 12px;
|
|
margin-bottom: 15px;
|
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
|
}
|
|
|
|
.filter-segmented {
|
|
width: 100%;
|
|
}
|
|
|
|
.content-card {
|
|
border-radius: 12px;
|
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
|
padding: 40px 20px;
|
|
}
|
|
|
|
.coupon-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
}
|
|
|
|
.coupon-card {
|
|
border-radius: 12px;
|
|
overflow: hidden;
|
|
background: linear-gradient(135deg, #f5f7ff 0%, #e8ecff 100%);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.coupon-card:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.15);
|
|
}
|
|
|
|
.coupon-card.expired {
|
|
opacity: 0.6;
|
|
background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
|
|
}
|
|
|
|
.coupon-content {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 20px;
|
|
padding: 20px;
|
|
}
|
|
|
|
.coupon-value {
|
|
font-size: 24px;
|
|
font-weight: 700;
|
|
color: #667eea;
|
|
padding: 20px;
|
|
background: rgba(102, 126, 234, 0.1);
|
|
border-radius: 8px;
|
|
min-width: 100px;
|
|
text-align: center;
|
|
}
|
|
|
|
.coupon-card.expired .coupon-value {
|
|
color: #8b8b9a;
|
|
background: rgba(139, 139, 154, 0.1);
|
|
}
|
|
|
|
.coupon-info {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 8px;
|
|
}
|
|
|
|
.coupon-name {
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
color: #1a1a2e;
|
|
}
|
|
|
|
.coupon-condition {
|
|
font-size: 12px;
|
|
color: #667eea;
|
|
}
|
|
|
|
.coupon-time {
|
|
font-size: 12px;
|
|
color: #8b8b9a;
|
|
}
|
|
|
|
.coupon-status {
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
padding: 2px 8px;
|
|
border-radius: 8px;
|
|
align-self: flex-start;
|
|
}
|
|
|
|
.coupon-status.available {
|
|
background: #f6ffed;
|
|
color: #52c41a;
|
|
}
|
|
|
|
.coupon-status.used {
|
|
background: #f5f5f5;
|
|
color: #8b8b9a;
|
|
}
|
|
|
|
.coupon-status.expired {
|
|
background: #fff1f0;
|
|
color: #ff4d4f;
|
|
}
|
|
</style> |