mall-uniapp/pages/goods_cate/goods_cate.vue

256 lines
6.3 KiB
Vue
Raw Permalink Normal View History

2020-08-13 08:12:57 +00:00
<template>
<view class='productSort'>
2023-06-23 15:53:53 +00:00
<!-- 商品搜索 -->
2020-08-13 08:12:57 +00:00
<view class='header acea-row row-center-wrapper'>
<view class='acea-row row-between-wrapper input'>
<text class='iconfont icon-sousuo'></text>
2023-06-23 15:53:53 +00:00
<input type='text' placeholder='点击搜索商品信息' @confirm="searchSubmitValue" confirm-type='search'
name="search" placeholder-class='placeholder' />
2020-08-13 08:12:57 +00:00
</view>
</view>
2023-06-23 15:53:53 +00:00
<!-- 商品分类 -->
<view class='aside' :style="{bottom: tabbarH + 'px',height: height + 'rpx'}">
<scroll-view scroll-y="true" scroll-with-animation='true' style="height: 100%;">
<view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""' v-for="(item,index) in productList"
2020-08-13 08:12:57 +00:00
:key="index" @click='tap(index,"b"+index)'><text>{{item.name}}</text></view>
</scroll-view>
2020-08-13 08:12:57 +00:00
</view>
2023-06-23 15:53:53 +00:00
<!-- 商品分类 -->
2020-08-13 08:12:57 +00:00
<view class='conter'>
<scroll-view scroll-y="true" :scroll-into-view="toView" :style='"height:"+height+"rpx;margin-top: 96rpx;"' @scroll="scroll"
2020-08-13 08:12:57 +00:00
scroll-with-animation='true'>
<block v-for="(item,index) in productList" :key="index">
<view class='listw' :id="'b'+index">
<view class='title acea-row row-center-wrapper'>
2023-06-23 15:53:53 +00:00
<view class='line' />
<view class='name'>{{ item.name }}</view>
<view class='line' />
2020-08-13 08:12:57 +00:00
</view>
<view class='list acea-row'>
2023-06-23 15:53:53 +00:00
<block v-for="(itemn,indexn) in item.children" :key="indexn">
2020-08-13 08:12:57 +00:00
<navigator hover-class='none' :url='"/pages/goods_list/index?cid="+itemn.id+"&title="+itemn.name' class='item acea-row row-column row-middle'>
2023-06-23 15:53:53 +00:00
<view class='picture' :style="{'background-color':itemn.picUrl?'none':'#f7f7f7'}">
<image :src='itemn.picUrl' />
2020-08-13 08:12:57 +00:00
</view>
<view class='name line1'>{{itemn.name}}</view>
</navigator>
</block>
</view>
</view>
</block>
2023-06-23 15:53:53 +00:00
<view :style='"height:"+(height-300)+"rpx;"' v-if="number < 15" />
2020-08-13 08:12:57 +00:00
</scroll-view>
</view>
</view>
</template>
<script>
2023-06-23 15:53:53 +00:00
import * as CategoryApi from '@/api/product/category.js';
import * as Util from '@/utils/util.js';
export default {
2020-08-13 08:12:57 +00:00
data() {
return {
navlist: [],
2023-06-23 15:53:53 +00:00
productList: [], // 商品分类,树形结构
2020-08-13 08:12:57 +00:00
navActive: 0,
number: "",
height: 0,
hightArr: [],
toView: "",
tabbarH: 0
2020-08-13 08:12:57 +00:00
}
},
onLoad(options) {
this.getAllCategory();
},
methods: {
infoScroll: function() {
2023-06-23 15:53:53 +00:00
let len = this.productList.length;
let child = this.productList[len - 1] && this.productList[len - 1].child ? this.productList[len - 1].child : [];
this.number = child ? child.length:0;
// 设置商品列表高度
let that = this;
uni.getSystemInfo({
2020-08-13 08:12:57 +00:00
success: function(res) {
2023-06-23 15:53:53 +00:00
that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
2020-08-13 08:12:57 +00:00
},
});
let hightArr = [];
for (let i = 0; i < len; i++) {
2023-06-23 15:53:53 +00:00
// 获取元素所在位置
2020-08-13 08:12:57 +00:00
let query = uni.createSelectorQuery().in(this);
let idView = "#b" + i;
query.select(idView).boundingClientRect();
query.exec(function(res) {
let top = res[0].top;
hightArr.push(top);
that.hightArr = hightArr
});
2023-06-23 15:53:53 +00:00
}
2020-08-13 08:12:57 +00:00
},
tap: function(index, id) {
this.toView = id;
this.navActive = index;
},
getAllCategory: function() {
2023-06-23 15:53:53 +00:00
CategoryApi.getCategoryList().then(res => {
this.productList = Util.handleTree(res.data);
setTimeout(() => {
this.infoScroll();
},500)
2020-08-13 08:12:57 +00:00
})
},
scroll: function(e) {
let scrollTop = e.detail.scrollTop;
let scrollArr = this.hightArr;
for (let i = 0; i < scrollArr.length; i++) {
if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
this.navActive = 0
} else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[0]) {
this.navActive = i
} else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
this.navActive = scrollArr.length - 1
}
}
},
searchSubmitValue: function(e) {
2023-06-23 15:53:53 +00:00
if (this.$util.trim(e.detail.value).length > 0) {
uni.navigateTo({
url: '/pages/goods_list/index?searchValue=' + e.detail.value
})
} else {
return this.$util.Tips({
title: '请填写要搜索的产品信息'
});
}
}
2020-08-13 08:12:57 +00:00
}
}
</script>
<style scoped lang="scss">
.productSort .header {
width: 100%;
height: 96rpx;
background-color: #fff;
position: fixed;
left: 0;
right: 0;
top: 0;
z-index: 9;
border-bottom: 1rpx solid #f5f5f5;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .header .input {
width: 700rpx;
height: 60rpx;
background-color: #f5f5f5;
border-radius: 50rpx;
box-sizing: border-box;
padding: 0 25rpx;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .header .input .iconfont {
font-size: 26rpx;
2020-08-13 08:12:57 +00:00
color: #555;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .header .input .placeholder {
color: #999;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .header .input input {
font-size: 26rpx;
height: 100%;
width: 597rpx;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .aside {
position: fixed;
width: 180rpx;
2020-08-13 08:12:57 +00:00
left: 0;
top:0;
2020-08-13 08:12:57 +00:00
background-color: #f7f7f7;
overflow-y: scroll;
2020-08-13 08:12:57 +00:00
overflow-x: hidden;
2023-06-23 15:53:53 +00:00
height: auto;
2020-08-13 08:12:57 +00:00
margin-top: 96rpx;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .aside .item {
height: 100rpx;
width: 100%;
font-size: 26rpx;
color: #424242;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .aside .item.on {
background-color: #fff;
border-left: 4rpx solid #fc4141;
width: 100%;
text-align: center;
color: #fc4141;
font-weight: bold;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter {
margin: 96rpx 0 0 180rpx;
padding: 0 14rpx;
background-color: #fff;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter .listw {
padding-top: 20rpx;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter .listw .title {
height: 90rpx;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter .listw .title .line {
width: 100rpx;
height: 2rpx;
background-color: #f0f0f0;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter .listw .title .name {
font-size: 28rpx;
color: #333;
margin: 0 30rpx;
font-weight: bold;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter .list {
flex-wrap: wrap;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter .list .item {
width: 177rpx;
margin-top: 26rpx;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter .list .item .picture {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter .list .item .picture image {
width: 100%;
height: 100%;
border-radius: 50%;
div{
background-color: #f7f7f7;
}
2020-08-13 08:12:57 +00:00
}
2023-06-23 15:53:53 +00:00
2020-08-13 08:12:57 +00:00
.productSort .conter .list .item .name {
font-size: 24rpx;
color: #333;
height: 56rpx;
line-height: 56rpx;
width: 120rpx;
text-align: center;
}
</style>