Newer
Older
import {Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {CommonService} from '../../../shared/common/common.service';
import {WorkService} from '../../../work/work.service';
import {SystemService} from '../../../system/system.service';
import {AssetsComponent} from '../../../work/modal/assets/assets.component';
import {SERVER_API_URL} from '../../../app.constants';
import {UploadComponent} from '../../../work/modal/upload/upload.component';
import {NzMessageService} from 'ng-zorro-antd';
@Component({
selector: 'smart-discovery-list',
templateUrl: './discovery-list.component.html',
styles: []
})
export class DiscoveryListComponent implements OnInit {
@ViewChild('smartAssets') smartAssets:AssetsComponent;
@ViewChild('smartUpload') smartUpload:UploadComponent;
hostId;
childrenList;
allChecked = false;
selectList = [];
disabledButton = true;
indeterminate = false;
constructor(private workSer: WorkService, private routerInfo: ActivatedRoute,private router:Router,
private message:NzMessageService,private systemSer:SystemService,
private commonSer:CommonService) {
this.routerInfo.queryParams.subscribe(
(res) => {
this.hostId = res.hostId;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
}
);
}
checkAll(value: boolean): void {
this.childrenList.forEach(data => data.checked = value);
this.refreshStatus();
}
currentPageDataChange($event: Array<{ checked: boolean }>): void {
this.childrenList = $event;
}
selectItem(item, e) {
if (e) {
this.selectList.push(item);
} else {
this.selectList.forEach((value, index) => {
if (value.id == item.id) {
this.selectList.splice(index, 1);
}
});
}
this.refreshStatus();
}
refreshStatus(): void {
const allChecked = this.childrenList.every(value => value.checked === true);
const allUnChecked = this.childrenList.every(value => !value.checked);
this.allChecked = allChecked;
this.indeterminate = (!allChecked) && (!allUnChecked);
}
ngOnInit() {
this.getList();
}
getList() {
this.workSer.findInventory(this.hostId).subscribe(
(res) => {
this.childrenList = res.data;
}
);
}
//删除资产--单个
deleteInVentory(item){
const data = {
inventoryIds:[]
};
data.inventoryIds.push(item.id);
this.commonSer.confirmThing("删除","确定删除该资产?",()=>{
this.workSer.deleteInventory(data).subscribe(
(res)=>{
if(res.errCode == 10000){
this.getList();
this.message.success("删除资产成功");
}else{
this.message.error(res.errMsg);
}
}
)
})
}
//批量删除
batchDeleteInventory(){
if(this.selectList.length == 0){
this.message.warning("请选择需要删除的资产");
return false;
}
const data = {
inventoryIds:this.selectList.map(e=>{
return e.id;
})
};
this.commonSer.confirmThing("批量删除","确定删除选择的资产?",()=>{
this.workSer.deleteInventory(data).subscribe(
(res)=>{
if(res.errCode == 10000){
this.getList();
this.message.success("删除资产成功");
}else{
this.message.error(res.errMsg);
}
}
)
})
}
//添加资产
showAddModal() {
this.smartAssets.showAddModal("添加资产");
}
//编辑资产
showEditModal(id){
this.smartAssets.showEditModal("编辑资产",id);
}
//goto 监测项原型
goToCheck(data){
this.router.navigate(['app/main/checkList'],{
queryParams:{
invertoryId:data.id
}
})
}
//goto 阈值原型
goToTrigger(data){
this.router.navigate(['app/main/triggerList'],{
queryParams:{
invertoryId:data.id
}
})
}
}