fenzigongsi
This commit is contained in:
parent
03a13f8eed
commit
881bf0c060
|
@ -51,6 +51,14 @@ export function importCMA(data) {
|
|||
data
|
||||
})
|
||||
}
|
||||
export function importCMA2(data) {
|
||||
return request({
|
||||
url: `/ability/cma/import2/`,
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function importCNAS(data) {
|
||||
return request({
|
||||
url: `/ability/cnas/import/`,
|
||||
|
|
|
@ -24,7 +24,7 @@ export default {
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
title: 'Django Vue Admin',
|
||||
title: '能力检索',
|
||||
logo: 'https://wpimg.wallstcn.com/69a1c46c-eb1c-4b46-8bd4-e9e686ef5251.png'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,18 @@ export const constantRoutes = [
|
|||
path: 'cma',
|
||||
name: 'CMA',
|
||||
component: () => import('@/views/ability/cma'),
|
||||
meta: { title: '检测能力', icon: 'table' }
|
||||
meta: { title: '检测能力(总部)', icon: 'table' }
|
||||
}]
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
component: Layout,
|
||||
redirect: '/cma2',
|
||||
children: [{
|
||||
path: 'cma2',
|
||||
name: 'CMA2',
|
||||
component: () => import('@/views/ability/cma2'),
|
||||
meta: { title: '检测能力(分子公司)', icon: 'table' }
|
||||
}]
|
||||
}
|
||||
// {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import defaultSettings from '@/settings'
|
||||
|
||||
const title = defaultSettings.title || 'Django Vue Admin'
|
||||
const title = defaultSettings.title || '能力检索'
|
||||
|
||||
export default function getPageTitle(pageTitle) {
|
||||
if (pageTitle) {
|
||||
|
|
|
@ -223,6 +223,7 @@ const defaultCMA = {
|
|||
const dflistQuery = {
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
type:'center'
|
||||
}
|
||||
export default {
|
||||
components: { Pagination },
|
||||
|
|
|
@ -0,0 +1,296 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<div>
|
||||
<el-input
|
||||
v-model="listQuery.search"
|
||||
placeholder="项目/标准/编号/中心"
|
||||
style="width: 600px;"
|
||||
class="filter-item"
|
||||
@keyup.enter.native="handleFilter"
|
||||
/>
|
||||
<el-button
|
||||
class="filter-item"
|
||||
type="primary"
|
||||
icon="el-icon-search"
|
||||
@click="handleFilter"
|
||||
>搜索</el-button>
|
||||
<el-button
|
||||
class="filter-item"
|
||||
style="margin-left: 10px;"
|
||||
type="primary"
|
||||
icon="el-icon-refresh-left"
|
||||
@click="resetFilter"
|
||||
>刷新重置</el-button>
|
||||
</div>
|
||||
<div style="margin-top:10px">
|
||||
<!-- <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['cma_create'])">新增</el-button> -->
|
||||
<el-popover
|
||||
placement="top"
|
||||
width="160"
|
||||
v-if="checkPermission(['ability_import'])"
|
||||
v-model="popovervisible"
|
||||
>
|
||||
<p>导入能力列表压缩包.</p>
|
||||
<div style="text-align: left; margin: 0;">
|
||||
<el-upload
|
||||
:action="upUrl"
|
||||
:on-success="handleUploadSuccess"
|
||||
accept=".rar"
|
||||
:headers="upHeaders"
|
||||
:show-file-list ="false"
|
||||
>
|
||||
<el-button size="small" type="primary" @click="popovervisible = false">上传导入</el-button>
|
||||
</el-upload>
|
||||
</div>
|
||||
|
||||
<el-button slot="reference">导入分子公司能力</el-button>
|
||||
</el-popover>
|
||||
</div>
|
||||
<el-table
|
||||
v-loading="listLoading"
|
||||
:data="cmaList.results"
|
||||
style="width: 100%;margin-top:10px;"
|
||||
border
|
||||
fit
|
||||
stripe
|
||||
highlight-current-row
|
||||
max-height="600"
|
||||
ref="filterTable"
|
||||
@filter-change="filterChange"
|
||||
>
|
||||
<el-table-column type="index" width="50" />
|
||||
<el-table-column align="center" label="大类名称">
|
||||
<template slot-scope="scope">{{ scope.row.dlmc }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="header-center" label="类别名称">
|
||||
<template slot-scope="scope">{{ scope.row.lbmc }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="header-center" label="项目序号">
|
||||
<template slot-scope="scope">{{ scope.row.xmxh }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="header-center" label="项目名称">
|
||||
<template slot-scope="scope">{{ scope.row.xmmc }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="header-center" label="标准名称">
|
||||
<template slot-scope="scope">{{ scope.row.bzmc }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="header-center" label="标准编号">
|
||||
<template slot-scope="scope">{{ scope.row.bzbh }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="header-center" label="所属中心"
|
||||
prop="sszx"
|
||||
column-key="sszx"
|
||||
:filters="groupBy.sszx"
|
||||
:filter-multiple="false"
|
||||
>
|
||||
<template slot-scope="scope">{{ scope.row.sszx }}</template>
|
||||
</el-table-column>
|
||||
<!-- <el-table-column align="center" label="操作">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
:disabled="!checkPermission(['cma_update'])"
|
||||
type="primary"
|
||||
size="small"
|
||||
icon="el-icon-edit"
|
||||
@click="handleEdit(scope)"
|
||||
/>
|
||||
<el-button
|
||||
:disabled="!checkPermission(['cma_delete'])"
|
||||
type="danger"
|
||||
size="small"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column> -->
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="cmaList.count>0"
|
||||
:total="cmaList.count"
|
||||
:page.sync="listQuery.page"
|
||||
:limit.sync="listQuery.page_size"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
<el-dialog :visible.sync="dialogVisible" :title="dialogType==='edit'?'编辑':'新增'">
|
||||
<el-form ref="Form" :model="cma" label-width="80px" label-position="right" >
|
||||
<el-form-item label="姓名" prop="name">
|
||||
<el-input v-model="cma.name" placeholder="姓名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="账户" prop="username">
|
||||
<el-input v-model="cma.username" placeholder="账户" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div style="text-align:right;">
|
||||
<el-button type="danger" @click="dialogVisible=false">取消</el-button>
|
||||
<el-button type="primary" @click="confirm('Form')">确认</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { getCMAList, createCMA, deleteCMA, updateCMA, importCMA2, getCNASList, importCNAS, getCMAGroup } from "@/api/cma";
|
||||
import checkPermission from "@/utils/permission"
|
||||
import { upUrl, upHeaders } from "@/api/file"
|
||||
import Pagination from "@/components/Pagination" // secondary package based on el-pagination
|
||||
const defaultCMA = {
|
||||
id: "",
|
||||
dlxh:null,
|
||||
dlmc:null,
|
||||
|
||||
};
|
||||
const dflistQuery = {
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
type:'sub'
|
||||
}
|
||||
export default {
|
||||
components: { Pagination },
|
||||
data() {
|
||||
return {
|
||||
cma: defaultCMA,
|
||||
upHeaders: upHeaders(),
|
||||
upUrl: upUrl(),
|
||||
groupBy:{sszx:[]},
|
||||
cmaList: {count:0},
|
||||
listLoading: true,
|
||||
listQuery: Object.assign({}, dflistQuery),
|
||||
enabledOptions: [
|
||||
{ key: "true", display_name: "激活" },
|
||||
{ key: "false", display_name: "禁用" }
|
||||
],
|
||||
dialogVisible: false,
|
||||
dialogType: "new",
|
||||
popovervisible: false,
|
||||
};
|
||||
},
|
||||
computed: {},
|
||||
watch: {
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
this.getGroup()
|
||||
},
|
||||
methods: {
|
||||
checkPermission,
|
||||
handleUploadSuccess(res, file) {
|
||||
const loading = this.openLoading()
|
||||
let data = {path:res.data.path}
|
||||
importCMA2(data).then(res=>{
|
||||
this.$message({
|
||||
message: '导入成功',
|
||||
type: 'success'
|
||||
})
|
||||
loading.close()
|
||||
this.resetFilter()
|
||||
}).catch(error=>{loading.close()})
|
||||
},
|
||||
getList() {
|
||||
this.listLoading = true;
|
||||
getCMAList(this.listQuery).then(response => {
|
||||
if (response.data) {
|
||||
this.cmaList = response.data
|
||||
}
|
||||
this.listLoading = false
|
||||
})
|
||||
},
|
||||
getGroup() {
|
||||
for(let key in this.groupBy){
|
||||
let data = Object.assign({}, this.listQuery)
|
||||
data.group_by = key
|
||||
getCMAGroup(data).then(response => {
|
||||
this.groupBy[key] = response.data
|
||||
})
|
||||
}
|
||||
},
|
||||
resetFilter() {
|
||||
this.listQuery = Object.assign({}, dflistQuery),
|
||||
this.getList()
|
||||
this.getGroup()
|
||||
},
|
||||
handleFilter() {
|
||||
this.listQuery.page = 1
|
||||
this.getList()
|
||||
this.getGroup()
|
||||
},
|
||||
handleAdd() {
|
||||
this.cma = Object.assign({}, defaultCMA)
|
||||
this.dialogType = "new"
|
||||
this.dialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs["Form"].clearValidate()
|
||||
})
|
||||
},
|
||||
handleEdit(scope) {
|
||||
this.cma = Object.assign({}, scope.row) // copy obj
|
||||
this.dialogType = "edit"
|
||||
this.dialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs["Form"].clearValidate()
|
||||
})
|
||||
},
|
||||
handleDelete(scope) {
|
||||
this.$confirm("确认删除?", "警告", {
|
||||
confirmButtonText: "确认",
|
||||
cancelButtonText: "取消",
|
||||
type: "error"
|
||||
})
|
||||
.then(async () => {
|
||||
await deleteCMA(scope.row.id);
|
||||
this.cmaList.splice(scope.row.index, 1);
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "成功删除!"
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
},
|
||||
filterChange (obj) {
|
||||
for(let key in obj){
|
||||
this.listQuery[key] = obj[key][0]
|
||||
}
|
||||
this.listQuery.page=1
|
||||
this.getList()
|
||||
},
|
||||
async confirm(form) {
|
||||
this.$refs[form].validate(valid => {
|
||||
if (valid) {
|
||||
const isEdit = this.dialogType === "edit";
|
||||
if (isEdit) {
|
||||
updateCMA(this.cma.id, this.cma).then(res => {
|
||||
if (res.code >= 200) {
|
||||
this.getList();
|
||||
this.dialogVisible = false;
|
||||
this.$notify({
|
||||
title: "成功",
|
||||
message: "编辑成功",
|
||||
type: "success",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
createCMA(this.cma).then(res => {
|
||||
if (res.code >= 200) {
|
||||
this.getList();
|
||||
this.dialogVisible = false;
|
||||
this.$notify({
|
||||
title: "成功",
|
||||
message: "新增成功",
|
||||
type: "success",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.7 on 2020-07-03 09:18
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ability', '0006_cnas_bztk'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='cma',
|
||||
name='type',
|
||||
field=models.CharField(choices=[('center', '总部'), ('sub', '分子公司')], default='center', max_length=50, verbose_name='所属类型'),
|
||||
),
|
||||
]
|
|
@ -6,6 +6,10 @@ class CMA(BaseModel):
|
|||
"""
|
||||
CMA检测能力表
|
||||
"""
|
||||
type_choices = (
|
||||
('center', '总部'),
|
||||
('sub', '分子公司')
|
||||
)
|
||||
dlxh = models.CharField('大类序号', max_length=200,null=True,blank=True)
|
||||
dlmc = models.CharField('大类', max_length=200,null=True,blank=True)
|
||||
lbxh = models.CharField('类别序号', max_length=200,null=True,blank=True)
|
||||
|
@ -17,6 +21,8 @@ class CMA(BaseModel):
|
|||
xzfw = models.TextField('限制范围',null=True,blank=True)
|
||||
bz = models.TextField('备注',null=True,blank=True)
|
||||
sszx = models.TextField('所属中心',null=True,blank=True)
|
||||
type = models.CharField('所属类型', max_length=50,
|
||||
choices=type_choices, default='center')
|
||||
|
||||
class CNAS(BaseModel):
|
||||
"""
|
||||
|
|
|
@ -20,7 +20,7 @@ class CMAViewSet(ModelViewSet):
|
|||
queryset = CMA.objects.all()
|
||||
serializer_class = CMASerializer
|
||||
search_fields = ['bzbh', 'bzmc', 'sszx', 'xmmc']
|
||||
filterset_fields = ['sszx']
|
||||
filterset_fields = ['sszx', 'type']
|
||||
ordering_fields = ['xmxh']
|
||||
ordering = 'xmxh'
|
||||
|
||||
|
@ -58,8 +58,28 @@ class CMAViewSet(ModelViewSet):
|
|||
for f in files:
|
||||
import_cma(f, os.path.join(root,f))
|
||||
return Response(status = status.HTTP_200_OK)
|
||||
|
||||
|
||||
@action(methods=['post'], detail=False, url_path='import2', url_name='cma_import2', perms_map = {'post':'cma_import2'})
|
||||
def cma_import2(self, request, pk=None):
|
||||
"""
|
||||
导入能力2
|
||||
"""
|
||||
filepath = request.data['path']
|
||||
fullpath = settings.BASE_DIR + filepath
|
||||
import os
|
||||
if fullpath.endswith('.rar'):
|
||||
rar = rarfile.RarFile(fullpath)
|
||||
fulldir = fullpath.replace('.rar','')
|
||||
os.mkdir(fulldir)
|
||||
os.chdir(fulldir)
|
||||
rar.extractall()
|
||||
rar.close()
|
||||
CMA.objects.all().delete()
|
||||
for root, dirs, files in os.walk(fulldir):
|
||||
for f in files:
|
||||
import_cma2(f, os.path.join(root,f))
|
||||
return Response(status = status.HTTP_200_OK)
|
||||
|
||||
class CNASViewSet(ModelViewSet):
|
||||
"""
|
||||
CNAS检测能力:增删改查
|
||||
|
@ -152,4 +172,29 @@ def import_cnas(filename, path):
|
|||
print(data)
|
||||
datalist.append(CNAS(**data))
|
||||
i = i + 1
|
||||
CNAS.objects.bulk_create(datalist)
|
||||
CNAS.objects.bulk_create(datalist)
|
||||
|
||||
def import_cma2(filename, path):
|
||||
wb = load_workbook(path)
|
||||
sheet = wb.worksheets[0]
|
||||
datalist = []
|
||||
sszx = filename.split('-')[0]
|
||||
i = 3
|
||||
while sheet['b'+str(i)].value:
|
||||
data = {}
|
||||
data['dlxh'] = sheet['a'+str(i)].value
|
||||
data['dlmc'] = sheet['b'+str(i)].value
|
||||
data['lbxh'] = sheet['c'+str(i)].value
|
||||
data['lbmc'] = sheet['d'+str(i)].value
|
||||
data['xmxh'] = sheet['e'+str(i)].value
|
||||
data['xmmc'] = sheet['f'+str(i)].value
|
||||
data['bzmc'] = sheet['g'+str(i)].value
|
||||
data['bzbh'] = sheet['h'+str(i)].value
|
||||
data['xzfw'] = sheet['i'+str(i)].value
|
||||
data['bz'] = sheet['j'+str(i)].value
|
||||
data['sszx'] = sszx
|
||||
data['type'] = 'sub'
|
||||
print(data)
|
||||
datalist.append(CMA(**data))
|
||||
i = i + 1
|
||||
CMA.objects.bulk_create(datalist)
|
Binary file not shown.
Loading…
Reference in New Issue