pcpuma_unam_operador/components/operador/Scanner.vue
2022-10-02 21:55:30 -05:00

43 lines
1.0 KiB
Vue

<template>
<QrcodeStream @decode="onDecode"> </QrcodeStream>
</template>
<script>
import { QrcodeStream } from 'vue-qrcode-reader'
export default {
components: { QrcodeStream },
props: {
prestamoIdPrestamo: { type: Function, required: true, default: () => {} },
resetTab: { type: Function, required: true, default: () => {} },
},
data() {
return { idPrestamo: '' }
},
methods: {
resetear() {
if (this.idPrestamo) this.idPrestamo = ''
},
onDecode(decodedString) {
let decodedData = {}
try {
decodedData = JSON.parse(decodedString)
} catch (err) {
this.resetear()
}
this.resetTab()
if (decodedData.id_prestamo) {
if (typeof decodedData.id_prestamo === 'number')
this.idPrestamo = decodedData.id_prestamo.toString()
else this.idPrestamo = decodedData.id_prestamo
}
if (this.idPrestamo)
this.prestamoIdPrestamo(this.idPrestamo, this.resetear)
},
},
}
</script>
<style></style>