mall-uniapp/sheep/components/s-seckill-block/s-seckill-block.vue

156 lines
3.7 KiB
Vue
Raw Normal View History

2022-11-22 07:45:36 +00:00
<!-- 装修组件 - 秒杀 -->
<template>
<view>
<!-- 样式一三列 - 上图下文 -->
<view v-if="layoutType === 'threeCol'" class="goods-sm-box ss-flex ss-flex-wrap"
:style="[{ margin: '-' + data.space + 'rpx' }]">
<view v-for="product in productList" :key="product.id" class="goods-card-box" :style="[
2022-11-22 07:45:36 +00:00
{
padding: data.space + 'rpx',
},
]">
<s-goods-column class="goods-card" size="sm" :goodsFields="data.fields" :tagStyle="tagStyle"
:data="product" :titleColor="data.fields.name?.color" :topRadius="data.borderRadiusTop"
:bottomRadius="data.borderRadiusBottom" @click="
2022-11-22 07:45:36 +00:00
sheep.$router.go('/pages/goods/seckill', {
2023-12-23 14:27:09 +00:00
id: props.data.activityId,
2022-11-22 07:45:36 +00:00
})
"></s-goods-column>
</view>
</view>
<!-- 样式二一列 - 左图右文 -->
<view class="goods-box" v-if="layoutType === 'oneCol'">
<view class="goods-list" v-for="(product, index) in productList" :key="index"
:style="[{ marginBottom: space + 'px' }]">
<s-goods-column class="goods-card" size="lg" :goodsFields="data.fields" :tagStyle="tagStyle"
:data="product" :titleColor="data.fields.name?.color"
:subTitleColor="data.fields.introduction?.color" :topRadius="data.borderRadiusTop"
:bottomRadius="data.borderRadiusBottom" @click="
2022-11-22 07:45:36 +00:00
sheep.$router.go('/pages/goods/seckill', {
2023-12-23 14:27:09 +00:00
id: props.data.activityId,
2022-11-22 07:45:36 +00: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>
</view>
2022-11-22 07:45:36 +00:00
</template>
<script setup>
/**
* 秒杀商品列表
*
* @property {Array} list 商品列表
*/
import {
computed,
onMounted,
ref
} from 'vue';
import sheep from '@/sheep';
import SeckillApi from "@/sheep/api/promotion/seckill";
import SpuApi from "@/sheep/api/product/spu";
2022-11-22 07:45:36 +00:00
// 接收参数
const props = defineProps({
data: {
type: Object,
default () {},
},
styles: {
type: Object,
default () {},
},
});
2022-11-22 07:45:36 +00:00
let {
layoutType,
tagStyle,
btnBuy,
space
} = props.data;
let {
marginLeft,
marginRight
} = props.styles;
2022-11-22 07:45:36 +00:00
// 购买按钮样式
const buyStyle = computed(() => {
let btnBuy = props.data.btnBuy;
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%',
};
}
});
2022-11-22 07:45:36 +00:00
// 商品列表
const productList = ref([]);
// 查询秒杀活动商品
onMounted(async () => {
// todo@owen 与Yudao结构不一致待重构
const {
data: activity
} = await SeckillApi.getSeckillActivity(props.data.activityId);
const {
data: spu
} = await SpuApi.getSpuDetail(activity.spuId)
// 循环活动信息,赋值秒杀最低价格
activity.products.forEach((product) => {
spu.price = Math.min(spu.price, product.seckillPrice); // 设置 SPU 的最低价格
});
productList.value = [spu];
});
2022-11-22 07:45:36 +00:00
</script>
<style lang="scss" scoped>
.header-box {
height: 100rpx;
}
2022-11-22 07:45:36 +00:00
.goods-list {
position: relative;
&:nth-last-child(1) {
margin-bottom: 0 !important;
}
.cart-btn {
position: absolute;
bottom: 10rpx;
right: 20rpx;
z-index: 11;
height: 50rpx;
line-height: 50rpx;
padding: 0 20rpx;
border-radius: 25rpx;
font-size: 24rpx;
color: #fff;
}
}
.goods-sm-box {
margin: 0 auto;
box-sizing: border-box;
.goods-card-box {
flex-shrink: 0;
overflow: hidden;
width: 33.3%;
box-sizing: border-box;
}
}
</style>