pcpuma_unam_operador/components/tablas/TablaAdmins.vue
2022-12-05 09:36:30 -06:00

120 lines
3.3 KiB
Vue

<template>
<b-table
class="pb-6"
:current-page="page"
:data="admins"
:loading="isLoadingTable"
:per-page="25"
:total="total"
@page-change="onPageChange"
backend-pagination
hoverable
paginated
striped
>
<b-table-column
field="operador"
label="Institución"
v-slot="props"
v-if="columnaInstitucion"
centered
>
<p>{{ props.row.institucion.institucion }}</p>
</b-table-column>
<b-table-column
field="operador"
label="Usuario administrador"
v-slot="props"
centered
>
<p>{{ props.row.operador }}</p>
</b-table-column>
<b-table-column field="nombre" label="Nombre" v-slot="props" centered>
<p>{{ props.row.nombre }}</p>
</b-table-column>
<b-table-column field="correo" label="Correo" v-slot="props" centered>
<p>{{ props.row.correo }}</p>
</b-table-column>
<b-table-column
field="activo"
label="Status"
v-slot="props"
v-if="columnaActivo"
centered
>
<BotonDesactivar
:activarDesactivar="activarDesactivar"
:row="props.row"
:msjWarning="`¿Estás segur@ de querer ${
props.row.activo ? 'desactivar' : 'activar'
} esta cuenta de admin?`"
/>
</b-table-column>
<b-table-column
field="password"
label="Cambiar contraseña"
v-slot="props"
v-if="columnaPasswordChange"
centered
>
<BotonUpdatePassword
:operador="props.row"
:updateIsLoading="updateIsLoading"
campo="admin"
/>
</b-table-column>
</b-table>
</template>
<script>
import axios from 'axios'
import BotonDesactivar from '@/components/botones/BotonDesactivar'
import BotonUpdatePassword from '@/components/botones/BotonUpdatePassword'
export default {
components: { BotonDesactivar, BotonUpdatePassword },
props: {
admins: { type: Array, required: true, default: () => [] },
columnaActivo: { type: Boolean, required: false, default: false },
columnaInstitucion: { type: Boolean, required: false, default: false },
columnaPasswordChange: { type: Boolean, required: false, default: false },
isLoadingTable: { type: Boolean, required: true, default: false },
obtenerAdmins: { type: Function, required: false, default: () => {} },
onPageChange: { type: Function, required: true, default: () => {} },
updateIsLoading: { type: Function, required: false, default: () => {} },
page: { type: Number, required: true, default: 0 },
total: { type: Number, required: true, default: 0 },
},
methods: {
activarDesactivar(operador) {
const data = {
id_operador: operador.id_operador,
activo: operador.activo ? false : true,
}
this.updateIsLoading(true)
return axios
.put(`${process.env.api}/operador`, data, this.$getToken.token())
.then((res) => {
this.obtenerAdmins()
this.updateIsLoading(false)
this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
})
.catch((err) => {
this.updateIsLoading(false)
this.$alertsGenericos.imprimirError(
this.$buefy,
this.$router,
err.response.data
)
})
},
},
}
</script>