Skip to content
assets-detail.component.ts 3.68 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, OnInit, ViewChild} from '@angular/core';
wangqinghua's avatar
wangqinghua committed
import {ActivatedRoute, Router} from '@angular/router';
wangqinghua's avatar
wangqinghua committed
import {WorkService} from '../../work.service';
wangqinghua's avatar
wangqinghua committed
import {pageSize} from '../../../app.constants';
import {NzMessageService} from 'ng-zorro-antd';
wangqinghua's avatar
wangqinghua committed
import {SelectGroupComponent} from '../../../modal/select-group/select-group.component';
wangqinghua's avatar
wangqinghua committed
import {CommonService} from '../../../shared/common/common.service';
import {Location} from '@angular/common';
import {AssetsComponent} from '../../modal/assets/assets.component';
wangqinghua's avatar
wangqinghua committed

@Component({
  selector: 'smart-assets-detail',
  templateUrl: './assets-detail.component.html',
  styles: []
})
export class AssetsDetailComponent implements OnInit {
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartSelectGroup') smartSelectGroup:SelectGroupComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartAssets') smartAssets:AssetsComponent;
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    invertoryId;
    inventoryExtend;
wangqinghua's avatar
wangqinghua committed

    totalNum;
    pageNum=1;
    pageCount = pageSize;
    loading = false;
    thingList;
wangqinghua's avatar
wangqinghua committed
  constructor(private routerInfo:ActivatedRoute,private workSer:WorkService,private commonSer:CommonService,
              private message:NzMessageService,private router:Router,private localSer:Location) {
wangqinghua's avatar
wangqinghua committed
    this.routerInfo.queryParams.subscribe(
        (res)=>{
          this.invertoryId = res.invertoryId;
        }
    )
  }
wangqinghua's avatar
wangqinghua committed

  ngOnInit() {
wangqinghua's avatar
wangqinghua committed
    this.getDetail();
wangqinghua's avatar
wangqinghua committed
    this.getEventList();
wangqinghua's avatar
wangqinghua committed
  }

wangqinghua's avatar
wangqinghua committed
  //资产详情
wangqinghua's avatar
wangqinghua committed
    getDetail(){
        this.workSer.selectByPrimaryKey(this.invertoryId).subscribe(
            (res)=>{
                    this.inventoryExtend = res.data;
            }
        )
    }

wangqinghua's avatar
wangqinghua committed
    //资产关联事件
    getEventList(){
      this.loading = true;
      const data = {
wangqinghua's avatar
wangqinghua committed
          "pageCount": this.pageCount,
          "pageNum": this.pageNum,
wangqinghua's avatar
wangqinghua committed
          "inventoryId":this.invertoryId
      };
      this.workSer.find(data).subscribe(
          (res)=>{
              this.thingList = res.data.data;
              this.totalNum = res.data.totalNum;
              this.loading = false;
          }
      )
    }

    //翻页
     change(e){
      this.pageNum = e;
      this.getEventList();
    }

    //查看事件详情
    lookEvent(item) {
        this.router.navigate(['app/main/handleDetail'], {
            queryParams: {
                eventId: item.id
            }
        });
    }

wangqinghua's avatar
wangqinghua committed
    //删除
    deleteModal(){
        const data = {
            inventoryIds: [this.invertoryId]
        };
        this.commonSer.confirmThing("删除","确定删除该资产?",()=>{
            this.workSer.deleteInventory(data).subscribe(
                (res)=>{
                    if(res.errCode == 10000){
                        this.localSer.back();
                        this.message.success("删除资产成功");
                    }else{
                        this.message.error(res.errMsg);
                    }
                }
            )
        })
    }

    //编辑
    showEditModal(){
        this.smartAssets.showEditModal("编辑资产",this.invertoryId);
    }

wangqinghua's avatar
wangqinghua committed
    // 打开添加关联modal
    linkThen(){
wangqinghua's avatar
wangqinghua committed
        this.smartSelectGroup.showAddModal("关联资产");
wangqinghua's avatar
wangqinghua committed
    }

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

    //查看资源
    goToHost(hostid){
        this.router.navigate(['app/main/basic-detail'], {
            queryParams: {
                hostId: hostid,
                type: 0,
            }
        });
    }
wangqinghua's avatar
wangqinghua committed
}