105 lines
2.3 KiB
Vue
105 lines
2.3 KiB
Vue
![]() |
<template>
|
||
|
<section>
|
||
|
<b-field>
|
||
|
<b-upload
|
||
|
type="is-black"
|
||
|
class="mb-5"
|
||
|
@input="validarCsv()"
|
||
|
v-model="csv"
|
||
|
drag-drop
|
||
|
expanded
|
||
|
>
|
||
|
<section
|
||
|
class="section is-flex is-align-items-center is-justify-content-center drag-drop"
|
||
|
>
|
||
|
<div class="content has-text-centered">
|
||
|
<p>
|
||
|
<b-icon icon="upload" size="is-large"></b-icon>
|
||
|
</p>
|
||
|
|
||
|
<p>
|
||
|
{{
|
||
|
csv.name || 'Arrastra aquí tu archivo o da click para buscar'
|
||
|
}}
|
||
|
</p>
|
||
|
</div>
|
||
|
</section>
|
||
|
</b-upload>
|
||
|
</b-field>
|
||
|
|
||
|
<div class="has-text-centered mb-6">
|
||
|
<b-button
|
||
|
type="is-info"
|
||
|
:disabled="!csv.name"
|
||
|
@click="
|
||
|
imprimirWarning(
|
||
|
'¿Esta segur@ de querer subir este archivo?',
|
||
|
cargaMasiva
|
||
|
)
|
||
|
"
|
||
|
>
|
||
|
Subir
|
||
|
</b-button>
|
||
|
</div>
|
||
|
</section>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import axios from 'axios'
|
||
|
|
||
|
export default {
|
||
|
props: {
|
||
|
admin: { type: Object, required: true },
|
||
|
imprimirMensaje: { type: Function, required: true },
|
||
|
imprimirWarning: { type: Function, required: true },
|
||
|
imprimirError: { type: Function, required: true },
|
||
|
updateIsLoading: { type: Function, required: true },
|
||
|
path: { type: String, required: true },
|
||
|
manejarRespuesta: { type: Function, required: true },
|
||
|
},
|
||
|
data() {
|
||
|
return {
|
||
|
csv: {},
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
validarCsv() {
|
||
|
const extPermitidas = /(.csv)$/i
|
||
|
|
||
|
if (!extPermitidas.exec(this.csv.name)) {
|
||
|
this.csv = {}
|
||
|
this.imprimirError({
|
||
|
message:
|
||
|
'El archivo seleccionado no es un csv. Asegurese de escoger un archivo valido.',
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
cargaMasiva() {
|
||
|
const formData = new FormData()
|
||
|
|
||
|
this.updateIsLoading(true)
|
||
|
formData.append('csv', this.csv)
|
||
|
axios
|
||
|
.post(`${process.env.api}/${this.path}`, formData)
|
||
|
.then((res) => {
|
||
|
this.manejarRespuesta(res.data)
|
||
|
|
||
|
this.csv = {}
|
||
|
this.updateIsLoading(false)
|
||
|
this.imprimirMensaje(res.data.message)
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
this.updateIsLoading(false)
|
||
|
this.imprimirError(err.response.data)
|
||
|
})
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style>
|
||
|
.drag-drop {
|
||
|
height: 50vh;
|
||
|
}
|
||
|
</style>
|