Commit e146dcdb by liwk

commit

1 parent 03dd8364
......@@ -7,10 +7,11 @@
>
<input
v-model="values[index]"
type="text"
type="number"
maxlength="1"
@input="input(index)"
@input="input(index,$event)"
:ref="`focus-${index}`"
@keydown="keydown(index,$event)"
>
</div>
</template>
......@@ -57,7 +58,16 @@ export default {
}
},
methods: {
keydown (index, $event) {
let { keyCode } = $event
if (keyCode == 8) {
setTimeout(() => {
if (index > 0) this.$refs[`focus-${index - 1}`][0].focus()
}, 100)
}
},
input (index) {
this.values[index] = this.values[index].substring(0, 1)
let { length } = this
if (index < length - 1 && this.values[index]) this.$refs[`focus-${index + 1}`][0].focus()
}
......
......@@ -34,7 +34,7 @@
</div>
<div class="item">
<div class="label">VIN码:</div>
<div :class="['item-input',{'active':vin}]">
<div :class="['item-input',{'active':vin},{'err':vinErr}]">
<input
type="text"
maxlength="17"
......@@ -44,7 +44,7 @@
</div>
<div class="item">
<div class="label">车牌号:</div>
<div :class="['item-input',{'active':plateNumber}]">
<div :class="['item-input',{'active':plateNumber},{'err':plateNumberErr}]">
<input
type="text"
maxlength="10"
......@@ -68,7 +68,7 @@
</template>
</div>
<div
:class="['btn',{'btn-disabled':!vin||!userName||!plateNumber}]"
:class="['btn',{'btn-disabled':!vin||!userName||!plateNumber||plateNumberErr}]"
v-show="vinImg"
@click="submit"
@touchstart="touchstart"
......@@ -103,7 +103,7 @@
</div>
<div class="item">
<div class="label">VIN码:</div>
<div :class="['item-input',{'active':vin}]">
<div :class="['item-input',{'active':vin},{'err':vinErr}]">
<input
type="text"
maxlength="17"
......@@ -113,7 +113,7 @@
</div>
<div class="item">
<div class="label">车牌号:</div>
<div :class="['item-input',{'active':plateNumber}]">
<div :class="['item-input',{'active':plateNumber},{'err':plateNumberErr}]">
<input
type="text"
maxlength="10"
......@@ -123,7 +123,7 @@
</div>
</div>
<div
:class="['btn',{'btn-disabled':!vin||!userName||!plateNumber}]"
:class="['btn',{'btn-disabled':!vin||!userName||!plateNumber || vinErr||plateNumberErr}]"
@click="submit"
@touchstart="touchstart"
@touchend="touchend"
......@@ -156,10 +156,27 @@ export default {
userName: '',
vin: '',
plateNumber: '',
showInput: false
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)
}
},
'plateNumber' (n) {
if (n) {
let rex = /^([京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][1-9DF][1-9ABCDEFGHJKLMNPQRSTUVWXYZ]\d{3}[1-9DF]|[京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][\dABCDEFGHJKLNMxPQRSTUVWXYZ]{5})$/
this.plateNumberErr = !rex.test(n)
}
}
},
methods: {
chooseImage () {
......@@ -213,8 +230,8 @@ export default {
this.inputType = !inputType
},
submit () {
let { vin, userName, plateNumber } = this
if (!vin || !userName || !plateNumber) return
let { vin, userName, plateNumber, vinErr, plateNumberErr } = this
if (!vin || !userName || !plateNumber || vinErr || plateNumberErr) return
this.showLoading('校检中...')
car.checkVin({
vin
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!