Actualizar presupuestos.html
This commit is contained in:
@@ -64,8 +64,12 @@
|
||||
<div class="bg-white p-5 rounded-[2rem] border border-slate-100 shadow-sm space-y-4">
|
||||
<h3 class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-1 flex items-center gap-1"><i data-lucide="user" class="w-3 h-3"></i> Cliente</h3>
|
||||
|
||||
<div class="relative">
|
||||
<input type="tel" id="c_phone" required placeholder="Teléfono (Busca cliente auto)" onblur="searchClientByPhone()" class="w-full px-4 py-3 bg-slate-50 border border-slate-100 rounded-xl text-sm font-bold text-slate-700 ring-primary-dynamic transition-all">
|
||||
<i id="phoneLoading" data-lucide="loader-2" class="w-4 h-4 absolute right-4 top-1/2 -translate-y-1/2 text-primary-dynamic animate-spin hidden"></i>
|
||||
</div>
|
||||
|
||||
<input type="text" id="c_name" required placeholder="Nombre del Cliente" class="w-full px-4 py-3 bg-slate-50 border border-slate-100 rounded-xl text-sm font-bold text-slate-700 ring-primary-dynamic transition-all">
|
||||
<input type="tel" id="c_phone" required placeholder="Teléfono" class="w-full px-4 py-3 bg-slate-50 border border-slate-100 rounded-xl text-sm font-bold text-slate-700 ring-primary-dynamic transition-all">
|
||||
<input type="text" id="c_address" placeholder="Dirección (Opcional)" class="w-full px-4 py-3 bg-slate-50 border border-slate-100 rounded-xl text-sm font-bold text-slate-700 ring-primary-dynamic transition-all">
|
||||
</div>
|
||||
|
||||
@@ -511,6 +515,39 @@ async function downloadPDF(id) {
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
// ------------------ BUSCADOR DE CLIENTES AUTOMÁTICO ------------------
|
||||
async function searchClientByPhone() {
|
||||
const phoneInput = document.getElementById('c_phone');
|
||||
const phone = phoneInput.value.trim();
|
||||
const loading = document.getElementById('phoneLoading');
|
||||
|
||||
// Si el teléfono tiene menos de 9 dígitos, no hacemos nada
|
||||
if (!phone || phone.length < 9) return;
|
||||
|
||||
loading.classList.remove('hidden'); // Mostramos el iconito de pensar
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/clients/search?phone=${encodeURIComponent(phone)}`, {
|
||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.ok && data.client) {
|
||||
// Si encuentra al cliente, rellenamos los datos
|
||||
document.getElementById('c_name').value = data.client.full_name || '';
|
||||
if (data.client.addresses && data.client.addresses.length > 0) {
|
||||
// Cogemos la primera dirección que tenga guardada
|
||||
document.getElementById('c_address').value = data.client.addresses[0] || '';
|
||||
}
|
||||
showToast("✅ Cliente encontrado y cargado");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error buscando cliente", e);
|
||||
} finally {
|
||||
loading.classList.add('hidden'); // Ocultamos el iconito
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------ CREACIÓN DE PRESUPUESTO (ITEMS) ------------------
|
||||
function addItem() {
|
||||
const conceptInput = document.getElementById('item_concept');
|
||||
|
||||
Reference in New Issue
Block a user