fix: select completo no sb_listar + busca por periodo (de/ate/turno)
This commit is contained in:
+28
-13
@@ -2229,16 +2229,25 @@ function buildConsultaModal(recentList) {
|
||||
}
|
||||
|
||||
overlay.innerHTML = `
|
||||
<div style="background:#fff;border-radius:10px;padding:20px;max-width:850px;width:95%;max-height:85vh;overflow-y:auto">
|
||||
<div style="background:#fff;border-radius:10px;padding:20px;max-width:900px;width:95%;max-height:85vh;overflow-y:auto">
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;flex-wrap:wrap;gap:8px">
|
||||
<h2 style="margin:0;font-size:16px">📅 Consultar Fechamentos</h2>
|
||||
<div style="display:flex;gap:8px;align-items:center">
|
||||
<input type="date" id="consulta-busca-data" value="" max="${ultimoDia}" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px" />
|
||||
<div style="display:flex;gap:6px;align-items:center;flex-wrap:wrap">
|
||||
<span style="font-size:12px;color:#555">De:</span>
|
||||
<input type="date" id="consulta-busca-de" value="" max="${ultimoDia}" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px" />
|
||||
<span style="font-size:12px;color:#555">Até:</span>
|
||||
<input type="date" id="consulta-busca-ate" value="" max="${ultimoDia}" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px" />
|
||||
<select id="consulta-busca-turno" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px;background:#fff">
|
||||
<option value="">Todos turnos</option>
|
||||
<option value="manha">Manhã</option>
|
||||
<option value="tarde">Tarde</option>
|
||||
<option value="integral">Integral</option>
|
||||
</select>
|
||||
<button onclick="window._filtrarConsulta()" style="background:#1565c0;color:#fff;border:none;border-radius:6px;padding:6px 14px;cursor:pointer;font-size:13px">🔍 Buscar</button>
|
||||
<button onclick="closeConsultaModal()" style="background:none;border:none;font-size:18px;cursor:pointer;padding:4px 8px">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="consulta-info" style="font-size:11px;color:#888;margin-bottom:8px"></div>
|
||||
<div id="consulta-info" style="font-size:11px;color:#888;margin-bottom:8px">Mostrando últimos 5 dias</div>
|
||||
<div style="max-height:55vh;overflow-y:auto;border:1px solid #eee;border-radius:6px">
|
||||
<table style="width:100%;border-collapse:collapse">
|
||||
<thead style="position:sticky;top:0;background:#f5f5f5;z-index:1">
|
||||
@@ -2264,25 +2273,31 @@ function buildConsultaModal(recentList) {
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
// Função de busca por data
|
||||
// Função de busca por período
|
||||
window._filtrarConsulta = () => {
|
||||
const dataBusca = document.getElementById('consulta-busca-data')?.value;
|
||||
const de = document.getElementById('consulta-busca-de')?.value;
|
||||
const ate = document.getElementById('consulta-busca-ate')?.value;
|
||||
const turno = document.getElementById('consulta-busca-turno')?.value || '';
|
||||
const tbody = document.getElementById('consulta-tbody');
|
||||
const info = document.getElementById('consulta-info');
|
||||
if (!tbody) return;
|
||||
if (!dataBusca) {
|
||||
let filtrados = [...recentList];
|
||||
if (de) filtrados = filtrados.filter(item => item.data >= de);
|
||||
if (ate) filtrados = filtrados.filter(item => item.data <= ate);
|
||||
if (turno) filtrados = filtrados.filter(item => (item.turno||'').toLowerCase() === turno);
|
||||
if (de || ate || turno) {
|
||||
tbody.innerHTML = renderRows(filtrados);
|
||||
const label = `${filtrados.length} registro${filtrados.length!==1?'s':''}${de&&ate?` de ${fmtDate(de)} a ${fmtDate(ate)}`:de?` a partir de ${fmtDate(de)}`:ate?` até ${fmtDate(ate)}`:''}`;
|
||||
if (info) info.textContent = label;
|
||||
} else {
|
||||
tbody.innerHTML = renderRows(cincoDias);
|
||||
if (info) info.textContent = 'Mostrando últimos 5 dias';
|
||||
return;
|
||||
}
|
||||
const filtrados = recentList.filter(item => item.data === dataBusca);
|
||||
tbody.innerHTML = renderRows(filtrados);
|
||||
if (info) info.textContent = filtrados.length ? `${filtrados.length} registro${filtrados.length!==1?'s':''} em ${fmtDate(dataBusca)}` : `Nenhum registro em ${fmtDate(dataBusca)}`;
|
||||
};
|
||||
|
||||
// Enter na busca
|
||||
document.getElementById('consulta-busca-data')?.addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter') window._filtrarConsulta();
|
||||
['consulta-busca-de','consulta-busca-ate'].forEach(id => {
|
||||
document.getElementById(id)?.addEventListener('keydown', e => { if (e.key === 'Enter') window._filtrarConsulta(); });
|
||||
});
|
||||
|
||||
window._recentList = recentList;
|
||||
|
||||
Reference in New Issue
Block a user