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
+1 -1
View File
@@ -1,7 +1,7 @@
### 项目打包配置
- 更改版本号
- 当前版本号`1.4.1`
- 包名:`uni.UNI8B187414`
- 包名:`uni.UNI8B187414/com.yougou.mall`
- 应用名称:`优购商城`
- appId:`__UNI__8B19741`
- api地址`.env`:
+89 -2
View File
@@ -8,6 +8,7 @@
<view class="corner-badge__bg"></view>
<view class="corner-badge__text">{{ cornerText }}</view>
</view>
<view v-if="showSoldOutTag" class="sold-out-tag">已售罄</view>
<image :src="props.data.picUrl" mode="scaleToFill" />
</view>
<view class="flex1 flex-column ju-between">
@@ -130,9 +131,25 @@
>
</view>
<view v-if="props.source === 0 && timeText !== '开始'" class="spec-btn-wrap">
<uni-badge :text="props.data.cartCount" absolute="rightTop" :offset="[8, 3]">
<view class="ai-button1 w_144" style="color: #fff" @click.stop="addCar">选规格</view>
<uni-badge
v-if="!isSoldOut"
:text="props.data.cartCount"
absolute="rightTop"
:offset="[8, 3]"
>
<view
class="ai-button1 w_144"
:class="{ 'btn-soldout': isSoldOut }"
:style="isSoldOut ? 'color:#fff;' : 'color: #fff;'"
@click.stop="addCar"
>{{ isSoldOut ? '已售罄' : '选规格' }}</view>
</uni-badge>
<view
v-else
class="ai-button1 w_144 btn-soldout"
style="color:#fff"
@click.stop="addCar"
>已售罄</view>
</view>
</view>
<view v-if="props.source === 1" class="flex-center ju-flex-end m-t-12">
@@ -191,6 +208,50 @@
if (raw !== '七数商') return '';
return raw;
});
const isSoldOut = computed(() => {
const d = props.data || {};
const stockNum = Number(
d.stock ?? d.stocks ?? d.pointStock ?? d.leftStock ?? -1,
);
if (stockNum !== -1 && !Number.isNaN(stockNum)) {
if (stockNum <= 0) return true;
}
if (Array.isArray(d.skuArr) && d.skuArr.length) {
const total = d.skuArr.reduce((s, sku) => {
const skuStock = Number(
(sku && (sku.stock ?? sku.stocks ?? sku.count ?? sku.leftStock)) ?? 0,
);
return s + (Number.isNaN(skuStock) ? 0 : skuStock);
}, 0);
if (total <= 0) return true;
}
if (Array.isArray(d.skus) && d.skus.length) {
const total = d.skus.reduce((s, sku) => {
const skuStock = Number(
(sku && (sku.stock ?? sku.stocks ?? sku.count ?? sku.leftStock)) ?? 0,
);
return s + (Number.isNaN(skuStock) ? 0 : skuStock);
}, 0);
if (total <= 0) return true;
}
if (Array.isArray(d.items1) && d.items1.length) {
const total = d.items1.reduce((s, sku) => {
const skuStock = Number(
(sku && (sku.stock ?? sku.stocks ?? sku.count ?? sku.leftStock)) ?? 0,
);
return s + (Number.isNaN(skuStock) ? 0 : skuStock);
}, 0);
if (total <= 0) return true;
}
return false;
});
const showSoldOutTag = computed(() => {
if (!isSoldOut.value) return false;
if (props.source === 0) return true;
return false;
});
let timeText = ref('结束');
let hour = ref(0);
let minute = ref(0);
@@ -291,6 +352,7 @@
}
}
const addCar = () => {
if (isSoldOut.value) return;
proxy.$emit('addCar', props.data);
};
const goInfo = () => {
@@ -470,4 +532,29 @@
align-items: baseline;
justify-content: space-between;
}
.sold-out-tag {
position: absolute;
right: 0;
top: 0;
z-index: 3;
width: 108rpx;
height: 52rpx;
line-height: 52rpx;
text-align: center;
font-size: 24rpx;
font-weight: 600;
color: #ffffff;
background: rgba(0, 0, 0, 0.58);
border-radius: 0 0 0 12rpx;
backdrop-filter: blur(2px);
}
.btn-soldout {
background: #cccccc !important;
color: #ffffff !important;
filter: grayscale(100%);
cursor: not-allowed !important;
pointer-events: none !important;
}
</style>
+82 -5
View File
@@ -16,6 +16,15 @@
goodsImg3: props.type == 3,
}"
>
<view
v-if="isSoldOut"
class="sold-out-tag"
:class="{
sold1: props.type == 1,
sold2: props.type == 2,
sold3: props.type == 3,
}"
>已售罄</view>
<image
class=""
:src="props.data.picUrl ? sheep.$url.cdn(props.data.picUrl) : '/static/icon/null1.png'"
@@ -66,13 +75,28 @@
> -->
</view>
<!-- -->
<uni-badge :text="props.data.cartCount" v-if="props.type == 2 && props.data.cartCount" absolute="rightTop" :customStyle="{background: '#FF0000'}">
<view class="shopIcon" :class="{ 'shopIcon1': props.type == 2 }" @click.stop="onShopIconClick">
<uni-badge
v-if="!isSoldOut && props.type == 2 && props.data.cartCount"
:text="props.data.cartCount"
absolute="rightTop"
:customStyle="{background: '#FF0000'}"
>
<view
class="shopIcon"
:class="{ 'shopIcon1': props.type == 2, 'shop-icon-soldout': isSoldOut }"
@click.stop="onShopIconClick"
>
<image src="/static/index/shop.png" mode="scaleToFill" />
</view>
</uni-badge>
<view class="shopIcon" :class="{ 'shopIcon1': props.type == 2 }" @click.stop="onShopIconClick" v-else>
<image src="/static/index/shop.png" mode="scaleToFill" />
<view
class="shopIcon"
:class="{ 'shopIcon1': props.type == 2, 'shop-icon-soldout': isSoldOut }"
@click.stop="onShopIconClick"
v-else
>
<image v-if="!isSoldOut" src="/static/index/shop.png" mode="scaleToFill" />
<view v-else class="shop-soldout-tip">售罄</view>
</view>
</view>
</view>
@@ -90,7 +114,7 @@
<script setup>
import sheep from '@/sheep';
import { ref, reactive, watch } from 'vue';
import { ref, reactive, watch, computed } from 'vue';
import SpuApi from '@/sheep/api/product/spu';
import { fen2yuan } from '@/sheep/hooks/useGoods';
@@ -123,6 +147,11 @@
deep: true,
},
);
const isSoldOut = computed(() => {
return Number(props.data.stock || 0) <= 0;
});
let showSelectSku = ref(false);
const goDetail = () => {
sheep.$router.go('/pages/goods/info', { id: props.data.id });
@@ -138,6 +167,7 @@
});
};
const onShopIconClick = () => {
if (isSoldOut.value) return;
if (props.memberPreferred) {
buyMemberGoods();
return;
@@ -216,6 +246,37 @@
</script>
<style lang="scss" scoped>
.sold-out-tag {
position: absolute;
right: 0;
top: 0;
z-index: 3;
color: #ffffff;
font-weight: 600;
background: rgba(0, 0, 0, 0.58);
border-radius: 0 0 0 8rpx;
backdrop-filter: blur(2px);
text-align: center;
}
.sold-out-tag.sold1 {
width: 108rpx;
height: 52rpx;
line-height: 52rpx;
font-size: 24rpx;
}
.sold-out-tag.sold2 {
width: 96rpx;
height: 44rpx;
line-height: 44rpx;
font-size: 22rpx;
}
.sold-out-tag.sold3 {
width: 76rpx;
height: 36rpx;
line-height: 36rpx;
font-size: 18rpx;
}
.goodItem {
padding: 20rpx 24rpx;
box-sizing: border-box;
@@ -265,6 +326,22 @@
height: 100%;
}
}
.shop-icon-soldout {
background: #cccccc;
filter: grayscale(100%);
border-radius: 50%;
cursor: not-allowed;
display: flex;
align-items: center;
justify-content: center;
}
.shop-soldout-tip {
font-size: 18rpx;
color: #ffffff;
font-weight: 600;
text-align: center;
line-height: 1.2;
}
}
.shrink{
border-radius: 10rpx;
+1 -1
View File
@@ -43,7 +43,7 @@
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>"
],
"abiFilters" : [ "arm64-v8a", "x86" ],
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ],
"minSdkVersion" : 21
},
"ios" : {
@@ -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 {