This commit is contained in:
caoqianming 2020-09-25 17:07:55 +08:00
commit f9717cdbbb
6 changed files with 150 additions and 26 deletions

View File

@ -30,6 +30,13 @@ export function transferCompany(id, data) {
}) })
} }
export function transferCompanys(data) {
return request({
url: `/crm/company/transfers/`,
method: 'put',
data
})
}
export function deleteCompany(id) { export function deleteCompany(id) {
return request({ return request({
url: `/crm/company/${id}/`, url: `/crm/company/${id}/`,

View File

@ -15,7 +15,13 @@
icon="el-icon-refresh-left" icon="el-icon-refresh-left"
@click="resetFilter" @click="resetFilter"
>刷新重置</el-button> >刷新重置</el-button>
<el-button
type="primary"
@click="handleTrans"
v-if="checkPermission(['consumer__transfers'])"
>批量移交</el-button>
</div> </div>
<el-table <el-table
:data="tableData.results" :data="tableData.results"
style="width: 100%;margin-top:10px;" style="width: 100%;margin-top:10px;"
@ -27,9 +33,9 @@
row-key="id" row-key="id"
default-expand-all default-expand-all
:tree-props="{children: 'children', hasChildren: 'hasChildren'}" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
@selection-change="handleSelectionChange"
> >
<el-table-column type="index" width="50"></el-table-column> <el-table-column type="selection" width="50"></el-table-column>
<el-table-column label="单位名称"> <el-table-column label="单位名称">
<template slot-scope="scope">{{ scope.row.name }}</template> <template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column> </el-table-column>
@ -92,7 +98,7 @@
</template> </template>
<script> <script>
import { getCompanyList, createCompany, deleteCompany, updateCompany, transferCompany } from "@/api/crm"; import { getCompanyList, createCompany, deleteCompany, updateCompany, transferCompany, transferCompanys } from "@/api/crm";
import { deepClone } from "@/utils"; import { deepClone } from "@/utils";
import checkPermission from "@/utils/permission"; import checkPermission from "@/utils/permission";
import Pagination from "@/components/Pagination" import Pagination from "@/components/Pagination"
@ -112,6 +118,7 @@ export default {
components: { Pagination }, components: { Pagination },
data() { data() {
return { return {
selects:[],
company: { company: {
id: "", id: "",
name: "", name: "",
@ -236,6 +243,34 @@ export default {
}) })
}).catch(() => { }).catch(() => {
}); });
},
handleSelectionChange(val) {
let selects = [];
for (var i = 0; i < val.length; i++) {
selects.push(val[i].id);
}
this.selects = selects;
},
handleTrans() {
if (this.selects.length) {
this.$prompt('请输入管理员账号以确认将'+this.selects.length + '家企业及其学员转交给他', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
// inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
// inputErrorMessage: ''
}).then(({ value }) => {
transferCompanys({admin:value, companys:this.selects}).then(res=>{
this.$message.success('转交成功!')
this.getList()
})
}).catch(() => {
});
} else {
this.$message({
message: "请先选择",
type: "warning",
});
}
} }
} }
}; };

View File

