Files
asan-service/pages/admin/admins/index.vue
T
2023-08-17 13:05:51 +03:30

109 lines
3.0 KiB
Vue

<template>
<div>
<CustomSubHeader>
<CBreadcrumb class="border-0 mb-0">{{ title }}</CBreadcrumb>
<CButton size="sm" color="success" :to="{ name: 'admin-admins-admin', params: { admin: 'new' } }" class="mr-auto"
>افزودن</CButton
>
</CustomSubHeader>
<CCard>
<CCardHeader>
<slot name="header">
<CIcon name="cil-grid" />
{{ list_title }}
</slot>
</CCardHeader>
<CCardBody>
<el-table :data="admins" style="width: 100%">
<el-table-column type="index" label="#"> </el-table-column>
<el-table-column prop="username" label="نام کاربری" width=""> </el-table-column>
<el-table-column prop="first_name" label="نام" width=""> </el-table-column>
<el-table-column prop="last_name" label="نام خانوادگی" width=""> </el-table-column>
<el-table-column label="ویرایش" width="105" align="left">
<template slot-scope="scope">
<CButton
:key="scope.row._id"
color="warning"
variant="outline"
:to="{ name: 'admin-admins-admin', params: { admin: scope.row._id } }"
>
<i class="fal fa-pencil"></i>
</CButton>
<CButton color="danger" variant="outline" @click="del(scope.row._id)">
<i class="fal fa-trash-alt"></i>
</CButton>
</template>
</el-table-column>
</el-table>
</CCardBody>
</CCard>
</div>
</template>
<script>
export default {
name: 'AddminAdminsList',
layout: 'admin',
async asyncData({ $axios, error }) {
try {
const admins = await $axios.get(`/api/admin/admins`)
return {
admins: admins.data
}
} catch (err) {
error({ status: 404, message: 'There is a problem here' })
}
},
data() {
return {
title: 'ادمین های سایت',
list_title: 'لیست',
admins: null
}
},
head() {
return {
title: this.title
}
},
computed: {},
methods: {
del(id) {
this.$confirm('این کاربر حذف شود؟', 'هشدار', {
confirmButtonText: 'بله',
cancelButtonText: 'لغو',
type: 'warning'
})
.then(() => {
this.$axios
.delete(`/api/admin/deleteAdmin/${id}`)
.then(response => {
this.admins = this.admins.filter(item => item._id !== id)
this.$message({
type: 'success',
message: 'کاربر حذف شد'
})
})
.catch(err => {
this.$message({
type: 'error',
message: err.response.data.message
})
})
})
.catch(() => {
this.$message({
type: 'warning',
message: 'عملیات لغو شد'
})
})
}
}
}
</script>