Vue.component('formulario-paso-1', { props: ['paises', 'distribuidor'], data: () => ({ msgError: '', nombre: '', apellidos: '', correo: '', pais: 'MEX', telefono: '', completo: false }), methods: { validarFormulario() { var nombre = this.nombre; if ((nombre == '') || (nombre.length < 2)) { this.msgError = 'El campo "Nombre" debe de contener información válida.'; this.limpiarMensaje(); return false; } var apellidos = this.apellidos; if ((apellidos == '') || (apellidos.length < 2)) { this.msgError = 'El campo "Apellidos" debe de contener información válida.'; this.limpiarMensaje(); return false; } var correo = this.correo; if (correo == '') { this.msgError = 'El campo "Correo" no debe de estar vacío.'; this.limpiarMensaje(); return false; } else if (!this.validarCorreo(correo)) { this.msgError = 'El correo registrado debe de ser un correo electrónico válido.'; this.limpiarMensaje(); return false; } var pais = this.pais; if (pais == '') { this.msgError = 'El campo "País" no debe de estar vacío.'; this.limpiarMensaje(); return false; } var telefono = this.telefono; if (telefono == '') { this.msgError = 'El campo "Teléfono" no debe de estar vacío.'; this.limpiarMensaje(); return false; } else { if (pais == 'MEX') { if (!this.validarTelefono(telefono)) { this.msgError = 'El teléfono registrado debe de ser un número telefonico valido a 10 digitos.'; this.limpiarMensaje(); return false; } } } this.enviarDatos(); }, limpiarMensaje() { var obj = this; setTimeout(function() { obj.msgError = ''; }, 4000); }, validarCorreo(correo) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(correo); }, validarTelefono: function(telefono) { var regla = /[0-9]{10}/; return regla.test(telefono); }, enviarDatos() { var obj = this; this.completo = true; axios.post('php/mysql/registro-principal.php', { params: { idDistribuidor: obj.distribuidor, nombre: obj.nombre, apellidos: obj.apellidos, correo: obj.correo, pais: obj.pais, telefono: obj.telefono } }).then(response => { var objRespuesta = response.data; if (!objRespuesta['boolError']) { window.location = 'registro-parte2.html?&' + obj.pais + '&' + objRespuesta['registro'] + '&' + obj.distribuidor; } obj.completo = false; }).catch(e => { console.log(e); }); } }, template: /* template */ `