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' export interface Food { name:string; value: string; } @Component({ selector: 'app-detachment-level', templateUrl: './detachment-level.component.html', styleUrls: ['../plan-audit/plan-audit.component.scss'] }) export class DetachmentLevelComponent 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; organizationName:any //当前单位所属辖区中队名称 allunittype:any //所有单位类型 planpatterns:Food[] = [ //预案类型 {name:"卡片预案",value:"8"}, {name:"二维预案",value:"1" }, {name:"三维预案",value:"2" }, {name:"其他预案",value:"4" },] passstates:Food[]=[ //审核状态 {name:"审核中",value:"1"}, {name:"审核通过",value:"2"}, {name:"审核退回",value:"4"},] displayedColumns: string[] = ['unitname','planname', 'addpeople', 'addtime','plantype','auditstate', 'isopen','preparethelevel','operation']; tabledataSource:any; //所有预案审核信息 //分页 @ViewChild(MatPaginator, {static: true}) pageEvent: PageEvent; paginator: MatPaginator; length:any; //共多少条数据 pageSize:any; //每页条数 pageSizeOptions: number[] = [10] //设置每页条数 PageNumber:number = 1; //第几页 //查询筛选条件 CompanyName:any; //单位名称 selectOrganizationID:any //选中的辖区中队id selectOrganizationIName:any //选中的辖区中队name HasChildrenOrganization:boolean = false; //辖区中队是否包含下级 BuildingTypeId:any; //选中的单位类型 PlanType:any; //选中的预案类型 AuditStatus:any = '1'; //选中的审核状态 PlanLevel:any='2'; //选中的编制级别 //分页事件 chagePage(e){ this.PageNumber = e.pageIndex + 1 let header = { CompanyName: this.CompanyName || '', OrganizationId: this.selectOrganizationID || '', HasChildrenOrganization: String(this.HasChildrenOrganization) || 'false', BuildingTypeId: this.BuildingTypeId || '', PlanType: this.PlanType || '', AuditStatus: this.AuditStatus || '1', PlanLevel: this.PlanLevel || '2', PageNumber: String(this.PageNumber), } this.http.get('/api/PlanAudits',{params:header}).subscribe((data:any)=>{ this.length = data.totalCount this.pageSize = data.pageSize this.tabledataSource = data.items }) } //查询 onSubmit(e){ this.getAllPlanAudits() } //重置 reset () { this.CompanyName = '' this.selectOrganizationID = '' this.selectOrganizationIName = '' this.HasChildrenOrganization = false this.BuildingTypeId = '' this.PlanType = '', this.AuditStatus = '1', this.PlanLevel = '2', this.getAllPlanAudits() } //获取当前所有预案审核 getAllPlanAudits () { let header = { CompanyName: this.CompanyName || '', OrganizationId: this.selectOrganizationID || '', HasChildrenOrganization: String(this.HasChildrenOrganization) || 'false', BuildingTypeId: this.BuildingTypeId || '', PlanType: this.PlanType || '', AuditStatus: this.AuditStatus || '1', PlanLevel: this.PlanLevel || '2', PageNumber: '1', } this.http.get('/api/PlanAudits',{params:header}).subscribe((data:any)=>{ this.length = data.totalCount this.pageSize = data.pageSize this.pageEvent.pageIndex = 0 this.tabledataSource = data.items }) } ngOnInit(): void { this.getunitdata(); this.getOrganizations(); this.getUnittype(); this.getAllPlanAudits() } //得到当前账号所属辖区中队名称 getunitdata(){ this.http.get("/api/Account/Profiles").subscribe((data:any)=>{ this.organizationName = data.organizationName }) } //获得所有辖区中队(处理数据结构) getOrganizations(){ let treeData = [] this.http.get('/api/Organizations').subscribe((data:any)=>{ data.forEach(element => { element.children = [] data.forEach(item => { if (item.parentId == element.id) {element.children.push(item)} }); }); if (this.organizationName) { //当前账号有辖区中队时 data.forEach(element => { if (element.name===this.organizationName) { treeData.push(element) this.dataSource.data = treeData } }); } else { //当前账号没有有辖区中队时 data.forEach(element => { if (!element.parentId) { treeData.push(element) this.dataSource.data = treeData } }); } }) } //获得所有单位类型 getUnittype(){ this.http.get('/api/BuildingTypes/Simple').subscribe(data=>{ this.allunittype = data }) } isorganizationbox:boolean = false //辖区中队DIV显隐 //打开辖区中队 openorganizationbox() { this.isorganizationbox = true } //关闭辖区中队 closediv(){ this.isorganizationbox = false } //选择辖区中队时 add(node) { this.selectOrganizationID = node.id this.selectOrganizationIName = node.name this.isorganizationbox = false } //预案审核 toExamine (e) { window.open(`/planAudit/planpass?id=${e.companyId}&companyName=${e.companyName}&auditPlanId=${e.id}&auditStatus=${e.auditStatus}`); } //预案公开 openReserve (e) { this.http.put(`/api/PlanAudits/${e.id}/Public`,[]).subscribe(data=>{ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.snackBar.open('预案公开成功','确定',config); this.renew() }) } //预案取消公开 closeReserve (e) { this.http.put(`/api/PlanAudits/${e.id}/Unpublic`,[]).subscribe(data=>{ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.snackBar.open('预案已取消公开','确定',config); this.renew() }) } //按查询条件及分页 更新当前页面 renew () { let header = { CompanyName: this.CompanyName || '', OrganizationId: this.selectOrganizationID || '', HasChildrenOrganization: String(this.HasChildrenOrganization) || 'false', BuildingTypeId: this.BuildingTypeId || '', PlanType: this.PlanType || '', AuditStatus: this.AuditStatus || '1', PlanLevel: this.PlanLevel || '2', PageNumber: String(this.PageNumber), } this.http.get('/api/PlanAudits',{params:header}).subscribe((data:any)=>{ this.length = data.totalCount this.pageSize = data.pageSize this.tabledataSource = data.items }) } }