综合,销量,价格

发布时间 2023-10-21 23:59:58作者: 樱花馆长
"tabs":"/components/tabs/tabs"

<tabs array="{{arr}}" bindmyevent="onMyEvent"></tabs> <view class="goodscontent"> <navigator wx:for="{{goods}}" class="goods_item"> <view class="left"> <image src="{{item.goods_small_logo?item.goods_small_logo:'https://image2.suning.cn/uimg/b2c/newcatentries/0070078057-000000000634917020_1_400x400.jpg'}}" mode="widthFix"></image> </view> <view class="right"> <view class="goods_name">{{item.goods_name}}</view> <view class="goods_price">¥{{item.goods_price}}</view> </view> </navigator> </view>
Page({
  data: {
    arr: ["综合", "销量", "价格"],
    goods: []
.goods_item{
  display: flex;
}
.left{
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}
.right{
  flex: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.left image{
  width: 60%;
}
.goods_name{
  font-size: 28rpx;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.goods_price{
  font-size: 30rpx;
  color: red;
}

 


  },
  onLoad: function(options) {
    this.getgoodslist(0);
  },
  onMyEvent(e) {
    console.log(e); 
    let index = e.detail; 
    this.getgoodslist(index); 
  },
  getgoodslist(num) {
    let that = this; 
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/goods/search',
      data: {
        pagesize: 20,
        pagenum: num + 1 
      },
      success(res) { 
        console.log(res); 
        that.setData({
          goods: res.data.message.goods
        });
      }
    });
  }
});