This commit is contained in:
2021-01-06 00:10:12 -06:00
parent d9563134b2
commit 34773defe0
7 changed files with 388 additions and 97 deletions
@@ -36,10 +36,16 @@
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
csv: {},
token: {
headers: {
token: window.localStorage.getItem("token"),
},
},
isLoading: false,
toastType: null,
toastMessage: null,
@@ -49,8 +55,8 @@ export default {
validarExt() {
const extPermitidas = /(.csv)$/i;
if (!extPermitidas.exec(this.csv.name)) {
this.toastType = 'is-danger'
this.toastMessage = 'Asegurate de ingresar un archivo .CSV'
this.toastType = "is-danger";
this.toastMessage = "Asegurate de ingresar un archivo .CSV";
this.toast();
this.csv = {};
}
@@ -72,27 +78,62 @@ export default {
onConfirm: () => this.enviarCargaMasiva(),
});
},
enviarCargaMasiva () {
enviarCargaMasiva() {
this.isLoading = true;
const formData = new FormData();
if (this.cartaAceptacion) {
formData.append("cartaAceptacion", this.cartaAceptacion);
}
axios
.put(`${process.env.api}/programa/carga_masiva`, formData)
.put(`${process.env.api}/programa/carga_masiva`, formData, {
headers: {
"Content-Type": "multipart/form-data",
token: this.token.headers.token,
},
})
.then((res) => {
this.isLoading = false;
this.toastType = 'is-success'
this.toastMessage = 'Se ha enviado la carga masiva con éxito'
this.toastType = "is-success";
this.toastMessage = "Se ha enviado la carga masiva con éxito";
this.toast();
})
.catch((err) => {
this.isLoading = false;
this.toastType = 'is-danger'
this.toastMessage = err.response.data.message
this.toast()
this.error(err.response.data.message);
console.log(err.response.data.message);
});
},
error(msj){
let salir =false;
switch(msj){
case 'invalid signature':
msj= "tu token no es valido, inicia sesión de nuevo"
break;
case 'jwt expired':
msj= "tu sesión ha expirado, inicia sesión de nuevo"
break;
case 'no hay token':
msj= "no has enviado tu token, inicia sesión de nuevo"
break;
default:
salir=true
}
this.$buefy.dialog.alert({
title: "Error",
message: msj,
type: "is-danger",
hasIcon: true,
icon: "alert-circle",
iconPack: "mdi",
ariaRole: "alertdialog",
ariaModal: true,
});
if (salir === true) {
localStorage.clear()
this.$router.push(`/`)
}
},
},
};
</script>
@@ -74,6 +74,11 @@ export default {
correo: "",
nombre: "",
idStatus: 1,
token: {
headers: {
token: window.localStorage.getItem("token"),
},
}
};
},
methods: {
@@ -87,7 +92,8 @@ export default {
this.data = [];
axios
.get(
`${process.env.api}/usuario/responsable?pagina=${this.page}&nombre=${this.nombre}&correo=${this.correo}`
`${process.env.api}/usuario/responsable?pagina=${this.page}&nombre=${this.nombre}&correo=${this.correo}`,
this.token
)
.then((res) => {
const servicios = res.data.servicios;
@@ -110,10 +116,42 @@ export default {
this.loading = false;
})
.catch((err) => {
console.log(err.response.data.message);
this.loading = false;
this.error(err.response.data.message);
console.log(err.response.data.message);
});
},
error(msj){
let salir =false;
switch(msj){
case 'invalid signature':
msj= "tu token no es valido, inicia sesión de nuevo"
break;
case 'jwt expired':
msj= "tu sesión ha expirado, inicia sesión de nuevo"
break;
case 'no hay token':
msj= "no has enviado tu token, inicia sesión de nuevo"
break;
default:
salir=true
}
this.$buefy.dialog.alert({
title: "Error",
message: msj,
type: "is-danger",
hasIcon: true,
icon: "alert-circle",
iconPack: "mdi",
ariaRole: "alertdialog",
ariaModal: true,
});
if (salir === true) {
localStorage.clear()
this.$router.push(`/`)
}
},
insertIdLocal() {
this.idUsuario = localStorage.getItem("idUsuario");
},