2024-08-07 10:31:42 +08:00
|
|
|
|
<!-- 装修商品组件:商品卡片 -->
|
|
|
|
|
<template>
|
2024-10-29 11:14:45 +08:00
|
|
|
|
<!-- 商品卡片 -->
|
|
|
|
|
<view>
|
|
|
|
|
<view class="new-fenlei" v-if="fl">
|
2024-10-30 18:49:19 +08:00
|
|
|
|
<view class="list" :class="state.isShow == 'recommendNew' ? 'on' : ''" @click="classValue('recommendNew')">
|
2024-10-29 11:14:45 +08:00
|
|
|
|
<view class="t">首页新品</view>
|
|
|
|
|
<view class="b">最新出炉</view>
|
|
|
|
|
</view>
|
2024-10-30 18:49:19 +08:00
|
|
|
|
<view class="list" :class="state.isShow == 'recommendBest' ? 'on' : ''" @click="classValue('recommendBest')">
|
|
|
|
|
<view class="t">精品推荐</view>
|
|
|
|
|
<view class="b">猜你喜欢</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="list" :class="state.isShow == 'recommendHot' ? 'on' : ''" @click="classValue('recommendHot')">
|
|
|
|
|
<view class="t">热门榜单</view>
|
|
|
|
|
<view class="b">好评如云</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="list" :class="state.isShow == 'recommendGood' ? 'on' : ''" @click="classValue('recommendGood')">
|
|
|
|
|
<view class="t">促销单品</view>
|
|
|
|
|
<view class="b">多买多销</view>
|
2024-10-29 11:14:45 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<!-- 布局1. 单列大图(上图,下内容)-->
|
|
|
|
|
<view v-if="layoutType === LayoutTypeEnum.ONE_COL_BIG_IMG && state.goodsList.length" class="goods-sl-box">
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
<view class="goods-box" v-for="item in state.goodsList" :key="item.id"
|
|
|
|
|
:style="[{ marginBottom: data.space * 2 + 'rpx' }]">
|
|
|
|
|
<s-goods-column class="" size="sl" :goodsFields="data.fields" :tagStyle="data.badge" :data="item"
|
|
|
|
|
:titleColor="data.fields.name?.color" :subTitleColor="data.fields.introduction.color"
|
|
|
|
|
:topRadius="data.borderRadiusTop" :bottomRadius="data.borderRadiusBottom"
|
|
|
|
|
@click="sheep.$router.go('/pages/goods/index', { id: item.id })">
|
|
|
|
|
<!-- 购买按钮 -->
|
|
|
|
|
<template v-slot:cart>
|
|
|
|
|
<button class="ss-reset-button cart-btn" :style="[buyStyle]">
|
|
|
|
|
{{ btnBuy.type === 'text' ? btnBuy.text : '' }}
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</s-goods-column>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
<!-- 布局2. 双列(每一列:上图,下内容)-->
|
|
|
|
|
<view v-if="layoutType === LayoutTypeEnum.TWO_COL && state.goodsList.length"
|
|
|
|
|
class="goods-md-wrap ss-flex ss-flex-wrap ss-col-top">
|
|
|
|
|
<view class="goods-list-box">
|
|
|
|
|
<view class="left-list" :style="[{ paddingRight: data.space + 'rpx', marginBottom: data.space + 'px' }]"
|
2024-11-05 15:57:31 +08:00
|
|
|
|
v-for="item in state.leftGoodsList" :key="item.id">
|
|
|
|
|
<!-- <view class="left-list" :style="[{ paddingRight: data.space + 'rpx', marginBottom: data.space + 'px' }]"
|
|
|
|
|
v-for="item in state.goodsList" :key="item.id"> -->
|
2024-10-29 11:14:45 +08:00
|
|
|
|
<s-goods-column class="goods-md-box" size="md" :goodsFields="data.fields" :tagStyle="data.badge"
|
|
|
|
|
:data="item" :titleColor="data.fields.name?.color"
|
|
|
|
|
:subTitleColor="data.fields.introduction.color" :topRadius="data.borderRadiusTop"
|
|
|
|
|
:bottomRadius="data.borderRadiusBottom" :titleWidth="330 - marginLeft - marginRight"
|
|
|
|
|
@click="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
2024-11-05 15:57:31 +08:00
|
|
|
|
>
|
2024-10-29 11:14:45 +08:00
|
|
|
|
<!-- 购买按钮 -->
|
|
|
|
|
<template v-slot:cart>
|
|
|
|
|
<button class="ss-reset-button cart-btn" :style="[buyStyle]">
|
|
|
|
|
{{ btnBuy.type === 'text' ? btnBuy.text : '' }}
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</s-goods-column>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2024-11-05 15:57:31 +08:00
|
|
|
|
<view class="goods-list-box">
|
2024-10-29 11:14:45 +08:00
|
|
|
|
<view class="right-list" :style="[{ paddingLeft: data.space + 'rpx', marginBottom: data.space + 'px' }]"
|
|
|
|
|
v-for="item in state.rightGoodsList" :key="item.id">
|
|
|
|
|
<s-goods-column class="goods-md-box" size="md" :goodsFields="data.fields" :tagStyle="data.badge"
|
|
|
|
|
:data="item" :titleColor="data.fields.name?.color"
|
|
|
|
|
:subTitleColor="data.fields.introduction.color" :topRadius="data.borderRadiusTop"
|
|
|
|
|
:bottomRadius="data.borderRadiusBottom" :titleWidth="330 - marginLeft - marginRight"
|
|
|
|
|
@click="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
2024-11-05 15:57:31 +08:00
|
|
|
|
>
|
2024-10-29 11:14:45 +08:00
|
|
|
|
<template v-slot:cart>
|
|
|
|
|
<button class="ss-reset-button cart-btn" :style="[buyStyle]">
|
|
|
|
|
{{ btnBuy.type === 'text' ? btnBuy.text : '' }}
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</s-goods-column>
|
|
|
|
|
</view>
|
2024-11-05 15:57:31 +08:00
|
|
|
|
</view>
|
2024-10-29 11:14:45 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<!-- 布局3. 单列小图(左图,右内容) -->
|
|
|
|
|
<view v-if="layoutType === LayoutTypeEnum.ONE_COL_SMALL_IMG && state.goodsList.length" class="goods-lg-box">
|
|
|
|
|
<view class="goods-box" :style="[{ marginBottom: data.space + 'px' }]" v-for="item in state.goodsList"
|
|
|
|
|
:key="item.id">
|
|
|
|
|
<s-goods-column class="goods-card" size="lg" :goodsFields="data.fields" :data="item"
|
|
|
|
|
:tagStyle="data.badge" :titleColor="data.fields.name?.color"
|
|
|
|
|
:subTitleColor="data.fields.introduction.color" :topRadius="data.borderRadiusTop"
|
|
|
|
|
:bottomRadius="data.borderRadiusBottom"
|
|
|
|
|
@tap="sheep.$router.go('/pages/goods/index', { id: item.id })">
|
|
|
|
|
<!-- 购买按钮 -->
|
|
|
|
|
<template v-slot:cart>
|
|
|
|
|
<button class="ss-reset-button cart-btn" :style="[buyStyle]">
|
|
|
|
|
{{ btnBuy.type === 'text' ? btnBuy.text : '' }}
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</s-goods-column>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2024-08-07 10:31:42 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2024-10-30 18:49:19 +08:00
|
|
|
|
|
|
|
|
|
import request from '@/sheep/request';
|
|
|
|
|
import {
|
|
|
|
|
baseUrl,
|
|
|
|
|
apiPath
|
|
|
|
|
} from '@/sheep/config';
|
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
/**
|
|
|
|
|
* 商品卡片
|
|
|
|
|
*/
|
|
|
|
|
import {
|
|
|
|
|
computed,
|
|
|
|
|
reactive,
|
|
|
|
|
onMounted
|
|
|
|
|
} from 'vue';
|
|
|
|
|
import sheep from '@/sheep';
|
|
|
|
|
import SpuApi from '@/sheep/api/product/spu';
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
// 布局类型
|
|
|
|
|
const LayoutTypeEnum = {
|
|
|
|
|
// 单列大图
|
|
|
|
|
ONE_COL_BIG_IMG: 'oneColBigImg',
|
|
|
|
|
// 双列
|
|
|
|
|
TWO_COL: 'twoCol',
|
|
|
|
|
// 单列小图
|
|
|
|
|
ONE_COL_SMALL_IMG: 'oneColSmallImg',
|
|
|
|
|
};
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
const state = reactive({
|
|
|
|
|
goodsList: [],
|
|
|
|
|
leftGoodsList: [],
|
|
|
|
|
rightGoodsList: [],
|
2024-11-05 15:57:31 +08:00
|
|
|
|
isShow:'recommendNew',
|
|
|
|
|
count:0
|
2024-10-29 11:14:45 +08:00
|
|
|
|
});
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
data: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default () {},
|
|
|
|
|
},
|
|
|
|
|
styles: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default () {},
|
|
|
|
|
},
|
|
|
|
|
fl: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
const {
|
|
|
|
|
layoutType,
|
|
|
|
|
btnBuy,
|
|
|
|
|
spuIds
|
|
|
|
|
} = props.data ?? {};
|
|
|
|
|
const {
|
|
|
|
|
marginLeft,
|
|
|
|
|
marginRight
|
|
|
|
|
} = props.styles ?? {};
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
// 购买按钮样式
|
|
|
|
|
const buyStyle = computed(() => {
|
|
|
|
|
if (btnBuy.type === 'text') {
|
|
|
|
|
// 文字按钮:线性渐变背景颜色
|
|
|
|
|
return {
|
|
|
|
|
background: `linear-gradient(to right, ${btnBuy.bgBeginColor}, ${btnBuy.bgEndColor})`,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (btnBuy.type === 'img') {
|
|
|
|
|
// 图片按钮
|
|
|
|
|
return {
|
|
|
|
|
width: '54rpx',
|
|
|
|
|
height: '54rpx',
|
|
|
|
|
background: `url(${sheep.$url.cdn(btnBuy.imgUrl)}) no-repeat`,
|
|
|
|
|
backgroundSize: '100% 100%',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
//region 商品瀑布流布局
|
|
|
|
|
// 下一个要处理的商品索引
|
2024-11-05 15:57:31 +08:00
|
|
|
|
// let count = 0;
|
2024-10-29 11:14:45 +08:00
|
|
|
|
// 左列的高度
|
|
|
|
|
let leftHeight = 0;
|
|
|
|
|
// 右列的高度
|
|
|
|
|
let rightHeight = 0;
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
/**
|
|
|
|
|
* 计算商品在左列还是右列
|
|
|
|
|
* @param height 商品的高度
|
|
|
|
|
* @param where 添加到哪一列
|
|
|
|
|
*/
|
2024-11-05 15:57:31 +08:00
|
|
|
|
function calculateGoodsColumn() {
|
2024-10-29 11:14:45 +08:00
|
|
|
|
// 处理完
|
2024-11-05 15:57:31 +08:00
|
|
|
|
// if (!state.goodsList[state.count]) return;
|
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
// 增加列的高度
|
2024-11-05 15:57:31 +08:00
|
|
|
|
// if (where === 'left') leftHeight += height;
|
|
|
|
|
// if (where === 'right') rightHeight += height;
|
2024-10-29 11:14:45 +08:00
|
|
|
|
// 添加到矮的一列
|
2024-11-05 15:57:31 +08:00
|
|
|
|
if (state.count % 2 == 0) {
|
|
|
|
|
state.leftGoodsList.push(state.goodsList[state.count]);
|
2024-10-29 11:14:45 +08:00
|
|
|
|
} else {
|
2024-11-05 15:57:31 +08:00
|
|
|
|
state.rightGoodsList.push(state.goodsList[state.count]);
|
2024-10-29 11:14:45 +08:00
|
|
|
|
}
|
2024-11-05 15:57:31 +08:00
|
|
|
|
// console.log();
|
2024-10-29 11:14:45 +08:00
|
|
|
|
// 计数
|
2024-11-05 15:57:31 +08:00
|
|
|
|
state.count++;
|
2024-10-29 11:14:45 +08:00
|
|
|
|
}
|
|
|
|
|
//endregion
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
/**
|
|
|
|
|
* 根据商品编号列表,获取商品列表
|
|
|
|
|
* @param ids 商品编号列表
|
|
|
|
|
* @return {Promise<undefined>} 商品列表
|
|
|
|
|
*/
|
|
|
|
|
async function getGoodsListByIds(ids) {
|
|
|
|
|
const {
|
|
|
|
|
data
|
|
|
|
|
} = await SpuApi.getSpuListByIds(ids);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
2024-10-30 18:49:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 分类的数据
|
|
|
|
|
function classValue(val) {
|
|
|
|
|
state.isShow = val;
|
|
|
|
|
request({
|
|
|
|
|
url: `${baseUrl}${apiPath}/product/spu/getActivityGoods`,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
params: {
|
|
|
|
|
// projectdayId: this.brandId4,
|
|
|
|
|
// technicianId: this.brandId3
|
|
|
|
|
activityType:val
|
|
|
|
|
},
|
|
|
|
|
custom: {
|
|
|
|
|
showLoading: false,
|
|
|
|
|
},
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
// 分列
|
|
|
|
|
leftHeight = 0;
|
|
|
|
|
rightHeight = 0;
|
2024-11-05 15:57:31 +08:00
|
|
|
|
// state.goodsList = [];
|
2024-10-30 18:49:19 +08:00
|
|
|
|
state.goodsList = res.data;
|
2024-11-05 15:57:31 +08:00
|
|
|
|
|
|
|
|
|
state.count = 0
|
|
|
|
|
// console.log(state.goodsList,"-----state.goodsList")
|
2024-10-30 18:49:19 +08:00
|
|
|
|
state.leftGoodsList = []
|
|
|
|
|
state.rightGoodsList = []
|
2024-11-05 15:57:31 +08:00
|
|
|
|
// 重新计算商品列
|
|
|
|
|
res.data.forEach((item) => {
|
|
|
|
|
calculateGoodsColumn();
|
|
|
|
|
});
|
|
|
|
|
|
2024-10-30 18:49:19 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-10-29 11:14:45 +08:00
|
|
|
|
// 初始化
|
|
|
|
|
onMounted(async () => {
|
2024-10-30 18:49:19 +08:00
|
|
|
|
if(props.fl){
|
|
|
|
|
}
|
2024-10-29 11:14:45 +08:00
|
|
|
|
// 加载商品列表
|
2024-10-30 18:49:19 +08:00
|
|
|
|
if(!props.fl){
|
|
|
|
|
state.goodsList = await getGoodsListByIds(spuIds.join(','));
|
|
|
|
|
// 只有双列布局时需要
|
|
|
|
|
if (layoutType === LayoutTypeEnum.TWO_COL) {
|
|
|
|
|
// 分列
|
|
|
|
|
calculateGoodsColumn();
|
|
|
|
|
}
|
2024-11-05 15:57:31 +08:00
|
|
|
|
}else{
|
|
|
|
|
classValue("recommendNew");
|
2024-10-29 11:14:45 +08:00
|
|
|
|
}
|
2024-10-30 18:49:19 +08:00
|
|
|
|
|
|
|
|
|
|
2024-11-05 15:57:31 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
});
|
2024-08-07 10:31:42 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2024-10-29 11:14:45 +08:00
|
|
|
|
.new-fenlei {
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
margin:10px 0;
|
2024-10-30 18:49:19 +08:00
|
|
|
|
justify-content: space-around;
|
2024-10-29 11:14:45 +08:00
|
|
|
|
.list {
|
|
|
|
|
width: 24%;
|
|
|
|
|
&.on{
|
|
|
|
|
.t {
|
2024-11-07 13:02:39 +08:00
|
|
|
|
color: #e93422;
|
2024-10-29 11:14:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.b {
|
2024-11-07 13:02:39 +08:00
|
|
|
|
background: #e93422;
|
2024-10-29 11:14:45 +08:00
|
|
|
|
color:white;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.t {
|
|
|
|
|
text-align: center;
|
2024-10-30 18:49:19 +08:00
|
|
|
|
font-size: 16px;
|
2024-10-29 11:14:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.b {
|
|
|
|
|
// background: rgba(255, 102, 7);
|
|
|
|
|
text-align: center;
|
|
|
|
|
color: rgba(153,153,153);
|
|
|
|
|
border-radius: 15px;
|
|
|
|
|
width: 63%;
|
|
|
|
|
margin: 0 auto;
|
2024-10-30 18:49:19 +08:00
|
|
|
|
font-size: 12px;
|
2024-10-29 11:14:45 +08:00
|
|
|
|
margin-top:5px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-05 15:57:31 +08:00
|
|
|
|
// .goods-md-wrap {
|
|
|
|
|
// width: 100%;
|
|
|
|
|
// }
|
2024-10-29 11:14:45 +08:00
|
|
|
|
|
|
|
|
|
.goods-list-box {
|
2024-11-05 15:57:31 +08:00
|
|
|
|
width: 50%;
|
2024-10-29 11:14:45 +08:00
|
|
|
|
box-sizing: border-box;
|
2024-10-30 18:49:19 +08:00
|
|
|
|
::v-deep &{
|
2024-11-05 15:57:31 +08:00
|
|
|
|
.left-list, .right-list{
|
|
|
|
|
// width:48%;
|
2024-10-30 18:49:19 +08:00
|
|
|
|
}
|
|
|
|
|
.left-list:nth-child(3n+2){
|
|
|
|
|
margin-right:0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-29 11:14:45 +08:00
|
|
|
|
.left-list {
|
|
|
|
|
&:nth-last-child(1) {
|
|
|
|
|
margin-bottom: 0 !important;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
.right-list {
|
|
|
|
|
&:nth-last-child(1) {
|
|
|
|
|
margin-bottom: 0 !important;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
.goods-box {
|
|
|
|
|
&:nth-last-of-type(1) {
|
|
|
|
|
margin-bottom: 0 !important;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
.goods-md-box,
|
|
|
|
|
.goods-sl-box,
|
|
|
|
|
.goods-lg-box {
|
|
|
|
|
position: relative;
|
2024-08-07 10:31:42 +08:00
|
|
|
|
|
2024-10-29 11:14:45 +08:00
|
|
|
|
.cart-btn {
|
|
|
|
|
position: absolute;
|
|
|
|
|
bottom: 18rpx;
|
|
|
|
|
right: 20rpx;
|
|
|
|
|
z-index: 11;
|
|
|
|
|
height: 50rpx;
|
|
|
|
|
line-height: 50rpx;
|
|
|
|
|
padding: 0 20rpx;
|
|
|
|
|
border-radius: 25rpx;
|
|
|
|
|
font-size: 24rpx;
|
|
|
|
|
color: #fff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|