Add custom serials
This commit is contained in:
@@ -254,15 +254,29 @@
|
||||
/>
|
||||
<CSidebarNavItem
|
||||
v-if="hasPermission('serials-exel')"
|
||||
name="فایل اکسل شماره سریال گارانتی"
|
||||
:to="{ name: 'admin-serials-exel', query: { type: 'guaranteeSerial' } }"
|
||||
name="اکسل سریال گارانتی(لوازم جانبی)"
|
||||
:to="{ name: 'admin-serials-exel', query: { type: 'guaranteeSerial', g:1 } }"
|
||||
font-icon="fal fa-file-excel"
|
||||
exact
|
||||
/>
|
||||
<CSidebarNavItem
|
||||
v-if="hasPermission('serials-exel')"
|
||||
name="فایل اکسل شماره سریال کالا"
|
||||
:to="{ name: 'admin-serials-exel', query: { type: 'orginality' } }"
|
||||
name="اکسل سریال کالا(لوازم جانبی)"
|
||||
:to="{ name: 'admin-serials-exel', query: { type: 'orginality', g:1 } }"
|
||||
font-icon="fal fa-file-excel"
|
||||
exact
|
||||
/>
|
||||
<CSidebarNavItem
|
||||
v-if="hasPermission('serials-exel')"
|
||||
name="اکسل سریال گارانتی(لوازم صوتی)"
|
||||
:to="{ name: 'admin-serials-exel', query: { type: 'guaranteeSerial', g:2 } }"
|
||||
font-icon="fal fa-file-excel"
|
||||
exact
|
||||
/>
|
||||
<CSidebarNavItem
|
||||
v-if="hasPermission('serials-exel')"
|
||||
name="اکسل سریال کالا(لوازم صوتی)"
|
||||
:to="{ name: 'admin-serials-exel', query: { type: 'orginality', g:2 } }"
|
||||
font-icon="fal fa-file-excel"
|
||||
exact
|
||||
/>
|
||||
|
||||
@@ -30,17 +30,17 @@
|
||||
download
|
||||
target="_blank"
|
||||
title="برای دانلود کلیک کنید"
|
||||
:href="scope.row.url + scope.row.name"
|
||||
:href="scope?.row.url + scope?.row.name"
|
||||
style="color: blue; display: block; direction: ltr !important; text-align: right"
|
||||
>
|
||||
{{ scope.row.name }}
|
||||
{{ scope?.row.name }}
|
||||
</a>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column v-if="scope.row.length > 1" label="حذف" width="60" align="left">
|
||||
<el-table-column v-if="scope?.row.length > 1" label="حذف" width="60" align="left">
|
||||
<template slot-scope="scope">
|
||||
<CButton :key="scope.row._id" color="danger" variant="outline" @click="del(scope.row.name)">
|
||||
<CButton :key="scope?.row._id" color="danger" variant="outline" @click="del(scope?.row.name)">
|
||||
<i class="fal fa-trash-alt"></i>
|
||||
</CButton>
|
||||
</template>
|
||||
@@ -60,9 +60,11 @@ export default {
|
||||
async asyncData({ $axios, error, query }) {
|
||||
try {
|
||||
const type = query?.type
|
||||
const g = query?.g
|
||||
|
||||
if (!type) throw new Error('invalid type')
|
||||
const files = await $axios.get('/api/admin/serialExels', {
|
||||
params: { type }
|
||||
params: { type, g }
|
||||
})
|
||||
return {
|
||||
files: files.data
|
||||
@@ -74,7 +76,7 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
files: null,
|
||||
files: [],
|
||||
validation: {}
|
||||
}
|
||||
},
|
||||
@@ -87,6 +89,9 @@ export default {
|
||||
type() {
|
||||
return this.$route.query?.type
|
||||
},
|
||||
g() {
|
||||
return this.$route.query?.g
|
||||
},
|
||||
title() {
|
||||
if (this.type === 'guaranteeSerial') return 'فایل اکسل شماره سریال گارانتی'
|
||||
else return 'فایل اکسل شماره سریال کالا'
|
||||
@@ -102,6 +107,7 @@ export default {
|
||||
this.validation = {}
|
||||
const data = new FormData()
|
||||
data.append('type', this.type)
|
||||
data.append('g', this.g)
|
||||
data.append('file', this.$refs.file.files[0])
|
||||
this.$axios
|
||||
.post('/api/admin/addExel', data)
|
||||
|
||||
+3
-1
@@ -132,6 +132,7 @@ export default {
|
||||
inquiryType: 'guaranteeSerial',
|
||||
checkingSerial: false,
|
||||
brands:[],
|
||||
g: 1
|
||||
}
|
||||
},
|
||||
head() {
|
||||
@@ -178,7 +179,8 @@ export default {
|
||||
this.checkingSerial = true
|
||||
const data = {
|
||||
serial: this.serial,
|
||||
type: this.inquiryType
|
||||
type: this.inquiryType,
|
||||
g: this.g
|
||||
}
|
||||
const loading = this.$loading({
|
||||
lock: true,
|
||||
|
||||
@@ -27,9 +27,9 @@ module.exports.addExel = [
|
||||
if (!req.files?.file.name.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item)))
|
||||
return res.status(422).json({ validation: { file: { msg: 'فرمت فایل درست نمیباشد' } } })
|
||||
const file = req.files.file
|
||||
const { type } = req.body
|
||||
const { type, g } = req.body
|
||||
try {
|
||||
const path = type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath
|
||||
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
|
||||
const files = await fs.readdirSync(path)
|
||||
for await (const item of files) {
|
||||
if (file.name === item) return res.status(422).json({ validation: { file: { msg: 'نام فایل تکراریست' } } })
|
||||
@@ -47,12 +47,14 @@ module.exports.addExel = [
|
||||
module.exports.getAllExels = [
|
||||
(req, res) => {
|
||||
const type = req.query?.type
|
||||
if (!type) {
|
||||
const g = req.query?.g
|
||||
|
||||
if (!type || !g) {
|
||||
res500(res, 'choose type')
|
||||
}
|
||||
const validValues = ['guaranteeSerial', 'orginality']
|
||||
if (!validValues.includes(type)) return res500(res, 'choose type')
|
||||
const path = type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath
|
||||
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
|
||||
const downloadAblePath = type === 'guaranteeSerial' ? '/uploads/serials/' : '/uploads/serials_products/'
|
||||
fs.readdir(path, (err, files) => {
|
||||
if (err) return res500(res, err)
|
||||
@@ -67,10 +69,12 @@ module.exports.getAllExels = [
|
||||
module.exports.removeExel = [
|
||||
(req, res) => {
|
||||
const type = req.query?.type
|
||||
if (!type) return res500(res, 'choose type')
|
||||
const g = req.query?.g
|
||||
|
||||
if (!type || !g) return res500(res, 'choose type')
|
||||
const validValues = ['guaranteeSerial', 'orginality']
|
||||
if (!validValues.includes(type)) return res500(res, 'choose type')
|
||||
const path = type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath
|
||||
const path = (type === 'guaranteeSerial' ? guaranteeSerialsPath : productSerialsPath) + `/${g}`
|
||||
fs.unlink(`${path}/${req.params.name}`, err => {
|
||||
if (err) return res404(res, _faSr.not_found.item_id)
|
||||
else return res.json({ message: _faSr.response.success_remove })
|
||||
@@ -95,8 +99,8 @@ module.exports.checkSerial = [
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { serial, type } = req.body
|
||||
const serialStatus = await serialChecker(serial, type)
|
||||
const { serial, type, g } = req.body
|
||||
const serialStatus = await serialChecker(serial, type, g)
|
||||
|
||||
let okMsg
|
||||
if (type === 'guaranteeSerial') okMsg = 'شماره سریال گارانتی معتبر میباشد.'
|
||||
|
||||
@@ -4,10 +4,10 @@ const readXlsxFile = require('read-excel-file/node')
|
||||
const guaranteeSerialsPath = './static/uploads/serials'
|
||||
const productSerialsPath = './static/uploads/serials_products'
|
||||
|
||||
const serialChecker = async (serial, type = 'guaranteeSerial') => {
|
||||
const serialChecker = async (serial, type = 'guaranteeSerial', g = 1) => {
|
||||
let exelsPath
|
||||
if (type === 'guaranteeSerial') exelsPath = guaranteeSerialsPath
|
||||
if (type === 'orginality') exelsPath = productSerialsPath
|
||||
if (type === 'guaranteeSerial') exelsPath = guaranteeSerialsPath + g
|
||||
if (type === 'orginality') exelsPath = productSerialsPath + g
|
||||
|
||||
const lowerSerial = serial.toLowerCase()
|
||||
// a promise to lowercase items and filter null or DateObjects
|
||||
|
||||
Reference in New Issue
Block a user