maintenance-statistics.component.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { ActivatedRoute, Router } from '@angular/router';
  2. import { Component, OnInit, OnDestroy } from "@angular/core";
  3. import { ToolService } from 'src/app/services/tool.service';
  4. @Component({
  5. selector: "app-maintenance-statistics",
  6. templateUrl: "./maintenance-statistics.component.html",
  7. styleUrls: ["./maintenance-statistics.component.less"],
  8. })
  9. export class MaintenanceStatisticsComponent implements OnInit, OnDestroy {
  10. constructor(
  11. public tool: ToolService,
  12. public route: ActivatedRoute,
  13. public router: Router,
  14. ) {}
  15. menuList: any[] = [];
  16. secondMenuList:any[] = [];
  17. ngOnInit() {
  18. this.getMenuList();
  19. this.initHospitalAndDuty(this.tool.getCurrentHospital());
  20. console.log('this.menuList:', this.menuList)
  21. }
  22. ngOnDestroy(){
  23. this.sessionRemove();
  24. }
  25. getMenuList(){
  26. this.menuList = this.tool.getMenuAutoType(this.route);
  27. this.menuList.length && this.clickMenu(this.menuList[0]);
  28. }
  29. // 点击一级菜单
  30. activeMenuId:number;
  31. clickMenu(data){
  32. this.activeMenuId = data.id;
  33. this.secondMenuList = this.menuList.find(v => v.id == this.activeMenuId).childrens || [];
  34. this.secondMenuList.length && this.clickSecondMenu(this.secondMenuList[0]);
  35. }
  36. // 点击二级菜单
  37. activeSecondMenuLink:string;
  38. clickSecondMenu(data){
  39. this.activeSecondMenuLink = data.link;
  40. // this.router.navigateByUrl(`newStatistics/${this.route.parent.snapshot.routeConfig.path}/${this.activeSecondMenuLink}`).finally();
  41. this.router.navigate([`newStatistics/${this.route.parent.snapshot.routeConfig.path}/${this.activeSecondMenuLink}`], { replaceUrl: true });
  42. }
  43. // 回显二级菜单
  44. selectTabEmit(link){
  45. this.activeSecondMenuLink = link;
  46. }
  47. // 全院查询-1|院区查询-2|责任部门查询-3|部门垂直查询-4
  48. hospital;
  49. duty;
  50. queryType;//查询范围
  51. // 初始化院区、部门显示
  52. initHospitalAndDuty(hospitalOrDuty){
  53. let type = 'hospital';//默认是院区
  54. if(hospitalOrDuty.type){
  55. // 当前是责任部门
  56. type = 'duty';
  57. }
  58. if(type === 'duty'){
  59. // 当前的所属责任部门
  60. this.hospital = hospitalOrDuty.parent;
  61. this.duty = hospitalOrDuty;
  62. }else{
  63. // 当前的所属院区
  64. this.hospital = hospitalOrDuty;
  65. this.duty = undefined;
  66. }
  67. console.log('this.hospital:', this.hospital)
  68. console.log('this.duty:', this.duty)
  69. // 查询范围单选框
  70. if(this.hospital){
  71. if(this.duty){
  72. if(this.duty.parentDeptId){
  73. this.queryType = 3;
  74. }else{
  75. this.queryType = 4;
  76. }
  77. }else{
  78. this.queryType = 2;
  79. }
  80. }else{
  81. this.queryType = 1;
  82. }
  83. this.sessionSave();
  84. }
  85. // 缓存数据
  86. sessionSave(){
  87. sessionStorage.setItem('maintenance_statistics_queryType', this.queryType);
  88. sessionStorage.setItem('maintenance_statistics_hospitalId', this.hospital ? this.hospital.id : '');
  89. sessionStorage.setItem('maintenance_statistics_dutyId', this.duty ? this.duty.id : '');
  90. }
  91. // 清除缓存数据
  92. sessionRemove(){
  93. sessionStorage.removeItem('maintenance_statistics_queryType');
  94. sessionStorage.removeItem('maintenance_statistics_hospitalId');
  95. sessionStorage.removeItem('maintenance_statistics_dutyId');
  96. }
  97. // 查询范围
  98. queryRangeFlag = false;
  99. queryRangeClick(){
  100. this.queryRangeFlag = true;
  101. }
  102. submitQueryRange({queryType, hospital, duty}) {
  103. console.log('queryType:', queryType)
  104. console.log('hospital:', hospital)
  105. console.log('duty:', duty)
  106. this.queryType = queryType;
  107. this.hospital = hospital;
  108. this.duty = duty;
  109. this.queryRangeFlag = false;
  110. this.sessionSave();
  111. this.router.navigate([`newStatistics/${this.route.parent.snapshot.routeConfig.path}/${this.activeSecondMenuLink}`], { replaceUrl: true });
  112. }
  113. cancelQueryRange() {
  114. this.queryRangeFlag = false;
  115. }
  116. }