营销:适配商城装修组件【商品卡片】
parent
7adf5dd257
commit
99529e3b9e
|
@ -0,0 +1,36 @@
|
||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// 获得商品 SPU 列表
|
||||||
|
getSpuList: (recommendType) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/spu/list',
|
||||||
|
method: 'GET',
|
||||||
|
params: {recommendType},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商品 SPU 列表
|
||||||
|
getSpuListByIds: (ids) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/spu/list-by-ids',
|
||||||
|
method: 'GET',
|
||||||
|
params: {ids},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商品 SPU 分页
|
||||||
|
getSpuPage: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/spu/page',
|
||||||
|
method: 'GET',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 查询商品
|
||||||
|
getSpuDetail: (id) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/spu/get-detail',
|
||||||
|
method: 'GET',
|
||||||
|
params: { id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
|
@ -29,7 +29,7 @@
|
||||||
<s-hotzone-block v-if="type === 'hotzone'" :data="data" :styles="styles" />
|
<s-hotzone-block v-if="type === 'hotzone'" :data="data" :styles="styles" />
|
||||||
|
|
||||||
<!-- 商品组件:商品卡片 -->
|
<!-- 商品组件:商品卡片 -->
|
||||||
<s-goods-card v-if="type === 'goodsCard'" :data="data" :styles="styles" />
|
<s-goods-card v-if="type === 'ProductCard'" :data="data" :styles="styles" />
|
||||||
<!-- 商品组件:商品栏 -->
|
<!-- 商品组件:商品栏 -->
|
||||||
<s-goods-shelves v-if="type === 'goodsShelves'" :data="data" :styles="styles" />
|
<s-goods-shelves v-if="type === 'goodsShelves'" :data="data" :styles="styles" />
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- 商品卡片 -->
|
<!-- 商品卡片 -->
|
||||||
<view>
|
<view>
|
||||||
<!-- 1 100%宽卡片列表-->
|
<!-- 布局1. 单列大图(上图,下内容)-->
|
||||||
<view v-if="mode === 1 && state.goodsList.length" class="goods-sl-box">
|
<view v-if="layoutType === LayoutTypeEnum.ONE_COL_BIG_IMG && state.goodsList.length" class="goods-sl-box">
|
||||||
<view
|
<view
|
||||||
class="goods-box"
|
class="goods-box"
|
||||||
v-for="item in state.goodsList"
|
v-for="item in state.goodsList"
|
||||||
|
@ -12,27 +12,28 @@
|
||||||
<s-goods-column
|
<s-goods-column
|
||||||
class=""
|
class=""
|
||||||
size="sl"
|
size="sl"
|
||||||
:goodsFields="goodsFields"
|
:goodsFields="productFields"
|
||||||
:tagStyle="tagStyle"
|
:tagStyle="badge"
|
||||||
:data="item"
|
:data="item"
|
||||||
:titleColor="goodsFields.title?.color"
|
:titleColor="data.fields.name?.color"
|
||||||
:subTitleColor="goodsFields.subtitle.color"
|
:subTitleColor="data.fields.introduction.color"
|
||||||
:topRadius="data.borderRadiusTop"
|
:topRadius="data.borderRadiusTop"
|
||||||
:bottomRadius="data.borderRadiusBottom"
|
:bottomRadius="data.borderRadiusBottom"
|
||||||
@click="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
@click="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
||||||
>
|
>
|
||||||
|
<!-- 购买按钮 -->
|
||||||
<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-goods-column>
|
</s-goods-column>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 2 双列瀑布流列表-->
|
<!-- 布局2. 双列(每一列:上图,下内容)-->
|
||||||
<view
|
<view
|
||||||
v-if="mode === 2 && state.goodsList.length"
|
v-if="layoutType === LayoutTypeEnum.TWO_COL && state.goodsList.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">
|
||||||
|
@ -45,20 +46,21 @@
|
||||||
<s-goods-column
|
<s-goods-column
|
||||||
class="goods-md-box"
|
class="goods-md-box"
|
||||||
size="md"
|
size="md"
|
||||||
:goodsFields="goodsFields"
|
:goodsFields="productFields"
|
||||||
:tagStyle="tagStyle"
|
:tagStyle="badge"
|
||||||
:data="item"
|
:data="item"
|
||||||
:titleColor="goodsFields.title?.color"
|
:titleColor="data.fields.name?.color"
|
||||||
:subTitleColor="goodsFields.subtitle.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/index', { id: item.id })"
|
@click="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
||||||
@getHeight="mountMasonry($event, 'left')"
|
@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-goods-column>
|
</s-goods-column>
|
||||||
|
@ -74,20 +76,21 @@
|
||||||
<s-goods-column
|
<s-goods-column
|
||||||
class="goods-md-box"
|
class="goods-md-box"
|
||||||
size="md"
|
size="md"
|
||||||
:goodsFields="goodsFields"
|
:goodsFields="productFields"
|
||||||
:tagStyle="tagStyle"
|
:tagStyle="badge"
|
||||||
:data="item"
|
:data="item"
|
||||||
:titleColor="goodsFields.title?.color"
|
:titleColor="data.fields.name?.color"
|
||||||
:subTitleColor="goodsFields.subtitle.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/index', { id: item.id })"
|
@click="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
||||||
@getHeight="mountMasonry($event, 'right')"
|
@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-goods-column>
|
</s-goods-column>
|
||||||
|
@ -95,8 +98,8 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 3 30%卡片列表-->
|
<!-- 布局3. 单列小图(左图,右内容) -->
|
||||||
<view v-if="mode === 3 && state.goodsList.length" class="goods-lg-box">
|
<view v-if="layoutType === LayoutTypeEnum.ONE_COL_SMALL_IMG && state.goodsList.length" class="goods-lg-box">
|
||||||
<view
|
<view
|
||||||
class="goods-box"
|
class="goods-box"
|
||||||
:style="[{ marginBottom: data.space + 'px' }]"
|
:style="[{ marginBottom: data.space + 'px' }]"
|
||||||
|
@ -106,18 +109,19 @@
|
||||||
<s-goods-column
|
<s-goods-column
|
||||||
class="goods-card"
|
class="goods-card"
|
||||||
size="lg"
|
size="lg"
|
||||||
:goodsFields="goodsFields"
|
:goodsFields="productFields"
|
||||||
:data="item"
|
:data="item"
|
||||||
:tagStyle="tagStyle"
|
:tagStyle="badge"
|
||||||
:titleColor="goodsFields.title?.color"
|
:titleColor="data.fields.name?.color"
|
||||||
:subTitleColor="goodsFields.subtitle.color"
|
:subTitleColor="data.fields.introduction.color"
|
||||||
:topRadius="data.borderRadiusTop"
|
:topRadius="data.borderRadiusTop"
|
||||||
:bottomRadius="data.borderRadiusBottom"
|
:bottomRadius="data.borderRadiusBottom"
|
||||||
@tap="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
@tap="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
||||||
>
|
>
|
||||||
|
<!-- 购买按钮 -->
|
||||||
<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-goods-column>
|
</s-goods-column>
|
||||||
|
@ -128,11 +132,21 @@
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
/**
|
/**
|
||||||
* 商品模板,装修商品卡片
|
* 商品卡片
|
||||||
* @description style 1:带tab 2:瀑布流,横向两个,上图下内容 3:大图,横向一个
|
|
||||||
*/
|
*/
|
||||||
import { computed, reactive, onMounted } from 'vue';
|
import { computed, reactive, onMounted } from 'vue';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
|
import SpuApi from '@/sheep/api/product/spu';
|
||||||
|
|
||||||
|
// 布局类型
|
||||||
|
const LayoutTypeEnum = {
|
||||||
|
// 单列大图
|
||||||
|
ONE_COL_BIG_IMG: 'oneColBigImg',
|
||||||
|
// 双列
|
||||||
|
TWO_COL: 'twoCol',
|
||||||
|
// 单列小图
|
||||||
|
ONE_COL_SMALL_IMG: 'oneColSmallImg',
|
||||||
|
}
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
goodsList: [],
|
goodsList: [],
|
||||||
|
@ -150,55 +164,95 @@
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { mode, tagStyle, buyNowStyle, goodsFields, goodsIds } = props.data ?? {};
|
const { layoutType, btnBuy, spuIds } = props.data ?? {};
|
||||||
const { marginLeft, marginRight } = props.styles ?? {};
|
const { marginLeft, marginRight } = props.styles ?? {};
|
||||||
|
|
||||||
async function getGoodsListByIds(ids) {
|
// 购买按钮样式
|
||||||
let { data } = await sheep.$api.goods.ids({ ids });
|
const buyStyle = computed(() => {
|
||||||
return data;
|
if (btnBuy.type === 'text') {
|
||||||
}
|
// 文字按钮:线性渐变背景颜色
|
||||||
|
return {
|
||||||
onMounted(async () => {
|
background: `linear-gradient(to right, ${btnBuy.bgBeginColor}, ${btnBuy.bgEndColor})`,
|
||||||
state.goodsList = await getGoodsListByIds(goodsIds.join(','));
|
};
|
||||||
if (mode === 2) {
|
} else if (btnBuy.type === 'img') {
|
||||||
mountMasonry();
|
// 图片按钮
|
||||||
|
return {
|
||||||
|
width: '54rpx',
|
||||||
|
height: '54rpx',
|
||||||
|
background: `url(${sheep.$url.cdn(btnBuy.imgUrl)}) no-repeat`,
|
||||||
|
backgroundSize: '100% 100%',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 加载瀑布流
|
// 商品字段配置,todo @owen 字段名称与服务端对齐,这里先转换,后期重构时再修改
|
||||||
|
const productFields = computed(() => {
|
||||||
|
return {
|
||||||
|
title: props.data.fields.name,
|
||||||
|
subtitle: props.data.fields.introduction,
|
||||||
|
price: props.data.fields.price,
|
||||||
|
original_price: props.data.fields.marketPrice,
|
||||||
|
stock: props.data.fields.stock,
|
||||||
|
salesCount: props.data.fields.salesCount,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 角标,todo @owen 规范命名,这里先转换,后期重构时再修改
|
||||||
|
const badge = computed(() => {
|
||||||
|
return {
|
||||||
|
show: props.data.badge.show,
|
||||||
|
src: props.data.badge.imgUrl,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
//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') {
|
/**
|
||||||
|
* 计算商品在左列还是右列
|
||||||
|
* @param height 商品的高度
|
||||||
|
* @param where 添加到哪一列
|
||||||
|
*/
|
||||||
|
function calculateGoodsColumn(height = 0, where = 'left') {
|
||||||
|
// 处理完
|
||||||
if (!state.goodsList[count]) return;
|
if (!state.goodsList[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.leftGoodsList.push(state.goodsList[count]);
|
state.leftGoodsList.push(state.goodsList[count]);
|
||||||
} else {
|
} else {
|
||||||
state.rightGoodsList.push(state.goodsList[count]);
|
state.rightGoodsList.push(state.goodsList[count]);
|
||||||
}
|
}
|
||||||
|
// 计数
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
// 购买按钮样式
|
/**
|
||||||
const buyStyle = computed(() => {
|
* 根据商品编号列表,获取商品列表
|
||||||
if (buyNowStyle.mode == 1) {
|
* @param ids 商品编号列表
|
||||||
// button
|
* @return {Promise<undefined>} 商品列表
|
||||||
return {
|
*/
|
||||||
background: `linear-gradient(to right, ${buyNowStyle.color1}, ${buyNowStyle.color2})`,
|
async function getGoodsListByIds(ids) {
|
||||||
};
|
const { data } = await SpuApi.getSpuListByIds(ids);
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buyNowStyle.mode == 2) {
|
// 初始化
|
||||||
// image
|
onMounted(async () => {
|
||||||
return {
|
// 加载商品列表
|
||||||
width: '54rpx',
|
state.goodsList = await getGoodsListByIds(spuIds.join(','));
|
||||||
height: '54rpx',
|
// 只有双列布局时需要
|
||||||
background: `url(${sheep.$url.cdn(buyNowStyle.src)}) no-repeat`,
|
if (layoutType === LayoutTypeEnum.TWO_COL){
|
||||||
backgroundSize: '100% 100%',
|
// 分列
|
||||||
};
|
calculateGoodsColumn();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
class="xs-goods-title ss-line-1"
|
class="xs-goods-title ss-line-1"
|
||||||
:style="[{ color: titleColor, width: titleWidth ? titleWidth + 'rpx' : '' }]"
|
:style="[{ color: titleColor, width: titleWidth ? titleWidth + 'rpx' : '' }]"
|
||||||
>
|
>
|
||||||
{{ data.title }}
|
{{ data.title || data.name }}
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
v-if="goodsFields.price?.show"
|
v-if="goodsFields.price?.show"
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
:style="[{ color: titleColor, width: titleWidth ? titleWidth + 'rpx' : '' }]"
|
:style="[{ color: titleColor, width: titleWidth ? titleWidth + 'rpx' : '' }]"
|
||||||
>
|
>
|
||||||
<view v-if="goodsFields.title?.show" class="sm-goods-title ss-line-1 ss-m-b-16">
|
<view v-if="goodsFields.title?.show" class="sm-goods-title ss-line-1 ss-m-b-16">
|
||||||
{{ data.title }}
|
{{ data.title || data.name }}
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
v-if="goodsFields.price?.show"
|
v-if="goodsFields.price?.show"
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
class="md-goods-subtitle ss-m-t-16 ss-line-1"
|
class="md-goods-subtitle ss-m-t-16 ss-line-1"
|
||||||
:style="[{ color: subTitleColor, background: subTitleBackground }]"
|
:style="[{ color: subTitleColor, background: subTitleBackground }]"
|
||||||
>
|
>
|
||||||
{{ data.subtitle }}
|
{{ data.subtitle || data.introduction }}
|
||||||
</view>
|
</view>
|
||||||
<slot name="activity">
|
<slot name="activity">
|
||||||
<view v-if="data.promos?.length" class="tag-box ss-flex-wrap ss-flex ss-col-center">
|
<view v-if="data.promos?.length" class="tag-box ss-flex-wrap ss-flex ss-col-center">
|
||||||
|
@ -156,7 +156,7 @@
|
||||||
class="lg-goods-subtitle ss-m-t-10 ss-line-1"
|
class="lg-goods-subtitle ss-m-t-10 ss-line-1"
|
||||||
:style="[{ color: subTitleColor, background: subTitleBackground }]"
|
:style="[{ color: subTitleColor, background: subTitleBackground }]"
|
||||||
>
|
>
|
||||||
{{ data.subtitle }}
|
{{ data.subtitle || data.introduction }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view>
|
<view>
|
||||||
|
@ -220,7 +220,7 @@
|
||||||
class="sl-goods-subtitle ss-m-t-16"
|
class="sl-goods-subtitle ss-m-t-16"
|
||||||
:style="[{ color: subTitleColor, background: subTitleBackground }]"
|
:style="[{ color: subTitleColor, background: subTitleBackground }]"
|
||||||
>
|
>
|
||||||
{{ data.subtitle }}
|
{{ data.subtitle || data.introduction }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view>
|
<view>
|
||||||
|
|
Loading…
Reference in New Issue