Commit e146dcdb by liwk

commit

1 parent 03dd8364
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
> >
<input <input
v-model="values[index]" v-model="values[index]"
type="text" type="number"
maxlength="1" maxlength="1"
@input="input(index)" @input="input(index,$event)"
:ref="`focus-${index}`" :ref="`focus-${index}`"
@keydown="keydown(index,$event)"
> >
</div> </div>
</template> </template>
...@@ -57,7 +58,16 @@ export default { ...@@ -57,7 +58,16 @@ export default {
} }
}, },
methods: { methods: {
keydown (index, $event) {
let { keyCode } = $event
if (keyCode == 8) {
setTimeout(() => {
if (index > 0) this.$refs[`focus-${index - 1}`][0].focus()
}, 100)
}
},
input (index) { input (index) {
this.values[index] = this.values[index].substring(0, 1)
let { length } = this let { length } = this
if (index < length - 1 && this.values[index]) this.$refs[`focus-${index + 1}`][0].focus() if (index < length - 1 && this.values[index]) this.$refs[`focus-${index + 1}`][0].focus()
} }
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
</div> </div>
<div class="item"> <div class="item">
<div class="label">VIN码:</div> <div class="label">VIN码:</div>
<div :class="['item-input',{'active':vin}]"> <div :class="['item-input',{'active':vin},{'err':vinErr}]">
<input <input
type="text" type="text"
maxlength="17" maxlength="17"
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
</div> </div>
<div class="item"> <div class="item">
<div class="label">车牌号:</div> <div class="label">车牌号:</div>
<div :class="['item-input',{'active':plateNumber}]"> <div :class="['item-input',{'active':plateNumber},{'err':plateNumberErr}]">
<input <input
type="text" type="text"
maxlength="10" maxlength="10"
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
</template> </template>
</div> </div>
<div <div
:class="['btn',{'btn-disabled':!vin||!userName||!plateNumber}]" :class="['btn',{'btn-disabled':!vin||!userName||!plateNumber||plateNumberErr}]"
v-show="vinImg" v-show="vinImg"
@click="submit" @click="submit"
@touchstart="touchstart" @touchstart="touchstart"
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
</div> </div>
<div class="item"> <div class="item">
<div class="label">VIN码:</div> <div class="label">VIN码:</div>
<div :class="['item-input',{'active':vin}]"> <div :class="['item-input',{'active':vin},{'err':vinErr}]">
<input <input
type="text" type="text"
maxlength="17" maxlength="17"
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
</div> </div>
<div class="item"> <div class="item">
<div class="label">车牌号:</div> <div class="label">车牌号:</div>
<div :class="['item-input',{'active':plateNumber}]"> <div :class="['item-input',{'active':plateNumber},{'err':plateNumberErr}]">
<input <input
type="text" type="text"
maxlength="10" maxlength="10"
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
</div> </div>
</div> </div>
<div <div
:class="['btn',{'btn-disabled':!vin||!userName||!plateNumber}]" :class="['btn',{'btn-disabled':!vin||!userName||!plateNumber || vinErr||plateNumberErr}]"
@click="submit" @click="submit"
@touchstart="touchstart" @touchstart="touchstart"
@touchend="touchend" @touchend="touchend"
...@@ -156,10 +156,27 @@ export default { ...@@ -156,10 +156,27 @@ export default {
userName: '', userName: '',
vin: '', vin: '',
plateNumber: '', plateNumber: '',
showInput: false showInput: false,
vinErr: false,
plateNumberErr: false
} }
}, },
mounted () { 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: { methods: {
chooseImage () { chooseImage () {
...@@ -213,8 +230,8 @@ export default { ...@@ -213,8 +230,8 @@ export default {
this.inputType = !inputType this.inputType = !inputType
}, },
submit () { submit () {
let { vin, userName, plateNumber } = this let { vin, userName, plateNumber, vinErr, plateNumberErr } = this
if (!vin || !userName || !plateNumber) return if (!vin || !userName || !plateNumber || vinErr || plateNumberErr) return
this.showLoading('校检中...') this.showLoading('校检中...')
car.checkVin({ car.checkVin({
vin vin
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!