import { Component, OnInit, ViewChild, Inject } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { MatTreeFlatDataSource, MatTreeFlattener, } from "@angular/material/tree"; import { MatPaginator } from "@angular/material/paginator"; import { FlatTreeControl } from "@angular/cdk/tree"; import { FormControl } from "@angular/forms"; import { Router, ActivatedRoute } from "@angular/router"; import { PageEvent } from "@angular/material/paginator"; import { MatDialogRef, MatDialog, MAT_DIALOG_DATA, } from "@angular/material/dialog"; import { MatSnackBar, MatSnackBarConfig } from "@angular/material/snack-bar"; import { TreeService } from "../../http-interceptors/tree.service"; import { Viewer } from "photo-sphere-viewer"; import { timeStamp } from "console"; @Component({ selector: "app-combined-query", templateUrl: "./combined-query.component.html", styleUrls: ["./combined-query.component.scss"], }) export class CombinedQueryComponent implements OnInit { constructor( private http: HttpClient, private router: Router, private route: ActivatedRoute, private tree: TreeService, public dialog: MatDialog, public snackBar: MatSnackBar ) {} private _transformer = (node, level: number) => { //初始化tree return { expandable: !!node.children && node.children.length > 0, name: node.name, level: level, id: node.id, parentId: node.parentId, children: node.children, }; }; treeControl = new FlatTreeControl( (node) => node.level, (node) => node.expandable ); treeFlattener = new MatTreeFlattener( this._transformer, (node) => node.level, (node) => node.expandable, (node) => node.children ); dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener); myControl = new FormControl(); hasChild = (_: number, node: any) => node.expandable; displayedColumns: string[] = ["组织名称", "总数"]; //, 'addtime', 'plantype', 'auditStatus', 'openRange', 'projectlevel', 'operation' yuanColumns: string[] = ["组织名称", "总数"]; tabledataSource = []; //单位表格数据 yuanTable = []; //预案表格数据 excelData: any; findTj = 0; //查询条件 allPlanInfo: any; //存储所有预案信息 lable = ["单位查询", "预案查询"]; selected = new FormControl(0); //选项卡实例 //判断选了哪一个 selectedIndexChange(e) { this.orRecord = []; this.selected.setValue(e); this.preparelevels = Number(e); if (this.preparelevels == 0) { this.js = this.organizationName; this.jsId = this.organizationId; this.jscheck = true; this.unittype = []; this.allunittype.forEach((element) => { this.unittype.push(element.id); }); this.preparelevel = [1]; this.dwaddtime = "2020-01-01"; //单位查询开始时间 this.dwendtime = this.getNowFormatDate(); //单位结束时间 } else if (this.preparelevels == 1) { this.yuanjs = this.organizationName; this.yuanjsId = this.organizationId; this.yuanaddtime = "2020-01-01"; //预案查询开始时间 this.yuanendtime = this.getNowFormatDate(); //预案查询结束时间 this.yuanjscheck = true; this.reservePlanType = ["1", "2", "4", "16"]; this.planCategory = ["1", "2", "3", "4", "5"]; } this.getAllPlanInfo(); } getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var year = date.getFullYear(); var month: any = date.getMonth() + 1; var strDate: any = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = year + seperator1 + month + seperator1 + strDate; return currentdate; } async ngOnInit(): Promise { await this.getunitdata(); await this.getOrganizations(); await this.getUnittype(); this.jscheck = true; this.yuanjscheck = true; this.dwaddtime = "2020-01-01"; //单位查询开始时间 this.dwendtime = this.getNowFormatDate(); //单位结束时间 this.yuanaddtime = "2020-01-01"; //预案查询开始时间 this.yuanendtime = this.getNowFormatDate(); //预案查询结束时间 this.reservePlanType = ["1", "2", "4", "16"]; this.planCategory = ["1", "2", "3", "4", "5"]; this.getAllPlanInfo(); } //得到当前单位信息 organizationName: any; //当前单位组织机构名称 organizationId: any; //当前单位组织机构id async getunitdata() { await new Promise((resolve, reject) => { this.http.get("/api/Account/Profiles").subscribe((data: any) => { console.log("当前登陆用户信息", data); resolve(data); this.organizationName = data.organizationName; this.organizationId = data.organizationId; }); }); } //获得所有组织机构 allorganizations: any; //所有组织机构 treedata: any; //组织机构树型数据 newallorganizations: any; //用于存储在原始数据基础上的每个机构增加children字段 async getOrganizations() { await new Promise((resolve, reject) => { this.http.get("/api/Organizations").subscribe((data: any) => { this.allorganizations = data; this.treedata = this.tree.toTree(data); this.getpresentOrganization(); resolve(data); }); }); } //得到当前单位所在组织机构的tree型数据 getpresentOrganization() { this.newallorganizations = this.allorganizations; this.newallorganizations.forEach((item) => { item.children = []; this.newallorganizations.forEach((element) => { if (element.parentId == item.id) { item.children.push(element); } }); }); if (this.organizationName) { this.newallorganizations.forEach((item) => { if (item.name == this.organizationName) { this.dataSource.data = [item]; } }); } else { this.dataSource.data = this.tree.toTree(this.treedata); } this.js = this.organizationName; this.jsId = this.organizationId; this.yuanjs = this.organizationName; this.yuanjsId = this.organizationId; } //获得所有单位类型 allunittype: any; //所有单位类型 async getUnittype() { await new Promise((resolve, reject) => { this.http.get("/api/BuildingTypes/Simple").subscribe((data: any) => { this.allunittype = data; console.log("单位类型", data); this.allunittype.forEach((element) => { this.unittype.push(element.id); }); resolve(data); }); }); } //获得所有预案或单位信息 tableDataNull = false; preparelevels: Number = 0; companyName: any; //单位名称 js: any; //单位所选组织机构 jsId: any; //单位所选组织机构的id jscheck: boolean; //单位所选组织机构勾选框 yuanjs: any; //预案所选组织机构 yuanjsId: any; //预案所选组织机构的id yuanjscheck: boolean; //预案所选组织机构勾选框 dwaddtime; //单位查询开始时间 dwendtime; //单位结束时间 yuanaddtime; //预案查询开始时间 yuanendtime; //预案查询结束时间 unittype = []; //单位类型 reservePlanType = []; //预案类型 preparelevel = [1]; //单位状态 plcheck: boolean; //编制级别勾选框 planCategory = []; //预案级别 integritySort; //单位排序字段 yuanintegritySort; //预案排序字段 unitIsFollowed = ""; //单位 重点 planIsFollowed = ""; //预案 重点单位 isMasklayer = false; async getAllPlanInfo() { let paramsdata: any = { QueryMode: this.preparelevels, OrganizationId: this.jsId || "", HasChildren: this.jscheck || "", TimeIntervalStart: this.dwaddtime || "", TimeIntervalEnd: this.dwendtime || "", BuildingTypeIds: this.unittype || [], CompanyStatuses: this.preparelevel || [], SortBy: this.integritySort ? "totalCount" : "", SortType: this.integritySort || "", IsFollowed: String(this.unitIsFollowed) || "", }; let yuandata = { QueryMode: this.preparelevels, OrganizationId: this.yuanjsId || "", HasChildren: this.yuanjscheck || "", TimeIntervalStart: this.yuanaddtime || "", TimeIntervalEnd: this.yuanendtime || "", PlanCategories: this.planCategory || [], PlanTypes: this.reservePlanType || [], SortBy: this.yuanintegritySort ? "totalCount" : "", SortType: this.yuanintegritySort || "", IsFollowed: String(this.planIsFollowed) || "", }; this.isMasklayer = true; await new Promise((resolve, reject) => { this.http .get("/api/StatisticsAnalysis/ReportTable", { params: this.preparelevels == 0 ? paramsdata : yuandata, }) .subscribe((data: any) => { console.log("接口数据", data); this.excelData = data; if (data.length == 0) { this.tableDataNull = true; } else { this.tableDataNull = false; if (this.preparelevels == 0) { //单位查询 if (this.preparelevel.length == 0) { //必须选择单位状态 let config = new MatSnackBarConfig(); config.verticalPosition = "top"; config.duration = 3000; this.snackBar.open("请选择单位状态", "确定", config); } else { this.tabledataSource = []; this.displayedColumns = ["组织名称", "总数"]; data.forEach((element, i, value) => { this.tabledataSource.push({ name: [ element.orgName, element.companyStatistics.totalCount, ], }); if (value[0].companyStatistics.buildingTypesCounts != null) { value[i].companyStatistics.buildingTypesCounts.forEach( (build, bi, bvalue) => { if (i == 0) { this.displayedColumns.push( value[0].companyStatistics.buildingTypesCounts[bi] .buildingTypeName ); this.tabledataSource[0].name.push( value[0].companyStatistics.buildingTypesCounts[bi] .count ); } else { this.tabledataSource[i].name.push(bvalue[bi].count); } } ); } }); } } else if (this.preparelevels == 1) { //预案查询 this.yuanColumns = ["组织名称", "总数"]; this.yuanTable = [{ name: [0, 0] }]; if (this.planCategory.length != 0) { this.planCategory.forEach((element) => { if (element == 1) { this.yuanColumns.push("Ⅰ级"); this.yuanTable[0].name.push(0); } else if (element == 2) { this.yuanColumns.push("Ⅱ级"); this.yuanTable[0].name.push(0); } else if (element == 3) { this.yuanColumns.push("Ⅲ级"); this.yuanTable[0].name.push(0); } else if (element == 4) { this.yuanColumns.push("Ⅳ级"); this.yuanTable[0].name.push(0); } else if (element == 5) { this.yuanColumns.push("Ⅴ级"); this.yuanTable[0].name.push(0); } }); } if (this.reservePlanType.length != 0) { this.reservePlanType.forEach((element) => { if (element == 1) { this.yuanColumns.push("二维"); this.yuanTable[0].name.push(0); } else if (element == 2) { this.yuanColumns.push("三维"); this.yuanTable[0].name.push(0); } else if (element == 4) { this.yuanColumns.push("其他"); this.yuanTable[0].name.push(0); } else if (element == 16) { this.yuanColumns.push("文本"); this.yuanTable[0].name.push(0); } }); } data.forEach((element, i, value) => { if (i == 0) { this.yuanTable[0].name[0] = value[0].orgName; this.yuanTable[0].name[1] = value[0].planStatistics.totalCount; } else { this.yuanTable.push({ name: [ value[i].orgName, value[i].planStatistics.totalCount, ], }); } }); this.yuanTable.forEach((element, i, value) => { if (i > 0) { for ( let a = value[i].name.length; a < value[0].name.length; a++ ) { value[i].name.push(0); } } }); this.yuanTable.forEach((yuan, yuani, yuanval) => { this.yuanColumns.forEach((th, thi, thvalu) => { data.forEach((element, i, value) => { //预案级别数据 if ( value[i].planStatistics.planCategoryStatistics != null ) { value[ i ].planStatistics.planCategoryStatistics.planCategories.forEach( (jibie, ji, jval) => { if ( thvalu[thi].indexOf(jval[ji].planCategoryName) != -1 && yuani == i ) { yuanval[yuani].name[thi] = jval[ji].count; } } ); } if (value[i].planStatistics.planTypeStatistics != null) { //预案类型数据 value[ i ].planStatistics.planTypeStatistics.planTypes.forEach( (planlx, lxi, lxval) => { if ( thvalu[thi].indexOf(lxval[lxi].planTypeName) != -1 && yuani == i ) { yuanval[yuani].name[thi] = lxval[lxi].count; } } ); } }); }); }); } } this.isMasklayer = false; resolve(this.excelData); }); }); } integrityScoreMin; //完整度最小值 integrityScoreMax; //完整度最大值 newArr: any = []; //辖区中队div是否显示 isorganizationbox: boolean = false; //点击辖区中队树,将选择的辖区中队添加到变量 add(node) { this.isorganizationbox = false; if (this.preparelevels == 0) { this.js = node.name; this.jsId = node.id; } else if (this.preparelevels == 1) { this.yuanjs = node.name; this.yuanjsId = node.id; } } //关闭辖区中队隐藏框 closeorganizationbox() { this.isorganizationbox = false; } //打开辖区中队隐藏框 openorganizationbox() { this.isorganizationbox = true; } //关闭出现的组织机构div closediv() { this.isorganizationbox = false; } //查询 onSubmit(e) { let config = new MatSnackBarConfig(); config.verticalPosition = "top"; config.duration = 3000; if ( this.dwendtime < this.dwaddtime || this.yuanaddtime > this.yuanendtime ) { this.snackBar.open("开始时间不能早于结束时间", "确定", config); } this.getAllPlanInfo(); } //重置 reset() { this.orRecord = []; this.integritySort = ""; this.yuanintegritySort = ""; if (this.preparelevels == 0) { this.js = this.organizationName; this.jsId = this.organizationId; this.jscheck = true; this.unittype = []; this.allunittype.forEach((element) => { this.unittype.push(element.id); }); this.preparelevel = [1]; this.dwaddtime = "2020-01-01"; //单位查询开始时间 this.dwendtime = this.getNowFormatDate(); //单位结束时间 this.unitIsFollowed = ""; //单位 重点 } else if (this.preparelevels == 1) { this.yuanjs = this.organizationName; this.yuanjsId = this.organizationId; this.yuanaddtime = "2020-01-01"; //预案查询开始时间 this.yuanendtime = this.getNowFormatDate(); //预案查询结束时间 this.yuanjscheck = true; this.reservePlanType = ["1", "2", "4", "16"]; this.planCategory = ["1", "2", "3", "4", "5"]; this.planIsFollowed = ""; //预案 重点单位 } //重新获取初始化列表 this.getAllPlanInfo(); } orRecord = []; //进入下一层 clicktd(key, element) { let config = new MatSnackBarConfig(); config.verticalPosition = "top"; config.duration = 3000; if (key == 0 && element != "合计") { let clickOr; this.allorganizations.forEach((item) => { if (element === item.name) { clickOr = item; } }); // console.log(clickOr) if (this.preparelevels == 0) { if (element == this.js) { this.snackBar.open( "已在当前查询的消防救援站下,无法下钻", "确定", config ); return; } } else if (this.preparelevels == 1) { if (element == this.yuanjs) { this.snackBar.open( "已在当前查询的消防救援站下,无法下钻", "确定", config ); return; } } if (clickOr.children.length == 0 && this.excelData.length == 1) { this.snackBar.open("无下级消防救援站,无法下钻", "确定", config); return; } //记录点击过的消防救援站 this.orRecord.push({ name: this.js, id: this.jsId }); if (this.preparelevels == 0) { this.js = element; this.jsId = clickOr.id; } else if (this.preparelevels == 1) { this.yuanjs = element; this.yuanjsId = clickOr.id; } console.log(this.orRecord); this.getAllPlanInfo(); } } goBack() { if (this.preparelevels == 0) { this.js = this.orRecord[this.orRecord.length - 1].name; this.jsId = this.orRecord[this.orRecord.length - 1].id; } else if (this.preparelevels == 1) { this.yuanjs = this.orRecord[this.orRecord.length - 1].name; this.yuanjsId = this.orRecord[this.orRecord.length - 1].id; } this.orRecord.pop(); console.log(this.orRecord); this.getAllPlanInfo(); } exal() { var uri = "data:application/vnd.ms-excel;base64,", template = '{table}
', base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))); }, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }); }; return function (table, name) { if (!table.nodeType) table = document.getElementById(table); var ctx = { worksheet: name || "Worksheet", table: table.innerHTML, }; window.location.href = uri + base64(format(template, ctx)); }; } export() { const httpOptions = { responseType: "blob" as "json", }; this.http .post( `/api/StatisticsAnalysis/Excel?queryMode=${this.preparelevels}`, this.excelData, httpOptions ) .subscribe((data: any) => { // // 文件名中有中文 则对文件名进行转码 const link = document.createElement("a"); const blob = new Blob([data], { type: "application/vnd.ms-excel" }); link.setAttribute("href", window.URL.createObjectURL(blob)); link.setAttribute("download", "报表统计" + ".xls"); link.style.visibility = "hidden"; document.body.appendChild(link); link.click(); document.body.removeChild(link); }); } }