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
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {NzMessageService, UploadFile} from 'ng-zorro-antd';
import {WorkService} from '../../../work/work.service';
import {SystemService} from '../../../system/system.service';
import {OverAllService} from '../../../overAll/overAll.service';
import {InfomationService} from '../../infomation.service';
import {asset_type} from '../../information.constans';
@Component({
selector: 'smart-upload-asset',
templateUrl: './upload-asset.component.html',
styles: []
})
export class UploadAssetComponent implements OnInit {
@Output() done = new EventEmitter<any>();
title;
isVisible = false;
isOkLoading = false;
assetList = asset_type;
type;
fileList: UploadFile[] = [];
constructor(private message: NzMessageService, private workSer: WorkService,
private systemSer: SystemService, private overAllSer: OverAllService,
private inforSer: InfomationService) {
}
ngOnInit() {
}
showModal(title) {
this.title = title;
this.isVisible = true;
}
beforeUpload = (file: UploadFile): boolean => {
const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || 'application/octet-stream';
if (!isExcel) {
this.message.error('请上传正确的文件!');
} else {
this.fileList[0] = file;
}
return false;
};
handleCancel() {
this.isVisible = false;
this.type = null;
this.fileList = [];
}
handleOk() {
if (this.fileList.length == 0) {
this.message.warning('请选择文件');
return false;
}
this.isOkLoading = true;
if (this.title == '导入资产') {
this.assetUpload();
}
}
assetUpload() {
const formData = new FormData();
this.fileList.forEach((file: any) => {
formData.append('file', file);
});
formData.append('type', this.type);
this.inforSer.importE(formData).subscribe(
(res) => {
if (res.errCode == 10000) {
this.isVisible = false;
this.fileList = [];
this.type = null;
this.done.emit();
this.message.success('上传成功');
}
this.isOkLoading = false;
}
);
}
}