fix/conceptos-agente-aduanal-bugs-filtros-y-modal
This commit is contained in:
@@ -36,11 +36,22 @@ export async function getCustomsBrokerConcepts(
|
||||
companyId: number,
|
||||
filters: Record<string, any> = {},
|
||||
): Promise<ApiResponse<CustomsBrokerConceptListResponse>> {
|
||||
const cleanFilters = Object.fromEntries(
|
||||
Object.entries(filters).filter(([, value]) => {
|
||||
if (value === undefined || value === null) return false;
|
||||
if (typeof value === 'string') {
|
||||
const trimmed = value.trim();
|
||||
return trimmed !== '' && trimmed.toLowerCase() !== 'undefined';
|
||||
}
|
||||
return true;
|
||||
})
|
||||
);
|
||||
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
company_id: companyId.toString(),
|
||||
...filters
|
||||
company_id: companyId.toString(),
|
||||
...cleanFilters
|
||||
});
|
||||
|
||||
return await api.get(`/v1/a76/customs-broker-concepts/?${params.toString()}`);
|
||||
|
||||
@@ -47,8 +47,20 @@
|
||||
let showBrokerSelector = $state(false);
|
||||
let selectedBrokerLabel = $state('');
|
||||
|
||||
// Cargar datos al editar
|
||||
function resetForm() {
|
||||
formData = {
|
||||
broker_key: '',
|
||||
concept: '',
|
||||
amount: undefined,
|
||||
priority: undefined
|
||||
};
|
||||
selectedBrokerLabel = '';
|
||||
}
|
||||
|
||||
// Cargar o limpiar datos al abrir el modal
|
||||
$effect(() => {
|
||||
if (!open) return;
|
||||
|
||||
if (item) {
|
||||
formData = {
|
||||
broker_key: item.broker_key || '',
|
||||
@@ -58,14 +70,10 @@
|
||||
};
|
||||
selectedBrokerLabel = item.broker_key || '';
|
||||
} else {
|
||||
formData = {
|
||||
broker_key: '',
|
||||
concept: '',
|
||||
amount: undefined,
|
||||
priority: undefined
|
||||
};
|
||||
selectedBrokerLabel = '';
|
||||
resetForm();
|
||||
}
|
||||
|
||||
error = null;
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
@@ -135,7 +143,10 @@
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
<Dialog.Content class="max-w-lg max-h-[90vh] overflow-y-auto">
|
||||
<Dialog.Content
|
||||
class="max-w-lg max-h-[90vh] overflow-y-auto"
|
||||
onInteractOutside={(e) => e.preventDefault()}
|
||||
>
|
||||
<Dialog.Header>
|
||||
<Dialog.Title>{title}</Dialog.Title>
|
||||
<Dialog.Description>
|
||||
|
||||
@@ -11,7 +11,7 @@ import InfiniteDataTable from '$lib/components/dashboard/common/infinite-data-ta
|
||||
import * as Card from '$lib/components/ui/card';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Pencil, Plus, Trash2, RefreshCw } from 'lucide-svelte';
|
||||
import { Pencil, Plus, Trash2 } from 'lucide-svelte';
|
||||
import { useShortcuts } from '$lib/hooks/use-shortcuts';
|
||||
import { obtenerAtajosListaConceptosAA } from '$lib/config/shortcuts/dashboard/general_catalogs/customs_broker_concepts/list';
|
||||
import { customsBrokerConceptsApi, type CustomsBrokerConcept } from '$lib/api/dashboard/a76/general_catalogs/customs-broker-concepts';
|
||||
@@ -48,8 +48,8 @@ manejarActualizar: () => reloadData()
|
||||
);
|
||||
|
||||
// Filtros
|
||||
let searchKey = $state($page.url.searchParams.get('code') || '');
|
||||
let searchDesc = $state($page.url.searchParams.get('description') || '');
|
||||
let searchBrokerKey = $state($page.url.searchParams.get('broker_key') || '');
|
||||
let searchConcept = $state($page.url.searchParams.get('concept') || '');
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
|
||||
let allItems = $state<CustomsBrokerConcept[]>(data.concepts?.items || []);
|
||||
@@ -83,10 +83,10 @@ loading = true;
|
||||
error = null;
|
||||
try {
|
||||
const response = await customsBrokerConceptsApi.list(1, pageSize, companyStore.activeCompany.id, {
|
||||
code: searchKey || undefined,
|
||||
description: searchDesc || undefined
|
||||
broker_key: searchBrokerKey || undefined,
|
||||
concept: searchConcept || undefined
|
||||
});
|
||||
const payload = response.data;
|
||||
const payload = (response as any).items ? response : (response as any).data;
|
||||
if (payload?.items) {
|
||||
allItems = payload.items;
|
||||
currentPage = payload.page || 1;
|
||||
@@ -99,10 +99,10 @@ loading = false;
|
||||
}
|
||||
|
||||
const url = new URL($page.url);
|
||||
if (searchKey) url.searchParams.set('code', searchKey);
|
||||
else url.searchParams.delete('code');
|
||||
if (searchDesc) url.searchParams.set('description', searchDesc);
|
||||
else url.searchParams.delete('description');
|
||||
if (searchBrokerKey) url.searchParams.set('broker_key', searchBrokerKey);
|
||||
else url.searchParams.delete('broker_key');
|
||||
if (searchConcept) url.searchParams.set('concept', searchConcept);
|
||||
else url.searchParams.delete('concept');
|
||||
history.replaceState(history.state, '', url);
|
||||
}, 500);
|
||||
}
|
||||
@@ -112,13 +112,13 @@ if (loading || !hasMore || !companyStore.activeCompany) return;
|
||||
loading = true;
|
||||
try {
|
||||
const response = await customsBrokerConceptsApi.list(currentPage + 1, pageSize, companyStore.activeCompany.id, {
|
||||
code: searchKey || undefined,
|
||||
description: searchDesc || undefined
|
||||
broker_key: searchBrokerKey || undefined,
|
||||
concept: searchConcept || undefined
|
||||
});
|
||||
const payload = response.data;
|
||||
const payload = (response as any).items ? response : (response as any).data;
|
||||
if (payload?.items) {
|
||||
allItems = [...allItems, ...payload.items];
|
||||
currentPage = payload.page || (currentPage + 1);
|
||||
currentPage = payload.page || currentPage + 1;
|
||||
totalItems = payload.total;
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -134,10 +134,10 @@ loading = true;
|
||||
error = null;
|
||||
try {
|
||||
const response = await customsBrokerConceptsApi.list(1, pageSize, companyStore.activeCompany.id, {
|
||||
code: searchKey || undefined,
|
||||
description: searchDesc || undefined
|
||||
broker_key: searchBrokerKey || undefined,
|
||||
concept: searchConcept || undefined
|
||||
});
|
||||
const payload = response.data;
|
||||
const payload = (response as any).items ? response : (response as any).data;
|
||||
if (payload?.items) {
|
||||
allItems = payload.items;
|
||||
currentPage = payload.page || 1;
|
||||
@@ -203,9 +203,6 @@ loading = false;
|
||||
<p class="text-muted-foreground">{m['common.sub_customs_broker_concepts']()}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<Button variant="outline" size="sm" class="h-9" onclick={reloadData}>
|
||||
<RefreshCw class="mr-2 h-4 w-4" /> {m['common.btn_refresh']()}
|
||||
</Button>
|
||||
{#if !isError && canCreate}
|
||||
<Button class="h-9" onclick={() => { editingItem = null; dialogOpen = true; }}>
|
||||
<Plus class="mr-2 h-4 w-4" /> {m['common.btn_new_record']()}
|
||||
@@ -226,8 +223,8 @@ onRetry={reloadData}
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<Card.Title>Listado</Card.Title>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Input placeholder="Código" bind:value={searchKey} oninput={handleSearch} class="h-9 w-40 bg-card lg:w-52" />
|
||||
<Input placeholder="Descripción" bind:value={searchDesc} oninput={handleSearch} class="h-9 w-44 bg-card lg:w-64" />
|
||||
<Input placeholder="Clave Agente" bind:value={searchBrokerKey} oninput={handleSearch} class="h-9 w-40 bg-card lg:w-52" />
|
||||
<Input placeholder="Concepto" bind:value={searchConcept} oninput={handleSearch} class="h-9 w-44 bg-card lg:w-64" />
|
||||
</div>
|
||||
</div>
|
||||
</Card.Header>
|
||||
|
||||
Reference in New Issue
Block a user