/* */ let AMBIENTE_PRODUCAO = true; class Engine { constructor () { this.comunicar = async (classe, acao, dados)=>{ // Default options are marked with * console.log("Engine.comunicar"); console.log(classe); console.log(acao); console.log(dados); let _dados = dados || {}; _dados.SID = sessionStorage.SID || null; let url = (AMBIENTE_PRODUCAO?"/ws/":"/ws_dev/") + classe + "/" + acao; const response = await fetch(url, { method: 'POST', // *GET, POST, PUT, DELETE, etc. mode: 'cors', // no-cors, *cors, same-origin cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached credentials: 'same-origin', // include, *same-origin, omit headers: { Accept: "application/json", "Content-Type": "application/json; charset=UTF-8", // 'Content-Type': 'application/x-www-form-urlencoded', }, redirect: 'follow', // manual, *follow, error referrerPolicy: 'no-referrer', // no-referrer, *client body: JSON.stringify(_dados) // body data type must match "Content-Type" header }); let resultado = await response.text(); // parses JSON response into native JavaScript objects console.log(resultado); return JSON.parse(resultado); } this.iniciar = async (token, doc)=>{ let dados = {} if ((token || null) != null) dados.TOKEN = token; if ((doc || null) != null) dados.DOC = doc; let resultado = await engine.comunicar("login", "iniciar", dados) return resultado } this.validar = async (dados, sucesso, falha)=>{ this.exibeAguarde(); let resultado = await this.comunicar("login", "validar", dados) this.ocultaAguarde(); if (resultado.ERRO == 0) { sessionStorage.setItem("SID", resultado.SID); sessionStorage.setItem("DADOS", JSON.stringify(resultado)); if (sucesso || null) sucesso(resultado); } else { if (falha || null) falha(resultado); } return resultado; }; this.logout = async ()=>{ let resultado = await this.comunicar("login", "logout", null); if (resultado.ERRO == 0) { sessionStorage.clear(); window.location.href = "index.html"; } return resultado; }; this.debitos = async ()=>{ this.exibeAguarde(); let resultado = await this.comunicar("debitos", "listar", null); this.ocultaAguarde(); return resultado; } this.informar_nao_reconhece = async (telefone, msg)=>{ this.exibeAguarde() let resultado = await this.comunicar("debitos", "nao_reconheco", {TELEFONE: telefone, MSG: msg }) this.ocultaAguarde() return resultado } this.pagar_cartao = async (dados)=>{ this.exibeAguarde() let resultado = await this.comunicar("pagamento", "cartao", {DADOS_CARTAO: dados}) this.ocultaAguarde() return resultado } this.gerar_boleto = async (n_parcelas, valor, forma_aviso, valor_aviso)=>{ this.exibeAguarde() let resultado = await this.comunicar("pagamento", "boleto", {QTD_PARCELAS : n_parcelas, VALOR: valor, FORMA_AVISO: forma_aviso, VALOR_AVISO: valor_aviso }) this.ocultaAguarde() return resultado } this.enviar_lead = async (telefone)=>{ this.exibeAguarde() let resultado = await this.comunicar("leads", "adicionar", {telefone}) this.ocultaAguarde() return resultado } this.dados_pix = async (txid)=>{ this.exibeAguarde() let resultado = await this.comunicar("pix", "ler", {txid}) this.ocultaAguarde() return resultado } this.exibeAguarde = ()=>{ var $aguarde = $("