1
This commit is contained in:
@@ -0,0 +1,349 @@
|
||||
<template>
|
||||
<view class="seckill_card_container" @click="$emit('click', item)">
|
||||
<!-- Left side image with optional countdown overlay -->
|
||||
<view class="seckill_card_left">
|
||||
<up-image :src="item.url || item.image || item.accessUrl" width="220rpx" height="220rpx" bgColor="#f1f6ff00" shape="square" radius="16rpx"></up-image>
|
||||
<view class="countdown_bar" v-if="showCountdown && countdownText">
|
||||
<text class="countdown_text">{{ countdownText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Right side content -->
|
||||
<view class="seckill_card_right">
|
||||
<!-- Tags row (Placeholders, toggleable via item flags) -->
|
||||
<view class="tags_row">
|
||||
<view class="tag_badge seckill" v-if="isSeckill">限时秒杀</view>
|
||||
<view class="tag_badge limit" v-if="isLimitTime">限时</view>
|
||||
<view class="tag_badge special" v-if="isSpecialSupply">
|
||||
<view class="vip_icon">V</view>特供
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Title -->
|
||||
<view class="product_title">{{ item.title || '商品名称' }}</view>
|
||||
|
||||
<!-- Coupon tag (秒杀券立减) -->
|
||||
<view class="coupon_row" v-if="hasCoupon">
|
||||
<view class="coupon_badge">
|
||||
<text class="flash_icon">⚡</text>
|
||||
<text class="coupon_text">秒杀券立减{{ item.couponAmount || '8.8' }}元</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Price and action card row -->
|
||||
<view class="price_action_row">
|
||||
<view class="price_section">
|
||||
<text class="price_symbol">¥</text>
|
||||
<text class="price_integer">{{ priceParts.integer }}</text>
|
||||
<text class="price_decimal">.{{ priceParts.decimal }}</text>
|
||||
<text class="original_price">¥{{ item.originalPrice || item.price || '0.00' }}</text>
|
||||
</view>
|
||||
<!-- Alarm clock button -->
|
||||
<view class="alarm_btn_wrapper" @click.stop="$emit('action', item)">
|
||||
<up-image src="https://static.tbmall.xin/static/new-home/home_3.png" width="36rpx" height="36rpx" bgColor="#f1f6ff00"></up-image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "product-seckill-card",
|
||||
props: {
|
||||
// Product details object
|
||||
item: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
// Control showing countdown bar
|
||||
showCountdown: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// Time object containing startTime and endTime timestamps
|
||||
timeObj: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
countdownText: "",
|
||||
timer: null,
|
||||
now: Date.now()
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
timeObj: {
|
||||
immediate: true,
|
||||
deep: true,
|
||||
handler() {
|
||||
this.startCountdown();
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
priceParts() {
|
||||
const price = String(this.item.price || '0.00');
|
||||
const parts = price.split('.');
|
||||
return {
|
||||
integer: parts[0] || '0',
|
||||
decimal: parts[1] || '00'
|
||||
};
|
||||
},
|
||||
hasCoupon() {
|
||||
return this.item.couponAmount !== undefined || this.item.couponText !== undefined;
|
||||
},
|
||||
isSeckill() {
|
||||
return this.item.isSeckill !== undefined ? this.item.isSeckill : true;
|
||||
},
|
||||
isLimitTime() {
|
||||
return this.item.isLimitTime !== undefined ? this.item.isLimitTime : true;
|
||||
},
|
||||
isSpecialSupply() {
|
||||
return this.item.isSpecialSupply !== undefined ? this.item.isSpecialSupply : true;
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.clearTimer();
|
||||
},
|
||||
methods: {
|
||||
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;
|
||||
padding: 24rpx;
|
||||
background-color: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-sizing: border-box;
|
||||
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;
|
||||
}
|
||||
|
||||
.tag_badge {
|
||||
font-size: 18rpx;
|
||||
font-weight: bold;
|
||||
padding: 4rpx 10rpx;
|
||||
border-radius: 6rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
line-height: 1;
|
||||
margin-right: 12rpx;
|
||||
|
||||
&:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
&.seckill {
|
||||
background-color: #ff1212;
|
||||
color: #ffffff;
|
||||
border: 1rpx dashed #ffffff;
|
||||
}
|
||||
|
||||
&.limit {
|
||||
background-color: #ae61fa;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
&.special {
|
||||
background-color: #333333;
|
||||
color: #e2d2b2; // Gold/bronze text color
|
||||
border: 1rpx solid #e2d2b2;
|
||||
padding: 3rpx 10rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.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 {
|
||||
font-size: 28rpx;
|
||||
color: #111111;
|
||||
font-weight: bold;
|
||||
line-height: 40rpx;
|
||||
word-break: break-all;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.coupon_row {
|
||||
display: flex;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.coupon_badge {
|
||||
background: linear-gradient(90deg, #b164fb 0%, #7632ff 100%);
|
||||
color: #ffffff;
|
||||
font-size: 20rpx;
|
||||
font-weight: bold;
|
||||
padding: 6rpx 16rpx;
|
||||
border-radius: 8rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.flash_icon {
|
||||
margin-right: 6rpx;
|
||||
color: #ffdd00;
|
||||
}
|
||||
|
||||
.price_action_row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background-color: #f1ebff; // Light purple box background
|
||||
padding: 10rpx 20rpx;
|
||||
border-radius: 16rpx;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.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;
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
.alarm_btn_wrapper {
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
background-color: #ffffff;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background-color 0.2s;
|
||||
|
||||
&:active {
|
||||
background-color: #f0e7ff;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user