feat: Integrate pedimento codes into the edit form and update data loading
This commit is contained in:
@@ -2,16 +2,25 @@
|
||||
import * as Card from '$lib/components/ui/card';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import * as Select from '$lib/components/ui/select';
|
||||
import type { Pedimento } from '$lib/api/dashboard/a76/pedimentos';
|
||||
import type { PedimentoCode } from '$lib/api/dashboard/refrence_data/pedimento_codes';
|
||||
|
||||
let {
|
||||
pedimento,
|
||||
formData = $bindable()
|
||||
formData = $bindable(),
|
||||
pedimentoCodes = []
|
||||
}: {
|
||||
pedimento: Pedimento | null;
|
||||
formData?: any;
|
||||
pedimentoCodes?: PedimentoCode[];
|
||||
} = $props();
|
||||
|
||||
// Debug: verificar que los datos llegan
|
||||
$effect(() => {
|
||||
console.log('pedimentoCodes:', pedimentoCodes.length, 'items');
|
||||
});
|
||||
|
||||
// Inicializar formData con los valores del pedimento (o vacío si es null)
|
||||
if (!formData) {
|
||||
formData = {
|
||||
@@ -32,6 +41,11 @@
|
||||
};
|
||||
}
|
||||
|
||||
const operationOptions = [
|
||||
{ value: 1, label: 'Exportación' },
|
||||
{ value: 2, label: 'Importación' },
|
||||
];
|
||||
|
||||
const statusOptions = [
|
||||
{ value: 'MODIFICABLE', label: 'Modificable' },
|
||||
{ value: 'ESPERA FIRMA PREVIO', label: 'Espera de firma previo' },
|
||||
@@ -135,12 +149,20 @@
|
||||
<!-- Tipo de Operación -->
|
||||
<div class="space-y-2">
|
||||
<Label for="operation_type">Tipo de Operación</Label>
|
||||
<Input
|
||||
id="operation_type"
|
||||
type="number"
|
||||
bind:value={formData.operation_type}
|
||||
placeholder="Ej: 1"
|
||||
/>
|
||||
<Select.Root
|
||||
type="single"
|
||||
value={String(formData.operation_type ?? '')}
|
||||
onValueChange={(v: string) => formData.operation_type = v ? Number(v) : null}
|
||||
>
|
||||
<Select.Trigger class="w-full">
|
||||
{operationOptions.find(o => o.value === formData.operation_type)?.label || 'Seleccionar...'}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
{#each operationOptions as option}
|
||||
<Select.Item value={String(option.value)} label={option.label} />
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
|
||||
<!-- Tipo de Pedimento -->
|
||||
@@ -154,17 +176,24 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Clave del Pedimento -->
|
||||
<div class="space-y-2">
|
||||
<Label for="pedimento_code">Clave del Pedimento</Label>
|
||||
<Input
|
||||
id="pedimento_code"
|
||||
bind:value={formData.pedimento_code}
|
||||
placeholder="Ej: A1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Régimen -->
|
||||
<!-- Clave del Pedimento -->
|
||||
<div class="space-y-2">
|
||||
<Label for="pedimento_code">Clave del Pedimento</Label>
|
||||
<Select.Root
|
||||
type="single"
|
||||
value={formData.pedimento_code || ''}
|
||||
onValueChange={(v: string) => formData.pedimento_code = v ?? ''}
|
||||
>
|
||||
<Select.Trigger class="w-full">
|
||||
{pedimentoCodes.find(o => o.code === formData.pedimento_code)?.description || 'Seleccionar...'}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
{#each pedimentoCodes as code}
|
||||
<Select.Item value={code.code} label={`${code.code} - ${code.description}`} />
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div> <!-- Régimen -->
|
||||
<div class="space-y-2">
|
||||
<Label for="regime">Régimen</Label>
|
||||
<Input
|
||||
@@ -177,16 +206,20 @@
|
||||
<!-- Estado -->
|
||||
<div class="space-y-2">
|
||||
<Label for="status">Estado</Label>
|
||||
<select
|
||||
id="status"
|
||||
bind:value={formData.status}
|
||||
class="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||
<Select.Root
|
||||
type="single"
|
||||
value={formData.status || ''}
|
||||
onValueChange={(v: string) => formData.status = v ?? ''}
|
||||
>
|
||||
<option value="">Seleccionar...</option>
|
||||
{#each statusOptions as option}
|
||||
<option value={option.value}>{option.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<Select.Trigger class="w-full">
|
||||
{statusOptions.find(o => o.value === formData.status)?.label || 'Seleccionar...'}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
{#each statusOptions as option}
|
||||
<Select.Item value={option.value} label={option.label} />
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
|
||||
<!-- Valor USD -->
|
||||
|
||||
@@ -9,12 +9,24 @@ export const load: PageServerLoad = async ({ params, cookies, fetch }) => {
|
||||
throw redirect(302, '/login');
|
||||
}
|
||||
|
||||
// Cargar pedimento_codes (datos de referencia)
|
||||
const pedimentoCodesPromise = authenticatedFetch(
|
||||
'v1/public/refrence_data/pedimento-codes?page=1&page_size=100',
|
||||
{},
|
||||
cookies,
|
||||
fetch
|
||||
);
|
||||
|
||||
// Si el ID es "new", es una creación
|
||||
if (params.id === 'new') {
|
||||
const pedimentoCodesResponse = await pedimentoCodesPromise;
|
||||
const pedimentoCodes = pedimentoCodesResponse.ok ? await pedimentoCodesResponse.json() : { items: [] };
|
||||
|
||||
return {
|
||||
pedimento: null,
|
||||
pedimentoId: null,
|
||||
isCreate: true
|
||||
isCreate: true,
|
||||
pedimentoCodes: pedimentoCodes.items || []
|
||||
};
|
||||
}
|
||||
|
||||
@@ -51,10 +63,15 @@ export const load: PageServerLoad = async ({ params, cookies, fetch }) => {
|
||||
|
||||
const pedimento = await response.json();
|
||||
|
||||
// Cargar pedimento_codes
|
||||
const pedimentoCodesResponse = await pedimentoCodesPromise;
|
||||
const pedimentoCodes = pedimentoCodesResponse.ok ? await pedimentoCodesResponse.json() : { items: [] };
|
||||
|
||||
return {
|
||||
pedimento,
|
||||
pedimentoId,
|
||||
isCreate: false
|
||||
isCreate: false,
|
||||
pedimentoCodes: pedimentoCodes.items || []
|
||||
};
|
||||
} catch (e) {
|
||||
console.error('Error loading pedimento:', e);
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
<GeneralTabForm
|
||||
pedimento={data.pedimento}
|
||||
bind:formData={generalFormData}
|
||||
pedimentoCodes={data.pedimentoCodes || []}
|
||||
/>
|
||||
</Tabs.Content>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user