import { Component, OnInit } from '@angular/core';
import {Api} from '../../service/api';
import {NavController} from '@ionic/angular';

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

  alarmItem = [{
      fieldRegionName: '1号牛舍',
      devErr: 36,
      devErrTotal:136,
      alarm:21,
      alarmTotal:121
  },{
      fieldRegionName: '2号牛舍',
      devErr: 1,
      devErrTotal:11,
      alarm:0,
      alarmTotal:10
  },{
      fieldRegionName: '3号牛舍',
      devErr: 2,
      devErrTotal:12,
      alarm:3,
      alarmTotal:13
  },];

  constructor(private api: Api,public nav: NavController) { }

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

                  });
              }
          }
      }]);
  }

    toControl(one){
        const query = '/env-alarmDetail?name=' + one.fieldRegionName + '&no='+ one.fieldRegionNo;
        // this.tf.transfer({
        //     url: '/' + one.url,
        //     query: query,
        //     hash: ''
        // });
        console.log(query);
        this.nav.navigateForward(query);
    }
}
