pedi2/resources/js/components/pedidos/ProductoCantidad.vue

140 lines
4.8 KiB
Vue
Raw Normal View History

2024-09-15 12:48:34 -03:00
<template>
2024-10-08 20:28:58 -03:00
<div>
<div class="field has-addons contador">
<div class="control">
<button class="button is-small" @click.capture="decrementar();">
<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>
<button :disabled="disableConfirm()" class="button is-small is-success ml-1" @click="confirmar()">
2024-10-08 20:28:58 -03:00
<span class="icon">
<i class="fas fa-check"></i>
</span>
2024-09-15 12:48:34 -03:00
</button>
2024-10-08 20:28:58 -03:00
<button :disabled="!puedeBorrar()" class="button is-small is-danger ml-1" @click="borrar()">
<span class="icon">
<i class="fas fa-trash-alt"></i>
</span>
2024-09-15 12:48:34 -03:00
</button>
</div>
<div v-if="producto.requiere_notas" v-bind:class="{'has-icons-right': notas_warning_visible}" class="control is-full-width has-icons-left">
<span class="icon is-small is-left">
<i class="fas fa-sticky-note"></i>
</span>
<input v-model="notas" v-bind:class="{'is-danger': notas_warning_visible}" id="notas" class="input" type="text" placeholder="Talle o color" />
<span v-if="notas_warning_visible" class="icon is-small is-right">
<i class="fas fa-exclamation-triangle"></i>
</span>
<article v-if="notas_warning_visible" class="message is-danger is-small">
<div class="message-body">
No se puede dejar este campo vac&iacute;o
</div>
</article>
2024-10-08 20:16:25 -03:00
</div>
2024-09-15 12:48:34 -03:00
</div>
</template>
<script>
export default {
props: {
producto: Object
},
data() {
return {
2024-10-08 20:16:25 -03:00
cantidad: this.cantidadEnChismosa(),
notas: this.notasEnChismosa(),
notas_warning_visible: false,
2024-09-15 12:48:34 -03:00
}
},
mounted() {
2024-10-08 20:16:25 -03:00
Event.$on('sync-subpedido', (cantidad, productoId, notas) => {
if (this.producto.id === productoId)
this.sincronizar(cantidad, notas);
2024-09-15 12:48:34 -03:00
});
},
methods: {
2024-10-08 20:16:25 -03:00
notasEnChismosa() {
return this.producto.pivot !== undefined ? this.producto.pivot.notas : "";
},
cantidadEnChismosa() {
return this.producto.pivot !== undefined ? this.producto.pivot.cantidad : 0;
},
2024-09-15 12:48:34 -03:00
decrementar() {
this.cantidad -= 1;
},
incrementar() {
this.cantidad += 1;
},
confirmar() {
if (this.warningNotas()) {
this.notas_warning_visible = true;
return;
}
2024-10-08 20:16:25 -03:00
console.log("Emit sync " + this.cantidad + " " + this.notas);
Event.$emit('sync-subpedido', this.cantidad, this.producto.id, this.notas);
2024-09-15 12:48:34 -03:00
},
borrar() {
this.cantidad = 0;
this.confirmar();
},
2024-10-08 20:16:25 -03:00
sincronizar(cantidad, notas) {
this.notas_warning_visible = false;
2024-10-08 20:16:25 -03:00
this.notas = notas;
2024-09-15 12:48:34 -03:00
this.cantidad = cantidad;
2024-10-08 20:16:25 -03:00
if (this.producto.pivot !== undefined) {
2024-09-16 09:25:26 -03:00
this.producto.pivot.cantidad = cantidad;
2024-10-08 20:16:25 -03:00
this.producto.pivot.notas = notas;
2024-09-16 09:25:26 -03:00
}
2024-09-15 12:48:34 -03:00
},
hayCambios() {
if (this.cantidad != this.cantidadEnChismosa()) return true;
return this.cantidad > 0 && this.notas != this.notasEnChismosa();
2024-09-15 12:48:34 -03:00
},
puedeBorrar() {
2024-10-08 20:16:25 -03:00
return this.cantidadEnChismosa() > 0;
2024-09-15 12:48:34 -03:00
},
warningNotas() {
return this.producto.requiere_notas && this.cantidad > 0 && !this.notas;
},
disableConfirm() {
return !this.hayCambios();
},
2024-09-15 12:48:34 -03:00
}
}
</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;
}
.is-danger {
background-color: #fca697;
}
.is-danger::placeholder {
color: #fff;
opacity: 1; /* Firefox */
}
2024-09-15 12:48:34 -03:00
</style>