|
@@ -109,7 +109,10 @@
|
|
|
|
|
|
|
|
<div class="checkout-section">
|
|
<div class="checkout-section">
|
|
|
<div class="checkout-section__title">选择支付方式</div>
|
|
<div class="checkout-section__title">选择支付方式</div>
|
|
|
- <PayMethodPicker v-model="payType" />
|
|
|
|
|
|
|
+ <PayMethodPicker v-model="payType" :methods="paymentMethods" :fallback-default="false" />
|
|
|
|
|
+ <p v-if="paymentMethods.length === 0" class="payment-method-empty">
|
|
|
|
|
+ 暂无可用支付方式,请稍后再试或联系管理员
|
|
|
|
|
+ </p>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<template #footer>
|
|
<template #footer>
|
|
@@ -132,7 +135,7 @@
|
|
|
<script setup>
|
|
<script setup>
|
|
|
import { ref, computed } from 'vue'
|
|
import { ref, computed } from 'vue'
|
|
|
import { getGoods } from '@/api/goods'
|
|
import { getGoods } from '@/api/goods'
|
|
|
-import { createOrder } from '@/api/order'
|
|
|
|
|
|
|
+import { createOrder, getPaymentMethods } from '@/api/order'
|
|
|
import { validateCoupon } from '@/api/coupon'
|
|
import { validateCoupon } from '@/api/coupon'
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
import { Notification, Message } from '@arco-design/web-vue'
|
|
import { Notification, Message } from '@arco-design/web-vue'
|
|
@@ -157,6 +160,7 @@ const couponCode = ref('')
|
|
|
const couponApplied = ref(null)
|
|
const couponApplied = ref(null)
|
|
|
const couponLoading = ref(false)
|
|
const couponLoading = ref(false)
|
|
|
const couponError = ref('')
|
|
const couponError = ref('')
|
|
|
|
|
+const paymentMethods = ref([])
|
|
|
|
|
|
|
|
const featureList = computed(() => parseFeatures(data.value?.features))
|
|
const featureList = computed(() => parseFeatures(data.value?.features))
|
|
|
|
|
|
|
@@ -166,7 +170,7 @@ const payablePrice = computed(() => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const openCheckout = () => {
|
|
const openCheckout = () => {
|
|
|
- payType.value = ''
|
|
|
|
|
|
|
+ payType.value = paymentMethods.value[0]?.type || ''
|
|
|
couponCode.value = ''
|
|
couponCode.value = ''
|
|
|
couponApplied.value = null
|
|
couponApplied.value = null
|
|
|
couponError.value = ''
|
|
couponError.value = ''
|
|
@@ -201,10 +205,19 @@ const applyCoupon = async () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const submitOrder = async () => {
|
|
const submitOrder = async () => {
|
|
|
|
|
+ if (paymentMethods.value.length === 0) {
|
|
|
|
|
+ Message.warning('暂无可用支付方式,请稍后再试')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
if (!payType.value) {
|
|
if (!payType.value) {
|
|
|
Message.warning('请选择支付方式')
|
|
Message.warning('请选择支付方式')
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!paymentMethods.value.some(method => method.type === payType.value)) {
|
|
|
|
|
+ Message.warning('该支付方式当前不可用,请重新选择')
|
|
|
|
|
+ payType.value = paymentMethods.value[0]?.type || ''
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
const paymentWindow = window.open('', '_blank')
|
|
const paymentWindow = window.open('', '_blank')
|
|
|
if (!paymentWindow) {
|
|
if (!paymentWindow) {
|
|
|
Message.warning('浏览器拦截了支付页弹窗,请允许弹窗后重试')
|
|
Message.warning('浏览器拦截了支付页弹窗,请允许弹窗后重试')
|
|
@@ -216,6 +229,7 @@ const submitOrder = async () => {
|
|
|
if (couponApplied.value?.code) payload.coupon_code = couponApplied.value.code
|
|
if (couponApplied.value?.code) payload.coupon_code = couponApplied.value.code
|
|
|
const res = await createOrder(payload)
|
|
const res = await createOrder(payload)
|
|
|
if (!res || res.code !== 0) {
|
|
if (!res || res.code !== 0) {
|
|
|
|
|
+ if (paymentWindow && !paymentWindow.closed) paymentWindow.close()
|
|
|
Notification.error({
|
|
Notification.error({
|
|
|
title: '创建订单失败',
|
|
title: '创建订单失败',
|
|
|
content: res?.msg ?? '请稍后再试'
|
|
content: res?.msg ?? '请稍后再试'
|
|
@@ -267,7 +281,20 @@ const getGoodsDetail = async () => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const loadPaymentMethods = async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await getPaymentMethods()
|
|
|
|
|
+ paymentMethods.value = Array.isArray(res?.data) ? res.data : []
|
|
|
|
|
+ if (!paymentMethods.value.some(method => method.type === payType.value)) {
|
|
|
|
|
+ payType.value = paymentMethods.value[0]?.type || ''
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ paymentMethods.value = []
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
getGoodsDetail()
|
|
getGoodsDetail()
|
|
|
|
|
+loadPaymentMethods()
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
<style lang="less" scoped>
|
|
@@ -482,6 +509,12 @@ getGoodsDetail()
|
|
|
color: @store-accent;
|
|
color: @store-accent;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+.payment-method-empty {
|
|
|
|
|
+ margin: 8px 0 0;
|
|
|
|
|
+ font-size: 12px;
|
|
|
|
|
+ color: rgb(var(--orange-6));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
.checkout-order__row--discount .discount {
|
|
.checkout-order__row--discount .discount {
|
|
|
color: rgb(var(--green-6));
|
|
color: rgb(var(--green-6));
|
|
|
font-weight: 600;
|
|
font-weight: 600;
|