<template>
    <div class="flex-box">
        <!-- 头部组件 -->
        <div :span="24" class="flex-header">
            <Tabs :tabList="tabList" @status="clickTabs">
            </Tabs>
            <el-button
                type="primary"
                @click="clickNewTag"
                v-show="lable.name === 'first'"
            >+新建
            </el-button
            >
        </div>
        <div class="flex-count">
            <Table
                @clickDemand="clickDemand"
                :list="lable"
                ref="TableList"
                @num="getNum"
                @changeNum="changeNum"
            >
                <template v-slot:three>
                </template>
            </Table>
        </div>
        <el-dialog
            :title="dialogTitle + '工单'"
            :visible.sync="dialogStatus"
            width="100%"
            :before-close="handleClose"
            :modal="false"
            v-if="dialogStatus"
            :destroy-on-close="true"
        >
            <!-- 后期维护 -->
            <div style="position: fixed; z-index: 10000" v-if="buttonStatus">
                <el-button type="primary" v-if="startStatus" @click="clickHandles"
                >处理
                </el-button
                >
                <el-button type="primary" v-if="closeStatus" @click="handleClose"
                >关闭
                </el-button
                >
                <el-button type="primary" v-if="saveStatus" @click="clickSave"
                >保存
                </el-button
                >
            </div>

            <FormTable
                :list="fromList"
                :disabled="disabled"
                class="flex-form"
                ref="formTable"
            />
            <div>
                <div class="table-title">流程追踪</div>
                <Tableid :list="lables"></Tableid>
            </div>
        </el-dialog>
        <div v-if="destroy">
            <el-dialog
                title="处理操作"
                width="100%"
                :visible.sync="handleStatus"
                :before-close="handleCloses"
                :modal="false"
                v-if="handleStatus"
                :destroy-on-close="true"
            >
                <Workflow
                    :list="fromList"
                    @updateForm="beforeClose"
                    v-if="isWorkflowStatus == true"
                    :requestForm="requestForm"
                />
                <WorkflowEntrance :list="fromList" v-else :lastManList="lastManList" @beforeClose="beforeClose"
                                  :requestForm="requestForm" />
                <!-- 后期维护 -->
            </el-dialog>
        </div>

    </div>
</template>

