feat: Add prefill functionality for pedidos and enhance item matching logic with modalidade support
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user