fix/modulo-bultos-filtros-y-detalles
This commit is contained in:
@@ -48,10 +48,15 @@ export async function getPackages(
|
|||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
page: page.toString(),
|
page: page.toString(),
|
||||||
page_size: pageSize.toString(),
|
page_size: pageSize.toString(),
|
||||||
company_id: companyId.toString(),
|
company_id: companyId.toString()
|
||||||
...filters
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Omitir filtros vacíos: URLSearchParams convierte `undefined`/`null` en el
|
||||||
|
// string literal "undefined", lo que rompería el ilike del backend.
|
||||||
|
for (const [k, v] of Object.entries(filters)) {
|
||||||
|
if (v !== undefined && v !== null && v !== '') params.set(k, String(v));
|
||||||
|
}
|
||||||
|
|
||||||
return await api.get(`/v1/a76/packages/?${params.toString()}`);
|
return await api.get(`/v1/a76/packages/?${params.toString()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Dialog.Root bind:open>
|
<Dialog.Root bind:open>
|
||||||
<Dialog.Content class="max-w-2xl max-h-[90vh] overflow-y-auto">
|
<Dialog.Content
|
||||||
|
class="max-w-2xl max-h-[90vh] overflow-y-auto"
|
||||||
|
onInteractOutside={(e) => e.preventDefault()}
|
||||||
|
>
|
||||||
<Dialog.Header>
|
<Dialog.Header>
|
||||||
<Dialog.Title>{title}</Dialog.Title>
|
<Dialog.Title>{title}</Dialog.Title>
|
||||||
<Dialog.Description>
|
<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 * as Card from '$lib/components/ui/card';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { Input } from '$lib/components/ui/input';
|
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 { useShortcuts } from '$lib/hooks/use-shortcuts';
|
||||||
import { obtenerAtajosListaBultos } from '$lib/config/shortcuts/dashboard/general_catalogs/packages/list';
|
import { obtenerAtajosListaBultos } from '$lib/config/shortcuts/dashboard/general_catalogs/packages/list';
|
||||||
import { packagesApi, type Package } from '$lib/api/dashboard/a76/general_catalogs/packages';
|
import { packagesApi, type Package } from '$lib/api/dashboard/a76/general_catalogs/packages';
|
||||||
@@ -48,8 +48,8 @@ manejarActualizar: () => reloadData()
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Filtros
|
// Filtros
|
||||||
let searchCode = $state($page.url.searchParams.get('code') || '');
|
let searchCode = $state($page.url.searchParams.get('key') || '');
|
||||||
let searchDesc = $state($page.url.searchParams.get('description') || '');
|
let searchDesc = $state($page.url.searchParams.get('description_es') || '');
|
||||||
let timeout: ReturnType<typeof setTimeout>;
|
let timeout: ReturnType<typeof setTimeout>;
|
||||||
|
|
||||||
let allItems = $state<Package[]>(data.packages?.items || data.packages || []);
|
let allItems = $state<Package[]>(data.packages?.items || data.packages || []);
|
||||||
@@ -83,8 +83,8 @@ loading = true;
|
|||||||
error = null;
|
error = null;
|
||||||
try {
|
try {
|
||||||
const response = await packagesApi.list(companyStore.activeCompany.id, {
|
const response = await packagesApi.list(companyStore.activeCompany.id, {
|
||||||
code: searchCode || undefined,
|
key: searchCode || undefined,
|
||||||
description: searchDesc || undefined,
|
description_es: searchDesc || undefined,
|
||||||
page: '1',
|
page: '1',
|
||||||
page_size: pageSize.toString()
|
page_size: pageSize.toString()
|
||||||
});
|
});
|
||||||
@@ -100,10 +100,10 @@ loading = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
const url = new URL($page.url);
|
const url = new URL($page.url);
|
||||||
if (searchCode) url.searchParams.set('code', searchCode);
|
if (searchCode) url.searchParams.set('key', searchCode);
|
||||||
else url.searchParams.delete('code');
|
else url.searchParams.delete('key');
|
||||||
if (searchDesc) url.searchParams.set('description', searchDesc);
|
if (searchDesc) url.searchParams.set('description_es', searchDesc);
|
||||||
else url.searchParams.delete('description');
|
else url.searchParams.delete('description_es');
|
||||||
history.replaceState(history.state, '', url);
|
history.replaceState(history.state, '', url);
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
@@ -113,8 +113,8 @@ if (loading || !hasMore || !companyStore.activeCompany) return;
|
|||||||
loading = true;
|
loading = true;
|
||||||
try {
|
try {
|
||||||
const response = await packagesApi.list(companyStore.activeCompany.id, {
|
const response = await packagesApi.list(companyStore.activeCompany.id, {
|
||||||
code: searchCode || undefined,
|
key: searchCode || undefined,
|
||||||
description: searchDesc || undefined,
|
description_es: searchDesc || undefined,
|
||||||
page: (currentPage + 1).toString(),
|
page: (currentPage + 1).toString(),
|
||||||
page_size: pageSize.toString()
|
page_size: pageSize.toString()
|
||||||
});
|
});
|
||||||
@@ -134,8 +134,8 @@ loading = true;
|
|||||||
error = null;
|
error = null;
|
||||||
try {
|
try {
|
||||||
const response = await packagesApi.list(companyStore.activeCompany.id, {
|
const response = await packagesApi.list(companyStore.activeCompany.id, {
|
||||||
code: searchCode || undefined,
|
key: searchCode || undefined,
|
||||||
description: searchDesc || undefined,
|
description_es: searchDesc || undefined,
|
||||||
page: '1',
|
page: '1',
|
||||||
page_size: pageSize.toString()
|
page_size: pageSize.toString()
|
||||||
});
|
});
|
||||||
@@ -166,9 +166,6 @@ const columns = $derived(createColumns(handleSuccess, { canEdit, canDelete }));
|
|||||||
<p class="text-muted-foreground">{m['common.sub_packages']()}</p>
|
<p class="text-muted-foreground">{m['common.sub_packages']()}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-3">
|
<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}
|
{#if !isError && canCreate}
|
||||||
<Button class="h-9" onclick={() => { editingItem = null; createDialogOpen = true; }}>
|
<Button class="h-9" onclick={() => { editingItem = null; createDialogOpen = true; }}>
|
||||||
<Plus class="mr-2 h-4 w-4" /> {m['common.btn_new_record']()}
|
<Plus class="mr-2 h-4 w-4" /> {m['common.btn_new_record']()}
|
||||||
@@ -189,7 +186,7 @@ onRetry={reloadData}
|
|||||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||||
<Card.Title>Listado de Embalajes</Card.Title>
|
<Card.Title>Listado de Embalajes</Card.Title>
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
<Input placeholder="Código" bind:value={searchCode} oninput={handleSearch} class="h-9 w-36 bg-card lg:w-44" />
|
<Input placeholder="Clave" bind:value={searchCode} oninput={handleSearch} class="h-9 w-36 bg-card lg:w-44" />
|
||||||
<Input placeholder="Descripción" bind:value={searchDesc} oninput={handleSearch} class="h-9 w-44 bg-card lg:w-64" />
|
<Input placeholder="Descripción" bind:value={searchDesc} oninput={handleSearch} class="h-9 w-44 bg-card lg:w-64" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user