Files
frontend-app/components/common/product-seckill-card.vue
T

375 lines
7.9 KiB
Vue
Raw Normal View History

2026-07-09 11:07:31 +08:00
<template>
2026-07-12 22:23:16 +08:00
<view class="seckill_card_container" @click="onSelectProct(item)">
2026-07-09 11:07:31 +08:00
<!-- Left side image with optional countdown overlay -->
<view class="seckill_card_left">
2026-07-12 22:23:16 +08:00
<up-image :src="item.url || item.image || item.accessUrl" width="220rpx" height="220rpx" bgColor="#f1f6ff00"
shape="square" radius="16rpx"></up-image>
2026-07-09 11:07:31 +08:00
<view class="countdown_bar" v-if="showCountdown && countdownText">
<text class="countdown_text">{{ countdownText }}</text>
</view>
</view>
<!-- Right side content -->
<view class="seckill_card_right">
2026-07-12 22:23:16 +08:00
<view>
2026-07-17 15:54:07 +08:00
<view class="tags_row" v-if="Array.isArray(item.goodsTagList)">
<image v-for="i in item.goodsTagList" :key="i.icon" :src="i.icon" class="tag_image"
2026-07-14 23:08:25 +08:00
mode="heightFix"></image>
2026-07-09 11:07:31 +08:00
</view>
2026-07-12 22:23:16 +08:00
<!-- 商品名称 -->
<view class="product_title">{{ item.title }}</view>
2026-07-09 11:07:31 +08:00
</view>
2026-07-12 22:23:16 +08:00
<!-- (秒杀券立减) -->
2026-07-09 11:07:31 +08:00
<view class="coupon_row" v-if="hasCoupon">
2026-07-15 20:06:20 +08:00
<view class="coupon_badge" v-if="activedType === 'seckill' || activedType === 'actived'">
2026-07-09 11:07:31 +08:00
<text class="flash_icon">⚡</text>
2026-07-14 23:08:25 +08:00
<text class="coupon_text" v-if="item.secDiscount || item.subsidy">加倍补{{ item.secDiscount ||
item.subsidy }}元</text>
2026-07-09 11:07:31 +08:00
</view>
2026-07-13 18:33:00 +08:00
<view class="coupon_badge" v-if="activedType === 'super'">
2026-07-12 22:23:16 +08:00
<text class="flash_icon">⚡</text>
<text class="coupon_text">加倍补{{ item.subsidy }}积分</text>
2026-07-13 18:33:00 +08:00
</view>
2026-07-09 11:07:31 +08:00
</view>
<!-- Price and action card row -->
<view class="price_action_row">
<view class="price_section">
<text class="price_symbol">¥</text>
2026-07-12 22:23:16 +08:00
<text class="price_integer">{{ item.price }}</text>
2026-07-14 23:08:25 +08:00
<text class="original_price seckill">{{ `${attributes.leftTime ?
2026-07-12 22:23:16 +08:00
`只剩${attributes.leftTime}` : ''}` }}</text>
<!-- <text class="original_price" v-else>¥{{ formatOriginalPrice }}</text> -->
2026-07-09 11:07:31 +08:00
</view>
<!-- Alarm clock button -->
2026-07-14 23:08:25 +08:00
<view class="alarm_btn_wrapper">
2026-07-15 20:06:20 +08:00
<image class="uni-image" v-if="activedType === 'actived'"
2026-07-14 23:08:25 +08:00
src="https://static.tbmall.xin/static/new-home/home_3.png"></image>
<image class="uni-image seckill-icon" v-else src="https://static.tbmall.xin/static/home/qiang.png">
</image>
2026-07-09 11:07:31 +08:00
</view>
</view>
</view>
</view>
</template>
<script>
export default {
name: "product-seckill-card",
props: {
2026-07-12 22:23:16 +08:00
// 单个商品
2026-07-09 11:07:31 +08:00
item: {
type: Object,
default: () => ({})
},
2026-07-12 22:23:16 +08:00
// 倒计时
2026-07-09 11:07:31 +08:00
showCountdown: {
type: Boolean,
default: true
},
// Time object containing startTime and endTime timestamps
timeObj: {
type: Object,
default: () => ({})
2026-07-12 22:23:16 +08:00
},
activedType: {
type: String,
},
attributes: {
type: Object,
default: () => ({})
2026-07-09 11:07:31 +08:00
}
},
data() {
return {
countdownText: "",
timer: null,
now: Date.now()
};
},
watch: {
timeObj: {
immediate: true,
deep: true,
handler() {
this.startCountdown();
}
}
},
computed: {
hasCoupon() {
2026-07-12 22:23:16 +08:00
return this.item.secDiscount || this.item.subsidy;
2026-07-09 11:07:31 +08:00
},
},
beforeDestroy() {
this.clearTimer();
},
methods: {
2026-07-12 22:23:16 +08:00
// 商品
onSelectProct(item) {
2026-07-15 20:06:20 +08:00
if (this.activedType === 'actived') {
uni.showToast({
title: '活动即将开始',
icon: 'none',
mask: true,
duration: 1500,
})
return;
}
2026-07-14 23:08:25 +08:00
let url = "/pages/other_package/productInfo/productInfo?id=" + item.id;
if (this.activedType === 'seckill') {
2026-07-13 18:33:00 +08:00
url = "/pages/other_package/productInfo/productInfo?id=" + item.id + "&activedType=" + this.activedType + "&activityId=" + item.activityId;
}
2026-07-12 22:23:16 +08:00
uni.navigateTo({
2026-07-13 18:33:00 +08:00
url: url,
2026-07-12 22:23:16 +08:00
});
},
2026-07-09 11:07:31 +08:00
startCountdown() {
this.clearTimer();
this.updateCountdown();
this.timer = setInterval(() => {
this.now = Date.now();
this.updateCountdown();
}, 1000);
},
updateCountdown() {
if (!this.timeObj || !this.timeObj.startTime || !this.timeObj.endTime) {
this.countdownText = "";
return;
}
const now = Date.now();
const startTime = Number(this.timeObj.startTime);
const endTime = Number(this.timeObj.endTime);
if (now < startTime) {
const diff = startTime - now;
this.countdownText = `秒杀专享 ${this.formatDuration(diff)} 后开始`;
} else if (now >= startTime && now <= endTime) {
const diff = endTime - now;
this.countdownText = `秒杀专享 ${this.formatDuration(diff)} 后结束`;
} else {
this.countdownText = "已结束";
}
},
formatDuration(ms) {
let totalSeconds = Math.floor(ms / 1000);
if (totalSeconds < 0) totalSeconds = 0;
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
const pad = (num) => String(num).padStart(2, '0');
return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
},
clearTimer() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
}
}
};
</script>
<style lang="scss" scoped>
.seckill_card_container {
display: flex;
background-color: #ffffff;
border-radius: 24rpx;
margin-bottom: 20rpx;
width: 100%;
}
.seckill_card_left {
position: relative;
width: 220rpx;
height: 220rpx;
flex-shrink: 0;
border-radius: 16rpx;
overflow: hidden;
}
.countdown_bar {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: rgba(109, 63, 10, 0.9); // Dark bronze/brown background
padding: 6rpx 0;
text-align: center;
}
.countdown_text {
color: #ffffff;
font-size: 18rpx;
font-weight: bold;
}
.seckill_card_right {
flex: 1;
margin-left: 24rpx;
display: flex;
flex-direction: column;
justify-content: space-between;
min-width: 0;
}
.tags_row {
display: flex;
align-items: center;
margin-bottom: 8rpx;
2026-07-12 22:23:16 +08:00
gap: 8rpx;
2026-07-09 11:07:31 +08:00
2026-07-12 22:23:16 +08:00
.tag_image {
height: 28rpx;
display: block;
2026-07-17 15:54:07 +08:00
flex-shrink: 0;
2026-07-09 11:07:31 +08:00
}
}
.vip_icon {
color: #ffffff;
background: #ffb100;
border-radius: 50%;
width: 18rpx;
height: 18rpx;
font-size: 14rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 6rpx;
font-weight: 900;
}
.product_title {
2026-07-12 22:23:16 +08:00
font-size: 26rpx;
color: #000;
2026-07-09 11:07:31 +08:00
font-weight: bold;
2026-07-15 20:06:20 +08:00
line-height: 30rpx;
2026-07-09 11:07:31 +08:00
word-break: break-all;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
2026-07-15 20:06:20 +08:00
// margin-bottom: 12rpx;
2026-07-09 11:07:31 +08:00
}
.coupon_row {
display: flex;
2026-07-12 22:23:16 +08:00
position: relative;
2026-07-09 11:07:31 +08:00
2026-07-12 22:23:16 +08:00
.coupon_badge {
position: absolute;
top: -12rpx;
background: linear-gradient(90deg, #b164fb 0%, #7632ff 100%);
color: #ffffff;
font-size: 20rpx;
font-weight: bold;
padding: 4rpx 10rpx;
border-radius: 8rpx;
display: flex;
align-items: center;
&::after {
content: '';
position: absolute;
bottom: -8rpx;
left: 24rpx;
width: 0;
height: 0;
border-left: 8rpx solid transparent;
border-right: 8rpx solid transparent;
border-top: 8rpx solid #b164fb;
}
}
2026-07-09 11:07:31 +08:00
}
.flash_icon {
margin-right: 6rpx;
color: #ffdd00;
}
.price_action_row {
display: flex;
justify-content: space-between;
align-items: center;
2026-07-12 22:23:16 +08:00
background: linear-gradient(270deg, #F0E7FE 0%, rgba(240, 231, 254, 0) 100%);
border-radius: 12rpx;
2026-07-09 11:07:31 +08:00
padding: 10rpx 20rpx;
2026-07-12 22:23:16 +08:00
height: 80rpx;
2026-07-09 11:07:31 +08:00
border-radius: 16rpx;
width: 100%;
box-sizing: border-box;
2026-07-12 22:23:16 +08:00
position: relative;
.uni-image {
display: block;
width: 80rpx;
height: inherit;
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 0;
border-radius: 12rpx;
&.seckill-icon {
height: 80rpx;
}
}
2026-07-09 11:07:31 +08:00
}
.price_section {
display: flex;
align-items: baseline;
}
.price_symbol {
font-size: 24rpx;
color: #7632ff;
font-weight: bold;
margin-right: 4rpx;
}
.price_integer {
font-size: 40rpx;
color: #7632ff;
font-weight: bold;
}
.price_decimal {
font-size: 28rpx;
color: #7632ff;
font-weight: bold;
}
.original_price {
font-size: 24rpx;
color: #999999;
text-decoration: line-through;
2026-07-12 22:23:16 +08:00
margin-left: 10rpx;
&.seckill {
color: #7934F6;
font-size: 20rpx;
text-decoration: none;
}
2026-07-09 11:07:31 +08:00
}
.alarm_btn_wrapper {
width: 56rpx;
height: 56rpx;
display: flex;
align-items: center;
justify-content: center;
transition: background-color 0.2s;
&:active {
background-color: #f0e7ff;
}
}
</style>