This commit is contained in:
caoqianming 2020-08-17 17:13:16 +08:00
parent 4672b65790
commit 89482b4aed
14 changed files with 537 additions and 14 deletions

View File

@ -2,5 +2,5 @@
ENV = 'production' ENV = 'production'
# base api # base api
VUE_APP_BASE_API = 'http://116.63.176.211:8035' VUE_APP_BASE_API = 'http://116.63.176.211:8036/api'

View File

@ -0,0 +1,53 @@
import request from '@/utils/request'
export function getQualificationList(query) {
return request({
url: '/ability/qualification/',
method: 'get',
params: query
})
}
export function getQualificationGroup(query) {
return request({
url: '/ability/qualification/group/',
method: 'get',
params: query
})
}
export function getCNASList(query) {
return request({
url: '/ability/cnas/',
method: 'get',
params: query
})
}
export function createQualification(data) {
return request({
url: '/ability/qualification/',
method: 'post',
data
})
}
export function updateQualification(id, data) {
return request({
url: `/ability/qualification/${id}/`,
method: 'put',
data
})
}
export function deleteQualification(id) {
return request({
url: `/ability/qualification/${id}/`,
method: 'delete'
})
}
export function importQualification(data) {
return request({
url: `/ability/qualification/import/`,
method: 'post',
data
})
}

View File

