Browse Source

fix: 组织架构调整11

outaozhen 3 years ago
parent
commit
14d41e92a1

+ 3 - 0
src/pages/Institutions/Company/Detail/components/Organization.tsx

@@ -39,6 +39,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
     expandTreeIds: [],
     defaultFormData: null,
     parentID: '',
+    delName: '',
     currentModalType: ModalTypeEnum.ADD,
     accountTotal: null
   })
@@ -168,6 +169,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
                     setState({
                       ...state,
                       visible: true,
+                      delName: record.ID,
                       defaultFormData: record,
                       currentModalType: ModalTypeEnum.DEL,
                       accountTotal: record.accountTotal
@@ -233,6 +235,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
       <OrganizationModal
         type={state.currentModalType}
         visible={state.visible}
+        delName={state.delName}
         setVisible={(visible: boolean) => setState({ ...state, visible })}
         reload={() => {
           tryOrganizationList()

+ 41 - 3
src/pages/Institutions/Company/Detail/components/OrganizationModal.tsx

@@ -37,14 +37,16 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
   defaultFormData,
   treeSource,
   accountTotal,
+  delName,
   reload
 }) => {
-  console.log(treeSource)
   const ref = useRef<FormInstance>(null)
   const [state, setState] = useState({
     organizationList: []
   })
 
+  const { TreeNode } = TreeSelect
+
   const titleTypeEunm = {
     1: {
       key: 'ADD',
@@ -135,6 +137,32 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
       }
     })
   }
+
+  const onChange = () => {
+    if (!state.organizationList?.length) {
+      tryOrganizationList()
+    }
+  }
+
+  const onNodeChange = (value, labelList) => {
+    onChange(value, { value, label: labelList[0] })
+  }
+  const renderTreeNodes = data =>
+    data.map(item => {
+      if (item.ID === delName) {
+        console.log('我是ID')
+      }
+      if (item.children) {
+        item.disabled = true
+        return (
+          <TreeNode {...item} disabled={item.disabled}>
+            {renderTreeNodes(item.children)}
+          </TreeNode>
+        )
+      }
+      return <TreeNode {...item} />
+    })
+
   return (
     <Modal
       width="35vw"
@@ -174,12 +202,22 @@ const OrganizationModal: React.FC<OrganizationModalProps> = ({
               <div>
                 <p>请设置包含人员至新的组织架构中:</p>
                 <Form.Item label="目标架构" name="moveID">
-                  <TreeSelect
+                  {treeSource?.length && (
+                    <TreeSelect
+                      style={{ width: '100%' }}
+                      placeholder="请选择目标架构"
+                      treeDefaultExpandAll
+                      treeNodeFilterProp="label"
+                      onChange={(value, labelList, extra) => onNodeChange(value, labelList, extra)}>
+                      {renderTreeNodes(treeSource)}
+                    </TreeSelect>
+                  )}
+                  {/* <TreeSelect
                     style={{ width: '100%' }}
                     placeholder="请选择目标架构"
                     treeDefaultExpandAll
                     treeData={treeSource}
-                  />
+                  /> */}
                 </Form.Item>
               </div>
             ) : null}