uploadFile.vue
11.7 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<template>
<div>
<div class="uploadFile-title">
<div class="content">
Import pre-clearance document upload <span>*</span>
<el-popover placement="top" width="510" trigger="hover">
<div>
Click the links below to upload customs clearance documents to
support <br />pre-clearance in destination.
</div>
<i slot="reference" class="el-icon-question questionIcon" />
</el-popover>
</div>
<el-button type="text" @click="viewHistory"
>VIEW UPLOAD HISTORY</el-button
>
</div>
<div class="uploadFile-box">
<div
v-for="(item, index) in fileData"
:key="index"
:class="{ uploadFileBoxItem: true }"
>
<div class="uploadButton" style="display: flex">
<div style="height: 45px" v-if="uploadType">
<div>
<el-button type="text" @click="upload(item.uploadType)"
>{{ item.titleName }}
</el-button>
<span v-if="item.required" class="requiredIcon">*</span>
</div>
<!-- <el-popover
style="margin-left: 5px"
v-if="item.uploadType == 'OTH'"
placement="top"
width="720"
trigger="hover"
>
<div>
Please provide
<span class="tipWeight">certificate of origin, contract</span>,
etc. if have any.<br />
And please provide
<span class="tipWeight">purchase receipts</span> or other
support clearance documents if declaring personal items.
</div>
<i slot="reference" class="el-icon-question questionIcon" />
</el-popover> -->
</div>
<div class="tipDom" v-if="item.uploadType == 'attachmentBizType_04'">
Please provide
<span class="tipWeight">certificate of origin,contract</span>,etc.
if have any.<br />
And please provide
<span class="tipWeight">purchase receipts</span> or other support
clearance documents if declaring personal items.
</div>
</div>
<div class="uploadFiles">
<div
class="uploadFileList"
v-for="(file, idx) in item.files"
:key="idx"
>
<div class="fileName">
<i class="el-icon-document" />{{ file.sourceFileName }}
</div>
<div class="fileOption">
<!-- 文件大小 -->
<span class="fileSize"
>{{ numberRound(Number(file.fileSize / 1024), 2) }}KB</span
>
<!-- 预览 -->
<!-- <el-button
type="text"
:loading="file.viewLoading"
@click="fileView(file)"
>view</el-button
> -->
<!-- 下载 -->
<el-button
type="text"
:loading="file.downLoading"
@click="downloadFile(file)"
>DOWNLOAD</el-button
>
<!-- 删除 -->
<el-popconfirm
title="Do you want to delete this file?"
@confirm="delFile(file)"
>
<el-button
slot="reference"
type="text"
:loading="file.delLoading"
>DELETE</el-button
>
</el-popconfirm>
</div>
</div>
</div>
</div>
<!-- <el-button
v-if="!uploadType"
type="text"
icon="el-icon-circle-plus-outline"
@click="addUpload"
>Add</el-button
> -->
<el-upload
class="upload-demo"
ref="uploadBlock"
:multiple="true"
action=""
:file-list="fileList"
:before-upload="beforeUpload"
:show-file-list="false"
:on-error="handleUploadError"
:on-success="handleUploadSuccess"
:on-remove="handleRemove"
:http-request="uploadFile"
:auto-upload="true"
:on-change="handleChange"
v-show="false"
>
</el-upload>
</div>
<HistoryDialog
ref="historyDialog"
:dialogVisible="viewHistoryType"
:headData="headData"
@close="historyClose"
/>
</div>
</template>
<script>
import HistoryDialog from "./dialog.vue";
export default {
components: {
HistoryDialog,
},
props: {
headData: {
type: Object,
default: null,
},
fileData: {
type: Array,
default: () => {
return [];
},
},
},
data() {
return {
fileFormData: {
uploadType: "",
},
fileList: [],
uploadType: true,
viewHistoryType: false,
errorTip: "",
};
},
methods: {
//上传
upload(type) {
this.errorTip = "";
this.fileList = [];
this.fileFormData.uploadType = type;
this.$refs.uploadBlock.$refs["upload-inner"].handleClick();
},
beforeUpload(val) {
let fileSum = 0;
let fileSize = 0;
let fileNameArray = [];
let errorTip = "";
this.fileData.forEach((item) => {
fileSum = Number(fileSum) + Number(item.files.length);
item.files.forEach((file) => {
fileSize = Number(fileSize) + Number(file.fileSize);
fileNameArray.push(file.sourceFileName);
});
});
if (fileSum + 1 > 100) {
if (this.errorTip == "") {
errorTip = "The maximum number of uploaded files is 100!";
this.$message.warning(this.errorTip);
}
} else if ((Number(fileSize) + Number(val.size)) / 1024 / 1024 > 95) {
if (this.errorTip == "") {
errorTip = "The maximum total size of uploaded files is 95M!";
}
} else if (fileNameArray.includes(val.name)) {
if (this.errorTip == "") {
errorTip = "Duplicate file name uploaded!";
}
}
if (errorTip == "") {
return true;
} else {
if (errorTip != "" && this.errorTip == "") {
this.errorTip = errorTip;
this.$message.warning(errorTip);
}
return false;
}
},
uploadFile(val) {
let obj = {
id: null,
bizId: null,
bizTypeName: null,
sourceFileName: val.file.name,
filePath: null,
fileTypeCode: null,
fileTypeName: this.fileFormData.uploadType,
status: null,
createTime: null,
createUserId: null,
createUserName: null,
modifyTime: null,
modifyUserId: null,
modifyUserName: null,
uploadRecordId: null,
consignmentCode: null,
file: "",
bizTypeCode: this.fileFormData.uploadType,
fileType: val.file.type,
fileName: val.file.name,
fileSize: val.file.size,
index: 0,
viewLoading: false,
downLoading: false,
delLoading: false,
};
let arr = this.fileData;
const reader = new FileReader();
reader.readAsDataURL(val.file);
reader.onload = (e) => {
obj.file = e.target.result;
arr.forEach((item, index) => {
if (item.uploadType == this.fileFormData.uploadType) {
obj.index = item.files.length == 0 ? 0 : item.files.length;
item.files.push(obj);
}
});
this.$emit("fileDataChange", arr);
};
},
//下载
downloadFile(val) {
if (val.file.split(";base64,").length > 1) {
const aLink = document.createElement("a");
aLink.href = val.file;
aLink.setAttribute("download", val.sourceFileName); // 设置下载文件名称
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
} else {
this.zipdownload
.downLoadZip(
"biz-customer/attachment/downLoadFile",
{
name: val.fileName,
path: val.filePath,
},
val.sourceFileName
)
.then((res) => {
console.log(res);
});
}
},
//删除
delFile(val) {
this.fileData.forEach((item) => {
if (item.uploadType == val.bizTypeCode) {
let arr = [];
item.files.forEach((file) => {
if (file.index != val.index) {
arr.push(file);
}
});
item.files = arr;
}
});
this.$emit("fileDataChange", this.fileData);
},
//预览
fileView(val) {
// var reader = new FileReader();
// reader.encoding = "UTF-8";
// reader.readAsText(this.b64ToBlob(val.file));
// reader.onload = function (e) {
// var content = e.target.result;
// let blob = new Blob([content], { type: val.fileType });
// let blobURL = window.URL.createObjectURL(blob);
// window.open(blobURL, "_black");
// };
let blob = new Blob([this.base64ConvertFile(val.file, val.fileName)], {
type: val.fileType,
});
let blobURL = window.URL.createObjectURL(blob);
window.open(blobURL, "_black");
},
handleUploadError(val) {},
handleUploadSuccess(val) {},
handleRemove() {
this.fileList = [];
},
handleChange() {},
addUpload() {
this.uploadType = true;
},
viewHistory() {
this.viewHistoryType = true;
},
historyClose(val) {
this.viewHistoryType = false;
if (val.type == "copy") {
this.$refs.historyDialog.detailSearch(val.data.id).then((res) => {
this.fileData.forEach((item) => {
if (item.uploadType == "attachmentBizType_01") {
item.files = res[0].list;
} else if (item.uploadType == "attachmentBizType_02") {
item.files = res[1].list;
} else if (item.uploadType == "attachmentBizType_03") {
item.files = res[2].list;
} else if (item.uploadType == "attachmentBizType_04") {
item.files = res[3].list;
}
});
this.$emit("fileDataChange", this.fileData);
});
}
},
},
};
</script>
<style lang="scss" scoped>
@import "@/assets/styles/variables.scss";
.uploadFile-title {
text-align: center;
height: 38px;
line-height: 38px;
position: relative;
margin-top: 20px;
.content {
font-size: 16px;
font-weight: 600;
span {
color: $fedexError;
}
}
.el-button {
position: absolute;
top: 0;
right: 10px;
}
}
.uploadFile-box {
margin-top: 8px;
.uploadFileBoxItem {
border: 1.5px solid rgba(153, 153, 153, 0.3);
box-shadow: 0px 4px 0.3rem 0.5px rgba(229, 242, 248, 0.8);
margin-top: 10px;
background-color: #fefefe;
.uploadButton {
height: 45px;
line-height: 45px;
padding: 0 20px;
border-bottom: 2px solid #e0e0e0;
.requiredIcon {
color: $fedexError;
}
}
.uploadFiles {
// max-height: 300px;
// overflow-y: scroll;
.uploadFileList {
height: 45px;
display: flex;
justify-content: space-between;
padding: 5px 0px 5px 20px;
line-height: 35px;
.fileName {
i {
display: inline-block;
margin-right: 5px;
}
}
.fileOption {
.fileSize {
font-size: 12px;
font-weight: 400;
color: #999;
margin-right: 20px;
}
.el-button {
margin-right: 16px;
}
}
}
}
}
.fileBoxItemDisable {
box-shadow: none;
background-color: $formItemBackgroundColor !important;
}
}
.tipDom {
display: inline-block;
font-size: 12px;
line-height: 16px;
padding: 7px 10px;
color: #777;
}
</style>