<script>
    import Workflow from "../../../components/workflowBase";
    import FormTable from "./formTable.vue";
    import Seach from "../../../components/el-search.vue";
    import Tabs from "../../../components/el-tabs.vue";
    import Table from "../../../components/el-form";
    import Tableid from "../../../components/el-formid";
    import WorkflowEntrance from "../../../components/workflowEntrance";

    import {
        getTodoBase,
        getDoneBase,
        getInitiateBase,
    } from "../../../http/api.js";

    export default {
        components: {
            Tabs,
            Table,
            Tableid,
            Seach,
            FormTable,
            Workflow,
            WorkflowEntrance
        },
        data() {
            return {
                tableName: "scsjdc_pro_process",
                buttonStatus: true,
                copyStatus: false,
                dialogTitle: "",
                disabled: false,
                destroy: false,
                //分页数据
                totalPage: "1", //默认第一页
                currentPage: "1", //当前页数
                pageSize: "10", //每页显示十条
                currentPageList: ["1", "2"],
                startStatus: true,
                closeStatus: true, //关闭按钮状态
                forwardStatus: false, //转需求管理平台状态
                exportBtnStatus: false, //导出按钮状态
                saveStatus: false, //保存按钮状态
                fromList: {}, //表单数据
                lastManList: [],
                isWorkflowStatus: true, //默认展示模式组件，为true时展示多人处理组件
                rejectStatus: true,
                taskId: "", //工单taskID
                treeUser: {},
                formId: "",
                fileId: "", //工作流开启Id
                request_form: {
                    userId: "",
                    userName: "",
                    path: this.$router.currentRoute.name,
                    userCode: JSON.parse(window.sessionStorage.userInfo).loginNo,
                    // path:this.$roter.options.routers,
                    // nextDealMan:'',
                    title: "title",
                    businessKey: "",
                    processDefinitionKey: "scsjdc_pro_process",
                },
                requestForm: {
                    // fresourceId: "ae3564a5-96f2-11ed-be6b-00505687dcd3", // 本地环境
                    fresourceId: "b67ff4ed-c312-11ed-afb6-e00084564cce", // 生产环境
                    // fresourceId: "bf79721c-33f3-11ed-ba0b-00505687dcd3", //测试环境
                    processDefinitionKey: "scsjdc_pro_process",
                },
                treeList: [], //候选人列表
                treeCopyList: [], //抄送人列表
                editStatus: false,
                querryList: [], //已选人员名单
                commonlyList: [
                    //常用意见列表页
                ],
                textarea: "未填写意见",
                num: 0,
                dialogStatus: false, //新建dialog显示
                handleStatus: false, //处理按钮状态
                tabList: [
                    {
                        index: "first",
                        label: "我的待办",
                        number: 0,
                        name: "prosss_key",
                    },
                    {
                        index: "two",
                        label: "我的已办",
                        number: 0,
                    },
                    {
                        index: "three",
                        label: "我发起的",
                        number: 0,
                    }
                ],//上层跳转已发起已办等
                todoBase: {
                    name: "first",
                    height: "650",
                    titledata: [
                        {
                            label: "文件标题",
                            prop: "need_name",
                            width: 300,
                            color: "#0682cd",
                        },
                        {
                            label: "发起部门",
                            prop: "apply_department",
                            width: 200,
                        },
                        {
                            label: "发起科室",
                            prop: "apply_office",
                            width: 200,
                        },
                        {
                            label: "发起人",
                            prop: "proposer",
                            width: 200,
                        },
                        {
                            label: "发起时间",
                            prop: "proposer_time",
                            width: 250,
                        },
                        {
                            label: "上一步处理人",
                            prop: "predealman",
                            width: 200,
                        },
                        {
                            label: "状态",
                            prop: "taskName",
                            width: 200,
                        },
                    ], //表格头
                    data: [], //内容数据
                    loading: true,
                    pageData: {
                        total: 100, // 总条数
                        pageSize: 10, // 每页数量
                        pageSizes: [10], // 每页数量
                        pageNum: 1, // 页码
                    },
                    isSelection: false, // 表格有多选时设置
                    isOperation: false, // 表格有操作列时设置
                    isIndex: true, // 列表序号
                    operation: {
                        // 表格有操作列时设置
                        label: "操作", // 列名
                        width: "50", // 根据实际情况给宽度
                        data: [
                            {
                                label: "操作", // 操作名称
                                type: "", //按钮类型
                                handleRow: (e, r, o) => {
                                }, // 自定义事件
                            },
                        ],
                    },
                },
                doneBase: {
                    name: "two",
                    disabled: true,
                    titledata: [
                        {
                            label: "文件标题",
                            prop: "need_name",
                            width: 300,
                            color: "#0682CD",
                        },
                        {
                            label: "发起部门",
                            prop: "apply_department",
                            width: 200,
                        },
                        {
                            label: "发起科室",
                            prop: "apply_office",
                            width: 200,
                        },
                        {
                            label: "发起人",
                            prop: "proposer",
                            width: 200,
                        },
                        {
                            label: "发起时间",
                            prop: "proposer_time",
                            width: 250,
                        },
                        {
                            label: "状态",
                            prop: "taskName",
                            width: 200,
                        },
                    ], //表格头
                    data: [], //内容数据
                    loading: true,
                    pageData: {
                        total: 100, // 总条数
                        pageSizes: [10], // 每页数量
                        pageSize: 10, // 每页数量
                        pageNum: 1, // 页码
                    },
                    isSelection: false, // 表格有多选时设置
                    isOperation: false, // 表格有操作列时设置
                    isIndex: true, // 列表序号
                    operation: {
                        // 表格有操作列时设置
                        label: "操作", // 列名
                        width: "50", // 根据实际情况给宽度
                        data: [
                            {
                                label: "操作", // 操作名称
                                type: "", //按钮类型
                                handleRow: function () {
                                }, // 自定义事件
                            },
                        ],
                    },
                },
                meLaunch: {
                    name: "three",
                    titledata: [
                        {
                            label: "文件标题",
                            prop: "need_name",
                            width: 300,
                            color: "#0682CD",
                        },
                        {
                            label: "发起部门",
                            prop: "apply_department",
                            width: 200,
                        },
                        {
                            label: "发起科室",
                            prop: "apply_office",
                            width: 200,
                        },
                        {
                            label: "发起人",
                            prop: "proposer",
                            width: 200,
                        },
                        {
                            label: "发起时间",
                            prop: "proposer_time",
                            width: 250,
                        },
                        {
                            label: "状态",
                            prop: "taskName",
                            width: 200,
                        },
                    ], //表格头
                    data: [], //内容数据
                    loading: true,
                    pageData: {
                        total: 100, // 总条数
                        pageSizes: [10], // 每页数量
                        pageSize: 10, // 每页数量
                        pageNum: 1, // 页码
                    },
                    isSelection: false, // 表格有多选时设置
                    isOperation: false, // 表格有操作列时设置
                    isIndex: true, // 列表序号
                },
                lable: {},//jziyy 页面table列表布局变量
                copyUser: "", //抄送人
                backThree: [],
                backCopyThree: [], //抄送人数组
                lables: {
                    height: "400",
                    titledata: [
                        {
                            label: "环节名称",
                            prop: "taskName",
                            width: 300,
                        },
                        {
                            label: "处理人",
                            prop: "assignee",
                            width: 300,
                        },
                        {
                            label: "到达时间",
                            prop: "startTime",
                            width: 300,
                        },
                        {
                            label: "处理时间",
                            prop: "endTime",
                            width: 300,
                        },
                        {
                            label: "回复意见",
                            prop: "content",
                            width: 300,
                        },
                    ], //表格头
                    data: [], //内容数据
                    loading: true,
                    pageData: {
                        total: 10, // 总条数
                        pageSize: 10, // 每页数量
                        pageSizes: [10], // 每页数量
                        pageNum: 1, // 页码
                    },
                    isSelection: false, // 表格有多选时设置
                    isOperation: false, // 表格有操作列时设置
                    isIndex: true, // 列表序号
                    operation: {
                        // 表格有操作列时设置
                        label: "操作", // 列名
                        width: "50", // 根据实际情况给宽度
                        data: [
                            {
                                label: "操作", // 操作名称
                                type: "", //按钮类型
                                handleRow: function () {
                                }, // 自定义事件
                            },
                        ],
                    },
                },
                formWorkId: "",
                taskName: "", //工单是否为起草阶段
                clicknextName: "", //点击选择流程节点
                firstStatus: false,
                selectUser: "", //选择人userName
                isSync: "1", //什么yes no起草状态判断
                createdId: "", //获取表单创始人Id
                batchList: ["fanyan"], //多选数组
                userList: [
                    //选择路径列表页
                ],
                props: {
                    lazy: true,
                    lazyLoad: this.lazyLoad,
                },
                propsList: [],
                DepartmentName: "",
                seleIndex: 9,
                clickTagName: "first",
                value: "",
                nextPath: [],
                nextPaths: [],
                node: [],
                nodes: [],
                transferStatus: false,
                TransferStatus: false,
                CopyStatus: false,
                initialList: [],
                clickTaskName: "",
                seachLists: {},
                timeList: {},
            };
        },
        created() {

            let status = JSON.stringify(this.$route.query) == "{}";
            if (status) {
                //oa跳转回来显示
                this.getQueryList();
                this.getMeDone();
                this.getMeLaunch();
                this.lable = this.todoBase;

            } else {
                let { id, type } = this.$route.query;
                let list = {
                    taskId: id,
                    tableName: this.tableName
                };
                this.getQueryList(0, list,0);//代办
            }

        },
        methods: {
            //添加面包屑
            setabList(n, p) {
                let params = {
                    children: "",
                    name: n,
                    rountPath: p,
                    target: "_self",
                };
                for (let i = 0; i < this.$store.state.tabList.length; i++) {
                    if (this.$store.state.tabList[i].name === params.name) {
                        this.$store.state.tabList[i] = params;
                    }
                }
                let set = new Set([...this.$store.state.tabList, params]);
                set.add(params);
                this.$store.commit("setDefaultActive", params.rountPath);
                this.$store.commit("setTabList", Array.from(set));
            },
            beforeClose() {
                this.dialogStatus = false;
                this.handleCloses();
                switch (this.clickTagName) {
                    case "first": {
                        this.getMeDone("1");
                        this.getMeLaunch("1");
                        this.getQueryList();
                        break;
                    }
                    case "two": {
                        this.getQueryList("1");
                        this.getMeLaunch("1");
                        this.getMeDone();
                        break;
                    }
                    case "three": {
                        this.getQueryList("1");
                        this.getMeDone("1");
                        this.getMeLaunch();
                        break;
                    }
                }
            },
            //是否最后一个人
            async getLastName() {
                console.log(this.fromList);
                let list = {
                    procinstid: this.fromList.processId,
                    taskid: this.fromList.taskId,

                    // taskId:e.taskId
                };
                let _this = this;
                let obj = {
                    url: this.$url.formList.getLastName, //流程追踪接口
                    data: list,
                    // status: "form",
                    headers: {
                        "Content-Type": "application/json",
                    },
                };

                let res = await this.common.httpPost(obj, success);
                function success(data) {
                    _this.isWorkflowStatus = data.lastMan != false;
                    _this.lastManList = data;
                    // console.log(_this.isWorkflowStatus);
                }
            },
            clickGetTree(e, index) {
                this.CopyStatus = false;
                this.TransferStatus = false;
                this.clickTaskName = e.properties.name;
                this.clicknextName = e.properties.name;
                this.seleIndex = index;
                this.getNextPath(e.resourceId); //1 为点击后获取线
            },
            //常用意见添加
            addStatus() {
                let newData = Date.parse(new Date());
                this.$prompt("请输入常用意见", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                })
                    .then(({value}) => {
                        let list = {
                            dictCode: "approval",
                            dataCode: newData,
                            dataName: value,
                            dictName: "审批意见",
                        };
                        this.geaddctType(list);
                        this.$message({
                            type: "success",
                            message: "常用意见添加成功",
                        });
                    })
                    .catch(() => {
                        this.$message({
                            type: "info",
                            message: "取消输入",
                        });
                    });
            },
            //常用意见删除
            deleStatus(e) {
                this.$confirm("此操作将删除此常用意见, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                })
                    .then(() => {
                        let list = {
                            dataCode: e.dataCode,
                            dictCode: "approval",
                        };
                        this.geDelectType(list);
                        this.$message({
                            type: "success",
                            message: "删除成功!",
                        });
                    })
                    .catch(() => {
                        this.$message({
                            type: "info",
                            message: "已取消删除",
                        });
                    });
            },
            //转需求管理平台
            clickReassignment() {
                this.$http({
                    url: "/market/waf/sync",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: this.$refs.formTable.form,
                }).then((res) => {
                    if (res.code === 0) {
                        this.$message.success("转需求管理平台成功！");
                    } else {
                        this.$message.error("转需求管理平台错误！");
                    }
                });
            },

            //点击工单状态跳转需求流程显示页面  e lab名称  res row对象
            clickDemand(e, res) {
                this.isWorkflowStatus = true
                //点击文件标题才会进行跳转
                if (e === "文件标题") {
                    //代办页面跳转
                    this.dialogTitle = "查看";
                    if (this.clickTagName === "first") {
                        if (res.taskName === "起草") {
                            this.disabled = false;

                            this.startStatus = true;
                            this.closeStatus = true;
                            this.saveStatus = true;
                        } else {
                            //不允许修改列表
                            this.disabled = true;
                            //弹出框表头  dialogTitle + 需求
                            this.startStatus = true;
                            this.closeStatus = true;
                            this.saveStatus = false;
                        }
                    }

                    if (this.clickTagName === "two") {
                        this.disabled = true;

                        this.startStatus = false;
                        this.closeStatus = true;
                        this.saveStatus = false;
                    }
                    if (this.clickTagName === "three") {
                        if (res.taskName === "起草") {
                            this.disabled = false;

                            this.startStatus = true;
                            this.closeStatus = true;
                            this.saveStatus = true;
                        } else {
                            this.disabled = true;

                            this.startStatus = false;
                            this.closeStatus = true;
                            this.saveStatus = false;
                        }
                    }

                    //流程追踪页面展示
                    this.clickForm(res);
                    //会查询单条数据 并且把 页面展示出来
                    this.getFromQuery(res);
                }


            },
            clickExport() {
                let array = [];
                array.push(this.$refs.formTable.form);
                this.downloadExcel(array);
            },
            getNowTime() {
                let date = new Date();
                let year = date.getFullYear(); //获取当前年份
                let mon = date.getMonth() + 1; //获取当前月份
                let da = date.getDate(); //获取当前日
                let h = date.getHours(); //获取小时
                let m = date.getMinutes(); //获取分钟
                return year + "-" + mon + "-" + da + "-" + h + ":" + m;
            },
            //导出方法
            downloadExcel(e) {
                let res = this.getNowTime();
                this.$http({
                    url: "/market/waf/exportAll",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    responseType: "blob",
                    data: e,
                }).then((response) => {
                    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                        let blob = new Blob([response.data.size], {
                            type: "application/vnd.ms-excel;",
                        });
                        if (e.length > 1) {
                            window.navigator.msSaveOrOpenBlob(
                                blob,
                                this.fromList.needName + ".zip"
                            );
                            // window.navigator.msSaveOrOpenBlob(blob, res + "需求申请单" + ".zip");
                        } else {
                            window.navigator.msSaveOrOpenBlob(
                                blob,
                                this.fromList.needName + ".zip"
                            );
                        }
                    } else {
                        /* 火狐谷歌的文件下载方式 */
                        var blob = new Blob([response.data]);
                        var downloadElement = document.createElement("a");
                        var href = window.URL.createObjectURL(blob);
                        downloadElement.href = href;
                        if (e.length > 1) {
                            downloadElement.download = res + "需求申请单" + ".zip";
                        } else {
                            downloadElement.download = e[0].needName + ".zip";
                        }

                        document.body.appendChild(downloadElement);
                        downloadElement.click();
                        document.body.removeChild(downloadElement);
                        window.URL.revokeObjectURL(href);
                    }
                });
            },
            //驳回方法
            clickReject(res) {
                let e = "no";
                this.submitWork(e, res);
            },
            //我发起的接口
            getMeLaunch(e) {
                this.loading = true;
                let list = {...{tableName: this.tableName}, ...e};
                getInitiateBase(this.totalPage, "", list).then((res) => {
                    if (e !== "1"){
                        this.meLaunch.data = res.data.data;
                        this.meLaunch.pageData.total = res.data.totalRecord;
                    }

                    this.tabList[2].number = res.data.totalRecord
                    this.loading = false;
                });
            },
            //按钮权限方法
            getBtnStatus(e) {
                this.$refs.formTable.form = e;
            },
            //我的已办接口
            getMeDone(e) {
                this.loading = true;
                getDoneBase(this.totalPage, "", {tableName: this.tableName,}).then((res) => {
                    if (e !== "1"){
                        this.doneBase.data = res.data.data;
                        this.doneBase.data.map((item) => {
                            item.status = "2";
                        });
                        this.doneBase.pageData.total = res.data.totalRecord;
                    }

                    this.tabList[1].number = res.data.totalRecord
                    this.loading = false;
                });
            },
            isNaNStatus(e) {
                if (e.size === 0) {
                    return "0";
                } else {
                    return e.size;
                }
            },
            //选择树的回调
            changeTree(e) {
                if (e.length > 1) {
                    this.$message.error("只能选择一个人");
                    return;
                } else {
                    this.backThree = e;
                    if (e[0]) {
                        this.selectUser = e[0].loginNameStr;
                    } else {
                        this.selectUser = "暂无选择";
                    }
                }
            },
            changeTreeCopy(e) {
                if (e.length > 1) {
                    this.$message.error("只能选择一个人");
                    return;
                } else {
                    this.backCopyThree = e;
                    if (e[0]) {
                        this.copyUser = e[0].loginNameStr;
                    } else {
                        this.copyUser = "暂无选择";
                    }
                }
            },
            //查询form表单数据
            getFromQuery(e) {
                this.$http({
                    url: "/market/scsjdcProProcess/query",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {id: e.id},
                }).then((res11) => {

                    this.dialogStatus = true;
                    this.fromList.mkFileShareAttachList = res11.data.mkFileShareAttachList;
                    this.taskId = res11.data.taskId;

                    this.fromList = res11.data;
                    this.fromList.createId = e.createId
                    console.log("==========" + this.fromList.createId)
                    this.fromList.resourceId = e.resourceId
                    this.taskId = res11.data.taskId;
                });
            },
            //我发起的搜索内容
            seachList(e) {
                this.seachLists = e;
                this.getMeLaunch(e);
            },
            //点击修改
            clickEdit() {
                this.editStatus = true;
            },
            //点击职位显示右侧列表
            //常用意见点击选择
            clickCommonly(e) {
                this.textarea = e.currentTarget.innerHTML;
            },


            //------------------ jziyy新建按钮
            async clickNewTag() {
                this.dialogTitle = "新建";
                this.lables.data = [];
                this.disabled = false;
                this.isWorkflowStatus = true;
                await this.getDepartmentName();
            },

            //获取用户部门名称
            getDepartmentName() {
                this.$http({
                    url: "/market/scsjdcProProcess/queryAutoInfo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    let list = {
                        phoneNo: res.data.body.phoneNo,
                        proposer: res.data.body.proposer,
                        proposerNo: res.data.body.proposer,
                        applyDepartment: res.data.body.applyDepartment,
                        applyOffice: res.data.body.applyOffice,
                        needNo: res.data.body.needNo,
                        proposerTime: res.data.body.proposerTime,
                        ruleType: "1", //新建按钮跳转过去的
                    };
                    this.fromList = list;

                    //将用户部门科室名称数据发送给新建弹出页
                    if (this.$refs.formTable) {
                        this.$refs.formTable.form = list;
                    }

                    this.dialogStatus = true;
                    this.saveStatus = true;
                });
            },


            //保存接口
            async clickSave() {
                this.$refs.formTable.$refs.form.validate((valid) => {
                    if (valid) {
                        if (this.fromList.id) {
                            this.setUpdateForm(this.$refs.formTable.form);
                        } else {

                            this.$http({
                                url: "/market/api/user/info/queryNodePers?params=" + JSON.parse(window.sessionStorage.userInfo).loginNo,
                                method: "post",
                                headers: {
                                    "Content-Type": "application/json",
                                },
                            }).then((res) => {
                                console.log(res);
                                this.request_form.userName = res.data[0].children[0].loginNameStr;
                                this.request_form.userId = res.data[0].children[0].loginNoStr;
                                this.setForm();
                            });
                        }
                    } else {
                        this.$message.error("请完善表单信息");
                        return false;
                    }
                });
            },

            //保存按钮
            //获取自己idname
            getUserIds() {
                this.$http({
                    url: "/market/api/user/info/queryNodePers?params=" + JSON.parse(window.sessionStorage.userInfo).loginNo,
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                }).then((res) => {
                    console.log(res);
                    this.request_form.userName = res.data[0].children[0].loginNameStr;
                    this.request_form.userId = res.data[0].children[0].loginNoStr;
                });
            },


            setForm(e) {
                this.request_form.title = this.$refs.formTable.form.needName;
                this.$http({
                    url: "/market/scsjdcProProcess/add",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: this.$refs.formTable.form,
                }).then((res) => {
                    this.request_form.businessKey = res.data.body;
                    this.fromList.id = res.data.body;
                    this.formWorkId = res.data.body;
                    this.clickHandle(res.data.body);
                    this.$message.success("保存成功");
                });
            },
            //处理按钮,开始工作流接口
            //处理按钮,开始工作流接口
            clickHandles() {
                this.getNextPath(this.fromList.resourceId || "");
                console.log(this.fromList);
                // if (this.fromList.taskId) {
                //     this.destroy = true;
                //     this.handleStatus = true;
                // } else {
                //     this.$message.error("请先点击保存按钮");
                // }
            },
            getNextPath(e) {
                let list = {
                    // fresourceId: "bf79721c-33f3-11ed-ba0b-00505687dcd3", //测试环境
                    fresourceId: this.requestForm.fresourceId, // 本地环境
                    processId: this.requestForm.processDefinitionKey,
                    // fresourceId: "0d94de8a-0281-11ed-a302-4ae7da54db39", // 本地环境
                    // processId: "request_form_process",
                    // resourceId: e,
                };
                if (e) {
                    // this.propsList = [];
                    list.resourceId = e;
                }
                this.$http({
                    url: "/market/waf/queryPath",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: list,
                }).then((res) => {
                    console.log(res);
                    console.log(res.data.body);
                    console.log(res.data.body.nextShapes[0].multi);
                    if (res.data.body.nextShapes[0].multi) {
                        if (res.data.body.nextShapes[0].multi.multi === "true") {
                            this.getLastName();
                        }
                    }
                    if (this.fromList.taskId) {
                        this.destroy = true;
                        this.handleStatus = true;
                        this.getMetirialType();
                    } else {
                        this.$message.error("请先点击保存按钮");
                    }
                });
            },
            //获取字典表常用意见
            getMetirialType(e) {
                this.$http({
                    url: "/market/cfgDataDict/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        dictCodePks: "approval",
                    },
                }).then((res) => {
                    this.commonlyList = res.data;
                });
            },

            async clickForm(e) {
                let list = {
                    processInstanceId: e.process_id,
                    // taskId:e.taskId
                };
                let _this = this;
                let obj = {
                    url: this.$url.formList.getCommentsByProcessId, //流程追踪接口
                    data: list,
                    headers: {
                        "Content-Type": "application/json",
                    },
                };

                let res = await this.common.httpPost(obj, success);
                function success(data) {
                    console.log('[ 接口返回值第一曾 ] >', data)
                    let list = [];
                    list = data.data.data;
                    if (data.data.lastmandata.length !== 0) {
                        data.data.lastmandata.map((item, index) => {
                            item.id = index + 22;
                        });
                    }

                    list.map((item, index) => {
                        item.startTime = _this.$util.datetimeFormat(item.startTime);
                        item.endTime = _this.$util.datetimeFormat(item.endTime);
                        item.id = index + 1;
                        item.children = [];
                        if (data.data.lastmandata.length != 0) {
                            let indexs = data.data.lastmandata.findIndex((items) => {
                                if (items.taskId == item.taskId) {
                                    item.children.push(items);
                                }
                            });
                        }
                    });
                    console.log(list);
                    _this.lables.data = list;
                    console.log("[ _this.lables.data ] >", _this.lables.data);
                    _this.abc = true;
                }
            },


            async clickHandle(e) {
                let _this = this;
                let obj = {
                    url: this.$url.formList.startWork, //开始工作流接口
                    data: _this.request_form,
                    status: "form",
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded",
                    },
                };

                let res = await this.common.httpPost(obj, success);

                function success(data) {
                    _this.fromList.taskId = data.data;
                    _this.taskId = data.data;
                    let list = {
                        id: e,
                        processId: _this.fromList.taskId,
                        tableName: _this.tableName,
                    };

                    _this.setUpdate(list);
                }
            },

            setUpdateForm(e) {
                this.request_form.title = "[工作台]-省生产数据导出-" + this.$refs.formTable.form.needName;
                // this.$refs.formTable.form.taskId = e;
                this.$http({
                    url: "/market/scsjdcProProcess/update",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: this.$refs.formTable.form,
                }).then((res) => {
                    this.request_form.businessKey = res.data.body;
                    this.fromList.id = res.data.body;
                    this.formWorkId = res.data.body;
                    this.setUpdate(e);
                    this.$message.success("更新成功");
                });
            },
            //更新工作流接口
            setUpdate(e) {

                if (!e.tableName){
                    e.tableName = this.tableName;
                }

                this.$http({
                    url: "/market/waf/updateBase",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: e,
                }).then((res) => {
                    this.fromList.taskId = res.data.body[0].taskId;
                    this.fromList.taskName = res.data.body[0].taskName;
                    this.fromList.processId = res.data.body[0].process_id;
                    if (res.data.result === 0) {
                        this.$message.success("工作流更新成功");
                    }
                })
            },
            //点击查阅接口
            //获取我的代办列表List
            getQueryList(e, currentList, status) {
                getTodoBase(this.totalPage, "", currentList || {tableName: this.tableName}).then((res) => {
                    if (status === 0) {
                        this.clickDemand("文件标题", res.data.data[0]);
                    }
                    this.tabList[0].number = res.data.totalRecord;
                    if (e !== "1") {
                        this.todoBase.data = res.data.data;
                        this.todoBase.pageData.total = res.data.totalRecord;
                        this.lable = this.todoBase;
                    }
                });
            },
            getCurrentPageList(e) {
                this.totalPage = Math.ceil(e.length / this.pageSize);
                this.totalPage = this.totalPage == 0 ? 1 : this.totalPage;
                let begin = (this.currentPage - 1) * this.pageSize;
                let end = this.currentPage * this.pageSize;
                this.currentPageList = e.slice(begin, end);
                return this.currentPageList;
            },
            getNum(e) {
                //多选数组
                this.batchList = e;
                if (e.length > 0) {
                    this.exportStatus = true;
                } else {
                    this.exportStatus = false;
                }
                this.num = e.length;
            },
            //获取页码
            changeNum(e) {
                this.pageNo = e;

                this.totalPage = e;
                if (this.clickTagName === "first") {
                    if (this.timeList) {
                        this.getQueryList(this.timeList);
                    } else {
                        this.getQueryList();
                    }
                } else if (this.clickTagName === "two") {
                    this.getMeDone();
                } else if (this.clickTagName === "three") {
                    if (this.seachLists) {
                        this.getMeLaunch(this.seachLists);
                    } else {
                        this.getMeLaunch();
                    }
                }
            },
            clickTabs(e) {
                this.buttonStatus = true;
                this.clickTagName = e;
                this.$refs.TableList.page = 1;
                this.totalPage = "1";
                //重新网络请求
                if (this.todoBase.name == e) {
                    this.lable = this.todoBase;
                    this.getQueryList();
                } else if (this.doneBase.name == e) {
                    this.lable = this.doneBase;
                    this.getMeDone();
                } else if (this.meLaunch.name === e) {
                    this.lable = this.meLaunch;
                    this.getMeLaunch();
                }
            },

            handleClose() {
                this.dialogStatus = false;
                this.forwardStatus = false;
                this.exportBtnStatus = false;
                this.saveStatus = false;
                this.startStatus = true;
                this.closeStatus = true;
                // this.fromList = {};
            },
            handleCloses() {
                this.treeList = [];
                this.textarea = "";
                this.handleStatus = false;
            },
            editCloses() {
                this.editStatus = false;
            },
        }
        ,
    }
    ;
