This commit is contained in:
李志鹏
2026-05-29 14:25:24 +08:00
parent c3aebf85c1
commit fe04ee3d1a
2 changed files with 64 additions and 16 deletions

View File

@@ -67,3 +67,25 @@ export const CreateOrder = (data, loading?: boolean) => {
loading loading
}) })
} }
/**
* 获取订单状态
* @param { String } paymentId - 订单ID
* @param loading - 是否显示loading
* @returns
*/
export const GetOrderStatus = (paymentId: string, loading?: boolean) => {
return request({
url: `/buyer/buyer/payment/status/${paymentId}`,
method: 'get',
loading
})
}
export const ORDER_STATUS = {
PENDING: 0,//待支付
SUCCESS: 1,//支付成功
FAILED: 2,//支付失败
CANCELED: 3,//已取消支付
PARTIAL_REFUND: 4,//已部分退款
FULL_REFUND: 5,//已全额退款
}

View File

@@ -4,13 +4,13 @@
<span class="icon"><svg-icon name="back" size="30" /></span> <span class="icon"><svg-icon name="back" size="30" /></span>
<span class="text">Payment Details</span> <span class="text">Payment Details</span>
</div> </div>
<div class="paylist" v-if="status !== 2"> <div class="paylist" v-if="paymentStatus !== ORDER_STATUS.SUCCESS">
<div class="item"> <div class="item">
<img src="@/assets/images/pay/stripe.png" alt="" /> <img src="@/assets/images/pay/stripe.png" alt="" />
<span>Credit / Debit Card</span> <span>Credit / Debit Card</span>
</div> </div>
</div> </div>
<div class="agreement" v-if="status !== 2"> <div class="agreement" v-if="paymentStatus !== ORDER_STATUS.SUCCESS">
<el-checkbox v-model="agreement"> <el-checkbox v-model="agreement">
<div class="text"> <div class="text">
I agree to the <span>Terms & Conditions</span> and <span>Privacy Policy</span>. I agree to the <span>Terms & Conditions</span> and <span>Privacy Policy</span>.
@@ -18,11 +18,11 @@
</div></el-checkbox </div></el-checkbox
> >
</div> </div>
<div class="title" v-if="status !== 2"> <div class="title" v-if="paymentStatus !== ORDER_STATUS.SUCCESS">
<span class="icon"><svg-icon name="card" size="20" /></span> <span class="icon"><svg-icon name="card" size="20" /></span>
<span class="text">Pay with Paypal</span> <span class="text">Pay with Paypal</span>
</div> </div>
<template v-if="status === 0"> <template v-if="!query.paymentId">
<div class="tip"> <div class="tip">
You'll be redirected to a Paypal popup to log in and confirm. No card details are You'll be redirected to a Paypal popup to log in and confirm. No card details are
shared with Stylish Parade — PayPal handles all payment security. shared with Stylish Parade — PayPal handles all payment security.
@@ -37,7 +37,7 @@
<span class="text" @click="onBack">Cancel</span> <span class="text" @click="onBack">Cancel</span>
</div> </div>
</template> </template>
<template v-if="status === 1"> <template v-if="query.paymentId">
<div class="tip"> <div class="tip">
Please keep the window open until the payment is completed. If you are to open the Please keep the window open until the payment is completed. If you are to open the
payment window, please check your browser settings to see if pop-ups are being payment window, please check your browser settings to see if pop-ups are being
@@ -51,7 +51,7 @@
<span class="text" @click="onBack">Back</span> <span class="text" @click="onBack">Back</span>
</div> </div>
</template> </template>
<template v-if="status === 2"> <template v-if="paymentStatus === ORDER_STATUS.SUCCESS">
<div class="success"> <div class="success">
<img src="@/assets/images/pay/success.png" alt="" /> <img src="@/assets/images/pay/success.png" alt="" />
<div class="title">Purchase Successful!</div> <div class="title">Purchase Successful!</div>
@@ -92,11 +92,13 @@
import { FormatBytes } from '@/utils/tools' import { FormatBytes } from '@/utils/tools'
import { fetchDownloadItemsByGet } from '@/api/user' import { fetchDownloadItemsByGet } from '@/api/user'
import { computed, onMounted, ref } from 'vue' import { computed, onMounted, ref } from 'vue'
import { CreateOrder } from '@/api/shoppingCart' import { CreateOrder, ORDER_STATUS, GetOrderStatus } from '@/api/shoppingCart'
import { useRouter } from 'vue-router' import { useRouter, useRoute } from 'vue-router'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
const router = useRouter()
const onBack = () => router.back() const onBack = () => router.back()
const router = useRouter()
const route = useRoute()
const query = computed(() => route.query)
const props = defineProps({ const props = defineProps({
ids: { ids: {
type: Array, type: Array,
@@ -104,22 +106,45 @@
} }
}) })
const agreement = ref(false) const agreement = ref(false)
const status = ref(0) // 0 初始 1 待支付 2 支付成功 const paymentStatus = ref(ORDER_STATUS.PENDING)
const onPayWith = () => { const onPayWith = () => {
if (!agreement.value) { if (!agreement.value) {
return ElMessage.warning('Please agree to the Terms & Conditions and Privacy Policy.') return ElMessage.warning('Please agree to the Terms & Conditions and Privacy Policy.')
} }
const ids = [...props.ids] const ids = [...props.ids]
if (ids.length === 0) return if (ids.length === 0) return
// CreateOrder(ids, true).then((res) => { CreateOrder(ids, true).then((res: any) => {
openView('https://www.baidu.com/') const url = res.paymentLink
status.value = 1 const paymentId = res.paymentId
// }) openView(url)
router.replace({
query: {
...query.value,
paymentId
}
})
})
}
const statusTips = {
[ORDER_STATUS.PENDING]: '订单未支付',
[ORDER_STATUS.FAILED]: '订单支付失败',
[ORDER_STATUS.CANCELED]: '订单已取消'
} }
const getOrderStatus = () => { const getOrderStatus = () => {
status.value = 2 const paymentId = query.value.paymentId as string
GetOrderStatus(paymentId).then((res: any) => {
const status = res as number
if (status === ORDER_STATUS.SUCCESS) {
// paymentStatus.value = status
}else{
} }
const openView = (url, width = 800, height = 600) => { // const tip = statusTips[status]
// console.log(status)
})
// paymentStatus.value = ORDER_STATUS.SUCCESS
}
const openView = (url, width = 600, height = 800) => {
const left = (screen.width - width) / 2 const left = (screen.width - width) / 2
const top = (screen.height - height) / 2 const top = (screen.height - height) / 2
window.open( window.open(
@@ -161,6 +186,7 @@
downloadInfo.value.total = event.total downloadInfo.value.total = event.total
}) })
.then((res) => { .then((res) => {
console.log(res)
const disposition = res.headers['content-disposition'] const disposition = res.headers['content-disposition']
const fileName = disposition?.split('filename=')[1]?.replace(/"/g, '') || 'download.zip' const fileName = disposition?.split('filename=')[1]?.replace(/"/g, '') || 'download.zip'
const blob = res.data const blob = res.data