<template>
<view class="list-content">
<view class="tabs">
<view v-for="(item, index) in TabList" :key="index" class="tab-item"
:class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">
{{ item.name }}
</view>
</view>
<view class="list-item" v-for="(item,index) in TabList" :key="index" v-if="tabCurrentIndex === index">
<view class="item" v-for="(item,index) in itemList" :key="index">
<image :src="item.mainPic" mode="widthFix"></image>
<view class="content">
<view class="title">
{{item.title}}
</view>
<view class="data">
<view class="price">{{item.actualPrice}}</view>
<view class="coupons">券{{item.couponPrice}}元</view>
</view>
<view class="bottom">
<text class="yj">原价:{{item.originalPrice}}</text>
<text class="sold">已售:{{item.monthSales}}件</text>
</view>
<text class="btn">领券购买</text>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
itemList: [],
pageSize: 20,
pageId: 1,
TabList: [{
id: '',
name: '推荐'
},
{
id: '1',
name: '女装'
},
{
id: '2',
name: '母婴'
},
{
id: '3',
name: '美妆'
},
{
id: '4',
name: '居家日用'
},
{
id: '5',
name: '鞋品'
},
{
id: '6',
name: '美食'
},
{
id: '7',
name: '文娱车品'
},
{
id: '8',
name: '数码家电'
},
{
id: '9',
name: '男装'
},
{
id: '10',
name: '内衣'
},
{
id: '11',
name: '箱包'
},
{
id: '12',
name: '配饰'
},
{
id: '13',
name: '户外运动'
},
{
id: '14',
name: '家装家纺'
}
],
tabCurrentIndex: 0,
}
},
onLoad() {
this.getList();
},
methods: {
changeTab(e) {
this.tabCurrentIndex = e.target.current;
},
//顶部tab点击
tabClick(index) {
this.tabCurrentIndex = index;
this.itemList = []
this.getList(this.TabList[index].id)
},
getList(id) {
uni.showLoading({
title: '加载中',
mask: true
});
uni.request({
url: '',
method: 'GET',
data: {
cids: id,
pageSize: this.pageSize,
pageId: this.pageId
},
header: {
'content-type': 'application/json'
},
success: res => {
this.itemList = res.data.data.data.list;
setTimeout(function() {
uni.hideLoading();
}, 100);
},
});
}
}
}
</script>
<style lang="scss">
// tab切换
.tabs {
position: relative;
margin-top: 20rpx;
margin-left: 20rpx;
background: #ffff;
z-index: 9;
padding: 0 15px;
text-align: center;
height: 88rpx;
line-height: 88rpx;
display: flex;
flex-flow: row;
justify-content: space-between;
color: #fff;
font-size: 16px;
overflow-x: auto;
white-space: nowrap;
overflow-y: hidden;
}
.tab-item {
margin-right: 15px;
color: #999999;
font-size: 32rpx;
}
.tab-item.current {
color: #ff0036;
border-bottom: 4rpx solid #ff0036;
font-size: 32rpx;
font-weight: bold;
}
::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
color: transparent;
}
/*商品列表*/
.list-item {
position: relative;
padding: 20rpx;
}
.list-item .item {
background-color: #ffffff;
width: 47%;
margin-bottom: 20rpx;
margin-right: 20rpx;
float: left;
padding: 10rpx;
border-radius: 6rpx;
box-shadow: 0px 4px 8px #eeeeee;
overflow: hidden;
}
.list-item .item:nth-of-type(2n) {
margin-right: auto;
}
.list-item .item image {
width: 100%;
height: 340rpx;
border-radius: 6rpx;
}
.list-item .item .content .title {
font-size: 26rpx;
line-height: 1.6;
font-weight: 600;
color: #333;
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.list-item .item .content .title .icon {
position: relative;
top: 10rpx;
width: 38rpx;
height: 38rpx;
}
.list-item .item .content .data {
padding: 6rpx 0;
display: flex;
align-items: center;
justify-content: space-between;
}
.list-item .item .content .data .price {
color: #ea3724;
font-size: 28rpx;
font-weight: 600;
}
.list-item .item .content .coupons {
position: relative;
background-color: #f95008;
color: #fff;
font-size: 22rpx;
border-radius: 4rpx;
padding: 0 10rpx;
width: auto;
display: inline-block;
}
.list-item .item .content .bottom {
position: relative;
padding: 6rpx 0;
border-top: 1px solid #eee;
display: flex;
align-items: center;
justify-content: space-between;
}
.list-item .item .content .bottom .yj {
color: #666666;
font-size: 22rpx;
font-weight: 500;
width: auto;
display: inline-block;
text-decoration: line-through;
}
.list-item .item .content .bottom .sold {
color: #666666;
font-size: 22rpx;
font-weight: 500;
width: auto;
display: inline-block;
}
.list-item .item .content .btn {
background-color: #f95008;
color: #fff;
width: auto;
display: block;
text-align: center;
border-radius: 10rpx;
padding: 6rpx;
}
</style>
uniapp tab切换并发送请求
最新推荐文章于 2023-12-22 15:04:24 发布