检验资质

This commit is contained in:
shilixia 2020-10-28 09:38:47 +08:00
parent f6ea77f58b
commit 4905729e07
8 changed files with 109 additions and 89 deletions

View File

@ -9,7 +9,7 @@ export function getQualificationList(query) {
}
export function getQualificationGroup(query) {
return request({
url: '/ability/qualification/group/',
url: '/system/organization/group/',
method: 'get',
params: query
})

View File

@ -2,9 +2,9 @@
<div class="app-container">
<el-row :gutter="6">
<el-col :xs="24" :md="4">
<el-select v-model="listQuery.qualification__sszx" placeholder="所属单位" @change="handleFilter2" clearable style="width: 100%;">
<el-select v-model="listQuery.qualification__ssbm__name" placeholder="所属单位" @change="handleFilter2" clearable style="width: 100%;">
<el-option
v-for="item in groupBy.sszx"
v-for="item in groupBy.name"
:key="item.value"
:label="item.text"
:value="item.value">
@ -71,14 +71,14 @@
</div>
<el-table
v-loading="listLoading"
:data="tableData.results"
:data="tableData"
:span-method="objectSpanMethod"
style="width: 100%;margin-top:10px;"
border
fit
stripe
highlight-current-row
height="600"
height="650"
ref="filterTable"
@selection-change="handleSelectionChange"
@filter-change="filterChange"
@ -88,76 +88,43 @@
type="selection"
width="55">
</el-table-column>
<el-table-column label="所属单位"
prop="sszx"
column-key="sszx"
:filters="groupBy.sszx"
:filter-multiple="false"
<el-table-column align="center" label="所属单位"
>
<template slot-scope="scope">{{ scope.row.qualification_.sszx }}</template>
<template style="text-align:left;" slot-scope="scope">{{ scope.row.qualification_.bm_.name }}</template>
</el-table-column>
<el-table-column label="CMA资质">
<template slot-scope="scope">
<span v-html="showlight(scope.row.qualification_.cma)"></span>
<el-table-column header-align="center" label="CMA资质">
<template style="text-align:left;" slot-scope="scope">
<span style="margin-top:0px" v-html="showlight(scope.row.qualification_.cma)"></span>
</template>
</el-table-column>
<el-table-column label="CNAS资质">
<template slot-scope="scope">
<el-table-column header-align="center" label="CNAS资质">
<template style="text-align:left;" slot-scope="scope">
<span v-html="showlight(scope.row.qualification_.cnas)"></span>
</template>
</el-table-column>
<el-table-column label="检验检测相关其他资质及校准资质">
<el-table-column label="其它资质" >
<template slot-scope="scope">
<el-table-column width="800" header-align="center" label="检验检测相关其他资质及校准资质">
<el-table-column width="300" header-align="center" label="其它资质" >
<template style="text-align:left;" slot-scope="scope">
<span v-html="showlight(scope.row.name)" ></span>
</template>
</el-table-column>
<el-table-column label="资质范围" >
<template slot-scope="scope">
<el-table-column width="500" header-align="center" label="资质范围" >
<template style="text-align:left;" slot-scope="scope">
<span v-html="showlight(scope.row.description)" ></span>
</template>
</el-table-column>
</el-table-column>
<el-table-column label="主要服务">
<template slot-scope="scope">
<el-table-column header-align="center" label="主要服务">
<template style="text-align:left;" slot-scope="scope">
<span v-html="showlight(scope.row.qualification_.service)"></span>
</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 >
@ -184,32 +151,24 @@ const defaultCMA = {
};
const dflistQuery = {
page: 1,
page_size: 20,
pageoff:true,
search:''
}
export default {
components: { Pagination },
components: { },
data() {
return {
formData: {
id: null,
cma:null,
cnas:null,
other:null,
service:null
},
delarr:[],
upHeaders: upHeaders(),
upUrl: upUrl(),
groupBy:{sszx:[]},
tableData: {count:0},
groupBy:{name:[]},
tableData: [],
rowIndex: '-1',
OrderIndexArr: [],
hoverOrderArr: [],
listLoading: true,
listQuery: Object.assign({}, dflistQuery),
listQuery: dflistQuery,
enabledOptions: [
{ key: "true", display_name: "激活" },
{ key: "false", display_name: "禁用" }
@ -277,7 +236,7 @@ delarr:[],
let OrderObj = {}
this.tableData.results.forEach((element, index) => {
this.tableData.forEach((element, index) => {
element.rowIndex = index
if (OrderObj[element.qualification_.id]) {
OrderObj[element.qualification_.id].push(index)
@ -360,6 +319,7 @@ delarr:[],
data.group_by = key
getQualificationGroup(data).then(response => {
this.groupBy[key] = response.data
console.log(response.data)
})
}
},
@ -369,12 +329,10 @@ delarr:[],
this.getGroup()
},
handleFilter() {
this.listQuery.page = 1
this.getList()
this.getGroup()
},
handleFilter2() {
this.listQuery.page = 1
this.getList()
},
handleAdd() {
@ -414,7 +372,7 @@ delarr:[],
for(let key in obj){
this.listQuery[key] = obj[key][0]
}
this.listQuery.page=1
this.getList()
},
async confirm(form) {

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.5 on 2020-10-27 08:24
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('system', '0005_organization_sort'),
('ability', '0015_remove_inspection_type'),
]
operations = [
migrations.AddField(
model_name='qualification',
name='ssbm',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='system_ssbm', to='system.Organization'),
),
]

View File

@ -1,5 +1,7 @@
from django.db import models
from utils.model import BaseModel
from apps.system.models import Organization
# Create your models here.
class CMA(BaseModel):
@ -54,6 +56,7 @@ class CNAS(BaseModel):
class Qualification(BaseModel):
sszx = models.TextField('所属中心', null=True, blank=True)
ssbm = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True, related_name='system_ssbm')
cma = models.TextField('cma资质', null=True, blank=True)
cnas = models.TextField('cnas资质', null=True, blank=True)
other = models.TextField('检验检测相关其它资质', null=True, blank=True)

View File

@ -1,5 +1,7 @@
from rest_framework import serializers
from .models import *
from apps.system.serializers import OrganizationSerializer
class CMASerializer(serializers.ModelSerializer):
"""
@ -28,10 +30,15 @@ class QualificationSerializer(serializers.ModelSerializer):
"""
资质能力序列化
"""
bm_=OrganizationSerializer(source = 'ssbm', read_only=True)
class Meta:
model = Qualification
fields = '__all__'
@staticmethod
def setup_eager_loading(queryset):
""" Perform necessary eager loading of data. """
queryset = queryset.select_related('ssbm')
return queryset
class QualificationotherSerializer(serializers.ModelSerializer):
qualification_ = QualificationSerializer(source = 'qualification', read_only=True)

View File

@ -8,8 +8,10 @@ from rest_framework import status
from rest_framework.response import Response
import zipfile
import rarfile
from apps.system.models import Organization
from openpyxl import Workbook, load_workbook
from django.db.models import Count
from utils.pagination import PageOrNot
# Create your views here.
class CMAViewSet(ModelViewSet):
"""
@ -170,7 +172,7 @@ class QualificationViewSet(ModelViewSet):
return Response(status = status.HTTP_200_OK)
else:
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
class QualificationotherViewSet(ModelViewSet):
class QualificationotherViewSet(PageOrNot,ModelViewSet):
"""
资质能力增删改查
"""
@ -178,9 +180,10 @@ class QualificationotherViewSet(ModelViewSet):
'put': 'qualificationother_update', 'delete': 'qualificationother_delete'}
queryset = Qualificationother.objects.all()
serializer_class = QualificationotherSerializer
search_fields = ['qualification__cma', 'name','description','qualification__cnas', 'qualification__sszx', 'qualification__service']
filterset_fields = ['qualification__sszx']
ordering = ['qualification__sszx']
search_fields = ['qualification__cma', 'name','description','qualification__cnas', 'qualification__ssbm__name', 'qualification__service']
filterset_fields = ['qualification__ssbm__name']
ordering_fields = ['qualification__ssbm__name']
ordering = ['qualification__ssbm__name']
@action(methods=['post'], detail=False, url_path='deletes', url_name='qualificationother_deletes', perms_map = {'post':'qualificationother_deletes'})
def deletes(self, request):
@ -315,6 +318,7 @@ def import_qualification(path):
max_row = sheet.max_row
obj = {}
Qualificationother.objects.all().delete()
Qualification.objects.all().delete()
while i<max_row+1:
sszx = sheet['b'+str(i)].value
cma = sheet['c'+str(i)].value
@ -323,16 +327,20 @@ def import_qualification(path):
name = sheet['e'+str(i)].value
description = sheet['f'+str(i)].value
if sszx:
if Qualification.objects.filter(sszx=sszx).exists():
qualification = Qualification.objects.get(sszx=sszx)
if Organization.objects.filter(name=sszx).exists():
ssbm=Organization.objects.get(name=sszx)
if Qualification.objects.filter(ssbm=ssbm).exists():
qualification = Qualification.objects.get(ssbm=ssbm)
Qualificationother.objects.create(qualification=qualification, name=name, description=description)
else:
qualification = Qualification.objects.create(sszx=sszx)
qualification = Qualification.objects.create(ssbm=ssbm)
qualification.cma = cma
qualification.cnas = cnas
qualification.service = service
qualification.save()
obj = qualification
Qualificationother.objects.create(qualification=qualification, name=name, description=description)
else:
Qualificationother.objects.create(qualification=obj, name=name, description=description)
i = i + 1

View File

@ -19,6 +19,7 @@ from rest_framework.views import APIView
from rest_framework.viewsets import GenericViewSet, ModelViewSet
from rest_framework_simplejwt.tokens import RefreshToken
from utils.queryset import get_child_queryset2
from django.db.models import Count
from .filters import UserFilter
from .models import (Dict, DictType, File, Message, Organization, Permission,
@ -185,7 +186,20 @@ class OrganizationViewSet(ModelViewSet):
search_fields = ['name']
ordering_fields = ['sort']
ordering = ['sort', 'pk']
@action(methods=['get'], detail=False,url_name='organization_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 RoleViewSet(ModelViewSet):
"""

View File

@ -1,6 +1,16 @@
from rest_framework.pagination import PageNumberPagination
from rest_framework.exceptions import ParseError
class MyPagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'
class PageOrNot:
def paginate_queryset(self, queryset):
if (self.paginator is None):
return None
elif self.request.query_params.get('pageoff', None) and self.get_queryset().count()<500:
return None
elif self.request.query_params.get('pageoff', None) and self.get_queryset().count()>=500:
return ParseError('单次请求数据量大,请求中止')
return self.paginator.paginate_queryset(queryset, self.request, view=self)