gaoshp
2025-08-13 96258d844aa1a8dfa62a77aaa33d3ff9b953d36f
src/views/flow/components/TodolistLeft.vue
@@ -1,53 +1,100 @@
<!--
 * @Date: 2025-07-01 20:45:15
 * @LastEditors: gaoshp
 * @LastEditTime: 2025-07-07 19:41:56
 * @LastEditTime: 2025-08-13 22:56:43
 * @FilePath: /mdmweb/src/views/flow/components/TodolistLeft.vue
-->
<template>
    <basic-container>
        <div class="tool" v-show="row.taskDefinitionKey === 'programmingTask'">
            <el-button type="primary" @click="addApp">添加程序</el-button>
        <div class="tool" v-show="['programmingTask','cureProgramTask','repalceProgrammingTask'].includes(row.taskDefinitionKey)">
             <el-button type="primary" plain @click="addApp">添加文件
                </el-button>
        </div>
        <el-table :data="tableData" border @row-click="showContent">
            <el-table-column prop="machineCode" label="加工机床">
            </el-table-column>
        <el-table :data="tableData" border @row-click="showContent" max-height="200">
            <!-- <el-table-column prop="machineCode" label="加工机床">
            </el-table-column> -->
         <el-table-column type="index" label="#" width="40" align="center"/>
            <el-table-column prop="name" label="程序名称">
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="100">
            <template #default="scope" v-show="row.taskDefinitionKey === 'programmingTask'">
                <el-button type="text" size="small" @click.stop="del(scope.$index,scope.row)">删除</el-button>
            <el-table-column fixed="right" label="操作" width="150" align="center">
            <template #default="scope" >
                <el-button v-show="['programmingTask','cureProgramTask','repalceProgrammingTask'].includes(row.taskDefinitionKey)" type="text" size="small" @click.stop="del(scope.$index,scope.row)">删除</el-button>
                <el-button type="text" size="small" @click.stop="downloadFile(scope.$index,scope.row)">下载</el-button>
            </template>
            </el-table-column>
        </el-table>
        <h4>程序内容</h4>
        <div v-html="appContent" class="app-content">
        </div>
        <el-dialog title="程序选择" v-model="appDialog" width="50%" v-if="appDialog">
            <avue-crud :option="optionApp" v-model="form" v-model:page="page" ref="crud" :data="appData"
                @current-change="currentChange" @size-change="sizeChange"
                @on-load="onLoad" @selection-change="selectionChange">
                <template #search="{ }"></template>
                <template #search-menu="{ }"></template>
            </avue-crud>
            <div slot="footer" class="dialog-footer">
        <el-dialog title="程序选择" v-model="appDialog" width="400" v-if="appDialog">
            <avue-form :option="attOption"
             v-model="attForm"
             :upload-after="uploadAfter" class="att-box"></avue-form>
            <!-- <div slot="footer" class="dialog-footer">
                <el-button @click="appDialog = false">取 消</el-button>
                <el-button type="primary" @click="add">确 定</el-button>
            </div>
            </div> -->
        </el-dialog>
    </basic-container>
