import {Component, ComponentFactoryResolver, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, ActivationStart, Router, RouterOutlet} from '@angular/router';
import {Api} from '../../service/api';

@Component({
  selector: 'v-tabs',
  templateUrl: './tabs.page.html',
  styleUrls: ['./tabs.page.scss'],
})
export class TabsPage implements OnInit {

    @ViewChild(RouterOutlet) outlet: RouterOutlet;

  constructor(private router: Router, private api: Api ) {

  }

  totalAlert;

  ngOnInit() {
      // this.router.events.subscribe(e => {
      //     if (e instanceof ActivationStart && e.snapshot.outlet === 'tabs')
      //         console.log('DDEDEDEEEEEEEEEDDDDDDDDDDDDDDDDD');
      //         this.outlet.deactivate();
      // });
      this.totalAlert = 0;

      this.api.alert.getAll([{fieldRegionType: '牛舍'}, (data) => {
        if (data.total > 0) {
          this.totalAlert = 0;
          const rows = data.rows;
          if (rows.constructor === Array) {
            rows.map((value, index) => {
              this.totalAlert = this.totalAlert + value.devErr + value.alarm;
            });
          }
        }
      }]);
  }


}
