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

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

  showFilter = false;
  query = {
    state: 0,
    focus: 0
  };
  req = {
    state: 0,
    focus: 0
  };
  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
  }];
  constructor(private tf: TransferService) { }

  ngOnInit() {}

  filter() {
    this.req = JSON.parse(JSON.stringify(this.query));
    this.showFilter = !this.showFilter;
  }

  cancel() {
    this.showFilter = !this.showFilter;
  }

  confirm() {
    this.query = this.req;
    this.showFilter = !this.showFilter;
  }

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