微信小程序实现车牌号键盘

<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">
            <text>+</text></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>
/* 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: 30rpx;
  padding-right: 30rpx;
  color: #999;
  font-size: 28rpx;

}

/* 虚拟键盘 */
.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: 30rpx;
  padding-right: 30rpx;
  color: red;
}

.keyboardClose_btn2 {
  float: right;
  line-height: 70rpx;
  font-size: 30rpx;
  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: 25rpx;
  color: #333333;
  background: #fff;
  display: inline-block;
  padding: 18rpx 0;
  width: 63rpx;
  text-align: center;
  box-shadow: 0 6rpx 5rpx 0 #999999;
  border-radius: 10rpx;
  margin: 12rpx 6rpx;
  box-sizing: border-box;
}

.keyboard-btn:active {
  font-size: 25rpx;
  color: #333333;
  background: #999999;
  display: inline-block;
  padding: 18rpx 0;
  width: 63rpx;
  text-align: center;
  box-shadow: 0 6rpx 5rpx 0 #999999;
  border-radius: 10rpx;
  margin: 12rpx 6rpx;
}

/* 虚拟键盘-删除按钮 */
.keyboard-del {
  font-size: 34rpx;
  color: #333333;
  background: #A7B0BC;
  display: inline-block;
  padding: 4rpx 25rpx;
  box-shadow: 0 2rpx 0 0 #999999;
  border-radius: 10rpx;
  margin: 12rpx 6rpx;
  position: absolute;
  width: 40rpx;
  height: 61.5rpx;
  line-height: 61.5rpx;
  bottom: 26rpx;
  right: 16rpx;
}

.keyboard-del:active {
  font-size: 34rpx;
  color: #333333;
  background: #fff;
  display: inline-block;
  padding: 4rpx 25rpx;
  box-shadow: 0 2rpx 0 0 #999999;
  border-radius: 10rpx;
  margin: 12rpx 6rpx;
  position: absolute;
  width: 40rpx;
  height: 61.5rpx;
  line-height: 61.5rpx;
  bottom: 26rpx;
  right: 16rpx;
}

.keyboard-del-font {
  font-size: 20rpx;
}

/* 车牌号码 */
.carNumber-items {
  text-align: center;
}

.carNumber-items-box {
  width: 122rpx;
  height: 60rpx;
  border: 2rpx solid #CCCCCC;
  border-radius: 4rpx;
  display: inline-block;
  vertical-align: middle;
  position: relative;
  margin-right: 30rpx;
  border-radius: 10rpx;
}

.carNumber-items-box-list {
  width: 60rpx;
  height: 60rpx;
  line-height: 60rpx;
  text-align: center;
  display: inline-block;
  font-size: 36rpx;
  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: 30rpx;
  border-radius: 50%;
  background-color: #ccc;
}

.carNumber-item {
  width: 60rpx;
	height: 60rpx;
	background-color: #ffffff;
	border-radius: 10rpx;
	border: 2rpx solid #cccccc;
  font-size: 36rpx;
  text-align: center;
  line-height: 60rpx;
  display: inline-block;
  margin: 0 4rpx;
  vertical-align: middle;
  transform: scale(1);

}

/* 新能源 */
.carNumber-item-newpower {
  width: 90rpx;
	height: 61rpx;
	background-color: #027aff;
  border-radius: 10rpx;
  color: #fff;
  font-size: 24rpx;
  line-height: 40rpx;
  text-align: center;
}

.carNumber-newpower-add {
  font-size: 24rpx;
  line-height: 58rpx;
}
.carNumber-newpower-add text{
  font-size: 36rpx;
  margin-right: 4rpx;
}

/* 确认按钮 */
.carNumberBtn {
  border-radius: 4rpx;
  margin: 80rpx 40rpx;
}
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);
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
 
  }
})
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值