@ -54,11 +54,22 @@ export const constantRoutes = [
}] }]
}, },
{ {
path: '/', path: '/qualification',
component: Layout,
redirect: '/qualification',
children: [{
path: '',
name: 'Qualification',
component: () => import('@/views/ability/qualification'),
meta: { title: '资质检索', icon: 'table' }
}]
},
{
path: '/cma2',
component: Layout, component: Layout,
redirect: '/cma2', redirect: '/cma2',
children: [{ children: [{
path: 'cma2', path: '',
name: 'CMA2', name: 'CMA2',
component: () => import('@/views/ability/cma2'), component: () => import('@/views/ability/cma2'),
meta: { title: '检测能力(分子公司)', icon: 'table' } meta: { title: '检测能力(分子公司)', icon: 'table' }

View File

@ -209,6 +209,13 @@
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<style >
.el-table-filter{
width:300px;
max-height: 300px;
overflow-y: auto;
}
</style>
<script> <script>
import { getCMAList, createCMA, deleteCMA, updateCMA, importCMA, getCNASList, importCNAS, getCMAGroup } from "@/api/cma"; import { getCMAList, createCMA, deleteCMA, updateCMA, importCMA, getCNASList, importCNAS, getCMAGroup } from "@/api/cma";
import checkPermission from "@/utils/permission" import checkPermission from "@/utils/permission"

View File

@ -85,6 +85,17 @@
<el-table-column align="header-center" label="标准编号"> <el-table-column align="header-center" label="标准编号">
<template slot-scope="scope">{{ scope.row.bzbh }}</template> <template slot-scope="scope">{{ scope.row.bzbh }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="限制范围">
<template slot-scope="scope">{{ scope.row.xzfw }}</template>
</el-table-column>
<el-table-column align="header-center" label="关联资质" prop="glzz"
column-key="glzz"
:filters="groupBy.glzz"
:filter-multiple="false">
<template slot-scope="scope"
>{{ scope.row.glzz }}</template>
</el-table-column>
<el-table-column align="header-center" label="所属中心" <el-table-column align="header-center" label="所属中心"
prop="sszx" prop="sszx"
column-key="sszx" column-key="sszx"
@ -140,6 +151,7 @@
</template> </template>
<style > <style >
.el-table-filter{ .el-table-filter{
width:400px;
max-height: 300px; max-height: 300px;
overflow-y: auto; overflow-y: auto;
} }
@ -167,7 +179,7 @@ export default {
cma: defaultCMA, cma: defaultCMA,
upHeaders: upHeaders(), upHeaders: upHeaders(),
upUrl: upUrl(), upUrl: upUrl(),
groupBy:{sszx:[]}, groupBy:{sszx:[], glzz:[]},
cmaList: {count:0}, cmaList: {count:0},
listLoading: true, listLoading: true,
listQuery: Object.assign({}, dflistQuery), listQuery: Object.assign({}, dflistQuery),
@ -216,6 +228,7 @@ export default {
data.group_by = key data.group_by = key
getCMAGroup(data).then(response => { getCMAGroup(data).then(response => {
this.groupBy[key] = response.data this.groupBy[key] = response.data
console.log(this.groupBy)
}) })
} }
}, },

View File

@ -0,0 +1,344 @@
<template>
<div class="app-container">
<div>
<el-select v-model="listQuery.sszx" placeholder="所属单位" @change="handleFilter2" clearable>
<el-option
v-for="item in groupBy.sszx"
:key="item.value"
:label="item.text"
:value="item.value">
</el-option>
</el-select>
<el-input
v-model="listQuery.search"
placeholder="资质/服务"
style="width: 40%;"
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(['qualification_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,.zip"
: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="tableData.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 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 label="CMA资质">
<template slot-scope="scope">{{ scope.row.cma }}</template>
</el-table-column>
<el-table-column label="CNAS资质">
<template slot-scope="scope">{{ scope.row.cnas }}</template>
</el-table-column>
<el-table-column label="其它资质">
<template slot-scope="scope">{{ scope.row.other }}</template>
</el-table-column>
<el-table-column label="主要服务">
<template slot-scope="scope">{{ scope.row.service }}</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button
:disabled="!checkPermission(['qualification_update'])"
type="primary"
size="small"
icon="el-icon-edit"
@click="handleEdit(scope)"
/>
<el-button
:disabled="!checkPermission(['qualification_delete'])"
type="danger"
size="small"
icon="el-icon-delete"
@click="handleDelete(scope)"
/>
</template>
</el-table-column>
</el-table>
<pagination
v-show="tableData.count>0"
:total="tableData.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="formData" label-width="100px" label-position="right" :rules="rule1">
<el-form-item label="所属单位" prop="sszx">
<el-input v-model="formData.sszx" placeholder="所属单位" />
</el-form-item>
<el-form-item label="CMA资质" prop="cma">
<el-input v-model="formData.cma" placeholder="CMA资质" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"/>
</el-form-item>
<el-form-item label="CNAS资质" prop="cnas">
<el-input v-model="formData.cnas" placeholder="CNAS资质" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"/>
</el-form-item>
<el-form-item label="其它资质" prop="other">
<el-input v-model="formData.other" placeholder="其它资质" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"/>
</el-form-item>
<el-form-item label="主要服务" prop="service">
<el-input v-model="formData.service" placeholder="主要服务" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"/>
</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>
<style >
.el-table-filter{
width:400px;
max-height: 300px;
overflow-y: auto;
}
.el-table .cell {
white-space: pre-line;
}
</style>
<script>
import { getQualificationList, getQualificationGroup, createQualification, updateQualification, deleteQualification } from "@/api/qualification";
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: null,
cma:null,
cnas:null,
other:null,
service:null
};
const dflistQuery = {
page: 1,
page_size: 20,
}
export default {
components: { Pagination },
data() {
return {
formData: {
id: null,
cma:null,
cnas:null,
other:null,
service:null
},
upHeaders: upHeaders(),
upUrl: upUrl(),
groupBy:{sszx:[]},
tableData: {count:0},
listLoading: true,
listQuery: Object.assign({}, dflistQuery),
enabledOptions: [
{ key: "true", display_name: "激活" },
{ key: "false", display_name: "禁用" }
],
dialogVisible: false,
dialogType: "new",
popovervisible: false,
rule1:{
sszx: [{
required: true,
message: '请填写',
trigger: 'blur'
}],
cma: [{
required: true,
message: '请填写',
trigger: 'blur'
}],
cna: [{
required: true,
message: '请填写',
trigger: 'blur'
}],
other: [{
required: true,
message: '请填写',
trigger: 'blur'
}],
service: [{
required: true,
message: '请填写',
trigger: 'blur'
}],
},
};
},
computed: {},
watch: {
},
created() {
this.getList()
this.getGroup()
},
methods: {
checkPermission,
handleUploadSuccess(res, file) {
const loading = this.openLoading()
let data = {path:res.data.path}
importQualification(data).then(res=>{
this.$message({
message: '导入成功',
type: 'success'
})
loading.close()
this.resetFilter()
}).catch(error=>{loading.close()})
},
getList() {
this.listLoading = true;
getQualificationList(this.listQuery).then(response => {
if (response.data) {
this.tableData = response.data
}
this.listLoading = false
})
},
getGroup() {
for(let key in this.groupBy){
let data = Object.assign({}, this.listQuery)
data.group_by = key
getQualificationGroup(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()
},
handleFilter2() {
this.listQuery.page = 1
this.getList()
},
handleAdd() {
this.formData = Object.assign({}, defaultCMA)
this.dialogType = "new"
this.dialogVisible = true
this.$nextTick(() => {
this.$refs["Form"].clearValidate()
})
},
handleEdit(scope) {
this.formData = 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 () => {
var res = await deleteQualification(scope.row.id);
this.tableData.results.splice(scope.row.index, 1);
this.$message.success('成功');
})
.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) {
updateQualification(this.formData.id, this.formData).then(res => {
if (res.code >= 200) {
this.getList();
this.dialogVisible = false;
this.$message.success('成功')
}
});
} else {
createQualification(this.formData).then(res => {
if (res.code >= 200) {
this.getList();
this.dialogVisible = false;
this.$message.success('成功')
}
});
}
} else {
return false;
}
});
}
}
};
</script>

View File

@ -3,7 +3,7 @@
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left"> <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
<div class="title-container"> <div class="title-container">
<h3 class="title">系统登陆</h3> <h3 class="title">CTC能力检索</h3>
</div> </div>
<el-form-item prop="username"> <el-form-item prop="username">

View File

@ -0,0 +1,31 @@
# Generated by Django 3.0.7 on 2020-08-17 06:14
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('ability', '0008_auto_20200705_1222'),
]
operations = [
migrations.CreateModel(
name='Qualification',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')),
('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')),
('is_deleted', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')),
('sszx', models.TextField(blank=True, null=True, verbose_name='所属中心')),
('cma', models.TextField(blank=True, null=True, verbose_name='cma资质')),
('cnas', models.TextField(blank=True, null=True, verbose_name='cnas资质')),
('other', models.TextField(blank=True, null=True, verbose_name='检验检测相关其它资质')),
('service', models.TextField(blank=True, null=True, verbose_name='主要检验检测服务')),
],
options={
'abstract': False,
},
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-08-17 07:54
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ability', '0009_qualification'),
]
operations = [
migrations.AddField(
model_name='cma',
name='glzz',
field=models.TextField(blank=True, null=True, verbose_name='关联资质'),
),
]

View File

@ -23,6 +23,7 @@ class CMA(BaseModel):
sszx = models.TextField('所属中心',null=True,blank=True) sszx = models.TextField('所属中心',null=True,blank=True)
type = models.CharField('所属类型', max_length=50, type = models.CharField('所属类型', max_length=50,
choices=type_choices, default='center') choices=type_choices, default='center')
glzz = models.TextField('关联资质', null=True, blank=True)
class CNAS(BaseModel): class CNAS(BaseModel):
""" """
@ -33,4 +34,11 @@ class CNAS(BaseModel):
bzmc = models.CharField('标准名称', max_length=400,null=True,blank=True) bzmc = models.CharField('标准名称', max_length=400,null=True,blank=True)
bzbh = models.CharField('标准编号', max_length=400,null=True,blank=True) bzbh = models.CharField('标准编号', max_length=400,null=True,blank=True)
bztk = models.CharField('标准条款', max_length=400,null=True,blank=True) bztk = models.CharField('标准条款', max_length=400,null=True,blank=True)
sszx = models.TextField('所属中心',null=True,blank=True) sszx = models.TextField('所属中心',null=True,blank=True)
class Qualification(BaseModel):
sszx = models.TextField('所属中心', null=True, blank=True)
cma = models.TextField('cma资质', null=True, blank=True)
cnas = models.TextField('cnas资质', null=True, blank=True)
other = models.TextField('检验检测相关其它资质', null=True, blank=True)
service = models.TextField('主要检验检测服务', null=True, blank=True)

View File

@ -1,5 +1,5 @@
from rest_framework import serializers from rest_framework import serializers
from .models import CMA, CNAS from .models import *
class CMASerializer(serializers.ModelSerializer): class CMASerializer(serializers.ModelSerializer):
""" """
@ -15,4 +15,12 @@ class CNASSerializer(serializers.ModelSerializer):
""" """
class Meta: class Meta:
model = CNAS model = CNAS
fields = '__all__'
class QualificationSerializer(serializers.ModelSerializer):
"""
资质能力序列化
"""
class Meta:
model = Qualification
fields = '__all__' fields = '__all__'

View File

@ -1,10 +1,11 @@
from django.urls import path, include from django.urls import path, include
from rest_framework import routers from rest_framework import routers
from .views import CMAViewSet, CNASViewSet from .views import CMAViewSet, CNASViewSet, QualificationViewSet
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register('cma', CMAViewSet, basename="cma") router.register('cma', CMAViewSet, basename="cma")
router.register('cnas', CNASViewSet, basename="cnas") router.register('cnas', CNASViewSet, basename="cnas")
router.register('qualification', QualificationViewSet, basename="qualification")
urlpatterns = [ urlpatterns = [
path('', include(router.urls)) path('', include(router.urls))
] ]

View File

@ -1,7 +1,7 @@
from django.shortcuts import render from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
from .models import CMA, CNAS from .models import *
from .serializers import CMASerializer, CNASSerializer from .serializers import *
from rest_framework.decorators import action from rest_framework.decorators import action
from django.conf import settings from django.conf import settings
from rest_framework import status from rest_framework import status
@ -19,8 +19,8 @@ class CMAViewSet(ModelViewSet):
'put': 'cma_update', 'delete': 'cma_delete'} 'put': 'cma_update', 'delete': 'cma_delete'}
queryset = CMA.objects.all() queryset = CMA.objects.all()
serializer_class = CMASerializer serializer_class = CMASerializer
search_fields = ['bzbh', 'bzmc', 'sszx', 'xmmc'] search_fields = ['bzbh', 'bzmc', 'sszx', 'xmmc', 'glzz']
filterset_fields = ['sszx', 'type'] filterset_fields = ['sszx', 'type', 'glzz']
ordering_fields = ['xmxh'] ordering_fields = ['xmxh']
ordering = 'sszx' ordering = 'sszx'
@ -35,7 +35,8 @@ class CMAViewSet(ModelViewSet):
group_by = request.query_params.get('group_by') group_by = request.query_params.get('group_by')
group_by_data = list(queryset.values(group_by).annotate(count=Count(group_by)).order_by(group_by)) group_by_data = list(queryset.values(group_by).annotate(count=Count(group_by)).order_by(group_by))
for i in group_by_data: for i in group_by_data:
ret.append({'text':i[group_by]+'('+str(i['count'])+')','value':i[group_by]}) if i[group_by] and i['count']:
ret.append({'text':i[group_by]+'('+ str(i['count']) +')','value':i[group_by]})
return Response(ret) return Response(ret)
@action(methods=['post'], detail=False, url_path='import', url_name='cma_import', perms_map = {'post':'cma_import'}) @action(methods=['post'], detail=False, url_path='import', url_name='cma_import', perms_map = {'post':'cma_import'})
@ -108,6 +109,33 @@ class CMAViewSet(ModelViewSet):
import_cma2(f.encode('cp437').decode('gbk'), os.path.join(root,f)) import_cma2(f.encode('cp437').decode('gbk'), os.path.join(root,f))
return Response(status = status.HTTP_200_OK) return Response(status = status.HTTP_200_OK)
class QualificationViewSet(ModelViewSet):
"""
资质能力增删改查
"""
perms_map = {'get': '*', 'post': 'qualificaiton_create',
'put': 'qualification_update', 'delete': 'qualification_delete'}
queryset = Qualification.objects.all()
serializer_class = QualificationSerializer
search_fields = ['cma', 'cnas', 'sszx', 'other', 'service']
# ordering_fields = ['sszx']
ordering = 'sszx'
@action(methods=['get'], detail=False,url_name='qualification_group_by', perms_map = {'*':'*'})
def group(self, request, pk=None):
"""
聚合查询列
"""
queryset = self.filter_queryset(self.get_queryset())
ret = []
if request.query_params.get('group_by', None):
group_by = request.query_params.get('group_by')
group_by_data = list(queryset.values(group_by).annotate(count=Count(group_by)).order_by(group_by))
for i in group_by_data:
if i[group_by] and i['count']:
ret.append({'text':i[group_by]+'('+ str(i['count']) +')','value':i[group_by]})
return Response(ret)
class CNASViewSet(ModelViewSet): class CNASViewSet(ModelViewSet):
""" """
CNAS检测能力增删改查 CNAS检测能力增删改查
@ -224,6 +252,7 @@ def import_cma2(filename, path):
CMA.objects.filter(sszx=sszx, type='sub').delete() CMA.objects.filter(sszx=sszx, type='sub').delete()
i = 3 i = 3
max_row = sheet.max_row max_row = sheet.max_row
print(max_row)
while i<max_row+1: while i<max_row+1:
data = {} data = {}
if sheet['a'+str(i)].value: if sheet['a'+str(i)].value:
@ -304,9 +333,9 @@ def import_cma2(filename, path):
m = m - 1 m = m - 1
data['xzfw'] = sheet['i'+str(i)].value if (sheet['i'+str(i)].value and sheet['i'+str(i)].value !='') else None data['xzfw'] = sheet['i'+str(i)].value if (sheet['i'+str(i)].value and sheet['i'+str(i)].value !='') else None
data['bz'] = sheet['j'+str(i)].value if (sheet['j'+str(i)].value and sheet['j'+str(i)].value !='') else None data['bz'] = sheet['j'+str(i)].value if (sheet['j'+str(i)].value and sheet['j'+str(i)].value !='') else None
data['glzz'] = sheet['k'+str(i)].value if (sheet['k'+str(i)].value and sheet['k'+str(i)].value !='') else None
data['sszx'] = sszx data['sszx'] = sszx
data['type'] = 'sub' data['type'] = 'sub'
# print(data)
datalist.append(CMA(**data)) datalist.append(CMA(**data))
i = i + 1 i = i + 1
CMA.objects.bulk_create(datalist) CMA.objects.bulk_create(datalist)

Binary file not shown.