123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- // components/addCarNumber/index.js
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- value: { //输入值
- value: null
- },
- placeholder: {
- type: String,
- value: '请输入车牌号'
- },
- isAudit: { //是否禁用
- type: Boolean,
- value: false
- },
- disabled: { //是否禁用
- type: Boolean,
- value: false
- },
- iscarNumber: {//键盘是否弹起
- type: Boolean,
- value: false
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- areaWordList: ['浙', '京', '沪', '苏', '粤', '鲁', '晋', '冀', '豫', '川', '渝', '辽', '吉', '黑', '皖', '鄂', '湘', '赣', '闽', '陕', '甘', '宁', '蒙', '津', '贵', '云', '桂', '琼', '青', '新', '藏', '港', '澳', '台'], //地域中文表
- numberList: [], //数字表
- wordList: [], //字母表
- show: false, //是否显示键盘弹窗
- showAreaWord: true, //是否显示地域中文表
- showCompleteButton: false //是否显示完成按钮
- },
- /**
- * 组件的方法列表
- */
- methods: {
- // 点击拉起键盘输入
- showpopup() {
- if (!this.data.isAudit && !this.data.disabled) {
- console.log(12345);
- this.setData({
- show: true
- })
- }
- },
- // 获得初始化英文数字数组
- getNumberList() {
- let numberArr = Array.from(new Array(10)).map((item, index) => {
- return index.toString()
- })
- let wordArr = Array.from(new Array(26)).map((item, index) => {
- return String.fromCharCode(index + 65)
- });
- wordArr = wordArr.concat(['挂', '领', '港', '澳', '学', '警'])
- this.setData({
- numberList: numberArr,
- wordList: wordArr,
- })
- },
- // 点击获得输入值
- getValue(e) {
- let word = e.currentTarget.dataset.value
- let {
- value
- } = this.data;
- value = value ? (value + word) : word;
- if (value.length == 2) {
- let charCode = word.charCodeAt()
- if (charCode < 65 || charCode > 90) {
- wx.showToast({
- title: '车牌号的第二位必需是字母',
- icon: 'none'
- });
- return
- }
- }
- this.matchValue(value)
- },
- // 判断输入值操作
- matchValue(value) {
- if (value && value.length > 8) return;
- this.setData({
- value
- });
- this.triggerEvent('change', value);
- if (!this.data.showCompleteButton && value && value.length >= 7) {
- this.setData({
- showCompleteButton: true
- });
- } else if (this.data.showCompleteButton && value && value.length < 7) {
- this.setData({
- showCompleteButton: false
- });
- }
- },
- // 删除
- delete() {
- let {
- value
- } = this.data;
- value = value.slice(0, value.length - 1);
- this.matchValue(value)
- },
- // 关闭键盘
- onClose() {
- this.setData({
- show: false
- })
- },
- },
- observers: {
- "value": function (value) {
- let showAreaWord = value ? false : true
- this.setData({
- showAreaWord: showAreaWord
- });
- },
- "iscarNumber":function(value){
- if(value){
- this.showpopup()
- }
- }
- },
- lifetimes: {
- attached() {
- this.getNumberList();
- this.matchValue(this.data.value)
- }
- }
- })
|