import {Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {WorkService} from '../../work.service';
import {DeviceComponent} from '../../../netTopology/model/device/device.component';
import {UploadComponent} from '../../modal/upload/upload.component';
import {pageSize} from '../../../app.constants';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
  selector: 'smart-assets-detail',
  templateUrl: './assets-detail.component.html',
  styles: []
})
export class AssetsDetailComponent implements OnInit {
    @ViewChild('smartDevice') smartDevice:DeviceComponent;

    invertoryId;
    inventoryExtend;

    totalNum;
    pageNum=1;
    pageCount = pageSize;
    loading = false;
    thingList;
  constructor(private routerInfo:ActivatedRoute,private workSer:WorkService,
              private message:NzMessageService) {
    this.routerInfo.queryParams.subscribe(
        (res)=>{
          this.invertoryId = res.invertoryId;
        }
    )
  }

  ngOnInit() {
    this.getDetail();
  }

    getDetail(){
        this.workSer.selectByPrimaryKey(this.invertoryId).subscribe(
            (res)=>{
                    this.inventoryExtend = res.data;
            }
        )
    }

    // 打开添加关联modal
    linkThen(){
        this.smartDevice.showAddModal("选择资源");
    }

    //设置关联
    setLink(e){
      console.log(e);
      const data = {
          hostid:e.hostIds[0],
          id:this.invertoryId
      }
      this.workSer.updateHostid(data).subscribe(
          (res)=>{
              if(res.errCode == 10000){
                  this.message.success("设置关联主机成功");
                  this.getDetail();
              }else{
                  this.message.error(res.errMsg);
              }
          }
      )
    }

    change(e){

    }

}
