var URL_IN_VENDOR = env.loginURL + "/vendor/in"; var vendorlogin = new Vue({ el: '#vendorlogin_form', store, data: { btnIniciarSesion: { label:'Iniciar Sesión', textIniciarSesion:'Iniciar Sesión', textIniciandoSesion:'Iniciando Sesión...', bloqueado: false, cerrar:'Cerrar Sesión' }, respuesta:{ mensajeError:'', alertaVisible: false, alertaVisibleErrorContrasenia: false, alertaVisibleSuccess: false, mensajeSuccess:'', }, dataForm:{ username: '', password: '', sessionType: 'WEB_SESSION' }, ventaSesion: { sinVendor: true, iniciaVenta: false }, typeProduct:'Flex' }, created: function () { //Verifica que no haya expirado la sesion /* var sessionExpiro = localStorage.getItem("session-expirada") == 'true'; if(sessionExpiro){ this.respuesta.mensajeError='Tu sesión ha expirado'; this.respuesta.alertaVisible=true; localStorage.setItem("session-expirada", false); }else{ this.respuesta.mensajeError=''; this.respuesta.alertaVisible=false; } */ // tipo de producto this.typeProduct = localStorage.getItem('typeProduct'); }, methods: { vendorlogin: function(event){ if(event) event.preventDefault(); if(this.btnIniciarSesion.bloqueado) return; /* if(!$("#flex_login_form").valid()) { alert('test'); return; } */ this.respuesta.mensajeSuccess=''; this.respuesta.alertaVisibleSuccess=false; this.btnIniciarSesion.label = this.btnIniciarSesion.textIniciandoSesion; this.btnIniciarSesion.bloqueado = true; // Reset localStorage session vendor this.$store.dispatch("addFlexVendor", { vendorid: '', usersiebel: '', vendorname: '', vendortype: '' }); if(document.getElementById('flex_login_correo').value == '' || document.getElementById('flex_login_password').value == ''){ //alert('Usuario y contraseña son requeridos...'); this.respuesta.mensajeError='Usuario y contraseña son requeridos...'; this.respuesta.alertaVisible=true; this.btnIniciarSesion.label = this.btnIniciarSesion.textIniciarSesion; this.btnIniciarSesion.bloqueado = false; return; } axios.post(URL_IN_VENDOR, { usersiebel: document.getElementById('flex_login_correo').value, password: document.getElementById('flex_login_password').value } ,{ headers:{'Content-Type': 'application/json'} }).then( result => { this.respuesta.alertaVisibleErrorContrasenia=false; this.respuesta.alertaVisible=false; this.respuesta.mensajeError = ''; if(result.data.code != null && result.data.code=='RSP_01'){ console.log(' --- Credenciales del vendedor incorrectas ---'); this.btnIniciarSesion.label = this.btnIniciarSesion.textIniciarSesion; this.btnIniciarSesion.bloqueado = false; this.respuesta.mensajeError='Credenciales del vendedor incorrectas...'; this.respuesta.alertaVisible=true; } else if(result.data.code != null && result.data.code=='RSP_00'){ // guardar en localStorage this.$store.dispatch("addFlexVendor", { vendorid: result.data.response.vendorid, usersiebel: result.data.response.usersiebel, vendorname: result.data.response.vendorname, vendortype: result.data.response.vendortype }); console.log(this.$store.getters.getFlexVendor.vendorid + ' ==>' + this.$store.getters.getFlexVendor.usersiebel ); // obtener var obj = this.$store.getters.getFlexVendor; //alert(obj.vendorname); this.btnIniciarSesion.label = this.btnIniciarSesion.textIniciarSesion; this.btnIniciarSesion.bloqueado = false; this.ventaSesion.sinVendor = false; this.ventaSesion.iniciaVenta = true; } /* var headers = result.headers; if(headers.authorization !== undefined){ this.respuesta.alertaVisible = false; this.respuesta.mensajeError = ''; var token = headers.authorization.replace('Bearer ', ''); login.$store.dispatch('addBearerToken', {bearerToken: token}); var profile = JSON.parse(headers.profile); login.$store.dispatch('addProfile', profile); login.redireccionarLogin(); } else { this.respuesta.alertaVisible = true; this.respuesta.mensajeError = headers.autherrormessage; if(this.respuesta.mensajeError=='error1'){ this.respuesta.alertaVisibleErrorContrasenia=true; this.respuesta.alertaVisible=false; } login.btnIniciarSesion.label = login.btnIniciarSesion.textIniciarSesion; login.btnIniciarSesion.bloqueado = false; } */ }, error => { this.respuesta.alertaVisible = true; this.respuesta.mensajeError = 'Algo salio mal, intentarlo más tarde.'; this.btnIniciarSesion.label = this.btnIniciarSesion.textIniciarSesion; this.btnIniciarSesion.bloqueado = false; } ); }, vendorlogout: function(event){ if(event) event.preventDefault(); //if(this.btnIniciarSesion.bloqueado) return; // Reset localStorage session vendor this.$store.dispatch("addFlexVendor", { vendorid: '', usersiebel: '', vendorname: '', vendortype: '' }); this.respuesta.mensajeSuccess='Sesión finalizada...'; this.respuesta.alertaVisibleSuccess=true; this.btnIniciarSesion.label = this.btnIniciarSesion.textIniciarSesion; this.btnIniciarSesion.bloqueado = false; }, redireccionarLogin: function(){ //Verifica que tenga un token vigente var promesaToken = session.isTokenValid(); promesaToken.then(function(value){ if(value){ //Obtiene la promesa si existen pedidos. var promesaPedidos = products.hasPedidos(); //Cuando la promesa se cumpla verifica que tenga pedidos promesaPedidos.then(function(value){ localStorage.setItem("hasPedidos", value ); if(value){ //Obtiene la promesa si existe un pedido pendiente // login.btnIniciarSesion.label = login.btnIniciarSesion.textIniciarSesion; // this.btnIniciarSesion.bloqueado = false; var promesaPedidosPendientes = products.hasPedidosPendientes(); //Cuando la promesa se cumpla redirecciona promesaPedidosPendientes.then(function(value){ if(value){ location.href = 'micuenta-pedido.html'; }else{ location.href = 'micuenta-miflex.html'; } }); }else{ //Verifica si hay paquete if(products.hasPaquete()){ if( localStorage.getItem('typeProduct') == "Pocket" ) location.href = 'contratacion.html'; else location.href = 'contratacion.html'; }else{ if( localStorage.getItem('typeProduct') == "Pocket" ) location.href = "detalle-pocket.html"; else location.href = "detalle-flex.html"; } } }); } }); }, } });