shop_uniapp/components/cate-home/cate-home.vue

137 lines
3.3 KiB
Vue

<template>
<view class="cate-home">
<mescroll-uni :ref="'mescrollRef'+i" bg-color="#f4f4f4" :top="positionTop" @init="mescrollInit" bottom="50px" :safearea="true"
@down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
<view class="content">
<view style="margin: 0 30rpx">
<cate-nav :list="navList"></cate-nav>
</view>
<view class="contain" v-if="hotGoods.length">
<active-area :list="hotGoods" type="double" title="品类热销" :price-type="category_price_type"></active-area>
</view>
<view class="contain" v-if="newGoods.length">
<active-area :list="newGoods" type="new" title="品类推荐" :price-type="category_price_type"></active-area>
</view>
<view class="goods">
<image src="https://zjeloong.oss-cn-hangzhou.aliyuncs.com/uniapp/category_title.png" class="title-img"></image>
<goods-list type="double" :list="goodsList" :price-type="price_type"></goods-list>
</view>
</view>
</mescroll-uni>
</view>
</template>
<script>
import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
import {
getGoodsList,
getListByLevelOne,
getIndexCategory
} from "@/api/store"
const app = getApp()
export default {
mixins: [MescrollMixin, MescrollMoreItemMixin],
name: "cate-home",
props: {
top: {
type: [Number, String]
},
cate: {
type: Object,
default: () => ({})
}
},
data() {
return {
goodsList: [],
navList: [],
hotGoods: [],
newGoods: [],
downOption: {
auto: false
},
upOption: {
auto: false,
noMoreSize: 1,
empty: {
icon: 'https://zjeloong.oss-cn-hangzhou.aliyuncs.com/uniapp/goods_null.png',
tip: '暂无商品~',
}
},
price_type: 0,
category_price_type: 0
};
},
computed: {
positionTop() {
return this.top
}
},
methods: {
async downCallback() {
await this.getIndexCategory()
this.mescroll.resetUpScroll();
},
upCallback(page) {
let pageNum = page.num;
let pageSize = page.size;
getGoodsList({
page_size: pageSize,
page_no: pageNum,
platform_cate_id: this.cate.id,
p_id: this.$store.getters.hasPid,
set: this.$store.getters.hasSetId
}).then(({
data
}) => {
this.price_type = data.set_price_type;
let curPageData = data.lists;
let curPageLen = curPageData.length;
let hasNext = !!data.more;
if (page.num == 1) this.goodsList = [];
this.goodsList = this.goodsList.concat(curPageData);
this.mescroll.endSuccess(curPageLen, hasNext);
})
},
async getIndexCategory() {
const {
id
} = this.cate
const {
code,
data
} = await getIndexCategory({
platform_category_id: id,
p_id: this.$store.getters.hasPid,
set: this.$store.getters.hasSetId
})
if (code == 1) {
const {level_two, category_hots, category_recommend} = data
this.category_price_type = data.set_price_type;
this.navList = level_two
this.hotGoods = category_hots
this.newGoods = category_recommend
}
}
}
}
</script>
<style lang="scss">
.cate-home {
border-radius: 20rpx 20rpx 0 0;
overflow: hidden;
.contain {
padding: 20rpx 30rpx 0;
}
.title-img {
width: 100%;
height: 120rpx;
}
}
</style>