|
@@ -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('请扫描正确的商品二维码');
|
|
|
}
|
|
|
})
|
|
|
},
|