import {Component, OnInit, ViewChild} from '@angular/core';
import {TransferService} from '../../service/transfer.service';

@Component({
    selector: 'app-page-one',
    templateUrl: './page-one.component.html',
    styleUrls: ['./page-one.component.scss'],
})
export class PageOneComponent implements OnInit {

    @ViewChild('slide') slide;
    options = {
        speed: 1000,
        allowTouchMove: true,
        effect: 'flip',
        autoplay: {
            delay: 2000,
        },
        loop: true,
        spaceBetween: 0
    };
    items = [{
        name: '总数',
        icon: 'iozongshu',
        num: 20,
        color: 'zi'
    }, {
        name: '在线',
        icon: 'iodui',
        num: 12,
        color: 'lv'
    }, {
        name: '故障',
        icon: 'iogantan',
        num: 3,
        color: 'hong'
    }, {
        name: '离线',
        icon: 'iolixian',
        num: 5,
        color: 'hui'
    }];

    list = [{
        name: '设备一',
        time: new Date().getTime(),
        temp: '20℃',
        humid: '25%rH',
        press: '1003kpa',
        online: 1,
        error: 1
    }, {
        name: '设备二',
        time: new Date().getTime() - 24 * 3600 * 1000,
        temp: '21℃',
        humid: '29%rH',
        press: '1005kpa',
        online: 0,
        error: 1
    }, {
        name: '设备三',
        time: new Date().getTime() + 24 * 3600 * 1000,
        temp: '25℃',
        humid: '22%rH',
        press: '1010kpa',
        online: 1,
        error: 0
    }, {
        name: '设备三',
        time: new Date().getTime() + 24 * 3600 * 1000,
        temp: '25℃',
        humid: '22%rH',
        press: '1010kpa',
        online: 1,
        error: 0
    }, {
        name: '设备三',
        time: new Date().getTime() + 24 * 3600 * 1000,
        temp: '25℃',
        humid: '22%rH',
        press: '1010kpa',
        online: 1,
        error: 0
    }, {
        name: '设备三',
        time: new Date().getTime() + 24 * 3600 * 1000,
        temp: '25℃',
        humid: '22%rH',
        press: '1010kpa',
        online: 1,
        error: 0
    }, {
        name: '设备三',
        time: new Date().getTime() + 24 * 3600 * 1000,
        temp: '25℃',
        humid: '22%rH',
        press: '1010kpa',
        online: 1,
        error: 0
    }, {
        name: '设备三',
        time: new Date().getTime() + 24 * 3600 * 1000,
        temp: '25℃',
        humid: '22%rH',
        press: '1010kpa',
        online: 1,
        error: 0
    }];

    imgs = ['1.png', '2.png', '3.png', '4.png'];

    params = [{label: '温度', value: 'temp'},
        {label: '湿度', value: 'humid'},
        {label: '压力', value: 'press'}];

    constructor(private tf: TransferService) {
    }

    ngOnInit() {
    }

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

    toDetail(one) {
        const req = {
            to: 'app-page-detail',
            from: 'app-page-one',
            url: '/main/detail',
            query: {name: one.name},
            hash: ''
        };
        this.tf.transfer(req);
    }

}
