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