97 lines
2.5 KiB
Vue
97 lines
2.5 KiB
Vue
<template>
|
|
<div>
|
|
<b-field
|
|
:label="`Carta de ${tipoCarta} (en formato .pdf, no se aceptan fotos).`"
|
|
>
|
|
<b-upload accept="application/pdf" v-model="file" drag-drop expanded>
|
|
<div class="section has-text-centered">
|
|
<b-icon icon="upload" size="is-large" class="mb-2" />
|
|
|
|
<p class="is-size-5">
|
|
{{
|
|
file.name ||
|
|
'Arrastra aquí tu archivo o da click aquí para buscarlo.'
|
|
}}
|
|
</p>
|
|
|
|
<p class="is-size-6">Tamaño máximo 20MB</p>
|
|
</div>
|
|
</b-upload>
|
|
</b-field>
|
|
|
|
<b-field class="has-text-centered my-5">
|
|
<b-button
|
|
type="is-success"
|
|
:disabled="!file.name"
|
|
@click="
|
|
imprimirWarning(
|
|
`¿Estas seguro(a) de querer subir esta carta de ${tipoCarta}?`,
|
|
subir
|
|
)
|
|
"
|
|
>
|
|
Enviar
|
|
</b-button>
|
|
</b-field>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import axios from 'axios'
|
|
|
|
export default {
|
|
props: {
|
|
idServicio: { type: Number, required: true },
|
|
path: { type: String, required: true },
|
|
tipoCarta: { type: String, required: true },
|
|
variableName: { type: String, required: true },
|
|
responsable: { type: Object, required: true },
|
|
imprimirError: { type: Function, required: true },
|
|
imprimirMensaje: { type: Function, required: true },
|
|
imprimirWarning: { type: Function, required: true },
|
|
updateIsLoading: { type: Function, required: true },
|
|
},
|
|
data() {
|
|
return {
|
|
file: {},
|
|
}
|
|
},
|
|
methods: {
|
|
subir() {
|
|
const formData = new FormData()
|
|
const data = { idServicio: this.idServicio }
|
|
|
|
this.updateIsLoading(true)
|
|
formData.append('data', JSON.stringify(data))
|
|
formData.append(this.variableName, this.file)
|
|
axios
|
|
.put(
|
|
`${process.env.api}/servicio/${this.path}`,
|
|
formData,
|
|
this.responsable.tokenArchivo
|
|
)
|
|
.then((res) => {
|
|
localStorage.removeItem('idServicio')
|
|
this.updateIsLoading(false)
|
|
this.imprimirMensaje(res.data.message)
|
|
this.$router.push('/responsable')
|
|
})
|
|
.catch((err) => {
|
|
this.updateIsLoading(false)
|
|
this.imprimirError(err.response.data)
|
|
})
|
|
},
|
|
},
|
|
watch: {
|
|
file() {
|
|
if (this.file.size >= 20000000) {
|
|
this.imprimirError({ message: 'El tamaño del archivo exede los 20MB' })
|
|
this.file = {}
|
|
}
|
|
},
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style scoped></style>
|