outaozhen 3 년 전
부모
커밋
5bad6fa266

+ 14 - 21
src/pages/Institutions/Company/Detail/components/Organization.tsx

@@ -16,20 +16,20 @@ import {
   moveSortOrganizationalStructure
 } from '@/services/api/institution'
 import OrganizationModal from './OrganizationModal'
-import { ModalType } from '@/utils/enum'
+// import { ModalType } from '@/utils/enum'
 
 type OrganizationProps = {
   dataID: string
   structureType: string
 }
 
-// export enum OrganizationModalEnum {
-//   ADD = 1,
-//   ADDITEM = 2,
-//   RENAME = 3,
-//   DEL = 4,
-//   MOVE = 5
-// }
+export enum ModalTypeEnum {
+  ADD = 1,
+  ADDITEM = 2,
+  UPDATE = 3,
+  DEL = 4,
+  MOVE = 5
+}
 
 const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) => {
   const tRef = useRef<ActionType>(null)
@@ -39,8 +39,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
     expandTreeIds: [],
     defaultFormData: null,
     parentID: '',
-    currentModalType: ModalType.ADD,
-    typeEum: '1',
+    currentModalType: ModalTypeEnum.ADD,
     accountTotal: null
   })
 
@@ -128,8 +127,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                   ...state,
                   visible: true,
                   defaultFormData: record,
-                  currentModalType: ModalType.MOVE,
-                  typeEum: ModalType.MOVE
+                  currentModalType: ModalTypeEnum.MOVE
                 })
               }}>
               <Tooltip placement="top" title="移动">
@@ -149,8 +147,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                   structureType: structureType,
                   parentID: record.ID
                 },
-                currentModalType: ModalType.ADD,
-                typeEum: ModalType.ADDITEM
+                currentModalType: ModalTypeEnum.ADDITEM
               })
             }}>
             <Tooltip placement="top" title="添加子项">
@@ -164,8 +161,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                 ...state,
                 visible: true,
                 defaultFormData: record,
-                currentModalType: ModalType.UPDATE,
-                typeEum: ModalType.UPDATE
+                currentModalType: ModalTypeEnum.UPDATE
               })
             }}>
             <Tooltip placement="top" title="重命名">
@@ -181,8 +177,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                       ...state,
                       visible: true,
                       defaultFormData: record,
-                      currentModalType: ModalType.DEL,
-                      typeEum: ModalType.DEL,
+                      currentModalType: ModalTypeEnum.DEL,
                       accountTotal: record.accountTotal
                     })
                   }}
@@ -230,8 +225,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                 setState({
                   ...state,
                   visible: true,
-                  currentModalType: ModalType.ADD,
-                  typeEum: ModalType.ADD,
+                  currentModalType: ModalTypeEnum.ADD,
                   defaultFormData: {
                     dataID: dataID,
                     structureType: structureType,
@@ -246,7 +240,6 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
       />
       <OrganizationModal
         type={state.currentModalType}
-        typeEum={state.typeEum}
         visible={state.visible}
         setVisible={(visible: boolean) => setState({ ...state, visible })}
         reload={() => {

+ 15 - 17
src/pages/Institutions/Company/Detail/components/OrganizationModal.tsx

@@ -10,13 +10,12 @@ import {
   moveOrganizationalStructure,
   queryOrganizationalStructureList
 } from '@/services/api/institution'
-import { ModalType } from '@/utils/enum'
+import { ModalTypeEnum } from './Organization'
 
 type OrganizationModalProps = {
   visible: boolean
   setVisible: (visible: boolean) => void
-  type: ModalType
-  typeEum: string
+  type: ModalTypeEnum
   reload: () => void
   defaultFormData?: {
     structureType?: string
@@ -31,7 +30,6 @@ type OrganizationModalProps = {
 const OrganizationModal: React.FC<OrganizationModalProps> = ({
   visible,
   type,
-  typeEum,
   dataID,
   structureType,
   setVisible,
@@ -46,23 +44,23 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
   })
 
   const titleTypeEunm = {
-    0: {
+    1: {
       key: 'ADD',
       name: '添加父级组织'
     },
-    1: {
+    2: {
       key: 'ADDITEM',
       name: '添加子项'
     },
-    2: {
+    3: {
       key: 'UPDATE',
       name: '重命名'
     },
-    3: {
+    4: {
       key: 'DEL',
       name: '删除组织架构'
     },
-    4: {
+    5: {
       key: 'MOVE',
       name: '移动'
     }
@@ -113,11 +111,11 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
     ref.current?.validateFields().then(async values => {
       try {
         // 执行表单提交
-        if (type === ModalType.ADD) {
+        if (type === ModalTypeEnum.ADD || type === ModalTypeEnum.ADDITEM) {
           await tryAddOrganization({ ...values, ...defaultFormData })
-        } else if (type === ModalType.DEL) {
+        } else if (type === ModalTypeEnum.DEL) {
           await tryDelOrganization(values)
-        } else if (type === ModalType.MOVE) {
+        } else if (type === ModalTypeEnum.MOVE) {
           await tryMoveOrganization(values)
         } else {
           await tryUpdateOrganization(values)
@@ -137,14 +135,14 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
       width="35vw"
       visible={visible}
       // title={type === ModalType.ADD ? '添加父级组织' : '重命名'}
-      title={titleTypeEunm[typeEum].name}
+      title={titleTypeEunm[type].name}
       onCancel={() => {
         ref.current?.resetFields()
         setVisible(false)
       }}
       onOk={() => handleOnFinish()}>
       <ProForm formRef={ref} submitter={{ render: false }}>
-        {type === ModalType.ADD ? (
+        {type === ModalTypeEnum.ADD || type === ModalTypeEnum.ADDITEM ? (
           <>
             <ProFormText
               name="name"
@@ -153,7 +151,7 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
             />
           </>
         ) : null}
-        {type === ModalType.UPDATE ? (
+        {type === ModalTypeEnum.UPDATE ? (
           <>
             <ProFormText name="ID" hidden />
             <ProFormText
@@ -163,7 +161,7 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
             />
           </>
         ) : null}
-        {type === ModalType.DEL ? (
+        {type === ModalTypeEnum.DEL ? (
           <>
             <ProFormText name="ID" hidden />
             <p>确认删除?</p>
@@ -182,7 +180,7 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
             ) : null}
           </>
         ) : null}
-        {type === ModalType.MOVE ? (
+        {type === ModalTypeEnum.MOVE ? (
           <>
             <ProFormText name="ID" hidden />
             <Form.Item label="目标架构" name="moveID">