فهرست منبع

增加判断提示

htc 1 ماه پیش
والد
کامیت
97c62c1e21
1فایلهای تغییر یافته به همراه19 افزوده شده و 9 حذف شده
  1. 19 9
      pagesStorage/inStorage/scan.vue

+ 19 - 9
pagesStorage/inStorage/scan.vue

@@ -47,16 +47,26 @@
 			scan(){
 				uni.scanCode({
 					success: (res) => {
-						let d = JSON.parse(res.result);
-						if(!d.hasOwnProperty('skuId')) return
-						let fi = this.list.findIndex(l=>l.skuId==d.skuId);
-						if(fi>=0){
-							this.$set(this.list[fi],'quantity',++this.list[fi].quantity);
-						}else{
-							d.quantity = 1;
-							d.amount = 0;
-							this.list = [...this.list,d]
+						try{
+							let d = JSON.parse(res.result);
+							if(!d.hasOwnProperty('skuId')||!d){
+								this.$showToast('请扫描正确的商品二维码');
+								return
+							} 
+							let fi = this.list.findIndex(l=>l.skuId==d.skuId);
+							if(fi>=0){
+								this.$set(this.list[fi],'quantity',++this.list[fi].quantity);
+							}else{
+								d.quantity = 1;
+								d.amount = 0;
+								this.list = [...this.list,d]
+							}
+						}catch(e){
+							this.$showToast('请扫描正确的商品二维码');
 						}
+					},
+					fail: (err) => {
+						this.$showToast('请扫描正确的商品二维码');
 					}
 				})
 			},