<template>
    <el-container id="repositoryMain" style="overflow: hidden;">
        <el-header v-if="!havingWritePerm || havingCreatePerm" :height="headerHeight2">
        </el-header>
        <el-header v-if="havingWritePerm || havingCreatePerm" :height="headerHeight1">
            <div style="margin: 12px 0px 10px;text-align: center;">
                <el-popover
                        v-if="havingWritePerm || havingCreatePerm"
                        placement="bottom"
                        width="280"
                        trigger="click"
                        :visible-arrow=false
                        v-model="createDesignerVisible"
                        @show="showCreateEvent">
                    <div v-loading="createMethodLoading" element-loading-text="拼命加载中">
                        <div>
                            <ul>
                                <li style="margin-bottom: 7px;" v-for="row in Math.ceil(fileMethodList.length/4)">
                                    <template v-for="item in fileMethodList.slice((row-1)*4, row*4)">
                                        <div class="new-repository-item"
                                             :style="{opacity: item.opacity, filter: item.filter, cursor: item.cursor}"
                                             @click="item.clickFlag && createDesigner(item.app,item.category,item.method)">
                                            <div style="position: relative;top: 9px;">
                                                <div class="icon-div-repository"
                                                     :style="{'background-color': item.icon.color}">
                                                    <i class="awsui-iconfont icon-dynamic-repository"
                                                       v-html="item.icon.code"></i>
                                                </div>
                                                <div class="item-name text-general-color icon-text">
                                                    <label :style="{cursor: item.cursor}">{{item.methodName}}</label>
                                                </div>
                                            </div>
                                        </div>
                                        <!--                    </el-tooltip>-->
                                    </template>
                                </li>
                            </ul>
                        </div>
                        <!--分隔线-->
                        <div style="border-bottom: 1px solid #F2F2F2;"></div>
                        <div style="margin-top: 7px;">
                            <ul>
                                <li>
                                    <template v-for="item in folderMethodList">
                                        <div class="new-repository-item"
                                             :style="{opacity: item.opacity, filter: item.filter, cursor: item.cursor}"
                                             @click="item.clickFlag && createFolder(item.method, item.methodName)">
                                            <div style="position: relative;top: 4px;">
                                                <div class="icon-div-repository">
                                                    <i class="awsui-iconfont icon-fixed-repository" :style="{'color': item.icon.color}" v-html="item.icon.code"></i>
                                                </div>
                                                <div class="item-name text-general-color fixed-icon-text">
                                                    <label :style="{cursor: item.cursor}">{{item.methodName}}</label>
                                                </div>
                                            </div>
                                        </div>
                                    </template>
                                    <div class="new-repository-item" style="cursor: pointer;" @click="importDesigners">
                                        <div style="position: relative;top: 4px;">
                                            <div class="icon-div-repository">
                                                <i class="iconfont text-linker-color icon-fixed-repository">&#xe671;</i>
                                            </div>
                                            <div class="item-name text-general-color fixed-icon-text">
                                                <label style="cursor: pointer;">导入模型</label>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <awsui-button slot="reference" style="width: 100%;height: 36px;margin: 0;font-size: 14px;"
                                  :class="{'button-general-color': !dis}" type="primary"  :disabled="dis" >新建
                    </awsui-button>
                </el-popover>
            </div>
            <div v-if="havingWritePerm || havingCreatePerm" style="width: 100%;border-bottom: 1px solid #F2F2F2;"></div>
        </el-header>
        <el-main class="main-tree" :style="{'overflow': 'auto', 'height': treeHeight}">
            <el-tree
                    ref="tree"
                    :props="treeProps"
                    :expand-on-click-node=false
                    :highlight-current=true
                    @node-click="openNode"
                    @node-expand="expandNode"
                    @node-collapse="closeNode"
                    node-key="id"
                    lazy
                    :load="loadNode">
        <span slot-scope="{node, data}">
          <i class="awsui-iconfont tree-content-icon tree-content-icon-padding" :style="{'color': node.data.icon.color}"
             v-html="node.data.icon.icon"></i>
          <span :style="{'font-weight': data.id.length < 36 ? '600' : ''}">{{node.label}}</span>
        </span>
            </el-tree>
        </el-main>
        <el-dialog
                :title="folderDialog.folderTitle"
                :visible.sync="folderDialog.dialogVisible"
                :modal-append-queryTreeByIdAndPathto-body=false
                :close-on-click-modal=false
                :close-on-press-escape=true
                :before-close="handleCloseFolder"
                width="600px">
            <div style="border: 1px solid #F2F2F2;padding: 0px 10px 10px 10px;">
                <awsui-form :model="folderDialog.folderForm" :rules="folderDialog.rules" ref="folderForm"
                            label-position="top">
                    <awsui-form-item label="名称" prop="name">
                        <awsui-input v-model="folderDialog.folderForm.name"></awsui-input>
                    </awsui-form-item>
                    <awsui-form-item v-if="folderDialog.folderMethod =='default'" label="描述" prop="desc">
                        <awsui-input type="textarea" v-model="folderDialog.folderForm.desc"></awsui-input>
                    </awsui-form-item>
                </awsui-form>
            </div>
            <span slot="footer" class="dialog-footer">
            <awsui-button class="button-general-color" type="primary" @click="createFolderSave('folderForm')">确定</awsui-button>
            <awsui-button @click="clearFolderDlg">取消</awsui-button>
          </span>
        </el-dialog>


        <el-dialog
                :title="ModelsetUpDialog.systemTitle"
                :visible.sync="ModelsetUpDialog.dialogVisible"
                :modal-append-queryTreeByIdAndPathto-body=false
                :close-on-click-modal=false
                :close-on-press-escape=true
                :before-close="handleCloseSystem"
                width="600px">
            <div style="border: 1px solid #F2F2F2;padding: 0px 10px 10px 10px;" >
                <awsui-form :model="ModelsetUpDialog.systemForm" :rules="ModelsetUpDialog.rules" ref="systemForm"
                            label-position="top">

                    <awsui-form-item label="当前选定路径">
                        <awsui-input v-model="ModelsetUpDialog.systemForm.repositoryPathData" disabled></awsui-input>
                    </awsui-form-item>
                    <awsui-form-item label="名称" prop="name">
                        <awsui-input v-model="ModelsetUpDialog.systemForm.name"></awsui-input>
                    </awsui-form-item>
                    <template v-if="ModelsetUpDialog.systemForm.method=='control.policy'">
                    <awsui-form-item label="制度类型" >
                        <awsui-select v-model="ModelsetUpDialog.systemForm.systemType" :options="ModelsetUpDialog.systemForm.SystemTypeOptions" placeholder="请选择制度类型"></awsui-select>
                    </awsui-form-item>
                    </template>

                </awsui-form>
            </div>
            <span slot="footer" class="dialog-footer">
            <awsui-button  class="button-general-color" type="primary" @click="createSystemSave('systemForm')">确定</awsui-button>
            <awsui-button @click="clearSystemDlg">取消</awsui-button>
          </span>
        </el-dialog>


        <awsui-dialog
                title="密级标定"
                :visible.sync="securityVisible"
                :border="false"
                append-to-body
                width="500px">
            <div style="max-height:500px;overflow-y: auto">
                <awsui-form :ref="file.uuid" label-width="200px" :rules="securityRules" v-for="file in securityFileList" :key="file.uuid" :model="file">
                    <awsui-form-item :label="file.name"  prop="securityLevel">
                        <awsui-select v-model="file.securityLevel" :options="securityOptions" style="width:70%"></awsui-select>
                    </awsui-form-item>
                </awsui-form>
            </div>
            <div slot="footer" class="dialog-footer">
                <awsui-button type="primary" @click="uploadServer">确定</awsui-button>
                <awsui-button @click="securityVisible = false">取 消</awsui-button>
            </div>
        </awsui-dialog>
        <RepositoryImport ref="repositoryImport"></RepositoryImport>
    </el-container>
