Newer
Older
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {WorkService} from '../../work.service';
import {NzMessageService, UploadFile} from 'ng-zorro-antd';
import {SelectPersonComponent} from '../../../modal/select-person/select-person.component';
@Component({
selector: 'smart-event',
templateUrl: './event.component.html',
styles: []
})
export class EventComponent implements OnInit {
@ViewChild('smartSelectPerson') smartSelectPerson: SelectPersonComponent;
@Output() done = new EventEmitter<any>();
isVisiable = false;
title;
eventId;
validateForm: FormGroup;
fileList: UploadFile[] = [];
operatorsList = []; //处理人列表
constructor(private workSer: WorkService, private message: NzMessageService,
title: [null, [Validators.required, Validators.maxLength(20)]],
description: [null, Validators.maxLength(300)],
requester: [this.userInfo.userName, [Validators.required, Validators.maxLength(10)]],
requesterPhone: [null, [Validators.required, Validators.maxLength(13)]],
};
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) {
}
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);
});
operators: this.operatorsList.length == 0 ? null : this.operatorsList
for (let i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
formData.append('json', JSON.stringify(this.validateForm.value));
this.workSer.create(formData).subscribe(
(res) => {
this.isVisiable = false;
this.initForm();
this.done.emit();
this.message.success('新增事件成功');
}
}
);
}
//编辑
update() {
let formData = new FormData();
this.fileList.forEach((file: any) => {
formData.append('file', file);
});
operators: this.operatorsList.length == 0 ? null : this.operatorsList
for (let i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
formData.append('json', JSON.stringify(this.validateForm.value));
formData.append('id', this.eventId);
this.workSer.update(formData).subscribe(
(res) => {
this.isVisiable = false;
this.initForm();
this.done.emit();
this.message.success('修改事件成功');
}
}
);
}
handleEditCancel() {
selectPerson() {
this.smartSelectPerson.showModal('选择处理人', null);