|
@@ -1,22 +1,26 @@
|
|
|
import { useRequest } from 'umi'
|
|
|
import React, { useRef, useEffect } from 'react'
|
|
|
-import { Modal, message } from 'antd'
|
|
|
+import { Modal, message, TreeSelect, Form } from 'antd'
|
|
|
import type { FormInstance } from 'antd'
|
|
|
import ProForm, { ProFormText } from '@ant-design/pro-form'
|
|
|
import {
|
|
|
addOrganizationalStructure,
|
|
|
- updateOrganizationalStructure
|
|
|
+ updateOrganizationalStructure,
|
|
|
+ delOrganizationalStructure
|
|
|
} from '@/services/api/institution'
|
|
|
|
|
|
export enum ModalType {
|
|
|
ADD = 0,
|
|
|
- UPDATE = 1
|
|
|
+ UPDATE = 1,
|
|
|
+ DEL = 2,
|
|
|
+ MOVE = 5
|
|
|
}
|
|
|
|
|
|
type OrganizationModalProps = {
|
|
|
visible: boolean
|
|
|
setVisible: (visible: boolean) => void
|
|
|
type: ModalType
|
|
|
+ typeEum: string
|
|
|
reload: () => void
|
|
|
defaultFormData?: {
|
|
|
structureType?: string
|
|
@@ -28,11 +32,34 @@ type OrganizationModalProps = {
|
|
|
const OrganizationModal: React.FC<OrganizationModalProps> = ({
|
|
|
visible,
|
|
|
type,
|
|
|
+ typeEum,
|
|
|
setVisible,
|
|
|
defaultFormData,
|
|
|
reload
|
|
|
}) => {
|
|
|
const ref = useRef<FormInstance>(null)
|
|
|
+ const titleTypeEunm = {
|
|
|
+ 1: {
|
|
|
+ key: 'ADD',
|
|
|
+ name: '添加父级组织'
|
|
|
+ },
|
|
|
+ 2: {
|
|
|
+ key: 'ADDITEM',
|
|
|
+ name: '添加子项'
|
|
|
+ },
|
|
|
+ 3: {
|
|
|
+ key: 'RENAME',
|
|
|
+ name: '重命名'
|
|
|
+ },
|
|
|
+ 4: {
|
|
|
+ key: 'DEL',
|
|
|
+ name: '删除组织架构'
|
|
|
+ },
|
|
|
+ 5: {
|
|
|
+ key: 'MOVE',
|
|
|
+ name: '移动'
|
|
|
+ }
|
|
|
+ }
|
|
|
useEffect(() => {
|
|
|
visible && defaultFormData && ref.current?.setFieldsValue({ ...defaultFormData })
|
|
|
}, [defaultFormData, visible])
|
|
@@ -48,15 +75,24 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
|
|
|
message.success('创建成功')
|
|
|
}
|
|
|
})
|
|
|
+ const { run: tryDelOrganization } = useRequest(delOrganizationalStructure, {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: () => {
|
|
|
+ message.success('删除成功')
|
|
|
+ }
|
|
|
+ })
|
|
|
const handleOnFinish = () => {
|
|
|
ref.current?.validateFields().then(async values => {
|
|
|
try {
|
|
|
// 执行表单提交
|
|
|
if (type === ModalType.ADD) {
|
|
|
- await tryAddOrganization(values)
|
|
|
+ await tryAddOrganization({ ...values, ...defaultFormData })
|
|
|
+ } else if (type === ModalType.DEL) {
|
|
|
+ await tryDelOrganization(values)
|
|
|
} else {
|
|
|
await tryUpdateOrganization(values)
|
|
|
}
|
|
|
+
|
|
|
setVisible(false)
|
|
|
|
|
|
ref.current?.resetFields()
|
|
@@ -70,20 +106,50 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
|
|
|
<Modal
|
|
|
width="35vw"
|
|
|
visible={visible}
|
|
|
- title={type === ModalType.ADD ? '添加父级组织' : '重命名'}
|
|
|
+ // title={type === ModalType.ADD ? '添加父级组织' : '重命名'}
|
|
|
+ title={titleTypeEunm[typeEum].name}
|
|
|
onCancel={() => {
|
|
|
ref.current?.resetFields()
|
|
|
setVisible(false)
|
|
|
}}
|
|
|
onOk={() => handleOnFinish()}>
|
|
|
- <ProForm formRef={ref} submitter={{ render: false }}>
|
|
|
- {type === ModalType.UPDATE ? <ProFormText name="ID" hidden /> : null}
|
|
|
- <ProFormText
|
|
|
- name="name"
|
|
|
- label="组织架构名称"
|
|
|
- rules={[{ required: true, message: '请输入组织架构名称' }]}
|
|
|
- />
|
|
|
- </ProForm>
|
|
|
+ {type === ModalType.ADD ? (
|
|
|
+ <ProForm formRef={ref} submitter={{ render: false }}>
|
|
|
+ <ProFormText
|
|
|
+ name="name"
|
|
|
+ label="组织架构名称"
|
|
|
+ rules={[{ required: true, message: '请输入组织架构名称' }]}
|
|
|
+ />
|
|
|
+ </ProForm>
|
|
|
+ ) : null}
|
|
|
+ {type === ModalType.UPDATE ? (
|
|
|
+ <ProForm formRef={ref} submitter={{ render: false }}>
|
|
|
+ <ProFormText name="ID" hidden />
|
|
|
+ <ProFormText
|
|
|
+ name="name"
|
|
|
+ label="组织架构名称"
|
|
|
+ rules={[{ required: true, message: '请输入组织架构名称' }]}
|
|
|
+ />
|
|
|
+ </ProForm>
|
|
|
+ ) : null}
|
|
|
+ {type === ModalType.DEL ? (
|
|
|
+ <ProForm formRef={ref} submitter={{ render: false }}>
|
|
|
+ <ProFormText name="ID" hidden />
|
|
|
+ <p>确认删除?</p>
|
|
|
+ </ProForm>
|
|
|
+ ) : null}
|
|
|
+ {type === ModalType.MOVE ? (
|
|
|
+ <ProForm formRef={ref} submitter={{ render: false }}>
|
|
|
+ <ProFormText name="ID" hidden />
|
|
|
+ <Form.Item label="目标架构" name="moveID">
|
|
|
+ <TreeSelect
|
|
|
+ style={{ width: '100%' }}
|
|
|
+ placeholder="请选择目标架构"
|
|
|
+ treeDefaultExpandAll
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ </ProForm>
|
|
|
+ ) : null}
|
|
|
</Modal>
|
|
|
)
|
|
|
}
|