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.
shengxian/pages/index/category/one-catgory.vue

318 lines
6.9 KiB

2 years ago
<template>
<view class="content_box">
2 years ago
<view style="display: flex;align-items: center;">
<view style="flex: 1;">
2 years ago
<!-- <block v-for="(item, index) in categoryData" :key="item.id"> -->
<!-- 滑动宫格v-if="item.type === 'menu'" -->
2 years ago
<sh-grid-swiper
2 years ago
:list="categoryData"
2 years ago
:oneRowNum="4"
2 years ago
:isIndex="false"
@catagory="catagoryClick"
2 years ago
:scroll="scroll"
></sh-grid-swiper>
2 years ago
<!-- </block> -->
2 years ago
</view>
<view @click="zhankai" :class="scroll?'zhankai':'zhankai active'">
<text>{{scroll?'展':"收"}}</text>
<text>{{scroll?'开':"起"}}</text>
</view>
</view>
2 years ago
<view class="u-flex u-col-center wrapper-box">
<view class="scroll-box" style="background-color: #F6F6F6;">
<scroll-view class="left u-flex-col u-col-center" enable-back-to-top scroll-y>
<view class="type-list u-ellipsis-1" :class="[{ 'list-active': listId == index }]" v-for="(item, index) in categoryData" :key="index" @tap="onType(index)">
<view class="line" :class="[{ 'line-active': listId == index }]"></view>
{{ item.name }}
</view>
<view class="hack-tabbar"></view>
</scroll-view>
</view>
<view style="height: 100%;width: 100%;">
<scroll-view @scrolltolower="loadMore" scroll-y class="scroll-box" enable-back-to-top scroll-with-animation>
<view class="right" v-if="categoryData.length">
<image class="type-img" v-if="categoryData[listId].image" :src="categoryData[listId].image" mode="aspectFill"></image>
<view class="item-list">
<view class="item-box u-flex">
<view
class="u-flex-col u-col-center goods-item"
@tap="jump('/pages/goods/detail', { id: goods.id })"
v-for="(goods, index1) in goodsList"
:key="goods.id"
>
<image class="item-img" lazy-load :src="goods.image" mode="aspectFill"></image>
<text class="item-title u-ellipsis-1 ">{{ goods.title }}</text>
<view class="item-price">{{ goods.price }}</view>
</view>
</view>
</view>
<!-- 缺省页 -->
<shopro-empty
v-if="isEmpty"
marginTop="200rpx"
:image="$IMG_URL + '/imgs/empty/empty_goods.png'"
tipText="暂无该商品,还有更多好货等着你噢~"
></shopro-empty>
<!-- 加载更多 -->
<u-loadmore v-if="!isEmpty" height="80rpx" :status="loadStatus" icon-type="flower" color="#ccc" />
<view class="hack-tabbar"></view>
</view>
</scroll-view>
</view>
</view>
</view>
</template>
<script>
import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
2 years ago
import shGridSwiper from './item.vue';
2 years ago
export default {
2 years ago
components: {shGridSwiper},
2 years ago
data() {
return {
2 years ago
scroll:true,
2 years ago
listId: 0,
2 years ago
categoryData: [],
2 years ago
categoryID: 0, //分类id
isEmpty: false,
currentPage: 1,
lastPage: 1,
loadStatus: 'loadmore', //loadmore-加载前的状态,loading-加载中的状态,nomore-没有更多的状态
goodsList: [] //商品数据
};
},
props: {
categoryStyleId: {
//分类样式ID
type: Number,
default: 0
}
},
2 years ago
computed: {
...mapGetters(['initShop', 'homeTemplate', 'hasTemplate', 'isLogin']),
},
2 years ago
created() {
console.log('%c当前分类:一级分类', 'color:green;background:yellow');
this.getCategory();
},
methods: {
2 years ago
catagoryClick(i){
let index = this.categoryData.findIndex(item=>{
return item.name==i.name
})
this.onType(index)
},
2 years ago
zhankai(){
this.scroll=!this.scroll
},
2 years ago
// 获取分类
getCategory() {
this.$http('category.detail', {
id: this.categoryStyleId
}).then(res => {
if (res.code === 1) {
this.categoryData = res.data.children;
this.categoryID = res.data.children[0].id;
this.getGoodsList();
}
});
},
// 获取分类商品
getGoodsList() {
let that = this;
that.$http('goods.lists', {
category_id: that.categoryID,
page: that.currentPage
}, '加载中...').then(res => {
if (res.code === 1) {
that.goodsList = [...that.goodsList, ...res.data.data];
that.isEmpty = !that.goodsList.length;
that.lastPage = res.data.last_page;
that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
}
});
},
// 商品底部
loadMore() {
if (this.currentPage < this.lastPage) {
this.currentPage += 1;
this.getGoodsList();
}
},
onType(index) {
2 years ago
console.log(index,typeof(index))
2 years ago
this.listId = index;
this.categoryID = this.categoryData[index].id;
this.goodsList = [];
this.currentPage = 1;
this.getGoodsList();
},
// 路由跳转
jump(path, parmas) {
this.$Router.push({
path: path,
query: parmas
});
}
}
};
</script>
<style lang="scss">
.hack-tabbar {
height: calc(100rpx + env(safe-area-inset-bottom) / 2);
width: 100%;
}
.content_box {
margin-top: 1upx;
display: flex;
flex-direction: column;
overflow: hidden;
height: 100%;
}
.wrapper-box {
flex: 1;
margin-top: 1upx;
2 years ago
// height: 100%;
height: calc(100% - 280rpx);
2 years ago
}
.scroll-box {
height: 100%;
flex: 1;
background: #fff;
}
.left {
width: 200upx;
height: 100%;
flex: 1;
.list-active {
background: #fff;
2 years ago
color: #222222 !important;
// font-weight: bold !important;
2 years ago
}
.line-active {
2 years ago
// background: #e6b873;
2 years ago
}
.type-list {
2 years ago
height: 120upx;
2 years ago
position: relative;
width: 200rpx;
padding-left: 16rpx;
2 years ago
line-height: 120rpx;
2 years ago
font-size: 28upx;
font-weight: 400;
2 years ago
color: #666666;
2 years ago
.line {
width: 10upx;
height: 100%;
position: absolute;
left: 0;
}
}
}
.right {
padding: 0 30upx;
flex: 1;
height: 100%;
.type-img {
width: 505rpx;
height: 150rpx;
background: #ccc;
margin: 20rpx 0;
border-radius: 10rpx;
}
.item-list {
.type-box {
height: 84rpx;
.type-title {
font-size: 28rpx;
font-weight: bold;
}
.more {
font-size: 26rpx;
color: #999;
}
}
.item-box {
flex-wrap: wrap;
width: 504rpx;
.goods-item {
margin-right: 12rpx;
margin-bottom: 12rpx;
background: #ffffff;
box-shadow: 0px 0px 20rpx 4rpx rgba(199, 199, 199, 0.22);
border-radius: 10rpx;
&:nth-child(2n) {
margin-right: 0;
}
.item-img {
width: 245rpx;
height: 246rpx;
border-radius: 10rpx 10rpx 0px 0px;
background: #f5f5f5;
}
.item-title {
font-size: 24rpx;
line-height: 24rpx;
margin-top: 10rpx;
width: 200rpx;
text-align: left;
margin: 20rpx;
}
.item-price {
font-size: 28rpx;
font-weight: 500;
color: #ff3000;
text-align: left;
width: 200rpx;
margin: 0 20rpx 20rpx;
&::before {
content: '¥';
font-size: 22rpx;
}
}
}
}
}
}
2 years ago
.grid-text {
font-size: 28rpx;
margin-top: 4rpx;
color: $u-type-info;
}
.zhankai{
background:#fff;
display: flex;flex-direction: column;
justify-content: space-around;align-items: center;
2 years ago
padding:0 40rpx;
2 years ago
box-shadow: -2px 0px 8px 0px rgba(31,32,14,0.05);
2 years ago
height: 100%;
margin-top: -16rpx;
2 years ago
}
.active{
height:380rpx;
margin-top: -10rpx;
}
2 years ago
</style>