You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 lines
1.2 KiB

import { getOrganList } from 'actions/base.action';
import { useEffect, useState } from 'react';
import { isEmpty, concat, compact } from 'lodash';
export default function useOrgan(params = {}, isEdit) {
const [treeData, setTreeData] = useState([]);
const [organIds, setOrganIds] = useState([]);
useEffect(() => {
if (!isEdit) {
getOrganList(Object.assign({}, params)).then(setTreeData);
}
if (isEdit && isEmpty(organIds)) {
getOrganList(Object.assign({}, params)).then(setTreeData);
}
}, []);
useEffect(() => {
if (isEdit && !isEmpty(organIds)) {
Promise.all(['', ...organIds].map((item) => getOrganList({
organId: item,
}))).then((values) => {
setTreeData(concat(...compact(values)));
});
}
}, [organIds]);
const onLoadData = ({ id, value }) => {
return getOrganList({
organId: value,
}).then((data) => {
setTreeData(treeData.concat(data));
});
};
return [
treeData,
{
onLoadData,
setOrganIds,
organExpandedKeys: organIds,
},
];
}