-
-
+
+
+
+
Dirección
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/modules/catalog/components/suppliers/Suppliers.vue b/src/modules/catalog/components/suppliers/Suppliers.vue
index 806bf72..a6a3479 100644
--- a/src/modules/catalog/components/suppliers/Suppliers.vue
+++ b/src/modules/catalog/components/suppliers/Suppliers.vue
@@ -15,8 +15,9 @@ import { useToast } from 'primevue/usetoast';
-import { supplierServices } from '../../services/supplierServices';
-import type { Supplier, SupplierPaginatedResponse, SupplierFormErrors } from '../../types/suppliers';
+import { supplierServices } from '../../services/supplier.services';
+import type { Supplier, SupplierPaginatedResponse, SupplierFormErrors } from '../../types/suppliers.interfaces';
+import { SupplierType } from '../../types/suppliers.interfaces';
import SupplierModal from './SupplierModal.vue';
@@ -29,6 +30,7 @@ const pagination = ref({
lastPage: 1,
});
const loading = ref(false);
+const loadingSupplier = ref(false);
// Modal state and form fields
const showModal = ref(false);
@@ -58,11 +60,12 @@ const handleDelete = (supplierId: number) => {
};
-const mapTypeToApi = (type: string) => {
- switch (type) {
- case 'General': return 'general';
- case 'Compra': return 'purchases';
- case 'Venta': return 'sales';
+const mapTypeToApi = (typeLabel: string | null) => {
+ if (!typeLabel) return undefined;
+ switch (typeLabel) {
+ case 'Cliente': return SupplierType.CLIENT;
+ case 'Proveedor': return SupplierType.PROVIDER;
+ case 'Ambos': return SupplierType.BOTH;
default: return undefined;
}
};
@@ -71,17 +74,11 @@ const fetchSuppliers = async (page = 1) => {
loading.value = true;
try {
const name = searchName.value ? searchName.value : undefined;
- const type = selectedType.value ? mapTypeToApi(selectedType.value) : undefined;
+ const type = selectedType.value ? mapTypeToApi(selectedType.value)?.toString() : undefined;
console.log('🔎 fetchSuppliers params:', { paginated: true, name, type, page });
const response = await supplierServices.getSuppliers(true, name, type);
const paginated = response as SupplierPaginatedResponse;
- suppliers.value = paginated.data.map(s => ({
- ...s,
- email: s.contact_email,
- phone: s.phone_number,
- typeColor: s.type === 'general' ? 'info' : s.type === 'purchases' ? 'success' : 'warning',
- date: s.created_at ? new Date(s.created_at).toLocaleDateString() : ''
- }));
+ suppliers.value = paginated.data;
pagination.value.total = paginated.total;
pagination.value.page = paginated.current_page;
pagination.value.lastPage = paginated.last_page;
@@ -100,9 +97,9 @@ onMounted(() => {
const supplierTypes = [
{ label: 'Todos', value: null },
- { label: 'General', value: 'General' },
- { label: 'Compras', value: 'Compra' },
- { label: 'Ventas', value: 'Venta' },
+ { label: 'Cliente', value: 'Cliente' },
+ { label: 'Proveedor', value: 'Proveedor' },
+ { label: 'Ambos', value: 'Ambos' },
];
const selectedType = ref(null);
@@ -133,11 +130,27 @@ const openCreateModal = () => {
formErrors.value = {};
};
-const openEditModal = (supplier: Supplier) => {
+const openEditModal = async (supplier: Supplier) => {
isEditMode.value = true;
- showModal.value = true;
- currentSupplier.value = supplier;
formErrors.value = {};
+ loadingSupplier.value = true;
+
+ try {
+ // Obtener la información completa del proveedor incluyendo direcciones
+ const response = await supplierServices.getSupplierById(supplier.id);
+ currentSupplier.value = response.data;
+ showModal.value = true;
+ } catch (e: any) {
+ toast.add({
+ severity: 'error',
+ summary: 'Error',
+ detail: 'No se pudo cargar la información del proveedor',
+ life: 3000
+ });
+ console.error('Error loading supplier details:', e);
+ } finally {
+ loadingSupplier.value = false;
+ }
};
const closeModal = () => {
@@ -151,24 +164,10 @@ const handleModalSubmit = async (form: any) => {
formErrors.value = {};
try {
if (isEditMode.value && currentSupplier.value) {
- const payload = {
- name: form.name,
- contact_email: form.email,
- phone_number: form.phone,
- address: form.address,
- type: form.type,
- };
- await supplierServices.updateSupplier(currentSupplier.value.id, payload, 'patch');
+ await supplierServices.updateSupplier(currentSupplier.value.id, form, 'patch');
toast.add({ severity: 'success', summary: 'Proveedor actualizado', detail: 'Proveedor actualizado correctamente', life: 3000 });
} else {
- const payload = {
- name: form.name,
- contact_email: form.email,
- phone_number: form.phone,
- address: form.address,
- type: form.type,
- };
- await supplierServices.createSupplier(payload);
+ await supplierServices.createSupplier(form);
toast.add({ severity: 'success', summary: 'Proveedor creado', detail: 'Proveedor registrado correctamente', life: 3000 });
}
closeModal();
@@ -182,14 +181,24 @@ const handleModalSubmit = async (form: any) => {
};
// Mapeo para mostrar el tipo de proveedor con label legible
-const typeLabel = (type: string) => {
+const typeLabel = (type: number) => {
switch (type) {
- case 'general': return 'General';
- case 'purchases': return 'Compras';
- case 'sales': return 'Ventas';
- default: return type;
+ case SupplierType.CLIENT: return 'Cliente';
+ case SupplierType.PROVIDER: return 'Proveedor';
+ case SupplierType.BOTH: return 'Ambos';
+ default: return 'Desconocido';
}
};
+
+const typeSeverity = (type: number) => {
+ switch (type) {
+ case SupplierType.CLIENT: return 'info';
+ case SupplierType.PROVIDER: return 'success';
+ case SupplierType.BOTH: return 'warning';
+ default: return 'secondary';
+ }
+};
+
@@ -204,7 +213,7 @@ const typeLabel = (type: string) => {