pay-admin/src/pages/company/organizations/modals/OrganizationCreate.tsx

91 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-06-30 14:24:39 +08:00
import {
MyBetaModalFormProps,
MyButtons,
MyFormItems,
MyModalFormProps,
rulesHelper,
} from '@/common';
2025-06-30 15:55:47 +08:00
import { Selects } from '@/components/Select';
2025-06-30 14:24:39 +08:00
import { Apis } from '@/gen/Apis';
2025-06-30 15:55:47 +08:00
import { OrganizationsTypeEnum } from '@/gen/Enums';
2025-06-30 14:24:39 +08:00
import { BetaSchemaForm } from '@ant-design/pro-components';
2025-07-16 10:18:01 +08:00
import { Form, message } from 'antd';
2025-06-30 14:24:39 +08:00
export default function Create(props: MyBetaModalFormProps) {
2025-07-16 10:18:01 +08:00
const [form] = Form.useForm();
2025-06-30 14:24:39 +08:00
return (
2025-06-30 15:55:47 +08:00
<BetaSchemaForm<ApiTypes.Company.Organizations.Store>
2025-06-30 14:24:39 +08:00
{...MyModalFormProps.props}
title={`添加${props.title}`}
wrapperCol={{ span: 24 }}
2025-07-16 10:18:01 +08:00
width="500px"
2025-06-30 14:24:39 +08:00
trigger={<MyButtons.Create title={`添加${props.title}`} />}
key={new Date().getTime()}
2025-07-16 10:18:01 +08:00
form={form}
onOpenChange={(open: any) => {
if (open) {
form.resetFields(); // 清空表单数据
}
}}
2025-07-17 13:58:54 +08:00
onFinish={async (values: any) =>
2025-06-30 15:55:47 +08:00
Apis.Company.Organizations.Store({
...values,
companies_id: values?.companies_id || props?.item?.companies_id,
2025-07-17 13:58:54 +08:00
parent_id: values?.parent_id?.[values.parent_id.length - 1],
2025-06-30 15:55:47 +08:00
})
2025-06-30 14:24:39 +08:00
.then(() => {
props.reload?.();
message.success(props.title + '成功');
return true;
})
.catch(() => false)
}
columns={[
...(props?.item?.id
? []
: [
Selects?.Companies({
key: 'companies_id',
title: '公司',
colProps: { span: 24 },
required: true,
}),
]),
MyFormItems.EnumRadio({
key: 'type',
2025-12-13 13:23:48 +08:00
title: '类型',
2025-06-30 15:55:47 +08:00
colProps: { span: 24 },
valueEnum: OrganizationsTypeEnum,
required: true,
2025-06-30 15:55:47 +08:00
}),
2025-06-30 14:24:39 +08:00
{
key: 'name',
2025-06-30 15:55:47 +08:00
title: '组织名称',
colProps: { span: 24 },
2025-06-30 14:24:39 +08:00
formItemProps: { ...rulesHelper.text },
},
{
name: ['type'],
valueType: 'dependency',
columns: ({ type }: any) => {
return type !== OrganizationsTypeEnum.Group.value
? [
Selects?.OrganizationsTree({
2025-12-13 13:23:48 +08:00
title: '设置上级组织(可选)',
key: 'parent_id',
params: { companies_id: props?.item?.id },
colProps: { span: 24 },
fieldProps: {
placeholder: '可搜索或手动选择上级组织',
},
}),
]
: [];
},
},
2025-06-30 14:24:39 +08:00
]}
/>
);
}