somewhere
This commit is contained in:
@@ -0,0 +1,194 @@
|
||||
<template>
|
||||
<div>
|
||||
<CustomSubHeader>
|
||||
<CBreadcrumb class="border-0 mb-0">{{ title }}</CBreadcrumb>
|
||||
<CButton size="sm" color="success" class="mr-auto" @click="addAgentModal = true">
|
||||
<span style="color: #fff"> افزودن نماینده </span>
|
||||
</CButton>
|
||||
</CustomSubHeader>
|
||||
|
||||
<CCard>
|
||||
<CCardHeader>
|
||||
<slot name="header">
|
||||
<i class="fas fa-filter"></i>
|
||||
<b>فیلتر ها</b>
|
||||
</slot>
|
||||
</CCardHeader>
|
||||
|
||||
<CCardBody>
|
||||
<CRow>
|
||||
<CCol sm="12">
|
||||
<h4>جستجو در لیست:</h4>
|
||||
<el-input
|
||||
v-model="filterText"
|
||||
clearable
|
||||
placeholder="کد نماینده - شماره موبایل - استان - شهر"
|
||||
style="display: inline-block; max-width: 500px; margin-top: 8px"
|
||||
></el-input>
|
||||
</CCol>
|
||||
</CRow>
|
||||
</CCardBody>
|
||||
</CCard>
|
||||
|
||||
<CCard>
|
||||
<CCardHeader>
|
||||
<slot name="header">
|
||||
<CIcon name="cil-grid" />
|
||||
{{ list_title }}
|
||||
</slot>
|
||||
</CCardHeader>
|
||||
|
||||
<CCardBody>
|
||||
<el-table :data="filteredItems" style="width: 100%">
|
||||
<el-table-column type="index" label="#"> </el-table-column>
|
||||
|
||||
<el-table-column prop="full_name" label="نام" width=""> </el-table-column>
|
||||
|
||||
<el-table-column prop="mobile_number" label="شماره موبایل" width=""> </el-table-column>
|
||||
|
||||
<el-table-column label="نوع نماینده" width="300">
|
||||
<template slot-scope="scope">
|
||||
<span v-if="scope.row.representation_type === 'both'">نماینده هر دو نوع لوازم</span>
|
||||
<span v-if="scope.row.representation_type === 'verity'">نماینده لوازم جانبی کامپیوتر و موبایل</span>
|
||||
<span v-if="scope.row.representation_type === 'panatech'">نماینده لوازم صوتی تصویری خودرو</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column prop="agent_code" label="کد نماینده" width=""> </el-table-column>
|
||||
|
||||
<el-table-column prop="province_name" label="استان" width=""> </el-table-column>
|
||||
|
||||
<el-table-column prop="city_name" label="شهر" width=""> </el-table-column>
|
||||
|
||||
<el-table-column label="مشاهده" width="70" align="center">
|
||||
<template slot-scope="scope">
|
||||
<CButton
|
||||
:key="scope.row._id"
|
||||
color="success"
|
||||
variant="outline"
|
||||
:to="{ name: 'admin-agents-agent', params: { agent: scope.row._id }, query: { ...$route.query } }"
|
||||
>
|
||||
<i class="fal fa-eye"></i>
|
||||
</CButton>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</CCardBody>
|
||||
</CCard>
|
||||
|
||||
<el-dialog :visible.sync="addAgentModal">
|
||||
<el-select v-model="selectedUserForNewAgent" style="width: 100%" label="کاربر را انتخاب کنید" filterable>
|
||||
<el-option
|
||||
v-for="item in users"
|
||||
:key="item._id"
|
||||
:label="item.first_name + ' ' + item.last_name + ' (' + item.national_code + ')'"
|
||||
:value="item._id"
|
||||
></el-option>
|
||||
</el-select>
|
||||
<br />
|
||||
<br />
|
||||
<el-button type="success" :disabled="!selectedUserForNewAgent" @click="addAgent">
|
||||
<span style="color: #fff">افزودن</span>
|
||||
</el-button>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'AdminAgentsList',
|
||||
layout: 'admin',
|
||||
async asyncData({ $axios, query, error }) {
|
||||
try {
|
||||
let agents
|
||||
if (query?.revoked) {
|
||||
agents = await $axios.get('/api/admin/revokedAgents')
|
||||
} else {
|
||||
agents = await $axios.get('/api/public/agents')
|
||||
}
|
||||
|
||||
return {
|
||||
agents: agents.data
|
||||
}
|
||||
} catch (err) {
|
||||
error({ status: 404, message: 'There is a problem here' })
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
list_title: 'لیست',
|
||||
agents: null,
|
||||
users: [],
|
||||
filterText: '',
|
||||
addAgentModal: false,
|
||||
selectedUserForNewAgent: null
|
||||
}
|
||||
},
|
||||
head() {
|
||||
return {
|
||||
title: this.title
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
revokedAgentsList() {
|
||||
return this.$route.query?.revoked
|
||||
},
|
||||
title() {
|
||||
if (this.revokedAgentsList) return 'لیست نمایندگان صلب امتیاز شده'
|
||||
else return 'لیست نمایندگان'
|
||||
},
|
||||
filteredItems() {
|
||||
const filterText = this.filterText.toLowerCase()
|
||||
if (!filterText.length) return this.agents
|
||||
else
|
||||
return this.agents.filter(item => {
|
||||
return (
|
||||
item.agent_code.toLowerCase().includes(filterText) ||
|
||||
item.full_name.toLowerCase().includes(filterText) ||
|
||||
item.mobile_number.toLowerCase().includes(filterText) ||
|
||||
item.province_name.toLowerCase().includes(filterText) ||
|
||||
item.city_name.toLowerCase().includes(filterText)
|
||||
)
|
||||
})
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
revokedAgentsList(newVal, oldVal) {
|
||||
this.$nuxt.refresh()
|
||||
},
|
||||
addAgentModal(newVal, oldVal) {
|
||||
this.selectedUserForNewAgent = null
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$axios.$get('/api/admin/users').then(res => {
|
||||
this.users = res
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
addAgent() {
|
||||
if (!this.selectedUserForNewAgent) {
|
||||
return this.$message({
|
||||
type: 'error',
|
||||
message: 'ابتدا کاربر مورد نظر را انتخاب نمایید'
|
||||
})
|
||||
}
|
||||
this.$axios
|
||||
.$post('/api/admin/addAgentByAdmin', { user: this.selectedUserForNewAgent })
|
||||
.then(res => {
|
||||
this.$router.push({
|
||||
name: 'admin-agents-agent',
|
||||
params: { agent: res.representationId },
|
||||
query: { ...this.$route.query }
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
this.$message({
|
||||
type: 'error',
|
||||
message: err.response.data.message
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user