mirror of
https://github.com/PlayEdu/backend
synced 2025-06-22 02:16:28 +08:00
后台学员列表部门显示数量
This commit is contained in:
parent
facbaad8f5
commit
a475e693dc
@ -11,6 +11,7 @@ interface Option {
|
||||
interface PropInterface {
|
||||
type: string;
|
||||
text: string;
|
||||
showNum: boolean;
|
||||
onUpdate: (keys: any, title: any) => void;
|
||||
}
|
||||
|
||||
@ -18,14 +19,26 @@ export const TreeDepartment = (props: PropInterface) => {
|
||||
const [treeData, setTreeData] = useState<any>([]);
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [selectKey, setSelectKey] = useState<any>([]);
|
||||
const [total, setTotal] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
department.departmentList().then((res: any) => {
|
||||
const departments = res.data.departments;
|
||||
|
||||
const departCount = res.data.dep_user_count;
|
||||
if (JSON.stringify(departments) !== "{}") {
|
||||
if (props.showNum) {
|
||||
const new_arr: any = checkNewArr(departments, 0, departCount);
|
||||
setTreeData(new_arr);
|
||||
let num = 0;
|
||||
for (let item in departCount) {
|
||||
num = num + Number(item);
|
||||
}
|
||||
setTotal(num);
|
||||
} else {
|
||||
const new_arr: Option[] = checkArr(departments, 0);
|
||||
setTreeData(new_arr);
|
||||
}
|
||||
} else {
|
||||
const new_arr: Option[] = [
|
||||
{
|
||||
@ -40,6 +53,38 @@ export const TreeDepartment = (props: PropInterface) => {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const checkNewArr = (departments: any[], id: number, counts: any) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < departments[id].length; i++) {
|
||||
if (!departments[departments[id][i].id]) {
|
||||
arr.push({
|
||||
title: getNewTitle(
|
||||
departments[id][i].name,
|
||||
departments[id][i].id,
|
||||
counts
|
||||
),
|
||||
key: departments[id][i].id,
|
||||
});
|
||||
} else {
|
||||
const new_arr: any = checkNewArr(
|
||||
departments,
|
||||
departments[id][i].id,
|
||||
counts
|
||||
);
|
||||
arr.push({
|
||||
title: getNewTitle(
|
||||
departments[id][i].name,
|
||||
departments[id][i].id,
|
||||
counts
|
||||
),
|
||||
key: departments[id][i].id,
|
||||
children: new_arr,
|
||||
});
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
const checkArr = (departments: any[], id: number) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < departments[id].length; i++) {
|
||||
@ -60,6 +105,15 @@ export const TreeDepartment = (props: PropInterface) => {
|
||||
return arr;
|
||||
};
|
||||
|
||||
const getNewTitle = (title: any, id: number, counts: any) => {
|
||||
if (counts) {
|
||||
let value = counts[id] || 0;
|
||||
return title + "(" + value + ")";
|
||||
} else {
|
||||
return title;
|
||||
}
|
||||
};
|
||||
|
||||
const onSelect = (selectedKeys: any, info: any) => {
|
||||
let label = "全部" + props.text;
|
||||
if (info) {
|
||||
@ -89,6 +143,7 @@ export const TreeDepartment = (props: PropInterface) => {
|
||||
onClick={() => onSelect([], "")}
|
||||
>
|
||||
全部{props.text}
|
||||
{props.showNum && total ? "(" + total + ")" : ""}
|
||||
</div>
|
||||
{treeData.length > 0 && (
|
||||
<Tree
|
||||
|
@ -89,6 +89,7 @@ const CoursePage = () => {
|
||||
children: (
|
||||
<div className="float-left">
|
||||
<TreeDepartment
|
||||
showNum={false}
|
||||
type="no-course"
|
||||
text={"部门"}
|
||||
onUpdate={(keys: any, title: any) => {
|
||||
|
@ -200,6 +200,7 @@ const MemberPage = () => {
|
||||
<div className="tree-main-body">
|
||||
<div className="left-box">
|
||||
<TreeDepartment
|
||||
showNum={true}
|
||||
type=""
|
||||
text={"部门"}
|
||||
onUpdate={(keys: any, title: any) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user