小程序tab选项卡切换及picker的添加

 wxml文件:

  <!-- tab切换卡 -->
  <view class="like-tab {{menuFixed ? 'menu-bar fixed' : 'menu-bar'}}">
      <block wx:for="{{changeTabList}}" wx:for-index="index" wx:for-item="item" wx:key="index">
          
          <view class="{{curTabIdx == index ? 'tab current' : 'tab'}}" data-index="{{index}}" bindtap="changeTab" >
            {{item.id == 4 ? '' : item.value}}
              <picker wx:if="{{item.id == 4}}"
              bindchange="bindPickerPriceChange" value="{{pickerPriceIndex}}" range="{{pickerPrice}}" range-key="value">
              <view class="picker">
                价格:{{pickerPrice[pickerPriceIndex].value}}
              </view>
            </picker>
          </view>
          <image bindtap="showSearch" class="icon-search" src="/image/icon_search.png"></image>
           
      </block>
  </view>

wxss文件

/* 切换卡 */
.like-tab {
    padding: 14rpx 0;
    margin-bottom: 14rpx;
    font-size: 24rpx;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    padding: 30rpx;
    position: relative;
}

.like-tab .tab {
  position: relative;
    display: inline-block;
    min-width: 120rpx;
    height: 50rpx;
    line-height: 50rpx;
    text-align: center;
    background-color: #1F1F1F;
    color: #999;
    border-radius: 25rpx
}
.like-tab .tab.current {
    background-color: #2D2D2D;
    color: white
}
.like-tab .icon-search {
  width: 40rpx;
  height: 40rpx;
  position: absolute;
  right: 5%;
  top: 50%;
  transform: translate(0, -50%);
}

js文件

data: {
    curTabIdx: 0,
    curTabId:1,
    changeTabList:[
      { value: "全部", id: 1 },
      { value: "特卖", id: 2 },
      { value: "热度", id: 3 },
      { value: "新品", id: 1 },
      { value: "价格", id: 4 },
    ],
    pickerPrice: [{ value: '降序', id: 4 }, { value: '升序', id: 5 }],
    pickerPriceIndex: 0,
  },
changeTab(e) {
    if (e.currentTarget.dataset.index == this.data.curTabIdx) return
    this.setData({
      curTabIdx: e.currentTarget.dataset.index,
    })
    this.setData({
      curTabId: this.data.changeTabList[this.data.curTabIdx].id
    })
    console.log('curTabId:' + this.data.curTabId)
  },
  bindPickerPriceChange(e){
    this.setData({
      pickerPriceIndex: e.detail.value,
      curTabId: this.data.pickerPrice[parseInt(e.detail.value)].id,
      curTabIdx: 4,
    })
    console.log(this.data.curTabId)
  },

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值