pcpuma_unam_operador/components/admin/SubirCsv.vue

111 lines
2.4 KiB
Vue
Raw Normal View History

2022-06-07 18:50:55 +00:00
<template>
<section>
<b-field>
<b-upload
type="is-black"
class="mb-5"
@input="validarCsv()"
v-model="csv"
drag-drop
expanded
>
<section
2022-08-12 20:42:56 +00:00
class="
section
is-flex is-align-items-center is-justify-content-center
drag-drop
"
2022-06-07 18:50:55 +00:00
>
<div class="content has-text-centered">
<p>
2022-08-25 21:27:32 +00:00
<b-icon icon="upload" size="is-large" />
2022-06-07 18:50:55 +00:00
</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="
2022-07-11 14:15:10 +00:00
$alertsGenericos.imprimirWarning(
$buefy,
2022-06-07 18:50:55 +00:00
'¿Esta segur@ de querer subir este archivo?',
cargaMasiva
)
"
>
Subir
</b-button>
</div>
</section>
</template>
<script>
import axios from 'axios'
export default {
props: {
2023-01-09 17:29:31 +00:00
updateIsLoading: { type: Function, required: true, default: () => {} },
path: { type: String, required: true, default: '' },
2022-06-07 18:50:55 +00:00
},
data() {
return {
csv: {},
}
},
methods: {
validarCsv() {
const extPermitidas = /(.csv)$/i
if (!extPermitidas.exec(this.csv.name)) {
this.csv = {}
2022-08-05 23:41:37 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, this.$router, {
2022-06-07 18:50:55 +00:00
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)
2022-12-05 15:36:30 +00:00
return axios
2022-07-19 16:41:33 +00:00
.post(
`${process.env.api}/${this.path}`,
formData,
2022-07-20 16:02:06 +00:00
this.$getToken.tokenFile()
2022-07-19 16:41:33 +00:00
)
2022-06-07 18:50:55 +00:00
.then((res) => {
this.csv = {}
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
2022-06-07 18:50:55 +00:00
})
.catch((err) => {
this.updateIsLoading(false)
2022-08-05 23:41:37 +00:00
this.$alertsGenericos.imprimirError(
this.$buefy,
this.$router,
err.response.data
)
2022-06-07 18:50:55 +00:00
})
},
},
}
</script>
<style>
.drag-drop {
height: 50vh;
}
</style>