installed device page

This commit is contained in:
Mr Swift
2024-08-25 16:16:45 +03:30
parent d91bc5beba
commit b0566dd807
7 changed files with 527 additions and 59 deletions
+1 -1
View File
@@ -351,7 +351,7 @@
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('gps')" v-if="hasPermission('gps')"
name="دستگاه های ثبت شده" name="دستگاه های ثبت شده"
:to="{ name: 'admin-admins-admin', params: { admin: 'new' } }" :to="{ name: 'admin-gps-installed-device', query: { filter: 'all' } }"
font-icon="fal fa-map" font-icon="fal fa-map"
:exact="false" :exact="false"
/> />
+233
View File
@@ -0,0 +1,233 @@
<template>
<div>
<CustomSubHeader>
<CBreadcrumb class="border-0 mb-0"> دستگاه های نصب شده</CBreadcrumb>
</CustomSubHeader>
<CRow>
<CCol xl="6">
<CCard>
<CCardHeader>
<slot name="header">
<i class="fas fa-filter"></i>
<b>فیلتر ها</b>
</slot>
</CCardHeader>
<CCardBody>
<CRow>
<CCol sm="12">
<CButtonGroup>
<CButton color="primary" :class="filterType === 'all' && 'selected'" @click="filterType = 'all'"
>همه</CButton
>
<CButton color="danger" :class="filterType === 'rej' && 'selected'" @click="filterType = 'rej'"
>رد شده</CButton
>
<CButton
color="success"
:class="filterType === 'accept' && 'selected'"
@click="filterType = 'accept'"
>تایید شده</CButton
>
<CButton color="warning" :class="filterType === 'pend' && 'selected'" @click="filterType = 'pend'"
>درانتظار تایید</CButton
>
</CButtonGroup>
</CCol>
<CCol sm="12">
<el-divider></el-divider>
</CCol>
<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>
</CCol>
</CRow>
<CCard>
<CCardHeader>
<slot name="header">
<CIcon name="cil-grid" />
دستگاه های نصب شده
</slot>
</CCardHeader>
<CCardBody>
<el-table :data="filteredItems" :row-class-name="hasUnread" style="width: 100%">
<el-table-column type="index" label="#"> </el-table-column>
<el-table-column label="مدل" width="150px">
<template slot-scope="scope">
{{ scope.row.deviceId.model }}
</template>
</el-table-column>
<el-table-column prop="IMEI" label=" IMEI" width="150px"> </el-table-column>
<el-table-column label="نام فروشگاه" width="">
<template slot-scope="scope">
{{ scope.row.userId.shopName }}
</template>
</el-table-column>
<el-table-column label="کدملی فروشنده" width="">
<template slot-scope="scope">
{{ scope.row.userId.national_code }}
</template>
</el-table-column>
<el-table-column label=" نام و نام خانوادگی" width="">
<template slot-scope="scope">
{{ scope.row.userId.first_name + " " + scope.row.userId.last_name }}
</template>
</el-table-column>
<el-table-column label=" شماره همراه" width="">
<template slot-scope="scope">
{{ scope.row.userId.mobile_number }}
</template>
</el-table-column>
<el-table-column label="محل سکونت" width="">
<template slot-scope="scope">
{{ scope.row.userId.province_name + ", "+ scope.row.userId.city_name }}
</template>
</el-table-column>
<el-table-column label="وضعیت" width="">
<template slot-scope="scope">
<el-tag v-if="scope.row.status == 2" type="danger"> رد شده</el-tag>
<el-tag v-if="scope.row.status == 1" type="success">تایید شده</el-tag>
<el-tag v-if="scope.row.status == 0" type="warning"> درانتظار تایید</el-tag>
</template>
</el-table-column>
<el-table-column label="تایید" width="110" align="center">
<template slot-scope="scope">
<CButton
v-if="scope.row.status == 0 || scope.row.status == 2"
:key="scope.row._id"
color="success"
variant="outline"
@click="post(scope.row._id, 'accept')"
>
<i class="fa fa-check-square"></i>
</CButton>
<CButton
v-if="scope.row.status == 0 || scope.row.status == 1"
:key="scope.row._id"
color="danger"
variant="outline"
@click="post(scope.row._id, 'reject')"
>
<i class="fa fa-window-close"></i>
</CButton>
</template>
</el-table-column>
</el-table>
</CCardBody>
</CCard>
</div>
</template>
<script>
export default {
name: 'AdminGpsInstalledDevicesList',
layout: 'admin',
async asyncData({ $axios, error, query }) {
try {
const { data } = await $axios.get('/api/admin/gps/register-device')
return {
devices: data.data
}
} catch (error) {
console.log(error)
}
},
data() {
return {
devices: [],
device: {},
filterText: '',
}
},
computed: {
config() {
return this.$config
},
filteredItems() {
const filterUsersByType = this.devices.filter(item => {
if (this.filterType === 'all') return item
// eslint-disable-next-line eqeqeq
else if (this.filterType === 'rej') return item.status == 2
// eslint-disable-next-line eqeqeq
else if (this.filterType === 'accept') return item.status == 1
// eslint-disable-next-line eqeqeq
else if (this.filterType === 'pend') return item.status == 0
else return null
})
const filterText = this.filterText
if (!this.filterText.length) return filterUsersByType
else {
return this.devices.filter(item => {
return item.IMEI.includes(filterText) || item.deviceId.model.includes(filterText)
})
}
},
filterType: {
get() {
return this.$route.query?.filter
},
set(val) {
this.$router.push({ name: 'admin-gps-installed-device', query: { filter: val } })
}
}
},
methods: {
hasUnread({ row, rowIndex }) {
return row.status === 0 ? 'unreadMsgInCv' : null
},
post(id, status) {
this.$axios
.patch(`/api/admin/gps/register-device/${id}/${status}`, {})
.then(res => {
this.$message({
type: 'success',
message: res.data.msg
})
this.$nuxt.refresh()
})
.catch(err => {
if (err.response.data.status === 401) {
return this.$message({
type: 'warning',
message: 'لطفا دوباره وارد حساب خود شوید'
})
}
if (err.response.status === 422) this.validation = err.response.data.validation
else {
console.log(err)
return this.$message({
type: 'warning',
message: err.data.msg
})
}
})
}
}
}
</script>
<style>
.unreadMsgInCv {
background: rgba(orange, 0.1) !important;
}
</style>
+2 -2
View File
@@ -24,9 +24,9 @@
</CCardBody> </CCardBody>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="centerDialogVisible = false">{{ <el-button @click="centerDialogVisible = false">{{
$route.query?.type == 'req' ? 'Cancel' : 'Close' $route.query?.type == 'req' ? 'بستن' : 'بستن'
}}</el-button> }}</el-button>
<el-button v-if="$route.query?.type == 'req'" type="primary" @click="confirmUser(user._id)">Confirm</el-button> <el-button v-if="$route.query?.type == 'req'" type="primary" @click="confirmUser(user._id)">تایید</el-button>
</span> </span>
</el-dialog> </el-dialog>
+234
View File
@@ -0,0 +1,234 @@
<template>
<div>
<CustomSubHeader>
<CBreadcrumb class="border-0 mb-0"> دستگاه های نصب شده</CBreadcrumb>
</CustomSubHeader>
<CRow>
<CCol xl="6">
<CCard>
<CCardHeader>
<slot name="header">
<i class="fas fa-filter"></i>
<b>فیلتر ها</b>
</slot>
</CCardHeader>
<CCardBody>
<CRow>
<CCol sm="12">
<CButtonGroup>
<CButton color="primary" :class="filterType === 'all' && 'selected'" @click="filterType = 'all'"
>همه</CButton
>
<CButton color="danger" :class="filterType === 'rej' && 'selected'" @click="filterType = 'rej'"
>رد شده</CButton
>
<CButton
color="success"
:class="filterType === 'accept' && 'selected'"
@click="filterType = 'accept'"
>تایید شده</CButton
>
<CButton color="warning" :class="filterType === 'pend' && 'selected'" @click="filterType = 'pend'"
>درانتظار تایید</CButton
>
</CButtonGroup>
</CCol>
<CCol sm="12">
<el-divider></el-divider>
</CCol>
<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>
</CCol>
</CRow>
<CCard>
<CCardHeader>
<slot name="header">
<CIcon name="cil-grid" />
دستگاه های نصب شده
</slot>
</CCardHeader>
<CCardBody>
<el-table :data="filteredItems" :row-class-name="hasUnread" style="width: 100%">
<el-table-column type="index" label="#"> </el-table-column>
<el-table-column label="مدل" width="150px">
<template slot-scope="scope">
{{ scope.row.deviceId.model }}
</template>
</el-table-column>
<el-table-column prop="IMEI" label=" IMEI" width="150px"> </el-table-column>
<el-table-column label="نام فروشگاه" width="">
<template slot-scope="scope">
{{ scope.row.userId.shopName }}
</template>
</el-table-column>
<el-table-column label="کدملی فروشنده" width="">
<template slot-scope="scope">
{{ scope.row.userId.national_code }}
</template>
</el-table-column>
<el-table-column label=" نام و نام خانوادگی" width="">
<template slot-scope="scope">
{{ scope.row.userId.first_name + " " + scope.row.userId.last_name }}
</template>
</el-table-column>
<el-table-column label=" شماره همراه" width="">
<template slot-scope="scope">
{{ scope.row.userId.mobile_number }}
</template>
</el-table-column>
<el-table-column label="محل سکونت" width="">
<template slot-scope="scope">
{{ scope.row.userId.province_name + ", "+ scope.row.userId.city_name }}
</template>
</el-table-column>
<el-table-column label="وضعیت" width="">
<template slot-scope="scope">
<el-tag v-if="scope.row.status == 2" type="danger"> رد شده</el-tag>
<el-tag v-if="scope.row.status == 1" type="success">تایید شده</el-tag>
<el-tag v-if="scope.row.status == 0" type="warning"> درانتظار تایید</el-tag>
</template>
</el-table-column>
<el-table-column label="تایید" width="110" align="center">
<template slot-scope="scope">
<CButton
v-if="scope.row.status == 0 || scope.row.status == 2"
:key="scope.row._id"
color="success"
variant="outline"
@click="post(scope.row._id, 'accept')"
>
<i class="fa fa-check-square"></i>
</CButton>
<CButton
v-if="scope.row.status == 0 || scope.row.status == 1"
:key="scope.row._id"
color="danger"
variant="outline"
@click="post(scope.row._id, 'reject')"
>
<i class="fa fa-window-close"></i>
</CButton>
</template>
</el-table-column>
</el-table>
</CCardBody>
</CCard>
</div>
</template>
<script>
export default {
name: 'AdminGpsInstalledDevicesList',
layout: 'admin',
async asyncData({ $axios, error, query }) {
try {
const { data } = await $axios.get('/api/admin/gps/register-device')
return {
devices: data.data
}
} catch (error) {
console.log(error)
}
},
data() {
return {
devices: [],
device: {},
filterText: '',
}
},
computed: {
config() {
return this.$config
},
filteredItems() {
const filterUsersByType = this.devices.filter(item => {
if (this.filterType === 'all') return item
// eslint-disable-next-line eqeqeq
else if (this.filterType === 'rej') return item.status == 2
// eslint-disable-next-line eqeqeq
else if (this.filterType === 'accept') return item.status == 1
// eslint-disable-next-line eqeqeq
else if (this.filterType === 'pend') return item.status == 0
else return null
})
const filterText = this.filterText
if (!this.filterText.length) return filterUsersByType
else {
return this.devices.filter(item => {
return item.IMEI.includes(filterText) || item.deviceId.model.includes(filterText)
})
}
},
filterType: {
get() {
return this.$route.query?.filter
},
set(val) {
this.$router.push({ name: 'admin-gps-installed-device', query: { filter: val } })
}
}
},
methods: {
hasUnread({ row, rowIndex }) {
return row.status === 0 ? 'unreadMsgInCv' : null
},
post(id, status) {
this.$axios
.patch(`/api/admin/gps/register-device/${id}/${status}`, {})
.then(res => {
this.$message({
type: 'success',
message: res.data.msg
})
this.$nuxt.refresh()
})
.catch(err => {
if (err.response.data.status === 401) {
return this.$message({
type: 'warning',
message: 'لطفا دوباره وارد حساب خود شوید'
})
}
if (err.response.status === 422) this.validation = err.response.data.validation
else {
console.log(err)
return this.$message({
type: 'warning',
message: err.data.msg
})
}
})
}
}
}
</script>
<style>
.unreadMsgInCv {
background: rgba(orange, 0.1) !important;
}
</style>
+6 -2
View File
@@ -171,10 +171,11 @@ module.exports.updateDevice = [
const creator = (exel) => { const creator = (exel) => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try {
for (const row of exel) { for (const row of exel) {
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
if (/^[0-9]{15}$/gm.test(row[0].toString().trim())) { if (/^[0-9]{15}$/gm.test(row[0].toString().trim())) {
const device = await Device.findOne({ IMEI: row[0] }) const device = await Device.findOne({ IMEI: row[0].trim() })
if (device) { if (device) {
console.info("Repeated IMEI ", row[0]) console.info("Repeated IMEI ", row[0])
@@ -188,7 +189,7 @@ const creator = (exel) => {
} else { } else {
await Device.create( await Device.create(
{ {
IMEI: row[0], IMEI: row[0].trim(),
model: row[1], model: row[1],
tomanPrice: row[2], tomanPrice: row[2],
dollarProfit: row[3] || 1, dollarProfit: row[3] || 1,
@@ -203,6 +204,9 @@ const creator = (exel) => {
} }
} }
resolve("end") resolve("end")
} catch (error) {
reject(error.message)
}
}) })
} }
+24 -27
View File
@@ -4,6 +4,7 @@ const User = require('../models/User');
const InstalledDevice = require('../models/GPS.InstalledDevice'); const InstalledDevice = require('../models/GPS.InstalledDevice');
const Device = require('../models/GPS.Device'); const Device = require('../models/GPS.Device');
const Score = require('../models/GPS.Score'); const Score = require('../models/GPS.Score');
const { _sr } = require('../plugins/serverResponses');
module.exports.deviceRegistration = [ module.exports.deviceRegistration = [
[ [
@@ -72,32 +73,28 @@ module.exports.getAllForUser = async (req, res) => {
} }
module.exports.getAllForAdmin = async (req, res) => { module.exports.getAllForAdmin = async (req, res) => {
let page; // let page;
let rows; // let rows;
if (!req.query?.rows || req.query?.rows <= 5) { // if (!req.query?.rows || req.query?.rows <= 5) {
rows = 10 // rows = 10
} else { // } else {
rows = parseInt(req.query.rows) // rows = parseInt(req.query.rows)
} // }
if (!req.query?.page) { // if (!req.query?.page) {
page = 0 // page = 0
// eslint-disable-next-line eqeqeq // // eslint-disable-next-line eqeqeq
} else if (req.query.page <= 1) { // } else if (req.query.page <= 1) {
page = 0 // page = 0
} else { // } else {
page = req.query.page // page = req.query.page
page = page * rows - rows // page = page * rows - rows
} // }
const search = req.query?.search ? req.query.search : "" // const search = req.query?.search ? req.query.search : ""
const data = await InstalledDevice.find({ const data = await InstalledDevice.find({}).sort({ status: 1 })
$or: [
{ IMEI: { $regex: search } },
]
}).sort({ status: 1 }).skip(page).limit(rows)
.populate('deviceId') .populate('deviceId')
.populate('userId', 'shopName shopNumber shopAddress birthDate score first_name last_name profilePic') .populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
const total = Math.ceil((await InstalledDevice.estimatedDocumentCount())) const total = Math.ceil((await InstalledDevice.estimatedDocumentCount()))
res.status(200).json({ data, total }) res.status(200).json({ data, total })
} }
@@ -139,8 +136,8 @@ module.exports.updateInstalled = [
user.save() user.save()
device.save() device.save()
installedDevice.save() installedDevice.save()
// res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice }) res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
res.status(200).json(installedDevice)
break; break;
} }
@@ -149,8 +146,8 @@ module.exports.updateInstalled = [
installedDevice.save() installedDevice.save()
device.status = 0; device.status = 0;
device.save() device.save()
// res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice }) res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
res.status(200).json(installedDevice)
break; break;
} }
+1 -1
View File
@@ -75,7 +75,7 @@ const { fullName, national, phoneNumber, email, receptionCode, caption } = req.
module.exports.getsComplaint = [ module.exports.getsComplaint = [
async(req, res)=>{ async(req, res)=>{
const complaints = await Complaint.find({type:0}).populate('user', 'first_name last_name personalCode') const complaints = await Complaint.find({type:0}).populate('user', 'first_name last_name personalCode').sort({created_at:-1, read:-1})
res.status(200).json(complaints) res.status(200).json(complaints)