2021-05-13 11:03:32 +08:00
|
|
|
<template>
|
|
|
|
<div class="layout">
|
2021-12-13 17:16:12 +08:00
|
|
|
<u-sticky>
|
2021-09-01 17:30:54 +08:00
|
|
|
<div class="goods-cell-title">
|
2022-10-19 11:56:42 +08:00
|
|
|
<div
|
|
|
|
class="goods-item-title"
|
|
|
|
:class="{ 'selected-title': selected.index == index }"
|
|
|
|
@click="handleClickTitle(title, index)"
|
|
|
|
v-for="(title, index) in res.list[0].titleWay"
|
|
|
|
:key="index"
|
|
|
|
>
|
2021-09-01 17:30:54 +08:00
|
|
|
<h4 class="h4">{{ title.title }}</h4>
|
|
|
|
<div>{{ title.desc }}</div>
|
|
|
|
</div>
|
2021-05-13 11:03:32 +08:00
|
|
|
</div>
|
2021-09-01 17:30:54 +08:00
|
|
|
</u-sticky>
|
2021-05-13 11:03:32 +08:00
|
|
|
<div class="goods-list">
|
2022-10-19 11:56:42 +08:00
|
|
|
<div
|
|
|
|
v-if="
|
|
|
|
item.___index != undefined
|
|
|
|
? selected.index == item.___index
|
|
|
|
: selected.val == item.type
|
|
|
|
"
|
|
|
|
@click="handleClick(item)"
|
|
|
|
class="goods-item"
|
|
|
|
v-for="(item, item_index) in res.list[0].listWay"
|
|
|
|
:key="item_index"
|
|
|
|
>
|
2021-05-13 11:03:32 +08:00
|
|
|
<div class="goods-img">
|
2022-10-19 11:56:42 +08:00
|
|
|
<u-image
|
|
|
|
:src="item.img"
|
|
|
|
height="350rpx"
|
|
|
|
mode="aspectFit"
|
|
|
|
width="100%"
|
|
|
|
>
|
2021-05-24 15:49:22 +08:00
|
|
|
<u-loading slot="loading"></u-loading>
|
|
|
|
</u-image>
|
2021-05-13 11:03:32 +08:00
|
|
|
</div>
|
|
|
|
<div class="goods-desc">
|
|
|
|
<div class="goods-title">
|
2021-12-13 17:17:02 +08:00
|
|
|
{{ item.title }}
|
2021-05-13 11:03:32 +08:00
|
|
|
</div>
|
|
|
|
<div class="goods-bottom">
|
2022-10-19 11:56:42 +08:00
|
|
|
<div class="goods-price">
|
|
|
|
¥<span
|
|
|
|
>{{ $options.filters.goodsFormatPrice(item.price)[0] }} </span
|
|
|
|
>.{{ $options.filters.goodsFormatPrice(item.price)[1] }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div
|
|
|
|
v-if="res.list[0].titleWay[selected.index].bindCategory && goodsData.length"
|
|
|
|
v-for="(item, index) in goodsData"
|
|
|
|
:key="index"
|
|
|
|
class="goods-item"
|
|
|
|
@click="handleClick(item)"
|
|
|
|
>
|
|
|
|
<div class="goods-img">
|
|
|
|
<u-image
|
|
|
|
:src="item.thumbnail"
|
|
|
|
height="350rpx"
|
|
|
|
mode="aspectFit"
|
|
|
|
width="100%"
|
|
|
|
>
|
|
|
|
<u-loading slot="loading"></u-loading>
|
|
|
|
</u-image>
|
|
|
|
</div>
|
|
|
|
<div class="goods-desc">
|
|
|
|
<div class="goods-title">
|
|
|
|
{{ item.goodsName }}
|
|
|
|
</div>
|
|
|
|
<div class="goods-bottom">
|
|
|
|
<div class="goods-price">
|
|
|
|
¥<span
|
|
|
|
>{{ $options.filters.goodsFormatPrice(item.price)[0] }} </span
|
|
|
|
>.{{ $options.filters.goodsFormatPrice(item.price)[1] }}
|
|
|
|
</div>
|
2021-05-13 11:03:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2022-10-19 11:56:42 +08:00
|
|
|
import { getGoodsList } from "@/api/goods.js";
|
2021-05-13 11:03:32 +08:00
|
|
|
export default {
|
2021-05-24 15:49:22 +08:00
|
|
|
title: "商品分类以及商品",
|
2021-05-13 11:03:32 +08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selected: {
|
|
|
|
index: 0,
|
2021-08-16 11:34:15 +08:00
|
|
|
val: "",
|
2021-05-13 11:03:32 +08:00
|
|
|
},
|
2022-10-19 11:56:42 +08:00
|
|
|
params: {
|
|
|
|
pageNumber: 1,
|
|
|
|
pageSize: 100,
|
|
|
|
categoryId: "",
|
|
|
|
},
|
|
|
|
goodsData: [], //商品循环内容
|
|
|
|
goodsResult:"", //es总返回内容
|
2021-05-13 11:03:32 +08:00
|
|
|
};
|
|
|
|
},
|
2022-10-19 11:56:42 +08:00
|
|
|
props: ["res","enableBottomLoad"],
|
2021-08-16 11:34:15 +08:00
|
|
|
watch: {
|
|
|
|
res: {
|
|
|
|
handler(val) {
|
|
|
|
// 监听父级的值 如果有值将值赋给selected
|
|
|
|
if (val) {
|
2022-10-19 11:56:42 +08:00
|
|
|
console.log(val)
|
|
|
|
// 如果第一个标签页绑定为商品
|
|
|
|
this.selected.val = this.res.list[0].listWay[0] ? this.res.list[0].listWay[0].type: '';
|
|
|
|
// 如果第一个标签为绑定为分类
|
|
|
|
this.res.list[0].titleWay[0].bindCategory ? this.initGoods(this.res.list[0].titleWay[0]) : ''
|
2021-08-16 11:34:15 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
immediate: true,
|
|
|
|
},
|
|
|
|
},
|
2022-10-19 11:56:42 +08:00
|
|
|
mounted() {
|
|
|
|
uni.$on('onReachBottom',()=>{
|
|
|
|
if(this.enableBottomLoad && this.goodsResult.totalElements >= this.params.pageNumber * this.params.pageSize){
|
|
|
|
this.params.pageNumber++
|
|
|
|
this.initGoods(this.res.list[0].titleWay[this.selected.index])
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
},
|
|
|
|
destroyed(){
|
|
|
|
uni.$off('onReachBottom')
|
|
|
|
},
|
2021-05-13 11:03:32 +08:00
|
|
|
methods: {
|
|
|
|
handleClick(item) {
|
2022-09-15 15:40:50 +08:00
|
|
|
uni.navigateTo({
|
2021-05-13 11:03:32 +08:00
|
|
|
url: `/pages/product/goods?id=${item.id}&goodsId=${item.goodsId}`,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
closeGoods(val, index) {
|
|
|
|
this.res.list[0].listWay.splice(index, 1);
|
|
|
|
},
|
2022-10-19 11:56:42 +08:00
|
|
|
async initGoods(val) {
|
|
|
|
if(this.enableBottomLoad) this.params.pageSize = 20
|
|
|
|
val ? this.params.categoryId = val.bindCategory.id : '';
|
|
|
|
const res = await getGoodsList(this.params);
|
|
|
|
if (res.data.success) {
|
|
|
|
this.goodsResult = res.data.result
|
2023-04-28 10:21:36 +08:00
|
|
|
const result = res.data.result.records
|
2022-10-19 11:56:42 +08:00
|
|
|
this.goodsData.push(...result);
|
|
|
|
console.log(this.goodsData)
|
|
|
|
}
|
|
|
|
},
|
2021-05-13 11:03:32 +08:00
|
|
|
handleClickTitle(val, index) {
|
|
|
|
this.selected.index = index;
|
|
|
|
this.selected.val = val.title;
|
2022-10-19 11:56:42 +08:00
|
|
|
if (val.bindCategory) {
|
|
|
|
this.params.pageNumber = 1
|
|
|
|
this.goodsData = []
|
|
|
|
this.initGoods(val);
|
|
|
|
}
|
2021-05-13 11:03:32 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
$w_94: 94%;
|
|
|
|
|
|
|
|
.layout {
|
|
|
|
padding: 8px 0;
|
|
|
|
background: #f9f9f9;
|
|
|
|
}
|
|
|
|
|
|
|
|
.selected-title {
|
|
|
|
> h4 {
|
|
|
|
font-size: 30rpx;
|
|
|
|
color: #000 !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
> div {
|
|
|
|
font-weight: bold;
|
|
|
|
color: $main-color !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.goods-cell-title {
|
2021-09-01 17:30:54 +08:00
|
|
|
background: #f9f9f9;
|
2021-05-13 11:03:32 +08:00
|
|
|
padding: 10px;
|
|
|
|
transition: 0.35s;
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
> .goods-item-title {
|
|
|
|
flex: 1;
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> h4 {
|
|
|
|
font-size: 32rpx;
|
|
|
|
}
|
|
|
|
|
|
|
|
> div {
|
|
|
|
color: #999;
|
|
|
|
font-size: 24rpx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.goods-list {
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
.goods-item {
|
|
|
|
width: 50%;
|
|
|
|
margin-bottom: 10px;
|
|
|
|
border-radius: 0.4em;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.goods-img {
|
|
|
|
position: relative;
|
|
|
|
margin: 0 auto;
|
|
|
|
// width: 158px;
|
|
|
|
width: $w_94;
|
|
|
|
border-top-left-radius: 20rpx;
|
|
|
|
border-top-right-radius: 20rpx;
|
|
|
|
overflow: hidden;
|
|
|
|
> img {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.goods-desc {
|
|
|
|
border-bottom-left-radius: 20rpx;
|
|
|
|
border-bottom-right-radius: 20rpx;
|
|
|
|
width: $w_94;
|
|
|
|
background: #fff;
|
|
|
|
padding: 8rpx 0 8rpx 8rpx;
|
|
|
|
margin: 0 auto;
|
|
|
|
> .goods-title {
|
|
|
|
font-size: 24rpx;
|
2022-10-19 11:56:42 +08:00
|
|
|
height: 67rpx;
|
2021-05-13 11:03:32 +08:00
|
|
|
display: -webkit-box;
|
|
|
|
font-weight: 500;
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
-webkit-line-clamp: 2;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .goods-bottom {
|
|
|
|
display: flex;
|
|
|
|
font-weight: bold;
|
|
|
|
> .goods-price {
|
|
|
|
line-height: 2;
|
|
|
|
color: $main-color;
|
2022-10-19 11:56:42 +08:00
|
|
|
> span {
|
2022-09-15 15:40:50 +08:00
|
|
|
font-size: 42rpx;
|
|
|
|
}
|
2021-05-13 11:03:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|