|
@@ -1,104 +1,166 @@
|
|
|
|
+<!-- 装修商品组件:【积分商城】商品卡片 -->
|
|
<template>
|
|
<template>
|
|
|
|
+ <!-- 商品卡片 -->
|
|
<view>
|
|
<view>
|
|
|
|
+ <!-- 布局1. 单列大图(上图,下内容)-->
|
|
<view
|
|
<view
|
|
- v-if="mode === 1 && state.scoreList.length"
|
|
|
|
|
|
+ v-if="layoutType === LayoutTypeEnum.ONE_COL_BIG_IMG && state.spuList.length"
|
|
|
|
+ class="goods-sl-box"
|
|
|
|
+ >
|
|
|
|
+ <view
|
|
|
|
+ class="goods-box"
|
|
|
|
+ v-for="item in state.spuList"
|
|
|
|
+ :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/point', { id: item.activityId })"
|
|
|
|
+ >
|
|
|
|
+ <!-- 购买按钮 -->
|
|
|
|
+ <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>
|
|
|
|
+
|
|
|
|
+ <!-- 布局2. 单列小图(左图,右内容) -->
|
|
|
|
+ <view
|
|
|
|
+ v-if="layoutType === LayoutTypeEnum.ONE_COL_SMALL_IMG && state.spuList.length"
|
|
|
|
+ class="goods-lg-box"
|
|
|
|
+ >
|
|
|
|
+ <view
|
|
|
|
+ class="goods-box"
|
|
|
|
+ :style="[{ marginBottom: data.space + 'px' }]"
|
|
|
|
+ v-for="item in state.spuList"
|
|
|
|
+ :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/point', { id: item.activityId })"
|
|
|
|
+ >
|
|
|
|
+ <!-- 购买按钮 -->
|
|
|
|
+ <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>
|
|
|
|
+
|
|
|
|
+ <!-- 布局3. 双列(每一列:上图,下内容)-->
|
|
|
|
+ <view
|
|
|
|
+ v-if="layoutType === LayoutTypeEnum.TWO_COL && state.spuList.length"
|
|
class="goods-md-wrap ss-flex ss-flex-wrap ss-col-top"
|
|
class="goods-md-wrap ss-flex ss-flex-wrap ss-col-top"
|
|
>
|
|
>
|
|
<view class="goods-list-box">
|
|
<view class="goods-list-box">
|
|
<view
|
|
<view
|
|
class="left-list"
|
|
class="left-list"
|
|
:style="[{ paddingRight: data.space + 'rpx', marginBottom: data.space + 'px' }]"
|
|
:style="[{ paddingRight: data.space + 'rpx', marginBottom: data.space + 'px' }]"
|
|
- v-for="item in state.leftScoreList"
|
|
|
|
|
|
+ v-for="item in state.leftSpuList"
|
|
:key="item.id"
|
|
:key="item.id"
|
|
>
|
|
>
|
|
- <s-point-card
|
|
|
|
|
|
+ <s-goods-column
|
|
class="goods-md-box"
|
|
class="goods-md-box"
|
|
size="md"
|
|
size="md"
|
|
- :goodsFields="goodsFields"
|
|
|
|
|
|
+ :goodsFields="data.fields"
|
|
|
|
+ :tagStyle="data.badge"
|
|
:data="item"
|
|
:data="item"
|
|
- :titleColor="goodsFields.title?.color"
|
|
|
|
- :subTitleColor="goodsFields.subtitle.color"
|
|
|
|
|
|
+ :titleColor="data.fields.name?.color"
|
|
|
|
+ :subTitleColor="data.fields.introduction.color"
|
|
:topRadius="data.borderRadiusTop"
|
|
:topRadius="data.borderRadiusTop"
|
|
:bottomRadius="data.borderRadiusBottom"
|
|
:bottomRadius="data.borderRadiusBottom"
|
|
:titleWidth="330 - marginLeft - marginRight"
|
|
:titleWidth="330 - marginLeft - marginRight"
|
|
- @click="sheep.$router.go('/pages/goods/score', { id: item.id })"
|
|
|
|
- @getHeight="mountMasonry($event, 'left')"
|
|
|
|
|
|
+ @click="sheep.$router.go('/pages/goods/seckill', { id: item.activityId })"
|
|
|
|
+ @getHeight="calculateGoodsColumn($event, 'left')"
|
|
>
|
|
>
|
|
|
|
+ <!-- 购买按钮 -->
|
|
<template v-slot:cart>
|
|
<template v-slot:cart>
|
|
<button class="ss-reset-button cart-btn" :style="[buyStyle]">
|
|
<button class="ss-reset-button cart-btn" :style="[buyStyle]">
|
|
- {{ buyNowStyle.mode === 1 ? buyNowStyle.text : '' }}
|
|
|
|
|
|
+ {{ btnBuy.type === 'text' ? btnBuy.text : '' }}
|
|
</button>
|
|
</button>
|
|
</template>
|
|
</template>
|
|
- </s-point-card>
|
|
|
|
|
|
+ </s-goods-column>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="goods-list-box">
|
|
<view class="goods-list-box">
|
|
<view
|
|
<view
|
|
class="right-list"
|
|
class="right-list"
|
|
:style="[{ paddingLeft: data.space + 'rpx', marginBottom: data.space + 'px' }]"
|
|
:style="[{ paddingLeft: data.space + 'rpx', marginBottom: data.space + 'px' }]"
|
|
- v-for="item in state.rightScoreList"
|
|
|
|
|
|
+ v-for="item in state.rightSpuList"
|
|
:key="item.id"
|
|
:key="item.id"
|
|
>
|
|
>
|
|
- <s-score-card
|
|
|
|
|
|
+ <s-goods-column
|
|
class="goods-md-box"
|
|
class="goods-md-box"
|
|
size="md"
|
|
size="md"
|
|
- :goodsFields="goodsFields"
|
|
|
|
|
|
+ :goodsFields="data.fields"
|
|
|
|
+ :tagStyle="data.badge"
|
|
:data="item"
|
|
:data="item"
|
|
- :titleColor="goodsFields.title?.color"
|
|
|
|
- :subTitleColor="goodsFields.subtitle.color"
|
|
|
|
|
|
+ :titleColor="data.fields.name?.color"
|
|
|
|
+ :subTitleColor="data.fields.introduction.color"
|
|
:topRadius="data.borderRadiusTop"
|
|
:topRadius="data.borderRadiusTop"
|
|
:bottomRadius="data.borderRadiusBottom"
|
|
:bottomRadius="data.borderRadiusBottom"
|
|
:titleWidth="330 - marginLeft - marginRight"
|
|
:titleWidth="330 - marginLeft - marginRight"
|
|
- @click="sheep.$router.go('/pages/goods/score', { id: item.id })"
|
|
|
|
- @getHeight="mountMasonry($event, 'right')"
|
|
|
|
|
|
+ @click="sheep.$router.go('/pages/goods/seckill', { id: item.activityId })"
|
|
|
|
+ @getHeight="calculateGoodsColumn($event, 'right')"
|
|
>
|
|
>
|
|
|
|
+ <!-- 购买按钮 -->
|
|
<template v-slot:cart>
|
|
<template v-slot:cart>
|
|
<button class="ss-reset-button cart-btn" :style="[buyStyle]">
|
|
<button class="ss-reset-button cart-btn" :style="[buyStyle]">
|
|
- {{ buyNowStyle.mode === 1 ? buyNowStyle.text : '' }}
|
|
|
|
|
|
+ {{ btnBuy.type === 'text' ? btnBuy.text : '' }}
|
|
</button>
|
|
</button>
|
|
</template>
|
|
</template>
|
|
- </s-score-card>
|
|
|
|
|
|
+ </s-goods-column>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
-
|
|
|
|
- <!-- <view class="goods-hack" v-if="state.scoreList.length % 2 == 1" style="width: 345rpx"></view> -->
|
|
|
|
- </view>
|
|
|
|
- <view v-if="mode === 2 && state.scoreList.length" class="goods-lg-box">
|
|
|
|
- <view
|
|
|
|
- class="goods-box"
|
|
|
|
- :style="[{ marginBottom: data.space + 'px' }]"
|
|
|
|
- v-for="item in state.scoreList"
|
|
|
|
- :key="item.id"
|
|
|
|
- >
|
|
|
|
- <s-score-card
|
|
|
|
- class="goods-card"
|
|
|
|
- size="lg"
|
|
|
|
- :goodsFields="goodsFields"
|
|
|
|
- :data="item"
|
|
|
|
- :titleColor="goodsFields.title?.color"
|
|
|
|
- :subTitleColor="goodsFields.subtitle.color"
|
|
|
|
- :topRadius="data.borderRadiusTop"
|
|
|
|
- :bottomRadius="data.borderRadiusBottom"
|
|
|
|
- @tap="sheep.$router.go('/pages/goods/score', { id: item.id })"
|
|
|
|
- >
|
|
|
|
- <template v-slot:cart>
|
|
|
|
- <button class="ss-reset-button cart-btn" :style="[buyStyle]">
|
|
|
|
- {{ buyNowStyle.mode === 1 ? buyNowStyle.text : '' }}
|
|
|
|
- </button>
|
|
|
|
- </template>
|
|
|
|
- </s-score-card>
|
|
|
|
- </view>
|
|
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
</template>
|
|
|
|
+
|
|
<script setup>
|
|
<script setup>
|
|
- import { computed, reactive, onMounted } from 'vue';
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 商品卡片
|
|
|
|
+ */
|
|
|
|
+ import { computed, onMounted, reactive, ref } from 'vue';
|
|
import sheep from '@/sheep';
|
|
import sheep from '@/sheep';
|
|
|
|
+ import SpuApi from '@/sheep/api/product/spu';
|
|
|
|
+ import PointApi from '@/sheep/api/promotion/point';
|
|
|
|
+ import { PromotionActivityTypeEnum } from '@/sheep/util/const';
|
|
|
|
+
|
|
|
|
+ // 布局类型
|
|
|
|
+ const LayoutTypeEnum = {
|
|
|
|
+ // 单列大图
|
|
|
|
+ ONE_COL_BIG_IMG: 'oneColBigImg',
|
|
|
|
+ // 双列
|
|
|
|
+ TWO_COL: 'twoCol',
|
|
|
|
+ // 单列小图
|
|
|
|
+ ONE_COL_SMALL_IMG: 'oneColSmallImg',
|
|
|
|
+ };
|
|
|
|
|
|
const state = reactive({
|
|
const state = reactive({
|
|
- scoreList: [],
|
|
|
|
- leftScoreList: [],
|
|
|
|
- rightScoreList: [],
|
|
|
|
|
|
+ spuList: [],
|
|
|
|
+ leftSpuList: [],
|
|
|
|
+ rightSpuList: [],
|
|
});
|
|
});
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
data: {
|
|
data: {
|
|
@@ -110,56 +172,113 @@
|
|
default() {},
|
|
default() {},
|
|
},
|
|
},
|
|
});
|
|
});
|
|
- const { mode, buyNowStyle, goodsFields, goodsIds } = props.data ?? {};
|
|
|
|
- const { marginLeft, marginRight } = props.styles ?? {};
|
|
|
|
- async function getScoreListByIds(ids) {
|
|
|
|
- let { data } = await sheep.$api.app.scoreShop.ids({ ids });
|
|
|
|
- return data;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- onMounted(async () => {
|
|
|
|
- state.scoreList = await getScoreListByIds(goodsIds.join(','));
|
|
|
|
- if (mode === 1) {
|
|
|
|
- mountMasonry();
|
|
|
|
|
|
+ const { layoutType, btnBuy, activityIds } = props.data || {};
|
|
|
|
+ const { marginLeft, marginRight } = props.styles || {};
|
|
|
|
+
|
|
|
|
+ // 购买按钮样式
|
|
|
|
+ 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%',
|
|
|
|
+ };
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- // 加载瀑布流
|
|
|
|
|
|
+ //region 商品瀑布流布局
|
|
|
|
+ // 下一个要处理的商品索引
|
|
let count = 0;
|
|
let count = 0;
|
|
|
|
+ // 左列的高度
|
|
let leftHeight = 0;
|
|
let leftHeight = 0;
|
|
|
|
+ // 右列的高度
|
|
let rightHeight = 0;
|
|
let rightHeight = 0;
|
|
|
|
|
|
- function mountMasonry(height = 0, where = 'left') {
|
|
|
|
- if (!state.scoreList[count]) return;
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 计算商品在左列还是右列
|
|
|
|
+ * @param height 商品的高度
|
|
|
|
+ * @param where 添加到哪一列
|
|
|
|
+ */
|
|
|
|
+ function calculateGoodsColumn(height = 0, where = 'left') {
|
|
|
|
+ // 处理完
|
|
|
|
+ if (!state.spuList[count]) return;
|
|
|
|
+ // 增加列的高度
|
|
if (where === 'left') leftHeight += height;
|
|
if (where === 'left') leftHeight += height;
|
|
if (where === 'right') rightHeight += height;
|
|
if (where === 'right') rightHeight += height;
|
|
|
|
+ // 添加到矮的一列
|
|
if (leftHeight <= rightHeight) {
|
|
if (leftHeight <= rightHeight) {
|
|
- state.leftScoreList.push(state.scoreList[count]);
|
|
|
|
|
|
+ state.leftSpuList.push(state.spuList[count]);
|
|
} else {
|
|
} else {
|
|
- state.rightScoreList.push(state.scoreList[count]);
|
|
|
|
|
|
+ state.rightSpuList.push(state.spuList[count]);
|
|
}
|
|
}
|
|
|
|
+ // 计数
|
|
count++;
|
|
count++;
|
|
}
|
|
}
|
|
- // 购买按钮样式
|
|
|
|
- const buyStyle = computed(() => {
|
|
|
|
- if (buyNowStyle.mode == 1) {
|
|
|
|
- // button
|
|
|
|
- return {
|
|
|
|
- background: `linear-gradient(to right, ${buyNowStyle.color1}, ${buyNowStyle.color2})`,
|
|
|
|
- };
|
|
|
|
|
|
+
|
|
|
|
+ //endregion
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据商品编号列表,获取商品列表
|
|
|
|
+ * @param ids 商品编号列表
|
|
|
|
+ * @return {Promise<undefined>} 商品列表
|
|
|
|
+ */
|
|
|
|
+ async function getPointActivityDetailList(ids) {
|
|
|
|
+ const { data } = await PointApi.getPointActivityListByIds(ids);
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据商品编号,获取商品详情
|
|
|
|
+ * @param ids 商品编号列表
|
|
|
|
+ * @return {Promise<undefined>} 商品列表
|
|
|
|
+ */
|
|
|
|
+ async function getSpuDetail(ids) {
|
|
|
|
+ const { data: spu } = await SpuApi.getSpuDetail(ids);
|
|
|
|
+ return spu;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 初始化
|
|
|
|
+ onMounted(async () => {
|
|
|
|
+ // 加载活动列表
|
|
|
|
+ const activityList = await getPointActivityDetailList(activityIds.join(','));
|
|
|
|
+ // 循环获取活动商品SPU详情并添加到spuList
|
|
|
|
+ for (const activity of activityList) {
|
|
|
|
+ state.spuList.push(await getSpuDetail(activity.spuId));
|
|
}
|
|
}
|
|
|
|
|
|
- if (buyNowStyle.mode == 2) {
|
|
|
|
- // image
|
|
|
|
- return {
|
|
|
|
- width: '54rpx',
|
|
|
|
- height: '54rpx',
|
|
|
|
- background: `url(${sheep.$url.cdn(buyNowStyle.src)}) no-repeat`,
|
|
|
|
- backgroundSize: '100% 100%',
|
|
|
|
- };
|
|
|
|
|
|
+ // 循环活动列表
|
|
|
|
+ activityList.forEach((activity) => {
|
|
|
|
+ // 查找对应的 spu 并更新价格
|
|
|
|
+ const spu = state.spuList.find((spu) => activity.spuId === spu.id);
|
|
|
|
+ if (spu) {
|
|
|
|
+ spu.pointStock = activity.stock
|
|
|
|
+ spu.pointTotalStock = activity.totalStock
|
|
|
|
+ spu.point = activity.point
|
|
|
|
+ spu.pointPrice = activity.price
|
|
|
|
+ // 赋值活动ID,为了点击跳转详情页
|
|
|
|
+ spu.activityId = activity.id;
|
|
|
|
+ // 赋值活动类型
|
|
|
|
+ spu.activityType = PromotionActivityTypeEnum.POINT.type;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 只有双列布局时需要
|
|
|
|
+ if (layoutType === LayoutTypeEnum.TWO_COL) {
|
|
|
|
+ // 分列
|
|
|
|
+ calculateGoodsColumn();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</script>
|
|
|
|
+
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
.goods-md-wrap {
|
|
.goods-md-wrap {
|
|
width: 100%;
|
|
width: 100%;
|
|
@@ -168,11 +287,18 @@
|
|
.goods-list-box {
|
|
.goods-list-box {
|
|
width: 50%;
|
|
width: 50%;
|
|
box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
|
|
+
|
|
.left-list {
|
|
.left-list {
|
|
&:nth-last-child(1) {
|
|
&:nth-last-child(1) {
|
|
margin-bottom: 0 !important;
|
|
margin-bottom: 0 !important;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ .right-list {
|
|
|
|
+ &:nth-last-child(1) {
|
|
|
|
+ margin-bottom: 0 !important;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
.goods-box {
|
|
.goods-box {
|
|
@@ -188,7 +314,7 @@
|
|
|
|
|
|
.cart-btn {
|
|
.cart-btn {
|
|
position: absolute;
|
|
position: absolute;
|
|
- bottom: 10rpx;
|
|
|
|
|
|
+ bottom: 18rpx;
|
|
right: 20rpx;
|
|
right: 20rpx;
|
|
z-index: 11;
|
|
z-index: 11;
|
|
height: 50rpx;
|
|
height: 50rpx;
|