Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {PerforManageService} from '../../perfor.manage.service';
import {CommonService} from '../../../shared/common/common.service';
import {NzMessageService} from 'ng-zorro-antd';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {Asset_Location, asset_type, data_type} from '../../../infomationResource/information.constans';
import {MonitorService} from '../../../monitor/monitor.service';
import {array, selectType, validateFormArray} from '../../perfor.constants';
@Component({
selector: 'smart-admin-office-modal',
templateUrl: './admin-office-modal.component.html',
styles: []
})
export class AdminOfficeModalComponent implements OnInit {
@Output() done = new EventEmitter<any>();
modal = {
isVisiable: false,
title: '',
id: '',
isOkLoading: false,
};
validateForm: FormGroup;
controlArray = [];
selectType = selectType;
constructor(private fb: FormBuilder, private perforSer: PerforManageService,
private message: NzMessageService,
private monitorSer: MonitorService) {
}
ngOnInit() {
this.initForm();
}
//字段初始化
initForm() {
this.controlArray = [...array,
{label: '项目运维费中的核心设备总数(件)', value: 'assetCount', type: 'input', isRequire: false},
{label: '处于正常使用的核心设备数(件)', value: 'normalCount', type: 'input', isRequire: false},
{label: '使用8年及8年以上的核心设备数(件)', value: 'yearAssetcount', type: 'input', isRequire: false},
{label: '核心设备维修的次数(次)', value: 'maintenanceCount', type: 'input', isRequire: false},
{label: '核心设备年均使用时长(小时/件)', value: 'maintenanceUsetime', type: 'input', isRequire: false},
{label: '系统用户登录次数(次)', value: 'userLogincount', type: 'input', isRequire: false},
{label: '系统用户数(个)', value: 'userCount', type: 'input', isRequire: false},
{label: '行政业务办件量(件)', value: 'vusinessVolume', type: 'input', isRequire: false},
];
const fb = Object.assign(validateFormArray, {
assetCount: [null],
normalCount: [null],
yearAssetcount: [null],
maintenanceCount: [null],
maintenanceUsetime: [null],
userLogincount: [null],
userCount: [null],
vusinessVolume: [null],
});
console.log(fb);
this.validateForm = this.fb.group(fb);
}
//新增
showAddModal(title) {
this.modal.isVisiable = true;
this.modal.title = title;
}
//编辑
const data = {
id:this.modal.id
}
this.perforSer.selectOfficeServiceCountsById(data).subscribe(
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
(res) => {
if (res.errCode == 10000) {
this.validateForm.patchValue(res.data);
}
}
);
}
//判断
handleOk() {
for (let i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
if (this.validateForm.invalid) {
return false;
}
this.modal.isOkLoading = true;
if (this.modal.title.includes('新增')) this.create();
if (this.modal.title.includes('编辑')) this.update();
}
//新增
create() {
console.log(this.validateForm.value);
this.perforSer.addOfficeService(this.validateForm.value).subscribe(
(res) => {
if (res.errCode == 10000) {
this.initForm();
this.done.emit();
this.modal.isVisiable = false;
this.message.success('新增成功');
}
}
);
}
//更新
update() {
this.validateForm.addControl('id', new FormControl(this.modal.id));
this.perforSer.updateOfficeService(this.validateForm.value).subscribe(
(res) => {
if (res.errCode == 10000) {
this.initForm();
this.done.emit();
this.modal.isVisiable = false;
this.message.success('更新成功');
}