fix: pop out the warning when scanning a undefine product

This commit is contained in:
snsd0805 2023-06-12 19:42:20 +08:00
parent a7ce5cfd7e
commit 287d0aa41d
Signed by: snsd0805
GPG Key ID: 569349933C77A854

View File

@ -65,6 +65,7 @@ export default {
onScanSuccess(decodedText, decodedResult) {
// handle the scanned code as you like, for example:
console.log(`Code matched = ${decodedText}`, decodedResult);
if (decodedText in this.products){
var product = this.products[decodedText]
this.productCar.push({
'name': product['name'],
@ -72,6 +73,10 @@ export default {
'price': product['price'],
'count': 1
})
} else {
this.msg = "商品列表中沒有這項商品:"+decodedText
this.warningModalStatus = true
}
this.scanner.clear()
},
scan() {
@ -130,7 +135,7 @@ export default {
</div>
<div class="block">
<button class="button is-success is-outlined is-large" @click="scan">掃描商品條碼</button>
<div id="reader" width="300px"></div>
<div id="reader" width="200px"></div>
</div>
<div class="block">
<table class="table is-fullwidth">