Actualizar automatizaciones.html
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
</h2>
|
||||
<p class="text-sm text-slate-500 mt-1 font-medium">Valida los expedientes bloqueados o listos para importar.</p>
|
||||
</div>
|
||||
<button onclick="loadInbox()" class="bg-white border-2 border-slate-200 hover:border-blue-600 hover:text-blue-600 px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 transition-all shadow-sm">
|
||||
<button onclick="loadInbox()" class="bg-white border-2 border-slate-200 hover:border-blue-600 hover:text-blue-600 text-slate-600 px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 transition-all shadow-sm">
|
||||
<i data-lucide="refresh-cw" class="w-4 h-4"></i> Actualizar
|
||||
</button>
|
||||
</div>
|
||||
@@ -45,7 +45,7 @@
|
||||
<div id="importModal" class="fixed inset-0 bg-slate-900/60 hidden z-[100] flex items-center justify-center backdrop-blur-md p-4">
|
||||
<div class="bg-white rounded-3xl shadow-2xl w-full max-w-4xl flex flex-col max-h-[95vh] overflow-hidden">
|
||||
<div class="p-6 border-b flex justify-between items-center bg-slate-50">
|
||||
<h3 class="text-xl font-black text-slate-800 flex items-center gap-2"><i data-lucide="check-square" class="text-emerald-500"></i> Alta de Servicio Automática</h3>
|
||||
<h3 class="text-xl font-black text-slate-800 flex items-center gap-2"><i data-lucide="check-square" class="text-emerald-500"></i> Validar Datos de Importación</h3>
|
||||
<button onclick="closeModal()" class="p-2 hover:bg-red-50 hover:text-red-500 rounded-full transition-all"><i data-lucide="x"></i></button>
|
||||
</div>
|
||||
|
||||
@@ -97,32 +97,39 @@
|
||||
<textarea id="impNotesInt" rows="2" class="w-full border-2 border-amber-50 bg-amber-50/20 p-3 rounded-xl text-xs outline-none"></textarea>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<label class="text-[10px] font-black text-blue-600 uppercase tracking-widest">Notas para el Cliente</label>
|
||||
<label class="text-[10px] font-black text-blue-600 uppercase tracking-widest">Notas Cliente</label>
|
||||
<textarea id="impNotesExt" rows="2" class="w-full border-2 border-blue-50 bg-blue-50/20 p-3 rounded-xl text-xs outline-none"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-4 border-t pt-6">
|
||||
<div class="space-y-1 text-center">
|
||||
<label class="text-[9px] font-black text-slate-400 uppercase">Estado</label>
|
||||
<div class="p-2 bg-slate-100 rounded-lg text-xs font-black text-slate-500 uppercase">Pendiente</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 border-t pt-6">
|
||||
<div class="space-y-1">
|
||||
<label class="text-[9px] font-black text-slate-400 uppercase">Referencia</label>
|
||||
<input type="text" id="impRef" readonly class="w-full bg-slate-100 p-2 rounded-lg text-xs font-bold text-center border-none">
|
||||
</div>
|
||||
<div class="space-y-1 text-center">
|
||||
<div class="space-y-1">
|
||||
<label class="text-[9px] font-black text-slate-400 uppercase">Compañía</label>
|
||||
<input type="text" id="impCompany" readonly class="w-full bg-slate-100 p-2 rounded-lg text-xs font-black text-center border-none text-blue-700">
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<label class="text-[9px] font-black text-slate-400 uppercase">Prioridad</label>
|
||||
<select id="impUrgent" class="w-full border-none bg-transparent text-xs font-black text-center focus:ring-0">
|
||||
<select id="impUrgent" class="w-full bg-slate-100 p-2 rounded-lg text-xs font-black text-center border-none">
|
||||
<option value="false">Normal</option>
|
||||
<option value="true">🚨 URGENTE</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="bg-emerald-600 hover:bg-emerald-700 text-white font-black rounded-2xl shadow-xl transition-all flex items-center justify-center gap-2">
|
||||
<i data-lucide="send"></i> TRASPASAR A CRM
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="w-full bg-emerald-600 hover:bg-emerald-700 text-white font-black py-4 rounded-2xl shadow-xl transition-all flex items-center justify-center gap-2 active:scale-95">
|
||||
<i data-lucide="send"></i> TRASPASAR A CRM
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="toast" class="fixed bottom-8 right-8 bg-slate-900 text-white px-8 py-4 rounded-2xl shadow-2xl hidden z-[200] border border-white/10"><span id="toastMsg" class="font-bold text-sm"></span></div>
|
||||
|
||||
<script src="js/layout.js"></script>
|
||||
<script>
|
||||
let allGuilds = [];
|
||||
@@ -156,51 +163,59 @@
|
||||
|
||||
async function loadInbox() {
|
||||
const container = document.getElementById('inboxContainer');
|
||||
const [resSvc, resMap] = await Promise.all([
|
||||
fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }),
|
||||
fetch(`${API_URL}/discovery/mappings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } })
|
||||
]);
|
||||
const dataSvc = await resSvc.json();
|
||||
const mappings = await resMap.json();
|
||||
scrapedData = dataSvc.services || [];
|
||||
container.innerHTML = "";
|
||||
try {
|
||||
const [resSvc, resMap] = await Promise.all([
|
||||
fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }),
|
||||
fetch(`${API_URL}/discovery/mappings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } })
|
||||
]);
|
||||
const dataSvc = await resSvc.json();
|
||||
scrapedData = dataSvc.services || [];
|
||||
container.innerHTML = "";
|
||||
|
||||
scrapedData.forEach(svc => {
|
||||
const raw = svc.raw_data || {};
|
||||
const myMap = mappings.filter(m => m.provider === svc.provider);
|
||||
const name = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
|
||||
const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
||||
const isBlocked = (!name || name.toUpperCase().includes('SIN NOMBRE') || !addr);
|
||||
const shortProv = svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME';
|
||||
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>';
|
||||
return;
|
||||
}
|
||||
|
||||
const card = document.createElement('div');
|
||||
card.className = `bg-white p-5 rounded-2xl border ${isBlocked ? 'opacity-60 bg-slate-50' : 'shadow-sm'} flex items-center justify-between group fade-in`;
|
||||
card.innerHTML = `
|
||||
<div class="flex items-center gap-6 min-w-0">
|
||||
<div class="w-14 h-14 rounded-2xl flex flex-col items-center justify-center shrink-0 ${isBlocked ? 'bg-slate-200 text-slate-500' : 'bg-blue-50 text-blue-600'}">
|
||||
<span class="text-[8px] font-black">${shortProv}</span>
|
||||
<i data-lucide="${isBlocked ? 'lock' : 'file-text'}" class="w-5 h-5"></i>
|
||||
scrapedData.forEach(svc => {
|
||||
const raw = svc.raw_data || {};
|
||||
const name = raw['Nombre Cliente'] || "";
|
||||
const addr = raw['Dirección'] || "";
|
||||
const isBlocked = (!name || name.toUpperCase().includes('SIN NOMBRE') || !addr);
|
||||
const shortProv = svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME';
|
||||
|
||||
const card = document.createElement('div');
|
||||
card.className = `bg-white p-5 rounded-2xl border ${isBlocked ? 'opacity-50' : 'shadow-sm hover:border-blue-300'} flex items-center justify-between transition-all group fade-in`;
|
||||
card.innerHTML = `
|
||||
<div class="flex items-center gap-6 min-w-0">
|
||||
<div class="w-14 h-14 rounded-2xl flex flex-col items-center justify-center shrink-0 ${isBlocked ? 'bg-slate-200' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}">
|
||||
<span class="text-[8px] font-black">${shortProv}</span>
|
||||
<i data-lucide="${isBlocked ? 'lock' : 'file-text'}" class="w-5 h-5"></i>
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<h3 class="font-black text-slate-800 truncate uppercase text-lg">${isBlocked ? 'Expediente Bloqueado' : name}</h3>
|
||||
<p class="text-xs text-slate-400 truncate italic">${isBlocked ? 'Pendiente de liberación' : addr}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<h3 class="font-black ${isBlocked ? 'text-slate-400' : 'text-slate-800'} truncate text-lg">${isBlocked ? 'EXPEDIENTE BLOQUEADO' : name}</h3>
|
||||
<p class="text-xs text-slate-400 truncate">${isBlocked ? 'Pendiente de acción en compañía' : addr}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
${!isBlocked ? `
|
||||
<div class="hidden group-hover:flex items-center gap-1 pr-4 border-r mr-2">
|
||||
<a href="https://www.google.com/maps/search/${encodeURIComponent(addr)}" target="_blank" class="p-2 hover:text-blue-600"><i data-lucide="map" class="w-5 h-5"></i></a>
|
||||
<button onclick="openEditor(${svc.id})" class="bg-blue-600 text-white p-4 rounded-2xl shadow-lg active:scale-90"><i data-lucide="edit-3"></i></button>
|
||||
</div>` : '<i data-lucide="shield-off" class="text-slate-300 mx-4"></i>'}
|
||||
</div>`;
|
||||
container.appendChild(card);
|
||||
});
|
||||
lucide.createIcons();
|
||||
<div class="flex items-center gap-2">
|
||||
${!isBlocked ? `
|
||||
<div class="hidden group-hover:flex items-center gap-1 pr-4 border-r mr-2">
|
||||
<a href="https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(addr)}" target="_blank" class="p-2.5 rounded-xl bg-slate-50 text-slate-400 hover:text-blue-600 transition-all"><i data-lucide="map" class="w-5 h-5"></i></a>
|
||||
<button onclick="openEditor(${svc.id})" class="bg-blue-600 text-white p-4 rounded-2xl shadow-lg active:scale-90 transition-all"><i data-lucide="edit-3"></i></button>
|
||||
</div>` : '<i data-lucide="shield-off" class="text-slate-300 mx-4"></i>'}
|
||||
</div>`;
|
||||
container.appendChild(card);
|
||||
});
|
||||
lucide.createIcons();
|
||||
} catch (e) { showToast("Error de conexión", true); }
|
||||
}
|
||||
|
||||
function openEditor(id) {
|
||||
const svc = scrapedData.find(s => s.id === id);
|
||||
if(!svc) return;
|
||||
const raw = svc.raw_data;
|
||||
|
||||
// SINCRONIZACIÓN DE TODOS LOS IDS DEL FORMULARIO
|
||||
document.getElementById('impScrapedId').value = id;
|
||||
document.getElementById('impName').value = raw['Nombre Cliente'] || "";
|
||||
document.getElementById('impPhone').value = (raw['Teléfono'] || "").match(/[6789]\d{8}/)?.[0] || "";
|
||||
@@ -208,12 +223,62 @@
|
||||
document.getElementById('impCP').value = raw['Código Postal'] || "";
|
||||
document.getElementById('impDesc').value = raw['Descripción'] || "";
|
||||
document.getElementById('impRef').value = svc.service_ref;
|
||||
document.getElementById('impCompany').value = svc.provider.toUpperCase();
|
||||
document.getElementById('impCompany').value = raw['Compañía'] || svc.provider.toUpperCase();
|
||||
document.getElementById('impUrgent').value = (raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true').toString();
|
||||
|
||||
// Campos adicionales vacíos por defecto
|
||||
document.getElementById('impNotesInt').value = "";
|
||||
document.getElementById('impNotesExt').value = "";
|
||||
document.getElementById('impGuild').value = "";
|
||||
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'); }
|
||||
|
||||
async function handleFinalImport(event) {
|
||||
event.preventDefault();
|
||||
const btn = event.submitter;
|
||||
btn.disabled = true;
|
||||
|
||||
const payload = {
|
||||
name: document.getElementById('impName').value,
|
||||
phone: document.getElementById('impPhone').value,
|
||||
address: document.getElementById('impAddress').value,
|
||||
cp: document.getElementById('impCP').value,
|
||||
description: document.getElementById('impDesc').value,
|
||||
company_ref: document.getElementById('impRef').value,
|
||||
guild_id: document.getElementById('impGuild').value,
|
||||
assigned_to: document.getElementById('impOperator').value || null,
|
||||
internal_notes: document.getElementById('impNotesInt').value,
|
||||
client_notes: document.getElementById('impNotesExt').value,
|
||||
is_urgent: document.getElementById('impUrgent').value === 'true'
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/providers/import/${document.getElementById('impScrapedId').value}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const result = await res.json();
|
||||
if(result.ok) {
|
||||
showToast("✅ Expediente enviado al CRM");
|
||||
closeModal();
|
||||
loadInbox();
|
||||
} else { showToast("❌ Error al importar", true); }
|
||||
} catch (e) { showToast("❌ Error de red", true); }
|
||||
finally { btn.disabled = false; }
|
||||
}
|
||||
|
||||
function showToast(msg, isError = false) {
|
||||
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
|
||||
t.className = `fixed bottom-8 right-8 px-8 py-4 rounded-2xl shadow-2xl z-[200] flex items-center gap-3 transition-all ${isError ? 'bg-red-600' : 'bg-slate-900'} text-white`;
|
||||
m.innerText = msg; t.classList.remove('hidden');
|
||||
setTimeout(() => t.classList.add('hidden'), 4000);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user