Actualizar servicios.html
This commit is contained in:
@@ -313,9 +313,10 @@
|
|||||||
<div class="grid grid-cols-2 gap-4 items-center">
|
<div class="grid grid-cols-2 gap-4 items-center">
|
||||||
<div>
|
<div>
|
||||||
<p class="text-[9px] font-black text-slate-400 uppercase tracking-widest mb-1.5">Operario Asignado</p>
|
<p class="text-[9px] font-black text-slate-400 uppercase tracking-widest mb-1.5">Operario Asignado</p>
|
||||||
<div class="flex items-center gap-2 bg-white p-2 rounded-xl border border-slate-100 shadow-sm">
|
<div class="flex items-center gap-2 bg-white p-2 rounded-xl border border-slate-100 shadow-sm relative">
|
||||||
<div class="bg-emerald-100 w-8 h-8 rounded-full flex items-center justify-center text-emerald-600 shrink-0"><i data-lucide="hard-hat" class="w-4 h-4"></i></div>
|
<div class="bg-emerald-100 w-8 h-8 rounded-full flex items-center justify-center text-emerald-600 shrink-0"><i data-lucide="hard-hat" class="w-4 h-4"></i></div>
|
||||||
<p id="detWorker" class="font-black text-slate-700 text-[11px] uppercase leading-tight truncate"></p>
|
<select id="detWorkerSelect" class="w-full font-black text-slate-700 text-[11px] uppercase leading-tight bg-transparent border-none outline-none appearance-none cursor-pointer pr-4 truncate"></select>
|
||||||
|
<i data-lucide="chevron-down" class="w-3 h-3 text-slate-400 absolute right-2 pointer-events-none"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="space-y-1.5">
|
<div class="space-y-1.5">
|
||||||
@@ -668,13 +669,33 @@
|
|||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NUEVA FUNCIÓN: Carga los operarios para poder reasignar sobre la marcha
|
||||||
|
async function loadOpsForReassign(gid, currentWorkerId) {
|
||||||
|
const sel = document.getElementById('detWorkerSelect');
|
||||||
|
if(!sel) return;
|
||||||
|
sel.innerHTML = '<option value="">-- Desasignar Operario --</option>';
|
||||||
|
try {
|
||||||
|
const endpoint = gid ? `${API_URL}/operators?guild_id=${gid}` : `${API_URL}/operators`;
|
||||||
|
const res = await fetch(endpoint, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
|
const data = await res.json();
|
||||||
|
if(data.ok) {
|
||||||
|
data.operators.forEach(op => {
|
||||||
|
const isSelected = String(op.id) === String(currentWorkerId) ? 'selected' : '';
|
||||||
|
sel.innerHTML += `<option value="${op.id}" ${isSelected}>${op.full_name}</option>`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
|
||||||
function buildGridCard(s) {
|
function buildGridCard(s) {
|
||||||
const raw = s.raw_data || {};
|
const raw = s.raw_data || {};
|
||||||
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Sin Nombre";
|
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Sin Nombre";
|
||||||
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 cita = raw.scheduled_date ? `${raw.scheduled_date.split('-').reverse().slice(0,2).join('/')} | ${raw.scheduled_time}` : 'Pte. Cita';
|
// FIX: Evitamos el 'undefined'
|
||||||
|
const timeStr = raw.scheduled_time ? raw.scheduled_time : '--:--';
|
||||||
|
const cita = raw.scheduled_date ? `${raw.scheduled_date.split('-').reverse().slice(0,2).join('/')} | ${timeStr}` : 'Pte. Cita';
|
||||||
const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || (s.provider === 'MANUAL' ? 'PARTICULAR' : 'ASEGURADORA');
|
const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || (s.provider === 'MANUAL' ? 'PARTICULAR' : 'ASEGURADORA');
|
||||||
|
|
||||||
const isUrgent = s.is_urgent === true || (raw['Urgente'] && raw['Urgente'].toLowerCase() === 'sí') || (raw['URGENTE'] && raw['URGENTE'].toLowerCase() === 'si');
|
const isUrgent = s.is_urgent === true || (raw['Urgente'] && raw['Urgente'].toLowerCase() === 'sí') || (raw['URGENTE'] && raw['URGENTE'].toLowerCase() === 'si');
|
||||||
@@ -809,7 +830,10 @@
|
|||||||
document.getElementById('panelAsignado').classList.remove('hidden');
|
document.getElementById('panelAsignado').classList.remove('hidden');
|
||||||
document.getElementById('panelSinAsignar').classList.add('hidden');
|
document.getElementById('panelSinAsignar').classList.add('hidden');
|
||||||
|
|
||||||
document.getElementById('detWorker').innerText = s.assigned_name;
|
// CARGAMOS EL DESPLEGABLE EN VEZ DEL TEXTO FIJO
|
||||||
|
const rawGuildId = s.guild_id || raw['guild_id'] || raw.guild_id;
|
||||||
|
loadOpsForReassign(rawGuildId, s.assigned_to);
|
||||||
|
|
||||||
document.getElementById('dateInput').value = raw.scheduled_date || "";
|
document.getElementById('dateInput').value = raw.scheduled_date || "";
|
||||||
document.getElementById('timeInput').value = raw.scheduled_time || "";
|
document.getElementById('timeInput').value = raw.scheduled_time || "";
|
||||||
document.getElementById('detStatusMap').value = stateInfo.id;
|
document.getElementById('detStatusMap').value = stateInfo.id;
|
||||||
@@ -864,6 +888,11 @@
|
|||||||
const time = document.getElementById('timeInput').value;
|
const time = document.getElementById('timeInput').value;
|
||||||
const statusMap = document.getElementById('detStatusMap').value;
|
const statusMap = document.getElementById('detStatusMap').value;
|
||||||
|
|
||||||
|
// 🚨 CAPTURAMOS AL NUEVO TÉCNICO SI LO HAS CAMBIADO
|
||||||
|
const newWorkerSelect = document.getElementById('detWorkerSelect');
|
||||||
|
const newWorkerId = newWorkerSelect ? newWorkerSelect.value : null;
|
||||||
|
const newWorkerName = (newWorkerSelect && newWorkerId) ? newWorkerSelect.options[newWorkerSelect.selectedIndex].text : "";
|
||||||
|
|
||||||
const selectedSt = systemStatuses.find(st => String(st.id) === String(statusMap));
|
const selectedSt = systemStatuses.find(st => String(st.id) === String(statusMap));
|
||||||
|
|
||||||
if (selectedSt && !selectedSt.is_final && !date && !selectedSt.name.toLowerCase().includes('pausa') && !selectedSt.name.toLowerCase().includes('asignar')) {
|
if (selectedSt && !selectedSt.is_final && !date && !selectedSt.name.toLowerCase().includes('pausa') && !selectedSt.name.toLowerCase().includes('asignar')) {
|
||||||
@@ -879,12 +908,19 @@
|
|||||||
await fetch(`${API_URL}/services/set-appointment/${id}`, {
|
await fetch(`${API_URL}/services/set-appointment/${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({ date, time, status_operativo: statusMap })
|
// ENVIAMOS LOS DATOS DEL NUEVO TÉCNICO
|
||||||
|
body: JSON.stringify({
|
||||||
|
date,
|
||||||
|
time,
|
||||||
|
status_operativo: statusMap,
|
||||||
|
assigned_to: newWorkerId || "",
|
||||||
|
assigned_to_name: newWorkerName
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
closeDetailModal(); showToast("Estado actualizado"); refreshPanel();
|
closeDetailModal(); showToast("Estado actualizado"); refreshPanel();
|
||||||
} catch (e) { alert("Error"); }
|
} catch (e) { alert("Error"); }
|
||||||
finally { btn.innerHTML = originalContent; btn.disabled = false; }
|
finally { btn.innerHTML = originalContent; btn.disabled = false; lucide.createIcons(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendToAutomate() {
|
async function sendToAutomate() {
|
||||||
|
|||||||
Reference in New Issue
Block a user