2024-09-15 12:48:34 -03:00
|
|
|
<template>
|
2024-09-17 20:13:34 -03:00
|
|
|
<div class="field has-addons contador">
|
2024-09-15 12:48:34 -03:00
|
|
|
<div class="control">
|
2024-09-17 19:14:30 -03:00
|
|
|
<button class="button is-small" @click.capture="decrementar();">
|
2024-09-15 12:48:34 -03:00
|
|
|
<i class="fa fa-solid fa-minus"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="control">
|
|
|
|
<input id="cantidad" v-model="cantidad" class="input is-small" type="number" style="text-align: center">
|
|
|
|
</div>
|
|
|
|
<div class="control" @click="incrementar();">
|
|
|
|
<button class="button is-small">
|
|
|
|
<i class="fa fa-solid fa-plus"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
2024-09-17 20:13:34 -03:00
|
|
|
<button :disabled="!hayCambios()" class="button is-small is-success ml-1" @click="confirmar()">
|
2024-09-15 12:48:34 -03:00
|
|
|
<span class="icon">
|
|
|
|
<i class="fas fa-check"></i>
|
|
|
|
</span>
|
|
|
|
</button>
|
2024-09-17 20:13:34 -03:00
|
|
|
<button :disabled="!puedeBorrar()" class="button is-small is-danger ml-1" @click="borrar()">
|
2024-09-15 12:48:34 -03:00
|
|
|
<span class="icon">
|
|
|
|
<i class="fas fa-trash-alt"></i>
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
producto: Object
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
cantidad: this.producto.cantidad,
|
|
|
|
enChismosa: this.producto.cantidad,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2024-09-16 09:25:26 -03:00
|
|
|
if (this.producto.pivot !== undefined) {
|
|
|
|
this.cantidad = this.producto.pivot.cantidad;
|
|
|
|
this.enChismosa = this.cantidad;
|
|
|
|
}
|
2024-09-15 12:48:34 -03:00
|
|
|
Event.$on('sync-subpedido', (cantidad,productoId) => {
|
|
|
|
if (this.producto.id === productoId)
|
|
|
|
this.sincronizar(cantidad);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
decrementar() {
|
|
|
|
this.cantidad -= 1;
|
|
|
|
},
|
|
|
|
incrementar() {
|
|
|
|
this.cantidad += 1;
|
|
|
|
},
|
|
|
|
confirmar() {
|
|
|
|
Event.$emit('sync-subpedido', this.cantidad, this.producto.id);
|
|
|
|
},
|
|
|
|
borrar() {
|
|
|
|
this.cantidad = 0;
|
|
|
|
this.confirmar();
|
|
|
|
},
|
|
|
|
sincronizar(cantidad) {
|
|
|
|
this.cantidad = cantidad;
|
2024-09-16 09:25:26 -03:00
|
|
|
if (this.producto.pivot != null) {
|
|
|
|
this.producto.pivot.cantidad = cantidad;
|
|
|
|
} else {
|
|
|
|
this.producto.cantidad = cantidad;
|
|
|
|
}
|
2024-09-15 12:48:34 -03:00
|
|
|
this.enChismosa = cantidad;
|
|
|
|
},
|
|
|
|
hayCambios() {
|
|
|
|
return this.cantidad != this.enChismosa;
|
|
|
|
},
|
|
|
|
puedeBorrar() {
|
|
|
|
return this.enChismosa > 0;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
/* Chrome, Safari, Edge, Opera */
|
|
|
|
input::-webkit-outer-spin-button,
|
|
|
|
input::-webkit-inner-spin-button {
|
|
|
|
-webkit-appearance: none;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Firefox */
|
|
|
|
input[type=number] {
|
|
|
|
appearance: textfield;
|
|
|
|
-moz-appearance: textfield;
|
|
|
|
}
|
2024-09-17 20:13:34 -03:00
|
|
|
|
|
|
|
.contador {
|
|
|
|
min-width: 178px;
|
|
|
|
}
|
2024-09-15 12:48:34 -03:00
|
|
|
</style>
|