feat: Add prefill functionality for pedidos and enhance item matching logic with modalidade support

This commit is contained in:
2025-12-03 11:31:33 -03:00
parent d86d7d8dbb
commit fb78866a0e
3 changed files with 132 additions and 26 deletions

View File

@@ -117,6 +117,8 @@
});
let addingItem = $state(false);
let hasAppliedPrefill = $state(false);
// Edit SEI State
let editingSei = $state(false);
let seiValue = $state('');
@@ -139,6 +141,47 @@
selectedObjeto = null;
}
$effect(() => {
if (hasAppliedPrefill) return;
if (objetosQuery.isLoading || acoesQuery.isLoading) return;
const url = $page.url;
const obj = url.searchParams.get('obj');
const qtdStr = url.searchParams.get('qtd');
const mod = url.searchParams.get('mod') as Modalidade | null;
const acao = url.searchParams.get('acao');
const ata = url.searchParams.get('ata');
if (!obj) return;
const objeto = objetos.find((o) => o._id === obj);
if (!objeto) return;
let quantidade = parseInt(qtdStr || '1', 10);
if (!Number.isFinite(quantidade) || quantidade <= 0) {
quantidade = 1;
}
const modalidade: Modalidade =
mod === 'dispensa' || mod === 'inexgibilidade' || mod === 'adesao' || mod === 'consumo'
? mod
: 'consumo';
showAddItem = true;
newItem = {
objetoId: obj,
valorEstimado: maskCurrencyBRL(objeto.valorEstimado || ''),
quantidade,
modalidade,
acaoId: acao || '',
ataId: ata || ''
};
void loadAtasForObjeto(obj);
hasAppliedPrefill = true;
});
async function handleAddItem() {
if (!newItem.objetoId || !newItem.valorEstimado) return;
addingItem = true;