2026-04-08 15:38:16 +08:00
|
|
|
import { useEffect, useState } from "react";
|
2026-04-30 15:40:12 +08:00
|
|
|
import useGetUrlQuery from "zy-react-library/hooks/useGetUrlQuery";
|
|
|
|
|
import useGetUserInfo from "zy-react-library/hooks/useGetUserInfo";
|
2026-04-08 15:38:16 +08:00
|
|
|
|
2026-04-30 15:40:12 +08:00
|
|
|
export default function useApplyDepartment(props) {
|
2026-04-08 15:38:16 +08:00
|
|
|
const [departmentTree, setDepartmentTree] = useState([]);
|
2026-04-30 15:40:12 +08:00
|
|
|
const [serviceDepartmentData, setServiceDepartmentData] = useState([]);
|
|
|
|
|
const { entrance } = props;
|
2026-04-08 15:38:16 +08:00
|
|
|
|
2026-04-30 15:40:12 +08:00
|
|
|
const corpInfoListAll = props["corpInfoListAll"];
|
|
|
|
|
const query = useGetUrlQuery();
|
|
|
|
|
|
|
|
|
|
const { getUserInfo } = useGetUserInfo();
|
2026-04-08 15:38:16 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-04-30 15:40:12 +08:00
|
|
|
const getInfoData = async () => {
|
|
|
|
|
const corpData = await getUserInfo();
|
|
|
|
|
const currentDepartment = { corpName: corpData.corpinfoName, id: corpData.corpinfoId };
|
|
|
|
|
|
|
|
|
|
if (entrance === "stakeholder") {
|
|
|
|
|
const { data = [] } = await corpInfoListAll({ inType: [0, 1] });
|
|
|
|
|
setServiceDepartmentData(data);
|
|
|
|
|
setDepartmentTree([currentDepartment, ...data]);
|
|
|
|
|
}
|
|
|
|
|
else if (
|
|
|
|
|
!entrance
|
|
|
|
|
) {
|
|
|
|
|
const [{ data: departmentTreeData = [] }, { data: departmentData = [] }] = await Promise.all([
|
|
|
|
|
corpInfoListAll({ inType: [3, 4, 5] }),
|
|
|
|
|
corpInfoListAll({ inType: [0, 1] }),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
setServiceDepartmentData(departmentData);
|
|
|
|
|
setDepartmentTree([currentDepartment, ...departmentTreeData]);
|
|
|
|
|
}
|
|
|
|
|
else if (entrance === "supervision") {
|
|
|
|
|
const [{ data: departmentTreeData = [] }, { data: departmentData = [] }] = await Promise.all([
|
|
|
|
|
corpInfoListAll({ inType: [3, 4, 5] }),
|
|
|
|
|
corpInfoListAll({ inType: [0, 1] }),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
setServiceDepartmentData(departmentData);
|
|
|
|
|
setDepartmentTree([{ corpName: query.corpName, id: query.corpinfoId }, ...departmentTreeData]);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getInfoData();
|
2026-04-08 15:38:16 +08:00
|
|
|
}, []);
|
|
|
|
|
|
2026-04-30 15:40:12 +08:00
|
|
|
return { departmentTree, serviceDepartmentData };
|
2026-04-08 15:38:16 +08:00
|
|
|
}
|