maintenance-statistics.component.ts 4.0 KB

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