Actualizar automatizaciones.html
This commit is contained in:
@@ -64,7 +64,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-4 text-left">
|
<div class="flex items-center gap-4 text-left">
|
||||||
<div class="flex flex-col items-end mr-4">
|
<div class="flex flex-col items-end mr-4 text-left">
|
||||||
<span class="text-[9px] font-black text-slate-400 uppercase mb-1">Prioridad</span>
|
<span class="text-[9px] font-black text-slate-400 uppercase mb-1">Prioridad</span>
|
||||||
<select id="impUrgent" class="bg-slate-50 border border-slate-200 text-xs font-black px-3 py-1.5 rounded-xl outline-none focus:border-red-400 cursor-pointer">
|
<select id="impUrgent" class="bg-slate-50 border border-slate-200 text-xs font-black px-3 py-1.5 rounded-xl outline-none focus:border-red-400 cursor-pointer">
|
||||||
<option value="false">BAJA (Normal)</option>
|
<option value="false">BAJA (Normal)</option>
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-5 gap-3 text-left">
|
<div class="grid grid-cols-1 md:grid-cols-5 gap-3 text-left">
|
||||||
<div class="md:col-span-4 space-y-1">
|
<div class="md:col-span-4 space-y-1 text-left">
|
||||||
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2 flex items-center gap-1">
|
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2 flex items-center gap-1">
|
||||||
<i data-lucide="map-pin" class="w-3 h-3"></i> Dirección
|
<i data-lucide="map-pin" class="w-3 h-3"></i> Dirección
|
||||||
</label>
|
</label>
|
||||||
@@ -142,7 +142,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-3 pt-4 border-t">
|
<div class="flex items-center gap-3 pt-4 border-t text-left">
|
||||||
<button type="button" onclick="saveDraftChanges(event)" class="bg-slate-100 hover:bg-slate-200 text-slate-600 font-black px-6 py-5 rounded-[1.8rem] transition-all flex items-center justify-center gap-2 active:scale-95 text-xs uppercase tracking-widest">
|
<button type="button" onclick="saveDraftChanges(event)" class="bg-slate-100 hover:bg-slate-200 text-slate-600 font-black px-6 py-5 rounded-[1.8rem] transition-all flex items-center justify-center gap-2 active:scale-95 text-xs uppercase tracking-widest">
|
||||||
<i data-lucide="save" class="w-4 h-4"></i> <span>Guardar Borrador</span>
|
<i data-lucide="save" class="w-4 h-4"></i> <span>Guardar Borrador</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -221,35 +221,27 @@
|
|||||||
const dataSvc = await resSvc.json();
|
const dataSvc = await resSvc.json();
|
||||||
scrapedData = dataSvc.services || [];
|
scrapedData = dataSvc.services || [];
|
||||||
container.innerHTML = "";
|
container.innerHTML = "";
|
||||||
|
|
||||||
if(scrapedData.length === 0) {
|
if(scrapedData.length === 0) {
|
||||||
container.innerHTML = '<div class="p-12 text-center text-slate-400 bg-white rounded-3xl border-2 border-dashed">No hay expedientes pendientes.</div>';
|
container.innerHTML = '<div class="p-12 text-center text-slate-400 bg-white rounded-3xl border-2 border-dashed">No hay expedientes pendientes.</div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scrapedData.forEach(svc => {
|
scrapedData.forEach(svc => {
|
||||||
const raw = svc.raw_data || {};
|
const raw = svc.raw_data || {};
|
||||||
const isArchived = svc.status === 'archived'; //
|
const isArchived = svc.status === 'archived';
|
||||||
const statusLabel = isArchived ? 'ARCHIVADO' : 'SERVICIO ACTIVO'; //
|
const statusLabel = isArchived ? 'ARCHIVADO' : 'SERVICIO ACTIVO';
|
||||||
const statusClass = isArchived ? 'bg-gray-100 text-gray-500 border-gray-200' : 'bg-emerald-50 text-emerald-600 border-emerald-100'; //
|
const statusClass = isArchived ? 'bg-gray-100 text-gray-500 border-gray-200' : 'bg-emerald-50 text-emerald-600 border-emerald-100';
|
||||||
const name = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
|
const name = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
|
||||||
const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
|
const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
|
||||||
const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
|
const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
|
||||||
const fullAddr = `${addr} ${pop}`.trim();
|
const fullAddr = `${addr} ${pop}`.trim();
|
||||||
const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || "";
|
const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || "";
|
||||||
|
|
||||||
const card = document.createElement('div');
|
const card = document.createElement('div');
|
||||||
card.className = `service-card bg-white p-5 rounded-2xl border ${isArchived ? 'archived' : 'shadow-sm'} flex items-center justify-between transition-all group fade-in text-left`;
|
card.className = `service-card bg-white p-5 rounded-2xl border ${isArchived ? 'archived' : 'shadow-sm'} flex items-center justify-between transition-all group fade-in text-left`;
|
||||||
|
|
||||||
card.onclick = (e) => {
|
card.onclick = (e) => {
|
||||||
if (e.target.closest('a') || e.target.closest('button')) return;
|
if (e.target.closest('a') || e.target.closest('button')) return;
|
||||||
if (isArchived) {
|
if (isArchived) showToast("⚠️ Este servicio está ARCHIVADO y no se puede editar.", true);
|
||||||
showToast("⚠️ Este servicio está ARCHIVADO y no se puede editar.", true);
|
else openEditor(svc.id);
|
||||||
} else {
|
|
||||||
openEditor(svc.id);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
<div class="flex items-center gap-4 min-w-0 text-left">
|
<div class="flex items-center gap-4 min-w-0 text-left">
|
||||||
<div class="w-16 h-16 rounded-2xl flex flex-col items-center justify-center shrink-0 shadow-sm border border-slate-100 ${isArchived ? 'bg-gray-200 text-gray-400' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}">
|
<div class="w-16 h-16 rounded-2xl flex flex-col items-center justify-center shrink-0 shadow-sm border border-slate-100 ${isArchived ? 'bg-gray-200 text-gray-400' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}">
|
||||||
@@ -284,79 +276,87 @@
|
|||||||
} catch (e) { showToast("Error de conexión", true); }
|
} catch (e) { showToast("Error de conexión", true); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEditor(id) {
|
async function openEditor(id) {
|
||||||
const svc = scrapedData.find(s => s.id === id);
|
const svc = scrapedData.find(s => s.id === id);
|
||||||
if(!svc) return;
|
if(!svc) return;
|
||||||
const raw = svc.raw_data;
|
const raw = svc.raw_data;
|
||||||
const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "";
|
const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "";
|
||||||
|
|
||||||
document.getElementById('modalCompanyLogo').innerHTML = `<img src="${getLogoUrl(companyName)}" class="max-w-full max-h-full object-contain">`;
|
document.getElementById('modalCompanyLogo').innerHTML = `<img src="${getLogoUrl(companyName)}" class="max-w-full max-h-full object-contain">`;
|
||||||
document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
|
document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
|
||||||
document.getElementById('displayCompany').innerText = companyName;
|
document.getElementById('displayCompany').innerText = companyName;
|
||||||
document.getElementById('modalStatusBadge').innerHTML = `<span class="text-[9px] bg-emerald-50 text-emerald-600 px-3 py-1 rounded-full font-black border border-emerald-100">SERVICIO ACTIVO</span>`;
|
document.getElementById('modalStatusBadge').innerHTML = `<span class="text-[9px] bg-emerald-50 text-emerald-600 px-3 py-1 rounded-full font-black border border-emerald-100">SERVICIO ACTIVO</span>`;
|
||||||
|
|
||||||
document.getElementById('impScrapedId').value = id;
|
document.getElementById('impScrapedId').value = id;
|
||||||
document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
|
document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
|
||||||
|
const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "";
|
||||||
|
document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || "";
|
||||||
|
const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
|
||||||
|
const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
|
||||||
|
document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
|
||||||
|
document.getElementById('impCP').value = raw['Código Postal'] || raw['C.P.'] || "";
|
||||||
|
document.getElementById('impDesc').value = raw['Descripción'] || "";
|
||||||
|
|
||||||
const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "";
|
const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
|
||||||
document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || "";
|
document.getElementById('impUrgent').value = isUrgent.toString();
|
||||||
|
|
||||||
const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
|
// --- RECUPERACIÓN DE DATOS GUARDADOS PREVIAMENTE ---
|
||||||
const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
|
document.getElementById('impNotesInt').value = raw['internal_notes'] || "";
|
||||||
document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
|
document.getElementById('impNotesExt').value = raw['client_notes'] || "";
|
||||||
document.getElementById('impCP').value = raw['Código Postal'] || raw['C.P.'] || "";
|
|
||||||
document.getElementById('impDesc').value = raw['Descripción'] || "";
|
|
||||||
|
|
||||||
const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
|
const savedGuild = raw['guild_id'] || "";
|
||||||
document.getElementById('impUrgent').value = isUrgent.toString();
|
document.getElementById('impGuild').value = savedGuild;
|
||||||
|
|
||||||
// RECUPERACIÓN DE DATOS GUARDADOS PREVIAMENTE
|
if(savedGuild) {
|
||||||
document.getElementById('impNotesInt').value = raw['internal_notes'] || "";
|
// Cargamos operarios y luego seleccionamos el guardado
|
||||||
document.getElementById('impNotesExt').value = raw['client_notes'] || "";
|
await loadOpsForGuild(savedGuild);
|
||||||
|
document.getElementById('impOperator').value = raw['assigned_to'] || "";
|
||||||
|
} else {
|
||||||
|
document.getElementById('impOperator').innerHTML = '<option value="">-- Automática --</option>';
|
||||||
|
}
|
||||||
|
|
||||||
// Cargar Gremio y disparar carga de operarios si ya existía
|
document.getElementById('importModal').classList.remove('hidden');
|
||||||
const savedGuild = raw['guild_id'] || "";
|
lucide.createIcons();
|
||||||
document.getElementById('impGuild').value = savedGuild;
|
}
|
||||||
|
|
||||||
if(savedGuild) {
|
|
||||||
loadOpsForGuild(savedGuild).then(() => {
|
|
||||||
document.getElementById('impOperator').value = raw['assigned_to'] || "";
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
document.getElementById('impOperator').innerHTML = '<option value="">-- Automática --</option>';
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('importModal').classList.remove('hidden');
|
|
||||||
lucide.createIcons();
|
|
||||||
}
|
|
||||||
function closeModal() { document.getElementById('importModal').classList.add('hidden'); }
|
function closeModal() { document.getElementById('importModal').classList.add('hidden'); }
|
||||||
|
|
||||||
async function saveDraftChanges(e) {
|
async function saveDraftChanges(e) {
|
||||||
const id = document.getElementById('impScrapedId').value;
|
const id = document.getElementById('impScrapedId').value;
|
||||||
const btn = e.currentTarget;
|
const btn = e.currentTarget;
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
name: document.getElementById('impName').value,
|
name: document.getElementById('impName').value,
|
||||||
phone: document.getElementById('impPhone').value,
|
phone: document.getElementById('impPhone').value,
|
||||||
address: document.getElementById('impAddress').value,
|
address: document.getElementById('impAddress').value,
|
||||||
cp: document.getElementById('impCP').value,
|
cp: document.getElementById('impCP').value,
|
||||||
description: document.getElementById('impDesc').value,
|
description: document.getElementById('impDesc').value,
|
||||||
|
is_urgent: document.getElementById('impUrgent').value === 'true',
|
||||||
|
// --- CAMPOS CORREGIDOS PARA EL GUARDADO ---
|
||||||
guild_id: document.getElementById('impGuild').value,
|
guild_id: document.getElementById('impGuild').value,
|
||||||
assigned_to: document.getElementById('impOperator').value || null,
|
assigned_to: document.getElementById('impOperator').value,
|
||||||
internal_notes: document.getElementById('impNotesInt').value,
|
internal_notes: document.getElementById('impNotesInt').value,
|
||||||
client_notes: document.getElementById('impNotesExt').value,
|
client_notes: document.getElementById('impNotesExt').value
|
||||||
is_urgent: document.getElementById('impUrgent').value === 'true'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/providers/scraped/${id}`, {
|
const res = await fetch(`${API_URL}/providers/scraped/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload)
|
||||||
});
|
});
|
||||||
if(res.ok) { showToast("✅ Borrador guardado"); loadInbox(); }
|
if(res.ok) {
|
||||||
else { showToast("❌ Error al guardar", true); }
|
showToast("✅ Borrador guardado correctamente");
|
||||||
} catch (e) { showToast("❌ Error de red", true); }
|
loadInbox();
|
||||||
finally { btn.disabled = false; }
|
} else {
|
||||||
|
showToast("❌ Error al guardar", true);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
showToast("❌ Error de red", true);
|
||||||
|
} finally {
|
||||||
|
btn.disabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleFinalImport(event) {
|
async function handleFinalImport(event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user