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.
shop-app/pages/goods/category.vue

224 lines
5.2 KiB

3 years ago
<template>
<view class="container">
<!-- 搜索框 -->
3 years ago
<UiPageHeader :back="false" class="search">
<u--input slot="custom" class="search--input" prefixIconStyle="font-size:48rpx;color:#ccc"
3 years ago
prefixIcon="search" placeholderClass="search--input__placeholder" clearable
placeholder="请输入您想要搜索的商品名称"
@focus="$Router.push('/search')"/>
</UiPageHeader>
<view class="cate-content" v-if="categoryData.length > 0">
3 years ago
<!-- 左侧 一级分类 -->
<scroll-view class="cate-left" :scroll-y="true">
<text class="type-nav" :class="{ selected: curIndex == index }"
3 years ago
v-for="(item, index) in categoryData" @click="handleSelectNav(index)"
3 years ago
:key="index" >{{ item.name }}</text>
</scroll-view>
<!-- 右侧 二级分类 -->
3 years ago
<scroll-view class="cate-right" @scrolltolower="reachBottom" :scroll-top="scrollTop" :scroll-y="true">
3 years ago
<image class="cate-tow-img" src="@/static/goods/category_banner.jpg"></image>
3 years ago
<!-- <view @click="onTargetGoodsList(item.id)"> -->
<view class="cate-tow-group" :class="idx === categoryData[curIndex].children.length - 1 ? 'cate-tow-group__last' :''"
v-for="(item, idx) in categoryData[curIndex].children" :key="idx">
<text class="cate-tow-group--title">{{item.name}}</text>
<view class="cate-tow-group--item" v-for="i in item.productList" :key="i.id"
@click="$Router.push(`/goodsDetail?id=${i.id}`)">
<image class="cate-tow-group--img" mode="scaleToFill"
:src="i.mainPicture"></image>
<text class="cate-tow-group--name">{{i.name}}</text>
3 years ago
</view>
</view>
3 years ago
<!-- </view> -->
<BsEmpty class="empty" v-if="!categoryData[curIndex].children.length && !categoryData[curIndex].isLoading"
:icon="require('@/static/common/empty_goods.png')" />
3 years ago
<u-loadmore status="loading" v-if="categoryData[curIndex].isLoading" />
3 years ago
</scroll-view>
</view>
3 years ago
<BsEmpty v-if="!categoryData.length && !isLoading" />
<u-loadmore status="loading" v-if="isLoading" />
3 years ago
</view>
</template>
<script>
3 years ago
import {ApiGetCategoryOneList, ApiGetCategoryTwoAndGoods} from '@/common/api/goods';
3 years ago
import BsEmpty from "@/components/BsEmpty";
3 years ago
import UiPageHeader from '../../components/UiPageHeader.vue';
3 years ago
export default {
3 years ago
components: { BsEmpty, UiPageHeader },
3 years ago
data() {
return {
// 一级分类:指针
curIndex: 0,
// 内容区竖向滚动条位置
scrollTop: 0,
// 分类列表
3 years ago
categoryData: [],
3 years ago
// 正在加载中
isLoading: true,
};
},
onLoad() {
// 加载页面数据
3 years ago
this.getCategoryData();
3 years ago
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
3 years ago
// this.getCategoryData();
3 years ago
},
methods: {
// 一级分类:选中分类
handleSelectNav(index) {
this.curIndex = index;
this.scrollTop = 0;
},
3 years ago
reachBottom(){
if(this.curIndex >= this.categoryData.length){
return false
}
this.handleSelectNav(this.curIndex+1);
},
3 years ago
/**
3 years ago
* 获取分类数据
3 years ago
*/
3 years ago
async getCategoryData() {
3 years ago
this.isLoading = true;
// 初始化分类列表数据
3 years ago
const {error, result } = await ApiGetCategoryOneList();
this.categoryData = result.map((item) => {
item.children = [];
item.isLoading = true;
this.getTwoCategoryData(item);
return item;
});
3 years ago
this.isLoading = false;
},
/**
* 初始化分类列表数据
* @param {Object} result
*/
3 years ago
async getTwoCategoryData(item) {
const {error, result} = await ApiGetCategoryTwoAndGoods({categoryId : item.id});
this.$set(item, 'children', result);
this.$set(item, 'isLoading', false);
}
3 years ago
},
};
</script>
<style lang="scss">
3 years ago
page {
background: $color-grey0;
3 years ago
}
</style>
<style lang="scss" scoped>
3 years ago
.search{
padding: 0 30rpx;
background: $color-grey0;
3 years ago
}
.search--input{
display: block;
height: 70rpx;
border:none;
box-sizing: border-box;
background: $color-grey1;
3 years ago
&__placeholder{
font-size: $font-size-base;
color: $color-grey5;
3 years ago
}
}
3 years ago
.cate-content {
background: $color-grey0;
height: calc(100vh - 180rpx);
3 years ago
display: flex;
}
.cate-left {
width: 190rpx;
color: #444;
height: 100%;
background: $color-grey1;
3 years ago
}
.cate-right {
height: 100%;
padding: 30rpx 0 0;
3 years ago
overflow: hidden;
3 years ago
box-sizing: border-box;
3 years ago
}
.type-nav {
display: block;
width: 190rpx;
height: 100rpx;
line-height: 100rpx;
font-size: $font-size-base;
3 years ago
text-align: center;
color: $color-grey4;
3 years ago
}
.type-nav.selected {
background: $color-grey0;
color: $color-yellow3;
font-size: $font-size-base;
font-weight: bold;
3 years ago
}
.cate-tow-img{
width:480rpx;
margin: 0 40rpx 20rpx;
3 years ago
height: 164rpx;
background: $color-grey3;
3 years ago
border-radius: 16rpx;
}
.cate-tow-group{
display: flex;
flex-wrap: wrap;
// margin-bottom: 20rpx;
3 years ago
&--title{
padding: 20rpx 40rpx;
display: block;
width: 100%;
font-size: 30rpx;
line-height: 30rpx;
font-weight: bold;
color: $color-grey6;
3 years ago
}
&--item{
margin-left: 40rpx;
}
&--img{
display: block;
width: 130rpx;
height: 130rpx;
}
&--name{
display: block;
3 years ago
width: 130rpx;
3 years ago
text-align: center;
font-size: $font-size-sm;
line-height: 30rpx;
margin: 14rpx 0 20rpx;
color: $color-grey6;
3 years ago
display: -webkit-box;
/*! autoprefixer: off */
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
&__last{
padding-bottom: 200rpx;
3 years ago
}
}
.empty{
margin-top: 100rpx;
}
3 years ago
</style>