</template>
<script>
import { getAppList,getSelectedAppList,getContent } from '@/api/flow/todolist';
import { getAppList,getSelectedAppList,getContent,removeAtt} from '@/api/flow/todolist';
import { exportBlob } from '@/api/common';
import { getToken } from '@/utils/auth';
import NProgress from 'nprogress';
import { downloadXls } from '@/utils/util';
export default {
    props: {
        row: {
            type: Object,
        }
    },
    watch: {
        'attForm.fileType': {
            handler(newVal) {
                this.attOption.column[1].data.fileType = newVal;
            },
            immediate: true,
        },
    },
    data() {
        return {
            showContentId: '',
            attForm: {
                att: '',
                fileType: 'program'
            }, //程序上传表单
            attOption: {
                submitBtn: false,
                emptyBtn: false,
                menu: false,
                column: [
                    {
                        label: '文件类型',
                        prop: 'fileType',
                        type: 'select',
                        span: 24,
                        clearable: false,
                        dicData: [
                            { label: '程序文件', value: 'program' },
                            { label: '其他文件', value: 'other' },
                        ],
                    },
                    {
                        label: '添加文件',
                        prop: 'att',
                        type: 'upload',
                        multiple: true,
                        action: '/api/blade-mdm/flow/mgr/ncupload',
                        span: 24,
                        data: {
                            processInstanceId: this.row.processInstanceId,
                            fileType: 'program',
                        },
                    }
                ]
            }, //程序上传
            tableData: [],//已选程序
            appContent: '',//程序内容
            appDialog: false,
@@ -85,28 +132,44 @@
                        label: '程序名称',
                        prop: 'name',
                    },
                    {
                        label: '工序名称',
                        prop: 'processName',
                    },
                    // {
                    //     label: '工序名称',
                    //     prop: 'processName',
                    // },
                ],
            },
        }
    },
    mounted() {
        console.log(this.row,'row')
        getSelectedAppList(this.row.processInstanceId).then(res => {
            if (res.data.code !== 200) {
                this.$message.error('获取已选程序失败');
                return;
            } else {
                this.appData = res.data
            }
            this.$emit('selection-change',this.tableData)
        })
        this.getAttList();
        this.onLoad(this.page);
    },
    methods: {
        uploadAfter(res, done, loading, column) {
            if (res.code === 200) {
                this.getAttList();
                this.$message.success(res.msg || '上传成功');
                this.attForm.att = '';
                this.attForm.fileType = 'program'
                this.appDialog = false
                return done();
            } else {
                console.log(res)
                this.$message.warning(res.msg || '上传失败');
                done()
            }
        },
        getAttList () {
            getSelectedAppList(this.row.processInstanceId).then(res => {
                if (res.data.code !== 200) {
                    this.$message.error('获取已选程序失败');
                    return;
                } else {
                    this.tableData = res.data.data || [];
                }
                // this.$emit('selection-change',this.tableData)
            })
        },
        addApp() {
            this.appDialog = true;
        },
@@ -136,6 +199,11 @@
            this.$emit('selection-change',this.tableData)
        },
        showContent (row, column, event) {
            if(!row?.id) {
                this.showContentId = ''
                return this.appContent = '';
            }
            this.showContentId = row.id
            getContent(row.id).then(res => {
                if(res.data.code === 200) {
                    this.appContent = res.data.data
@@ -145,8 +213,31 @@
            })
        },
        del (index,row) {
            this.tableData = this.tableData.filter(item => item.id !== row.id);
            this.$emit('selection-change',this.tableData)
            if(row.id === this.showContentId) {
                this.showContentId = '';
                this.showContent(null, null, null);
            }
            removeAtt(row.id).then(res => {
                if(res.data.code === 200) {
                    this.$message.success('删除成功');
                    this.getAttList();
                } else {
                    this.$message.error('删除失败');
                }
            })
        },
        downloadFile(index,row) {
            NProgress.start();
            exportBlob(
                `/blade-mdm/flow/mgr/down-flow-file?id=${row.id}`
            ).then(res => {
                console.log(res)
                if(res.status !== 200) {
                    return this.$message.error(res.msg);
                }
                downloadXls(res.data, `${row.name}`);
                NProgress.done();
            });
        }
    },
}
@@ -163,7 +254,21 @@
}
.app-content {
    background-color: #fffee1;
    padding: 10px;
    padding: 10px 30px;
    min-height: 100px;
    overflow: auto;
    max-height: 400px;
    white-space: pre-wrap;
}
</style>
<style lang="scss">
    .att-box {
        .el-form-item--default {
            margin-bottom: 0;
        }
        .avue-form__menu--center {
            display: none;
        }
    }
</style>