2025-03-28 15:30:35 +08:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
|
import {
|
|
|
|
|
ModalForm,
|
|
|
|
|
ProForm,
|
|
|
|
|
ProFormDigit,
|
|
|
|
|
ProFormRadio,
|
2025-04-02 19:07:15 +08:00
|
|
|
ProFormTreeSelect,
|
2025-03-28 15:30:35 +08:00
|
|
|
ProFormText,
|
2025-03-31 17:43:40 +08:00
|
|
|
ProDescriptions,
|
2025-03-28 15:30:35 +08:00
|
|
|
} from '@ant-design/pro-components';
|
|
|
|
|
import { Form } from 'antd';
|
|
|
|
|
import { DictValueEnumObj } from '@/components/DictTag';
|
|
|
|
|
import { FormattedMessage } from '@@/exports';
|
2025-04-02 19:07:15 +08:00
|
|
|
import { getCmsIndustryTreeList } from '@/services/classify/industry'; // 修改导入为 getCmsIndustryTreeList
|
2025-03-31 17:43:40 +08:00
|
|
|
|
2025-04-02 19:07:15 +08:00
|
|
|
interface IndustryDetail {
|
|
|
|
|
id?: number;
|
|
|
|
|
industryName?: string;
|
|
|
|
|
orderNum?: number;
|
|
|
|
|
status?: string;
|
|
|
|
|
parentId?: number;
|
|
|
|
|
parentName?: string;
|
2025-03-31 17:43:40 +08:00
|
|
|
}
|
2025-03-28 15:30:35 +08:00
|
|
|
|
|
|
|
|
export type ListFormProps = {
|
|
|
|
|
onCancel: (flag?: boolean, formVars?: unknown) => void;
|
2025-04-02 19:07:15 +08:00
|
|
|
onSubmit: (values: any) => Promise<void>;
|
2025-03-28 15:30:35 +08:00
|
|
|
open: boolean;
|
2025-04-02 19:07:15 +08:00
|
|
|
values?: Partial<IndustryDetail>;
|
2025-03-28 15:30:35 +08:00
|
|
|
industryStatusEnum: DictValueEnumObj;
|
2025-03-31 17:43:40 +08:00
|
|
|
mode?: 'view' | 'edit' | 'create';
|
2025-03-28 15:30:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const listEdit: React.FC<ListFormProps> = (props) => {
|
|
|
|
|
const [form] = Form.useForm();
|
2025-04-02 19:07:15 +08:00
|
|
|
const { industryStatusEnum, mode = props.values ? 'edit' : 'create', values } = props;
|
|
|
|
|
|
2025-03-28 15:30:35 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
form.resetFields();
|
2025-03-31 17:43:40 +08:00
|
|
|
if (values) {
|
2025-04-02 19:07:15 +08:00
|
|
|
form.setFieldsValue({
|
|
|
|
|
...values,
|
|
|
|
|
parentId: values?.parentId ?? 0
|
|
|
|
|
});
|
2025-03-28 15:30:35 +08:00
|
|
|
}
|
2025-04-02 19:07:15 +08:00
|
|
|
}, [form, values?.id]);
|
2025-03-31 17:43:40 +08:00
|
|
|
|
2025-04-02 19:07:15 +08:00
|
|
|
const getSafeDetailData = (data?: Partial<IndustryDetail>): IndustryDetail => {
|
|
|
|
|
return {
|
|
|
|
|
id: data?.id ?? 0,
|
|
|
|
|
industryName: data?.industryName ?? '',
|
|
|
|
|
orderNum: data?.orderNum ?? 0,
|
|
|
|
|
parentId: data?.parentId ?? 0,
|
|
|
|
|
parentName: data?.parentName ?? '顶级节点',
|
|
|
|
|
status: data?.status ?? '0',
|
|
|
|
|
};
|
2025-03-31 17:43:40 +08:00
|
|
|
};
|
2025-03-28 15:30:35 +08:00
|
|
|
|
|
|
|
|
const handleCancel = () => {
|
|
|
|
|
props.onCancel();
|
|
|
|
|
form.resetFields();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleFinish = async (values: Record<string, any>) => {
|
2025-04-02 19:07:15 +08:00
|
|
|
const submitValues = {
|
|
|
|
|
...values,
|
|
|
|
|
parentId: values.parentId === 0 ? undefined : values.parentId
|
|
|
|
|
};
|
|
|
|
|
props.onSubmit(submitValues);
|
2025-03-28 15:30:35 +08:00
|
|
|
};
|
2025-04-02 19:07:15 +08:00
|
|
|
|
|
|
|
|
// 获取行业树数据
|
|
|
|
|
const fetchIndustryTree = async () => {
|
|
|
|
|
const res = await getCmsIndustryTreeList();
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
id: 0,
|
|
|
|
|
label: '顶级节点',
|
|
|
|
|
value: 0,
|
|
|
|
|
children: res.data || []
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (mode === 'view') {
|
|
|
|
|
return (
|
|
|
|
|
<ModalForm
|
|
|
|
|
title="行业详情"
|
|
|
|
|
open={props.open}
|
|
|
|
|
width={800}
|
|
|
|
|
modalProps={{
|
|
|
|
|
destroyOnClose: true,
|
|
|
|
|
onCancel: () => handleCancel(),
|
|
|
|
|
footer: null,
|
|
|
|
|
}}
|
|
|
|
|
submitter={false}
|
2025-03-31 17:43:40 +08:00
|
|
|
>
|
2025-04-02 19:07:15 +08:00
|
|
|
<ProDescriptions<IndustryDetail>
|
2025-03-31 17:43:40 +08:00
|
|
|
column={1}
|
|
|
|
|
dataSource={getSafeDetailData(values)}
|
|
|
|
|
loading={!values}
|
|
|
|
|
>
|
2025-04-02 19:07:15 +08:00
|
|
|
<ProDescriptions.Item label="行业ID" dataIndex="id" />
|
2025-03-31 17:43:40 +08:00
|
|
|
<ProDescriptions.Item label="行业名称" dataIndex="industryName" />
|
|
|
|
|
<ProDescriptions.Item label="显示顺序" dataIndex="orderNum" />
|
|
|
|
|
<ProDescriptions.Item
|
|
|
|
|
label="父行业"
|
|
|
|
|
dataIndex="parentName"
|
2025-04-02 19:07:15 +08:00
|
|
|
renderText={(text, record) => record.parentId === 0 ? '顶级节点' : text}
|
2025-03-31 17:43:40 +08:00
|
|
|
/>
|
|
|
|
|
<ProDescriptions.Item
|
|
|
|
|
label="行业状态"
|
|
|
|
|
dataIndex="status"
|
|
|
|
|
valueEnum={industryStatusEnum}
|
|
|
|
|
/>
|
|
|
|
|
</ProDescriptions>
|
|
|
|
|
</ModalForm>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-04-02 19:07:15 +08:00
|
|
|
|
2025-03-28 15:30:35 +08:00
|
|
|
return (
|
2025-03-31 17:43:40 +08:00
|
|
|
<ModalForm
|
|
|
|
|
title={`${values ? '编辑' : '新增'}行业`}
|
2025-03-28 15:30:35 +08:00
|
|
|
form={form}
|
|
|
|
|
autoFocusFirstInput
|
|
|
|
|
open={props.open}
|
|
|
|
|
modalProps={{
|
|
|
|
|
destroyOnClose: true,
|
|
|
|
|
onCancel: () => handleCancel(),
|
|
|
|
|
}}
|
|
|
|
|
submitTimeout={2000}
|
|
|
|
|
onFinish={handleFinish}
|
|
|
|
|
>
|
2025-04-02 19:07:15 +08:00
|
|
|
<ProFormDigit name="id" disabled hidden={true} />
|
2025-03-28 15:30:35 +08:00
|
|
|
<ProForm.Group>
|
2025-04-02 19:07:15 +08:00
|
|
|
<ProFormText
|
|
|
|
|
width="md"
|
|
|
|
|
name="industryName"
|
|
|
|
|
label="行业名称"
|
|
|
|
|
placeholder="请输入行业名称"
|
|
|
|
|
rules={[{ required: true, message: '请输入行业名称' }]}
|
|
|
|
|
/>
|
2025-03-28 15:30:35 +08:00
|
|
|
<ProFormDigit
|
|
|
|
|
label="显示顺序"
|
|
|
|
|
name="orderNum"
|
|
|
|
|
width="md"
|
|
|
|
|
min={0}
|
|
|
|
|
placeholder="请输入显示顺序"
|
2025-04-02 19:07:15 +08:00
|
|
|
rules={[{ required: true, message: '请输入显示顺序' }]}
|
2025-03-28 15:30:35 +08:00
|
|
|
/>
|
|
|
|
|
</ProForm.Group>
|
|
|
|
|
<ProForm.Group>
|
2025-04-02 19:07:15 +08:00
|
|
|
<ProFormTreeSelect
|
2025-03-28 15:30:35 +08:00
|
|
|
name="parentId"
|
|
|
|
|
label="父行业"
|
2025-04-02 19:07:15 +08:00
|
|
|
placeholder="请选择父行业"
|
2025-03-28 15:30:35 +08:00
|
|
|
allowClear
|
|
|
|
|
width="md"
|
2025-04-02 19:07:15 +08:00
|
|
|
request={fetchIndustryTree}
|
2025-03-28 15:30:35 +08:00
|
|
|
fieldProps={{
|
2025-04-02 19:07:15 +08:00
|
|
|
treeDefaultExpandAll: true,
|
2025-03-28 15:30:35 +08:00
|
|
|
showSearch: true,
|
2025-04-02 19:07:15 +08:00
|
|
|
filterTreeNode: true,
|
2025-03-28 15:30:35 +08:00
|
|
|
fieldNames: {
|
|
|
|
|
label: 'label',
|
|
|
|
|
value: 'id',
|
2025-04-02 19:07:15 +08:00
|
|
|
children: 'children',
|
|
|
|
|
},
|
|
|
|
|
dropdownStyle: {
|
|
|
|
|
maxHeight: 400,
|
|
|
|
|
overflow: 'auto',
|
2025-03-28 15:30:35 +08:00
|
|
|
},
|
|
|
|
|
}}
|
2025-04-02 19:07:15 +08:00
|
|
|
rules={[{ required: true, message: '请选择父行业' }]}
|
2025-03-28 15:30:35 +08:00
|
|
|
/>
|
|
|
|
|
<ProFormRadio.Group
|
|
|
|
|
valueEnum={industryStatusEnum}
|
|
|
|
|
name="status"
|
|
|
|
|
label="行业状态"
|
|
|
|
|
width="md"
|
2025-04-02 19:07:15 +08:00
|
|
|
initialValue="0"
|
|
|
|
|
rules={[{ required: true, message: '请选择行业状态' }]}
|
2025-03-28 15:30:35 +08:00
|
|
|
/>
|
|
|
|
|
</ProForm.Group>
|
|
|
|
|
</ModalForm>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-02 19:07:15 +08:00
|
|
|
export default listEdit;
|