import {Component, OnInit} from '@angular/core';
import {FormBuilder} from '@angular/forms';
import {Router} from '@angular/router';
import {OverAllService} from '../../overAll.service';
import {color} from '../../../app.constants';
import {CommonService} from '../../../shared/common/common.service';
import {LocalStorageService} from 'ngx-webstorage';
@Component({
    selector: 'monitoring-point',
    templateUrl: './monitoring-point.component.html',
    styles: []
})
export class MonitoringPointComponent implements OnInit {
    color = color;
    dataSet;
    loading = false;

    //设备状态
    red;
    yellow;
    green;
    gray;

    pageNum = 1;
    pageCount = 10;
    totalNum = 0;
    dataList;

    subtype =[
        {num:1,type:'区域或机房类型'},
        {num:3,type:'基本采集设备'},
        {num:4,type:'视频2.3'},
        {num:5,type:'视频3.0'},
        {num:6,type:'中控门禁'},
        {num:7,type:'报警设备'},
        {num:8,type:'UPS'},
        {num:9,type:'空调'},
        {num:10,type:'配电柜'},
        {num:11,type:'其他'},
        {num:14,type:'温湿度设备'},
        {num:15,type:'微耕门禁'},
        {num:16,type:'基本采集设备II'},
        {num:17,type:'485通用设备'},
        {num:18,type:'机柜温湿度'},
        {num:19,type:'冷通道温湿度'},
        {num:20,type:'热通道温湿度'},
        {num:21,type:'水温压力检测'},
    ]

    constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,
                private commonSer: CommonService,
                private $localStorage: LocalStorageService,
               ) {
    }
    ngOnInit() {
        this.getwebList();
    }
    //网站列表
    getwebList() {
        this.loading = true;
        const accessToken = this.$localStorage.retrieve('accessToken');
        let data = {
            pageNum: this.pageNum,
            pageSize: this.pageCount
        }
        let that = this;
        let dataContent = [];
        this.overAllSer.getSiteAndSub(accessToken,data).subscribe(
            (res) => {
                this.dataList = res.data.data;
                this.dataList.forEach(function(item,index) {
                    if(index < that.pageCount){
                        dataContent.push(item)
                    }

                })
                this.dataSet = dataContent;
                this.totalNum = res.data.totalNum;
                this.loading = false;
            }
        );
    }
    //翻页
    change(event) {
        let that = this;
        let dataContent = [];
        this.pageNum = event;
        this.dataList.forEach(function(item,index) {
            if(index >= (that.pageNum-1) * that.pageCount  && index < that.pageNum * that.pageCount){
                dataContent.push(item)
            }
        })
        this.dataSet = dataContent;
    }

}
