vehicle-info.vue
20.2 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
755
756
757
758
<template>
<el-container
class="customer-details-box vehicle-info"
:class="isShow?'read':'edit'"
>
<el-card
shadow="never"
style="width: 100%"
class="outCard"
>
<div class="block">
<el-card
shadow="never"
class="form-box"
>
<el-form
:model="vehicles"
:rules="rules"
>
<div class="form-item-box">
<div class="form-item">
<el-form-item
label="车辆编号:"
prop="id"
>
<!-- <span class="span-title">车辆编号:</span> -->
<el-input
v-model="vehicles.id"
:disabled="true"
:placeholder="isShow?'--':'请输入车辆编号'"
maxlength="20"
/>
</el-form-item>
</div>
<div class="form-item">
<el-form-item
label="车牌号码:"
prop="licensePlate"
>
<el-input
v-model="vehicles.licensePlate"
:disabled="isShow"
:placeholder="isShow?'--':'请输入车牌号码'"
maxlength="15"
/>
</el-form-item>
<!-- <span class="span-title">车牌号码:</span> -->
</div>
<div class="form-item">
<el-form-item
label="车型名称:"
prop="truckTypeName"
>
<!-- <span class="span-title">车型名称:</span> -->
<el-select
v-model="vehicles.truckTypeName"
value-key="id"
:disabled="isShow"
:placeholder="isShow?'--':'请选择车型名称'"
clearable
@change="selectTruckTypeGet"
>
<el-option
v-for="item in carTypeList"
:key="item.id"
:value="item.name"
:label="item.name"
/>
</el-select>
</el-form-item>
</div>
<div class="form-item">
<el-form-item
label="车辆体积:"
prop="allowableVolume"
>
<!-- <span class="span-title">车辆体积:</span> -->
<el-input
v-model="isShow?vehicles.allowableVolume +' m³':vehicles.allowableVolume"
:disabled="isShow"
:placeholder="isShow?'--':'请输入车辆体积'"
maxlength="20"
>
<span
slot="suffix"
style="
color: #20232a;
font-weight: 400;
font-size: 14px;
font-family: PingFangSC, PingFangSC-Regular;
margin-right: 14px;
line-height: 40px;
"
>m³</span>
</el-input></el-form-item>
</div>
<div class="form-item">
<el-form-item
label="车辆载重:"
prop="allowableLoad"
>
<!-- <span class="span-title">车辆载重:</span> -->
<el-input
v-model="isShow?vehicles.allowableLoad + ' 吨':vehicles.allowableLoad"
:disabled="isShow"
:placeholder="isShow?'--':'请输入车辆载重'"
maxlength="20"
>
<span
slot="suffix"
style="
color: #20232a;
font-weight: 400;
font-size: 14px;
font-family: PingFangSC, PingFangSC-Regular;
margin-right: 14px;
line-height: 40px;
"
>吨</span>
</el-input></el-form-item>
</div>
<div class="form-item">
<el-form-item
label="GPSID:"
prop="deviceGpsId"
>
<!-- <span class="span-title">GPSID:</span> -->
<el-input
v-model="vehicles.deviceGpsId"
:disabled="isShow"
:placeholder="isShow?'--':'请输入GPSID'"
maxlength="20"
style="margin-left:12px"
/>
</el-form-item>
</div>
</div>
</el-form>
</el-card>
<div class="car-base car-img-base drive-base">
<span
class="imgUpload-label"
style="margin-right:14px;margin-left:12px"
>图片信息</span>
<el-card
shadow="never"
class="info-box"
>
<div
class="demo-input-suffix"
style="color: #2a2929; font-size: 14px; padding-left: 6px"
>
<ImageUpload
v-if="!isShow"
:prop-image-url="vehicles.picture"
:disabled="isShow"
:edit-type="isShow?'read':'edit'"
:is-show-example-img="diasbledImg"
:example-list="['https://yjy-slwl-oss.oss-cn-hangzhou.aliyuncs.com/2a6cbcb0-93d0-41a3-ae18-248ee68c1def.png','https://yjy-slwl-oss.oss-cn-hangzhou.aliyuncs.com/95f1ad63-c8f0-4be3-a5e9-c3c9320de30f.png']"
@imageChange="imageChange"
>
注:图片大小不超过5M;仅能上传 PNG JPEG JPG类型图片;建议上传400*300尺寸的图片;最多上传2张
</ImageUpload>
<div
v-else
class="read-img"
style="padding-left:15px"
>
<img
v-if="!vehicles.picture.length"
src="../../../assets/empty-img.png"
style="width:212px;height:159px;border: 1px solid #D8DDE3;border-radius: 4px;"
/>
<div
v-for="(item,index) in vehicles.picture"
v-else
:key="index"
class="img-box"
>
<img
style="width:212px;height:159px;border: 1px solid #D8DDE3;border-radius: 4px;margin-right:20px"
:src="item.url"
>
<div class="img-shadow">
<img
class="el-upload-span searchBigImg"
src="../../../assets/img-search.png"
@click.stop="searchBigImg(item)"
/>
</div>
</div>
</div>
</div>
</el-card>
</div>
</div>
</el-card>
<div
v-if="isShow"
class="footer-box"
>
<el-button
class="save-btn"
type="warning"
@click="handleEditVehicleInfo()"
>编辑</el-button>
</div>
<div
v-else
class="footer-box"
>
<el-button
class="save-btn"
type="warning"
@click="handleSubVehicleInfo()"
>保存</el-button>
<el-button
class="cancel-btn"
type="warning"
plain
@click="handleCanVehicleInfo()"
>取消</el-button>
</div>
<!-- 预览弹窗 -->
<el-dialog
:visible.sync="dialogVisible"
width="600px"
height="600px"
>
<img
width="100%"
:src="imageUrl"
alt=""
>
</el-dialog>
</el-container>
</template>
<script>
import { truckTypeDetail, truckTypeUpdate, getCarTypeList } from '@/api/transit'
import ImageUpload from '@/components/ImgUpload/index.vue'
export default {
components: {
ImageUpload
},
data() {
return {
imageUrl: '',
dialogVisible: false,
diasbledImg: true,
disabled: true,
isShow: true,
disabledLicensePlate: true,
disabledAllowableVolume: true,
disabledAllowableLoad: true,
disabledGPSID: true,
vehicles: {
id: '',
licensePlate: '',
fleetName: '',
truckTypeName: '',
truckTypeId: '',
allowableVolume: '',
allowableLoad: '',
deviceGpsId: '',
workStatus: '',
picture: []
},
carTypeList: [],
rules: {
id: [
{
required: true,
validator: (rule, value, callback) => {
if (value) {
const reg = /^[0-9]+(.[0-9]{1,2})?$/
if (!reg.test(value)) {
callback(
new Error('车辆编号输入有误,请重新输入')
)
} else {
callback()
}
} else {
callback(new Error('车辆编号不能为空'))
}
},
trigger: 'blur'
}
],
allowableVolume: [
{
required: true,
validator: (rule, value, callback) => {
if (value) {
const reg = /^[0-9]+(.[0-9]{1,2})?$/
if (!reg.test(value)) {
callback(
new Error('请输入车辆体积,只保留两位小数')
)
} else {
callback()
}
} else {
callback(new Error('车辆体积不能为空'))
}
},
trigger: 'blur'
}
],
licensePlate: [
{
required: true,
validator: (rule, value, callback) => {
if (value) {
const reg =
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/
if (!reg.test(value)) {
callback(
new Error('请输入正确的车牌号码')
)
} else {
callback()
}
} else {
callback(new Error('车牌号码不能为空'))
}
},
trigger: 'blur'
}
],
truckTypeName: [
{
required: true,
validator: (rule, value, callback) => {
if (value) {
callback()
} else {
callback(new Error('车型名称不能为空'))
}
},
trigger: 'change'
}
],
allowableLoad: [
{
required: true,
validator: (rule, value, callback) => {
if (value) {
const reg = /^[0-9]+(.[0-9]{1,2})?$/
if (!reg.test(value)) {
callback(
new Error('请输入车辆载重,只保留两位小数')
)
} else {
callback()
}
} else {
callback(new Error('车辆载重不能为空'))
}
},
trigger: 'blur'
}
],
deviceGpsId: [
{
required: true,
validator: (rule, value, callback) => {
if (value) {
const reg = /^[0-9]+(.[0-9]{1,2})?$/
if (!reg.test(value)) {
callback(
new Error('GPSID输入有误,请重新输入')
)
} else {
callback()
}
} else {
callback(new Error('GPSID不能为空'))
}
},
trigger: 'blur'
}
]
}
}
},
created() {
this.id = this.$route.query.id
this.getList(this.id)
this.getCarTypeList()
},
methods: {
// 查询大图
searchBigImg(file) {
this.imageUrl = file.url
this.dialogVisible = true
},
selectTruckTypeGet(vId) {
let obj = {}
obj = this.carTypeList.find((item) => {
return item.name === vId
})
this.$set(this.vehicles, 'truckTypeName', obj.name)
this.$set(this.vehicles, 'truckTypeId', obj.id)
},
async getCarTypeList() {
const { data: res } = await getCarTypeList()
this.carTypeList = res
},
imageChange(value) {
this.diasbledImg = !value.length
this.vehicles.picture = value.map((item) => {
return { url: item.size ? item.response.data : item.url }
})
},
// 获取车辆详情-基本信息
async getList(id) {
const { data: res } = await truckTypeDetail(id)
this.vehicles.id = res.id
this.vehicles.licensePlate = res.licensePlate
this.vehicles.truckTypeName = res.truckTypeName
this.vehicles.allowableVolume = res.allowableVolume
this.vehicles.allowableLoad = res.allowableLoad
this.vehicles.deviceGpsId = res.deviceGpsId
this.vehicles.picture = res.picture
? res.picture.split(',').map((item) => {
return { url: item }
})
: []
this.diasbledImg = !res.picture
},
// 编辑基本信息
async handleEditVehicleInfo() {
this.isShow = false
},
// 保存
async handleSubVehicleInfo() {
const { deviceGpsId, picture, licensePlate, truckTypeName, allowableVolume, allowableLoad } = this.vehicles
if (/[\u4E00-\u9FA5]/g.test(deviceGpsId)) {
return this.$message.error('GPSID不能为中文')
}
if (picture.length < 1) {
return this.$message.error('车辆信息照片至少上传一张')
}
if (!licensePlate) {
return this.$message.error('请填写车牌号码')
} else if (!truckTypeName) {
return this.$message.error('请选择车型名称')
} else if (!allowableVolume) {
return this.$message.error('请填写车辆体积')
} else if (!allowableLoad) {
return this.$message.error('请填写车辆载重')
} else if (!deviceGpsId) {
return this.$message.error('GPSID')
}
const data = {
deviceGpsId: this.vehicles.deviceGpsId,
licensePlate: this.vehicles.licensePlate,
allowableLoad: this.vehicles.allowableLoad,
allowableVolume: this.vehicles.allowableVolume,
truckTypeId: this.vehicles.truckTypeId,
truckTypeName: this.vehicles.truckTypeName,
picture: this.vehicles.picture
.map((item) => {
return item.size ? item.response.data : item.url
})
.join()
}
await truckTypeUpdate(this.vehicles.id, data).then((res) => {
if (String(res.code) === '200') {
this.$message({
message: '保存成功!',
type: 'success'
})
this.isShow = true
this.disabledLicensePlate = true
this.disabledAllowableVolume = true
this.disabledAllowableLoad = true
this.disabledGPSID = true
}
})
},
// 取消
handleCanVehicleInfo() {
this.isShow = true
this.disabledLicensePlate = true
this.disabledAllowableVolume = true
this.disabledAllowableLoad = true
this.disabledGPSID = true
this.getList(this.id)
}
}
}
</script>
<style lang="scss" scoped>
/deep/ .el-card {
height: 100%;
}
/deep/ .el-upload {
border: 1px dashed #d9d9d9;
}
/deep/ .avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
display: block;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409eff;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
}
.el-aside {
color: #333;
}
/deep/ .el-row {
margin-bottom: 20px;
}
.customer-details-box {
height: 100%;
margin-left: 20px;
.block {
background-color: #ffffff;
width: 100%;
padding: 0 24px;
}
.car-base {
color: #2a2929;
font-size: 16px;
margin: 15px 0;
font-weight: 700;
}
.car-img-base {
margin: 25px 0;
margin-top: 10px;
display: flex;
padding-left: 25px;
position: relative;
bottom: 20px;
.info-box {
border: 0 !important;
padding: 0 0 15px 0;
width: 100%;
}
.imgUpload-label {
font-size: 14px;
color: #20232a;
font-weight: normal;
white-space: nowrap;
}
/deep/ .img-box {
display: inline-block;
position: relative;
.img-shadow {
position: absolute;
top: 0;
width: 212px;
height: 159px;
background: rgba(0, 0, 0, 0.5);
border-radius: 4px;
text-align: center;
display: none;
.searchBigImg {
width: 28px;
height: 28px;
margin-top: 64px;
cursor: pointer;
}
}
}
/deep/ .el-card {
.el-card__body {
padding-left: 5px;
}
}
.img-box:hover {
.img-shadow {
display: block;
}
}
}
.form-box {
border: 0 !important;
/deep/ .el-card__body {
padding: 15px 26px;
padding-bottom: 30px;
.form-item-box {
display: flex;
flex-wrap: wrap;
.form-item {
width: 50%;
display: flex;
align-items: center;
margin-top: 24px;
box-sizing: border-box;
&:nth-child(1),
&:nth-child(2) {
margin-top: 0;
}
&:nth-child(odd) {
padding-right: 35px;
}
&:nth-child(even) {
padding-left: 35px;
}
.span-title {
min-width: 80px;
font-weight: 400;
text-align: right;
color: #20232a;
font-size: 14px;
}
/deep/ .el-input {
flex: 1;
margin-left: 10px;
}
/deep/.el-input.is-disabled .el-input__inner {
background: #eff3f8;
border: 1px solid #d8dde3;
border-radius: 5px;
font-weight: 400;
color: #bac0cd;
}
}
}
}
}
.footer-box {
text-align: center;
padding: 30px 0 16px;
.save-btn {
width: 110px;
border-radius: 5px;
font-weight: 400;
}
.cancel-btn {
width: 110px;
border-radius: 5px;
font-weight: 400;
}
}
}
// 修改el-button中warnning的默认样式
.el-button--warning {
width: 100px;
height: 40px;
background: #e15536;
border-radius: 4px;
// 修改鼠标悬浮时的样式
&:hover {
width: 100px;
height: 40px;
background: #ffab98;
border-radius: 4px;
}
// 修改按下时的样式
&:active {
width: 100px;
height: 40px;
background: #cc4628;
border-radius: 4px;
}
// 修改禁用时的样式
&.is-disabled {
width: 100px;
height: 40px;
background: #ffdfda;
border-radius: 4px;
}
}
/deep/ .el-dialog__header {
background-color: white;
position: relative;
z-index: 2;
padding: 0px;
}
/deep/ .el-dialog__body {
position: absolute;
height: 600px;
width: 100%;
top: 0;
padding: 0;
img {
position: absolute;
width: 100%;
height: 600px;
}
}
/deep/ .el-dialog {
height: 600px;
}
/deep/ .el-form-item__content{
white-space: nowrap;
flex-wrap: nowrap;
}
/deep/ .el-form-item{
margin-bottom: 0px;
width: 100%;
}
/deep/ .el-form-item__label{
font-size: 14px;
color:#20232a ;
font-weight: normal;
}
/deep/ .el-form-item__error{
left: 90px;
}
/deep/ .el-date-editor{
width:auto!important;
}
//只读状态下不展示表单提示语
.read{
/deep/ .el-form-item__error {
display: none;
}
}
</style>