From 1d3f1ad9b368d1e15391e26d16497b8940cb5c74 Mon Sep 17 00:00:00 2001
From: Jacob <hlnie@tohours.com>
Date: 星期二, 13 十月 2026 14:37:55 +0800
Subject: [PATCH] fix: 商品售罄判断统一抽离为 computed 并完善空值处理
---
pages/goods_details/index.vue | 15 ++++++++++++---
components/productConSwiper/index.vue | 12 +++++++++++-
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/components/productConSwiper/index.vue b/components/productConSwiper/index.vue
index 812c365..7bb447d 100644
--- a/components/productConSwiper/index.vue
+++ b/components/productConSwiper/index.vue
@@ -20,7 +20,7 @@
<block v-for="(item,index) in imgUrls" :key='index'>
<swiper-item>
<image :src="item" class="slide-image" />
- <image v-if="productSelect.stock !== undefined && productSelect.stock !== null && (!productSelect.stock || productSelect.stock <= 0)" style="position:absolute;left:0;top:0" class="slide-image" src="https://ossacmall.bluedeer.com.cn/app/static/images/noStock.png" mode="aspectFill"></image>
+ <image v-if="isSoldOut" style="position:absolute;left:0;top:0" class="slide-image" src="https://ossacmall.bluedeer.com.cn/app/static/images/noStock.png" mode="aspectFill"></image>
</swiper-item>
</block>
</swiper>
@@ -72,6 +72,16 @@
type: 'image'
};
},
+ computed: {
+ // 搴撳瓨瀛楁鏈姞杞斤紙undefined/null锛夋椂涓嶈涓� 0锛岄伩鍏嶆帴鍙h繑鍥炲墠璇洊鍞絼姘村嵃
+ isSoldOut() {
+ const stock = this.productSelect && this.productSelect.stock;
+ if (stock === undefined || stock === null || stock === '') {
+ return false;
+ }
+ return Number(stock) <= 0;
+ }
+ },
mounted() {
},
diff --git a/pages/goods_details/index.vue b/pages/goods_details/index.vue
index c6fb732..770c02a 100644
--- a/pages/goods_details/index.vue
+++ b/pages/goods_details/index.vue
@@ -191,7 +191,7 @@
</view>
<view>璐墿杞�</view>
</view>
- <view class="bnt acea-row" v-if="productInfo.id && attr.productSelect && attr.productSelect.stock <= 0">
+ <view class="bnt acea-row" v-if="isStockEmpty">
<form @submit="joinCart" report-submit="true"><button class="joinCart bnts" form-type="submit"
:class="(seckillId || (zoneId && zoneType == 2) || (couponMoneyType && couponMoneyType > 0) || productInfo.isVisual || birthdayGift) ? 'disable' : ''">鍔犲叆璐墿杞�</button>
</form>
@@ -208,7 +208,7 @@
</view>
</block>
<view class="bnt bntVideo acea-row"
- v-if="productInfo.id && attr.productSelect && attr.productSelect.stock <= 0 && type === 'video'">
+ v-if="isStockEmpty && type === 'video'">
<form report-submit="true"><button class="buy bnts bg-color-hui" form-type="submit">宸插敭缃�</button></form>
</view>
<view class="bnt bntVideo acea-row" v-if="attr.productSelect.stock > 0 && type === 'video'">
@@ -475,7 +475,16 @@
priceName: null,
};
},
- computed: mapGetters(['isLogin', 'uid', 'chatUrl']),
+ computed: {
+ ...mapGetters(['isLogin', 'uid', 'chatUrl']),
+ // 搴撳瓨瀛楁鏈姞杞斤紙undefined/null锛夋椂涓嶈涓� 0锛岄伩鍏嶈鎯呮帴鍙h繑鍥炲墠璇樉绀哄凡鍞絼
+ isStockEmpty() {
+ if (!this.productInfo.id) return false;
+ const stock = this.attr.productSelect && this.attr.productSelect.stock;
+ if (stock === undefined || stock === null || stock === '') return false;
+ return Number(stock) <= 0;
+ }
+ },
watch: {
isLogin: {
handler: function (newV, oldV) {
--
Gitblit v1.4.0