</template>

<script>
    import RepositoryImport from "./RepositoryImport";
    import {openDesigner} from "../../api/commonFun";
    import awsuiAxios from "../../awsuiAxios";
    import bus from '../../eventBus'

    export default {
        name: "RepositoryTree",
        components: {RepositoryImport},
        data() {
            let securityValidate = (rule, value, callback) => {
                if (value === undefined ) {
                    callback(new Error('请选择文件密级'));
                } else {
                    callback();
                }
            };
            return {
                dis: false,
                headerHeight1: '60px',
                headerHeight2: '10px',
                treeHeight: (parseInt(this.$store.getters.getTopMainHeightFn)) - (this.havingWritePerm || this.havingCreatePerm ? parseInt(this.headerHeight1) : parseInt(this.headerHeight2)) + 'px',
                fileMethodList: [],
                folderMethodList: [],
                createDesignerVisible: false,
                folderDialog: {
                    dialogVisible: false,
                    folderMethod: 'default',// 文件夹类型，default默认文件夹，custom自定义文件夹（扩展的文件夹类型的建模方法）
                    folderTitle: '新建文件夹',// 新建文件夹时自定义标题
                    folderForm: {
                        name: '',
                        desc: ''
                    },
                    rules: {
                        name: [
                            {required: true, message: '必填', trigger: 'blur'},
                            {min: 1, max: 120, message: '长度在 1 到 120 个字符', trigger: 'blur'}
                        ],
                        securityLevel: [
                            { required: true, trigger: "change", validator: securityValidate ,type: "number"}
                        ],
                        desc: [
                            {min: 0, max: 2550, message: '长度在 255 个字符以内', trigger: 'blur'}
                        ]
                    }
                },

                //制度弹框
                ModelsetUpDialog: {
                    loading: false,
                    dialogVisible: false,
                    systemMethod: 'default',// 文件夹类型，default默认文件夹，custom自定义文件夹（扩展的文件夹类型的建模方法）
                    systemTitle: '名称录入',// 新建文件夹时自定义标题
                    systemForm: {
                        name: '',
                        uuid:"",
                        parentId:"",
                        repositoryPathData:"",
                        method:"",
                        systemType: '1',
                        category:"",
                        SystemTypeOptions: [
                            {
                                "label" : '制度',
                                "value" : "1"
                            },
                            {
                                "label" : '操作指导',
                                "value" : "2"
                            }
                        ],
                    },
                    rules: {
                        name: [
                            {required: true, message: '必填', trigger: 'blur'},
                            {min: 1, max: 120, message: '长度在 1 到 120 个字符', trigger: 'blur'}
                        ]
                    }
                },
                treeProps: {
                    label: 'name',
                    isLeaf: 'leaf'
                },
                createMethodLoading: false,
                havingWritePerm: false,
                havingRemovePerm: false,
                havingVersionManagePerm: false,
                validUserPermDataCount: 0,
                isOlderVersion:true,
                havingCreatePerm:false,
                havingBatchPerm:false,
                isHighSecurity: false,
                securityList: {},
                securityVisible: false,
                securityFileList: [],
                securityOptions: [],
                securityRules: {
                    securityLevel: [{ required: true, trigger: "change", validator: securityValidate ,type: "number"}],
                },
                securityType: "",
            }
        },
        inject: ['openRepositoryList','transferTreeNode'],
        provide: function(){
            return{
                getIsHighSecurity: this.getIsHighSecurity,
                setSecurityVisible: this.setSecurityVisible,
                securityFileList: this.securityFileList,
                setSecurityType: this.setSecurityType,
                SystemTypeList:this.SystemTypeList
            }
        },
        created() {
            this.initData();
        },
        mounted() {
            bus.$on("getisDisabled",data =>{
                this.dis=data;
            });
        },
        methods: {
            initData() {
                const that = this;
                that.loadingText = '加载中';
                that.loading = true;
                if (that.$store.getters.getTeamIdFn && that.$store.getters.getTeamIdFn != '') {
                    const data = {
                        url: 'jd',
                        data: {
                            wsId: that.$store.getters.getWsIdFn,
                            teamId: that.$store.getters.getTeamIdFn,
                            cmd: 'com.actionsoft.apps.coe.pal_user_perm_query'
                        }
                    };
                    // 查询数据
                    awsuiAxios.post(data).then(function (ro) {
                        that.validUserPermDataCount = ro.data.validUserPermDataCount;
                        if (that.validUserPermDataCount > 0) {
                            that.havingWritePerm = ro.data.havingWritePerm;
                            that.havingCreatePerm = ro.data.havingCreatePerm
                        } else {
                            that.havingWritePerm = false;
                            that.havingCreatePerm = false;
                        }
                        that.havingRemovePerm = ro.data.havingRemovePerm;
                        that.havingVersionManagePerm = ro.data.havingVersionManagePerm;
                        that.havingBatchPerm = ro.data.havingBatchPerm;
                        that.isOlderVersion = ro.data.isOlderVersion;
                        that.initTreeHeight();
                    }).catch(error => {
                        console.log(error);
                    })
                } else {
                    that.havingWritePerm = true;
                    that.havingRemovePerm = true;
                    that.havingVersionManagePerm = true;
                }
                this.initTreeHeight();
            },

            queryTreeByIdAndPath(id, versionId, path) {// 定位展开某节点
                const that = this;
                const tree = that.$refs.tree;
                // 分隔字符串
                const pathArr = path.split(',');
                let index = 1;
                for (let i = 0; i < pathArr.length; i++) {// 依次展开
                    if (i > 0) {
                        if (tree.getNode(pathArr[i - 1]) != null) {
                            setTimeout(that._expandNode(tree, pathArr[i - 1]), index * 300);
                            index++;
                        }
                    }
                }
                setTimeout(function () {
                    if (tree.getNode(versionId) != null) {
                        tree.setCurrentKey(versionId);
                    }
                    that.openRepositoryList(id);
                }, index * 300);
            },
            _expandNode(tree, id) {
                return function () {
                    tree.getNode(id).expand();
                }
            },
            openNode(obj, node, tree) {// 打开一只模型文件
                this.closeCreatePopover();
                this.openRepositoryList(node.data.currId);
                this.transferTreeNode(obj)
            },
            loadNode(node, resolve) {
                const that = this;
                const data = {
                    url: 'jd',
                    data: {}
                };
                data.data.wsId = that.$store.getters.getWsIdFn;
                data.data.teamId = that.$store.getters.getTeamIdFn;
                data.data.cmd = 'com.actionsoft.apps.coe.pal_processlevel_tree_data';
                if (node.level === 0) {
                    // 获取根目录
                    data.data.pid = '';
                } else {
                    // 获取其他目录
                    data.data.pid = node.data.id;
                }
                // 查询数据
                awsuiAxios.post(data).then(function (ro) {
                    resolve(ro.data);
                    if (node.level == 0 && ro.data.length > 0) {
                        const tree = that.$refs.tree;
                        tree.getNode(ro.data[0].id).expand();
                        setTimeout(function () {
                            const childNode = tree.getNode(ro.data[0].id).childNodes[0];
                            if (childNode != null) {
                                childNode.expand();
                            }
                        }, 500);
                    }
                }).catch(error => {
                    console.log(error);
                    that.tableLoading = false;
                })
            },
            expandNode(obj, node, tree) {// 展开节点

            },
            closeNode(obj, node, tree) {// 关闭时清空，下次展开重新请求动态加载
                node.childNodes = [];
                node.loaded = false;
            },
            refreshNode(id) {// 刷新当前选中节点的子节点，即关闭当前节点后重新打开，会执行loadNode进行自动加载
                if (id == undefined) {// 未指定节点，默认刷新当前选中
                    const nodeData = this.$refs.tree.getCurrentNode();
                    if (nodeData != null) {
                        if (this.$refs.tree.store.nodesMap[nodeData.id] != undefined) {
                            this.$refs.tree.store.nodesMap[nodeData.id].expanded = false;
                        }
                        const node = this.$refs.tree.getNode(nodeData.id);
                        this.closeNode(null, node, null);
                        node.expand();
                    }
                } else {// 指定刷新某节点
                    if (this.$refs.tree.store.nodesMap[id] != undefined) {
                        this.$refs.tree.store.nodesMap[id].expanded = false;
                    }
                    const node = this.$refs.tree.getNode(id);
                    if (node != null) {
                        this.closeNode(null, node, null);
                        node.expand();
                        //刷新后，默认点击当前node
                        this.openNode(node.data,node,null);
                    }
                }
            },
            refreshParentNode(id) {// 刷新当前id节点的父节点，即重新加载id节点
                let nodeData = null;
                if (id == undefined) {
                    nodeData = this.$refs.tree.getCurrentNode();
                } else {
                    nodeData = this.$refs.tree.getNode(id);
                }
                if (nodeData != null) {
                    nodeData = this.$refs.tree.getNode(nodeData.data.pid);
                    this.refreshNode(nodeData.data.id);
                }
            },
            showCreateEvent() {
                const that = this;
                const node = that.$refs.tree.getCurrentNode();
                if (node == null) {
                    that.closeCreatePopover();
                    that.$message({
                        message: '请选择新建文件位置',
                        type: 'warning'
                    });
                    return;
                }
                that.createMethodLoading = true;
                const category = that.$refs.tree.getCurrentNode().plCategory;
                const methodId = that.$refs.tree.getCurrentNode().plMethodId;
                // 获取所有类型
                const data = {
                    url: 'jd',
                    data: {
                        cmd: 'com.actionsoft.apps.coe.pal_processlevel_create_method_list',
                        category: category,
                        methodId: methodId
                    }
                };
                // 查询数据
                awsuiAxios.post(data).then(function (ro) {
                    if (ro.result == 'ok') {
                        const fileMethodList = ro.data.fileMethodList;// 文件类建模
                        for (let i = 0; i < fileMethodList.length; i++) {
                            let item = fileMethodList[i];
                            if (item.havingCreatePerm) {
                                item.opacity = 1.0;
                                item.filter = 'alpha(opacity=100)';
                                item.clickFlag = true;
                                item.cursor = 'pointer';
                            } else {
                                item.opacity = 0.4;
                                item.filter = 'alpha(opacity=40)';
                                item.clickFlag = false;
                                item.cursor = 'default';
                            }
                        }
                        that.fileMethodList = fileMethodList;

                        const folderMethodList = ro.data.folderMethodList;// 文件夹类型
                        for (let i = 0; i < folderMethodList.length; i++) {
                            let item = folderMethodList[i];
                            if (item.havingCreatePerm) {
                                item.opacity = 1.0;
                                item.filter = 'alpha(opacity=100)';
                                item.clickFlag = true;
                                item.cursor = 'pointer';
                            } else {
                                item.opacity = 0.4;
                                item.filter = 'alpha(opacity=40)';
                                item.clickFlag = false;
                                item.cursor = 'default';
                            }
                        }
                        that.folderMethodList = folderMethodList;
                        // 三员管理配置
                        if(ro.data.isHighSecurity != undefined){
                            that.isHighSecurity = ro.data.isHighSecurity;
                            that.securityList = ro.data.securityList;
                            //设置密级options
                            that.securityOptions = [];
                            Object.keys(that.securityList).map(key =>{
                                let option= {
                                    value: key,
                                    label: that.securityList[key]
                                }
                                that.securityOptions.push(option);
                            })
                        }
                    }
                    that.createMethodLoading = false;
                }).catch(error => {
                    console.log(error);
                })
            },
            createFolder(method, methodName) {// 创建文件夹

                this.folderDialog.folderMethod = method;
                this.folderDialog.folderTitle = '新建' + methodName;
                this.folderDialog.dialogVisible = true;
                this.closeCreatePopover();
            },

            clearFolderDlg(closeDlg) {
                this.$refs['folderForm'].resetFields();
                if (closeDlg) {
                    this.folderDialog.dialogVisible = false;
                }
            },

            clearSystemDlg(closeDlg) {
                this.$refs['systemForm'].resetFields();
                if (closeDlg) {
                    this.ModelsetUpDialog.dialogVisible = false;
                }
            },


            handleCloseFolder(done) {
                this.clearFolderDlg(false);
                done();
            },

            handleCloseSystem(done) {
                this.clearSystemDlg(false);
                done();
            },

            //ModelsetUpDialog
            createModelsetUp(method) {// 创建文件夹
                this.ModelsetUpDialog.systemMethod = method;
                this.ModelsetUpDialog.systemForm.method = method;
                this.ModelsetUpDialog.systemTitle = '名称录入';
                this.ModelsetUpDialog.dialogVisible = true;
                this.closeCreatePopover();
            },

            createFolderSave(formName) {// 保存新建的文件夹
                const that = this;
                that.$refs[formName].validate((valid) => {
                    if (valid) {
                        const name = that.folderDialog.folderForm.name;
                        const desc = that.folderDialog.folderForm.desc;
                        if (desc.length > 255) {
                            that.$message({message: '[描述]不允许超过255个字符', type: 'warning'});
                            return;
                        }
                        const nodeData = that.$refs.tree.getCurrentNode();
                        const parentId = nodeData.id;
                        const wsId = that.$store.getters.getWsIdFn;
                        const teamId = that.$store.getters.getTeamIdFn;
                        const method = that.folderDialog.folderMethod;// 默认文件夹或自定义method的文件夹
                        const data = {
                            url: 'jd',
                            data: {
                                cmd: 'com.actionsoft.apps.coe.pal_processlevel_folder_create_save',
                                wsId: wsId,
                                teamId: teamId,
                                method: method,
                                parentId: parentId,
                                name: name,
                                desc: desc,
                                id: ''// 为空代表创建，不为空则更新
                            }
                        };
                        // 查询数据
                        awsuiAxios.post(data).then(function (ro) {
                            if (ro.result == 'ok') {
                                // 刷新节点，重新打开
                                that.refreshNode();
                                that.clearFolderDlg(true);
                                that.openRepositoryList(parentId);
                            }
                        }).catch(error => {
                            console.log(error);
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },

            //
            createSystemSave(formName) {// 保存新建的文件夹
                const that = this;



                that.$refs[formName].validate((valid) => {
                        if (valid) {

                            const checkdata = {
                                url:'jd',
                                data:{
                                    cmd: 'com.actionsoft.apps.coe.pal_pl_repository_designer_checkname',
                                    title: that.ModelsetUpDialog.systemForm.name,
                                    method:that.ModelsetUpDialog.systemForm.method,
                                }
                            };
                            // 查询数据
                            awsuiAxios.post(checkdata).then(function (ro) {
                                if (ro.data.result == 'ok') {

                                    const nodeData = that.$refs.tree.getCurrentNode();
                                    const parentId = nodeData.id;
                                    const wsId = that.$store.getters.getWsIdFn;
                                    const teamId = that.$store.getters.getTeamIdFn;
                                    const data = {
                                        url: 'jd',
                                        data: {
                                            cmd: 'com.actionsoft.apps.coe.pal_processlevel_repository_create_save_Designer',
                                            wsId: wsId,
                                            teamId: teamId,
                                            category: that.ModelsetUpDialog.systemForm.category,
                                            method: that.ModelsetUpDialog.systemForm.method,
                                            parentId: parentId,
                                            container: '_blank',// 模板，暂时不做模板
                                            name:that.ModelsetUpDialog.systemForm.name
                                        }
                                    };
                                    // 查询数据
                                    awsuiAxios.post(data).then(function (ro) {

                                        if (ro.result == 'ok') {
                                            that.ModelsetUpDialog.systemForm.uuid=ro.data.id;
                                            that.ModelsetUpDialog.systemForm.parentId=parentId;
                                            const data = {
                                                url:'jd',
                                                data:{
                                                    cmd: 'com.actionsoft.apps.coe.pal_pl_repository_designer_CreateSystemModelBySelectType',
                                                    title: that.ModelsetUpDialog.systemForm.name,
                                                    type: that.ModelsetUpDialog.systemForm.systemType,
                                                    method:that.ModelsetUpDialog.systemForm.method,
                                                    uuid:that.ModelsetUpDialog.systemForm.uuid,
                                                    parentId:that.ModelsetUpDialog.systemForm.parentId
                                                }
                                            };
                                            // 查询数据
                                            awsuiAxios.post(data).then(function (ro) {

                                                if (ro.result == 'ok') {
                                                    that.ModelsetUpDialog.dialogVisible = false;
                                                    that.openRepositoryList(that.ModelsetUpDialog.systemForm.parentId);
                                                    // 返回id
                                                    openDesigner(that.$store.getters.getTeamIdFn, that.ModelsetUpDialog.systemForm.uuid, that.$store.state.sessionId);

                                                    //清空数据
                                                    that.$refs['systemForm'].resetFields();
                                                } else {
                                                    that.$message.error(ro.msg);
                                                }
                                            }).catch(error=>{
                                                console.log(error);
                                            })

                                        }
                                    }).catch(error => {
                                        console.log(error);
                                    })
                                } else {
                                    that.$message({message: that.ModelsetUpDialog.systemForm.name+'名称重复,请重新输入！！！', type: 'warning'});
                                    return;
                                }
                            }).catch(error=>{
                                console.log(error);
                            })


                        }else {
                            console.log('error submit!!');
                            return false;
                        }
                });


            },


            createDesigner(app, category, method) {// 新建文件
                const that = this;
                that.closeCreatePopover();
                if(this.isHighSecurity){
                    //密级标定dialog
                    let file = {
                        uuid: 1,
                        name : "未命名文件",
                        category: category,
                        method: method,
                    };
                    this.securityFileList.push(file);
                    this.securityType = "create";
                    this.securityVisible = true;
                }else {
                    const nodeData = that.$refs.tree.getCurrentNode();
                    const parentId = nodeData.id;
                    const data = {
                        url: 'jd',
                        data: {
                            cmd: 'com.actionsoft.apps.coe.getArchitecturePath',
                            parentId: parentId,

                        }
                    };
                    // 查询数据
                    awsuiAxios.post(data).then(function (ro) {

                        // 返回id
                        that.ModelsetUpDialog.systemForm.repositoryPathData = ro.data.repositoryPathData;
                        that.ModelsetUpDialog.systemForm.parentId = parentId;
                        that.createModelsetUp(method);

                    }).catch(error => {
                        console.log(error);
                    })

                }
            },
            uploadServer(){
                this.validateFlag = true;
                //规则校验
                for(let i=0;i<this.securityFileList.length;i++){
                    let file = this.securityFileList[i];
                    this.$refs[file.uuid][0].validate(valid =>{
                        if(!valid){
                            this.validateFlag = false;
                            return false;
                        }
                    });
                }
                if(this.validateFlag){
                    if("import" === this.securityType){
                        //导入模型密级标定
                        const data = {
                            url: 'jd',
                            data: {
                                cmd: 'com.actionsoft.apps.coe.pal_pl_file_security_level_batch_update',
                                fileList: JSON.stringify(this.securityFileList),
                            }
                        };
                        // 查询数据
                        awsuiAxios.post(data).then(function (ro) {
                            if (ro.result == 'ok') {
                                // 刷新节点，重新打开
                                that.refreshNode();
                                that.openRepositoryList(parentId);
                                that.$message({
                                    message: '导入成功',
                                    type: 'success'
                                });
                            }
                        }).catch(error => {
                            console.log(error);
                        });
                    }else{
                        //开启设计器
                        const that = this;
                        const nodeData = that.$refs.tree.getCurrentNode();
                        const parentId = nodeData.id;
                        const wsId = that.$store.getters.getWsIdFn;
                        const teamId = that.$store.getters.getTeamIdFn;
                        for(let i=0;i<this.securityFileList.length;i++){
                            let file = this.securityFileList[i];
                            // 新建文件密级标定
                            const data = {
                                url: 'jd',
                                data: {
                                    cmd: 'com.actionsoft.apps.coe.pal_processlevel_repository_create_save',
                                    wsId: wsId,
                                    teamId: teamId,
                                    category: file.category,
                                    method: file.method,
                                    parentId: parentId,
                                    container: '_blank',// 模板，暂时不做模板
                                    securityLevel: file.securityLevel,
                                }
                            };
                            // 查询数据
                            awsuiAxios.post(data).then(function (ro) {
                                if (ro.result == 'ok') {
                                    // 刷新节点，重新打开
                                    that.refreshNode();
                                    that.openRepositoryList(parentId);
                                    // 返回id
                                    const id = ro.data.id;
                                    openDesigner(that.$store.getters.getTeamIdFn, id, that.$store.state.sessionId);
                                }
                            }).catch(error => {
                                console.log(error);
                            })
                        }
                    }
                    this.securityVisible = false;
                }
            },
            importDesigners() {
                this.closeCreatePopover();
                // 导出窗口
                this.$refs.repositoryImport.openImportRepositoryDlg(this, this.$refs.tree.getCurrentNode().plCategory, this.$refs.tree.getCurrentNode().id);
            },
            closeCreatePopover() {
                this.createDesignerVisible = false;
            },
            reload() {

            },
            initTreeHeight() {
                this.treeHeight = (parseInt(this.$store.getters.getTopMainHeightFn)) - (this.havingWritePerm || this.havingCreatePerm ? parseInt(this.headerHeight1) : parseInt(this.headerHeight2)) + 'px';
            },
            getIsHighSecurity(){
                return this.isHighSecurity;
            },
            setSecurityVisible(visible){
                this.securityVisible= visible;
            },
            setSecurityType(val){
                this.securityType = val;
            }
        },
        computed: {
            listenTopMainHeight() {
                return this.$store.getters.getTopMainHeightFn;
            }
        },
        watch: {
            listenTopMainHeight: function (newd, old) {
                this.initTreeHeight();
            },
            //密级选择dialogVisible 变为false，清空securityFileList
            securityVisible(newval, oldval){
                if(!newval){
                    this.securityFileList.splice(0,this.securityFileList.length);
                }
            },
        }
    }
</script>

<style scoped>
    #repositoryMain >>> .el-main {
        display: block;
        -webkit-box-flex: 1;
        -ms-flex: 1;
        flex: 1;
        -ms-flex-preferred-size: auto;
        flex-basis: auto;
        overflow: auto;
        margin: 0 10px 10px;
    }
    #repositoryMain >>> .el-header {
        padding: 0 10px;
    }
    #repositoryMain >>> .el-tree .el-tree-node > .el-tree-node__children {
        overflow: visible;
    }

    #repositoryMain >>> .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
        background-color: #F5F7FA;
        color: #F79500;
    }

    #repositoryMain >>> .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content .awsui-iconfont {
        color: #F79500 !important;
    }

    #repositoryMain >>> .el-dialog__body {
        padding: 10px 20px;
        color: #606266;
        font-size: 14px;
        word-break: break-all;
    }

    #repositoryMain >>> .el-form-item__label {
        line-height: 0;
    }

    #repositoryMain >>> .el-tree {
        min-width: 100%;
        display: inline-block !important;
    }

    .icon-div-repository {
        border-radius: 10%;
        display: inline-block;
        width: 32px;
        height: 32px;
        text-align: center;
        line-height: 32px;
        vertical-align: middle;
    }

    .icon-dynamic-repository {
        color: white;
        font-size: 18px;
    }

    .new-repository-item:hover .item-name {
        color: #4E7FF9;
    }

    .new-repository-item:hover {
        background-color: #F5F7FA;
    }

    .new-repository-item {
        width: 60px;
        height: 70px;
        line-height: 30px;
        text-align: center;
        display: inline-block;
        padding: 5px;
        vertical-align: middle;
    }

    .icon-fixed-repository {
        font-size: 23px;
        height: 20px;
        width: 20px;
    }

    .icon-text {
        font-size: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .fixed-icon-text {
        font-size: 12px;
        line-height: 25px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .main-tree::-webkit-scrollbar {
        display: none;
    }
</style>
