支付方式显示

This commit is contained in:
dzl
2025-10-17 14:29:22 +08:00
parent f058a6f4e2
commit d2816a7f78

View File

@@ -229,7 +229,7 @@
<!-- 积分+融豆混合支付选项 --> <!-- 积分+融豆混合支付选项 -->
<div <div
v-if="shouldShowPaymentMethod('mixed')" v-if="shouldShowPaymentMethod('points') || shouldShowPaymentMethod('beans')"
class="payment-option" class="payment-option"
:class="{ :class="{
active: selectedPaymentMethod === 'mixed', active: selectedPaymentMethod === 'mixed',
@@ -257,6 +257,7 @@
class="payment-option" class="payment-option"
:class="{ active: selectedPaymentMethod === 'alipay_wap' }" :class="{ active: selectedPaymentMethod === 'alipay_wap' }"
@click="selectPaymentMethod('alipay_wap')" @click="selectPaymentMethod('alipay_wap')"
v-if="shouldShowPaymentMethod('alipay')"
> >
<div class="payment-icon" style="color: #1677FF;"> <div class="payment-icon" style="color: #1677FF;">
<svg viewBox="0 0 24 24" width="20" height="20"> <svg viewBox="0 0 24 24" width="20" height="20">
@@ -276,6 +277,7 @@
class="payment-option" class="payment-option"
:class="{ active: selectedPaymentMethod === 'wechat_h5' }" :class="{ active: selectedPaymentMethod === 'wechat_h5' }"
@click="selectPaymentMethod('wechat_h5')" @click="selectPaymentMethod('wechat_h5')"
v-if="shouldShowPaymentMethod('wechatpay')"
> >
<div class="payment-icon" style="color: #07C160;"> <div class="payment-icon" style="color: #07C160;">
<svg viewBox="0 0 24 24" width="20" height="20"> <svg viewBox="0 0 24 24" width="20" height="20">
@@ -414,6 +416,8 @@ const paymentData = ref({
items: [] // 添加商品列表 items: [] // 添加商品列表
}) })
const items = ref([])
const couponList = ref([]) const couponList = ref([])
const selectedCoupon = ref() const selectedCoupon = ref()
@@ -652,30 +656,19 @@ const isPaymentMethodAvailable = (method) => {
// 检查支付方式是否应该显示 // 检查支付方式是否应该显示
const shouldShowPaymentMethod = (method) => { const shouldShowPaymentMethod = (method) => {
// 基于折后金额判断显示 // console.log(12345,method,items.value)
const totalRMBBase = totalRongdouPrice.value const can = ref(false)
const discountedRMB = applyCouponToRMB(totalRMBBase) // 检查商品是否支持所选支付方式
const totalPointsPrice = Math.ceil(discountedRMB * EXCHANGE_RATE) items.value.forEach(item => {
item.paymentMethod.map(itemMethod => itemMethod === 'rongdou' ? 'beans' : itemMethod).forEach(itemMethod => {
switch (method) { // console.log(1234,itemMethod,method)
case 'beans': if (itemMethod === method) {
// 当总积分大于等于10000且用户融豆足够支付总积分价值时显示融豆支付选项 can.value = true
if (totalPointsPrice < 10000) {
return false
}
const requiredBeans = Math.ceil(totalPointsPrice / EXCHANGE_RATE)
return totalPointsPrice > 0 && userBalance.value.beans >= requiredBeans
case 'points':
// 当用户积分足够支付时显示积分支付选项
return totalPointsPrice > 0 && userBalance.value.points >= totalPointsPrice
case 'mixed':
// 当用户积分不够但积分+融豆换算足够时显示混合支付选项且用户积分必须大于等于10000
const pointsNotEnough = totalPointsPrice > 0 && userBalance.value.points < totalPointsPrice
const hasEnoughPoints = userBalance.value.points >= 10000
return pointsNotEnough && hasEnoughPoints && isPaymentMethodAvailable('mixed')
default:
return false
} }
})
})
// console.log(111,can.value)
return can.value
} }
const fetchPaymentData = async () => { const fetchPaymentData = async () => {
@@ -699,7 +692,7 @@ const fetchPaymentData = async () => {
if (response.data.success) { if (response.data.success) {
const data = response.data.data const data = response.data.data
const items = (data.items || []).map(item => ({ items.value = (data.items || []).map(item => ({
id: item.id, id: item.id,
productId: item.product_id, productId: item.product_id,
name: item.product_name, name: item.product_name,
@@ -710,12 +703,13 @@ const fetchPaymentData = async () => {
rongdouPrice: item.rongdou_price, rongdouPrice: item.rongdou_price,
quantity: item.quantity, quantity: item.quantity,
description: item.description, description: item.description,
specInfo: item.spec_info specInfo: item.spec_info,
paymentMethod: item.payment_methods
})) }))
// 计算总积分价格和总融豆价格 // 计算总积分价格和总融豆价格
const totalPointsPrice = items.reduce((sum, item) => sum + (item.points * item.quantity), 0) const totalPointsPrice = items.value.reduce((sum, item) => sum + (item.points * item.quantity), 0)
const totalBeansPrice = items.reduce((sum, item) => sum + (item.rongdouPrice * item.quantity), 0) const totalBeansPrice = items.value.reduce((sum, item) => sum + (item.rongdouPrice * item.quantity), 0)
paymentData.value = { paymentData.value = {
totalAmount: 0, // 初始不设置总金额,等用户选择支付方式后再设置 totalAmount: 0, // 初始不设置总金额,等用户选择支付方式后再设置