update
This commit is contained in:
parent
e2720eecbb
commit
79ec214050
@ -65,6 +65,7 @@
|
||||
:loading="loading"
|
||||
@change="handleTableChange"
|
||||
row-key="id"
|
||||
:scroll="{ x: 1500 }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<!-- 订单状态列 -->
|
||||
@ -74,17 +75,87 @@
|
||||
</a-tag>
|
||||
</template>
|
||||
<!-- 金额列 -->
|
||||
<template v-if="['original_amount', 'coupon_discount_amount', 'point_discount_amount', 'final_amount'].includes(column.key)">
|
||||
¥{{ record[column.dataIndex] }}
|
||||
<template v-if="['original_amount', 'coupon_discount_amount', 'point_discount_amount', 'final_amount', 'refund_amount'].includes(column.key)">
|
||||
¥{{ (record[column.dataIndex] || 0).toFixed(2) }}
|
||||
</template>
|
||||
<!-- 退款原因,如果字段为空则显示占位符 -->
|
||||
<template v-if="column.key === 'refund_reason'">
|
||||
{{ record.refund_reason || '-' }}
|
||||
</template>
|
||||
<!-- 操作列 -->
|
||||
<template v-if="column.key === 'action'">
|
||||
<a-button
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="showRefundModal(record)"
|
||||
:disabled="record.status === 'CANCELLED' || record.refund_amount > 0"
|
||||
>
|
||||
退款
|
||||
</a-button>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<!-- 退款模态框 -->
|
||||
<a-modal
|
||||
v-model:visible="refundModalVisible"
|
||||
title="订单退款"
|
||||
@ok="handleRefundSubmit"
|
||||
@cancel="handleRefundCancel"
|
||||
:confirmLoading="refundLoading"
|
||||
width="500px"
|
||||
okText="确定"
|
||||
cancelText="取消"
|
||||
>
|
||||
<div v-if="currentOrder" class="refund-modal-content">
|
||||
<div class="order-info">
|
||||
<div class="order-info-item">
|
||||
<span class="label">订单号:</span>
|
||||
<span class="value">{{ currentOrder.orderid }}</span>
|
||||
</div>
|
||||
<a-divider style="margin: 12px 0" />
|
||||
<div class="order-amount-info">
|
||||
<div class="amount-item">
|
||||
<span class="label">订单金额</span>
|
||||
<span class="amount">¥{{ currentOrder.final_amount.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="amount-item">
|
||||
<span class="label">可退款金额</span>
|
||||
<span class="amount available">¥{{ calculateAvailableRefund(currentOrder).toFixed(2) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="refund-form">
|
||||
<div class="form-item">
|
||||
<div class="form-label"><span class="required">*</span> 退款金额</div>
|
||||
<a-input-number
|
||||
v-model:value="refundForm.amount"
|
||||
:min="0.01"
|
||||
:max="calculateAvailableRefund(currentOrder)"
|
||||
:precision="2"
|
||||
class="refund-input"
|
||||
placeholder="请输入退款金额"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div class="form-label"><span class="required">*</span> 退款原因</div>
|
||||
<a-input
|
||||
v-model:value="refundForm.reason"
|
||||
placeholder="请输入退款原因"
|
||||
class="refund-input"
|
||||
allowClear
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-modal>
|
||||
</div>
|
||||
</page-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref, onMounted } from 'vue'
|
||||
import { defineComponent, ref, onMounted, onBeforeUnmount } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import PageContainer from '@/components/PageContainer.vue'
|
||||
import request from '@/utils/request'
|
||||
@ -116,61 +187,75 @@ export default defineComponent({
|
||||
title: '订单号',
|
||||
dataIndex: 'orderid',
|
||||
key: 'orderid',
|
||||
width: 180
|
||||
width: 160
|
||||
},
|
||||
{
|
||||
title: '用户ID',
|
||||
dataIndex: 'userid',
|
||||
key: 'userid',
|
||||
width: 100,
|
||||
width: 80,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '包裹数量',
|
||||
dataIndex: 'package_count',
|
||||
key: 'package_count',
|
||||
width: 100,
|
||||
width: 80,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '订单金额',
|
||||
dataIndex: 'original_amount',
|
||||
key: 'original_amount',
|
||||
width: 120,
|
||||
width: 100,
|
||||
align: 'right'
|
||||
},
|
||||
{
|
||||
title: '服务券抵扣',
|
||||
dataIndex: 'coupon_discount_amount',
|
||||
key: 'coupon_discount_amount',
|
||||
width: 120,
|
||||
width: 100,
|
||||
align: 'right'
|
||||
},
|
||||
{
|
||||
title: '积分抵扣',
|
||||
dataIndex: 'point_discount_amount',
|
||||
key: 'point_discount_amount',
|
||||
width: 120,
|
||||
width: 100,
|
||||
align: 'right'
|
||||
},
|
||||
{
|
||||
title: '最终金额',
|
||||
dataIndex: 'final_amount',
|
||||
key: 'final_amount',
|
||||
width: 120,
|
||||
width: 100,
|
||||
align: 'right'
|
||||
},
|
||||
{
|
||||
title: '退款金额',
|
||||
dataIndex: 'refund_amount',
|
||||
key: 'refund_amount',
|
||||
width: 100,
|
||||
align: 'right'
|
||||
},
|
||||
{
|
||||
title: '退款原因',
|
||||
dataIndex: 'refund_reason',
|
||||
key: 'refund_reason',
|
||||
width: 120,
|
||||
ellipsis: true
|
||||
},
|
||||
{
|
||||
title: '订单状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
width: 90,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '配送地址',
|
||||
key: 'address',
|
||||
width: 300,
|
||||
width: 250,
|
||||
ellipsis: true,
|
||||
customRender: ({ record }) => {
|
||||
const { address } = record
|
||||
@ -181,7 +266,14 @@ export default defineComponent({
|
||||
title: '下单时间',
|
||||
dataIndex: 'create_time',
|
||||
key: 'create_time',
|
||||
width: 180
|
||||
width: 160
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
fixed: 'right'
|
||||
}
|
||||
]
|
||||
|
||||
@ -276,10 +368,106 @@ export default defineComponent({
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 修复 ResizeObserver 循环错误
|
||||
const handleResizeObserverError = () => {
|
||||
const errorHandler = (error) => {
|
||||
if (error.message && error.message.includes('ResizeObserver')) {
|
||||
error.stopImmediatePropagation();
|
||||
console.warn('ResizeObserver error intercepted');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
window.addEventListener('error', errorHandler, true);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('error', errorHandler, true);
|
||||
};
|
||||
};
|
||||
|
||||
const clearErrorHandler = ref(null);
|
||||
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
fetchData();
|
||||
clearErrorHandler.value = handleResizeObserverError();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (clearErrorHandler.value) {
|
||||
clearErrorHandler.value();
|
||||
}
|
||||
});
|
||||
|
||||
// 添加退款相关状态
|
||||
const refundModalVisible = ref(false)
|
||||
const refundLoading = ref(false)
|
||||
const currentOrder = ref(null)
|
||||
const refundForm = ref({
|
||||
amount: undefined,
|
||||
reason: ''
|
||||
})
|
||||
|
||||
// 显示退款模态框
|
||||
const showRefundModal = (record) => {
|
||||
currentOrder.value = record
|
||||
refundForm.value = {
|
||||
amount: undefined,
|
||||
reason: ''
|
||||
}
|
||||
refundModalVisible.value = true
|
||||
}
|
||||
|
||||
// 计算可退款金额
|
||||
const calculateAvailableRefund = (order) => {
|
||||
if (!order) return 0
|
||||
const alreadyRefunded = order.refund_amount || 0
|
||||
return Number((order.final_amount - alreadyRefunded).toFixed(2))
|
||||
}
|
||||
|
||||
// 处理退款提交
|
||||
const handleRefundSubmit = async () => {
|
||||
// 表单验证
|
||||
if (!refundForm.value.amount) {
|
||||
message.error('请输入退款金额')
|
||||
return
|
||||
}
|
||||
|
||||
if (!refundForm.value.reason) {
|
||||
message.error('请输入退款原因')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
refundLoading.value = true
|
||||
const params = {
|
||||
order_id: currentOrder.value.orderid,
|
||||
amount: refundForm.value.amount,
|
||||
reason: refundForm.value.reason
|
||||
}
|
||||
|
||||
const res = await request.put('/api/order/admin/refund_order_amount', params)
|
||||
if (res.code === 200) {
|
||||
message.success('退款操作成功')
|
||||
refundModalVisible.value = false
|
||||
// 刷新数据
|
||||
fetchData()
|
||||
} else {
|
||||
message.error(res.message || '退款操作失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('退款操作失败:', error)
|
||||
message.error('退款操作失败')
|
||||
} finally {
|
||||
refundLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 取消退款
|
||||
const handleRefundCancel = () => {
|
||||
refundModalVisible.value = false
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
columns,
|
||||
@ -291,7 +479,15 @@ export default defineComponent({
|
||||
handleSearch,
|
||||
handleReset,
|
||||
getStatusText,
|
||||
getStatusColor
|
||||
getStatusColor,
|
||||
refundModalVisible,
|
||||
refundLoading,
|
||||
currentOrder,
|
||||
refundForm,
|
||||
showRefundModal,
|
||||
calculateAvailableRefund,
|
||||
handleRefundSubmit,
|
||||
handleRefundCancel
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -329,4 +525,127 @@ export default defineComponent({
|
||||
min-width: 60px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 优化表格组件性能 */
|
||||
:deep(.ant-table-wrapper) {
|
||||
contain: content;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
:deep(.ant-table) {
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
:deep(.ant-table-container) {
|
||||
contain: layout;
|
||||
}
|
||||
|
||||
:deep(.ant-table-tbody > tr > td) {
|
||||
padding: 12px 8px;
|
||||
contain: content;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
:deep(.ant-table-thead > tr > th) {
|
||||
padding: 12px 8px;
|
||||
contain: content;
|
||||
}
|
||||
|
||||
/* 退款模态框样式 */
|
||||
.refund-modal-content {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.order-info {
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 4px;
|
||||
padding: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.order-info-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.order-info-item .label {
|
||||
font-weight: 500;
|
||||
color: #666;
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.order-info-item .value {
|
||||
color: #333;
|
||||
font-family: monospace;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.order-amount-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.amount-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 8px 12px;
|
||||
width: 48%;
|
||||
border-radius: 4px;
|
||||
background-color: #fff;
|
||||
margin: 4px 0;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.amount-item .label {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
margin-bottom: 4px;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.amount-item .amount {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.amount-item .available {
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.refund-form {
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
color: rgba(0, 0, 0, 0.85);
|
||||
}
|
||||
|
||||
.required {
|
||||
color: #ff4d4f;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.refund-input {
|
||||
width: 100%;
|
||||
height: 32px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
:deep(.ant-input-number-input) {
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
:deep(.ant-input-number),
|
||||
:deep(.ant-input) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue
Block a user