功能:收口小程序前后台安全与防重复提交
This commit is contained in:
@@ -13,7 +13,15 @@ Page({
|
||||
data: {
|
||||
loading: false,
|
||||
isLoggedIn: false,
|
||||
coupons: []
|
||||
coupons: [],
|
||||
filteredCoupons: [],
|
||||
activeFilter: 'all',
|
||||
filterOptions: [
|
||||
{ value: 'all', label: '全部' },
|
||||
{ value: 'available', label: '未使用' },
|
||||
{ value: 'used', label: '已使用' },
|
||||
{ value: 'expired', label: '已过期' }
|
||||
]
|
||||
},
|
||||
|
||||
onShow() {
|
||||
@@ -30,6 +38,8 @@ Page({
|
||||
if (!isLoggedIn) {
|
||||
this.setData({
|
||||
coupons: [],
|
||||
filteredCoupons: [],
|
||||
activeFilter: 'all',
|
||||
loading: false
|
||||
})
|
||||
return
|
||||
@@ -47,9 +57,11 @@ Page({
|
||||
this.setData({
|
||||
coupons: list
|
||||
})
|
||||
this.applyFilter(this.data.activeFilter, list)
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
coupons: []
|
||||
coupons: [],
|
||||
filteredCoupons: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '优惠券加载失败',
|
||||
@@ -62,6 +74,33 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
applyFilter(filterValue, sourceCoupons) {
|
||||
const activeFilter = filterValue || 'all'
|
||||
const coupons = Array.isArray(sourceCoupons) ? sourceCoupons : this.data.coupons
|
||||
let filteredCoupons = coupons
|
||||
|
||||
if (activeFilter === 'available') {
|
||||
filteredCoupons = coupons.filter(item => Number(item.status) === 1)
|
||||
} else if (activeFilter === 'used') {
|
||||
filteredCoupons = coupons.filter(item => Number(item.status) === 2)
|
||||
} else if (activeFilter === 'expired') {
|
||||
filteredCoupons = coupons.filter(item => Number(item.status) === 3)
|
||||
}
|
||||
|
||||
this.setData({
|
||||
activeFilter,
|
||||
filteredCoupons
|
||||
})
|
||||
},
|
||||
|
||||
handleFilterChange(event) {
|
||||
const value = event.currentTarget.dataset.value
|
||||
if (!value || value === this.data.activeFilter) {
|
||||
return
|
||||
}
|
||||
this.applyFilter(value)
|
||||
},
|
||||
|
||||
handleOpenAuth() {
|
||||
navigation.openAuth('/pages/coupons/index')
|
||||
},
|
||||
|
||||
@@ -4,27 +4,46 @@
|
||||
<view class="page-content">
|
||||
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
|
||||
<text class="empty-title">登录后查看优惠券</text>
|
||||
<text class="empty-desc">可用优惠、VIP 自动折扣都会统一展示在这里。</text>
|
||||
<text class="empty-desc">登录后查看可用优惠。</text>
|
||||
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
|
||||
</view>
|
||||
|
||||
<block wx:elif="{{coupons.length}}">
|
||||
<view class="page-hero coupons-hero">
|
||||
<text class="hero-kicker">优惠资产</text>
|
||||
<text class="hero-title">当前有 {{coupons.length}} 张可查看</text>
|
||||
<text class="hero-desc">普通优惠券和系统自动匹配的 VIP 折扣都会在结算前统一展示。</text>
|
||||
<text class="hero-title">当前有 {{coupons.length}} 张</text>
|
||||
<text class="hero-desc">下单前可查看可用优惠。</text>
|
||||
</view>
|
||||
|
||||
<view wx:for="{{coupons}}" wx:key="id" class="page-card coupon-card">
|
||||
<view class="coupon-top">
|
||||
<view>
|
||||
<view class="coupon-title">{{item.couponName}}</view>
|
||||
<view class="coupon-source">{{item.sourceText}}</view>
|
||||
</view>
|
||||
<view class="coupon-status">{{item.statusName || '待使用'}}</view>
|
||||
<view class="coupon-filter-row">
|
||||
<view
|
||||
wx:for="{{filterOptions}}"
|
||||
wx:key="value"
|
||||
class="coupon-filter-chip {{activeFilter === item.value ? 'active' : ''}}"
|
||||
data-value="{{item.value}}"
|
||||
bindtap="handleFilterChange"
|
||||
>
|
||||
{{item.label}}
|
||||
</view>
|
||||
<view class="coupon-benefit">{{item.benefitText}}</view>
|
||||
<view class="coupon-period">{{item.periodText}}</view>
|
||||
</view>
|
||||
|
||||
<block wx:if="{{filteredCoupons.length}}">
|
||||
<view wx:for="{{filteredCoupons}}" wx:key="id" class="page-card coupon-card">
|
||||
<view class="coupon-top">
|
||||
<view>
|
||||
<view class="coupon-title">{{item.couponName}}</view>
|
||||
<view class="coupon-source">{{item.sourceText}}</view>
|
||||
</view>
|
||||
<view class="coupon-status">{{item.statusName || '待使用'}}</view>
|
||||
</view>
|
||||
<view class="coupon-benefit">{{item.benefitText}}</view>
|
||||
<view class="coupon-period">{{item.periodText}}</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view wx:else class="page-card empty-card">
|
||||
<text class="empty-title">当前筛选下暂无优惠券</text>
|
||||
<text class="empty-desc">换个筛选试试。</text>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
@@ -34,7 +53,7 @@
|
||||
|
||||
<view wx:else class="page-card empty-card">
|
||||
<text class="empty-title">你还没有优惠券</text>
|
||||
<text class="empty-desc">下单前系统也会自动帮你匹配最合适的优惠方式。</text>
|
||||
<text class="empty-desc">下单前会自动匹配可用优惠。</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -2,6 +2,32 @@
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.coupon-filter-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.coupon-filter-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 120rpx;
|
||||
height: 60rpx;
|
||||
padding: 0 24rpx;
|
||||
border-radius: 999rpx;
|
||||
background: rgba(255, 255, 255, 0.78);
|
||||
color: #8d7a84;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.coupon-filter-chip.active {
|
||||
background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%);
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.coupon-card + .coupon-card {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user