import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
  selector: 'app-data',
  templateUrl: './data.component.html',
  styleUrls: ['./data.component.less']
})
export class  DataComponent implements OnInit {

  data = [
  {
    "id": 1,
    "title": "云平台",
    "expend": false,
    "children": []
  },
  {
    "id": 2,
    "title": "设备实时监控",
    "expend": false,
    "children": []
  },
  {
    "id": 3,
    "title": "项目对比信息",
    "expend": false,
    "children": []
  },
  {
    "id": 4,
    "expend": false,
    "children": []
  }
];
  currentArr = []; // 收起
  remainArr = []; //更多
  constructor(private router: Router) {}

  ngOnInit() {}
  click(event) {
    const url = event.data.link;
    this.router.navigateByUrl(url);
  }
  onExpend(item) {
    item.expend = !item.expend;
    if (item.expend) {
      this.currentArr = item.children.slice(0, 4);
      this.remainArr = item.children;
      this.data[item.id - 1].children = this.currentArr;
    } else {
      this.data[item.id - 1].children = [...this.remainArr];
    }
    console.log(this.data);
  }
}
