feat(payment): 新增支付订单创建和状态查询功能
- 添加创建支付订单接口 - 添加查询订单状态接口 - 添加获取收银台页面URL方法 - 创建支付结果展示页面 PaymentResult.vue - 实现订单信息展示和状态判断逻辑 - 添加支付成功、失败、审核中等状态显示 - 集成 Element Plus 的结果页组件和描述列表 - 实现继续支付和查询订单操作按钮
This commit is contained in:
30
src/api/payment.js
Normal file
30
src/api/payment.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import request from './request'
|
||||
|
||||
/**
|
||||
* 创建支付订单
|
||||
*/
|
||||
export function createPaymentOrder(data) {
|
||||
return request({
|
||||
url: '/payment/checkout',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单状态
|
||||
*/
|
||||
export function getOrderStatus(merchantTransactionId) {
|
||||
return request({
|
||||
url: `/payment/order/${merchantTransactionId}`,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取收银台页面URL
|
||||
*/
|
||||
export function getCheckoutPageUrl(token) {
|
||||
return `/api/payment/checkout/page?token=${token}`
|
||||
}
|
||||
|
||||
171
src/views/PaymentResult.vue
Normal file
171
src/views/PaymentResult.vue
Normal file
@@ -0,0 +1,171 @@
|
||||
<template>
|
||||
<div class="payment-result">
|
||||
<el-card>
|
||||
<div class="result-container">
|
||||
<el-result
|
||||
:icon="resultIcon"
|
||||
:title="resultTitle"
|
||||
:sub-title="resultSubTitle"
|
||||
>
|
||||
<template #extra>
|
||||
<el-descriptions :column="1" border>
|
||||
<el-descriptions-item label="订单号">
|
||||
{{ orderInfo.merchantTransactionId || '未知' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="交易流水号">
|
||||
{{ orderInfo.transactionId || '暂无' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="订单状态">
|
||||
<el-tag :type="statusTagTypeComputed">{{ orderInfo.statusText }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="交易金额" v-if="orderInfo.amount">
|
||||
{{ orderInfo.amount }} {{ orderInfo.currency }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间" v-if="orderInfo.createTime">
|
||||
{{ orderInfo.createTime }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<div class="action-buttons">
|
||||
<el-button type="primary" @click="goToCreate">继续支付</el-button>
|
||||
<el-button @click="goToQuery">查询订单</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-result>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { getOrderStatus } from '../api/payment'
|
||||
import { getStatusText, getStatusTagType } from '../utils/helpers'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const orderInfo = ref({
|
||||
merchantTransactionId: '',
|
||||
transactionId: '',
|
||||
status: '',
|
||||
statusText: '',
|
||||
amount: '',
|
||||
currency: '',
|
||||
createTime: ''
|
||||
})
|
||||
|
||||
const resultIcon = computed(() => {
|
||||
const status = orderInfo.value.status?.toUpperCase()
|
||||
if (status === 'SUCCESS' || status === 'SUCCESSFUL') {
|
||||
return 'success'
|
||||
} else if (status === 'FAILED' || status === 'FAILURE') {
|
||||
return 'error'
|
||||
} else if (status === 'REVIEW') {
|
||||
return 'warning'
|
||||
}
|
||||
return 'info'
|
||||
})
|
||||
|
||||
const resultTitle = computed(() => {
|
||||
const status = orderInfo.value.status?.toUpperCase()
|
||||
if (status === 'SUCCESS' || status === 'SUCCESSFUL') {
|
||||
return '支付成功'
|
||||
} else if (status === 'FAILED' || status === 'FAILURE') {
|
||||
return '支付失败'
|
||||
} else if (status === 'REVIEW') {
|
||||
return '订单审核中'
|
||||
}
|
||||
return '支付处理中'
|
||||
})
|
||||
|
||||
const resultSubTitle = computed(() => {
|
||||
const status = orderInfo.value.status?.toUpperCase()
|
||||
if (status === 'SUCCESS' || status === 'SUCCESSFUL') {
|
||||
return '您的订单已成功支付'
|
||||
} else if (status === 'FAILED' || status === 'FAILURE') {
|
||||
return '支付失败,请重试或联系客服'
|
||||
} else if (status === 'REVIEW') {
|
||||
return '您的订单正在审核中,请耐心等待'
|
||||
}
|
||||
return '订单正在处理中,请稍候'
|
||||
})
|
||||
|
||||
const statusTagTypeComputed = computed(() => {
|
||||
return getStatusTagType(orderInfo.value.status)
|
||||
})
|
||||
|
||||
const loadOrderInfo = async () => {
|
||||
const merchantTransactionId = route.query.merchantTransactionId
|
||||
const status = route.query.status
|
||||
|
||||
if (!merchantTransactionId) {
|
||||
// 如果没有订单号,只显示状态
|
||||
orderInfo.value.status = status || 'UNKNOWN'
|
||||
orderInfo.value.statusText = getStatusText(status)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await getOrderStatus(merchantTransactionId)
|
||||
if (response.code === '0000' && response.data) {
|
||||
orderInfo.value = {
|
||||
merchantTransactionId: response.data.merchantTransactionId,
|
||||
transactionId: response.data.transactionId || '',
|
||||
status: response.data.status,
|
||||
statusText: getStatusTextLocal(response.data.status),
|
||||
amount: response.data.amount,
|
||||
currency: response.data.currency,
|
||||
createTime: response.data.createTime
|
||||
}
|
||||
} else {
|
||||
ElMessage.error(response.message || '查询订单失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('查询订单失败:', error)
|
||||
// 如果查询失败,使用URL参数中的状态
|
||||
orderInfo.value.merchantTransactionId = merchantTransactionId
|
||||
orderInfo.value.status = status || 'UNKNOWN'
|
||||
orderInfo.value.statusText = getStatusTextLocal(status)
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusTextLocal = (status) => {
|
||||
return getStatusText(status)
|
||||
}
|
||||
|
||||
const goToCreate = () => {
|
||||
router.push('/')
|
||||
}
|
||||
|
||||
const goToQuery = () => {
|
||||
router.push('/query')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadOrderInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.payment-result {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.result-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.action-buttons .el-button {
|
||||
margin: 0 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user