You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.0 KiB
90 lines
3.0 KiB
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
},
|
|
properties: {
|
|
plateNumber: {
|
|
type: Array,
|
|
value: ["", "", "", "", "", "", ""]
|
|
},
|
|
safeBottom: {
|
|
type: Number,
|
|
value: 0
|
|
}
|
|
},
|
|
data: {
|
|
provinces: "京津沪冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤川青藏琼宁渝港澳台",
|
|
letters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
numbers: "0123456789",
|
|
visible: false,
|
|
activeIndex: -1,
|
|
type: 0,
|
|
disabled: true,
|
|
mode: 0 // 键盘模式 0 关闭状态 1 显示省份输入 2 显示数字和字母输入
|
|
},
|
|
lifetimes: {
|
|
attached: function () {
|
|
|
|
},
|
|
},
|
|
methods: {
|
|
show: function (number, type) {
|
|
var index = 0
|
|
if(number && number.length){
|
|
this.data.plateNumber = number.split('')
|
|
index = this.data.plateNumber.length - 1
|
|
}
|
|
this.data.type = type
|
|
this.updateNumber()
|
|
this.setData({ plateNumber: this.data.plateNumber, mode: 1, activeIndex: index, visible: true})
|
|
},
|
|
hide: function () {
|
|
this.setData({visible: false, plateNumber: ["", "", "", "", "", "", ""]})
|
|
this.triggerEvent("change", null)
|
|
},
|
|
updateNumber: function(){
|
|
this.data.disabled = false
|
|
for (let index = 0; index < this.data.plateNumber.length; index++) {
|
|
const element = this.data.plateNumber[index]
|
|
if(element.length == 0){
|
|
this.data.disabled = true
|
|
break
|
|
}
|
|
}
|
|
this.setData({disabled: this.data.disabled, plateNumber: this.data.plateNumber})
|
|
},
|
|
inputKeyboard: function(e){
|
|
let index = typeof e === 'number' ? e : e.currentTarget.dataset.index
|
|
if(e.currentTarget && this.data.plateNumber[index].length == 0){
|
|
return
|
|
}
|
|
this.setData({ mode: index == 0 ? 1 : 2, activeIndex: index })
|
|
},
|
|
tapDelete: function(e){
|
|
let activeIndex = this.data.activeIndex
|
|
this.data.plateNumber[activeIndex] = ''
|
|
this.updateNumber()
|
|
if (activeIndex > 0) {
|
|
this.inputKeyboard(--activeIndex)
|
|
}
|
|
},
|
|
tapFinish: function(){
|
|
if(this.data.disabled){
|
|
return
|
|
}
|
|
this.setData({visible: false, activeIndex: -1 })
|
|
this.triggerEvent("change", {plateNumber: this.data.plateNumber.join(''), type: this.data.type})
|
|
},
|
|
tapKeyboard: function(e){
|
|
let val = e.currentTarget.dataset.val
|
|
let activeIndex = this.data.activeIndex
|
|
this.data.plateNumber[activeIndex] = val
|
|
this.updateNumber()
|
|
if (activeIndex < 6) {
|
|
this.inputKeyboard(++activeIndex)
|
|
} else {
|
|
this.tapFinish()
|
|
}
|
|
},
|
|
}
|
|
})
|