feat: 添加已售罄标签

This commit is contained in:
2026-08-26 10:40:18 +08:00
parent 677b18bca9
commit a573a61be7
5 changed files with 290 additions and 14 deletions
@@ -11,6 +11,7 @@
<view v-if="tagStyle.show" class="tag-icon-box">
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
</view>
<view v-if="isSoldOut" class="sold-out-tag sold-out-tag-xs ss-flex ss-row-center">已售罄</view>
<image class="xs-img-box" :src="sheep.$url.cdn(data.image || data.picUrl)" mode="aspectFit" />
<view
v-if="goodsFields.title?.show || goodsFields.name?.show || goodsFields.price?.show"
@@ -73,6 +74,7 @@
<view v-if="tagStyle.show" class="tag-icon-box">
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
</view>
<view v-if="isSoldOut" class="sold-out-tag sold-out-tag-sm ss-flex ss-row-center">已售罄</view>
<image
class="sm-img-box"
:src="sheep.$url.cdn(data.image || data.picUrl)"
@@ -140,6 +142,7 @@
<view v-if="tagStyle.show" class="tag-icon-box">
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)" />
</view>
<view v-if="isSoldOut" class="sold-out-tag sold-out-tag-md ss-flex ss-row-center">已售罄</view>
<image
v-if="data.image_wh"
class="md-img-box"
@@ -244,8 +247,14 @@
</view>
<slot name="cart">
<view class="cart-box ss-flex ss-col-center ss-row-center">
<image class="cart-icon" src="/static/img/shop/tabbar/category2.png" mode="" />
<view
v-if="buttonShow"
class="cart-box cart-box-soldout ss-flex ss-col-center ss-row-center"
:class="{ 'is-soldout': isSoldOut }"
@click.stop="onCartClick($event)"
>
<image v-if="!isSoldOut" class="cart-icon" src="/static/img/shop/tabbar/category2.png" mode="" />
<view v-else class="cart-icon soldout-cart-ico">售罄</view>
</view>
</slot>
</view>
@@ -260,6 +269,7 @@
<view v-if="tagStyle.show" class="tag-icon-box">
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
</view>
<view v-if="isSoldOut" class="sold-out-tag sold-out-tag-lg ss-flex ss-row-center">已售罄</view>
<view v-if="seckillTag" class="seckill-tag ss-flex ss-row-center">秒杀</view>
<view v-if="grouponTag" class="groupon-tag ss-flex ss-row-center">
<view class="tag-icon">拼团</view>
@@ -354,7 +364,14 @@
</view>
<slot name="cart">
<view class="buy-box ss-flex ss-col-center ss-row-center" v-if="buttonShow"> 去购买</view>
<view
v-if="buttonShow"
class="buy-box ss-flex ss-col-center ss-row-center"
:class="{ 'is-soldout': isSoldOut }"
@click.stop="onCartClick($event)"
>
{{ isSoldOut ? '已售罄' : '去购买' }}
</view>
</slot>
</view>
@@ -363,6 +380,7 @@
<view v-if="tagStyle.show" class="tag-icon-box">
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)" />
</view>
<view v-if="isSoldOut" class="sold-out-tag sold-out-tag-sl ss-flex ss-row-center">已售罄</view>
<image
class="sl-img-box"
:src="sheep.$url.cdn(data.image || data.picUrl)"
@@ -457,7 +475,13 @@
</view>
<slot name="cart">
<view class="buy-box ss-flex ss-col-center ss-row-center">去购买</view>
<view
class="buy-box ss-flex ss-col-center ss-row-center"
:class="{ 'is-soldout': isSoldOut }"
@click.stop="onCartClick($event)"
>
{{ isSoldOut ? '已售罄' : '去购买' }}
</view>
</slot>
</view>
</view>
@@ -659,8 +683,22 @@
return text.join(' | ');
});
// 售罄判断
const isSoldOut = computed(() => {
if (props.data.activityType && props.data.activityType === PromotionActivityTypeEnum.POINT.type) {
return Number(props.data.pointStock || 0) <= 0;
}
return Number(props.data.stock || 0) <= 0;
});
// 购买/购物车按钮点击
function onCartClick(e) {
if (isSoldOut.value) return;
emits('cartClick', e);
}
// 返回事件
const emits = defineEmits(['click', 'getHeight']);
const emits = defineEmits(['click', 'getHeight', 'cartClick']);
const onClick = () => {
emits('click');
@@ -751,6 +789,53 @@
line-height: 32rpx;
}
.sold-out-tag {
position: absolute;
z-index: 5;
font-weight: 600;
color: #ffffff;
background: rgba(0, 0, 0, 0.58);
border-radius: 4rpx;
line-height: 1.2;
user-select: none;
backdrop-filter: blur(2px);
}
.sold-out-tag-xs {
left: 0;
top: 38rpx;
width: 76rpx;
height: 40rpx;
font-size: 20rpx;
}
.sold-out-tag-sm {
left: 0;
top: 0;
width: 76rpx;
height: 40rpx;
font-size: 20rpx;
}
.sold-out-tag-md {
left: 0;
top: 0;
width: 88rpx;
height: 48rpx;
font-size: 24rpx;
}
.sold-out-tag-lg {
left: 0;
top: 0;
width: 88rpx;
height: 48rpx;
font-size: 24rpx;
}
.sold-out-tag-sl {
left: 0;
top: 0;
width: 88rpx;
height: 48rpx;
font-size: 24rpx;
}
.goods-img {
width: 100%;
height: 100%;
@@ -887,6 +972,19 @@
height: 30rpx;
}
}
.cart-box-soldout.is-soldout {
background: #cccccc;
filter: grayscale(100%);
cursor: not-allowed;
pointer-events: none;
}
.cart-box-soldout.is-soldout .soldout-cart-ico {
font-size: 18rpx;
color: #ffffff;
font-weight: 600;
text-align: center;
line-height: 1.2;
}
}
// lg
@@ -937,6 +1035,13 @@
font-size: 24rpx;
color: #ffffff;
}
.buy-box.is-soldout {
background: #cccccc;
color: #ffffff;
filter: grayscale(100%);
pointer-events: none;
cursor: not-allowed;
}
.tag-box {
width: 100%;
@@ -993,6 +1098,13 @@
font-size: 24rpx;
color: #ffffff;
}
.buy-box.is-soldout {
background: #cccccc;
color: #ffffff;
filter: grayscale(100%);
pointer-events: none;
cursor: not-allowed;
}
}
.card {