WXML
<view class="page"> <!-- 车牌号码输入框 --> <view class="carNumber"> <view class="weui-cells__title">请输入您要缴费的车牌号码</view> <!-- 车牌号头两位 --> <view class="carNumber-items"> <view class="carNumber-items-box" bindtap='openKeyboard'> <view class="carNumber-items-province carNumber-items-box-list">{{carnum[0] || ''}}</view> <view class="carNumber-items-En carNumber-items-box-list">{{carnum[1] || ''}}</view> </view> <!-- 常规 --> <view class="carNumber-item" bindtap='openKeyboard'>{{carnum[2] || ''}}</view> <view class="carNumber-item" bindtap='openKeyboard'>{{carnum[3] || ''}}</view> <view class="carNumber-item" bindtap='openKeyboard'>{{carnum[4] || ''}}</view> <view class="carNumber-item" bindtap='openKeyboard'>{{carnum[5] || ''}}</view> <view class="carNumber-item" bindtap='openKeyboard'>{{carnum[6] || ''}}</view> <!-- 新能源 --> <view class="carNumber-item {{showNewPower ? '': 'carNumber-item-newpower'}}"> <view wx:if="{{!showNewPower}}" bindtap='showPowerBtn'> <view class="carNumber-newpower-add">+</view> <view style="font-size:12px;">新能源</view> </view> <view wx:if="{{showNewPower}}" bindtap='openKeyboard'> {{carnum[7]}} </view> </view> </view> </view> <!-- 提交车牌 --> <button class="carNumberBtn" bindtap='submitNumber' style="background: green;color:#fff;" type="default">确定</button> <!-- 虚拟键盘 --> <view class="keyboard" hidden='{{!KeyboardState}}'> <view class="keyboardClose"> <view class="keyboardClose_btn1" bindtap='deleteAll'>清空</view> <view class="keyboardClose_btn2" bindtap='closeKeyboard'>关闭</view> </view> <!-- 省份简写键盘 --> <view class="keyboard-item" hidden="{{carnum[0]}}"> <view class="keyboard-line" wx:for="{{provinces}}" wx:key="index"> <view class="keyboard-btn" wx:for="{{item}}" wx:key="index" data-val="{{itemlist}}" wx:for-item="itemlist" bindtap='bindChoose'>{{itemlist}}</view> </view> <view class="keyboard-del" bindtap='bindDelChoose'> <text class="font_family icon-shanchu keyboard-del-font">←</text> </view> </view> <!-- 车牌号码选择键盘 --> <view class="keyboard-item iscarnumber" hidden="{{!carnum[0]}}"> <view class="keyboard-line" wx:for="{{numbers}}" wx:key="index"> <view class="keyboard-btn" wx:for="{{item}}" wx:key="index" data-val="{{itemlist}}" wx:for-item="itemlist" bindtap='bindChoose'>{{itemlist}}</view> </view> <view class="keyboard-del" bindtap='bindDelChoose'> <text class="font_family icon-shanchu keyboard-del-font">←</text> </view> </view> </view> </view>
CSS
/* pages/parking_home/parking_home.wxss */ .page{ background: #fff; position: absolute; top:0; bottom:0; width: 100%; } .weui-cells__title{ margin-top:.77em; margin-bottom:.3em; padding-left:15px; padding-right:15px; color:#999; font-size:14px; } /* 虚拟键盘 */ .keyboard{ height: auto; background: #d1d5d9; position: fixed; bottom:0; width: 100%; left:0; } .keyboard-item{ padding:10rpx 2rpx 25rpx 2rpx; position: relative; display: block; } /* 关闭虚拟键盘 */ .keyboardClose{ height: 70rpx; background-color: #f7f7f7; overflow: hidden; } .keyboardClose_btn1{ float: right; line-height: 70rpx; font-size: 15px; padding-right: 30rpx; color: red; } .keyboardClose_btn2{ float: right; line-height: 70rpx; font-size: 15px; padding-right: 30rpx; color: orange; } /* 虚拟键盘-省缩写 */ /* 虚拟键盘-行 */ .keyboard-line{ margin:0 auto; text-align: center; } .iscarnumber .keyboard-line{ text-align: center; margin-left: 5rpx; } /* 虚拟键盘-单个按钮 */ .keyboard-btn{ font-size: 25px; color: #333333; background: #fff; display: inline-block; padding:18rpx 0; width: 64rpx; text-align: center; box-shadow: 0 6rpx 5rpx 0 #999999; border-radius: 10rpx; margin:12rpx 5rpx; } .keyboard-btn:active{ font-size: 25px; color: #333333; background: #999999; display: inline-block; padding:18rpx 0; width: 64rpx; text-align: center; box-shadow: 0 6rpx 5rpx 0 #999999; border-radius: 10rpx; margin:12rpx 6rpx; } /* 虚拟键盘-删除按钮 */ .keyboard-del{ font-size: 17px; color: #333333; background: #A7B0BC; display: inline-block; padding:4rpx 25rpx; box-shadow: 0 2rpx 0 0 #999999; border-radius: 10rpx; margin:5rpx; position: absolute; width: 20px; height: 45px; line-height: 45px; bottom:26rpx; right: 16rpx; } .keyboard-del:active{ font-size: 17px; color: #333333; background: #fff; display: inline-block; padding:4rpx 25rpx; box-shadow: 0 2rpx 0 0 #999999; border-radius: 10rpx; margin:5rpx; position: absolute; width: 20px; height: 45px; line-height: 45px; bottom:26rpx; right: 16rpx; } .keyboard-del-font{ font-size:25px; } /* 车牌号码 */ .carNumber-items{ text-align: center; } .carNumber-items-box{ width: 158rpx; height: 90rpx; border: 2rpx solid #CCCCCC; border-radius: 4rpx; display: inline-block; vertical-align: middle; position: relative; margin-right: 30rpx; } .carNumber-items-box-list{ width: 76rpx; height: 70rpx; line-height: 70rpx; text-align: center; display: inline-block; font-size: 18px; margin:10rpx 0; vertical-align: middle; } .carNumber-items-province{ border-right: 1rpx solid #ccc; } .carNumber-items-box::after{ content: ""; width: 6rpx; height: 6rpx; position: absolute; right: -22rpx; top: 40rpx; border-radius: 50%; background-color: #ccc; } .carNumber-item{ width: 76rpx; height: 90rpx; font-size: 18px; text-align: center; border: 2rpx solid #CCCCCC; border-radius: 4rpx; line-height: 90rpx; display: inline-block; margin:0 4rpx; vertical-align: middle; } /* 新能源 */ .carNumber-item-newpower{ border: 2rpx dashed #A8BFF3; background-color: #F6F9FF; color: #A8BFF3; font-size: 12px; line-height: 45rpx; } .carNumber-newpower-add{ font-size: 18px; } /* 确认按钮 */ .carNumberBtn{ border-radius: 4rpx; margin:80rpx 40rpx; }
JS
Page({ /** * 页面的初始数据 */ data: { // 省份简写 provinces: [ ['京', '沪', '粤', '津', '冀', '晋', '蒙', '辽', '吉', '黑'], ['苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘'], ['桂', '琼', '渝', '川', '贵', '云', '藏'], ['陕', '甘', '青', '宁', '新'], ], // 车牌输入 numbers: [ ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"], ["A", "S", "D", "F", "G", "H", "J", "K", "L"], ["Z", "X", "C", "V", "B", "N", "M"] ], carnum: [], showNewPower: false, KeyboardState: true }, // 选中点击设置 bindChoose(e) { if (!this.data.carnum[6] || this.data.showNewPower) { var arr = []; arr[0] = e.target.dataset.val; this.data.carnum = this.data.carnum.concat(arr) this.setData({ carnum: this.data.carnum }) } if(this.data.carnum[6]){ this.setData({ showNewPower: true, KeyboardState: true }) } }, bindDelChoose() { if (this.data.carnum.length != 0) { this.data.carnum.splice(this.data.carnum.length - 1, 1); this.setData({ carnum: this.data.carnum }) } }, showPowerBtn() { this.setData({ showNewPower: true, KeyboardState: true }) }, closeKeyboard() { this.setData({ KeyboardState: false }) }, openKeyboard() { this.setData({ KeyboardState: true }) }, //清空按钮 deleteAll(){ this.setData({ carnum:[], }) }, // 提交车牌号码 submitNumber() { if(this.data.carnum.length<7){ wx.showToast({ title: '请输入完整的车牌!', icon:'none', duration: 2000, }) } if (this.data.carnum[6]) { var carno=this.data.carnum; var carnonew=carno.join(''); console.log(carnonew); } }, /** * 生命周期函数--监听页面加载 */ onl oad: function (options) { this.setData({ carnum:[], }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })
标签:车牌号码,carnum,微信,border,height,键盘,font,margin,size From: https://www.cnblogs.com/linweimu/p/17864660.html