Jacob
2026-10-13 1d3f1ad9b368d1e15391e26d16497b8940cb5c74
fix: 商品售罄判断统一抽离为 computed 并完善空值处理
2个文件已修改
27 ■■■■■ 已修改文件
components/productConSwiper/index.vue 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/goods_details/index.vue 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
components/productConSwiper/index.vue
....@@ -20,7 +20,7 @@
2020 <block v-for="(item,index) in imgUrls" :key='index'>
2121 <swiper-item>
2222 <image :src="item" class="slide-image" />
23
- <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>
23
+ <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>
2424 </swiper-item>
2525 </block>
2626 </swiper>
....@@ -72,6 +72,16 @@
7272 type: 'image'
7373 };
7474 },
75
+ computed: {
76
+ // 库存字段未加载(undefined/null)时不视为 0,避免接口返回前误盖售罄水印
77
+ isSoldOut() {
78
+ const stock = this.productSelect && this.productSelect.stock;
79
+ if (stock === undefined || stock === null || stock === '') {
80
+ return false;
81
+ }
82
+ return Number(stock) <= 0;
83
+ }
84
+ },
7585 mounted() {
7686
7787 },
pages/goods_details/index.vue
....@@ -191,7 +191,7 @@
191191 </view>
192192 <view>购物车</view>
193193 </view>
194
- <view class="bnt acea-row" v-if="productInfo.id && attr.productSelect && attr.productSelect.stock <= 0">
194
+ <view class="bnt acea-row" v-if="isStockEmpty">
195195 <form @submit="joinCart" report-submit="true"><button class="joinCart bnts" form-type="submit"
196196 :class="(seckillId || (zoneId && zoneType == 2) || (couponMoneyType && couponMoneyType > 0) || productInfo.isVisual || birthdayGift) ? 'disable' : ''">加入购物车</button>
197197 </form>
....@@ -208,7 +208,7 @@
208208 </view>
209209 </block>
210210 <view class="bnt bntVideo acea-row"
211
- v-if="productInfo.id && attr.productSelect && attr.productSelect.stock <= 0 && type === 'video'">
211
+ v-if="isStockEmpty && type === 'video'">
212212 <form report-submit="true"><button class="buy bnts bg-color-hui" form-type="submit">已售罄</button></form>
213213 </view>
214214 <view class="bnt bntVideo acea-row" v-if="attr.productSelect.stock > 0 && type === 'video'">
....@@ -475,7 +475,16 @@
475475 priceName: null,
476476 };
477477 },
478
- computed: mapGetters(['isLogin', 'uid', 'chatUrl']),
478
+ computed: {
479
+ ...mapGetters(['isLogin', 'uid', 'chatUrl']),
480
+ // 库存字段未加载(undefined/null)时不视为 0,避免详情接口返回前误显示已售罄
481
+ isStockEmpty() {
482
+ if (!this.productInfo.id) return false;
483
+ const stock = this.attr.productSelect && this.attr.productSelect.stock;
484
+ if (stock === undefined || stock === null || stock === '') return false;
485
+ return Number(stock) <= 0;
486
+ }
487
+ },
479488 watch: {
480489 isLogin: {
481490 handler: function (newV, oldV) {