From 7bcc46431a684433d80f9152eb637f193303c920 Mon Sep 17 00:00:00 2001 From: marsalva Date: Mon, 2 Mar 2026 08:41:20 +0000 Subject: [PATCH] Actualizar servicios.html --- servicios.html | 187 +++++++++++++++++++++++++++++++------------------ 1 file changed, 120 insertions(+), 67 deletions(-) diff --git a/servicios.html b/servicios.html index 83e719a..ee81af2 100644 --- a/servicios.html +++ b/servicios.html @@ -142,6 +142,13 @@
+ + + +
@@ -383,6 +390,40 @@
+ + + // --- FUNCIÓN PARA BUSCAR CLIENTE POR TELÉFONO AL ESCRIBIR --- +async function searchClientByPhone(phone) { + if (phone.length < 9) { + document.getElementById('addrSuggestions').classList.add('hidden'); + return; + } + try { + const res = await fetch(`${API_URL}/clients/search?phone=${phone}`, { + headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } + }); + const data = await res.json(); + + if (data.ok && data.client) { + // Rellenar nombre si está vacío + const nameInput = document.getElementById('nName'); + if (!nameInput.value) { + nameInput.value = data.client.full_name; + nameInput.classList.add('bg-emerald-50'); // Efecto visual de éxito + } + + // Mostrar aviso de direcciones si existen + const addrDiv = document.getElementById('addrSuggestions'); + if (data.client.addresses && data.client.addresses.length > 0) { + addrDiv.classList.remove('hidden'); + // Si el campo de dirección está vacío, ponemos la primera que tengamos + if (!document.getElementById('nAddr').value) { + document.getElementById('nAddr').value = data.client.addresses[0]; + } + } + } + } catch (e) { console.error("Error en buscador rápido:", e); } +} \ No newline at end of file