feat: 添加已售罄标签
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user