import { Component, OnInit } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { MatSnackBar } from "@angular/material/snack-bar"; import { Router } from "@angular/router"; import { TreeService } from "src/app/http-interceptors/tree.service"; @Component({ selector: "app-examinee-capacity", templateUrl: "./examinee-capacity.component.html", styleUrls: ["./examinee-capacity.component.scss"], }) export class ExamineeCapacityComponent implements OnInit { constructor( private router: Router, public http: HttpClient, public snackBar: MatSnackBar, private tree: TreeService ) {} ngOnInit(): void { //获得登陆组织机构id this.getProfiles().then((res) => { //过滤得到正确的组织机构tree this.getOrganizations(); this.getAlltabledate(); }); } //获取登录账号的个人资料 Profiles: any; getProfiles() { return new Promise((resolve) => { this.http.get("/api/ExamAccounts/Profiles").subscribe((data: any) => { this.Profiles = data; sessionStorage.setItem("creatorData", JSON.stringify(data)); resolve(data); }); }); } //获得所有组织机构 allorganizations; treedata; nodes = []; expandedKeys = []; getOrganizations() { this.http.get("/api/Organizations").subscribe((data: any) => { this.allorganizations = data; this.treedata = this.tree.toTree(data); this.orId = this.Profiles.organizationId; this.getpresentOrganization(); }); } //得到当前单位所在组织机构的tree型数据 organizationName; newallorganizations; getpresentOrganization() { this.newallorganizations = this.allorganizations; this.newallorganizations.forEach((item) => { item.children = []; this.newallorganizations.forEach((element) => { if (element.parentId == item.id) { item.children.push(element); } }); }); this.organizationName = this.Profiles.organizationName; if (this.organizationName) { this.newallorganizations.forEach((item) => { if (item.name == this.organizationName) { this.nodes = [item]; this.expandedKeys = [item.key]; } }); } else { this.nodes = this.tree.toTree(this.treedata); this.expandedKeys = this.nodes[0].key; } } //获取表格信息 PageNumber = 1; PageSize = 10; name; orId; orIdChecked = true; tabledataSource; length; getAlltabledate() { let paramsdata: any = { ExamineeRealName: this.name || "", OrganizationId: this.Profiles.organizationId, ContainsChildren: this.orIdChecked, PageNumber: this.PageNumber, PageSize: this.PageSize, }; this.http .get("/api/ExamStatisticalAnalyses/AbilityAnalysis", { params: paramsdata, }) .subscribe((data: any) => { console.log("数据", data); this.tabledataSource = data.items; this.length = data.totalCount; }); } //分页事件 chagePage(e) { this.PageNumber = e.pageIndex + 1; this.getAlltabledate(); } //查询按钮 Submit() { if (!this.orId) { this.snackBar.open("组织机构不能为空", "确定", { verticalPosition: "top", duration: 3000, }); return; } this.getAlltabledate(); } //重置按钮 Reset() { this.name = ""; this.orId = this.Profiles.organizationId; this.orIdChecked = true; this.getAlltabledate(); } }