search group

This commit is contained in:
caoqianming 2020-06-09 11:55:12 +08:00
parent 1661f3deeb
commit c60ee7cd58
3 changed files with 65 additions and 12 deletions

View File

@ -7,6 +7,14 @@ export function getCMAList(query) {
params: query params: query
}) })
} }
export function getCMAGroup(query) {
return request({
url: '/ability/cma/group/',
method: 'get',
params: query
})
}
export function getCNASList(query) { export function getCNASList(query) {
return request({ return request({
url: '/ability/cnas/', url: '/ability/cnas/',

View File

@ -76,6 +76,8 @@
stripe stripe
highlight-current-row highlight-current-row
max-height="260" max-height="260"
ref="filterTable"
@filter-change="filterChange"
> >
<el-table-column type="index" width="50" /> <el-table-column type="index" width="50" />
<el-table-column align="center" label="大类名称"> <el-table-column align="center" label="大类名称">
@ -96,7 +98,12 @@
<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="所属中心"> <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> <template slot-scope="scope">{{ scope.row.sszx }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="限制范围"> <el-table-column align="header-center" label="限制范围">
@ -139,6 +146,7 @@
stripe stripe
highlight-current-row highlight-current-row
max-height="260" max-height="260"
> >
<el-table-column type="index" width="50" /> <el-table-column type="index" width="50" />
<el-table-column align="header-center" label="类别名称"> <el-table-column align="header-center" label="类别名称">
@ -153,7 +161,8 @@
<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="所属中心"> <el-table-column align="header-center" label="所属中心"
>
<template slot-scope="scope">{{ scope.row.sszx }}</template> <template slot-scope="scope">{{ scope.row.sszx }}</template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="操作"> <el-table-column align="center" label="操作">
@ -201,7 +210,7 @@
</div> </div>
</template> </template>
<script> <script>
import { getCMAList, createCMA, deleteCMA, updateCMA, importCMA, getCNASList, importCNAS } 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"
import { upUrl, upHeaders } from "@/api/file" import { upUrl, upHeaders } from "@/api/file"
import Pagination from "@/components/Pagination" // secondary package based on el-pagination import Pagination from "@/components/Pagination" // secondary package based on el-pagination
@ -211,6 +220,10 @@ const defaultCMA = {
dlmc:null, dlmc:null,
}; };
const dflistQuery = {
page: 1,
page_size: 20,
}
export default { export default {
components: { Pagination }, components: { Pagination },
data() { data() {
@ -218,13 +231,12 @@ export default {
cma: defaultCMA, cma: defaultCMA,
upHeaders: upHeaders(), upHeaders: upHeaders(),
upUrl: upUrl(), upUrl: upUrl(),
groupBy:{sszx:[]},
cmaList: {count:0}, cmaList: {count:0},
cnasList: {count:0}, cnasList: {count:0},
listLoading: true, listLoading: true,
listQuery: { listLoading2:false,
page: 1, listQuery: Object.assign({}, dflistQuery),
page_size: 20
},
listQuery2: { listQuery2: {
page: 1, page: 1,
page_size: 20 page_size: 20
@ -244,6 +256,7 @@ export default {
}, },
created() { created() {
this.getList() this.getList()
this.getGroup()
this.getList2() this.getList2()
}, },
methods: { methods: {
@ -281,6 +294,15 @@ export default {
this.listLoading = false 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
})
}
},
getList2() { getList2() {
this.listLoading2 = true; this.listLoading2 = true;
getCNASList(this.listQuery2).then(response => { getCNASList(this.listQuery2).then(response => {
@ -291,16 +313,14 @@ export default {
}) })
}, },
resetFilter() { resetFilter() {
this.listQuery = { this.listQuery = Object.assign({}, dflistQuery),
page: 1,
page_size: 20
}
this.listQuery2 = { this.listQuery2 = {
page: 1, page: 1,
page_size: 20 page_size: 20
} }
this.getList() this.getList()
this.getList2() this.getList2()
this.getGroup()
}, },
handleFilter() { handleFilter() {
this.listQuery.page = 1 this.listQuery.page = 1
@ -308,6 +328,7 @@ export default {
this.listQuery2.page = 1 this.listQuery2.page = 1
this.listQuery2.search = this.listQuery.search this.listQuery2.search = this.listQuery.search
this.getList2() this.getList2()
this.getGroup()
}, },
handleAdd() { handleAdd() {
this.cma = Object.assign({}, defaultCMA) this.cma = Object.assign({}, defaultCMA)
@ -343,6 +364,13 @@ export default {
console.error(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) { async confirm(form) {
this.$refs[form].validate(valid => { this.$refs[form].validate(valid => {
if (valid) { if (valid) {

View File

@ -9,6 +9,7 @@ from rest_framework.response import Response
import zipfile import zipfile
import rarfile import rarfile
from openpyxl import Workbook, load_workbook from openpyxl import Workbook, load_workbook
from django.db.models import Count
# Create your views here. # Create your views here.
class CMAViewSet(ModelViewSet): class CMAViewSet(ModelViewSet):
""" """
@ -19,9 +20,24 @@ class CMAViewSet(ModelViewSet):
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']
filterset_fields = ['sszx']
ordering_fields = ['xmxh'] ordering_fields = ['xmxh']
ordering = 'xmxh' ordering = 'xmxh'
@action(methods=['get'], detail=False,url_name='cma_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:
ret.append({'text':i[group_by]+'('+str(i['count'])+')','value':i[group_by]})
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'})
def cma_import(self, request, pk=None): def cma_import(self, request, pk=None):
""" """
@ -42,7 +58,8 @@ class CMAViewSet(ModelViewSet):
for f in files: for f in files:
import_cma(f, os.path.join(root,f)) import_cma(f, os.path.join(root,f))
return Response(status = status.HTTP_200_OK) return Response(status = status.HTTP_200_OK)
class CNASViewSet(ModelViewSet): class CNASViewSet(ModelViewSet):
""" """
CNAS检测能力增删改查 CNAS检测能力增删改查