@ -1,5 +1,37 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<el-card>
<div slot="header" class="clearfix">
<span>单位</span>
</div>
<el-table
:data="tableDatac.results"
style="width: 100%;"
border
fit
v-loading="listLoadingc"
highlight-current-row
height="160"
row-key="id"
@row-click = 'handleCompanyClick'
>
<el-table-column label="单位名称">
<template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column>
</el-table>
<pagination
v-show="tableDatac.count>0"
:total="tableDatac.count"
:page.sync="listQueryc.page"
:limit.sync="listQueryc.limit"
@pagination="getListc"
/>
</el-card>
<el-card style="margin-top:6px">
<div slot="header" class="clearfix">
<span>学员</span>
</div>
<div> <div>
<el-select <el-select
v-if="checkPermission(['admin'])" v-if="checkPermission(['admin'])"
@ -17,7 +49,7 @@
:value="item.id" :value="item.id"
/> />
</el-select> </el-select>
<el-select <!-- <el-select
v-model="listQuery.company" v-model="listQuery.company"
placeholder="所属单位" placeholder="所属单位"
clearable clearable
@ -34,7 +66,7 @@
:label="item.label" :label="item.label"
:value="item.value" :value="item.value"
/> />
</el-select> </el-select> -->
<el-select <el-select
v-model="listQuery.role" v-model="listQuery.role"
placeholder="用户类型" placeholder="用户类型"
@ -90,7 +122,7 @@
type="primary" type="primary"
icon="el-icon-refresh-left" icon="el-icon-refresh-left"
@click="resetFilter" @click="resetFilter"
>刷新重置</el-button> >刷新</el-button>
</div> </div>
<div style="margin-top:10px"> <div style="margin-top:10px">
@ -151,6 +183,7 @@
@change="tableKey=tableKey+1" @change="tableKey=tableKey+1"
>创建信息</el-checkbox> >创建信息</el-checkbox>
</div> </div>
<el-table <el-table
:data="consumerList" :data="consumerList"
style="width: 100%;margin-top:10px;" style="width: 100%;margin-top:10px;"
@ -158,7 +191,7 @@
fit fit
v-loading="listLoading" v-loading="listLoading"
highlight-current-row highlight-current-row
max-height="600" height="400"
@sort-change="changeSort" @sort-change="changeSort"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
> >
@ -235,7 +268,7 @@
:limit.sync="listQuery.limit" :limit.sync="listQuery.limit"
@pagination="getList" @pagination="getList"
/> />
</el-card>
<el-dialog :visible.sync="dialogVisible" :title="dialogType==='edit'?'编辑用户':'新增用户'"> <el-dialog :visible.sync="dialogVisible" :title="dialogType==='edit'?'编辑用户':'新增用户'">
<el-form <el-form
:model="consumer" :model="consumer"
@ -355,7 +388,6 @@ import { getUserList } from "@/api/user";
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import Companychose from "@/views/crm/companychose"; import Companychose from "@/views/crm/companychose";
const defaultConsumer = { const defaultConsumer = {
id: "", id: "",
name: "", name: "",
@ -390,11 +422,18 @@ export default {
consumerList: [], consumerList: [],
total: 0, total: 0,
listLoading: true, listLoading: true,
listLoadingc: false,
listQuery: { listQuery: {
page: 1, page: 1,
limit: 20, limit: 20,
search: "", search: "",
}, },
listQueryc: {
page: 1,
limit: 20,
search: "",
},
tableDatac: {count:0},
enabledOptions: [ enabledOptions: [
{ key: "true", display_name: "已缴" }, { key: "true", display_name: "已缴" },
{ key: "false", display_name: "未缴" }, { key: "false", display_name: "未缴" },
@ -473,7 +512,7 @@ export default {
}, },
created() { created() {
this.getList(); this.getList();
this.getCompanyList(); this.getListc();
this.getSubjectAll(); this.getSubjectAll();
this.getWorkScopeAll(); this.getWorkScopeAll();
this.getConsumerRoleAll(); this.getConsumerRoleAll();
@ -518,20 +557,27 @@ export default {
this.listLoading = false; this.listLoading = false;
}); });
}, },
getCompanyList() { getListc() {
this.treeLoding = true; this.listLoadingc = true;
getCompanyList().then((response) => { getCompanyList(this.listQueryc).then((response) => {
this.companyData = genTree(response.data.results); this.tableDatac = response.data;
this.treeLoding = false; this.listLoadingc = false;
});
},
searchCompany(val) {
this.treeLoding = true;
getCompanyList({ search: val, perm: "all" }).then((response) => {
this.companyData = genTree(response.data.results);
this.treeLoding = false;
}); });
}, },
// getCompanyList() {
// this.treeLoding = true;
// getCompanyList().then((response) => {
// this.companyData = genTree(response.data.results);
// this.treeLoding = false;
// });
// },
// searchCompany(val) {
// this.treeLoding = true;
// getCompanyList({ search: val, perm: "all" }).then((response) => {
// this.companyData = genTree(response.data.results);
// this.treeLoding = false;
// });
// },
getSubjectAll() { getSubjectAll() {
getSubjectAll().then((response) => { getSubjectAll().then((response) => {
this.subjectData = genTree(response.data); this.subjectData = genTree(response.data);
@ -714,8 +760,8 @@ export default {
}, },
getAdminOptions() { getAdminOptions() {
if (checkPermission(["admin"])) { if (checkPermission(["admin"])) {
getUserList().then((res) => { getUserList({pageoff:true}).then((res) => {
this.adminOptions = genTree(res.data.results); this.adminOptions = res.data;
}); });
} }
}, },
@ -729,6 +775,10 @@ export default {
this.consumer.company = val.id; this.consumer.company = val.id;
} }
}, },
handleCompanyClick(row, column, event){
this.listQuery.company = row.id
this.getList()
}
}, },
}; };
</script> </script>

View File

@ -133,6 +133,22 @@ class CompanyViewSet(ModelViewSet):
return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_200_OK)
else: else:
return Response({"error":"账号错误"}) return Response({"error":"账号错误"})
@action(methods=['put'], detail=False, url_name='company_transfers',perms_map=[{'*':'company_transfers'}])
def transfers(self, request, *args, **kwargs):
"""
批量移交
"""
companys = Company.objects.filter(id__in = request.data['companys'])
adminname = request.data.get('admin', None)
if adminname and UserProfile.objects.filter(username=adminname).exists():
adminobj = UserProfile.objects.get(username=adminname)
if companys.exists():
companys.update(create_admin=adminobj)
Consumer.objects.filter(company__in = companys).update(create_admin=adminobj)
return Response(status=status.HTTP_200_OK)
else:
return Response({"error":"账号错误"})
class ConsumerViewSet(ModelViewSet): class ConsumerViewSet(ModelViewSet):
""" """

View File

@ -57,9 +57,9 @@ class UserInfoView(APIView):
from utils.pagination import PageOrNot
class UserViewSet(PageOrNot, ModelViewSet):
class UserViewSet(ModelViewSet):
""" """
用户管理增删改查 用户管理增删改查
""" """

View File

@ -0,0 +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)