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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user