import {Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {Transfer} from '../../service/transfer';
import {Api} from '../../service/api';
import {Load} from '../../service/load';
import {NavController} from '@ionic/angular';

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

  constructor(private tf: Transfer, private ac: ActivatedRoute,
              private api: Api, private load: Load, public nav: NavController) { }

  ifFocus = false;
    lunbo = {
        speed: 1000,
        allowTouchMove: true,
        effect: 'flip',
        autoplay: {
            delay: 2000,
        },
        loop: true,
        spaceBetween: 0,
        zoom: false
    };

    farmMsg = {
        temp : 28.6,
        humi : 32.1,
        thi : '中',
        hasCow : true,
    }

  items = [
      {
          name : '1号牛舍',
          temp : '23.5',
          humi : '82',
          thi: '轻',
          time : '2019-08-05 23:44',
          online : true,
          remoteMode: true,  //true 平控  false 现控
          wokeMode: 1,  //0 手控  1 自控  2 智控
          ctrl: 0,
          alarm: true,
      },
      {
          name : '3号牛舍',
          temp : '23.5',
          humi : '82',
          thi: '轻',
          time : '2019-08-05 23:44',
          online : true,
          remoteMode: true,  //true 平控  false 现控
          wokeMode: 1,  //0 手控  1 自控  2 智控
          ctrl: 0,
          alarm: true,
      },
      {
          name : '4号牛舍',
          temp : '23.5',
          humi : '82',
          thi: '轻',
          time : '2019-08-05 23:44',
          online : true,
          remoteMode: true,  //true 平控  false 现控
          wokeMode: 1,  //0 手控  1 自控  2 智控
          ctrl: 0,
          alarm: true,
      },
      {
          name : '5号牛舍',
          temp : '23.5',
          humi : '82',
          thi: '轻',
          time : '2019-08-05 23:44',
          online : true,
          remoteMode: true,  //true 平控  false 现控
          wokeMode: 1,  //0 手控  1 自控  2 智控
          ctrl: 0,
          alarm: true,
      },
      {
          name : '6号牛舍',
          temp : '23.5',
          humi : '82',
          thi: '轻',
          time : '2019-08-05 23:44',
          online : true,
          remoteMode: true,  //true 平控  false 现控
          wokeMode: 1,  //0 手控  1 自控  2 智控
          ctrl: 0,
          alarm: true,
      },
      {
          name : '7号牛舍',
          temp : '23.5',
          humi : '82',
          thi: '轻',
          time : '2019-08-05 23:44',
          online : true,
          remoteMode: true,  //true 平控  false 现控
          wokeMode: 1,  //0 手控  1 自控  2 智控
          ctrl: 0,
          alarm: true,
      },
      {
          name : '8号牛舍',
          temp : '23.5',
          humi : '82',
          thi: '轻',
          time : '2019-08-05 23:44',
          online : true,
          remoteMode: true,  //true 平控  false 现控
          wokeMode: 1,  //0 手控  1 自控  2 智控
          ctrl: 0,
          alarm: true,
      },
  ];

  imgs = ['1.jpg', '2.jpg', '3.jpg'];

  itam = {
      name : '',
      temp : '',
      humi : '',
      thi: '',
      time : '',
      online : false,
      ctrl: 0,
      alarm: true,
  };

  dummyData = {
      name : '1好',
      temp : '',
      humi : '',
      thi: '',
      time : '',
      online : false,
      ctrl: 0,
      alarm: true,
  };

  @ViewChild('slide') slide;

  ngOnInit() {
      this.ionViewWillEnter();
  }

    // ionic的生命周期函数
    ionViewWillEnter() {
        this.slideDidChange();
        //this.getData(0);
    }

  toIndex() {
      if (this.ifFocus) {
          this.ifFocus = false;
      } else {
          this.tf.transfer({url: '/index'});
      }
  }
    //
    // toControl(one){
    //     const query = '?name=' + one.name + '&no=' + one.no + '&group=' + one.group;
    //     // this.tf.transfer({
    //     //     url: '/' + one.url,
    //     //     query: query,
    //     //     hash: ''
    //     // });
    //     this.nav.navigateForward(one.url + query);
    // }

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

    getData()
    {

    }

    slideDidChange() {
        this.slide.startAutoplay();
    }

    toggleFocus(a){

    }

}
