Pārlūkot izejas kodu

fix: 组织架构弹窗BUG

outaozhen 3 gadi atpakaļ
vecāks
revīzija
bc16c0dbd3

+ 28 - 26
src/pages/Institutions/Company/Detail/components/Organization.tsx

@@ -16,19 +16,20 @@ import {
   moveSortOrganizationalStructure
 } from '@/services/api/institution'
 import OrganizationModal from './OrganizationModal'
+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 OrganizationModalEnum {
+//   ADD = 1,
+//   ADDITEM = 2,
+//   RENAME = 3,
+//   DEL = 4,
+//   MOVE = 5
+// }
 
 const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) => {
   const tRef = useRef<ActionType>(null)
@@ -38,7 +39,8 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
     expandTreeIds: [],
     defaultFormData: null,
     parentID: '',
-    modalType: OrganizationModalEnum.ADD,
+    currentModalType: ModalType.ADD,
+    typeEum: '1',
     accountTotal: null
   })
 
@@ -98,8 +100,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                 title="确认上移吗?"
                 okText="确认"
                 cancelText="取消"
-                onConfirm={() => tryMoveOrganization({ ID: record.ID, operation: 'up' })}
-              >
+                onConfirm={() => tryMoveOrganization({ ID: record.ID, operation: 'up' })}>
                 <Tooltip placement="top" title="上移">
                   <ArrowUpOutlined />
                 </Tooltip>
@@ -112,8 +113,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                 title="确认下移吗?"
                 okText="确认"
                 cancelText="取消"
-                onConfirm={() => tryMoveOrganization({ ID: record.ID, operation: 'down' })}
-              >
+                onConfirm={() => tryMoveOrganization({ ID: record.ID, operation: 'down' })}>
                 <Tooltip placement="top" title="下移">
                   <ArrowDownOutlined />
                 </Tooltip>
@@ -128,10 +128,10 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                   ...state,
                   visible: true,
                   defaultFormData: record,
-                  modalType: OrganizationModalEnum.MOVE
+                  currentModalType: ModalType.MOVE,
+                  typeEum: ModalType.MOVE
                 })
-              }}
-            >
+              }}>
               <Tooltip placement="top" title="移动">
                 <SwapOutlined />
               </Tooltip>
@@ -149,10 +149,10 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                   structureType: structureType,
                   parentID: record.ID
                 },
-                modalType: OrganizationModalEnum.ADDITEM
+                currentModalType: ModalType.ADD,
+                typeEum: ModalType.ADDITEM
               })
-            }}
-          >
+            }}>
             <Tooltip placement="top" title="添加子项">
               <PlusSquareOutlined />
             </Tooltip>
@@ -164,10 +164,10 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                 ...state,
                 visible: true,
                 defaultFormData: record,
-                modalType: OrganizationModalEnum.RENAME
+                currentModalType: ModalType.UPDATE,
+                typeEum: ModalType.UPDATE
               })
-            }}
-          >
+            }}>
             <Tooltip placement="top" title="重命名">
               <EditOutlined />
             </Tooltip>
@@ -181,7 +181,8 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                       ...state,
                       visible: true,
                       defaultFormData: record,
-                      modalType: OrganizationModalEnum.DEL,
+                      currentModalType: ModalType.DEL,
+                      typeEum: ModalType.DEL,
                       accountTotal: record.accountTotal
                     })
                   }}
@@ -229,22 +230,23 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                 setState({
                   ...state,
                   visible: true,
-                  modalType: OrganizationModalEnum.ADD,
+                  currentModalType: ModalType.ADD,
+                  typeEum: ModalType.ADD,
                   defaultFormData: {
                     dataID: dataID,
                     structureType: structureType,
                     parentID: state.parentID
                   }
                 })
-              }
-            >
+              }>
               添加组织
             </Button>
           ]
         }}
       />
       <OrganizationModal
-        type={state.modalType}
+        type={state.currentModalType}
+        typeEum={state.typeEum}
         visible={state.visible}
         setVisible={(visible: boolean) => setState({ ...state, visible })}
         reload={() => {

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

@@ -10,12 +10,13 @@ import {
   moveOrganizationalStructure,
   queryOrganizationalStructureList
 } from '@/services/api/institution'
-import { OrganizationModalEnum } from './Organization'
+import { ModalType } from '@/utils/enum'
 
 type OrganizationModalProps = {
   visible: boolean
   setVisible: (visible: boolean) => void
-  type: OrganizationModalEnum
+  type: ModalType
+  typeEum: string
   reload: () => void
   defaultFormData?: {
     structureType?: string
@@ -30,6 +31,7 @@ type OrganizationModalProps = {
 const OrganizationModal: React.FC<OrganizationModalProps> = ({
   visible,
   type,
+  typeEum,
   dataID,
   structureType,
   setVisible,
@@ -37,30 +39,30 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
   accountTotal,
   reload
 }) => {
-  console.log(type === OrganizationModalEnum.RENAME)
+  // console.log(type)
   const ref = useRef<FormInstance>(null)
   const [state, setState] = useState({
     organizationList: []
   })
 
   const titleTypeEunm = {
-    1: {
+    0: {
       key: 'ADD',
       name: '添加父级组织'
     },
-    2: {
+    1: {
       key: 'ADDITEM',
       name: '添加子项'
     },
-    3: {
-      key: 'RENAME',
+    2: {
+      key: 'UPDATE',
       name: '重命名'
     },
-    4: {
+    3: {
       key: 'DEL',
       name: '删除组织架构'
     },
-    5: {
+    4: {
       key: 'MOVE',
       name: '移动'
     }
@@ -88,7 +90,7 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
     {
       manual: true,
       onSuccess: result => {
-        console.log(result)
+        // console.log(result)
 
         setState({ ...state, organizationList: result })
       }
@@ -135,14 +137,14 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
       width="35vw"
       visible={visible}
       // title={type === ModalType.ADD ? '添加父级组织' : '重命名'}
-      title={titleTypeEunm[type].name}
+      title={titleTypeEunm[typeEum].name}
       onCancel={() => {
         ref.current?.resetFields()
         setVisible(false)
       }}
       onOk={() => handleOnFinish()}>
       <ProForm formRef={ref} submitter={{ render: false }}>
-        {type === OrganizationModalEnum.ADD ? (
+        {type === ModalType.ADD ? (
           <>
             <ProFormText
               name="name"
@@ -151,7 +153,7 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
             />
           </>
         ) : null}
-        {type === OrganizationModalEnum.RENAME ? (
+        {type === ModalType.UPDATE ? (
           <>
             <ProFormText name="ID" hidden />
             <ProFormText
@@ -161,7 +163,7 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
             />
           </>
         ) : null}
-        {type === OrganizationModalEnum.DEL ? (
+        {type === ModalType.DEL ? (
           <>
             <ProFormText name="ID" hidden />
             <p>确认删除?</p>
@@ -180,7 +182,7 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
             ) : null}
           </>
         ) : null}
-        {type === OrganizationModalEnum.MOVE ? (
+        {type === ModalType.MOVE ? (
           <>
             <ProFormText name="ID" hidden />
             <Form.Item label="目标架构" name="moveID">