Files
servicio_social_front/components/responsable/cartaTermino.vue
T

191 lines
4.6 KiB
Vue
Raw Normal View History

2020-12-04 17:22:54 -06:00
<template>
2021-01-04 20:34:02 -06:00
<div
v-if="idServicio != null && cartaTermino != null"
class="container footter"
>
2021-01-04 17:31:37 -06:00
<b-button
2021-01-04 20:34:02 -06:00
class="border-info mt-5"
2021-01-04 17:31:37 -06:00
type="is-info is-light"
icon-left="arrow-left-box"
tag="router-link"
to="/responsable"
>Regresar</b-button
>
2021-01-04 20:34:02 -06:00
<h3 class="title is-4 mt-4">
2020-12-08 21:50:16 -06:00
Carta de termino (en formato .PDF. No se aceptan fotos).
</h3>
2020-12-04 17:22:54 -06:00
<b-field>
2020-12-08 21:50:16 -06:00
<b-upload
v-model="file"
drag-drop
type="is-black"
expanded
accept="application/pdf"
>
<section class="section">
<div class="content has-text-centered">
<p>
<b-icon icon="upload" size="is-large"></b-icon>
</p>
<p>
{{
file.name || "Arrastra aquí tu archivo o da click para buscar"
}}
</p>
<p>Tamaño máximo para el archivo: 20MB</p>
</div>
</section>
</b-upload>
2020-12-04 17:22:54 -06:00
</b-field>
2020-12-04 17:55:45 -06:00
2020-12-07 16:13:14 -06:00
<b-field class="centro">
<b-button
2020-12-08 21:50:16 -06:00
:disabled="file == ''"
2021-01-04 18:02:57 -06:00
class="border-success my-5 is-medium"
type="is-success"
2020-12-09 20:22:40 -06:00
@click="Enviar()"
2020-12-08 21:50:16 -06:00
>
Enviar
2020-12-08 18:41:21 -06:00
</b-button>
2020-12-07 16:13:14 -06:00
</b-field>
2021-01-05 18:54:43 -06:00
<b-loading :is-full-page="true" v-model="isLoading" :can-cancel="true">
</b-loading>
2020-12-08 21:50:16 -06:00
</div>
2020-12-04 17:22:54 -06:00
</template>
<script>
2020-12-09 20:22:40 -06:00
import axios from "axios";
2021-01-04 20:34:02 -06:00
2020-12-04 17:22:54 -06:00
export default {
2020-12-08 21:50:16 -06:00
data() {
2020-12-04 17:22:54 -06:00
return {
2020-12-10 13:06:44 -06:00
isFullPage: true,
2020-12-09 20:22:40 -06:00
file: [],
idServicio: "",
2020-12-14 14:19:16 -06:00
cartaTermino: "",
2021-01-05 18:54:43 -06:00
isLoading: false,
2021-01-04 20:34:02 -06:00
token: {
headers: {
token: window.localStorage.getItem("token"),
},
},
2020-12-08 21:50:16 -06:00
};
2020-12-08 18:41:21 -06:00
},
methods: {
2020-12-08 21:50:16 -06:00
validarTamaño() {
const TamMax = 20000000;
const archivo = this.file;
2021-01-22 18:50:32 -06:00
2020-12-08 18:41:21 -06:00
if (archivo.size > TamMax) {
2020-12-08 21:50:16 -06:00
this.toast();
this.file = "";
2020-12-08 18:41:21 -06:00
}
},
2020-12-08 21:50:16 -06:00
toast() {
2020-12-08 18:41:21 -06:00
this.$buefy.toast.open({
2020-12-08 21:50:16 -06:00
message: "El archivo excede el tamaño permitido",
type: "is-danger",
});
},
2020-12-09 20:22:40 -06:00
Enviar() {
const data = { idServicio: this.idServicio };
const formData = new FormData();
2021-01-06 17:43:26 -06:00
2020-12-09 20:22:40 -06:00
formData.append("data", JSON.stringify(data));
formData.append("cartaTermino", this.file);
2021-01-05 18:54:43 -06:00
this.isLoading = true;
2020-12-09 20:22:40 -06:00
axios
2021-01-05 18:54:43 -06:00
.put(`${process.env.api}/servicio/carta_termino`, formData, {
headers: {
"Content-Type": "multipart/form-data",
token: this.token.headers.token,
},
})
2020-12-09 20:22:40 -06:00
.then((res) => {
2020-12-10 10:41:59 -06:00
this.$buefy.dialog.alert({
title: "Success",
message: "Se enviaron los datos correctamente",
type: "is-success",
hasIcon: true,
icon: "checkbox-marked-circle",
iconPack: "mdi",
ariaRole: "alertdialog",
ariaModal: true,
});
})
.catch((error) => {
2021-01-06 16:33:56 -06:00
this.error(error.response.data.message);
2020-12-10 10:41:59 -06:00
})
.finally(() => {
2021-01-05 18:54:43 -06:00
this.isLoading = false;
2020-12-14 14:19:16 -06:00
localStorage.removeItem("idServicio");
localStorage.removeItem("cartaTermino");
2021-01-06 17:43:26 -06:00
this.$router.push("/responsable");
2020-12-09 20:22:40 -06:00
});
},
getIdLocal() {
2020-12-10 10:41:59 -06:00
this.idServicio = localStorage.getItem("idServicio");
2020-12-14 14:19:16 -06:00
this.cartaTermino = localStorage.getItem("cartaTermino");
if (this.idServicio === null || this.cartaTermino === null) {
this.$router.push("/responsable");
}
2020-12-09 20:22:40 -06:00
},
2021-01-05 18:54:43 -06:00
error(msj) {
2021-01-05 20:28:26 -06:00
let salir = false;
switch (msj) {
case "invalid signature":
2021-01-06 16:33:56 -06:00
msj = "Tu token no es valido, inicia sesión de nuevo.";
2021-01-06 16:00:41 -06:00
salir = true;
2021-01-05 20:28:26 -06:00
break;
case "jwt expired":
2021-01-06 16:33:56 -06:00
msj = "Tu sesión ha expirado, inicia sesión de nuevo.";
2021-01-06 16:00:41 -06:00
salir = true;
2021-01-05 20:28:26 -06:00
break;
2021-01-06 16:00:41 -06:00
case "jwt malformed":
2021-01-06 17:43:26 -06:00
msj = "No se encontro tu token, inicia sesión de nuevo.";
2021-01-06 16:00:41 -06:00
salir = true;
2021-01-05 20:28:26 -06:00
break;
2021-01-06 16:00:41 -06:00
case "No hay token":
2021-01-06 16:33:56 -06:00
msj = "Ocurrio un error al enviar tu token, inicia sesión de nuevo.";
2021-01-05 20:28:26 -06:00
salir = true;
2021-01-06 16:00:41 -06:00
break;
2021-01-05 18:54:43 -06:00
}
this.$buefy.dialog.alert({
title: "Error",
message: msj,
type: "is-danger",
hasIcon: true,
icon: "alert-circle",
iconPack: "mdi",
ariaRole: "alertdialog",
ariaModal: true,
});
2021-01-06 16:00:41 -06:00
if (salir == true) {
2021-01-05 18:54:43 -06:00
localStorage.clear();
2021-01-05 20:28:26 -06:00
this.$router.push(`/`);
2021-01-05 18:54:43 -06:00
}
},
2020-12-08 18:41:21 -06:00
},
watch: {
2020-12-08 21:50:16 -06:00
file: function(newFile, oldFile) {
this.validarTamaño();
},
},
2020-12-10 10:41:59 -06:00
created() {
this.getIdLocal();
},
2020-12-08 21:50:16 -06:00
};
2020-12-04 17:22:54 -06:00
</script>
<style>
2020-12-08 21:50:16 -06:00
.centro {
2020-12-07 16:13:14 -06:00
text-align: center;
}
2021-01-04 20:34:02 -06:00
.footter {
margin-bottom: 10rem;
}
2020-12-04 17:22:54 -06:00
</style>