- 新增 invoice_title、showcase、wallet_log 模型及对应语言包 - 新增后台控制器、视图及搜索字段配置 - 修复服务类目删除保护逻辑 - 优化后台登录页面文案及样式 - 新增前端角色切换逻辑及页面拦截 - 新增 SVG 图标及样式变量 - 修复接口权限及下拉框默认值问题
390 行
7.8 KiB
Vue
390 行
7.8 KiB
Vue
<template>
|
|
<view class="drawer-mask" v-if="visible" @tap="close">
|
|
<view class="drawer-sheet" @tap.stop>
|
|
<view class="drawer-head">
|
|
<view class="dh-left">
|
|
<text class="dh-title">选择优惠券</text>
|
|
<view class="dh-center-link clickable-hover" @tap="goCouponCenter">
|
|
<text class="dh-link-txt">领券中心</text>
|
|
<image class="dh-link-arrow" src="/static/icons/arrow-right-orange.svg" mode="aspectFit" />
|
|
</view>
|
|
</view>
|
|
<view class="dh-close clickable-hover" @tap="close">
|
|
<image class="dh-close-img" src="/static/icons/close.svg" mode="aspectFit" />
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 不使用优惠券选项 -->
|
|
<view class="no-coupon-bar clickable-hover" @tap="selectNone">
|
|
<text class="ncb-txt">不使用优惠券</text>
|
|
<view class="radio-circle" :class="{ on: !currentId }">
|
|
<image v-if="!currentId" class="rc-check" src="/static/icons/check-white.svg" mode="aspectFit" />
|
|
</view>
|
|
</view>
|
|
|
|
<scroll-view scroll-y class="coupon-scroll">
|
|
<view class="loading-box" v-if="loading">
|
|
<text class="loading-txt">加载可用优惠券中...</text>
|
|
</view>
|
|
|
|
<view class="empty-box" v-else-if="!coupons.length">
|
|
<image class="empty-icon" src="/static/icons/empty-coupon.svg" mode="aspectFit" />
|
|
<text class="empty-txt">暂无未使用的优惠券</text>
|
|
<view class="empty-btn clickable-hover" @tap="goCouponCenter">
|
|
<text class="empty-btn-txt">去领券中心领取</text>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="coupon-list" v-else>
|
|
<view
|
|
v-for="c in enrichedCoupons"
|
|
:key="c.id"
|
|
class="cp-card"
|
|
:class="{ disabled: !c.usable, active: Number(currentId) === Number(c.id) }"
|
|
@tap="handleTapCoupon(c)"
|
|
>
|
|
<view class="cp-left">
|
|
<text class="cp-val">{{ c.value_text }}</text>
|
|
<text class="cp-rule">{{ c.rule_text }}</text>
|
|
</view>
|
|
<view class="cp-mid">
|
|
<text class="cp-name">{{ c.name }}</text>
|
|
<text class="cp-time">{{ c.time_text }}</text>
|
|
<text class="cp-reason" v-if="!c.usable">{{ c.unusableReason }}</text>
|
|
</view>
|
|
<view class="cp-right">
|
|
<view class="radio-circle" :class="{ on: Number(currentId) === Number(c.id), disabled: !c.usable }">
|
|
<image v-if="Number(currentId) === Number(c.id)" class="rc-check" src="/static/icons/check-white.svg" mode="aspectFit" />
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</scroll-view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, computed, watch } from 'vue';
|
|
import api from '@/utils/api.js';
|
|
import { isLogin } from '@/utils/request.js';
|
|
|
|
const props = defineProps({
|
|
visible: { type: Boolean, default: false },
|
|
currentId: { type: [Number, String], default: 0 },
|
|
orderTotal: { type: [Number, String], default: 0 }
|
|
});
|
|
|
|
const emit = defineEmits(['update:visible', 'select']);
|
|
|
|
const loading = ref(false);
|
|
const coupons = ref([]);
|
|
|
|
const enrichedCoupons = computed(() => {
|
|
const total = Number(props.orderTotal) || 0;
|
|
return coupons.value.map(c => {
|
|
const minAmt = Number(c.min_amount) || 0;
|
|
let usable = true;
|
|
let unusableReason = '';
|
|
if (c.expired) {
|
|
usable = false;
|
|
unusableReason = '该优惠券已过期';
|
|
} else if (total < minAmt) {
|
|
usable = false;
|
|
const diff = (minAmt - total).toFixed(2);
|
|
unusableReason = `满 ¥${minAmt} 可用,还差 ¥${diff}`;
|
|
}
|
|
return {
|
|
...c,
|
|
usable,
|
|
unusableReason
|
|
};
|
|
}).sort((a, b) => (a.usable === b.usable ? 0 : (a.usable ? -1 : 1)));
|
|
});
|
|
|
|
async function loadMyCoupons() {
|
|
if (!isLogin()) {
|
|
coupons.value = [];
|
|
return;
|
|
}
|
|
loading.value = true;
|
|
try {
|
|
const res = await api.couponMy({ status: 'unused' });
|
|
coupons.value = (res && res.list) ? res.list : [];
|
|
} catch (e) {
|
|
coupons.value = [];
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
watch(() => props.visible, (val) => {
|
|
if (val) {
|
|
loadMyCoupons();
|
|
}
|
|
});
|
|
|
|
function close() {
|
|
emit('update:visible', false);
|
|
}
|
|
|
|
function selectNone() {
|
|
emit('select', null);
|
|
close();
|
|
}
|
|
|
|
function handleTapCoupon(c) {
|
|
if (!c.usable) {
|
|
uni.showToast({ title: c.unusableReason || '未满足使用门槛', icon: 'none' });
|
|
return;
|
|
}
|
|
emit('select', c);
|
|
close();
|
|
}
|
|
|
|
function goCouponCenter() {
|
|
close();
|
|
uni.navigateTo({ url: '/pages/coupon/coupon' });
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.drawer-mask {
|
|
position: fixed;
|
|
inset: 0;
|
|
background: rgba(0, 0, 0, 0.55);
|
|
z-index: 1000;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.drawer-sheet {
|
|
background: #F5F6F8;
|
|
border-top-left-radius: 24rpx;
|
|
border-top-right-radius: 24rpx;
|
|
padding: 30rpx 28rpx calc(36rpx + env(safe-area-inset-bottom));
|
|
max-height: 78vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.drawer-head {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding-bottom: 24rpx;
|
|
}
|
|
|
|
.dh-left {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 18rpx;
|
|
}
|
|
|
|
.dh-title {
|
|
font-size: 32rpx;
|
|
font-weight: 700;
|
|
color: #1F1F1F;
|
|
}
|
|
|
|
.dh-center-link {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 4rpx;
|
|
background: #FFF7F0;
|
|
padding: 6rpx 16rpx;
|
|
border-radius: 24rpx;
|
|
}
|
|
|
|
.dh-link-txt {
|
|
font-size: 22rpx;
|
|
font-weight: 600;
|
|
color: #F0710D;
|
|
}
|
|
|
|
.dh-link-arrow {
|
|
width: 20rpx;
|
|
height: 20rpx;
|
|
}
|
|
|
|
.dh-close {
|
|
width: 56rpx;
|
|
height: 56rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.dh-close-img {
|
|
width: 30rpx;
|
|
height: 30rpx;
|
|
opacity: 0.6;
|
|
}
|
|
|
|
.no-coupon-bar {
|
|
background: #FFFFFF;
|
|
border-radius: 16rpx;
|
|
padding: 24rpx 28rpx;
|
|
margin-bottom: 20rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.ncb-txt {
|
|
font-size: 28rpx;
|
|
font-weight: 500;
|
|
color: #1F1F1F;
|
|
}
|
|
|
|
.coupon-scroll {
|
|
max-height: 54vh;
|
|
}
|
|
|
|
.loading-box,
|
|
.empty-box {
|
|
padding: 72rpx 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.loading-txt,
|
|
.empty-txt {
|
|
font-size: 26rpx;
|
|
color: #888888;
|
|
margin-top: 16rpx;
|
|
}
|
|
|
|
.empty-icon {
|
|
width: 140rpx;
|
|
height: 140rpx;
|
|
}
|
|
|
|
.empty-btn {
|
|
margin-top: 28rpx;
|
|
height: 68rpx;
|
|
padding: 0 40rpx;
|
|
border-radius: 34rpx;
|
|
background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%);
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.empty-btn-txt {
|
|
font-size: 26rpx;
|
|
font-weight: 600;
|
|
color: #FFFFFF;
|
|
}
|
|
|
|
.coupon-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 18rpx;
|
|
padding-bottom: 12rpx;
|
|
}
|
|
|
|
.cp-card {
|
|
background: #FFFFFF;
|
|
border-radius: 18rpx;
|
|
padding: 24rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
border: 2rpx solid transparent;
|
|
}
|
|
|
|
.cp-card.active {
|
|
border-color: #F0710D;
|
|
background: #FFFDFB;
|
|
}
|
|
|
|
.cp-card.disabled {
|
|
opacity: 0.58;
|
|
}
|
|
|
|
.cp-left {
|
|
width: 156rpx;
|
|
flex-shrink: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
padding-right: 20rpx;
|
|
border-right: 1rpx dashed #F0DCC8;
|
|
}
|
|
|
|
.cp-val {
|
|
font-size: 38rpx;
|
|
font-weight: 800;
|
|
color: #F0710D;
|
|
}
|
|
|
|
.cp-rule {
|
|
margin-top: 6rpx;
|
|
font-size: 22rpx;
|
|
color: #888888;
|
|
}
|
|
|
|
.cp-mid {
|
|
flex: 1;
|
|
min-width: 0;
|
|
padding: 0 20rpx;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 6rpx;
|
|
}
|
|
|
|
.cp-name {
|
|
font-size: 28rpx;
|
|
font-weight: 700;
|
|
color: #1F1F1F;
|
|
}
|
|
|
|
.cp-time {
|
|
font-size: 22rpx;
|
|
color: #888888;
|
|
}
|
|
|
|
.cp-reason {
|
|
font-size: 22rpx;
|
|
color: #E8331B;
|
|
}
|
|
|
|
.cp-right {
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.radio-circle {
|
|
width: 40rpx;
|
|
height: 40rpx;
|
|
border-radius: 50%;
|
|
border: 2rpx solid #CCCCCC;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.radio-circle.on {
|
|
background: #F0710D;
|
|
border-color: #F0710D;
|
|
}
|
|
|
|
.radio-circle.disabled {
|
|
background: #F0F0F2;
|
|
border-color: #DCDCDC;
|
|
}
|
|
|
|
.rc-check {
|
|
width: 24rpx;
|
|
height: 24rpx;
|
|
}
|
|
|
|
.clickable-hover:active {
|
|
opacity: 0.85;
|
|
}
|
|
</style>
|