赞
踩
<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) => {
// console.log(res.data.data);
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//px
}
},
name: "my-search",
data() {
return {
};
},
methods:{
searchHandler(){
this.$emit('click')
}
}
}
</script>
<style lang="scss">
.my-search-container {
height: 50px;
// background-color: #55aaff;
display: flex;
align-items: center;
padding: 0 10px;
.my-search-box {
height: 36px;
// border-radius: 18px;
background-color: #ffffff;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.placeholder {
font-size: 15px;
margin-left: 5px;
}
}
</style>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。