增加追加任务

This commit is contained in:
caoqianming 2021-03-31 16:50:47 +08:00
parent 6cffb4bf26
commit 3cfd346873
3 changed files with 76 additions and 5 deletions

View File

@ -48,6 +48,13 @@ export function inittask(id, data) {
})
}
export function appendtask(id, data) {
return request({
url: `/supervision/task/${id}/append/`,
method: 'post',
data
})
}
export function gettaskcontents(id) {
return request({

View File

@ -74,6 +74,13 @@
size="small"
>初始化任务</el-button
>
<el-button
type="primary"
@click="append()"
v-if="task.state == '执行中'"
size="small"
>追加任务</el-button
>
<el-button
type="primary"
@click="starttask()"
@ -258,7 +265,7 @@
</el-card>
<el-dialog
:visible.sync="dialogVisible"
title="初始化任务"
:title="dgaction.name"
:close-on-click-modal="false"
width="70%"
>
@ -298,7 +305,7 @@
}
</style>
<script>
import { gettask, inittask, gettaskdeptall, starttask } from "@/api/task";
import { gettask, inittask, gettaskdeptall, starttask, appendtask } from "@/api/task";
import { getRecordList, updateRecords } from "@/api/record";
import Pagination from "@/components/Pagination";
import taskinit from "@/views/supervision/taskinit";
@ -322,7 +329,11 @@ export default {
data: {},
taskdeptall: [],
listQuery:{},
selectRecords:[]
selectRecords:[],
dgaction:{
action:'init',
name:'初始化任务'
}
};
},
created() {
@ -352,16 +363,37 @@ export default {
});
},
init() {
this.dgaction ={
action:'init',
name:'初始化任务'
}
this.dialogVisible = true;
},
append() {
this.dgaction ={
action:'append',
name:'追加任务'
}
this.dialogVisible = true;
},
chooseComplete(data) {
this.dialogVisible = false;
if(this.dgaction.action == 'init'){
const rLoading = this.openLoading("正在初始化任务,请稍等...");
inittask(this.task.id, data).then((res) => {
rLoading.close();
this.$message.success("成功");
this.$router.go(0);
});
}).catch(e=>{rLoading.close();});
}else if(this.dgaction.action == 'append'){
const rLoading = this.openLoading("正在追加任务,请稍等...");
appendtask(this.task.id, data).then((res) => {
rLoading.close();
this.$message.success("成功");
this.$router.go(0);
}).catch(e=>{rLoading.close();});
}
},
starttask() {
this.$confirm("确认发布任务吗?", "提示")

View File

@ -91,6 +91,38 @@ class TaskViewSet(CreateUpdateCustomMixin, ModelViewSet):
return Response(status=status.HTTP_200_OK)
return Response('单位或清单不能为空', status=status.HTTP_400_BAD_REQUEST)
@action(methods=['post'], detail=True, perms_map = {'post':'task_append'})
def append(self, request, *args, **kwargs):
"""
追加任务,生成记录
"""
obj = self.get_object()
depts = request.data['depts']
contents = request.data['contents']
if obj.state !='执行中':
return Response('任务状态错误', status=status.HTTP_400_BAD_REQUEST)
if depts and contents:
for m in depts:
m = Organization.objects.get(pk=m)
TaskDept.objects.get_or_create(task=obj, dept=m, defaults={'task':obj, 'dept':m})
for n in contents:
n = Content.objects.get(pk=n)
if not Record.objects.filter(belong_dept=m, content=n, task=obj).exists():
r = Record()
r.content = n
r.content_name = n.name
r.content_desc = n.desc
r.belong_dept = m
r.task = obj
r.end_date = obj.end_date
r.create_by = request.user
r.state = '待上报'
r.save()
obj.save()
return Response(status=status.HTTP_200_OK)
return Response('单位或清单不能为空', status=status.HTTP_400_BAD_REQUEST)
@action(methods=['get'], detail=True, perms_map = {'get':'*'})
def contents(self, request, *args, **kwargs):
"""