feat: 根据订单号创建退款单功能开发
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
.createModal {
|
||||
:global {
|
||||
.ant-modal-header {
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
padding: 16px 24px;
|
||||
}
|
||||
|
||||
.ant-modal-body {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.ant-form-item-label > label {
|
||||
font-weight: 500;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.ant-input {
|
||||
border-radius: 4px;
|
||||
|
||||
&:focus {
|
||||
border-color: #1890ff;
|
||||
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tips {
|
||||
margin-top: 16px;
|
||||
padding: 12px 16px;
|
||||
background-color: #f6ffed;
|
||||
border: 1px solid #b7eb8f;
|
||||
border-radius: 4px;
|
||||
|
||||
p {
|
||||
margin: 0 0 4px 0;
|
||||
color: #52c41a;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { message } from 'antd';
|
||||
import React from 'react';
|
||||
import { createRefund } from '@/services/orders/api';
|
||||
import styles from './CreateRefundForm.less';
|
||||
|
||||
interface CreateRefundFormProps {
|
||||
onSubmit: (values: any) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
createModalVisible: boolean;
|
||||
}
|
||||
|
||||
const CreateRefundForm: React.FC<CreateRefundFormProps> = (props) => {
|
||||
return (
|
||||
<ModalForm
|
||||
title="创建退款订单"
|
||||
width={500}
|
||||
visible={props.createModalVisible}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
onFinish={async (values) => {
|
||||
try {
|
||||
// 检查用户是否已登录
|
||||
const accessToken = sessionStorage.getItem('access_token');
|
||||
if (!accessToken) {
|
||||
message.error('请先登录');
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('开始创建退款订单,订单号:', values.orderNo);
|
||||
|
||||
const result = await createRefund(values.orderNo);
|
||||
console.log('创建退款订单结果:', result);
|
||||
|
||||
if (result.resp_code === 0) {
|
||||
message.success('退款订单创建成功');
|
||||
props.onSubmit(values);
|
||||
return true;
|
||||
} else {
|
||||
const errorMsg = result.resp_msg || '创建失败';
|
||||
console.error('创建退款订单失败:', errorMsg);
|
||||
message.error(errorMsg);
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('创建退款订单异常:', error);
|
||||
message.error('创建退款订单失败,请检查网络连接或联系管理员');
|
||||
return false;
|
||||
}
|
||||
}}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
className: styles.createModal
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
name="orderNo"
|
||||
label="订单编号"
|
||||
placeholder="请输入订单编号"
|
||||
rules={[
|
||||
{ required: true, message: '请输入订单编号' },
|
||||
{ pattern: /^[A-Za-z0-9]+$/, message: '订单编号只能包含字母和数字' }
|
||||
]}
|
||||
fieldProps={{
|
||||
maxLength: 50,
|
||||
}}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<div className={styles.tips}>
|
||||
<p>• 请输入需要退款的订单编号</p>
|
||||
<p>• 系统将自动创建退款申请</p>
|
||||
<p>• 创建后可在列表中查看退款状态</p>
|
||||
</div>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateRefundForm;
|
||||
@@ -59,6 +59,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
.createButton {
|
||||
margin-bottom: 16px;
|
||||
|
||||
:global {
|
||||
.ant-btn {
|
||||
height: 36px;
|
||||
font-weight: 500;
|
||||
box-shadow: 0 2px 4px rgba(24, 144, 255, 0.2);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 8px rgba(24, 144, 255, 0.3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.queryFilter {
|
||||
:global {
|
||||
.ant-form-item {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { refund, updateRefund } from '@/services/orders/api';
|
||||
import { refund, updateRefund, createRefund } from '@/services/orders/api';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
PageContainer,
|
||||
@@ -7,10 +7,12 @@ import {
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, Tag, Space, message, Card } from 'antd';
|
||||
import { Typography, Tag, Space, message, Card, Button } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { ORDER_STATUS, REFUND_STATUS, REFUND_ORDER_STATUS } from './constants';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import CreateRefundForm from './components/CreateRefundForm';
|
||||
import type { RefundItem } from './types';
|
||||
import styles from './index.less';
|
||||
|
||||
@@ -42,8 +44,14 @@ const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
||||
const [createModalVisible, setCreateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<RefundItem>();
|
||||
|
||||
// 检查用户是否已登录
|
||||
const isLoggedIn = () => {
|
||||
return !!sessionStorage.getItem('access_token');
|
||||
};
|
||||
|
||||
const columns: ProColumns<RefundItem>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
@@ -126,7 +134,7 @@ const TableList: React.FC = () => {
|
||||
align: 'center',
|
||||
render: (_, record) => (
|
||||
<Space size="middle">
|
||||
{record.state === 0 && (
|
||||
{String(record.state) === '0' && (
|
||||
<Link
|
||||
className={styles.actionLink}
|
||||
onClick={() => {
|
||||
@@ -199,7 +207,14 @@ const TableList: React.FC = () => {
|
||||
rowKey="id"
|
||||
headerTitle="退款列表"
|
||||
actionRef={actionRef}
|
||||
request={refund}
|
||||
request={async (params) => {
|
||||
const result = await refund(params);
|
||||
return {
|
||||
data: result.data as any,
|
||||
total: result.total,
|
||||
success: true,
|
||||
};
|
||||
}}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
@@ -212,27 +227,48 @@ const TableList: React.FC = () => {
|
||||
scroll={{ x: 'max-content' }}
|
||||
dateFormatter="string"
|
||||
className={styles.customTable}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
key="create"
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => {
|
||||
if (!isLoggedIn()) {
|
||||
message.error('请先登录');
|
||||
return;
|
||||
}
|
||||
setCreateModalVisible(true);
|
||||
}}
|
||||
disabled={!isLoggedIn()}
|
||||
>
|
||||
创建退款
|
||||
</Button>
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
if (!currentRow) return false;
|
||||
if (!currentRow) return;
|
||||
const success = await updateRefund({ ...currentRow, ...values });
|
||||
if (success) {
|
||||
setUpdateModalVisible(false);
|
||||
actionRef.current?.reload();
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
return success;
|
||||
}}
|
||||
onVisibleChange={setUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
refundStatusOptions={Object.entries(REFUND_STATUS).map(([key, value]) => ({
|
||||
label: value.text,
|
||||
value: Number(key),
|
||||
}))}
|
||||
/>
|
||||
|
||||
<CreateRefundForm
|
||||
onSubmit={async () => {
|
||||
setCreateModalVisible(false);
|
||||
actionRef.current?.reload();
|
||||
}}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
createModalVisible={createModalVisible}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
@@ -154,6 +154,19 @@ export async function updateRefund(data: ORDERS.Refund): Promise<API.Result<ORDE
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 创建退款订单 */
|
||||
export async function createRefund(orderNo: string): Promise<API.Result<ORDERS.Refund>> {
|
||||
console.log('开始创建退款订单,订单号:', orderNo);
|
||||
|
||||
const result = await request<API.Result<ORDERS.Refund>>('/api-order/refund/auto', {
|
||||
method: 'PUT',
|
||||
params: { orderNo },
|
||||
});
|
||||
|
||||
console.log('创建退款订单响应:', result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 获取景区列表 */
|
||||
export async function getTourismList(params: {
|
||||
page: number;
|
||||
|
||||
Reference in New Issue
Block a user