feat: 退款订单与订单列表整合

This commit is contained in:
2025-10-29 15:00:32 +08:00
parent e419ed10f1
commit e226bd11c2
8 changed files with 234 additions and 21 deletions
@@ -1,6 +1,6 @@
// UTF-8: 退款审核弹框组件
import React, { useState, useEffect } from 'react';
import { Modal, Form, Select, Input, message, Empty, Image, Space, Row, Col, Divider } from 'antd';
import { Modal, Form, Select, Input, message, Empty, Image, Space, Row, Col, Divider, InputNumber, Button } from 'antd';
import { ordersApi } from '@/services/orders';
interface RefundReviewModalProps {
@@ -22,6 +22,8 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
const [loading, setLoading] = useState(false);
const [refundData, setRefundData] = useState<any>(null);
const [fetching, setFetching] = useState(false);
const [editingAmount, setEditingAmount] = useState(false);
const [customRefundAmount, setCustomRefundAmount] = useState<number | null>(null);
// 审核结果选项
const reviewResults = [
@@ -54,10 +56,23 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
}
};
// 根据status获取退款状态的文案和颜色
const getRefundStatusInfo = (status: number) => {
const statusMap: Record<number, { text: string; bgColor: string; textColor: string }> = {
7: { text: '退款中', bgColor: '#fff7e6', textColor: '#d46b08' }, // orange
8: { text: '退款成功', bgColor: '#f6ffed', textColor: '#52c41a' }, // lime
9: { text: '退款失败', bgColor: '#fff1f0', textColor: '#f5222d' }, // red
};
return statusMap[status] || { text: '未知状态', bgColor: '#f5f5f5', textColor: '#666' };
};
// 获取退款订单详情
useEffect(() => {
if (visible && orderNo) {
fetchRefundDetail();
// 打开弹窗时清空编辑状态
setEditingAmount(false);
setCustomRefundAmount(null);
}
}, [visible, orderNo]);
@@ -92,13 +107,20 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
const values = await form.validateFields();
setLoading(true);
// 调用审核接口(需要与后端 RefundController.approveOrder 的参数匹配)
const res = await ordersApi.updateRefund({
orderNo: refundData?.orderNo, // 订单号(后端需要校验订单状态)
refundNo: refundData?.refundNo, // 退款单号
status: refundData?.status, // 退款状态(应保持为 REFUNDING)
state: values.reviewResult, // 审核状态:1=通过(APPROVED),0=拒绝(REFUSED)
approveReason: values.reviewComment, // 审核意见
// 计算实际退款金额(分)
// 如果用户编辑了退款金额,就用编辑的,否则用原始退款金额
const actualRefundAmount = customRefundAmount !== null
? Math.round(customRefundAmount * 100) // 元转分
: refundData?.refundAmount;
// 调用自定义金额的退款审核接口
const res = await ordersApi.approveRefundWithCustomAmount({
orderNo: refundData?.orderNo,
refundNo: refundData?.refundNo,
refundAmount: String(actualRefundAmount), // 后端期望字符串格式
status: 7, // 退款中状态码
state: values.reviewResult, // 审核状态:1=通过(APPROVED),0=拒绝(REFUSED)
approveReason: values.reviewComment, // 审核意见
});
// 显示后端返回的实际消息
@@ -161,7 +183,63 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
<Col span={12}>
<div>
<span style={{ fontWeight: 'bold' }}>退款金额</span>
<div style={{ marginTop: 4 }}>¥ {formatAmount(refundData?.refundAmount)}</div>
{editingAmount ? (
<div style={{ marginTop: 4, display: 'flex', gap: 8, alignItems: 'center' }}>
<InputNumber
style={{ flex: 1 }}
value={customRefundAmount}
onChange={setCustomRefundAmount}
min={0.01}
max={parseFloat(formatAmount(refundData?.orderAmount))}
step={0.01}
precision={2}
prefix="¥"
/>
<Button
size="small"
type="primary"
onClick={() => {
if (customRefundAmount === null || customRefundAmount <= 0) {
message.error('请输入大于0的退款金额');
return;
}
// 校验通过,关闭编辑模式
setEditingAmount(false);
}}
>
确定
</Button>
<Button
size="small"
onClick={() => {
// 取消编辑,恢复原值
setEditingAmount(false);
setCustomRefundAmount(null);
message.info('已取消编辑');
}}
>
取消
</Button>
</div>
) : (
<div style={{ marginTop: 4, display: 'flex', gap: 8, alignItems: 'center' }}>
<span>¥ {customRefundAmount !== null ? customRefundAmount.toFixed(2) : formatAmount(refundData?.refundAmount)}</span>
{isReviewMode && (
<Button
size="small"
onClick={() => {
// 编辑时,如果还没有自定义金额,则使用接口返回的原始金额
if (customRefundAmount === null) {
setCustomRefundAmount(parseFloat(formatAmount(refundData?.refundAmount)));
}
setEditingAmount(true);
}}
>
编辑
</Button>
)}
</div>
)}
</div>
</Col>
</Row>
@@ -172,20 +250,30 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
<Row gutter={[16, 16]}>
<Col span={12}>
<div>
<span style={{ fontWeight: 'bold' }}>订单状态</span>
<span style={{ fontWeight: 'bold' }}>退款状态</span>
<div style={{ marginTop: 4 }}>
<span style={{ padding: '2px 8px', backgroundColor: '#fff7e6', color: '#d46b08', borderRadius: 2 }}>
{refundData?.orderStatus || '退款中'}
</span>
{(() => {
const statusInfo = getRefundStatusInfo(refundData?.status);
return (
<span style={{
padding: '2px 8px',
backgroundColor: statusInfo.bgColor,
color: statusInfo.textColor,
borderRadius: 2
}}>
{statusInfo.text}
</span>
);
})()}
</div>
</div>
</Col>
<Col span={12}>
<div>
<span style={{ fontWeight: 'bold' }}>退款状态</span>
<span style={{ fontWeight: 'bold' }}>订单状态</span>
<div style={{ marginTop: 4 }}>
<span style={{ padding: '2px 8px', backgroundColor: '#f6f8fb', color: '#000', borderRadius: 2 }}>
{refundData?.status === 1 ? '待审核' : refundData?.status === 2 ? '已审核' : '待审核'}
{refundData?.orderStatus || '-'}
</span>
</div>
</div>
@@ -155,6 +155,11 @@ export const ordersApi = {
const res = await request('/api-order/refund/approve', { method: 'POST', data });
return (res as any).data || res;
},
// 审核退款(支持自定义退款金额)
approveRefundWithCustomAmount: async (data: any) => {
const res = await request('/api-order/refund/approve/custom', { method: 'POST', data });
return (res as any).data || res;
},
createRefund: async (payload: { orderNo: string }) => {
const res = await request('/api-order/refund/auto', { method: 'PUT', data: payload });
return (res as any).data || res;