From b93ff58453e2843c9fcdcd3a664742aa521557cb Mon Sep 17 00:00:00 2001 From: guilherme guia Date: Thu, 19 Oct 2023 19:08:09 +0000 Subject: [PATCH] Habilitando a pesquisa de atendimentos na fila de espera e em conversasao --- public/js/main.js | 25 +++++++++------- public/js/requests.js | 1 - public/js/util.js | 67 +++++++++++++++++++++++++++---------------- 3 files changed, 58 insertions(+), 35 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index 3e597fc..b14b580 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -47,9 +47,12 @@ $(function () { }); $("#btnFila").on("click", () => { filaNotifications(); + isAtend = false; }); $("#btnAtendimento").on("click", () => { notifications(); + isAtend = true; + click_btn(document.querySelector("#btnAtendimento")); }); $("#exitChat").on("click", () => { abrirMensagem = false; @@ -82,13 +85,17 @@ $(function () { recuperarAtendimento(); } }); + $("input[name=contato]").on("keyup", (event) => { + let input = event.target + input.value = phoneMask(input.value) + }); /** * HABILITA O ENVIO DE MIDIAS CTRL+V */ $(document).on('keydown', function (e) { if (e.ctrlKey || e.metaKey) { if (e.keyCode == 86) { // 86 é o código da tecla "V" - if(+localStorage.getItem('session_status') === 0) return; + if (+localStorage.getItem('session_status') === 0) return; $(document).one('paste', function (event) { // Verifica se o que foi colado é uma imagem if (event.originalEvent.clipboardData.items && event.originalEvent.clipboardData.items.length) { @@ -179,7 +186,7 @@ $(function () { * EVENTOS DE CLICK PARA SELECIONAR A SESSAO DE MENSAGEM/CONVERSA E RECUPERAR AS MENSAGENS JA TROCADAS NO ATENDIMENTO * @param {*} id */ -const selectNotification = (id, status, datetime) => { +const selectNotification = (id, status, datetime, chatType) => { marcarMensagemVista(id); toggleEnvioTemplates(0); listaMensagem(id).then(async () => { @@ -192,13 +199,11 @@ const selectNotification = (id, status, datetime) => { listarAtendimentoAgente( localStorage.getItem("my_uniqueid") ); - const allNotifications = JSON.parse( - localStorage.getItem("obj_search") - ); + const allNotifications = typeChat(chatType); const atendimentos = await buscarAtendimento(id); hideButtons(false); - allNotifications.data.forEach((e) => { + allNotifications.forEach((e) => { $("#" + e.uniqueid.replace(".", `\\.`)).removeClass( "select-notification" ); @@ -208,13 +213,13 @@ const selectNotification = (id, status, datetime) => { monitoraStatusRecuperacaoAtendimento(datetime); } const statusIsSended = e.evento === sendTemplate; - if(e.uniqueid == id && statusIsSended){ + if (e.uniqueid == id && statusIsSended) { hideButtons(true); } }); $("#" + id.replace(".", `\\.`)).addClass("select-notification"); - allNotifications.data.forEach((e) => { + allNotifications.forEach((e) => { if (e.uniqueid == id && e.status == 0) { hideButtons(true); monitoraStatusRecuperacaoAtendimento(datetime); @@ -229,7 +234,7 @@ const selectNotification = (id, status, datetime) => { }); } - allNotifications.data.forEach((e) => { + allNotifications.forEach((e) => { if (id === e.uniqueid) { uniqueid = e.uniqueid; name = e.nome; @@ -383,7 +388,7 @@ const sendMessage = (obj = {}) => { const agent = JSON.parse(localStorage.getItem("obj_status")); if (!sendNumber || !myUniqueid || !agent) { - + alert('Não foi possível carregar todas as informações da sessão do atendimento! Por favor, Tente novamente.'); return; } diff --git a/public/js/requests.js b/public/js/requests.js index d9a1b77..f8beeb9 100644 --- a/public/js/requests.js +++ b/public/js/requests.js @@ -390,7 +390,6 @@ const cadastrarContato = (dataSend) => new Promise((resolve) =>{ resolve(res) }, error: function (res) { - console.log(res); alert(res.responseText); } }); diff --git a/public/js/util.js b/public/js/util.js index f3cd469..860399c 100644 --- a/public/js/util.js +++ b/public/js/util.js @@ -1,3 +1,12 @@ +const phoneMask = (value) => { + if (!value) return "" + value = value.replace(/\D/g,'') + value = value.replace(/(\d{2})(\d)/,"+$1 $2") + value = value.replace(/(\d{2})(\d)/,"($1) $2") + value = value.replace(/(\d)(\d{4})$/,"$1-$2") + return value +} + /** ROLAGEM DO SCROLL AT NO FINAL DO CHAT */ const scrollDown = () => { $(".chat-window").animate({ scrollTop: 99999 * $(this).height() }, 1); @@ -16,21 +25,20 @@ function formatedNumber(telefone) { } const search = (input) => { let inputValue = input.value.trim(); - $("#chats").empty(); - const atendimentos = JSON.parse(localStorage.getItem('obj_search')).data; - let pesquisa; - let chatList = ""; - if (!inputValue) { - notifications(); - return; + return isAtend ? notifications() : filaNotifications();; } + $("#chats").empty(); + const key = isAtend ? 'obj_search' : 'obj_queueNotification'; + const atendimentos = JSON.parse(localStorage.getItem(key)); + let pesquisa; + let chatList = ""; pesquisa = atendimentos.filter((atendimento) => { return ( - atendimento.nome.toLowerCase().includes(inputValue.toLowerCase()) || - atendimento.protocolo.toString().includes(inputValue.toLowerCase()) || - atendimento.cliente_id.toString().includes(inputValue.toLowerCase()) + atendimento?.nome.toLowerCase().includes(inputValue.toLowerCase()) || + atendimento?.protocolo.toString().includes(inputValue.toLowerCase()) || + atendimento?.cliente_id.toString().includes(inputValue.toLowerCase()) ) }); @@ -50,7 +58,8 @@ const search = (input) => { status: e.status, protocolo: e.protocolo, media: e.media, - evento: e.evento + evento: e.evento, + type: chatTypes.search }); }); @@ -377,11 +386,10 @@ const enviaHsm = async (btn) => { toggleEnvioTemplates(false); abrirTelaContato(); const atendimento = response.data.data; - startSearch(); notifications(); loadingBtn(btn, "Enviar Mensagem", false) setTimeout(() => { - selectNotification(atendimento.uniqueid, true, atendimento.data_reg); + selectNotification(atendimento.uniqueid, true, atendimento.data_reg, chatTypes.notification); }, 1000); } } @@ -397,13 +405,29 @@ const cadastroContato = async (form) => { descricao: formData.get("descricao"), status: formData.get("ativo") }; - const response = await cadastrarContato(dataSend); if (response) { alert('Cadastrado com sucesso'); voltarTelaCadastro(); } } +/** + * Gerencia a renderização do chat +*/ +const typeChat = (type) => { + let data; + switch (type) { + case 1: + data = JSON.parse(localStorage.getItem("obj_search")) + break; + case 2: + data = JSON.parse(localStorage.getItem("obj_notification")).data + break; + default: + break; + } + return data; +} /** * GERENCIA A RESPONSIVIDADE DO LAYOUT */ @@ -889,7 +913,7 @@ const buildNotification = (data = {}) => { const badge = data.evento === sendTemplate ? "" : "" const datesend = converdata(data.datetime); const status = (data.status == 0) ? "opacity-8" : ""; - return `
+ return `
@@ -991,7 +1015,7 @@ const startSearch = () => { localStorage.getItem("my_uniqueid") ).then(res => { localStorage.removeItem('obj_search'); - localStorage.setItem('obj_search', JSON.stringify(res)); + localStorage.setItem('obj_search', JSON.stringify(res.data)); }) } /** @@ -1046,12 +1070,11 @@ const notifications = (obj = {}) => { status: e.status, protocolo: e.protocolo, media: e.media, - evento: e.evento + evento: e.evento, + type: chatTypes.notification }); }); - chatsArray = chat; - click_btn(document.querySelector("#btnAtendimento")); $("#chats").append(chatList); }); }; @@ -1092,9 +1115,7 @@ const filaNotifications = (obj = {}) => { media: e.media, }); }); - - chatsArray = chat; - + localStorage.setItem('obj_queueNotification', JSON.stringify(chat)); $("#chats").append(chatList); } ); @@ -1158,12 +1179,10 @@ const supervisorAgente = () => { window.close(); } startSearch(); - notifications(); }); }, 30000); }; - /** CONNECT TO WS */ const connect = (wsserver) => { const ws = new WebSocket(wsserver);