<template>
<view>
<view class="search">
<view class="searchBox">
<navigator url="#">
<image src="../../static/image/search2.png" mode=""></image>
搜索全部
</navigator>
</view>
</view>
<view class="cate">
<view class="cateleft">
<scroll-view class="cateNameList" scroll-y="true"
:scroll-top="scrollTop"
scroll-with-animation>
<view class="cateNameItem"
:class="{cateActive:index==current}"
v-for="(item,index) in cate" :key="index"
@click="menuTab(index)"
>
{{item.catename}}
<view class="cateLine"></view>
</view>
</scroll-view>
</view>
<view class="cateright">
<scroll-view class="cateRightScroll"
scroll-y="true"
:scroll-into-view="'cate'+mainCurrent"
scroll-with-animation
@scroll="rightScroll"
>
<view class="cateItem"
v-for="(item,index) in cate" :key="index"
:id="'cate'+index"
>
<view class="caterightTitle">
——<text>{{item.catename}}</text>——
</view>
<view class="cateRightList">
<view class="cateRightItem"
v-for="(child,childindex) in item.product" :key="childindex">
<navigator hover-class="none" :url="'../detail/detail?id='+child.id">
<image :src="'http://api.intewl.cn/uploads/'+child.mainimage" mode=""></image>
<text>{{child.smalltitle}}</text>
</navigator>
</view>
</view>
</view>
<view style="height: 30rpx;width: 100%;"></view>
</scroll-view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
cate:[],
current:0,
rectInfo:[],
mainCurrent:0,
scrollTop:0
}
},
onLoad() {
this.getData()
},
mounted() {
setTimeout(()=>{
this.getRectInfo();
},200)
},
methods: {
getData(){
uni.request({
url:'http://api.intewl.cn/api/index/cate',
success:res=>{
this.cate=res.data.data
}
})
},
//滚动
rightScroll(e){
var scrollTop=e.detail.scrollTop;
var index;
for(var i=0;i<this.rectInfo.length;i++){
if(scrollTop>this.rectInfo[i].top&&scrollTop<this.rectInfo[i].bottom){
this.current=i
this.scrollTop=i*uni.upx2px(100);
}
}
},
//菜单选择
menuTab(index){
this.current=index
this.mainCurrent=index
this.scrollTop=index*uni.upx2px(100);
},
//获取矩形信息
getRectInfo(){
var top=0;
var bottom=0;
var temp=0;
for(var i=0;i<this.cate.length;i++){
let view = uni.createSelectorQuery().in(this).select("#cate"+i);
view.fields({
size: true,
rect: true
}, data => {
top=temp;
bottom=top+data.height
temp+=data.height;
this.rectInfo[i]={'top':top,"bottom":bottom}
}).exec();
}
}
}
}
</script>
<style>
page{background: #f7f7f7;}
.search{height: 110rpx;width: 100%;background: #fff;display: flex;
justify-content: center;align-items: center;}
.searchBox{width: 690rpx;height: 70rpx;border-radius: 10rpx;
font-size: 28rpx;color: #999;background: #f7f7f7;}
.searchBox navigator{display: flex;justify-content: center;align-items: center;
height: 70rpx;}
.searchBox image{width: 38rpx;height: 38rpx;margin-right: 12rpx;}
.cate{position: absolute;top:120rpx;bottom:0;width: 100%;
display: flex;}
.cateleft{width: 200rpx;background: #f7f7f7;height: 100%;}
.cateNameList{height: 100%;overflow: auto;}
.cateRightList{height: auto;overflow: hidden;}
.cateNameItem{font-size: 28rpx;color: #000;
line-height: 100rpx;text-align: center;position:relative}
.cateActive{background: #fff;}
.cateLine{position: absolute;width: 4rpx;height: 30rpx;background: #f7f7f7;
top:35rpx;}
.cateActive .cateLine{background: #10b6e8;}
.cateright{width:550rpx ;background: #fff;height: 100%;}
.cateRightScroll{height: 100%;overflow: auto;}
.caterightTitle{line-height: 86rpx;padding-top: 16rpx;color: #999;font-size: 28rpx;
text-align: center;}
.caterightTitle text{padding:0 30rpx}
.cateRightItem{width: 33.33%;float:left;margin-top:20rpx;}
.cateRightItem image{width: 160rpx;height: 160rpx;display: block;margin:0 auto;}
.cateRightItem text{line-height: 36rpx;font-size: 24rpx;
text-align: center;display: block;width: 100%;overflow: hidden;
text-overflow: ellipsis;white-space: nowrap;}
</style>
unapp左右联动
最新推荐文章于 2024-07-19 23:03:01 发布