yangys
2025-08-16 bbba8ba895b5e0f5bad0db31fd80f75be184206e
src/views/flow/todolist.vue
@@ -2,42 +2,76 @@
    <basic-container>
        <avue-crud :option="option" :table-loading="loading" :data="data" v-model:page="page" v-model="form" ref="crud"
            @search-change="searchChange" @search-reset="searchReset" @current-change="currentChange"
            @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
            @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad"
            @selection-change="selectionTransferTask">
            <template #menu-left>
                <el-button type="primary" plain @click="reassign">重新指派
                <el-button type="primary" plain @click="reassign(0)">重新指派</el-button>
                <el-button type="primary" v-if="permission.manual_dispatch" plain @click="reassign(1)">手动派工
                </el-button>
                <el-button type="primary" v-if="permission.auto_dispatch" plain @click="reassign(2)">自动派工
                </el-button>
                <el-button type="primary" v-if="permission.batch_approve" plain @click="reassign(3)">批量审批
                </el-button>
            </template>
            <template #menu="scope">
                <el-button type="primary" text size="default" v-if="permission.flow_model_update"
                    @click.stop="handleAction(scope.row, scope.index)">审批
                <el-button type="primary" text size="default" @click.stop="handleAction(scope.row, scope.index)">
                    {{scope.row.taskDefinitionKey === 'teamLeaderTask' ? '派工' : '审批'}}
                </el-button>
            </template>
        </avue-crud>
        <el-dialog title="审批" append-to-body v-model="approveBox" width="20%">
            <avue-form ref="form" :option="optionApprove" v-model="formApprove" @submit="handleSubmit" />
            <!-- <template #footer>
                <span class="dialog-footer">
                    <el-button @click="deployBox = false">取 消</el-button>
                    <el-button type="primary" @click="handleDoDeploy" :loading="deployLoading">确 定</el-button>
                </span>
            </template> -->
        <el-dialog title=" " append-to-body v-model="reassignBox" width="30%">
            <avue-form ref="reassginform" :option="reassignOption" v-model="reassignForm" @submit="toPerson"></avue-form>
        </el-dialog>
        <el-drawer title="审批" append-to-body v-model="approveBox" size="100%" v-if="approveBox">
            <div class="approve-box">
                <div class="left">
                    <TodolistLeft :row="row" @selection-change="selectionChange" />
                </div>
                <div class="right">
                    <TodolistRightTop :row="row" />
                    <el-tabs
                        type="card"
                        class="demo-tabs"
                        v-model="activeName"
                    >
                        <el-tab-pane label="审批" name="approve">
                            <avue-form ref="form" :option="optionApprove" v-model="formApprove" @submit="handleSubmit" />
                        </el-tab-pane>
                        <el-tab-pane label="流程轨迹" name="log">
                            <processTrace :item="row" v-if="activeName==='log'"></processTrace>
                        </el-tab-pane>
                    </el-tabs>
                </div>
            </div>
        </el-drawer>
    </basic-container>
</template>
<script>
import { getList, approve,getAssignee } from '@/api/flow/todolist';
import { getList, approve, getAssignee,reassgin,manualDispatch,autoDispatch,getPrevius,batchApprove } from '@/api/flow/todolist';
import { mapGetters } from 'vuex';
import dayjs from 'dayjs';
import TodolistLeft from './components/TodolistLeft.vue';
import TodolistRightTop from './components/TodolistRightTop.vue';
import processTrace from './components/process-trace.vue';
export default {
    components: {
        TodolistLeft,
        TodolistRightTop,
        processTrace
    },
    data() {
        return {
            activeName: 'approve',
            applist: [],
            assigneeData: [],
            row: {},
            approveBox: false,
            formApprove: {
                comment: '',
                approve: '', // 默认同意
                assignee: ''
            },
            optionApprove: {
                labelWidth: 100,
@@ -55,7 +89,7 @@
                        rules: [{ required: true, message: '请选择审批结果', trigger: 'blur' }],
                    },
                    {
                        label: '下一审批用户',
                        label: '发送给',
                        prop: 'assignee',
                        type: 'select',
                        // dicUrl: `/blade-mdm/flow/flow-user-list?deptId=0`,
@@ -64,11 +98,22 @@
                            label: 'name',
                            value: 'id',
                        },
                        display: true,
                        filterable: true,
                        span: 24,
                        disabled: false,
                        dicData: [
                        ],
                        // rules: [{ required: true, message: '请选择下一审批用户', trigger: 'blur' }],
                    },
                    {
                        label: '工序版次',
                        prop: 'processEdition',
                        type: 'input',
                        span: 24,
                        // disabled: true,
                        display: false,// 隐藏显示
                        // rules: [{ required: true, message: '请选择下一审批用户', trigger: 'blur' }],
                    },
                    {
@@ -76,7 +121,20 @@
                        span: 24,
                        prop: 'comment',
                        type: 'textarea',
                        rules: [{ required: true, message: '请输入审批意见', trigger: 'blur' }],
                        // rules: [{ required: true, message: '请输入审批意见', trigger: 'blur' }],
                        rules: [
                            {
                            validator: (rule, value, callback) => {
                                console.log('-------',this.formApprove)
                                if (value === '' && this.formApprove.approve !== 'Y') {
                                    callback(new Error('请输入备注'));
                                } else {
                                    callback();
                                }
                            },
                            trigger: 'blur'
                            }
                        ]
                    },
                ],
            },
