Adiciona Fluxo de Resolução (motivo + resolução do atendimento)
- Settings > Fluxo: cadastro de motivos e flags (visualizar/obrigatório para motivo e resolução) - Tela de conversa: dropdown de motivos + campo de resolução abaixo dos dados do titular, exibidos conforme configuração - Finalização valida obrigatoriedade (front e backend) e salva CON_MOTIVO_ID/CON_RESOLUCAO - Estrutura criada de forma idempotente (Postgres/Firebird) em src/resolucaoSetup.js; CRUD de motivos restrito a gerente Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+72
-6
@@ -685,7 +685,20 @@ window.darkModeIsDark=function(){return localStorage.getItem('chatc2_dark_mode')
|
||||
<div class="header"><h3>📋 Informações</h3></div>
|
||||
<div class="cliente-foto" id="clienteFoto">?</div>
|
||||
<div class="info-section" id="clienteInfoContainer"></div>
|
||||
|
||||
|
||||
<!-- Fluxo de Resolução (aparece conforme configuração da empresa) -->
|
||||
<div class="info-section" id="resolucaoPanel" style="display:none">
|
||||
<div class="label" style="font-size:10px;text-transform:uppercase;color:#9ca3af;margin-bottom:6px">RESOLUÇÃO DO ATENDIMENTO</div>
|
||||
<div id="motivoWrap" style="display:none;margin-bottom:8px">
|
||||
<select id="selectMotivo" style="width:100%;padding:6px 8px;border:1px solid #e5e7eb;border-radius:6px;font-size:12px;outline:none">
|
||||
<option value="">Selecione o motivo...</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="resolucaoWrap" style="display:none">
|
||||
<textarea id="campoResolucao" rows="3" placeholder="Descreva a resolução do atendimento..." style="width:100%;padding:8px;border:1px solid #e5e7eb;border-radius:6px;font-size:12px;outline:none;resize:vertical;font-family:inherit"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<div class="label" style="font-size:10px;text-transform:uppercase;color:#9ca3af;margin-bottom:4px">ATENDENTE</div>
|
||||
<select id="selectAtendente" style="width:100%;padding:6px 8px;border:1px solid #e5e7eb;border-radius:6px;font-size:12px;outline:none" onchange="mudarAtendente(this)">
|
||||
@@ -746,6 +759,36 @@ function esc(s){ return String(s == null ? '' : s)
|
||||
.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>')
|
||||
.replace(/"/g,'"').replace(/'/g,'''); }
|
||||
|
||||
// ===== FLUXO DE RESOLUÇÃO =====
|
||||
var cfgResolucao = { motivoVisualizar:'N', motivoObrigatorio:'N', resolucaoVisualizar:'N', resolucaoObrigatorio:'N' };
|
||||
var motivosList = [];
|
||||
async function carregarConfigResolucao() {
|
||||
try {
|
||||
var cd = await (await fetch('/api/' + alias + '/company/config?empresaId=' + empresaId, { headers: { 'Authorization': 'Bearer ' + token } })).json();
|
||||
if (cd.success && cd.data) cfgResolucao = cd.data;
|
||||
var md = await (await fetch('/api/' + alias + '/motivos?empresaId=' + empresaId, { headers: { 'Authorization': 'Bearer ' + token } })).json();
|
||||
if (md.success) motivosList = md.data || [];
|
||||
} catch(e) {}
|
||||
}
|
||||
function aplicarPainelResolucao(conv) {
|
||||
var panel = document.getElementById('resolucaoPanel');
|
||||
if (!panel) return;
|
||||
var verMot = cfgResolucao.motivoVisualizar === 'S';
|
||||
var verRes = cfgResolucao.resolucaoVisualizar === 'S';
|
||||
panel.style.display = (verMot || verRes) ? 'block' : 'none';
|
||||
document.getElementById('motivoWrap').style.display = verMot ? 'block' : 'none';
|
||||
document.getElementById('resolucaoWrap').style.display = verRes ? 'block' : 'none';
|
||||
if (verMot) {
|
||||
var sel = document.getElementById('selectMotivo');
|
||||
sel.innerHTML = '<option value="">Selecione o motivo...</option>' +
|
||||
motivosList.map(function(m){ return '<option value="' + m.id + '">' + esc(m.descricao) + '</option>'; }).join('');
|
||||
sel.value = (conv && conv.motivoId) ? String(conv.motivoId) : '';
|
||||
}
|
||||
if (verRes) {
|
||||
document.getElementById('campoResolucao').value = (conv && conv.resolucao) ? conv.resolucao : '';
|
||||
}
|
||||
}
|
||||
|
||||
// ===== NAVEGAÇÃO =====
|
||||
document.querySelectorAll('.sidebar-left .nav-tabs a').forEach(function(a) {
|
||||
a.addEventListener('click', function(e) { e.preventDefault(); });
|
||||
@@ -884,6 +927,7 @@ function renderInfoConversa(conv) {
|
||||
}
|
||||
|
||||
window._convAtual = conv;
|
||||
aplicarPainelResolucao(conv);
|
||||
|
||||
// Info cliente
|
||||
var infoContainer = document.getElementById('clienteInfoContainer');
|
||||
@@ -1361,11 +1405,31 @@ dropArea.addEventListener('drop', function(e) {
|
||||
|
||||
// ===== FINALIZAR =====
|
||||
window.finalizarConversa = async function() {
|
||||
if (!conversaAtiva || !confirm('Finalizar esta conversa?')) return;
|
||||
if (!conversaAtiva) return;
|
||||
|
||||
// Coleta motivo/resolução (se visíveis) e valida obrigatoriedade
|
||||
var motivoId = null, resolucao = '';
|
||||
if (cfgResolucao.motivoVisualizar === 'S') {
|
||||
var sel = document.getElementById('selectMotivo');
|
||||
motivoId = sel && sel.value ? parseInt(sel.value, 10) : null;
|
||||
if (cfgResolucao.motivoObrigatorio === 'S' && !motivoId) {
|
||||
alert('Selecione o motivo do atendimento para finalizar.'); return;
|
||||
}
|
||||
}
|
||||
if (cfgResolucao.resolucaoVisualizar === 'S') {
|
||||
var txt = document.getElementById('campoResolucao');
|
||||
resolucao = txt ? (txt.value || '').trim() : '';
|
||||
if (cfgResolucao.resolucaoObrigatorio === 'S' && !resolucao) {
|
||||
alert('Preencha a resolução do atendimento para finalizar.'); return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!confirm('Finalizar esta conversa?')) return;
|
||||
try {
|
||||
var res = await fetch('/api/' + alias + '/conversations/' + conversaAtiva + '/finalize', {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': 'Bearer ' + token }
|
||||
headers: { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ motivoId: motivoId, resolucao: resolucao })
|
||||
});
|
||||
var data = await res.json();
|
||||
if (data.success) {
|
||||
@@ -1374,6 +1438,8 @@ window.finalizarConversa = async function() {
|
||||
document.querySelector('.btn-finalizar').style.opacity = '0.6';
|
||||
carregarConversas();
|
||||
abrirConversa(conversaAtiva);
|
||||
} else {
|
||||
alert(data.error || 'Não foi possível finalizar a conversa.');
|
||||
}
|
||||
} catch(e) {}
|
||||
};
|
||||
@@ -1519,9 +1585,9 @@ window.mudarFiltro = function(filtro, el) {
|
||||
|
||||
// ===== INICIAR =====
|
||||
carregarConversas();
|
||||
if (conversaId) {
|
||||
setTimeout(function() { abrirConversa(parseInt(conversaId)); }, 300);
|
||||
}
|
||||
carregarConfigResolucao().then(function() {
|
||||
if (conversaId) abrirConversa(parseInt(conversaId));
|
||||
});
|
||||
|
||||
// ===== LOGOUT =====
|
||||
window.logout = function() {
|
||||
|
||||
Reference in New Issue
Block a user