carta termino listo

This commit is contained in:
Lemuel Marquez
2021-05-16 22:27:34 -05:00
parent 9cd91c8752
commit 5a08433938
5 changed files with 139 additions and 208 deletions
-179
View File
@@ -1,179 +0,0 @@
<template>
<div class="container">
<h3 class="title is-4 mt-4">
Carta de aceptación (en formato .PDF. No se aceptan fotos).
</h3>
<b-field>
<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>
</b-field>
<b-field class="centro">
<b-button
:disabled="file == ''"
class="border-success my-5"
type="is-success"
@click="Enviar()"
>Enviar</b-button
>
</b-field>
<b-loading :is-full-page="true" v-model="isLoading" :can-cancel="false">
</b-loading>
</div>
</template>
<script>
import axios from 'axios'
export default {
data() {
return {
isFullPage: true,
file: [],
idServicio: '',
cartaAceptacion: '',
isLoading: false,
token: {
headers: {
token: localStorage.getItem('token'),
},
},
}
},
methods: {
validarTamaño() {
const TamMax = 20000000
const archivo = this.file
if (archivo.size > TamMax) {
this.toast()
this.file = ''
}
},
toast() {
this.$buefy.toast.open({
message: 'El archivo excede el tamaño permitido',
type: 'is-danger',
})
},
Enviar() {
const data = { idServicio: this.idServicio }
const formData = new FormData()
formData.append('data', JSON.stringify(data))
formData.append('cartaAceptacion', this.file)
this.isLoading = true
axios
.put(`${process.env.api}/servicio/carta_aceptacion`, formData, {
headers: {
'Content-Type': 'multipart/form-data',
token: this.token.headers.token,
},
})
.then((res) => {
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) => {
this.error(error.response.data.message)
})
.finally(() => {
this.isLoading = false
localStorage.removeItem('idServicio')
localStorage.removeItem('cartaAceptacion')
this.$router.push('/responsable')
})
},
getIdLocal() {
this.idServicio = localStorage.getItem('idServicio')
this.cartaAceptacion = localStorage.getItem('cartaAceptacion')
// if (this.idServicio === null || this.cartaAceptacion === null) {
// this.$router.push('/responsable')
// }
},
error(msj) {
let salir = false
switch (msj) {
case 'invalid signature':
msj = 'Tu token no es valido, inicia sesión de nuevo.'
salir = true
break
case 'jwt expired':
msj = 'Tu sesión ha expirado, inicia sesión de nuevo.'
salir = true
break
case 'jwt malformed':
msj = 'No se encontro tu token, inicia sesión de nuevo.'
salir = true
break
case 'No hay token':
msj = 'Ocurrio un error al enviar tu token, inicia sesión de nuevo.'
salir = true
break
}
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(`/`)
}
},
},
watch: {
file: function (newFile, oldFile) {
this.validarTamaño()
},
},
created() {
this.getIdLocal()
},
}
</script>
<style>
.centro {
text-align: center;
}
.footter {
margin-bottom: 10rem;
}
</style>
-22
View File
@@ -1,22 +0,0 @@
<template>
<section>
<Cuestionario />
</section>
</template>
<script>
import Cuestionario from '../../../components/responsable/cartaTermino'
export default {
components: {
Cuestionario,
},
beforeCreate() {
const idTipoUsuario = Number(localStorage.getItem('idTipoUsuario'))
if (idTipoUsuario === 1) this.$router.push('/admin')
if (idTipoUsuario === 3) this.$router.push('/alumno')
if (idTipoUsuario === 4) this.$router.push('/casoEspecial')
},
}
</script>
@@ -133,7 +133,6 @@ export default {
file() {
const TamMax = 20000000
console.log(this.file)
if (this.file.size > TamMax) {
this.$buefy.toast.open({
message: 'El archivo excede el tamaño permitido',
+138 -5
View File
@@ -1,15 +1,146 @@
<template>
<section>
<cartaTermino />
<section class="container section">
<BotonRegresar
path="/responsable"
:deleteFromLocalStorage="['idServicio']"
/>
<h3 class="title is-4 mt-4">
Carta de aceptación (en formato .PDF. No se aceptan fotos).
</h3>
<b-field>
<b-upload
v-model="file"
type="is-black"
accept="application/pdf"
drag-drop
expanded
>
<div class="section 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>
</b-upload>
</b-field>
<b-field class="has-text-centered">
<b-button
:disabled="!file.size"
class="border-success my-5"
type="is-success"
@click="subir()"
>Enviar</b-button
>
</b-field>
<b-loading
:is-full-page="true"
v-model="isLoading"
:can-cancel="false"
></b-loading>
</section>
</template>
<script>
import cartaTermino from '../../../components/responsable/cartaTermino'
import axios from 'axios'
import BotonRegresar from '../../../components/botonRegresar'
export default {
components: {
cartaTermino,
data() {
return {
responsable: {},
file: {},
idServicio: '',
isLoading: false,
token: {},
}
},
components: { BotonRegresar },
methods: {
getLocalhostInfo() {
this.responsable.idUsuario = localStorage.getItem('idUsuario')
this.responsable.idTipoUsuario = Number(
localStorage.getItem('idTipoUsuario')
)
this.responsable.tipoUsuario = localStorage.getItem('tipoUsuario')
this.token = {
headers: {
'Content-Type': 'multipart/form-data',
token: localStorage.getItem('token'),
},
}
this.idServicio = localStorage.getItem('idServicio')
},
subir() {
const formData = new FormData()
const data = { idServicio: this.idServicio }
this.isLoading = true
formData.append('data', JSON.stringify(data))
formData.append('cartaTermino', this.file)
axios
.put(`${process.env.api}/servicio/carta_termino`, formData, this.token)
.then((res) => {
this.isLoading = false
this.$buefy.dialog.alert({
title: 'Success',
message: 'Se subio el archivo correctamente.',
type: 'is-success',
hasIcon: true,
icon: 'checkbox-marked-circle',
iconPack: 'mdi',
ariaRole: 'alertdialog',
ariaModal: true,
})
localStorage.removeItem('idServicio')
this.$router.push('/responsable')
})
.catch((err) => {
this.isLoading = false
this.imprimirerr(err.response.data)
})
},
imprimirError(err) {
this.$buefy.dialog.alert({
title: 'Error',
message: err.message,
type: 'is-danger',
hasIcon: true,
icon: 'alert-circle',
iconPack: 'mdi',
ariaRole: 'alertdialog',
ariaModal: true,
})
if (err.err === 'token error') {
localStorage.clear()
this.$router.push('/')
}
},
},
watch: {
file() {
const TamMax = 20000000
if (this.file.size > TamMax) {
this.$buefy.toast.open({
message: 'El archivo excede el tamaño permitido',
type: 'is-danger',
})
this.file = {}
}
},
},
created() {
if (localStorage.getItem('idServicio')) this.getLocalhostInfo()
else this.$router.push('/responsable')
},
beforeCreate() {
const idTipoUsuario = Number(localStorage.getItem('idTipoUsuario'))
@@ -20,3 +151,5 @@ export default {
},
}
</script>
<style></style>
+1 -1
View File
@@ -1,6 +1,6 @@
<template>
<section>
<cuestionario />
<Cuestionario />
</section>
</template>