import { ActivatedRoute, Router } from '@angular/router'; import { Component, OnInit, OnDestroy } from "@angular/core"; import { ToolService } from 'src/app/services/tool.service'; @Component({ selector: "app-maintenance-statistics", templateUrl: "./maintenance-statistics.component.html", styleUrls: ["./maintenance-statistics.component.less"], }) export class MaintenanceStatisticsComponent implements OnInit, OnDestroy { constructor( public tool: ToolService, public route: ActivatedRoute, public router: Router, ) {} menuList: any[] = []; secondMenuList:any[] = []; ngOnInit() { this.getMenuList(); this.initHospitalAndDuty(this.tool.getCurrentHospital()); console.log('this.menuList:', this.menuList) } ngOnDestroy(){ this.sessionRemove(); } getMenuList(){ this.menuList = this.tool.getMenuAutoType(this.route); this.menuList.length && this.clickMenu(this.menuList[0]); } // 点击一级菜单 activeMenuId:number; clickMenu(data){ this.activeMenuId = data.id; this.secondMenuList = this.menuList.find(v => v.id == this.activeMenuId).childrens || []; this.secondMenuList.length && this.clickSecondMenu(this.secondMenuList[0]); } // 点击二级菜单 activeSecondMenuLink:string; clickSecondMenu(data){ this.activeSecondMenuLink = data.link; // this.router.navigateByUrl(`newStatistics/${this.route.parent.snapshot.routeConfig.path}/${this.activeSecondMenuLink}`).finally(); this.router.navigate([`newStatistics/${this.route.parent.snapshot.routeConfig.path}/${this.activeSecondMenuLink}`], { replaceUrl: true }); } // 回显二级菜单 selectTabEmit(link){ this.activeSecondMenuLink = link; } // 全院查询-1|院区查询-2|责任部门查询-3|部门垂直查询-4 hospital; duty; queryType;//查询范围 // 初始化院区、部门显示 initHospitalAndDuty(hospitalOrDuty){ let type = 'hospital';//默认是院区 if(hospitalOrDuty.type){ // 当前是责任部门 type = 'duty'; } if(type === 'duty'){ // 当前的所属责任部门 this.hospital = hospitalOrDuty.parent; this.duty = hospitalOrDuty; }else{ // 当前的所属院区 this.hospital = hospitalOrDuty; this.duty = undefined; } console.log('this.hospital:', this.hospital) console.log('this.duty:', this.duty) // 查询范围单选框 if(this.hospital){ if(this.duty){ if(this.duty.parentDeptId){ this.queryType = 3; }else{ this.queryType = 4; } }else{ this.queryType = 2; } }else{ this.queryType = 1; } this.sessionSave(); } // 缓存数据 sessionSave(){ sessionStorage.setItem('maintenance_statistics_queryType', this.queryType); sessionStorage.setItem('maintenance_statistics_hospitalId', this.hospital ? this.hospital.id : ''); sessionStorage.setItem('maintenance_statistics_dutyId', this.duty ? this.duty.id : ''); } // 清除缓存数据 sessionRemove(){ sessionStorage.removeItem('maintenance_statistics_queryType'); sessionStorage.removeItem('maintenance_statistics_hospitalId'); sessionStorage.removeItem('maintenance_statistics_dutyId'); } // 查询范围 queryRangeFlag = false; queryRangeClick(){ this.queryRangeFlag = true; } submitQueryRange({queryType, hospital, duty}) { console.log('queryType:', queryType) console.log('hospital:', hospital) console.log('duty:', duty) this.queryType = queryType; this.hospital = hospital; this.duty = duty; this.queryRangeFlag = false; this.sessionSave(); this.router.navigate([`newStatistics/${this.route.parent.snapshot.routeConfig.path}/${this.activeSecondMenuLink}`], { replaceUrl: true }); } cancelQueryRange() { this.queryRangeFlag = false; } }