material.vue
15.1 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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<template>
<div class="report-components">
<div class="title">上传资料</div>
<div class="material">
<div class="material-item" v-for="item in materialData" :key="item.name">
<label :class="{ require: item.label }">{{ item.label }}</label>
<el-upload :disabled="pageType == 2 || renewDisable" :id="item.name" :ref="item.name + 'Ref'" :file-list="materialForm[item.name]" :list-type="item.listType ? item.listType : 'picture-card'" :class="[ pageType == 2 || item.limit == materialForm[item.name].length ? 'hidePlusBtn' : '', 'upload-item',{'renewDisable':renewDisable&&!materialForm[item.name].length}]" :limit="item.limit" action="#" :before-upload="e => beforeAvatarUpload(e, item.name)" :on-preview="handlePictureCardPreview" :on-remove="e => handleRemove(e, item.name)" :http-request="e => httpRequest(e, item.name)">
<!-- <i v-if="item.name == 'billInfo'" slot="default" class="el-icon-plus">
<p>上传图片</p>
</i> -->
<img v-if="item.name === 'billInfo'" slot="default" :src="upload_img" alt="" />
<img v-if="item.name === 'idCard'" slot="default" :src="idCard" alt="" />
<img v-if="item.name === 'idCardBack'" slot="default" :src="idCardBack" alt="" />
<el-button v-if="item.name == 'otherInfo'" slot="default" :disabled="renewDisable || pageType == 2 || item.limit == materialForm[item.name].length" size="small" class="el-icon-plus">上传文件</el-button>
<!-- <div slot="tip" class="remark" v-if="item.name == 'idCard'">身份证人像面</div>
<div slot="tip" class="remark" v-if="item.name == 'idCardBack'">身份证国徽面</div> -->
<div slot="tip" class="file-box" v-if="item.name == 'otherInfo'">
<span class="file_tip">支持扩展名:.doc .docx .pdf .jpg .png .jpeg。图片类型大小不能超过9M,其他类型文件大小不能超过30M。</span>
<template>
<div class="bar_outer" v-for="(imgItem, imgId) in materialForm[item.name]" :key="imgId">
<template v-if="!imgItem.mark">
<el-progress
color="#F5F7FA"
text-inside
:format="
() => {
return imgItem.name
}
"
:percentage="imgItem.progress"
></el-progress>
<el-tooltip class="item" effect="dark" content="下载" placement="top">
<img v-if="imgItem.progress == 100" class="download" :src="download" alt="" @click="downloadFile(imgItem)" />
</el-tooltip>
<el-tooltip class="item" effect="dark" content="删除" placement="top">
<i v-if="imgItem.progress == 100 && pageType != 2" @click="handleRemove(imgItem.url, item.name)" class="el-icon-delete del_img"></i>
</el-tooltip>
</template>
</div>
</template>
</div>
<!-- 续保图 -->
<div slot="tip" v-if="item.name == 'otherInfo' && isXB" class="file-box xuBao">
<template>
<div class="bar_outer" v-for="(imgItem, imgId) in materialForm[item.name]" :key="imgId">
<template v-if="imgItem.mark">
<el-progress
color="#F5F7FA"
text-inside
:format="
() => {
return markMapItem[imgItem.mark]
}
"
:percentage="imgItem.progress"
></el-progress>
<el-tooltip class="item" effect="dark" content="下载" placement="top">
<img v-if="imgItem.progress == 100" class="download" :src="download" alt="" @click="downloadFile(imgItem)" />
</el-tooltip>
<el-tooltip class="item" effect="dark" content="删除" placement="top">
<i v-if="imgItem.progress == 100 && pageType != 2&&!renewDisable" @click="handleRemove(imgItem.url, item.name)" class="el-icon-delete del_img"></i>
</el-tooltip>
</template>
</div>
</template>
</div>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="" />
</el-dialog>
</div>
</div>
</div>
</template>
<script>
import glsxCombiForm from '@/components/glsx-combi-form'
import idCard from '@/assets/images/idCard.png'
import idCardBack from '@/assets/images/idCardBack.png'
import upload_img from '@/assets/images/upload.png'
import download from '@/assets/images/download.png'
export default {
name: '',
components: {
// glsxCombiForm
},
props: {
materialForm: Object,
pageType: {
type: Number,
default: 1 // 1.新增 2.查看 3.重新提交 4.去处理
},
isXB: Boolean,
renewDisable:Boolean
},
data() {
return {
progress: 0,
progressName: '',
idCard,
idCardBack,
upload_img,
download,
dialogVisible: false,
// materialForm: {
// idCard: [],
// idCardBack: [],
// billInfo: [],
// otherInfo: []
// },
materialData: [
{
label: '身份证照:',
name: 'idCard',
limit: 1
},
{
name: 'idCardBack',
limit: 1
},
{
label: '发票:',
name: 'billInfo',
limit: 10
},
{
label: '其他:',
name: 'otherInfo',
listType: 'fileList',
limit: 20
}
],
markMapItem: {
drivingLicense: '驾驶证',
accident: '事故责任认定书或相关凭证',
vin: '车架号VIN照片',
carAndPeople: '45°车头角度全车照片及人车合照',
vehicleDamage: '车辆受损细节照片',
InsuranceLossStatement: '保险定损单',
repiare:'维修单'
}
}
},
methods: {
downloadFile(file) {
window.open(file.url)
},
beforeAvatarUpload(e, fieldName) {
console.log(e)
return new Promise((resolve, reject) => {
let AllImgExt = '.png|.jpg|.jpeg'
if (fieldName === 'otherInfo') {
AllImgExt = '.jpeg|.png|.jpg|.pdf|.doc|.docx'
}
let extName = e.name.substring(e.name.lastIndexOf('.')).toLowerCase()
if (AllImgExt.indexOf(extName) === -1) {
this.$message.error('上传格式不正确')
return reject(false)
}
const size = e.size / 1024 / 1024
let maxSize = 9
let filetype = this.getFileType(e.type)
if (filetype == 'image') {
maxSize = 9
} else {
maxSize = 30
}
if (size > maxSize) {
this.$message.error(`上传文件不可超过${maxSize}M`)
return reject(false)
}
return resolve(true)
})
},
getFileType(type) {
if (!type) return 'doc'
if (type.indexOf('image') > -1) {
return 'image'
} else {
return 'doc'
}
},
httpRequest({ file: e }, fieldName) {
let size = e.size / 1024 / 1024
let loading = null
// 大于2给loading
if (size > 2) {
loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
})
}
// // 转码base64
const reader = new FileReader()
reader.readAsDataURL(e)
reader.onload = event => {
const imgFile = event.target.result
const arrBase64 = imgFile.split(',')
const targetNameList = e.name.split('.')
const fileInfo = targetNameList[targetNameList.length - 1] + '@' + arrBase64[1]
const fileType = this.getFileType(e.type)
const fileItem = { name: e.name, progress: 0, fileType: fileType }
if (fieldName === 'idCard') fileItem.name = '&front&_' + e.name
if (fieldName === 'idCardBack') fileItem.name = '&behind&_' + e.name
this.materialForm[fieldName].push(fileItem)
const id = this.materialForm[fieldName].length - 1
const paramObj = { file: fileInfo, fileType: fileType }
let param = {}
param.fileList = [paramObj]
this.$apis.common
.uploadFileApi(param, res => {
if (loading != null) {
loading.close()
loading = null
}
let progress = ((res.loaded / res.total) * 100).toFixed(2)
if (progress > 90) {
progress = 90
}
this.$set(this.materialForm[fieldName][id], 'progress', progress)
})
.then(res => {
if (res.code == '0') {
this.$set(this.materialForm[fieldName][id], 'url', res.data[0])
this.$set(this.materialForm[fieldName][id], 'progress', 100)
} else {
// this.materialForm[fieldName] = this.materialForm[fieldName].filter(item => item.url)
// console.log(this.materialForm[fieldName])
this.$set(this.materialForm[fieldName][id], 'progress', 100)
this.materialForm[fieldName].splice(id, 1)
this.$message.error('该文件上传失败')
}
})
}
},
handleRemove(e, fieldName) {
if (e.status == 'ready') return
// let id = this.$refs[fieldName + 'Ref'][0].uploadFiles.findIndex(item => item.uid === e.uid)
// this.$refs[fieldName + 'Ref'][0].uploadFiles.splice(id, 1)
const index = this.materialForm[fieldName].findIndex(item => item.url == e)
setTimeout(() => {
this.materialForm[fieldName].splice(index, 1)
})
//加定时是因为去除element删除有一个闪动
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url
this.dialogVisible = true
}
}
}
</script>
<style lang="scss" scoped>
/deep/ .hidePlusBtn {
.el-upload--picture-card {
display: none;
}
}
/deep/ .renewDisable {
.el-upload--picture-card {
display: block;
cursor: not-allowed;
}
}
// 上传闪屏问题
/deep/.el-upload-list__item.is-ready {
display: none;
}
.report-components {
background: white;
margin: 20px 0 0;
.title {
padding: 0 20px;
font-size: 16px;
font-weight: bold;
height: 58px;
line-height: 58px;
border-bottom: 1px solid #d8d8d8;
margin: 0 0;
color: #333;
}
.edit-form-container {
margin-top: 20px;
}
.material {
padding: 32px 20px;
min-width: 650px;
.material-item {
display: flex;
margin-bottom: 20px;
.upload-item {
position: relative;
}
/deep/ .el-upload-list__item-status-label {
display: none;
}
&:nth-child(-n + 3) {
/deep/.el-upload-list__item,
/deep/.el-upload--picture-card {
width: 180px;
height: 104px;
background: rgba(0, 0, 0, 0.04);
border-radius: 4px;
border: 1px dashed rgba(0, 0, 0, 0.15);
img {
width: 100%;
height: 100%;
}
}
// 删除动画
/deep/ .el-upload-list__item {
transition: none;
margin: 0;
}
}
&:nth-child(1) {
display: inline-block;
position: relative;
padding-left: 118px;
margin-bottom: 20px;
height: 104px;
.require {
position: absolute;
left: 0;
top: 0;
}
}
&:nth-child(2) {
margin-left: 12px;
display: inline-block;
}
&:nth-child(3) {
flex: 1;
margin-bottom: 0;
.upload-item {
max-width: 650px;
}
/deep/.el-upload-list__item,
/deep/.el-upload--picture-card {
width: 104px;
margin-right: 12px;
margin-bottom: 15px;
p {
font-size: 14px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #666666;
}
}
}
&:nth-child(4) {
margin-top: 5px;
.require {
margin-top: 9px;
}
/deep/ .el-upload {
text-align: left;
}
/deep/.el-upload-list--fileList {
display: none;
}
/deep/ .el-button:hover,
.el-button:active,
.el-button:focus {
background: #fff;
border: 1px solid #dcdfe6;
color: #606266;
}
/deep/ .el-button.is-disabled:hover {
color: #c0c4cc;
background: #fff;
border-color: #ebeef5;
}
}
.remark {
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
font-size: 14px;
color: #999;
top: 112px;
position: absolute;
}
.file-box {
margin-top: 8px;
.file_tip {
font-size: 14px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
line-height: 22px;
}
.bar_outer {
width: 320px;
position: relative;
margin-bottom: 4px;
margin-top: 8px;
.download {
width: 20px;
height: 18px;
}
.del_img,
.download {
color: #c6c6c6;
position: absolute;
right: -25px;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
}
.del_img {
right: -49px;
}
/deep/ .el-progress-bar__outer {
height: 26px !important;
border-radius: 4px;
background-color: transparent !important;
border: 1px solid #f4f6fc;
.el-progress-bar__inner {
border-radius: 4px;
text-align: left;
.el-progress-bar__innerText {
color: #333;
width: 310px;
overflow: hidden;
height: 13px;
text-overflow: ellipsis;
}
}
}
.file-name {
left: 0;
top: 50%;
transform: translateY(-50%);
position: absolute;
}
}
.imgTip {
font-weight: 400;
font-size: 14px;
color: #333333;
}
.wrapper {
display: inline-block;
}
.xbImg {
display: inline-block;
width: 104px;
height: 104px;
}
}
.require {
width: 118px;
text-align: right;
display: inline-block;
white-space: nowrap;
font-size: 14px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #333333;
}
.require::before {
content: '*';
color: #f56c6c;
margin-right: 4px;
}
.xuBao {
margin-top: 22px;
width: 522px;
min-height: 24px;
}
}
.material-item:last-child {
display: flex;
}
}
}
</style>