From dce7d15ab1d3ebecd46358d07287ce3a33d80605 Mon Sep 17 00:00:00 2001 From: shijing Date: Thu, 10 Feb 2022 09:20:43 +0800 Subject: [PATCH] bugList --- pages/goods/goods.vue | 58 ++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/pages/goods/goods.vue b/pages/goods/goods.vue index c1785af..eef576f 100644 --- a/pages/goods/goods.vue +++ b/pages/goods/goods.vue @@ -46,7 +46,8 @@ 加入购物车 - 立即购买 + 立即购买 + 库存不足 @@ -102,16 +103,12 @@ - + - 数量 @@ -336,12 +333,11 @@ methods: { getGood(id) { this.$u.api.getGood(id).then(res => { - let good = res.data + let good = res.data; + good._num = 1;//购买数 if (good.content) { good.content = richTextUtil.formatRichText(good.content); - good._num = 1;//购买数 } - // console.log(good) this.good = good }) }, @@ -399,13 +395,6 @@ buy() { this.action = 'buy'; this.specClass = 'show' - // this.showSpec() - // if(this.selectSpec==null){ - // return this.showSpec(()=>{ - // this.toConfirmation(); - // }); - // } - // this.toConfirmation(); }, //商品评论 toRatings() { @@ -524,24 +513,25 @@ }, //关闭规格弹窗 confirm() { - this.specClass = 'none'; - //回调 - - // this.selectSpec&&this.specCallback&&this.specCallback(); - // this.specCallback = false; - // setTimeout(() => { - // this.specClass = 'none'; - // }, 200); - if (this.action == 'buy') { - - this.toConfirmation() - } else { - this.$u.api.addtoCart(this.good.id, this.good._num).then(res => { - uni.showToast({ - title: "已加入购物车" - }); - }) - + debugger; + let num = parseInt(this.good._num); + if(num>this.good.num){ + uni.showToast({ + icon:'error', + title: "库存不足!" + }); + }else{ + this.specClass = 'none'; + if (this.action == 'buy') { + + this.toConfirmation() + } else { + this.$u.api.addtoCart(this.good.id, this.good._num).then(res => { + uni.showToast({ + title: "已加入购物车" + }); + }) + } } }, discard() {