vehicleInfo.vue
22.5 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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
<template>
<div class="info-wrapper">
<div v-for="(item, index) in configData"
:key="index"
class="item">
<div class="title">
{{ item.title }}
</div>
<div class="detail-content">
<div v-if="item.infoData && item.infoData.length" class="form_div">
<el-form :ref="item.childRef"
class="edit-sub-block"
label-width="150px"
:inline="true"
:model="detailInfo"
:rules="rules">
<el-row :gutter="20">
<template v-for="(item, key) in item.infoData">
<el-col :key="key" :span="item.col ? item.col : 12">
<el-form-item :label="`${item.title}:`" :prop="item.key">
<template v-if="item.type == 'imgList'">
<div v-if="
detailInfo[item.key] && detailInfo[item.key].length
"
class="photo-box">
<GlsxPreview limit="1"
:image-url-arr="getImgPreviewUrls(item)"
:pic-options="{ ...picOptions, type: item.otherType }"
:video-img="true">
</GlsxPreview>
</div>
<template v-else>
-
</template>
</template>
<template v-else-if="item.type == 'file'">
<template v-if="
detailInfo[`${item.key}`]
&& detailInfo[`${item.key}`].length > 0
">
<!-- 分别处理图片和非图片文件 -->
<div>
<!-- 图片文件处理 -->
<div v-for="(file, fileIndex) in getImageFiles(
detailInfo[`${item.key}`],
)"
:key="`img_${item.key}_${fileIndex}`">
<div v-if="
getImageFiles(detailInfo[`${item.key}`])
.length === 1
"
class="photoItem photoItemList">
<div class="picItem">
<img class="icon" src="./images/picIcon.png" />
<span class="labelItem">图片.jpg</span>
<span class="handle"
@click="
handleImg(
getImageFiles(detailInfo[`${item.key}`]),
)
">
点击预览
</span>
</div>
</div>
<div v-else-if="fileIndex === 0"
class="photoItem photoItemList">
<div class="picItem">
<img class="icon" src="./images/picIcon.png" />
<span class="labelItem">图片.jpg</span>
<span class="handle"
@click="
handleEnlargeImg(
getImageFiles(detailInfo[`${item.key}`]),
)
">
点击预览({{
getImageFiles(detailInfo[`${item.key}`])
.length
}}个)
</span>
</div>
</div>
</div>
<!-- 非图片文件处理 -->
<div v-for="(file, fileIndex) in getNonImageFiles(
detailInfo[`${item.key}`],
)"
:key="`file_${item.key}_${fileIndex}`">
<div class="photoItem photoItemList">
<div class="picItem">
<img class="icon" src="./images/fileIcon.png" />
<span class="labelItem">
{{
getFileNameFromUrlForDisplay(file.fileUrl)
}}
</span>
<span class="handle"
@click="openFileByUrl(file.fileUrl)">
预览
</span>
</div>
</div>
</div>
</div>
</template>
<template v-else>
-
</template>
</template>
<template v-else-if="item.isEdit">
<template v-if="item.type == 'input'">
<el-input v-model="detailInfo[item.key]"
class="edit-form-item"
size="small"
:maxlength="item.maxLength || ''"
:placeholder="`请输入${item.label}`">
</el-input>
</template>
<template v-else-if="item.type == 'date'">
<el-date-picker v-model="detailInfo[item.key]"
class="edit-form-item"
size="small"
type="date"
:picker-options="item.pickerOptions"
:placeholder="item.label">
</el-date-picker>
</template>
<template v-else-if="item.type == 'textarea'">
<el-input v-model="detailInfo[item.key]"
class="edit-form-item"
placeholder="请输入"
type="textarea"
:maxlength="item.maxLength"
:rows="3">
</el-input>
</template>
<template v-else-if="item.type == 'select'">
<el-select v-model="detailInfo[item.key]"
class="edit-form-item"
size="small"
:placeholder="`请选择${item.label}`">
<el-option v-for="item in item.options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</template>
</template>
<template v-else>
<div class="flex" :style="getExpiryTextStyle(item, detailInfo)">
<div v-if="item.className && item.className(detailInfo)"
class="dot"
:style="{
background: item.className(detailInfo),
}">
</div>
{{
item.formatter
? item.formatter(detailInfo) || "-"
: detailInfo[item.key] !== ""
&& detailInfo[item.key] !== null
? detailInfo[item.key]
: "-"
}}
<template v-if="item.suffixText">
<div class="unit">
{{ item.suffixText }}
</div>
</template>
</div>
</template>
</el-form-item>
</el-col>
</template>
</el-row>
</el-form>
</div>
</div>
<template v-if="item.subTitle">
<div v-for="signIndex in item.sign" :key="signIndex">
<div class="subtitle">
{{ item.subTitle }}{{ signIndex }}
</div>
<div class="detail-content">
<div v-if="item.subData && item.subData.length" class="form_div">
<el-form class="edit-sub-block"
label-width="150px"
:inline="true">
<el-row :gutter="20">
<template v-for="(item, key) in item.subData">
<el-col :key="key" :span="item.col ? item.col : 12">
<el-form-item :label="`${item.title}:`">
<div v-if="item.className && item.className(detailInfo)"
class="dot"
:style="{
background: item.className(detailInfo),
}">
</div>
<template>
{{
item.formatter
? item.formatter(detailInfo) || "-"
: detailInfo[item.key]
? detailInfo[item.key]
: "-"
}}
</template>
</el-form-item>
</el-col>
</template>
</el-row>
</el-form>
</div>
</div>
</div>
</template>
</div>
<ElImageViewer v-if="imgVisible"
:initial-index="initialIndex"
:on-close="closeImgViewer"
:url-list="imgList" />
</div>
</template>
<script>
import {
evaluationSourceOpt,
evaluationStatusOpt,
evaluationStatusOptMap,
ownerTypeOpt,
usageTypeOpt,
} from "@/common/constants.js";
import { deepClone } from "@/common/util";
import preview from "../../components/preview";
import { getExpiryTextStyle } from "./vehicleInfoExpiry";
export default {
components: {
GlsxPreview: preview,
ElImageViewer: () =>
import("element-ui/packages/image/src/image-viewer"),
},
props: {
detailInfo: {
type: Object,
default: () => {},
},
},
data() {
return {
videoStr: "?x-oss-process=video/snapshot,t_7000,f_jpg,w_800,h_600,m_fast",
picOptions: {
width: "90px",
height: "90px",
isClose: false,
},
rules: {},
configData: [
{
title: "车辆信息",
infoData: [
{
title: "车牌号",
key: "licensePlate",
},
{
title: "车架号",
key: "vin",
},
{
title: "车型",
key: "carTypeName",
formatter: (cellValue) => {
const carBrand = cellValue.carBrand ? cellValue.carBrand : "";
const carSeriesName = cellValue.carSeriesName
? cellValue.carSeriesName
: "";
const carTypeName = cellValue.carTypeName
? cellValue.carTypeName
: "";
return carBrand || carSeriesName || carTypeName
? carBrand + " " + carSeriesName + " " + carTypeName
: "-";
},
},
{
title: "上牌时间",
key: "registrationDate",
},
{
title: "上牌城市",
key: "registrationCityName",
formatter: (cellValue) => {
if (
!cellValue.registrationCityName
&& !cellValue.registrationProvinceName
) {
return "-";
}
return cellValue.registrationProvinceName
== cellValue.registrationCityName
? cellValue.registrationProvinceName
: cellValue.registrationProvinceName
+ cellValue.registrationCityName;
},
},
{
title: "交强险到期",
key: "compulsoryInsuranceExpiry",
formatter: (cellValue) => {
return cellValue.compulsoryInsuranceExpiry || "-";
},
},
{
title: "表显里程",
key: "mileageStr",
},
{
title: "年审到期",
key: "annualInspectionExpiry",
formatter: (cellValue) => {
return cellValue.annualInspectionExpiry || "-";
},
},
{
title: "使用性质",
key: "carTypeName",
formatter: (row) => {
const statusItem = this.getStatusItem(
this.baseData,
"usageTypeOpt", // 配置项数组的键名
row,
"usageType",
);
return statusItem ? statusItem.confValue : "-";
},
},
{
title: "商业险到期",
key: "commercialInsuranceExpiry",
formatter: (cellValue) => {
return cellValue.commercialInsuranceExpiry || "-";
},
},
{
title: "所有人性质",
key: "ownerType",
formatter: (row) => {
const statusItem = this.getStatusItem(
this.baseData,
"ownerTypeOpt",
row,
"ownerType",
);
return statusItem ? statusItem.confValue : "-";
},
},
{
title: "天窗",
key: "sunroof",
formatter: (row) => {
const sunRoofMap = {
1: "无天窗",
2: "普通天窗",
3: "全景天窗",
};
return sunRoofMap[row.sunroof];
},
},
{
title: "外观颜色",
key: "exteriorColor",
},
{
title: "内饰颜色",
key: "interiorColor",
},
{
title: "门店",
key: "sellerMerchantName",
},
{
title: "销售顾问",
key: "sellerName",
},
{
title: "驻店人员",
key: "conversionName",
},
{
title: "是否购买新车",
key: "buyNewCar",
formatter: (row) => {
return row.buyNewCar == 1 ? "是" : "否";
},
},
{
title: "是否事故",
key: "hasAccident",
formatter: (row) => {
return row.hasAccident == 1 ? "是" : "否";
},
},
{
title: "评估单状态",
key: "status",
formatter: (row) => {
const statusItem = this.getStatusItem(
this.baseData,
"evaluationStatusOpt", // 配置项数组的键名
row,
"status",
);
return statusItem ? statusItem.confValue : "-";
},
className: (row) => {
return this.baseData.evaluationStatusOptMap[row.status] || "";
},
},
{
title: "车主姓名",
key: "previousOwnerName",
},
{
title: "车主联系方式",
key: "previousOwnerPhone",
},
{
title: "评估单下单时间",
key: "evalOrderTime",
},
{
title: "评估单编号",
key: "evalOrderNo",
},
{
title: "评估单来源",
key: "source",
formatter: (cellValue) => {
const statusItem = this.getStatusItem(
this.baseData,
"evaluationSourceOpt", // 配置项数组的键名
cellValue,
"source",
);
return statusItem ? statusItem.confValue : "-";
},
},
{
title: "综合评价",
key: "overallRating",
col: 24,
formatter: (row) => {
const map = { 1: "优", 2: "良", 3: "中", 4: "差" };
return map[row.overallRating];
},
},
{
title: "车况描述",
key: "conditionDescription",
col: 24,
},
{
title: "车辆图片",
key: "carImageUrls",
type: "imgList",
col: 24,
},
{
title: "证件资料",
key: "documentUrls",
type: "file",
col: 24,
},
{
title: "车辆视频",
key: "carVideoUrls",
type: "imgList",
col: 24,
otherType: "video",
},
{
title: "车辆检测报告",
key: "carCheckReportUrls",
type: "file",
col: 24,
},
{
title: "其他图片",
key: "otherImageUrls",
type: "file",
col: 24,
},
],
},
],
baseData: {
usageTypeOpt: deepClone(usageTypeOpt),
ownerTypeOpt: deepClone(ownerTypeOpt),
evaluationStatusOpt: deepClone(evaluationStatusOpt),
evaluationStatusOptMap: deepClone(evaluationStatusOptMap),
evaluationSourceOpt: deepClone(evaluationSourceOpt),
},
imgVisible: false,
index: 0,
imgList: [],
imgUrlName: "",
initialIndex: 0,
};
},
methods: {
getExpiryTextStyle,
getStatusItem(baseData, optKey, row, rowKey) {
if (!baseData || !baseData[optKey] || !row) {
return null;
}
return baseData[optKey].find(
item => item.confId == row[rowKey], // 使用严格相等
);
},
getFileTypeFromUrl(url) {
if (!url) {
return "file";
}
const pathname = url.split("?")[0];
const extension = pathname.split(".").pop()?.toLowerCase() || "";
const imageExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "webp"];
if (imageExtensions.includes(extension)) {
return "image";
}
// 阿里云 OSS 图片处理:x-oss-process=image/format,jpg 表示图片
if (/x-oss-process=image\/format,\w+/.test(url)) {
return "image";
}
return "file";
},
getOssImageUrl(url) {
if (!url) {
return url;
}
// 已经带有 x-oss-process 参数时不重复拼接
if (url.includes("x-oss-process=")) {
return url;
}
const param = "x-oss-process=image/format,jpg/quality,q_100";
const sep = url.includes("?") ? "&" : "?";
return `${url}${sep}${param}`;
},
// imgList 类型(如 carImageUrls、carVideoUrls)预览使用的 URL 列表
getImgPreviewUrls(item) {
const urls = this.detailInfo && this.detailInfo[item.key];
if (!urls || !Array.isArray(urls)) {
return [];
}
// 视频不加图片处理参数
if (item.otherType === "video") {
return urls;
}
return urls.map(url => this.getOssImageUrl(url));
},
getFileNameFromUrlForDisplay(url) {
if (!url) {
return "未知文件";
}
try {
const fileName = url.split("/").pop().split("?")[0];
return fileName || "未知文件";
} catch (e) {
return "未知文件";
}
},
getFileNameFromUrl(url) {
if (!url) {
return "";
}
try {
const fileName = url.split("/").pop().split("?")[0];
return fileName || "未命名文件";
} catch (e) {
return "未命名文件";
}
},
openFileByUrl(url) {
if (url) {
window.open(url);
}
},
viewAllFiles(key) {
const fileListKey = `${key}List`;
const fileList = this.detailInfo[fileListKey];
if (fileList && fileList.length > 0) {
// 打开第一个文件,或者您可以实现一个文件预览弹窗来展示所有文件
window.open(fileList[0].fileUrl);
}
},
processFileLinks(fileString) {
if (!fileString) {
return [];
}
// 兼容数组;字符串时按"逗号+http"分割,避免 OSS query 中逗号误分割
const links = Array.isArray(fileString)
? fileString
: fileString.split(/,\s*(?=https?:\/\/)/).map(s => s.trim()).filter(Boolean);
console.log(links, "links");
// 根据文件类型返回相应的对象数组
return links.map((link) => {
const trimmedLink = link.trim();
return {
fileUrl: trimmedLink,
fileType: this.getFileTypeFromUrl(trimmedLink),
fileName: this.getFileNameFromUrl(trimmedLink),
};
});
},
processFileUrls(fileUrls) {
if (!fileUrls || !Array.isArray(fileUrls)) {
return [];
}
return fileUrls.map((url) => {
const fileType = this.getFileTypeFromUrl(url);
const fileUrl = fileType === "image" ? this.getOssImageUrl(url) : url;
return {
fileUrl,
fileType,
fileName: this.getFileNameFromUrl(url),
};
});
},
getImageFiles(fileUrls) {
const processedFiles = this.processFileUrls(fileUrls);
if (!processedFiles || !Array.isArray(processedFiles)) {
return [];
}
return processedFiles.filter(file => this.isImageType(file));
},
getNonImageFiles(fileUrls) {
const processedFiles = this.processFileUrls(fileUrls);
if (!processedFiles || !Array.isArray(processedFiles)) {
return [];
}
return processedFiles.filter(file => !this.isImageType(file));
},
isImageType(file) {
// 检查 file 对象是否有 fileType 属性
if (file && file.fileType) {
return file.fileType === "image";
}
// 如果是字符串 URL,通过扩展名判断
if (typeof file === "string") {
return this.getFileTypeFromUrl(file) === "image";
}
return false;
},
handleEnlargeImg(url) {
this.imgList = [];
this.imgVisible = !this.imgVisible;
this.initialIndex = 0;
// this.imgList = url
console.log("url", url);
url.map((item) => {
this.imgList.push(this.getOssImageUrl(item.fileUrl));
this.imgUrlName = item.fileName;
});
// this.imgList = url.map((item) => item[name])
// this.imgList = url
// this.imgUrlName = name
},
handleImg(url) {
this.imgList = [];
this.imgVisible = !this.imgVisible;
this.initialIndex = 0;
url.map((item) => {
this.imgList.push(this.getOssImageUrl(item.fileUrl));
this.imgUrlName = item.fileName;
});
},
closeImgViewer() {
this.imgVisible = false;
},
},
};
</script>
<style scoped lang="scss">
.photoItem {
// display: flex;
// min-height: 100px;
.picItem {
width: 240px;
height: 32px;
background: #f4f6f7;
border-radius: 4px;
display: flex;
align-items: center;
// justify-content: center;
.icon {
width: 15px;
height: 15px;
margin-left: 9px;
flex-shrink: 0;
}
.labelItem {
font-size: 14px;
color: #666666;
margin-left: 9px;
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
.handle {
font-size: 12px;
color: #2a58ad;
margin-left: auto;
margin-right: 8px;
cursor: pointer;
flex-shrink: 0;
white-space: nowrap;
}
}
}
.photoItemList {
// width: 400px;
display: flex;
width: auto;
height: auto;
margin-bottom: 10px;
.img {
width: 80px;
height: 80px;
margin-left: 10px;
}
}
@import "./detail.scss";
</style>