From 70aaadd901f946dfba86d8574a0ba469cd915249 Mon Sep 17 00:00:00 2001 From: Ale Date: Sat, 27 May 2023 20:08:55 -0300 Subject: [PATCH] refactor de chismosa --- resources/js/app.js | 69 ++++++++-- resources/js/components/Chismosa.vue | 86 ++++++------- resources/js/components/ChismosaDropdown.vue | 64 ++++++++++ resources/js/components/Login.vue | 4 +- resources/js/components/NavBar.vue | 125 ++++++------------- resources/js/components/ProductoModal.vue | 2 +- resources/js/components/ProductoRow.vue | 2 +- resources/js/components/SubpedidoSelect.vue | 7 +- resources/sass/app.scss | 4 - 9 files changed, 204 insertions(+), 159 deletions(-) create mode 100644 resources/js/components/ChismosaDropdown.vue diff --git a/resources/js/app.js b/resources/js/app.js index 7c8a5b4..18712d5 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -5,6 +5,7 @@ */ import axios from 'axios'; import animate from 'animate.css'; +import Vue from 'vue'; window.Vue = require('vue'); window.Event = new Vue(); window.axios = axios; @@ -17,32 +18,74 @@ window.bulmaToast = require('bulma-toast'); * * Eg. ./components/ExampleComponent.vue -> */ - const files = require.context('./', true, /\.vue$/i) files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default)) - /** - * Global data + * Constants */ -Vue.prototype.$gdc = null -Vue.prototype.$pedido = - {id: null, nombre: null, grupo_de_compra_id: null, created_at: null, updated_at: null} -Vue.prototype.$rootMiga = - {nombre: "Categorías", href: "/productos"} - +Vue.prototype.$rootMiga = { + nombre: "Categorías", + href: "/productos" +} /** * Global methods */ -Vue.prototype.$settearProducto = - function(cantidad, id) { Event.$emit("sync-subpedido", this.cant, this.producto.id) } +Vue.prototype.$settearProducto = function(cantidad, id) { + Event.$emit("sync-subpedido", this.cant, this.producto.id) +} +Vue.prototype.$toast = function(mensaje) { + return window.bulmaToast.toast({ + message: mensaje, + duration: 1000, + type: 'is-danger', + position: 'bottom-center', + animate: { in: 'fadeIn', out: 'fadeOut' } + }); +} /** * Next, we will create a fresh Vue application instance and attach it to * the page. Then, you may begin adding components to this application * or customize the JavaScript scaffolding to fit your unique needs. */ - const app = new Vue({ - el: '#root' + el: '#root', + data() { + return { + gdc: null, + pedido: null + } + }, + mounted() { + Event.$on('obtener-sesion', () => { + axios.get('/subpedidos/obtener_sesion') + .then(response => { + this.pedido = response.data.subpedido.id + axios.get('/api/subpedidos/' + this.pedido) + .then(response => { + this.pedido = response.data.data + this.gdc = this.pedido.grupo_de_compra.id + }) + }) + }) + Event.$on('sync-subpedido', (cantidad, id) => { + axios.post("/api/subpedidos/" + this.pedido.id + "/sync", { + cantidad: cantidad, + producto_id: id + }).then((response) => { + this.pedido = response.data.data + this.$toast('Pedido actualizado exitosamente') + }); + }); + Event.$on('aprobacion-subpedido', (subpedidoId, aprobado) => { + axios.post("/api/admin/subpedidos/" + subpedidoId + "/aprobacion", { + aprobacion: aprobado + }).then((response) => { + Event.$emit('sync-aprobacion', response.data.data); + this.$toast('Pedido ' + (aprobado ? 'aprobado' : 'desaprobado') + ' exitosamente') + }) + }) + Event.$emit('obtener-sesion') + }, }); diff --git a/resources/js/components/Chismosa.vue b/resources/js/components/Chismosa.vue index aa6ebe1..c6b140d 100644 --- a/resources/js/components/Chismosa.vue +++ b/resources/js/components/Chismosa.vue @@ -1,6 +1,6 @@ @@ -38,55 +47,36 @@ export default { data() { return { - subpedido: { - productos:[] - }, - init: true, - visible: false + subpedido: this.$root.pedido } }, computed: { - animation: function() { - return this.visible ? "animate__slideInDown" : "animate__slideOutUp"; + productos: function() { + return this.$root.pedido.productos + }, + cantidadBonosDeTransporte: function() { + return this.$root.pedido.subtotal_bonos_de_transporte / 15 + }, + totalBonosDeTransporte: function() { + return this.$root.pedido.subtotal_bonos_de_transporte + }, + cantidadBonos: function() { + return this.$root.pedido.subtotal_bonos / 20 + }, + totalBonos: function() { + return this.$root.pedido.subtotal_bonos + }, + total: function() { + return this.$root.pedido.total } }, - beforeCreate() { - axios.get("/subpedidos/obtener_sesion").then(response => { - this.subpedido = response.data.subpedido; - this.fetchSubpedido(); - }); - }, - methods: { - fetchSubpedido() { - axios.get("/api/subpedidos/" + this.subpedido.id) - .then(response => { - this.subpedido = response.data.data; - }); - } - }, - mounted() { - Event.$on('sync-chismosa', (subpedido) => { - this.subpedido = subpedido; - }); - Event.$on('toggle-chismosa', () => { - this.init = false; - this.visible = !this.visible; - var main = document.getElementById("main"); - if (this.visible) main.classList.add("chisma-abierta"); - else main.classList.remove("chisma-abierta"); - }); - } } \ No newline at end of file diff --git a/resources/js/components/ChismosaDropdown.vue b/resources/js/components/ChismosaDropdown.vue new file mode 100644 index 0000000..c90c4d0 --- /dev/null +++ b/resources/js/components/ChismosaDropdown.vue @@ -0,0 +1,64 @@ + + + + + \ No newline at end of file diff --git a/resources/js/components/Login.vue b/resources/js/components/Login.vue index a008734..6530957 100644 --- a/resources/js/components/Login.vue +++ b/resources/js/components/Login.vue @@ -28,14 +28,14 @@ data() { return { visible: false, - gdc: this.$gdc, + gdc: this.$root.gdc, passwordVisible: false, passwordType: "password", } }, mounted() { Event.$on('gdc-seleccionado', (gdc) => { - this.gdc = gdc; + this.$root.gdc = gdc; this.visible = true; }); }, diff --git a/resources/js/components/NavBar.vue b/resources/js/components/NavBar.vue index 0587b63..7c266b1 100644 --- a/resources/js/components/NavBar.vue +++ b/resources/js/components/NavBar.vue @@ -1,45 +1,36 @@ diff --git a/resources/js/components/ProductoModal.vue b/resources/js/components/ProductoModal.vue index c41dbb2..de9db3e 100644 --- a/resources/js/components/ProductoModal.vue +++ b/resources/js/components/ProductoModal.vue @@ -83,7 +83,7 @@ if (this.cant < 0) alert("No se puede agregar cantidades negativas") else if (!Number.isInteger(this.cant)) alert("Las cantidades deben ser números enteros") else { - this.$settearProducto(this.cant, this.producto.id); + Event.$emit('sync-subpedido',this.cant, this.producto.id); this.cerrar(); } } diff --git a/resources/js/components/ProductoRow.vue b/resources/js/components/ProductoRow.vue index c39a9bd..c583fc2 100644 --- a/resources/js/components/ProductoRow.vue +++ b/resources/js/components/ProductoRow.vue @@ -2,7 +2,7 @@ {{ this.producto.nombre }} {{ this.producto.pivot.cantidad }} - {{ this.producto.pivot.total }} + {{ Math.ceil(this.producto.pivot.total) }}