</script>

<style lang="scss" scoped>
    .copyClass {
        display: flex;
    }

    .flex-header-text-tree {
        width: 50%;
        text-align: center;
    }

    .active {
        background-color: #f3faff;
    }

    .flex-common {
        padding: 10px 5%;
        font-size: 18px;
    }

    .flex-buttons {
        background-color: #cde4f6;
        border-color: #cde4f6;
        color: #606266;
    }

    .flex-button {
        margin-top: 10px;
        margin-bottom: 10px;

        ::v-deep .el-button--primary {
            width: 222px;
        }
    }

    .flex-left-header-text {
        height: 40px;
        line-height: 40px;
        color: black;
        padding-left: 10px;
        background-color: #cde4f6;
        font-size: 18px;
        font-weight: bold;
    }

    .flex-right-text {
        margin-right: 20px;
        width: 50%;
    }

    .flex-handle {
        width: 100%;
        padding: 30px;
        display: flex;

        .flex-right {
            width: 50%;
            border: 1px solid #e1e1e1;
            margin-left: 20px;
        }

        .flex-left {
            width: 50%;
            display: flex;
            flex-direction: column;

            .flex-left-header {
                display: flex;
                justify-content: space-around;
            }
        }
    }

    .table-title {
        height: 50px;
        line-height: 50px;
        background-color: #f3faff;
        font-size: 18px;
        font-weight: bold;
    }

    ::v-deep .el-dialog {
        margin-top: 0 !important;
    }

    ::v-deep .el-table__fixed-body-wrapper {
        top: 50px !important;
    }

    .flex-box {
        display: flex;
        width: calc(100% - 40px);
        border-radius: 20px;
        background-color: #fff;
        margin: 0 auto;
        margin-top: 20px;
        position: relative;
        flex-direction: column;

        .flex-header {
            display: flex;
            width: 100%;
            position: relative;
            height: 60px;
            margin: 1%;
            border-bottom: 1px solid #e1e1e1;
            justify-content: space-between;

            .el-button {
                width: 150px;
                float: right;
                height: 40px !important;
                margin-right: 30px;
            }
        }
    }

    //设置子组件样式
    ::v-deep .el-tabs__item {
        padding: 0;
        margin-right: 20px;
        width: 166px;
        text-align: center;
        background-color: #d8eaf6;
        color: black;
    }

    ::v-deep .is-active {
        color: #fff;
        background-color: #0583cd;
    }

    ::v-deep .el-tabs__active-bar {
        display: none;
    }

    ::v-deep .el-tabs__nav-wrap::after {
        display: none !important;
    }

    .flex-form {
        margin-top: 50px;
    }

    .flex-footer-botton {
        display: flex;
        justify-content: space-evenly;
    }
</style>