@@ -89,6 +147,7 @@
            query: {},
            loading: true,
            option: {
                rowKey: "taskId",
                addBtn: false,
                editBtn: false,
                delBtn: false,
@@ -101,7 +160,7 @@
                // tree: true,
                border: true,
                index: true,
                // selection: true,
                selection: true,
                // viewBtn: true,
                menuWidth: 100,
                dialogClickModal: false,
@@ -124,17 +183,38 @@
                            },
                        ],
                    },
                    {
                        label: '任务名称',
                        prop: 'processDefinitionName',
               {
                        label: '标题',
                        prop: '',
                        width: 100,
                  render: ({ row }) => {
                            return h('p',
                                {
                                    attrs: {},
                                    class: {},
                                    style: {},
                                }, row?.variables?.title)
                        }
                    },
                    {
                        label: '流程名称',
                        prop: '',
                        width: 100,
                  render: ({ row }) => {
                            return h('p',
                                {
                                    attrs: {},
                                    class: {},
                                    style: {},
                                }, row?.variables?.myProcessName)
                        }
                    },/*
                    {
                        label: '流程类型',
                        width: 100,
                        prop: 'processDefinitionName',
                    },
                        prop: 'categoryName',
                    },*/
                    {
                        label: '机床',
                        width: 100,
@@ -161,6 +241,24 @@
                        // hide: true,
                    },
                    {
                        label: '上一步用户',
                        width: 200,
                        prop: '',
                        formatter: (val, value, label) => {
                            return `${val?.variables?.approveUserNickName || ''}`;
                        },
                    },
                    {
                        label: '当前节点',
                        width: 200,
                        prop: 'taskName',
                    },
                    {
                        label: '文件',
                        width: 200,
                        prop: 'file',
                    },
                    {
                        label: '到达时间',
                        width: 200,
                        prop: 'createTime',
@@ -170,19 +268,57 @@
                        width: 200,
                        prop: 'comment',
                    },
                    {
                        label: '文件',
                        width: 200,
                        prop: '',
                    },
                    {
                        label: '当前节点',
                        prop: 'taskName',
                    },
                ],
            },
            data: [],
            transferTaskSelection: [],
            reassignBox: false,
            reassignType: 0, // 0:重新指派,1:自动派工 2: 自动派工
            reassignOption: {
                submitBtn: true,
                emptyBtn: false,
                column: [
                    {
                        label: '审批结果',
                        prop: 'approve',
                        type: 'radio',
                        span: 24,
                        display: false,
                        dicData: [
                            { label: '通过', value: 'Y' },
                            { label: '驳回', value: 'N' },
                        ],
                        rules: [{ required: true, message: '请选择审批结果', trigger: 'blur' }],
                    },
                    {
                        label: '发送给',
                        prop: 'newAssigneeId',
                        type: 'select',
                        // dicUrl: `/blade-mdm/flow/flow-user-list?deptId=0`,
                        // dicFlag: true,
                        props: {
                            label: 'name',
                            value: 'id',
                        },
                        span: 24,
                        disabled: false,
                        display: true,
                        dicData: [
                        ],
                        rules: [{ required: true, message: '请输入选择', trigger: 'blur' }],
                    },
                    {
                        label: '备注',
                        span: 24,
                        prop: 'comment',
                        type: 'textarea',
                        // rules: [{ required: true, message: '请输入审批意见', trigger: 'blur' }],
                    },
                ],
            },
            reassignForm: {}
        };
    },
    watch: {
@@ -198,68 +334,325 @@
        //     });
        // },
        'formApprove.approve'(val) {
            if (val === 'Y' && this.row.taskDefinitionKey === 'approveTask') {
                this.optionApprove.column[1].disabled = true;
                this.formApprove.assignee = ''; // 如果是通过,则默认指派给自己
            } else {
                this.optionApprove.column[1].disabled = false;
            }
            this.setAssignee(this.row, val);
            // if(val === 'Y' && ['confirmIsUseableTask'].includes(this.row.taskDefinitionKey) && this.row.variables.isProcessEditionSame=='N') {
            //     // this.optionApprove.column[2].display = true; // 显示工序版次
            // } else {
            //     this.optionApprove.column[2].display = false; // 隐藏工序版次
            // }
        },
        'reassignForm.approve'(val) {
            if(this.reassignType ===3) {
                if(val === 'Y') {
                    this.reassignOption.column[1].disabled = true;
                    this.reassignOption.column[1].display = false;
                    this.reassignForm.newAssigneeId = '';
                } else {
                    this.reassignOption.column[1].display = false;
                    this.reassignOption.column[1].disabled = false;
                    this.reassignForm.newAssigneeId = '';
                }
            }
        }
    },
    computed: {
        ...mapGetters(['userInfo', 'permission']),
        // permissionList() {
        //     return {
        //         addBtn: this.validData(this.permission.menu_add, false),
        //         viewBtn: this.validData(this.permission.menu_view, false),
        //         delBtn: this.validData(this.permission.menu_delete, false),
        //         editBtn: this.validData(this.permission.menu_edit, false),
        //     };
        // },
        permissionList() {
            return {
                manual_dispatch: this.validData(this.permission.manual_dispatch, false),
                auto_dispatch: this.validData(this.permission.auto_dispatch, false),
                batch_approve: this.validData(this.permission.batch_approve, true),
            };
        },
    },
    mounted() {
        getAssignee().then(res=> {
        getAssignee().then(res => {
            this.assigneeData = res.data.data;
            this.optionApprove.column[1].dicData = this.assigneeData;
            this.reassignOption.column[1].dicData = this.assigneeData;
        })
        this.setApproveBtn()
    },
    methods: {
        // 设置审批结果的状态
        setApproveBtn () {
            // 1.审批界面radio文本修改,普通节点的2个radio文本 通过(approve=Y),不通过(现在的驳回)(approve=N)
            this.optionApprove.column[0].dicData = [
                { label: '通过', value: 'Y' },
                { label: '不通过', value: 'N' },
            ];
            switch (this.row.taskDefinitionKey) {
                case 'teamLeaderTask': // 任务派工
                case 'cureProgramTask': // 固化编制
                    this.optionApprove.column[0].dicData = [
                        { label: '通过', value: 'Y' },
                        { label: '结束', value: 'N' },
                    ];
                    break;
                case 'confirmIsUseableTask': // 检查程序是否可用
                    this.optionApprove.column[0].dicData = [
                        { label: '通过', value: 'Y' },
                        { label: '不通过', value: 'N' },
                        { label: '驳回', value: 'R' },
                    ];
                    break;
                case 'seniorApproveTask': // 高师审核
                case 'approveTask': // 高师审核
                default:
                    this.optionApprove.column[0].dicData = [
                        { label: '通过', value: 'Y' },
                        { label: '不通过', value: 'N' },
                    ];
                    break;
            }
        },
        setAssignee (row, approve) {
            if (approve === 'Y') {//审批通过的情况
                this.optionApprove.column[1].disabled = false;
                if (["check", 'cureCheckTask','repalceCheckTask'].includes(row.taskDefinitionKey)) {// 校对节点
                    this.formApprove.assignee = row.variables.senior;
                } else if (["programmingTask",'cureProgramTask','repalceProgrammingTask'].includes(row.taskDefinitionKey)) {// 编制节点
                    this.formApprove.assignee = row.variables.checker;
                } else if (row.taskDefinitionKey == "teamLeaderTask") {// 任务派工(组长)
                    this.optionApprove.column[1].disabled = false;
                    this.formApprove.assignee = row.variables.programmer
                } else if (row.taskDefinitionKey == "confirmIsUseableTask") {//判断程序是否可用节点,都是发送给校对
                    this.formApprove.assignee = row.variables.checker
                } else if (["approveTask", 'seniorApproveTask','replaceApprove'].includes(row.taskDefinitionKey)) {// 高师审核
                    this.optionApprove.column[1].disabled = true;//最后一个节点"发送给" 禁用
                    this.formApprove.assignee = ''; // 如果是通过流程直接结束
                }
            } else if(approve === 'N'){
                //不通过的情况
                //根据在线文档34行,'发送给'是禁用,但有默认选项
                this.optionApprove.column[1].disabled = true;
                if (["approveTask", 'seniorApproveTask','replaceApprove'].includes(row.taskDefinitionKey)) {
                    //审批节点,上一步是校对
                    this.formApprove.assignee = row.variables.checker;
                }else if(["check", 'cureCheckTask','repalceCheckTask'].includes(row.taskDefinitionKey)){
                    //校对节点,上一步是编程
                    this.formApprove.assignee = row.variables.programmer;
                }else if (["programmingTask"].includes(row.taskDefinitionKey)) {
                    // 编制节点,上一步是组长
                    this.formApprove.assignee = row.variables.teamLeader;
                }else if(["cureProgramTask"].includes(row.taskDefinitionKey)) {
                    //固化编制节点,不通过就结束了,assignee设置=''
                    this.formApprove.assignee = '';
                }else if(["confirmIsUseableTask"].includes(row.taskDefinitionKey)) {
                    //判断是否可用节点,不可用,给编制
                    this.formApprove.assignee = row.variables.programmer;
                }if(['teamLeaderTask'].includes(row.taskDefinitionKey)){
                    this.formApprove.assignee = '';
                }
            }else if(approve === 'R'){
                //驳回,目前只有检查程序是否可用节点
                if(["confirmIsUseableTask"].includes(row.taskDefinitionKey)) {
                    //判断程序是否可用节点,驳回,给组长
                    this.formApprove.assignee = row.variables.teamLeader;
                }
            }
        },
        selectionTransferTask(list) {
            this.transferTaskSelection = list;
        },
        reassign(val) {// 重新指派
            this.reassignType = val;
            if (this.transferTaskSelection.length === 0) {
                this.$message.warning('请选择需要操作的任务');
                return;
            }
            if (this.transferTaskSelection.length > 1 && this.reassignType === 0) {
                this.$message.warning('请选择一条');
                return;
            }
            if(val === 2) {
                this.$confirm('请确认是否进行批量自动派工?', '', {
                    confirmButtonText: this.$t('submitText'),
                    cancelButtonText: this.$t('cancelText'),
                    type: 'warning',
                }).then(() => {
                    autoDispatch({
                        taskIds: this.transferTaskSelection.map(v => v.taskId),
                        processInstanceIds: this.transferTaskSelection.map(v => v.processInstanceId),
                    }).then(res => {
                        if(res.data.code !== 200) {
                            this.$message.error(res.data.msg);
                            return;
                        }
                        this.$message.success('操作成功');
                        this.onLoad(this.page, this.query);
                    }).catch(err => {
                        this.$message.success('操作失败');
                    })
                }).catch(() => {
                    // this.$message.info('已取消操作');
                });
            } else {
                this.reassignBox = true;
                if(val === 3) {//批量审批时 显示通过驳回
                    this.reassignOption.column[0].display = true;
                    this.reassignOption.column[0].dicData[1].label = '不通过';
                    this.reassignForm.approve = 'Y';
                    this.reassignForm.newAssigneeId = '';
                    this.reassignOption.column[1].disabled = true;
                    this.reassignOption.column[1].display = true;
                } else {
                    this.reassignOption.column[0].display = false;
                    this.reassignForm.approve = '';
                }
                if(val ===1) {
                    this.reassignForm.newAssigneeId = this.transferTaskSelection[0].variables.programmer;
                }
            }
        },
        toPerson(form, done) {
            let tip = ''
            this.reassignType === 1 ? tip = '请确认是否手动派工' : this.reassignType === 2 ? tip = '请确认是否自动派工' : tip = '请确认是否重新指派';
            if (this.reassignType === 0) {
                this.$confirm(tip, '', {
                    confirmButtonText: this.$t('submitText'),
                    cancelButtonText: this.$t('cancelText'),
                    type: 'warning',
                }).then((res) => {
                    console.log(res,'>>>>>>')
                    reassgin({
                        ...form,
                        taskId: this.transferTaskSelection[0].taskId,
                        processInstanceId: this.transferTaskSelection[0].processInstanceId,
                    }).then(res => {
                        if(res.data.code !== 200) {
                            this.$message.error(res.data.msg);
                            return;
                        }
                        this.$message.success('操作成功');
                        this.reassignBox = false;
                        this.$refs?.reassginform?.resetForm();
                        this.onLoad(this.page, this.query);
                        done()
                    }).catch(err => {
                        this.$message.error('操作失败');
                        done()
                    })
                }).catch(() => {
                    console.log('>>>>>>')
                    // this.$message.info('已取消操作');
                    done();
                });
            } else if (this.reassignType === 1) {
                this.$confirm(tip, '', {
                    confirmButtonText: this.$t('submitText'),
                    cancelButtonText: this.$t('cancelText'),
                    type: 'warning',
                }).then(() => {
                    manualDispatch({
                        assignee: form.newAssigneeId,
                        comment: form.comment,
                        taskIds: this.transferTaskSelection.map(v => v.taskId),
                        processInstanceIds: this.transferTaskSelection.map(v => v.processInstanceId),
                    }).then(res => {
                        if(res.data.code !== 200) {
                            this.$message.error(res.data.msg);
                            return;
                        }
                        this.$message.success('操作成功');
                        this.reassignBox = false;
                        this.$refs?.reassginform?.resetForm();
                        this.onLoad(this.page, this.query);
                        done()
                    }).catch(err => {
                        console.error(err);
                        done()
                    })
                }).catch(() => {
                    console.log('>>>>>>')
                    // this.$message.info('已取消操作');
                    done();
                });
            } else if (this.reassignType === 3) {
                this.$confirm('确认要进行批量审批吗?', '', {
                    confirmButtonText: this.$t('submitText'),
                    cancelButtonText: this.$t('cancelText'),
                    type: 'warning',
                }).then(() => {
                    batchApprove({
                        assignee: form.newAssigneeId,
                        comment: form.comment,
                        approve: form.approve,
                        taskIds: this.transferTaskSelection.map(v => v.taskId),
                        processInstanceIds: this.transferTaskSelection.map(v => v.processInstanceId),
                    }).then(res => {
                        if(res.data.code !== 200) {
                            this.$message.error(res.data.msg);
                            return;
                        }
                        this.$message.success('操作成功');
                        this.reassignBox = false;
                        this.$refs?.reassginform?.resetForm();
                        this.onLoad(this.page, this.query);
                        done()
                    }).catch(err => {
                        console.error(err);
                        done()
                    })
                }).catch(() => {
                    console.log('>>>>>>')
                    // this.$message.info('已取消操作');
                    done();
                });
            }
        },
        handleAction(row, index) {
            this.formApprove = {
                comment: '',
                approve: '', // 默认同
                approve: 'Y', // 默认同
            }
            this.approveBox = true;
            this.row = row
            if(row.taskDefinitionKey=="check") {
                this.formApprove.assignee = row.variables.senior;
            } else if(row.taskDefinitionKey=="programmingTask") {
                this.formApprove.assignee = row.variables.checker;
            } else if(row.taskDefinitionKey=="teamLeaderTask") {
                this.formApprove.assignee = row.variables.programmer
            } else if(row.taskDefinitionKey=="confirmIsUseableTask") {
                this.formApprove.assignee = row.variables.checker
            } else if(row.taskDefinitionKey=="approveTask") {
            }
            this.setAssignee(row, this.formApprove.approve);
            console.log('handleAction', row, index);
        },
        handleSubmit(form, done) {
            if(this.row.taskDefinitionKey === 'programmingTask') {
                // if(this.applist.length !== 1) {
                //     done();
                //     return this.$message.success('请选择1个程序');
                // }
            }
            approve({
                ...this.formApprove,
                taskId: this.row.taskId,
                processInstanceId: this.row.processInstanceId,
                // programIds: this.row.taskDefinitionKey === 'programmingTask' ? this.applist.map(v => v.id).join(',') : '',
            }).then(res => {
                if(res.data.code !== 200) {
                    this.$message.error(res.data.msg);
                    done();
                    return;
                }
                this.$message.success('审批成功');
                this.approveBox = false;
                this.onLoad(this.page, this.query);
                done();
            }).catch(err => {
                done();
                console.error(err);
            });
        },
        reassign() {// 重新指派
        },
        searchChange(params, done) {
            let data = {}
@@ -279,6 +672,7 @@
                createTimeEnd: params.createTimeEnd,
                keyword: params.keyword || ''
            }
            this.query = data
            this.onLoad(this.page, data);
            done();
        },
@@ -307,7 +701,7 @@
            } catch (error) {
                console.error('日期格式化错误', error);
            }
            this.loading = true;
            getList(page.currentPage, page.pageSize, Object.assign(query, params)).then(res => {
                const data = res.data.data;
@@ -316,8 +710,28 @@
                this.loading = false;
            });
        },
        selectionChange(applist) {
            this.applist = applist
        },
    },
};
</script>
<style></style>
<style scoped="scoped" lang="scss">
.approve-box {
    display: flex;
    &>div {
        border: 1px solid #ccc;
    }
    .left {
        width: 400px;
    }
    .right {
        flex: 1;
        padding: 0 10px;
    }
}
</style>