import { ActivatedRoute, Router } from '@angular/router';
import { Component, OnInit } from "@angular/core";
import { ToolService } from 'src/app/services/tool.service';
import { TabService } from '../services/tab.service';
@Component({
  selector: "app-distribution-inspection-statistics",
  templateUrl: "./distribution-inspection-statistics.component.html",
  styleUrls: ["./distribution-inspection-statistics.component.less"],
})
export class DistributionInspectionStatisticsComponent implements OnInit {
  constructor(
    public tool: ToolService,
    public route: ActivatedRoute,
    public router: Router,
    public tabService: TabService,
  ) {}

  menuList: any[] = [];
  secondMenuList:any[] = [];

  ngOnInit() {
    this.getMenuList();
    console.log('this.menuList:', this.menuList)
  }

  initSecondMenu(){
    this.secondMenuList = this.menuList.find(v => v.link == this.route.parent.routeConfig.path).childrens || [];
    if(location.hash == '#/newStatistics/distributionInspectionStatistics'){
      this.router.navigate([`/newStatistics/${this.route.parent.snapshot.routeConfig.path}/${this.secondMenuList[0].link}`], { replaceUrl: true });
    }else{
      let tab = this.tabService.tabs.find(v => v.active);
      this.router.navigate([tab.path], { replaceUrl: true });
    }
  }

  getMenuList(){
    this.menuList = this.tool.getMenuAutoType();
    this.initSecondMenu();
  }

}
