1.分类页面代码
<template>
<view>
<!-- 自定义搜索组件 -->
<my-search @click="gotoSearch"></my-search>
<view class="scroll-view-container">
<!-- 左侧滑动区域 -->
<scroll-view class="left-scroll-view" scroll-y="true" :style="{height: windowHeight+'px'}" :scroll-top="scrollTop">
<block v-for="(item,i) in cateList" :key="i">
<view :class="['left-scroll-item',i===active?'active':'']" @click="activeChanged(i)">
{{item.cateName}}
</view>
</block>
</scroll-view>
<!-- 右侧滑动区域 -->
<scroll-view scroll-y="true" :style="{height: windowHeight+'px'}">
<view class="cate-lv2" v-for="(item2,i2) in cataLevel2" :key="i2">
<!-- 二级分类标题 -->
<view class="cate-lv2-title">/ {{item2.cateName}} /</view>
<!-- 二级分类下的三级分类 -->
<view class="cate-lv3-list">
<!-- 三级分类的item -->
<view class="cate-lv3-item" v-for="(item3,i3) in item2.children" :key="i3" @click="gotoGoodsList(item3)">
<!-- 三级分类的图片 -->
<image :src="item3.cataIcon"></image>
<!--三级分类的文本 -->
<text>{{item3.cateName}}</text>
</view>
</view>
</view>
</scroll-view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
windowHeight: 0,
cateList: [],
active: 0,
cataLevel2: [],
scrollTop:0
};
},
onLoad() {
const sysInfo = uni.getSystemInfoSync()
this.windowHeight = sysInfo.windowHeight-50
this.getCateList()
},
methods: {
getCateList() {
uni.request({
url: uni.$baseUrl + '/api/Cate/GetCateList',
})
.then((res) => {
if (res.data.code != 200) return uni.$showMsg();
this.cateList = res.data.data;
this.cataLevel2 = res.data.data[0].children
});
},
activeChanged(i) {
this.active = i
this.cataLevel2 = this.cateList[i].children
this.scrollTop=Math.random(0,1)
},
gotoGoodsList(item){
uni.navigateTo({
url:'/subpkg/goods_list/goods_list?id='+item
})
},
gotoSearch(){
uni.navigateTo({
url:'/subpkg/search/search'
})
}
}
}
</script>
<style lang="scss">
.scroll-view-container {
display: flex;
.left-scroll-view {
width: 120px;
.left-scroll-item {
background-color: #f7f7f7;
line-height: 60px;
text-align: center;
font-size: 14px;
&.active {
background-color: #ffffff;
position: relative;
&::before {
content: ' ';
display: block;
width: 3px;
height: 30px;
background-color: #c00000;
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
}
}
}
}
}
.cate-lv2-title {
font-size: 12px;
font-weight: bold;
text-align: center;
padding: 15px 0;
}
.cate-lv3-list {
display: flex;
flex-wrap: wrap;
.cate-lv3-item {
width: 33%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
image {
width: 60px;
height: 60px;
}
text {
font-size: 12px;
}
}
}
</style>
自定义搜索组件
<template>
<view @click="searchHandler" class="my-search-container" :style="{'background-color': bgcolor}">
<view class="my-search-box" :style="{'border-radius': radius+'px'}">
<uni-icons type="search" size="18"></uni-icons>
<text class="placeholder">搜索</text>
</view>
</view>
</template>
<script>
export default {
props:{
bgcolor:{
type:String,
default:'#55aaff'
},
radius:{
type:Number,
default:18
}
},
name: "my-search",
data() {
return {
};
},
methods:{
searchHandler(){
this.$emit('click')
}
}
}
</script>
<style lang="scss">
.my-search-container {
height: 50px;
display: flex;
align-items: center;
padding: 0 10px;
.my-search-box {
height: 36px;
background-color: #ffffff;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.placeholder {
font-size: 15px;
margin-left: 5px;
}
}
</style>
2.效果示例