You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong_qianduan/pages/category/index.vue

250 lines
5.0 KiB

11 months ago
<template>
9 months ago
<view class="u-wrap">
<view class="u-search-box" @click="goSearch">
<view class="u-search-inner">
<u-icon name="search" color="#909399" :size="28"></u-icon>
<text class="u-search-text">搜索</text>
</view>
9 months ago
</view>
<view class="u-menu-wrap">
<scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view">
9 months ago
<view v-for="(item,index) in tabbar" :key="index" class="u-tab-item"
:class="[current == index ? 'u-tab-item-active' : '']" @tap.stop="swichMenu(index)">
9 months ago
<text class="u-line-1">{{item.name}}</text>
</view>
9 months ago
</scroll-view>
9 months ago
<scroll-view :scroll-top="scrollRightTop" scroll-y scroll-with-animation class="right-box"
@scroll="rightScroll">
9 months ago
<view class="page-view">
<view class="class-item">
<view class="item-box" v-for="(item1, index1) in tabbarList.children" :key="index1">
9 months ago
<view class="item-title">
<text>{{item1.name}}</text>
</view>
<view class="item-container">
9 months ago
<view class="thumb-box" @click="goodsDetail(item2)"
v-for="(item2, index2) in item1.children" :key="index2">
<image class="item-menu-image" :src="item2.image?item2.image.external_url:''"
mode=""></image>
9 months ago
<view class="item-menu-name">{{item2.name}}</view>
</view>
</view>
</view>
</view>
</view>
9 months ago
</scroll-view>
</view>
</view>
11 months ago
</template>
<script>
10 months ago
import * as cstegory from '@/api/category'
9 months ago
// import classifyData from '@/common/classify.data.js';
export default {
data() {
return {
9 months ago
current: 0, // 预设当前项的值
tabbar: [],
tabbarList: [],
scrollRightTop: 0,
9 months ago
oldScrollTop: 0,
}
},
9 months ago
onLoad() {
10 months ago
this.getGoodsTypeList();
9 months ago
},
onReady() {
this.getMenuItemTop()
10 months ago
},
methods: {
9 months ago
goodsDetail(item) {
console.log(item)
// 跳转商品详情
uni.navigateTo({
url: '/pages/goods/list?categoryId=' + item.category_id
9 months ago
})
},
9 months ago
goSearch() {
uni.navigateTo({
url: '/pages/search/index'
})
},
// 点击左边的栏目切换
async swichMenu(index) {
this.tabbarList = []
this.current = index;
9 months ago
this.scrollRightTop = this.oldScrollTop;
this.tabbarList = this.tabbar[index];
9 months ago
this.$nextTick(function() {
this.getMenuItemTop()
})
},
getGoodsTypeList() {
10 months ago
const that = this;
return new Promise((resolve, reject) => {
cstegory.list({
9 months ago
// is_hot: 0
})
10 months ago
.then(res => {
9 months ago
// 合并新数据
console.log(res, '分类数据')
9 months ago
that.tabbar = res.data.list;
that.tabbarList = res.data.list[0]
10 months ago
})
.catch(reject)
})
},
9 months ago
// 右边菜单滚动
async rightScroll(e) {
this.oldScrollTop = e.detail.scrollTop;
},
9 months ago
// 获取右边菜单每个item到顶部的距离
getMenuItemTop() {
9 months ago
let that = this
9 months ago
new Promise(resolve => {
let selectorQuery = uni.createSelectorQuery();
selectorQuery.selectAll('.class-item').boundingClientRect((rects) => {
rects.forEach((rect) => {
9 months ago
that.scrollRightTop = rect.top - rects[0].top
9 months ago
resolve();
})
}).exec()
10 months ago
})
},
}
}
11 months ago
</script>
9 months ago
11 months ago
<style lang="scss" scoped>
9 months ago
.u-wrap {
height: calc(100vh);
/* #ifdef H5 */
height: calc(100vh - var(--window-top));
/* #endif */
display: flex;
flex-direction: column;
}
9 months ago
.u-search-box {
padding: 18rpx 30rpx;
}
9 months ago
.u-menu-wrap {
flex: 1;
display: flex;
overflow: hidden;
}
9 months ago
.u-search-inner {
background-color: #ffffff;
border-radius: 100rpx;
display: flex;
align-items: center;
padding: 14rpx 16rpx;
}
9 months ago
.u-search-text {
font-size: 26rpx;
color: $u-tips-color;
margin-left: 10rpx;
}
9 months ago
.u-tab-view {
width: 200rpx;
height: 100%;
}
9 months ago
.u-tab-item {
height: 110rpx;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
font-size: 28rpx;
9 months ago
color: #444;
font-weight: 400;
line-height: 1;
}
9 months ago
.u-tab-item-active {
position: relative;
color: #F21A1C;
font-weight: 600;
// background: #fff;
9 months ago
}
9 months ago
// .u-tab-item-active::before {
// content: "";
// position: absolute;
// border-left: 4px solid #F21A1C;
// height: 32rpx;
// left: 0;
// top: 39rpx;
// }
9 months ago
.u-tab-view {
height: 100%;
}
9 months ago
.right-box {
background-color: rgb(250, 250, 250);
}
9 months ago
.page-view {
9 months ago
padding: 0 16rpx 16rpx;
overflow: hidden;
9 months ago
}
9 months ago
.class-item {
margin-bottom: 30rpx;
9 months ago
background-color: #fff;
padding: 20rpx;
9 months ago
border-radius: 8rpx;
}
9 months ago
.class-item:last-child {
min-height: 100vh;
}
9 months ago
.item-box {
9 months ago
margin-top: 30rpx;
9 months ago
&:first-child {
9 months ago
margin-top: 0;
}
}
9 months ago
9 months ago
.item-title {
font-size: 28rpx;
9 months ago
color: $u-main-color;
font-weight: bold;
padding: 10rpx;
9 months ago
}
9 months ago
.item-menu-name {
font-weight: normal;
font-size: 28rpx;
9 months ago
color: $u-main-color;
}
9 months ago
.item-container {
display: flex;
flex-wrap: wrap;
}
9 months ago
.thumb-box {
width: 33.333333%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
margin-top: 20rpx;
}
.item-menu-image {
width: 120rpx;
height: 120rpx;
margin-bottom: 10rpx;
}
9 months ago
</style>