Actualizar servicios.html

This commit is contained in:
2026-03-02 23:10:55 +00:00
parent c01f8431aa
commit 2f7203af05

View File

@@ -664,21 +664,29 @@ async function searchClientByPhone(phone) {
setTimeout(() => { toast.classList.add('hidden'); }, 3500); setTimeout(() => { toast.classList.add('hidden'); }, 3500);
} }
function openDetail(id) { function openDetail(id, startInEditMode = false) {
const s = localData.find(x => x.id === id); const s = localData.find(x => x.id === id);
if (!s) return; if (!s) return;
const raw = s.raw_data; const raw = s.raw_data;
// 1. IDs y Referencias
document.getElementById('detId').value = s.id; document.getElementById('detId').value = s.id;
document.getElementById('detRef').innerText = s.service_ref; document.getElementById('detRef').innerText = s.service_ref;
document.getElementById('detCp').value = raw["Código Postal"] || "00000"; document.getElementById('detCp').value = raw["Código Postal"] || "00000";
const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "Particular"; const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "Particular";
document.getElementById('detCompany').innerText = companyName; document.getElementById('detCompany').innerText = companyName;
document.getElementById('detName').innerText = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Sin Nombre";
// 2. RELLENAR CAMPOS EDITABLES (NUEVO)
// Rellenamos tanto los visuales como los que usaremos para editar
const clientName = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Sin Nombre";
document.getElementById('detName').innerText = clientName;
if(document.getElementById('editName')) document.getElementById('editName').value = clientName;
const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || ""; const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || "";
const matchPhone = rawPhone.toString().match(/[6789]\d{8}/); const matchPhone = rawPhone.toString().match(/[6789]\d{8}/);
const singlePhone = matchPhone ? matchPhone[0] : ""; const singlePhone = matchPhone ? matchPhone[0] : "";
if(document.getElementById('editPhone')) document.getElementById('editPhone').value = singlePhone;
if (singlePhone) { if (singlePhone) {
document.getElementById('detPhone').innerText = singlePhone; document.getElementById('detPhone').innerText = singlePhone;
@@ -692,11 +700,16 @@ async function searchClientByPhone(phone) {
document.getElementById('detPhoneLink').classList.add('text-slate-400', 'pointer-events-none'); document.getElementById('detPhoneLink').classList.add('text-slate-400', 'pointer-events-none');
} }
document.getElementById('detAddrText').innerText = `${raw["Dirección"] || "Dirección no especificada"} ${raw["Población"] || ""}`; const fullAddr = `${raw["Dirección"] || ""} ${raw["Población"] || ""}`.trim();
document.getElementById('detDesc').innerHTML = (raw["Descripción"] || raw["DESCRIPCION"] || "Sin notas.").replace(/\n/g, '<br>'); document.getElementById('detAddrText').innerText = fullAddr || "Dirección no especificada";
if(document.getElementById('editAddr')) document.getElementById('editAddr').value = raw["Dirección"] || "";
const descContent = raw["Descripción"] || raw["DESCRIPCION"] || "Sin notas.";
document.getElementById('detDesc').innerHTML = descContent.replace(/\n/g, '<br>');
if(document.getElementById('editDesc')) document.getElementById('editDesc').value = descContent;
// 3. Lógica de Paneles (Asignación/Bolsa)
const stateInfo = s._stateInfo; const stateInfo = s._stateInfo;
if (s.automation_status === 'in_progress') { if (s.automation_status === 'in_progress') {
document.getElementById('panelEnBolsa').classList.remove('hidden'); document.getElementById('panelEnBolsa').classList.remove('hidden');
document.getElementById('panelAsignado').classList.add('hidden'); document.getElementById('panelAsignado').classList.add('hidden');
@@ -726,10 +739,18 @@ async function searchClientByPhone(phone) {
} }
} }
// 4. ACTIVAR MODO EDICIÓN SI SE PULSÓ EL LÁPIZ (NUEVO)
document.getElementById('detailModal').classList.remove('hidden'); document.getElementById('detailModal').classList.remove('hidden');
lucide.createIcons();
if (startInEditMode) {
enableEditing();
} else {
cancelEditing(); // Resetear a modo lectura
} }
lucide.createIcons();
}
async function stopAutomation() { async function stopAutomation() {
const id = document.getElementById('detId').value; const id = document.getElementById('detId').value;
if(!confirm("¿Deseas cancelar la búsqueda del robot para asignar este servicio manualmente?")) return; if(!confirm("¿Deseas cancelar la búsqueda del robot para asignar este servicio manualmente?")) return;