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>
|
2024-10-16 21:56:05 -03:00
|
|
|
<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>
|
2024-10-16 22:32:16 -03:00
|
|
|
<div v-if="producto.requiere_notas" v-bind:class="{'has-icons-right': notas_warning_visible}" class="control is-full-width has-icons-left">
|
2024-10-16 21:56:05 -03:00
|
|
|
<span class="icon is-small is-left">
|
|
|
|
<i class="fas fa-sticky-note"></i>
|
|
|
|
</span>
|
2024-10-16 22:32:16 -03:00
|
|
|
<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">
|
2024-10-16 21:56:05 -03:00
|
|
|
<i class="fas fa-exclamation-triangle"></i>
|
|
|
|
</span>
|
2024-10-16 22:32:16 -03:00
|
|
|
<article v-if="notas_warning_visible" class="message is-danger is-small">
|
2024-10-16 21:56:05 -03:00
|
|
|
<div class="message-body">
|
|
|
|
No se puede dejar este campo vací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(),
|
2024-10-16 22:32:16 -03:00
|
|
|
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() {
|
2024-10-16 22:32:16 -03:00
|
|
|
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) {
|
2024-10-16 22:32:16 -03:00
|
|
|
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() {
|
2024-10-08 20:33:20 -03:00
|
|
|
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
|
|
|
},
|
2024-10-16 21:56:05 -03:00
|
|
|
warningNotas() {
|
|
|
|
return this.producto.requiere_notas && this.cantidad > 0 && !this.notas;
|
|
|
|
},
|
|
|
|
disableConfirm() {
|
2024-10-16 22:32:16 -03:00
|
|
|
return !this.hayCambios();
|
2024-10-16 21:56:05 -03:00
|
|
|
},
|
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;
|
|
|
|
}
|
2024-10-16 21:56:05 -03:00
|
|
|
|
|
|
|
.is-danger {
|
|
|
|
background-color: #fca697;
|
|
|
|
}
|
|
|
|
.is-danger::placeholder {
|
|
|
|
color: #fff;
|
|
|
|
opacity: 1; /* Firefox */
|
|
|
|
}
|
2024-09-15 12:48:34 -03:00
|
|
|
</style>
|