思路解析:车牌号码由31位汉字,26位字母,10位数字组成的,开头第一位由省份简称的汉字,第二位字母根据省份下的城市或地区区分,最后的五位或者六位,是有字母和数字组成的,共有七位的车牌号码和八位的车牌号码,(注:其中的八位数的车牌号码为能源车的车牌号码。)
Page({ data: { licensePlateShowHidden:true, licensePlate_provinces_Box:true, licensePlate_letter_Box: true, licensePlate_digital_Box: true, licensePlate_provinces: [ "京", "沪", "浙", "苏", "粤", "鲁", "晋", "冀", "豫", "川", "渝", "辽", "吉", "黑", "皖", "鄂", "津", "贵", "云", "桂", "琼", "青", "新", "藏", "蒙", "宁", "甘", "陕", "闽", "赣", "湘" ], licensePlate_letter: [ "A", "B", "C", "D", "E", "F", "G", "H", "L", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ], licensePlate_digital: [ "", "", "", "", "", "", "", "", "", "" ], LicensePlateNumber:'', }, // 显示模拟键盘 LicensePlateNumber:function(){ var that = this; var LicensePlateNumber = this.data.LicensePlateNumber; var LicensePlateNumberLen = LicensePlateNumber.length; console.log(LicensePlateNumber, LicensePlateNumberLen) if (LicensePlateNumberLen == ){ this.setData({ licensePlateShowHidden: false, licensePlate_provinces_Box: false, }) } else if (LicensePlateNumberLen == ){ this.setData({ licensePlateShowHidden: false, licensePlate_letter_Box: false, }) }else{ this.setData({ licensePlateShowHidden: false, licensePlate_digital_Box: false, }) } }, // 切换成字母 licensePlate_switchLetter:function(){ this.setData({ licensePlate_provinces_Box:true, licensePlate_letter_Box:false, licensePlate_digital_Box: true, }) }, // 切换成数字 licensePlate_switchDigital: function () { var LicensePlateNumber = this.data.LicensePlateNumber; var LicensePlateNumberLen = LicensePlateNumber.length; if (LicensePlateNumberLen == ){ wx.showToast({ title: '车牌号码第二位必须是字母', icon: 'none', duration: , }) }else{ this.setData({ licensePlate_provinces_Box: true, licensePlate_letter_Box: true, licensePlate_digital_Box: false, }) } }, // 删除 licensePlate_delete: function (e) { var LicensePlateNumber = this.data.LicensePlateNumber; var LicensePlateNumberLen = LicensePlateNumber.length; var LicensePlateNumberDelete = LicensePlateNumber.split(''); var NewLicensePlateNumber = LicensePlateNumberDelete.join('').slice(,-) if (LicensePlateNumberDelete.slice(,-).length == ){ this.setData({ licensePlate_provinces_Box: true, licensePlate_letter_Box: false, licensePlate_digital_Box: true, }) } else if (LicensePlateNumberLen == || LicensePlateNumber == '' || LicensePlateNumberDelete.slice(, -).length == ){ this.setData({ licensePlate_provinces_Box: false, licensePlate_letter_Box: true, licensePlate_digital_Box: true, }) } this.setData({ LicensePlateNumber: NewLicensePlateNumber }) }, // 清空 licensePlate_empty: function (e) { this.setData({ LicensePlateNumber:'', licensePlate_provinces_Box: false, licensePlate_letter_Box: true, licensePlate_digital_Box: true, }) }, // 关闭模拟键盘 licensePlate_close:function(){ this.setData({ licensePlateShowHidden: true }) }, // 点击获取省份 licensePlate_provinces: function (e) { this.setData({ LicensePlateNumber: e.target.dataset.licenseplateprovinces, licensePlate_letter_Box: false, licensePlate_digital_Box: true, }) console.log(e.target.dataset.licenseplateprovinces) }, // 点击获取字母 licensePlate_letter: function (e) { var LicensePlateNumber = this.data.LicensePlateNumber; var LicensePlateNumberLen = LicensePlateNumber.length; if (LicensePlateNumberLen != ) { this.setData({ LicensePlateNumber: LicensePlateNumber + e.target.dataset.licenseplateprovinces }) console.log(e.target.dataset.licenseplateprovinces) } else { wx.showToast({ title: '车牌号码最多不能超过位', icon: 'none', duration: , }) } }, // 点击获取数字 licensePlate_digital: function (e) { var LicensePlateNumber = this.data.LicensePlateNumber; var LicensePlateNumberLen = LicensePlateNumber.length; if (LicensePlateNumberLen != ){ this.setData({ LicensePlateNumber: LicensePlateNumber + e.target.dataset.licenseplateprovinces }) console.log(e.target.dataset.licenseplateprovinces) }else{ wx.showToast({ title: '车牌号码最多不能超过位', icon:'none', duration:, }) } }, })