// component/carnumber_input/carnumber_input.js
// mode = P - province, N - number,P是省模式,N是号码模式
Component({
/**
* 组件的属性列表
*/
properties: {
show: {
type: Boolean,
value: false
}
},
/**
* 组件的初始数据
*/
data: {
mode: 'P',
provinceList: '京沪粤津浙苏湘渝云豫皖陕桂新青琼闽蒙辽宁鲁晋吉翼黑甘鄂赣贵川藏使'.split(''),
numberList: '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ挂港澳警领学'.split(''),
inputList: [
{
type: 'input',
value: null
},
{
type: 'input',
value: null
},
{
type: 'break',
value: '•'
},
{
type: 'input',
value: null
},
{
type: 'input',
value: null
},
{
type: 'input',
value: null
},
{
type: 'input',
value: null
},
{
type: 'input',
value: null
},
{
type: 'input',
value: null
}
],
input_active_index: 0
},
/**
* 组件的方法列表
*/
methods: {
tapInput(e) {
var index = e.currentTarget.dataset.index;
var item = e.currentTarget.dataset.item;
console.log(index, item);
this.setData({
mode: index === 0 ? 'P' : 'N',
input_active_index: index
})
},
tapProvince(e) {
var item = e.currentTarget.dataset.item;
console.log(item);
var key = `inputList[0].value`;
this.setData({
[key]: [item],
input_active_index: 1,
mode: 'N'
})
},
tapNumber(e) {
var item = e.currentTarget.dataset.item;
var key = `inputList[${this.data.input_active_index}].value`;
var newIndex = this.data.input_active_index + 1;
if (newIndex === 2) {
newIndex++;
} else if (newIndex >= 8) {
newIndex = 8;
}
this.setData({
[key]: [item],
input_active_index: newIndex
})
},
tapDel(e) {
var key = `inputList[${this.data.input_active_index}].value`;
var newIndex = this.data.input_active_index - 1;
if (newIndex < 0) {
newIndex = 0
} else if (newIndex === 2) {
newIndex--;
}
this.setData({
[key]: [null],
mode: newIndex === 0 ? 'P' : 'N',
input_active_index: newIndex
})
},
complete() {
var carnum = "";
this.data.inputList.forEach(e=>{
if (e.value) {
carnum += e.value
}
})
console.log('carnum', carnum);
this.triggerEvent('getCarNumber', carnum);
this.setData({
show: false
})
this.triggerEvent('closeCarNumberInput');
},
closeWindow(e) {
if(e.target.dataset.target === 'main') {
this.setData({
show: false
})
this.triggerEvent('closeCarNumberInput');
}
},
donothing() {
}
}
})