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
})
}
export function getCMAGroup(query) {
return request({
url: '/ability/cma/group/',
method: 'get',
params: query
})
}
export function getCNASList(query) {
return request({
url: '/ability/cnas/',

View File

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

View File

@ -9,6 +9,7 @@ from rest_framework.response import Response
import zipfile
import rarfile
from openpyxl import Workbook, load_workbook
from django.db.models import Count
# Create your views here.
class CMAViewSet(ModelViewSet):
"""
@ -19,9 +20,24 @@ class CMAViewSet(ModelViewSet):
queryset = CMA.objects.all()
serializer_class = CMASerializer
search_fields = ['bzbh', 'bzmc', 'sszx', 'xmmc']
filterset_fields = ['sszx']
ordering_fields = ['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'})
def cma_import(self, request, pk=None):
"""
@ -43,6 +59,7 @@ class CMAViewSet(ModelViewSet):
import_cma(f, os.path.join(root,f))
return Response(status = status.HTTP_200_OK)
class CNASViewSet(ModelViewSet):
"""
CNAS检测能力增删改查