功能:新增微信小程序界面

This commit is contained in:
xiaowang
2026-04-01 15:18:35 +08:00
parent bb2d8c4410
commit 7fa67d0511
92 changed files with 7463 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
const couponApi = require('../../api/coupon')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
function getBenefitText(coupon) {
if (Number(coupon.couponType) === 1) {
return `${coupon.discountValue} 折`
}
return `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
}
Page({
data: {
loading: false,
isLoggedIn: false,
coupons: []
},
onShow() {
this.loadCoupons()
},
async loadCoupons() {
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
loading: isLoggedIn
})
if (!isLoggedIn) {
this.setData({
coupons: [],
loading: false
})
return
}
try {
const coupons = await couponApi.listUserCoupons()
const list = Array.isArray(coupons) ? coupons.map(item => ({
...item,
benefitText: getBenefitText(item),
periodText: `${String(item.startTime || '').slice(0, 10)} - ${String(item.endTime || '').slice(0, 10)}`,
sourceText: item.sourceType === 'SYSTEM_VIP' ? 'VIP 自动匹配' : '用户优惠券'
})) : []
this.setData({
coupons: list
})
} catch (error) {
this.setData({
coupons: []
})
wx.showToast({
title: error.message || '优惠券加载失败',
icon: 'none'
})
} finally {
this.setData({
loading: false
})
}
},
handleOpenAuth() {
navigation.openAuth('/pages/coupons/index')
},
handleBack() {
navigation.goBack('/pages/profile/index')
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
+40
View File
@@ -0,0 +1,40 @@
<navigation-bar title="我的优惠券" color="#2d2430" background="#fff7f8" bindback="handleBack"></navigation-bar>
<view class="page-shell coupons-page">
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后查看优惠券</text>
<text class="empty-desc">可用优惠、VIP 自动折扣都会统一展示在这里。</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>
</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>
<view class="coupon-benefit">{{item.benefitText}}</view>
<view class="coupon-period">{{item.periodText}}</view>
</view>
</block>
<view wx:elif="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载优惠内容</text>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">你还没有优惠券</text>
<text class="empty-desc">下单前系统也会自动帮你匹配最合适的优惠方式。</text>
</view>
</view>
</view>
+58
View File
@@ -0,0 +1,58 @@
.coupons-hero {
margin-bottom: 20rpx;
}
.coupon-card + .coupon-card {
margin-top: 20rpx;
}
.coupon-card {
padding: 26rpx 28rpx;
background: linear-gradient(135deg, #fff8fa 0%, #fff1f5 100%);
}
.coupon-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20rpx;
}
.coupon-title {
font-size: 30rpx;
font-weight: 700;
color: #2d2430;
}
.coupon-source {
margin-top: 10rpx;
font-size: 22rpx;
color: #8d7a84;
}
.coupon-status {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 140rpx;
height: 52rpx;
padding: 0 18rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.8);
color: #c6597d;
font-size: 22rpx;
font-weight: 700;
}
.coupon-benefit {
margin-top: 26rpx;
font-size: 42rpx;
font-weight: 800;
color: #d5536f;
}
.coupon-period {
margin-top: 18rpx;
font-size: 24rpx;
color: #8d7a84;
}