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

@Component({
  selector: 'v-env-waterchannel',
  templateUrl: './env-waterchannel.page.html',
  styleUrls: ['./env-waterchannel.page.scss'],
})
export class EnvWaterchannelPage implements OnInit {
    // 牧场区域编号
    fieldRegionNo = '';
    // 牧场设备
    devices = [];

    // 发送指令延时判断
    comm = {
        remain : 20,
        isLoading : true
    };

    constructor(private api: Api, private ac: ActivatedRoute, private load: Load, private route: ActivatedRoute) { }

    ngOnInit() {
        // this.ac.queryParams.subscribe((data) => {
        //     this.fieldRegionNo = data.no;
        // });
        this.init();
    }

    // ionic的生命周期函数
    // ionViewWillEnter() {
    //     console.log('ionViewWillEnter_waterChannel');
    //     this.init();
    // }

    init() {
        this.route.paramMap.subscribe(params => {
            this.fieldRegionNo = params.get('fieldRegionNo');
            this.getData(0);
        });
    }

    getData(time) {
        if (time) {
            this.load.toLoad('加载中...', false);
        }
        this.api.cowshedApp.getShuiCaoData([{fieldRegionNo: this.fieldRegionNo}, (data) => {
            if (data) {
                this.devices = data.param;
            }
            this.load.offLoad();
        }]);
    }
}
