step-one.vue
10.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
<template>
<div class="step-one">
<div
:class="['user-orc']"
v-show="inputType"
>
<div class="title">上传驾驶证自动识别VIN码</div>
<div
class="img-box"
@click="chooseImage"
@touchstart="touchstart"
@touchend="touchend"
>
<template v-if="vinImg">
<img :src="vinImg">
</template>
<template v-else>
<div class="sprite-icon icon-car-add"></div>
</template>
</div>
<div
class="input-items"
v-show="showInput"
>
<div class="item">
<div class="label">所有人:</div>
<div :class="['item-input',{'active':userName}]">
<input
type="text"
maxlength="20"
v-model="userName"
>
</div>
</div>
<div class="item">
<div class="label">VIN码:</div>
<div :class="['item-input',{'active':vin},{'err':vinErr}]">
<input
type="text"
maxlength="17"
v-model="vin"
>
</div>
</div>
<div class="item">
<div class="label">车牌号:</div>
<div :class="['item-input',{'active':plateNum},{'err':plateNumberErr}]">
<input
type="text"
maxlength="10"
v-model="plateNum"
>
</div>
</div>
</div>
<div class="line"></div>
<div class="subtitle">拍照要求</div>
<div class="photo-list">
<template v-for="(i,index) in photoList">
<div
:key="index"
class="photo-item"
>
<div :class="['sprite-icon',index == 0 ?'icon-car-success':'icon-car-err']"></div>
<div :class="['sprite-icon',`icon-car-photo-${index}`,'photo']"></div>
{{i}}
</div>
</template>
</div>
<div
:class="['btn',{'btn-disabled':!vin||!userName||!plateNumber||plateNumberErr}]"
v-show="vinImg"
@click="submit"
@touchstart="touchstart"
@touchend="touchend"
>
提交
</div>
<div :class="['tips',{'clearMargin':vinImg}]">
行驶证不在身边?
<div
class="change"
@click="changeType"
>
手动填写
<div class="sprite-icon icon-car-edit"></div>
</div>
</div>
</div>
<div :class="['user-input',{'show-user-input':!inputType}]">
<div class="title">请输入17位车辆VIN码信息</div>
<div class="input-items">
<div class="item">
<div class="label">所有人:</div>
<div :class="['item-input',{'active':userName}]">
<input
type="text"
maxlength="20"
v-model="userName"
>
</div>
</div>
<div class="item">
<div class="label">VIN码:</div>
<div :class="['item-input',{'active':vin},{'err':vinErr}]">
<input
type="text"
maxlength="17"
v-model="vin"
>
</div>
</div>
<div class="item">
<div class="label">车牌号:</div>
<div :class="['item-input',{'active':plateNum},{'err':plateNumberErr}]">
<input
type="text"
maxlength="10"
v-model="plateNum"
>
</div>
</div>
</div>
<div
:class="['btn',{'btn-disabled':!vin||!userName||!plateNumber || vinErr||plateNumberErr}]"
@click="submit"
@touchstart="touchstart"
@touchend="touchend"
>
提交
</div>
<div
class="tips"
@click="changeType"
>
证件识别
<div class="sprite-icon icon-car-camera"></div>
</div>
</div>
</div>
</template>
<script type='text/ecmascript-6'>
import WxConfig from '@u/WxConfig'
const WX = new WxConfig(['chooseImage'])
import { common, car } from '@r/api'
export default {
name: 'step-one',
data () {
return {
inputType: true,
photoList: ['正常拍摄', '照片模糊', '边框缺失', '照片反光'],
vinImg: '',
userName: '',
vin: '',
plateNum: '',
showInput: false,
vinErr: false,
plateNumberErr: false
}
},
mounted () {
},
watch: {
'vin' (n) {
if (n) {
let rex = /^[A-HJ-NPR-Z\d]{17}$/
this.vinErr = !rex.test(n)
}
},
'plateNum' (n) {
if (n) {
let rex = /^([京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][1-9DF][1-9ABCDEFGHJKLMNPQRSTUVWXYZ]\d{3}[1-9DF]|[京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][\dABCDEFGHJKLNMxPQRSTUVWXYZ]{5})$/
this.plateNumberErr = !rex.test(n)
}
}
},
methods: {
chooseImage () {
WX.chooseImage().then(res => {
let [data] = res
let { localData } = data
let suffix = ''
let imgUrl = ''
if (localData.indexOf(';') != -1) {
suffix = localData.split(';')[0]
imgUrl = localData.split('base64,')[1]
}
let type = suffix ? suffix.split('/')[1] : 'jpg'
if (!imgUrl) imgUrl = localData
if (type == 'unknown') type = 'jpg'
if (type.toLowerCase() != 'jpg' && type.toLowerCase() != 'jpeg' && type.toLowerCase() != 'png') {
this.showToast('图片格式错误')
return
}
this.showLoading('上传中...')
common.uploadImage({
file: `${type}@${imgUrl}`
}).then(img => {
if (img) {
let { data } = img
this.showLoading('识别中...')
car.scanVehicle({ imageUrl: data }).then(vinRes => {
if (vinRes) {
console.log(vinRes)
let { code, data } = vinRes
if (code == 0) {
this.vinImg = img.data
console.log(data)
this.plateNum = data.plateNumber
this.vin = data.vin
this.userName = data.userName
this.showInput = true
} else {
this.showToast('识别失败请重试', 'close')
this.vinImg = ''
this.showInput = false
}
} else {
this.showToast('识别失败请重试', 'close')
this.vinImg = ''
this.showInput = false
}
})
} else {
this.showToast('上传失败')
this.vinImg = ''
this.showInput = false
}
})
})
},
changeType () {
let { inputType } = this
this.inputType = !inputType
},
submit () {
let { vin, userName, plateNum, vinErr, plateNumberErr } = this
if (!vin || !userName || !plateNum || vinErr || plateNumberErr) return
this.showLoading('校检中...')
car.checkVin({
vin
}).then(res => {
if (res) {
console.log(res)
let { code, message } = res
if (code == 0) {
this.$emit('step_one_success', {
vin,
userName,
plateNum
})
} else {
this.showToast(message)
}
} else {
this.showToast('系统异常')
}
console.log(res)
})
}
}
}
</script>
<style scoped lang='scss'>
.step-one {
position: relative;
padding: 0 20px 20px;
.title {
font-size: 14px;
padding-top: 20px;
}
.input-items {
padding: 20px 26px 6px 17px;
.item {
display: flex;
align-items: center;
font-size: 12px;
color: #333333;
margin-bottom: 24px;
.label {
margin-right: 10px;
text-align: right;
width: 50px;
}
&-input {
background: #ffffff;
border: 1px solid #d8d8d8;
height: 28px;
width: calc(100% - 60px);
padding: 0 12px;
transition: all 0.2s;
input {
border: none;
width: 100%;
height: 100%;
font-size: 14px;
}
}
.active {
border-color: #008fff;
}
.err {
border-color: #fa5151;
}
}
}
.btn {
display: flex;
align-items: center;
justify-content: center;
width: 226px;
height: 30px;
background: #008fff;
border-radius: 18.5px;
font-size: 14px;
color: #ffffff;
margin: 30px auto;
}
.btn-disabled {
background: #e0e0e0;
}
.user-orc {
color: #3b3b3b;
text-align: center;
.subtitle {
font-size: 12px;
margin: 16px 0 10px;
}
.img-box {
width: 300px;
height: 180px;
margin: 10px auto 20px;
background: #ffffff;
box-shadow: 0 2px 8px 0 rgba(59, 147, 217, 0.1);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
}
.line {
background: #e9e9e9;
border-radius: 1px;
width: 100%;
height: 2px;
}
.photo-list {
display: grid;
grid-template-columns: repeat(4, 1fr);
font-size: 12px;
.photo-item {
display: flex;
flex-direction: column;
align-items: center;
.photo {
margin: 5px 0;
}
}
}
.tips {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 12px;
color: #666666;
margin-top: 90px;
.change {
display: flex;
align-items: center;
color: #008fff;
.sprite-icon {
margin-left: 6px;
}
}
}
.clearMargin {
margin-top: 0;
}
}
.user-input {
text-align: center;
padding: 20px 20px 0;
position: absolute;
right: 100%;
top: 0;
transition: all 0.5s;
.tips {
display: flex;
align-items: center;
justify-content: flex-end;
font-size: 12px;
color: #008fff;
.sprite-icon {
margin-left: 6px;
}
}
}
.show-user-input {
right: 0;
width: 100%;
box-sizing: border-box;
}
}
</style>