feat(Purchase): warn user whit browser actions #67.

This commit is contained in:
Mono Mono 2024-11-11 22:45:47 -05:00
parent 201333ab4b
commit 159bd737c4

View File

@ -1,6 +1,6 @@
<template> <template>
<v-container> <v-container>
<v-form ref="purchase" v-model="valid" > <v-form ref="purchase" v-model="valid" @change="onFormChange">
<v-row> <v-row>
<v-col> <v-col>
<v-autocomplete <v-autocomplete
@ -10,6 +10,7 @@
no-data-text="No se hallaron clientes" no-data-text="No se hallaron clientes"
item-title="name" item-title="name"
item-value="id" item-value="id"
@update:model-value="onFormChange"
label="Cliente" label="Cliente"
:rules="[rules.required]" :rules="[rules.required]"
required required
@ -156,6 +157,7 @@
data() { data() {
return { return {
valid: false, valid: false,
form_changed: false,
show_alert_lines: false, show_alert_lines: false,
show_alert_purchase: false, show_alert_purchase: false,
client_search: '', client_search: '',
@ -189,6 +191,12 @@
this.drawer = false this.drawer = false
}, },
}, },
beforeMount() {
window.addEventListener('beforeunload', this.confirmLeave);
},
beforeDestroy() {
window.removeEventListener('beforeunload', this.confirmLeave);
},
computed: { computed: {
calculateTotal() { calculateTotal() {
return this.purchase.saleline_set.reduce((total, saleline) => { return this.purchase.saleline_set.reduce((total, saleline) => {
@ -218,9 +226,20 @@
openModal() { openModal() {
this.$refs.customerModal.openModal(); this.$refs.customerModal.openModal();
}, },
onFormChange() {
this.form_changed = true;
},
openCasherModal() { openCasherModal() {
this.$refs.casherModal.dialog = true this.$refs.casherModal.dialog = true
}, },
confirmLeave(event) {
if (this.form_changed) {
const message = '¿seguro que quieres salir? Perderas la información diligenciada';
event.preventDefault();
event.returnValue = message;
return message;
}
},
getCurrentDate() { getCurrentDate() {
const today = new Date(); const today = new Date();
const yyyy = today.getFullYear(); const yyyy = today.getFullYear();
@ -233,7 +252,6 @@
const selectedProductId = this.purchase.saleline_set[index].product; const selectedProductId = this.purchase.saleline_set[index].product;
const selectedProduct = this.products.find(p => p.id == selectedProductId); const selectedProduct = this.products.find(p => p.id == selectedProductId);
this.purchase.saleline_set[index].unit_price = selectedProduct.price; this.purchase.saleline_set[index].unit_price = selectedProduct.price;
console.log(selectedProduct.measuring_unit);
this.purchase.saleline_set[index].measuring_unit = selectedProduct.measuring_unit; this.purchase.saleline_set[index].measuring_unit = selectedProduct.measuring_unit;
}, },
fetchClients() { fetchClients() {