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'; @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) { } ngOnInit(): void { if (window.matchMedia("(max-width: 1400px)").matches) { this.pcMore = false this.padMore = true this.pcfind = false this.padjt = true } else { this.pcfind = true this.pcMore = true this.padMore = false this.padjt = false } this.getunitdata(); this.getOrganizations(); this.getUnittype(); this.getAllPlanInfo(); let level = sessionStorage.getItem("level"); this.url = window.location.href.substring(window.location.href.length - 1, window.location.href.length) } 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[]=['组织名称', '总数']; allorganizations: any //所有组织机构 allunittype: any //所有单位类型 tabledataSource=[] //单位表格数据 yuanTable=[]//预案表格数据 url findTj=0//查询条件 preparelevels:Number=0 pcMore//pc更多 pcput = false//pc收起 pcfind//pc查询 padjt = false padMore = true//pad收缩控制 padput = false//pad收起按钮 imgsrcopen = "../../../assets/images/routdown2.png" imgsrcdown = "../../../assets/images/routup2.png" pcInfo() { this.pcMore = !this.pcMore this.pcput = !this.pcput } padInfo() { this.padMore = !this.padMore this.padput = !this.padput } allPlanInfo: any //存储所有预案信息 lable=['单位查询','预案查询'] selected = new FormControl(0); //选项卡实例 //判断选了哪一个 selectedIndexChange(e){ this.selected.setValue(e) this.preparelevels=Number(e) } //获得所有预案或单位信息 getAllPlanInfo() { let paramsdata:any={ QueryMode:this.preparelevels, OrganizationId:this.jsId||'', HasChildren:this.jscheck||'', TimeIntervalStart:this.addtime||'', TimeIntervalEnd:this.endtime||'', BuildingTypeIds:this.unittype||'', CompanyStatus:this.preparelevel||'' } let yuandata={ QueryMode:this.preparelevels, OrganizationId:this.jsId||'', HasChildren:this.jscheck||'', TimeIntervalStart:this.addtime||'', TimeIntervalEnd:this.endtime||'', PlanCategory:this.planCategory||'', PlanType:this.reservePlanType||'' } this.http.get("/api/StatisticsAnalysis/ReportTable", { params:this.preparelevels==0? paramsdata:yuandata }).subscribe((data: any) => { console.log(data) //this.tabledataSource=data if(this.preparelevels==0){ this.tabledataSource=[] this.displayedColumns=['组织名称', '总数'] data.forEach((element,i,value) => { this.tabledataSource.push({name:[element.orgName,element.companyStatistics.totalCount]}) if(value[0].companyStatistics.buildingTypesCounts.length>0){ value[i].companyStatistics.buildingTypesCounts.forEach((build,bi,bvalue) => { if(i==0){ this.displayedColumns.push(value[0].companyStatistics.buildingTypesCounts[bi].buildingTypeName||'111') this.tabledataSource[0].name.push(value[0].companyStatistics.buildingTypesCounts[bi].count) }else{ this.tabledataSource[i].name.push(bvalue[bi].count) } /* this.tabledataSource.forEach((td,ti,tval)=>{ tval[ti].name.push(item.count) }) */ }); } }); } else if(this.preparelevels==1){ this.yuanColumns=['组织名称', '总数'] this.yuanTable=[{name:[0,0]}] //console.log(this.planCategory,this.reservePlanType) if(this.planCategory.length==0&&this.reservePlanType.length!=0){ this.yuanColumns.push('Ⅰ级预案','Ⅱ级预案','Ⅲ级预案','Ⅳ级预案','Ⅴ级预案') this.yuanTable[0].name.push(0,0,0,0,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) } }); }else if(this.planCategory.length!=0&&this.reservePlanType.length==0){ this.yuanColumns.push('文本预案','二维预案','三维预案','其他预案') this.yuanTable[0].name.push(0,0,0,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) } }) console.log(this.yuanTable) 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]}) } /* if(value[0].planStatistics.planCategoryStatistics.planCategories.length>0){ value[i].planStatistics.planCategoryStatistics.planCategories.forEach((build,bi,bvalue) => { if(i==0){ this.yuanColumns.push(value[0].planStatistics.planCategoryStatistics.planCategories[bi].planCategoryName) this.yuanTable[0].name.push(value[0].planStatistics.planCategoryStatistics.planCategories[bi].count) }else{ this.yuanTable[i].name.push(bvalue[bi].count) } }); } */ /* if(value[0].planStatistics.planTypeStatistics.length>0){ value[i].planStatistics.planTypeStatistics.forEach((build,bi,bvalue) => { if(i==0){ this.yuanColumns.push(value[0].planStatistics.planTypeStatistics[bi].planCategoryName) this.yuanTable[0].name.push(value[0].planStatistics.planCategoryStatistics[bi].count) }else{ this.yuanTable[i].name.push(bvalue[bi].count) } }); } */ }); this.yuanTable.forEach((element,i,value)=>{ if(i>0){ for(let a=value[i].name.length;a{ }) } console.log(this.yuanColumns) console.log(this.yuanTable) } ) } colorRgb(sColor) { var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; var sColor = sColor.toLowerCase(); if (sColor && reg.test(sColor)) { if (sColor.length === 4) { var sColorNew = "#"; for (var i = 1; i < 4; i += 1) { sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1)); } sColor = sColorNew; } //处理六位的颜色值 var sColorChange = []; for (var i = 1; i < 7; i += 2) { sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2))); } return sColorChange; } else { return sColor; } } colorHex(rgb) { var _this = rgb; var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; if (/^(rgb|RGB)/.test(_this)) { var aColor = _this.replace(/(?:(|)|rgb|RGB)*/g, "").split(","); var strHex = "#"; for (var i = 0; i < aColor.length; i++) { var hex: any = Number(aColor[i]).toString(16); hex = hex < 10 ? 0 + '' + hex : hex;// 保证每个rgb的值为2位 if (hex === "0") { hex += hex; } strHex += hex; } if (strHex.length !== 7) { strHex = _this; } return strHex; } else if (reg.test(_this)) { var aNum = _this.replace(/#/, "").split(""); if (aNum.length === 6) { return _this; } else if (aNum.length === 3) { var numHex = "#"; for (var i = 0; i < aNum.length; i += 1) { numHex += (aNum[i] + aNum[i]); } return numHex; } } else { return _this; } } gradientColor(startColor, endColor, step) { let _this = this let startRGB = _this.colorRgb(startColor);//转换为rgb数组模式 let startR = startRGB[0]; let startG = startRGB[1]; let startB = startRGB[2]; let endRGB = _this.colorRgb(endColor); let endR = endRGB[0]; let endG = endRGB[1]; let endB = endRGB[2]; let sR = (endR - startR) / step;//总差值 let sG = (endG - startG) / step; let sB = (endB - startB) / step; var colorArr = []; for (var i = 0; i < step; i++) { //计算每一步的hex值 var hex = _this.colorHex('rgb(' + parseInt((sR * i + startR)) + ',' + parseInt((sG * i + startG)) + ',' + parseInt((sB * i + startB)) + ')'); colorArr.push(hex); } return colorArr; } integrity(width) { let _this = this let style: any = {} style.width = width + '%'; if (width < 30) { let colorArr = this.gradientColor('#D50000', '#E53935', 30); for (let i = 0; i < 30; i++) { if (i == width) { style.background = colorArr[i] } } } if (width >= 30 && width < 60) { let colorArr = this.gradientColor('#FF9800', '#E65100', 30); for (let i = 30; i < 60; i++) { if (i == width) { style.background = colorArr[i - 30] } } } if (width >= 60) { let colorArr = this.gradientColor('#81C784', '#2E7D32', 41); for (let i = 60; i <= 100; i++) { if (i == width) { style.background = colorArr[i - 60] } } } return style } integrityDetails(width, zong) { let style: any = {} style.width = (width / zong) * 100 + '%'; return style } //得到当前单位信息 getunitdata() { this.http.get("/api/Account/Profiles").subscribe( (data: any) => { this.organizationName = data.organizationName } ) } addtime//开始时间 endtime//结束时间 integrityScoreMin//完整度最小值 integrityScoreMax//完整度最大值 organizationName: any //当前单位组织机构名称 treedata: any //组织机构树型数据 newArr: any = [] newallorganizations: any //用于存储在原始数据基础上的每个机构增加children字段 //得到当前单位所在组织机构的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) } }); }); this.http.get("/api/Account/Profiles").subscribe( (data: any) => { this.organizationName = data.organizationName 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); } } ) } //获得所有组织机构 getOrganizations() { this.http.get('/api/Organizations').subscribe( (data: any) => { this.allorganizations = data this.treedata = this.tree.toTree(data); this.getpresentOrganization(); } ) } //获得所有单位类型 getUnittype() { this.http.get('/api/BuildingTypes/Simple').subscribe( data => { this.allunittype = data } ) } //辖区中队div是否显示 isorganizationbox: boolean = false //点击辖区中队树,将选择的辖区中队添加到变量 add(node) { this.isorganizationbox = false this.js = node.name this.jsId = 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,this.endtime { // // 文件名中有中文 则对文件名进行转码 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); }) } }