+
+
+
+
Rastreando tu zona...
@@ -219,7 +226,9 @@ if (isRestricted) return; // Doble seguridad document.getElementById('servicesList').classList.add('hidden'); + document.getElementById('searchContainer').classList.add('hidden'); document.getElementById('loader').classList.remove('hidden'); + document.getElementById('searchInput').value = ""; // Limpiamos el buscador al recargar try { const res = await fetch(`${API_URL}/providers/scraped`, { @@ -252,7 +261,11 @@ return false; }); - renderServices(); + renderServices(availableServices); // Renderizamos pasando la lista completa inicialmente + + if (availableServices.length > 0) { + document.getElementById('searchContainer').classList.remove('hidden'); + } } } catch (e) { alert("Error de conexi贸n"); @@ -262,23 +275,53 @@ } } - function renderServices() { + // 馃敟 FUNCI脫N DE FILTRADO (BUSCADOR) 馃敟 + function filterServices() { + const query = document.getElementById('searchInput').value.toLowerCase().trim(); + + if (query === "") { + renderServices(availableServices); // Si est谩 vac铆o, pinta todos + return; + } + + const filtered = availableServices.filter(s => { + const raw = s.raw_data || {}; + + const searchString = ` + ${s.service_ref || ""} + ${raw["Nombre Cliente"] || raw["CLIENTE"] || ""} + ${raw["Direcci贸n"] || raw["DOMICILIO"] || ""} + ${raw["Poblaci贸n"] || raw["POBLACION-PROVINCIA"] || ""} + ${raw["C贸digo Postal"] || raw["C.P."] || ""} + ${raw["Descripci贸n"] || raw["DESCRIPCION"] || raw["Averia"] || ""} + ${raw["Compa帽铆a"] || raw["Procedencia"] || ""} + `.toLowerCase(); + + return searchString.includes(query); + }); + + renderServices(filtered); + } + + // Se ha modificado para que reciba el array a pintar (filtered o full) + function renderServices(servicesToRender) { const container = document.getElementById('servicesList'); - if (availableServices.length === 0) { + if (!servicesToRender || servicesToRender.length === 0) { + const isSearch = document.getElementById('searchInput').value.trim() !== ""; container.innerHTML = ` -
+
`;
lucide.createIcons();
return;
}
- container.innerHTML = availableServices.map(s => {
+ container.innerHTML = servicesToRender.map(s => {
const raw = s.raw_data || {};
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado";
const addr = raw["Direcci贸n"] || "Sin direcci贸n";
@@ -380,7 +423,7 @@
if (res.ok) {
showToast("隆Te lo has quedado!");
closeModal();
- loadAvailableServices(); // Recarga la bolsa
+ loadAvailableServices(); // Recarga la bolsa y limpia el buscador
} else {
alert("Alguien ha sido m谩s r谩pido o hubo un error.");
}
-
+
- Bolsa Vac铆a
-No hay servicios nuevos en tu zona.
+${isSearch ? 'Sin resultados' : 'Bolsa Vac铆a'}
+${isSearch ? 'Prueba con otra palabra clave.' : 'No hay servicios nuevos en tu zona.'}