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 {
|
interface PropInterface {
|
||||||
type: string;
|
type: string;
|
||||||
text: string;
|
text: string;
|
||||||
|
showNum: boolean;
|
||||||
onUpdate: (keys: any, title: any) => void;
|
onUpdate: (keys: any, title: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,14 +19,26 @@ export const TreeDepartment = (props: PropInterface) => {
|
|||||||
const [treeData, setTreeData] = useState<any>([]);
|
const [treeData, setTreeData] = useState<any>([]);
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
const [selectKey, setSelectKey] = useState<any>([]);
|
const [selectKey, setSelectKey] = useState<any>([]);
|
||||||
|
const [total, setTotal] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
department.departmentList().then((res: any) => {
|
department.departmentList().then((res: any) => {
|
||||||
const departments = res.data.departments;
|
const departments = res.data.departments;
|
||||||
|
const departCount = res.data.dep_user_count;
|
||||||
if (JSON.stringify(departments) !== "{}") {
|
if (JSON.stringify(departments) !== "{}") {
|
||||||
const new_arr: Option[] = checkArr(departments, 0);
|
if (props.showNum) {
|
||||||
setTreeData(new_arr);
|
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 {
|
} else {
|
||||||
const new_arr: Option[] = [
|
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 checkArr = (departments: any[], id: number) => {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
for (let i = 0; i < departments[id].length; i++) {
|
for (let i = 0; i < departments[id].length; i++) {
|
||||||
@ -60,6 +105,15 @@ export const TreeDepartment = (props: PropInterface) => {
|
|||||||
return arr;
|
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) => {
|
const onSelect = (selectedKeys: any, info: any) => {
|
||||||
let label = "全部" + props.text;
|
let label = "全部" + props.text;
|
||||||
if (info) {
|
if (info) {
|
||||||
@ -89,6 +143,7 @@ export const TreeDepartment = (props: PropInterface) => {
|
|||||||
onClick={() => onSelect([], "")}
|
onClick={() => onSelect([], "")}
|
||||||
>
|
>
|
||||||
全部{props.text}
|
全部{props.text}
|
||||||
|
{props.showNum && total ? "(" + total + ")" : ""}
|
||||||
</div>
|
</div>
|
||||||
{treeData.length > 0 && (
|
{treeData.length > 0 && (
|
||||||
<Tree
|
<Tree
|
||||||
|
@ -89,6 +89,7 @@ const CoursePage = () => {
|
|||||||
children: (
|
children: (
|
||||||
<div className="float-left">
|
<div className="float-left">
|
||||||
<TreeDepartment
|
<TreeDepartment
|
||||||
|
showNum={false}
|
||||||
type="no-course"
|
type="no-course"
|
||||||
text={"部门"}
|
text={"部门"}
|
||||||
onUpdate={(keys: any, title: any) => {
|
onUpdate={(keys: any, title: any) => {
|
||||||
|
@ -200,6 +200,7 @@ const MemberPage = () => {
|
|||||||
<div className="tree-main-body">
|
<div className="tree-main-body">
|
||||||
<div className="left-box">
|
<div className="left-box">
|
||||||
<TreeDepartment
|
<TreeDepartment
|
||||||
|
showNum={true}
|
||||||
type=""
|
type=""
|
||||||
text={"部门"}
|
text={"部门"}
|
||||||
onUpdate={(keys: any, title: any) => {
|
onUpdate={(keys: any, title: any) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user