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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {SelectPersonComponent} from '../../../modal/select-person/select-person.component';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {NzMessageService, UploadFile} from 'ng-zorro-antd';
import {WorkService} from '../../work.service';
@Component({
selector: 'smart-cost',
templateUrl: './cost.component.html',
styles: []
})
export class CostComponent implements OnInit {
@ViewChild('smartSelectPerson') smartSelectPerson: SelectPersonComponent;
@Output() done = new EventEmitter<any>();
isVisiable = false;
title;
eventId;
validateForm: FormGroup;
fileList: UploadFile[] = [];
operatorsList = []; //处理人列表
eventTypeList = []; //事件分类列表
constructor(private workSer: WorkService, private message: NzMessageService,
private fb: FormBuilder) {
}
ngOnInit() {
this.initForm();
}
initForm() {
this.fileList = [];
this.operatorsList = [];
this.validateForm = this.fb.group(
{
title: [null, [Validators.required,Validators.maxLength(20)]],
description: [null,Validators.maxLength(300)],
type: [null, [Validators.required]],
requester: [null, [Validators.required,Validators.maxLength(10)]],
requesterPhone: [null, [Validators.required,Validators.maxLength(13)]],
operators: [null],
}
);
}
getEventType() {
const data = {
type: 0
};
this.workSer.findByType(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.eventTypeList = res.data;
}
}
);
}
beforeUpload = (file: UploadFile): boolean => {
const isLt5M = file.size / 1024 < 5000;
if (!isLt5M) {
this.message.error('图标必须小于5M!');
} else {
this.fileList.push(file);
}
return false;
};
showAddModal(title) {
this.isVisiable = true;
this.title = title;
this.getEventType();
}
showEditModal(title, id) {
this.isVisiable = true;
this.title = title;
this.eventId = id;
this.getEventType();
this.workSer.findByNo(this.eventId).subscribe(
(res) => {
this.validateForm.patchValue(res.data);
}
);
}
handEditleOk() {
if (this.title == '新增事件') {
this.create();
}
if (this.title == '编辑事件') {
this.update();
}
}
//新增
create() {
let formData = new FormData();
this.fileList.forEach((file: any) => {
formData.append('file', file);
});
if (this.operatorsList.length == 0) {
this.message.error('请选择人员');
return false;
}
this.validateForm.patchValue({
operators: this.operatorsList
});
for (let i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
if (this.validateForm.invalid) {
return false;
}
formData.append('json', JSON.stringify(this.validateForm.value));
this.workSer.create(formData).subscribe(
(res) => {
if (res.errCode == 10000) {
this.isVisiable = false;
this.initForm();
this.done.emit();
this.message.success('新增事件成功');
} else {
this.message.error(res.errMsg);
}
}
);
}
//编辑
update() {
let formData = new FormData();
this.fileList.forEach((file: any) => {
formData.append('file', file);
});
this.validateForm.patchValue({
operators: this.operatorsList
});
if (this.operatorsList.length == 0) {
this.message.error('请选择人员');
return false;
}
for (let i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
if (this.validateForm.invalid) {
return false;
}
formData.append('json', JSON.stringify(this.validateForm.value));
formData.append('id', this.eventId);
this.workSer.update(formData).subscribe(
(res) => {
if (res.errCode == 10000) {
this.isVisiable = false;
this.initForm();
this.done.emit();
this.message.success('修改事件成功');
} else {
this.message.error(res.errMsg);
}
}
);
}
handleEditCancel() {
this.isVisiable = false;
this.initForm();
}
//选择处理人
selectPerson() {
this.smartSelectPerson.showModal('选择处理人', null);
}
deletePerson(i) {
this.operatorsList.splice(i, 1);
}
getUser(e) {
const arr = [];
e.forEach(res => {
const data = {
username: res.name,
userId: res.id
};
arr.push(data);
});
this.operatorsList = arr;
}
}