小程序软键盘 添加删除数字

1.将软键盘绑定data-id 将获取的data-id的值

2.获取到我要出价的值,将拿到的值和data-id进行拼接

3.

  <!--出价软键盘-->
        <view class="mark" hidden="{{hidden}}" bindtap="bindMark"></view>
        <view class="Bid_list" hidden='{{hidden}}'>
            <view class="Lead">
                <view><span>领先价</span><span class="Lead_price">{{lead_price}}元</span></view>
                <view class="close">x</view>
            </view>
            <view class="shuru">
                <span class="bid">我要出价</span>
                <view id="view">{{new_price}}</view>
            </view>
            <view class="offer_price" bindtap='bindGoPrice' data-id='{{product_info.product_id}}'>出价</view>
            <view class="Explain">出价即表示同意《随手拍竞拍服务协议》</view>
            <view class="layer-content" style="bottom: 0px;">
                <view class="form_edit clearfix">
                    <view class="num" bindtap="bindNumber" data-id="1">1</view>
                    <view class="num" bindtap="bindNumber" data-id="2">2</view>
                    <view class="num" bindtap="bindNumber" data-id="3">3</view>
                    <view class="num" bindtap="bindNumber" data-id="4">4</view>
                    <view class="num" bindtap="bindNumber" data-id="5">5</view>
                    <view class="num" bindtap="bindNumber" data-id="6">6</view>
                    <view class="num" bindtap="bindNumber" data-id="7">7</view>
                    <view class="num" bindtap="bindNumber" data-id="8">8</view>
                    <view class="num" bindtap="bindNumber" data-id="9">9</view>
                    <view class="num" bindtap="bindNumber" data-id=".">.</view>
                    <view class="num" bindtap="bindNumber" data-id="0">0</view>
                    <view id="remove" bindtap='bindRemove'>删除</view>
                </view>
            </view>

        </view>
/*软键盘*/
.mark {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
}
.form_edit {
    width: 100%;
    background: #D1D4DD;
}

.form_edit > view {
    margin-bottom: 2px;
    margin-right: 0.5%;
    float: left;
    width: 33%;
    height: 45px;
    text-align: center;
    color: #333;
    line-height: 45px;
    font-size: 18px;
    font-weight: 600;
    background-color: #fff;
    border-radius: 5px;
}

.form_edit > view:nth-child(3n) {
    margin-right: 0;
}

.form_edit > view:last-child {
    background-color: #DEE1E9;
}


.Bid_list {
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
    display: block;
    background-color: #f3f3f3;
}
.shuru {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}
.offer_price {
    background-color: #085556;
    position: relative;
    width: 90%;
    margin: auto;
    height: 40px;
    line-height: 40px;
    color: #fff;
    font-size: 16px;
    text-align: center;
    border-radius: 4px;
}
.Explain {
    text-align: right;
    font-size: 12px;
    padding: 10px 20px;
}
.bid {
    width: 20%;
    text-align: center;
    background: #085556;
    color: white;
    height: 40px;
    line-height: 40px;
}
#view {
    flex: 1;
    height: 40px;
    line-height: 40px;
    background: white;
    color: #576b95;
    font-size: 18px;
    /* margin-left: 10px; */
    padding-left: 10px;
}
.Lead {
    display: flex;
    justify-content: space-between;
    padding: 10px;
}
.Lead_price {
    color: #576b95;
    font-size: 18px;
    margin-left: 10px;
}
.mask {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
}
.close {
    width: 30px;
    text-align: center;
}


data:{
lead_price:'',//当前出价
      new_price:'',//领先价
      hidden:true,//软键盘显示状态
},

 //  点击软键盘
  bindNumber:function(event){
    var value = event.currentTarget.dataset.id;//软键盘的值
    var new_price = this.data.new_price.toString();//将数字转换为字符串
    var str = new_price.split('');//在将字符串转换成数组
    str.push(value);//将点击的值添加进数组中
    this.data.new_price = str.join("");//再将数组装换为字符串
    this.setData({
      new_price: this.data.new_price
    })
  },
 // 删除软键盘数字
  bindRemove:function(){
    var new_price = this.data.new_price.toString();//同上
    var str = new_price.split('');
    str.splice(str.length-1,1);
    this.data.new_price = str.join("")
    this.setData({
      new_price: this.data.new_price
    })
  },
  // 遮罩层
  bindMark:function(){
    this.setData({
      hidden: true
    })
  },
发布了69 篇原创文章 · 获赞 17 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/Acitylion/article/details/90757207