小程序自定義鍵盤車牌號輸入

page {
  background: rgba(248, 248, 248, 1);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", sans-serif;
}

.userinfo, .uploader, .tunnel {
  margin-top: 40rpx;
  height: 140rpx;
  width: 100%;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-left: none;
  border-right: none;
  display: flex;
  flex-direction: row;
  align-items: center;
  transition: all 300ms ease;
}

.userinfo-avatar {
  width: 100rpx;
  height: 100rpx;
  margin: 20rpx;
  border-radius: 50%;
  background-size: cover;
  background-color: white;
}

.userinfo-avatar:after {
  border: none;
}

.userinfo-nickname {
  font-size: 32rpx;
  color: #007aff;
  background-color: white;
  background-size: cover;
}

.userinfo-nickname::after {
  border: none;
}

.uploader, .tunnel {
  height: auto;
  padding: 0 0 0 40rpx;
  flex-direction: column;
  align-items: flex-start;
  box-sizing: border-box;
}

.uploader-text, .tunnel-text {
  width: 100%;
  line-height: 52px;
  font-size: 34rpx;
  color: #007aff;
}

.uploader-container {
  width: 100%;
  height: 400rpx;
  padding: 20rpx 20rpx 20rpx 0;
  display: flex;
  align-content: center;
  justify-content: center;
  box-sizing: border-box;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.uploader-image {
  width: 100%;
  height: 360rpx;
}

.tunnel {
  padding: 0 0 0 40rpx;
}

.tunnel-text {
  position: relative;
  color: #222;
  display: flex;
  flex-direction: row;
  align-content: center;
  justify-content: space-between;
  box-sizing: border-box;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.tunnel-text:first-child {
  border-top: none;
}

.tunnel-switch {
  position: absolute;
  right: 20rpx;
  top: -2rpx;
}

.disable {
  color: #888;
}

.service {
  position: fixed;
  right: 40rpx;
  bottom: 40rpx;
  width: 140rpx;
  height: 140rpx;
  border-radius: 50%;
  background: linear-gradient(#007aff, #0063ce);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
  display: flex;
  align-content: center;
  justify-content: center;
  transition: all 300ms ease;
}

.service-button {
  position: absolute;
  top: 40rpx;
}

.service:active {
  box-shadow: none;
}

.request-text {
  padding: 20rpx 0;
  font-size: 24rpx;
  line-height: 36rpx;
  word-break: break-all;
}
.carNum {
  width: 90%;
  height: 100rpx;
  display: flex;
  justify-content: space-between;
  margin-top: 50rpx; 
}
.carNum view{
  width: 84rpx;
  height: 84rpx;
  /* border-radius: 5px; */
  border: 1px solid #efefef;
  text-align: center;
  line-height: 84rpx;
  background: #fff;
  font-size:50rpx;
  font-family:PingFangSC-Semibold,PingFang SC;
  font-weight:600;
  color:rgba(0,0,0,1);
}
.carNum view.active{
  border:1px solid rgba(255,56,61,1);
  /* box-shadow: 0 0 4px 0px red; */
}
.keyProvienceboard{
  position: fixed;
  display: flex;
  padding: 20rpx;
  background: rgba(241, 241, 241, 1);
  flex-flow: row wrap;
  justify-content: space-around;
  bottom: 0;
}
.keyboard{
  background: rgba(241, 241, 241, 1);
}
.keyProvienceboard view,
.keyboard view.key view{
  width:70rpx;
  height: 90rpx;
  margin: 7rpx;
  text-align: center;
  line-height: 90rpx;
  /* flex: 0 0 16%; */
  border-radius: 20rpx;
  border: 1px solid rgba(219,219,219,1);
  background:#fff;
  font-size: 30rpx;
  margin-right: 0;
}
.keyboard{
  position: fixed;
  bottom: 0;
  width: 100%;
  padding: 20rpx;
  box-sizing: border-box;
}
.keyboard view.key{
  height: 90rpx;
  margin: 10rpx 0;
}
.keyboard view.key view{
  width: calc(9% - 2px);
  margin: 0 0.5%;
  float: left;
}
.moduleTitle{
  width: 100%;
  height: 140rpx;
  font-size: 50rpx;
  font-family: PingFangSC-Semibold,PingFang SC;
  font-weight: 600;
  color: rgba(0,0,0,1);
  line-height: 140rpx;
  letter-spacing: 1px;
  text-align: center;
  margin-top: 40rpx;
}
.moduleTip{
  width:100%;
  height:42rpx;
  font-size:32rpx;
  font-family:PingFang-SC-Medium,PingFang-SC;
  font-weight:500;
  color:rgba(133,132,136,1);
  line-height:42rpx;
  letter-spacing:1px;
  text-align: center;
}
.carNumbtn{
  width: 90%;
  height:90rpx;
  background:rgba(74,144,226,1);
  border-radius:45rpx;
  font-size:30rpx;
  font-family:PingFangSC-Semibold,PingFang SC;
  font-weight:600;
  color:rgba(255,255,255,1);
  line-height:90rpx;
  letter-spacing:2px;
  margin-top:60rpx;
}
.lichengBtn{
  position:fixed;bottom:62rpx;width:100%;background:#fff;height:100rpx;display: flex;justify-content: space-around;
}
.lichengBtn button{
  width:45%;
  float: left;
  box-sizing: border-box;
  text-align: center;
  line-height: 90rpx;
background:rgba(255,255,255,1);
border-radius:45px;
border:1px solid rgba(74,144,226,1);
font-size:30rpx;

}
.picker-box{
  width:70px;
  height: 70px;
  font-size:50rpx;
font-family:PingFang-SC-Heavy,PingFang-SC;
font-weight:800;
color:rgba(45,45,45,1);
}
.carNum text{
  line-height: 140rpx;
  color:rgba(133, 132, 136, 1);
}
//index.js
const app = getApp()

Page({
  data: {
    avatarUrl: './user-unlogin.png',
    userInfo: {},
    logged: false,
    takeSession: false,
    requestResult: '',
    // 車牌號
    arrProvience: ['京', '津', '冀', '晉', '蒙', '遼', '吉', '黑', '滬', '蘇', '浙', '皖', '閩', '贛', '魯', '豫', '鄂', '湘', '粵','桂', '瓊', '渝', '川', '貴', '雲', '藏', '陝', '甘', '青', '寧', '新'],
    arrNumber: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
    arrCaptainOne: ['Q', 'W', 'E', 'R', 'T', 'Y', 'U','I','O' ,'P'],
    arrCaptainTwo: ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'],
    arrCaptainThree: ['Z', 'X', 'C', 'V', 'B', 'N', 'M'],
    arrlicheng: [1,2,3],
    lichengOne:1,
    activeIndex: 0,
    choosedArr:new Array(7),
    carView:true,
    lichengView: false,
    isLicheng: false,
    wanUnitIndex: 0,
    qianUnitIndex: 0
  },
  // 車牌號開始
  addProvience(e){
    if (this.data.activeIndex == 1 && !isNaN(Number(e.currentTarget.dataset.value))){
      return
    }
    
    this.data.choosedArr[this.data.activeIndex] = e.currentTarget.dataset.value
    if (this.data.activeIndex < 6 ) {
      this.data.activeIndex = parseInt(this.data.activeIndex) + 1
      // if (!this.data.choosedArr[parseInt(this.data.activeIndex) + 1]){
        
      // }
    } 
    this.setData({
      choosedArr: this.data.choosedArr,
      activeIndex: this.data.activeIndex
    })
    
    console.log('選擇的車牌號', this.data.choosedArr)
  },
  activeNum(e){
    console.log(e.currentTarget.dataset.index)
    this.data.activeIndex = e.currentTarget.dataset.index
    this.setData({
      activeIndex: this.data.activeIndex
    })
  },
  cancel(){
    // 線判斷當前是否有選中操作的車牌號
    if(this.data.activeIndex == -1) return
    
    this.data.choosedArr[this.data.activeIndex] = ''
    if (this.data.activeIndex > 0) {
      this.data.activeIndex = parseInt(this.data.activeIndex) - 1
      // if (!this.data.choosedArr[parseInt(this.data.activeIndex) + 1]){

      // }
    }
    this.setData({
      choosedArr: this.data.choosedArr,
      activeIndex: this.data.activeIndex
    })
  },
  boardStop(){
    this.setData({
      activeIndex: -1
    })
  },
  wanChange(e){
    console.log(e)
    this.setData({
      wanUnitIndex: e.detail.value
    })
  },
  qianChange(e) {
    console.log(e)
    this.setData({
      qianUnitIndex: e.detail.value
    })
  },
  sure(){
    this.setData({
      carView: false,
      lichengView: true
    })
    let result = this.data.choosedArr.every((item) => {
      return item
    })
    if(result){
      console.log(this.data.choosedArr.join(''))
      // this.setData({
      //   carStr: this.data.choosedArr.join('')
      // })
    }
  },
  // 車牌號結束
  onLoad: function() {
   
  },

 

})

<view class="container">
  <view style="width: 100%;height: 100%;position: fixed;z-index: -1;" bindtap="boardStop"></view>
  <!-- 車牌號 -->
  <view wx:if="{{carView}}" style="width: 100%;">
    <view class="moduleTitle" style="">填寫車牌號</view>
    <view class="moduleTip">爲了給您提供更好的服務</view>
    <view class="moduleTip">請正確填寫您的車牌</view>
    <view class="carNum">
      <view wx:for="{{7}}" wx:for-index='index' data-index="{{index}}" class="{{index == activeIndex ? 'active' : ''}}" bindtap="activeNum">{{ choosedArr.length > 0 && choosedArr[index] ? choosedArr[index] : '' }}</view>
    </view>
    <view class="moduleTip" style="text-align: left;width:90%;margin-top:15rpx;">例如:京A88888</view>
    <text class="moduleTip" style="text-align: left;width:90%;color:rgba(255,56,61,1);font-size:24rpx;">*您填寫的車牌號有誤,請重新填寫</text>
    <button class="carNumbtn" bindtap="sure">確認</button>
    <view class="keyProvienceboard" hidden="{{activeIndex != 0 || activeIndex == -1}}">
      <view wx:for="{{arrProvience}}" data-value="{{item}}" bindtap="addProvience">{{item}}</view>
      <view style="flex-grow: 1" bindtap="cancel">
        <image src="../../images/back.png" mode="widthFix" style="width: 60rpx;"></image>
      </view>
    </view>
    <view class="keyboard" hidden="{{activeIndex == 0 || activeIndex == -1}}">
      <view class="key numKey">
        <view wx:for="{{arrNumber}}" data-value="{{item}}" bindtap="addProvience" style="{{activeIndex == 1 ? 'color:#cccccc':''}}">{{item}}</view>
      </view>
      <view class="key">
        <view wx:for="{{arrCaptainOne}}" data-value="{{item}}" bindtap="addProvience">{{item}}</view>
      </view>
      <view class="key">
        <view style="width:4%;border:none;visibility: hidden;"></view>
        <view wx:for="{{arrCaptainTwo}}" data-value="{{item}}" bindtap="addProvience">{{item}}</view>
        <view style="width:4%;border:none;visibility: hidden;"></view>
      </view>
      <view class="key" style="display: flex;justify-content: center;">
        <view wx:for="{{arrCaptainThree}}" data-value="{{item}}" bindtap="addProvience">{{item}}</view>
        <view style="width:20%;border:none;background:none;position:relative;" bindtap="cancel">
          <image src="../../images/back2x.png" mode="widthFix" style="width: 70%;position: absolute;margin: auto;top: 0;left: 0;right: 0;bottom: 0;"></image>
        </view>
      </view>

    </view>
  </view>
  <view wx:if="{{lichengView}}" style="width: 100%;">
    <view class="moduleTitle" style="">填寫行駛里程</view>
    <view class="moduleTip">門店可通過您的行駛里程</view>
    <view class="moduleTip">爲您推薦最佳保養方案</view>
    <view style="height:70px;width:90%;margin:50rpx auto 0 auto;display: flex;justify-content: space-around;">
      <picker-view 
      indicator-style="height: 70px;" style="width:70px;height:70px;float:left;"
      value="{{wanUnitIndex}}"
      bindchange="wanChange">
      <picker-view-column>
        <view wx:for="{{41}}" wx:key="{{item}}" style="width:70px;line-height: 70px;text-align:center;background:linear-gradient(180deg,rgba(238,238,238,1) 0%,rgba(216,216,216,1) 100%);">{{item}}</view>
      </picker-view-column>
 </picker-view>
 <text style="float:left;line-height:70px;padding:0 20rpx;">萬</text>
 <picker-view 
      indicator-style="height: 70px;" style="width:70px;height:70px;float:left;"
      value="{{qianUnitIndex}}"
      bindchange="qianChange">
      <picker-view-column>
        <view wx:for="{{10}}" wx:key="{{item}}" style="width:70px;line-height: 70px;text-align:center;background:linear-gradient(180deg,rgba(238,238,238,1) 0%,rgba(216,216,216,1) 100%);">{{item}}</view>
      </picker-view-column>
 </picker-view>
 <text style="float:left;line-height:70px;padding:0 20rpx;">千</text>
 <text style="color:rgba(45, 45, 45, 1);line-height:70px;">公里</text>
    </view>
    <text class="moduleTip" style="text-align: left;width:90%;color:rgba(255,56,61,1);font-size:24rpx;margin:0 auto;display:block;">*未選擇,請選擇後確定!</text>
     <view class="moduleTip" style="width:60%;margin:0 auto;margin-top:80rpx;font-size:30rpx;display:block;">如果您記不住詳細的行駛里程,可以選個大概的數字哦</view>
     <view class="lichengBtn" style="">
     <button style="color:rgba(74, 144, 226, 1);">忘記了</button>
     <button style="background:rgba(74,144,226,1);color:#fff;">確定</button>
     </view>

  </view>

</view>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章