Files
servicio_social_front/components/admin/servicio/documento.vue
T

210 lines
5.3 KiB
Vue
Raw Normal View History

2020-12-28 04:24:00 -06:00
<template>
<div>
<span class="spanDoc"
><strong>{{ title }}</strong></span
>
<a :href="link" target="_blank">
<b-button class="is-info">
Ver
</b-button>
</a>
<b-button
class="is-danger"
v-if="esRechazable()"
@click="mensajeBool = !mensajeBool"
>
Rechazar
</b-button>
<b-field label="Razón del rechazo: " v-if="mensajeBool">
<b-input maxlength="500" type="textarea" v-model="mensajeRech"></b-input>
</b-field>
<b-button
v-if="mensajeRech && mensajeBool"
class="is-danger"
@click="rechazarDialog()"
>
Rechazar documento
</b-button>
<b-button v-else-if="mensajeBool" disabled>
Rechazar documento
</b-button>
<b-loading
:is-full-page="true"
v-model="isLoading"
:can-cancel="false"
></b-loading>
</div>
</template>
<script>
import axios from "axios";
export default {
props: {
title: String,
link: String,
idDoc: Number,
2020-12-30 22:15:38 -06:00
doc: String,
2020-12-28 04:24:00 -06:00
status: Number,
},
data() {
return {
mensajeRech: "",
mensajeBool: false,
idServicio: localStorage.getItem("idServicio"),
isLoading: false,
2021-01-06 00:10:12 -06:00
token: {
headers: {
token: window.localStorage.getItem("token"),
},
},
2020-12-28 04:24:00 -06:00
};
},
methods: {
esRechazable() {
switch (this.idDoc) {
case 1:
if (this.status == 1) return true;
else return false;
case 2:
if (this.status == 5) return true;
else return false;
case 3:
if (this.status == 5) return true;
else return false;
}
},
rechazarDialog() {
this.$buefy.dialog.confirm({
title: "Confimar servicio",
message: "¿Seguro(a) que quiere rechazar este documento?",
confirmText: "Confirmar",
cancelText: "Cancelar",
type: "is-danger",
hasIcon: true,
onConfirm: () => {
switch (this.idDoc) {
case 1:
this.rechazarCartaAceptacion();
break;
case 2:
this.rechazarCartaTermino();
break;
case 3:
this.rechazarInformeGlobal();
}
},
});
},
rechazarCartaAceptacion() {
this.isLoading = true;
const data = {
mensaje: this.mensajeRech,
idServicio: this.idServicio,
};
axios
2021-01-06 00:10:12 -06:00
.put(
`${process.env.api}/servicio/rechazar_aceptacion`,
data,
this.token
)
2020-12-28 04:24:00 -06:00
.then((res) => {
this.isLoading = false;
this.$buefy.dialog.alert("Se ha rechazado el documento");
this.$router.push("/admin");
})
.catch((err) => {
this.isLoading = false;
2021-01-06 00:10:12 -06:00
this.error(err.response.data.message);
2021-01-12 20:28:04 -06:00
this.errorDoc();
2020-12-28 04:24:00 -06:00
});
},
rechazarCartaTermino() {
this.isLoading = true;
const data = {
mensaje: this.mensajeRech,
idServicio: this.idServicio,
};
axios
2021-01-06 00:10:12 -06:00
.put(`${process.env.api}/servicio/rechazar_termino`, data, this.token)
2020-12-28 04:24:00 -06:00
.then((res) => {
this.isLoading = false;
this.$buefy.dialog.alert("Se ha rechazado el documento");
this.$router.push("/admin");
})
.catch((err) => {
this.isLoading = false;
2021-01-06 00:10:12 -06:00
this.error(err.response.data.message);
this.errorDoc();
2020-12-28 04:24:00 -06:00
});
},
rechazarInformeGlobal() {
this.isLoading = true;
const data = {
mensaje: this.mensajeRech,
idServicio: this.idServicio,
};
axios
2021-01-06 00:10:12 -06:00
.put(`${process.env.api}/servicio/rechazar_informe`, data, this.token)
2020-12-28 04:24:00 -06:00
.then((res) => {
this.isLoading = false;
this.$buefy.dialog.alert("Se ha rechazado el documento");
this.$router.push("/admin");
})
.catch((err) => {
this.isLoading = false;
2021-01-06 00:10:12 -06:00
this.error(err.response.data.message);
this.errorDoc();
2020-12-28 04:24:00 -06:00
});
},
2021-01-06 00:10:12 -06:00
error(msj) {
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 15:27:23 -06:00
salir = true;
2021-01-06 00:10:12 -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 15:27:23 -06:00
salir = true;
2021-01-06 00:10:12 -06:00
break;
2021-01-06 15:27:23 -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 15:27:23 -06:00
salir = true;
2021-01-06 00:10:12 -06:00
break;
2021-01-06 15:27:23 -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-06 00:10:12 -06:00
salir = true;
2021-01-06 15:27:23 -06:00
break;
2021-01-06 00:10:12 -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 15:27:23 -06:00
if (salir == true) {
2021-01-06 00:10:12 -06:00
localStorage.clear();
this.$router.push(`/`);
}
},
errorDoc() {
this.$buefy.dialog.alert({
title: "Error",
2021-01-06 15:27:23 -06:00
message: "Ha ocurrido un error al rechazar el documento",
2021-01-06 00:10:12 -06:00
type: "is-danger",
hasIcon: true,
icon: "times-circle",
iconPack: "fa",
ariaRole: "alertdialog",
ariaModal: true,
});
},
2020-12-28 04:24:00 -06:00
},
};
</script>