boletin-vue.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. new Vue({
  2. el: '#appmodal',
  3. data: {
  4. errors: [],
  5. email: null,
  6. form: true,
  7. loader: false,
  8. respuesta: false,
  9. imagen: "",
  10. message: ""
  11. },
  12. i18n,
  13. langnavi: '',
  14. langstore: '',
  15. mounted() {
  16. if (localStorage.getItem("idioma")) {
  17. this.obtenerIdioma();
  18. } else {
  19. this.obtenerGeolocalizaion();
  20. }
  21. let cookieBoletin = $cookies.get('boletin');
  22. if (cookieBoletin == null) {
  23. setTimeout(function() {
  24. $('.submenu-conoce').hide('slow');
  25. $('.submenu-construye').hide('slow');
  26. $('#ouibounce-modal').show();
  27. }, 30000);
  28. }
  29. },
  30. methods: {
  31. cambiarIdioma(idioma) {
  32. i18n.locale = idioma;
  33. },
  34. obtenerGeolocalizaion() {
  35. navlang = navigator.browserLanguage || navigator.language;
  36. this.langnavi = navlang.substr(-20, 2);
  37. i18n.locale = this.langnavi;
  38. },
  39. guardarIdioma(idioma) {
  40. this.langstorage = idioma;
  41. i18n.locale = this.langstorage;
  42. localStorage.setItem("idioma", this.langstorage);
  43. },
  44. obtenerIdioma() {
  45. let langs = localStorage.getItem("idioma");
  46. if (langs == 'es') {
  47. i18n.locale = 'es';
  48. this.langnavi = 'es';
  49. } else if (langs == 'en') {
  50. i18n.locale = 'en';
  51. this.langnavi = 'en';
  52. }
  53. },
  54. checkForm: function(e) {
  55. this.errors = [];
  56. if (this.email == null || this.email == '') {
  57. console.log(this.langnavi);
  58. if (this.langnavi == 'es') {
  59. this.errors.push("Es necesario ingresar una dirección de correo electrónico.");
  60. } else if (this.langnavi == 'en') {
  61. this.errors.push("You need to enter an email address.");
  62. }
  63. } else if (!this.validEmail(this.email)) {
  64. if (this.langnavi == 'es') {
  65. this.errors.push("Por favor, introduce un correo electrónico válido.");
  66. } else if (this.langnavi == 'en') {
  67. this.errors.push("Please enter a valid email.");
  68. }
  69. }
  70. if (!this.errors.length) {
  71. this.sendData();
  72. }
  73. e.preventDefault();
  74. },
  75. validEmail: function(email) {
  76. 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,}))$/;
  77. return re.test(email);
  78. },
  79. closeModal() {
  80. $('#ouibounce-modal').hide();
  81. },
  82. sendData() {
  83. this.loader = true;
  84. this.form = false,
  85. axios.post('mysql/suscripcion-boletin.php', {
  86. params: {
  87. correo: this.email
  88. }
  89. }).then(response => {
  90. var objRespuesta = response.data;
  91. if (!objRespuesta.error && objRespuesta.respuesta == 'Exito') {
  92. this.imagen = "images/shared/success.gif";
  93. if (this.langnavi == 'es') {
  94. this.message = "Se ha registrado con éxito.";
  95. } else if (this.langnavi == 'en') {
  96. this.message = "You have registered successfully.";
  97. }
  98. } else if (objRespuesta.error) {
  99. this.imagen = "images/shared/error.gif";
  100. if (this.langnavi == 'es') {
  101. this.message = "Ups! Ha ocurrido un error, intentalo más tarde.";
  102. } else if (this.langnavi == 'en') {
  103. this.message = "Oops! An error has occurred, please try again later.";
  104. }
  105. }
  106. this.loader = false;
  107. this.respuesta = true;
  108. window.$cookies.set("boletin", this.email, "1y", null, null, true, "Lax");
  109. setTimeout(function() {
  110. $('#ouibounce-modal').hide();
  111. }, 3500);
  112. }).catch(e => {
  113. // console.log(e);
  114. this.imagen = "images/shared/error.gif";
  115. if (this.langnavi == 'es') {
  116. this.message = "Ups! Ha ocurrido un error, intentalo más tarde.";
  117. } else if (this.langnavi == 'en') {
  118. this.message = "Oops! An error has occurred, please try again later.";
  119. }
  120. this.loader = false;
  121. this.respuesta = true;
  122. setTimeout(function() {
  123. $('#ouibounce-modal').hide();
  124. }, 3500);
  125. });
  126. }
  127. }
  128. })