feat(order): support balance payment, dynamic marketing coupon recommendation, and quick activity picker

这个提交包含在:
xcbyy
2026-10-10 15:37:41 +08:00
父节点 872af22c20
当前提交 7ac81035b4
共有 7 个文件被更改,包括 559 次插入 和 18 次删除

查看文件

@@ -1,5 +1,5 @@
<template>
<view class="create-order-container">
<view class="create-order-container" :class="{ 'theme-warm': currentThemeKey === 'warm' }">
<!-- 服务大神与项目信息 -->
<view class="order-card">
<view class="expert-profile">
@@ -139,13 +139,60 @@
</view>
</view>
<!-- 支付方式人性化选择 (支持微信支付与钱包余额抵扣) -->
<view class="order-card payment-method-card">
<view class="section-title">支付方式</view>
<view class="pay-method-list">
<view
class="pay-method-item btn-active"
:class="{ active: payMethod === 'WECHAT' }"
@click="payMethod = 'WECHAT'"
>
<view class="method-left">
<image class="method-svg" :src="ICONS.wechat" mode="aspectFit" />
<view class="method-info">
<text class="method-title">微信支付</text>
<text class="method-desc">亿万用户的安全移动支付通道</text>
</view>
</view>
<view class="radio-circle" :class="{ checked: payMethod === 'WECHAT' }"></view>
</view>
<view
class="pay-method-item btn-active"
:class="{
active: payMethod === 'BALANCE',
disabled: Number(userBalance) < finalTotal
}"
@click="selectBalancePay"
>
<view class="method-left">
<image class="method-svg" :src="ICONS.wallet" mode="aspectFit" />
<view class="method-info">
<view class="title-with-badge">
<text class="method-title">钱包余额抵扣</text>
<text class="balance-tag" :class="{ 'low-balance': Number(userBalance) < finalTotal }">
可用: ¥{{ userBalance }}
</text>
</view>
<text class="method-desc" v-if="Number(userBalance) >= finalTotal">扣除钱包余额,秒级极速结算</text>
<text class="method-desc warn-tip" v-else>余额不足以支付整单 (差额 ¥{{ (finalTotal - Number(userBalance)).toFixed(2) }})</text>
</view>
</view>
<view class="radio-circle" :class="{ checked: payMethod === 'BALANCE' }"></view>
</view>
</view>
</view>
<!-- 底部固定结算条 -->
<view class="bottom-bar">
<view class="amount-wrap">
<text class="amount-label">实付:</text>
<text class="amount-num">¥{{ finalTotal }}</text>
</view>
<button class="btn-pay btn-active" @click="handlePay">微信支付</button>
<button class="btn-pay btn-active" :class="{ 'btn-balance': payMethod === 'BALANCE' }" @click="handlePay">
{{ payMethod === 'BALANCE' ? '余额极速支付' : '微信安全支付' }}
</button>
</view>
<!-- 优惠券选择弹窗 -->
@@ -190,10 +237,48 @@
</template>
<script setup>
import { ref, computed } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { createOrder, getCompanionDetail } from '@/common/api.js';
import { ref, computed, onMounted, onUnmounted } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import { createOrder, getCompanionDetail, getUserProfile, getMarketingCoupons } from '@/common/api.js';
import { ICONS } from '@/common/icons.js';
import { getCurrentThemeKey, applyThemeToNativeUI } from '@/common/theme.js';
const currentThemeKey = ref(getCurrentThemeKey());
const userBalance = ref('0.00');
const payMethod = ref('WECHAT'); // 'WECHAT' | 'BALANCE'
const onThemeChanged = (key) => {
currentThemeKey.value = key;
applyThemeToNativeUI(key);
};
onMounted(() => {
currentThemeKey.value = getCurrentThemeKey();
applyThemeToNativeUI(currentThemeKey.value);
uni.$on('theme-change', onThemeChanged);
loadUserWallet();
});
onShow(() => {
currentThemeKey.value = getCurrentThemeKey();
applyThemeToNativeUI(currentThemeKey.value);
loadUserWallet();
});
onUnmounted(() => {
uni.$off('theme-change', onThemeChanged);
});
const loadUserWallet = async () => {
try {
const u = await getUserProfile(1001);
if (u && u.balance !== undefined) {
userBalance.value = String(u.balance);
}
} catch (err) {
console.warn('[OrderCreate] 加载用户资产异常:', err);
}
};
const expert = ref({
id: '',
@@ -206,7 +291,7 @@ const expert = ref({
const selectedService = ref(null);
const hours = ref(2);
const timeType = ref('NOW');
const discount = ref(10);
const discount = ref(0);
const remark = ref('');
const meetVenue = ref('朝阳大悦城海底捞');
const expenseBurden = ref('AA');
@@ -244,6 +329,9 @@ onLoad(async (query) => {
} catch (err) {
console.warn('[OrderCreate] 获取线上大神详情异常:', err);
}
// 加载后台真实可用优惠券
await loadLiveCoupons();
});
const rawTotal = computed(() => {
@@ -257,16 +345,50 @@ const finalTotal = computed(() => {
const changeHours = (delta) => {
hours.value = Math.max(1, Math.min(10, hours.value + delta));
autoSelectBestCoupon();
};
const couponModalVisible = ref(false);
const availableCoupons = ref([
{ id: 'c1', title: '平台新客专享立减券', amount: 10, minAmount: 0, tag: '新人专享' },
{ id: 'c2', title: '周末高阶开黑满减券', amount: 20, minAmount: 150, tag: '满150可用' },
{ id: 'c3', title: '不使用优惠券', amount: 0, minAmount: 0, tag: '不使用' }
{ id: 'c_none', title: '不使用优惠券', amount: 0, minAmount: 0, tag: '不使用' }
]);
const currentCoupon = ref(availableCoupons.value[0]);
const loadLiveCoupons = async () => {
try {
const list = await getMarketingCoupons();
if (Array.isArray(list) && list.length > 0) {
const activeCoupons = list
.filter(c => c.status === 1)
.map(c => ({
id: String(c.id),
title: c.name,
amount: Number(c.discountAmount || 0),
minAmount: Number(c.minSpend || 0),
tag: c.minSpend > 0 ? `满¥${c.minSpend}减¥${c.discountAmount}` : `立减¥${c.discountAmount}`
}));
activeCoupons.push({ id: 'c_none', title: '不使用优惠券', amount: 0, minAmount: 0, tag: '不使用' });
availableCoupons.value = activeCoupons;
autoSelectBestCoupon();
}
} catch (e) {
console.warn('[OrderCreate] 加载优惠券异常:', e);
}
};
const autoSelectBestCoupon = () => {
const validList = availableCoupons.value.filter(c => c.amount > 0 && rawTotal.value >= c.minAmount);
if (validList.length > 0) {
// 选减免金额最大的一张
validList.sort((a, b) => b.amount - a.amount);
currentCoupon.value = validList[0];
discount.value = validList[0].amount;
} else {
currentCoupon.value = availableCoupons.value.find(c => c.id === 'c_none') || availableCoupons.value[0];
discount.value = 0;
}
};
const openCouponModal = () => {
couponModalVisible.value = true;
};
@@ -293,8 +415,36 @@ const selectCouponItem = (coupon) => {
}
};
const selectBalancePay = () => {
if (Number(userBalance.value) < finalTotal.value) {
uni.showModal({
title: '钱包余额不足',
content: `当前钱包余额为 ¥${userBalance.value},实付需 ¥${finalTotal.value}。您可以前往「我的」-「我的钱包」充值后再使用余额支付,或切换为微信直接支付。`,
confirmText: '去充值',
cancelText: '微信支付',
confirmColor: '#6366F1',
success: (res) => {
if (res.confirm) {
uni.switchTab({ url: '/pages/user/index' });
} else {
payMethod.value = 'WECHAT';
}
}
});
return;
}
payMethod.value = 'BALANCE';
};
const handlePay = async () => {
uni.showLoading({ title: '正在拉起微信支付...' });
if (payMethod.value === 'BALANCE' && Number(userBalance.value) < finalTotal.value) {
selectBalancePay();
return;
}
const payDesc = payMethod.value === 'BALANCE' ? '钱包余额支付' : '微信支付';
uni.showLoading({ title: `正在处理${payDesc}...` });
try {
const payload = {
buyerId: 1001,
@@ -307,6 +457,8 @@ const handlePay = async () => {
hourlyRate: selectedService.value ? selectedService.value.price : (expert.value.price || 35),
durationHours: hours.value,
amount: finalTotal.value,
couponDiscount: discount.value,
payType: payMethod.value,
location: isOffline.value ? meetVenue.value : (remark.value || '线上语音开黑'),
expenseBurden: expenseBurden.value === 'AA' ? 'AA制各自付' : (expenseBurden.value === 'CLIENT' ? '客户全包' : '大神自理'),
remark: remark.value,
@@ -317,7 +469,7 @@ const handlePay = async () => {
uni.hideLoading();
uni.showToast({
title: '支付成功!订单已写入系统',
title: `${payDesc}成功!订单已写入系统`,
icon: 'success',
duration: 1500
});
@@ -732,6 +884,117 @@ const handlePay = async () => {
padding: 0 60rpx;
box-shadow: 0 4rpx 20rpx rgba(16, 185, 129, 0.35);
margin: 0;
&.btn-balance {
background: linear-gradient(135deg, #6366F1 0%, #4F46E5 100%);
box-shadow: 0 4rpx 20rpx rgba(99, 102, 241, 0.35);
}
}
}
.payment-method-card {
.pay-method-list {
display: flex;
flex-direction: column;
gap: 16rpx;
margin-top: 12rpx;
.pay-method-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx 24rpx;
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 16rpx;
transition: all 0.2s ease;
.method-left {
display: flex;
align-items: center;
gap: 20rpx;
.method-svg {
width: 44rpx;
height: 44rpx;
flex-shrink: 0;
}
.method-info {
display: flex;
flex-direction: column;
gap: 4rpx;
.title-with-badge {
display: flex;
align-items: center;
gap: 12rpx;
}
.method-title {
font-size: 28rpx;
font-weight: 600;
color: #F8FAFC;
}
.balance-tag {
font-size: 20rpx;
color: #10B981;
background: rgba(16, 185, 129, 0.15);
padding: 2rpx 10rpx;
border-radius: 6rpx;
font-weight: 600;
&.low-balance {
color: #EF4444;
background: rgba(239, 68, 68, 0.15);
}
}
.method-desc {
font-size: 22rpx;
color: #64748B;
&.warn-tip {
color: #EF4444;
}
}
}
}
.radio-circle {
width: 36rpx;
height: 36rpx;
border-radius: 50%;
border: 2px solid #475569;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
&.checked {
border-color: #6366F1;
background: #6366F1;
&::after {
content: '';
width: 14rpx;
height: 14rpx;
background: #FFFFFF;
border-radius: 50%;
}
}
}
&.active {
border-color: #6366F1;
background: rgba(99, 102, 241, 0.08);
}
&.disabled {
opacity: 0.6;
}
}
}
}
@@ -900,7 +1163,42 @@ const handlePay = async () => {
background: #FFF7ED;
}
}
.payment-method-card {
background: #FFFFFF;
border-color: #E7E5E4;
.pay-method-item {
background: #FDFBF7;
border-color: #E7E5E4;
.method-info {
.method-title {
color: #1C1917;
}
.method-desc {
color: #78716C;
}
}
.radio-circle {
border-color: #D6D3D1;
&.checked {
border-color: #EA580C;
background: #EA580C;
}
}
&.active {
border-color: #EA580C;
background: #FFF7ED;
}
}
}
.btn-pay.btn-balance {
background: linear-gradient(135deg, #EA580C 0%, #C2410C 100%);
box-shadow: 0 4rpx 20rpx rgba(234, 88, 12, 0.35);
}
}
</style>