import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-assets',
  templateUrl: './assets.component.html',
  styleUrls: ['./assets.component.less'],
})
export class AssetsComponent implements OnInit {
  data = [
    {
      id: 1,
      title: '(类)固定资产->资产信息',
      expend: false,
      children: [
        {
          icon: '/assets/tmp/img/1.png',
          text: '固定资产台账',
          link: '/admin/fixed-assets/assets-info/fixed-assets',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '类固定资产台账',
          link: '/admin/fixed-assets/assets-info/cate-fixed-assets',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '资产分类',
          link: '/admin/fixed-assets/assets-info/assets-cate',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '房屋',
          link: '/admin/fixed-assets/assets-info/house',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '一键折旧',
          link: '/admin/fixed-assets/assets-info/depreciate',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '资产折旧记录',
          link: '/admin/fixed-assets/assets-info/depreciation-record',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '资产性质',
          link: '/admin/fixed-assets/assets-info/assets-nature',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '特种设备事故记录',
          link: '/admin/fixed-assets/assets-info/plant-accident',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '特种设备运行故障',
          link: '/admin/fixed-assets/assets-info/plant-operate',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '车辆/特种设备检定',
          link: '/admin/fixed-assets/assets-info/plant-verify',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '附件表',
          link: '/admin/fixed-assets/assets-info/parts',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '自定义字段',
          link: '/admin/fixed-assets/assets-info/custom',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '附属设备及配件',
          link: '/admin/fixed-assets/assets-info/anlage',
        },
      ],
    },
    {
      id: 2,
      title: '(类)固定资产->资产使用',
      expend: false,
      children: [
        {
          icon: '/assets/tmp/img/1.png',
          text: '消息通知',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '预警中心',
        },
      ],
    },
    {
      id: 3,
      title: '(类)固定资产->资产租赁',
      expend: false,
      children: [
        {
          icon: '/assets/tmp/img/1.png',
          text: '消息通知',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '预警中心',
        },
      ],
    },
    {
      id: 4,
      title: '(类)固定资产->设备维保',
      expend: false,
      children: [
        {
          icon: '/assets/tmp/img/1.png',
          text: '消息通知',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '预警中心',
        },
      ],
    },
    {
      id: 5,
      title: '(类)固定资产->单机车核算',
      expend: false,
      children: [
        {
          icon: '/assets/tmp/img/1.png',
          text: '消息通知',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '预警中心',
        },
      ],
    },
    {
      id: 6,
      title: '(类)固定资产->资产保险',
      expend: false,
      children: [
        {
          icon: '/assets/tmp/img/1.png',
          text: '消息通知',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '预警中心',
        },
      ],
    },
    {
      id: 7,
      title: '(类)固定资产->证件管理',
      expend: false,
      children: [
        {
          icon: '/assets/tmp/img/1.png',
          text: '消息通知',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '预警中心',
        },
      ],
    },
    {
      id: 8,
      title: '(类)固定资产->搅拌站配比',
      expend: false,
      children: [
        {
          icon: '/assets/tmp/img/1.png',
          text: '消息通知',
        },
        {
          icon: '/assets/tmp/img/1.png',
          text: '预警中心',
        },
      ],
    },
  ];
  currentArr = []; // 收起
  remainArr = []; //更多
  constructor(private router: Router) {}

  ngOnInit() {}
  click(event) {
    console.log(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);
  }
}
