feat: support refund

This commit is contained in:
Rogee
2025-05-06 21:16:23 +08:00
parent 533c9b70af
commit 811ed3a41f
6 changed files with 101 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
import { orderService } from '@/api/orderService';
import { formatDate } from '@/utils/date';
import Badge from 'primevue/badge';
import Button from 'primevue/button';
import Column from 'primevue/column';
import ConfirmDialog from 'primevue/confirmdialog';
import DataTable from 'primevue/datatable';
@@ -17,6 +18,7 @@ const confirm = useConfirm();
const globalFilterValue = ref('');
const loading = ref(false);
const refunding = ref(false);
const searchTimeout = ref(null);
const filters = ref({
global: { value: null, matchMode: 'contains' },
@@ -57,7 +59,31 @@ const getFinalPrice = (price, discount) => {
return price - getDiscountAmount(price, discount);
};
const handleRefund = (id) => {
confirm.require({
message: '确定要对此订单进行退款操作吗?',
header: '退款确认',
icon: 'pi pi-exclamation-triangle',
rejectProps: {
label: '取消',
icon: 'pi pi-times',
outlined: true,
size: 'small'
},
acceptProps: {
label: '确认',
icon: 'pi pi-check',
size: 'small'
},
acceptClass: 'p-button-success',
accept: () => {
refundOrder(id);
}
});
};
const refundOrder = async (id) => {
refunding.value = true;
try {
await orderService.refund(id)
fetchOrders();
@@ -65,7 +91,7 @@ const refundOrder = async (id) => {
console.error('Failed to refund orders:', error);
toast.add({ severity: 'error', summary: '错误', detail: ' 退款失败', life: 3000 });
} finally {
loading.value = false;
refunding.value = false;
}
}
@@ -194,6 +220,14 @@ onMounted(() => {
</div>
</template>
</Column>
<Column field="actions" header="操作">
<template #body="{ data }">
<Button v-if="data.status === 7" icon="pi pi-replay" severity="danger" class="text-nowrap!"
size="small" @click="handleRefund(data.id)" :loading="refunding">
退款
</Button>
</template>
</Column>
</DataTable>
</div>
</div>