diff --git a/src/pages/catalog.vue b/src/pages/catalog.vue index 68376d2..48ef7e9 100644 --- a/src/pages/catalog.vue +++ b/src/pages/catalog.vue @@ -87,6 +87,98 @@ + + + + + Confirmar Compra + + + + + + {{ item.name }} + + {{ currency(item.price) }} x {{ item.quantity }} + + + + {{ currency(item.price * item.quantity) }} + + + + + + + Total + {{ + currency(cartStore.cartTotal) + }} + + + + + Cancelar + Confirmar + + + + + + + + Datos de Contacto + + + + + + + + + + + Cancelar + + Finalizar Compra + + + + @@ -137,6 +229,20 @@ export default { currentPage: 1, itemsPerPage: 20, itemsPerPageOptions: [10, 20, 50, 100], + checkoutDialog: false, + personalDataDialog: false, + customerName: "", + customerAddress: "", + customerPhone: "", + pickupMethod: "STORE", + pickupOptions: [ + { text: "En Sitio", value: "STORE" }, + { text: "Domicilio", value: "DELIVERY" }, + ], + isSubmitting: false, + rules: { + required: (value) => !!value || "Requerido.", + }, }; }, computed: { @@ -178,11 +284,11 @@ export default { if (this.totalPages <= 7) { return this.totalPages; } - + // Breakpoints responsivos basados en windowWidth // OPTIMIZADO: Reducidos para evitar que desaparezcan los iconos de navegación const width = this.windowWidth; - + if (width < 400) { return 3; // Extra small mobile } else if (width < 680) { @@ -255,7 +361,65 @@ export default { } }, goToCheckout() { - this.$router.push("/comprar"); + this.checkoutDialog = true; + }, + onConfirmCheckout() { + this.checkoutDialog = false; + this.personalDataDialog = true; + }, + cancelPurchase() { + this.checkoutDialog = false; + this.personalDataDialog = false; + this.customerName = ""; + this.customerAddress = ""; + this.customerPhone = ""; + this.pickupMethod = "STORE"; + }, + async onSubmitPurchase() { + const form = this.$refs.personalForm; + + if (form) { + const { valid } = await form.validate(); + if (!valid) return; + } + this.isSubmitting = true; + const payload = { + date: this.getCurrentDate(), + customer: 1, + notes: "", + payment_method: "CASH", + saleline_set: this.cartItems.map((item) => ({ + product: item.id, + unit_price: item.price, + quantity: item.quantity, + measuring_unit: item.measuring_unit || "Unidad", + })), + customer_name: this.customerName, + customer_address: this.customerAddress, + customer_phone: this.customerPhone, + pickup_method: this.pickupMethod, + }; + + this.api + .createCatalogPurchase(payload) + .then((data) => { + this.cartStore.clearCart(); + this.personalDataDialog = false; + this.$router.push({ + path: "/summary_purchase", + query: { id: parseInt(data.id) }, + }); + }) + .catch((error) => { + console.error("Error al crear la compra:", error); + this.isSubmitting = false; + }); + }, + getCurrentDate() { + const today = new Date(); + const gmtOffSet = -5; + const localDate = new Date(today.getTime() + gmtOffSet * 60 * 60 * 1000); + return localDate.toISOString().slice(0, 16); }, toggleCart() { this.cartCollapsed = !this.cartCollapsed; @@ -396,4 +560,9 @@ export default { margin-bottom: 14px; } } + +.product-list-scroll { + max-height: 400px; + overflow-y: auto; +} diff --git a/src/services/api.js b/src/services/api.js index cd9c455..dbd2b8b 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -1,67 +1,71 @@ class Api { - constructor (apiImplementation) { - this.apiImplementation = apiImplementation; - } + constructor(apiImplementation) { + this.apiImplementation = apiImplementation; + } - getCustomers() { - return this.apiImplementation.getCustomers(); - } + getCustomers() { + return this.apiImplementation.getCustomers(); + } - getProducts() { - return this.apiImplementation.getProducts(); - } + getProducts() { + return this.apiImplementation.getProducts(); + } - getPaymentMethods() { - return this.apiImplementation.getPaymentMethods(); - } + getPaymentMethods() { + return this.apiImplementation.getPaymentMethods(); + } - getSummaryPurchase(purchaseId) { - return this.apiImplementation.getSummaryPurchase(purchaseId); - } + getSummaryPurchase(purchaseId) { + return this.apiImplementation.getSummaryPurchase(purchaseId); + } - getPurchasesForReconciliation() { - return this.apiImplementation.getPurchasesForReconciliation(); - } + getPurchasesForReconciliation() { + return this.apiImplementation.getPurchasesForReconciliation(); + } - getListReconcliations(page=1, itemsPerPage=10) { - return this.apiImplementation.getListReconcliations(page, itemsPerPage); - } + getListReconcliations(page = 1, itemsPerPage = 10) { + return this.apiImplementation.getListReconcliations(page, itemsPerPage); + } - getReconciliation(reconciliationId) { - return this.apiImplementation.getReconciliation(reconciliationId); - } + getReconciliation(reconciliationId) { + return this.apiImplementation.getReconciliation(reconciliationId); + } - createPurchase(purchase) { - return this.apiImplementation.createPurchase(purchase); - } + createPurchase(purchase) { + return this.apiImplementation.createCatalogPurchase(purchase); + } - createReconciliationJar(reconciliation) { - return this.apiImplementation.createReconciliationJar(reconciliation); - } + createCatalogPurchase(purchase) { + return this.apiImplementation.createPurchase(purchase); + } - createCustomer(customer) { - return this.apiImplementation.createCustomer(customer); - } + createReconciliationJar(reconciliation) { + return this.apiImplementation.createReconciliationJar(reconciliation); + } - getCSVForTryton() { - return this.apiImplementation.getCSVForTryton(); - } + createCustomer(customer) { + return this.apiImplementation.createCustomer(customer); + } - getProductsFromTryton() { - return this.apiImplementation.getProductsFromTryton(); - } + getCSVForTryton() { + return this.apiImplementation.getCSVForTryton(); + } - getCustomersFromTryton() { - return this.apiImplementation.getCustomersFromTryton(); - } + getProductsFromTryton() { + return this.apiImplementation.getProductsFromTryton(); + } - sendSalesToTryton(){ - return this.apiImplementation.sendSalesToTryton(); - } + getCustomersFromTryton() { + return this.apiImplementation.getCustomersFromTryton(); + } - getCurrentUser() { - return this.apiImplementation.getCurrentUser(); - } + sendSalesToTryton() { + return this.apiImplementation.sendSalesToTryton(); + } + + getCurrentUser() { + return this.apiImplementation.getCurrentUser(); + } } export default Api; diff --git a/src/services/django-api.js b/src/services/django-api.js index f4171c9..3544e25 100644 --- a/src/services/django-api.js +++ b/src/services/django-api.js @@ -60,6 +60,11 @@ class DjangoApi { return this.postRequest(url, purchase); } + createCatalogPurchase(purchase) { + const url = this.base + "/don_confiao/api/catalog_sales/"; + return this.postRequest(url, purchase); + } + createReconciliationJar(reconciliation) { const url = this.base + "/don_confiao/reconciliate_jar"; return this.postRequest(url, reconciliation);