Purchase Successful!
@@ -92,11 +92,13 @@
import { FormatBytes } from '@/utils/tools'
import { fetchDownloadItemsByGet } from '@/api/user'
import { computed, onMounted, ref } from 'vue'
- import { CreateOrder } from '@/api/shoppingCart'
- import { useRouter } from 'vue-router'
+ import { CreateOrder, ORDER_STATUS, GetOrderStatus } from '@/api/shoppingCart'
+ import { useRouter, useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
- const router = useRouter()
const onBack = () => router.back()
+ const router = useRouter()
+ const route = useRoute()
+ const query = computed(() => route.query)
const props = defineProps({
ids: {
type: Array,
@@ -104,22 +106,45 @@
}
})
const agreement = ref(false)
- const status = ref(0) // 0 初始 1 待支付 2 支付成功
+ const paymentStatus = ref(ORDER_STATUS.PENDING)
const onPayWith = () => {
if (!agreement.value) {
return ElMessage.warning('Please agree to the Terms & Conditions and Privacy Policy.')
}
const ids = [...props.ids]
if (ids.length === 0) return
- // CreateOrder(ids, true).then((res) => {
- openView('https://www.baidu.com/')
- status.value = 1
- // })
+ CreateOrder(ids, true).then((res: any) => {
+ const url = res.paymentLink
+ 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 = () => {
- 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 tip = statusTips[status]
+ // console.log(status)
+ })
+ // paymentStatus.value = ORDER_STATUS.SUCCESS
}
- const openView = (url, width = 800, height = 600) => {
+ const openView = (url, width = 600, height = 800) => {
const left = (screen.width - width) / 2
const top = (screen.height - height) / 2
window.open(
@@ -161,6 +186,7 @@
downloadInfo.value.total = event.total
})
.then((res) => {
+ console.log(res)
const disposition = res.headers['content-disposition']
const fileName = disposition?.split('filename=')[1]?.replace(/"/g, '') || 'download.zip'
const blob = res.data