<template>
    <div>
        <awsui-sidebar
                :size="size"
                :title="title"
                :before-close="handleClose"
                :wrapper-closable=false
                :destroy-on-close=true
                :visible.sync="sidebarVisible">
            <!--awsui-sidebar标签中的内容都可以自行去控制-->
            <div id="updateRole" v-loading="loading" style="padding: 0px;">
                <div style="border-top:1px solid #F2F2F2;"></div>
                <div id="drawerBody" :style="{height: drawerBodyHeight}" style="padding: 16px;overflow-y: auto;">
                    <awsui-form ref="roleForm" :rules="rules" :model="roleForm" label-position="top">
<!--                        <div class="awsui-form-item">-->
<!--                            <label class="awsui-form-item__label"><span class="text-important-color">*</span>角色名称</label>-->
<!--                            <div class="awsui-form-item__content">-->
<!--                                <awsui-input v-model="roleForm.roleName"></awsui-input>-->
<!--                            </div>-->
<!--                        </div>-->
                        <awsui-form-item label="角色名称" prop="roleName">
                            <awsui-input placeholder="请输入内容" v-model="roleForm.roleName" :disabled="isUser"></awsui-input>
                        </awsui-form-item>
                        <div class="awsui-form-item">
                            <label class="awsui-form-item__label">角色描述</label>
                            <div class="awsui-form-item__content">
                                <awsui-input type="textarea" v-model="roleForm.roleDesc"></awsui-input>
                            </div>
                        </div>
                        <div class="awsui-form-item">
                            <label class="awsui-form-item__label">数据权限</label>
                            <el-tooltip class="item" effect="dark" placement="bottom-start" :key="Math.random()">
                                <div slot="content">选择右侧全选则该角色数据权限始终与小组一致<br/>当小组数据权限调整时，该角色数据权限自动调整</div>
                                <label class="awsui-form-item__label">
                                    <span><i class="awsui-iconfont">&#xe629;</i></span>
                                </label>
                            </el-tooltip>
                            <awsui-checkbox size="small" v-model="roleForm.isAllDataPerm">全部</awsui-checkbox>
                            <div class="awsui-form-item__content">
                                <awsui-input v-if="isOlderVersion" class="role_data_perm_textarea" type="textarea" v-model="roleForm.isAllDataPerm ? '全部' : roleForm.dataPermText" readonly placeholder="请选择" @click.native="openDataPermTreeDlg"></awsui-input>
                                <div v-else style="height: 300px;border: 1px solid #f2f2f2;">
                                  <div v-if="roleForm.isAllDataPerm"> 全部</div>
                                  <div v-else class="tree">
                                    <div class="allGroup">
                                      <div class="processAll">
                                        <el-checkbox v-model="checkAllProcess" @change="checkAllProcessChange">全选</el-checkbox>
                                      </div>
                                      <div class="actionGroup">
                                        <el-checkbox v-model="checkAllUpdate" @change="checkAllUpdateChange">编辑</el-checkbox>
                                        <el-checkbox v-model="checkAllDelete" @change="checkAllDeleteChange">删除</el-checkbox>
                                        <el-checkbox v-model="checkAllVersion" @change="checkAllVersionChange">版本管理</el-checkbox>
                                      </div>
                                    </div>
                                    <el-tree
                                      v-if="refreshTree"
                                      style="height: 270px;overflow: auto;"
                                      v-loading="loading"
                                      ref="tree"
                                      :props="treeProps"
                                      :default-checked-keys="roleForm.dataPerm"
                                      :expand-on-click-node=false
                                      :highlight-current=true
                                      empty-text=""
                                      @node-click="openNode"
                                      @node-expand="expandNode"
                                      @node-collapse="closeNode"
                                      @check-change="checkedNode"
                                      check-strictly
                                      :show-checkbox=multiple
                                      node-key="id"
                                      lazy
                                      :load="loadNode">
                                        <span slot-scope="{node, data}" style="display: flex;width: 100%">
                                          <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 :title="node.label" style="max-width:250px;overflow: hidden; white-space: nowrap;">{{node.label}}</span>
                                          <span v-if="node.level > 1" class="action-checkBox" style="flex: 1;text-align: right" @click="handleCheckedActionChange(node)">
                                            <el-checkbox-group  v-model="node.data.dataActionPerm">
                                              <el-checkbox v-for="dataAction in node.data.dataActionPermOpts" :label="dataAction.label" :key="dataAction.label"
                                                           :disabled="!node.checked" @change="checkBoxChangeHandle(node.data,dataAction)" >{{dataAction.value}}</el-checkbox>
                                            </el-checkbox-group>
                                          </span>
                                        </span>
                                    </el-tree>
                                  </div>
                                </div>
                            </div>
                        </div>
                        <awsui-form-item label="操作权限">
                            <el-checkbox-group v-model="roleForm.actionPerm">
                                <template v-for="item in roleForm.actionPermOpts">
                                    <el-checkbox :label="item.label">{{item.value}}</el-checkbox>
                                </template>
                            </el-checkbox-group>
                        </awsui-form-item>
                        <div class="awsui-form-item">
                            <label class="awsui-form-item__label">应用权限</label>
                            <el-tooltip class="item" effect="dark" placement="bottom-start" :key="Math.random()">
                                <div slot="content">选择右侧全选则该角色默认拥有所有相关应用权限<br/>当PAL小组有新的扩展应用时，该角色应用权限自动增加</div>
                                <label class="awsui-form-item__label">
                                    <span><i class="awsui-iconfont">&#xe629;</i></span>
                                </label>
                            </el-tooltip>
                            <awsui-checkbox size="small" v-model="roleForm.isAllAppPerm"></awsui-checkbox>
                            <div class="awsui-form-item__content">
                                <el-checkbox-group v-model="roleForm.appPerm">
                                    <template v-for="item in roleForm.appPermOpts">
                                        <el-checkbox :disabled="roleForm.isAllAppPerm" :label="item.label">{{item.value}}</el-checkbox>
                                    </template>
                                </el-checkbox-group>
                            </div>
                        </div>
                    </awsui-form>
                </div>
                <div class="drawer-footer" :style="{'background-color': '#F2F2F2', height: footerHeight}">
                    <div id="drawerFooter" style="float: right;position: relative;top: 9px;">
                        <awsui-button :disabled="buttonDisabled" size="large" style="width: 80px;" class="button-general-color" type="primary" @click="submit">保存</awsui-button>
                        <awsui-button size="large" style="width: 80px;" @click="cancel">取消</awsui-button>
                    </div>
                </div>
            </div>
        </awsui-sidebar>
        <cooperation-repository-tree
                ref="cooperationRepositoryTree"
                :visible.sync="cooperationRepositoryTree.visible"
                :wsId="wsId"
                :teamId="teamId"
                :multiple=true
                v-on:cancel="cooperationRepositoryTree.visible = false"
                v-on:getResult="saveCooperationRepositoryResult"
                :title="cooperationRepositoryTree.title"
                :selected="JSON.parse(JSON.stringify(roleForm.dataPerm))"
        />
    </div>

</template>

<script>
    import awsuiAxios from "../../awsuiAxios";
    import cooperationRepositoryTree from "../../components/CooperationRepositoryTree/component"

    export default {
        name: "RoleUpdate",
        components: {cooperationRepositoryTree},
        props: {
            visible: {
                type: Boolean,
                default: false
            },
            teamId: {// 小组ID
                type: String,
                default: ''
            },
            roleId: {// 角色id，是否空值进行判断是新增和修改
                type: String,
                default: ''
            },
            isUser: {
              type:Boolean,
              default:false
            },
            userid:{
              type: String,
              default:""
            }
        },
        data() {
            return {
                loading: false,
                sidebarVisible: false,
                buttonDisabled: false,
                title: '新增角色',
                size: '80%',
                drawerBodyHeight: '0px',
                footerHeight: '50px',
                wsId: '',
                roleForm: {
                    roleName: '',
                    roleDesc: '',
                    roleType: '',
                    appPermOpts: [],
                    actionPermOpts: [],
                    isAllDataPerm: false,
                    isAllAppPerm: false,
                    dataPerm: [],
                    dataPermText: '',// 权限模型文字，逗号分隔
                    appPerm: [],
                    actionPerm: [],
                },
                cooperationRepositoryTree: {
                    visible: false,
                    title: '设置数据权限'
                },
                rules: {
                    roleName: [
                        {required: true,message: '必填',trigger: 'blur'}
                    ]
                },
                isOlderVersion:true,
                treeProps: {
                  label: 'name',
                  isLeaf: 'leaf'
                },
                treeChecked: [],
                multiple:true,
                categorys:'',
                pid: '',
                dataActionPerm: {},
                dataActionPermOpts:[],
                teamPermFileSize: 0,
                checkAllProcess: false,
                checkAllUpdate: false,
                checkAllDelete: false,
                checkAllVersion: false,
                refreshTree: false
            }
        },
        mounted() {
        },
        methods: {
            initParams() {
                if (this.isUser){
                  this.title = '用户权限';
                }else{
                  if (this.roleId == '') {
                    this.title = '新增角色';
                  } else {
                    this.title = '修改角色';
                  }
                }
                this.initRoleSidebar();
            },
            initData() {
                const that = this;
                that.loading = true;
                const params = {
                    url:'jd',
                    data:{
                        cmd: 'com.actionsoft.apps.coe.pal.cooperation_role_create_or_update_data_query',
                        teamId: that.teamId,
                        roleId: that.roleId
                    }
                };
                if (that.isUser){
                  params.data.cmd = "com.actionsoft.apps.coe.pal.cooperation_hide_role_update_data_query"
                  params.data.userid = that.userid
                }
                // 查询数据
                awsuiAxios.post(params).then(function (ro) {
                    if (ro.result == 'ok') {
                        const data = ro.data;
                        that.wsId = data.wsId;
                        that.isOlderVersion = data.isOlderVersion;
                        that.roleForm.roleName = data.roleName;
                        that.roleForm.roleDesc = data.roleDesc;
                        that.roleForm.roleType = data.roleType;
                        that.roleForm.appPermOpts = data.appPermOpts;
                        that.roleForm.actionPermOpts = data.actionPermOpts;
                        that.roleForm.isAllDataPerm = data.isAllDataPerm;
                        that.roleForm.isAllAppPerm = data.isAllAppPerm;
                        that.roleForm.dataPerm = data.dataPerm;
                        that.dataActionPermOpts = data.dataActionPermOpts;
                        that.dataActionPerm = data.dataActionPerm;
                        // that.treeChecked = data.dataPerm;
                        that.roleForm.appPerm = data.appPerm;
                        that.roleForm.actionPerm = data.actionPerm;
                        that.roleForm.dataPermText = data.dataPermText;
                        //每次初始化重新加载el-tree
                        // let node = that.$refs.tree?.root;
                        // if (undefined!= node){
                        //   node.loaded = false;
                        //   node.expand();
                        // }
                        that.refreshTree = true;


                        //计算全选按钮
                        that.teamPermFileSize = data.teamPermFileSize
                        that.checkAllProcess = data.teamPermFileSize == data.dataPerm.length;
                        let wPermNum = that.getActionPermNum("w");
                        that.checkAllUpdate = wPermNum == data.teamPermFileSize;
                        let dPermNum = that.getActionPermNum("d");
                        that.checkAllDelete = dPermNum == data.teamPermFileSize;
                        let vPermNum = that.getActionPermNum("v");
                        that.checkAllVersion = vPermNum == data.teamPermFileSize;

                        //用户权限设置roleId
                      that.$emit('setUserRole', data.roleId);
                    } else {
                        that.$message.error(ro.msg);
                    }
                    that.loading = false;
                }).catch(error=>{
                    console.log(error);
                    that.loading = false;
                })
            },
            openDataPermTreeDlg() {// 打开角色数据权限设置
                this.cooperationRepositoryTree.visible = true;
            },
            saveCooperationRepositoryResult(data) {// 角色数据权限保存
                // 根据选中的数据查询名称
                const that = this;
                const params = {
                    url:'jd',
                    data:{
                        cmd: 'com.actionsoft.apps.coe.pal.cooperation_repository_names_query',
                        versionIds: JSON.stringify(data)
                    }
                };
                // 查询数据
                awsuiAxios.post(params).then(function (ro) {
                    if (ro.result == 'ok') {
                        const data = ro.data;
                        that.roleForm.dataPerm = data.versionIdArr;
                        that.roleForm.dataPermText = data.names;
                    } else {
                        that.$message.error(ro.msg);
                    }
                }).catch(error=>{
                    console.log(error);
                })
                this.cooperationRepositoryTree.visible = false;
            },
            clearAllData() {// 清空数据
                const that = this;
                that.buttonDisabled = false;
                that.wsId = '';
                that.roleForm = {
                    roleName: '',
                    roleDesc: '',
                    roleType: '',
                    appPermOpts: [],
                    actionPermOpts: [],
                    isAllDataPerm: false,
                    isAllAppPerm: false,
                    dataPerm: [],
                    dataPermText: '',// 权限模型文字，逗号分隔
                    appPerm: [],
                    actionPerm: [],
                };
                if (!that.isOlderVersion){
                  that.$refs.tree.setCheckedNodes([]);
                  that.$refs.tree.$children = [];
                  that.treeChecked = [];
                  that.dataActionPerm =  {};
                  that.dataActionPermOpts = [];
                }
                that.refreshTree = false;
            },
            handleClose(done) {
                this.closeDlalog('cancel');
                done();
            },
            cancel() {
                this.closeDlalog('cancel');
            },
            submit() {
                this.$refs['roleForm'].validate(valid => {
                    if (valid){
                        this.closeDlalog('save');
                    }
                })
            },
            closeDlalog(type) {// 取消/确定之后的关闭
                const that = this;
                if (type == 'save') {
                    // 必填校验不符合开发规范--注释
                    // if (that.roleForm.roleName == '' || that.roleForm.roleName.trim() == '') {
                    //     that.$message.error('[角色名称]不允许为空');
                    //     return;
                    // }
                    if (that.roleForm.roleName.trim().length > 30) {
                        that.$message.error('[角色名称]不允许超过30个字符');
                        return;
                    }
                    if (that.roleForm.roleDesc != '' && that.roleForm.roleDesc.trim().length > 255) {
                        that.$message.error('[角色名称]不允许超过255个字符');
                        return;
                    }
                    const data = {
                        teamId: that.teamId,
                        roleId: that.roleId,
                        roleName: that.roleForm.roleName,
                        roleDesc: that.roleForm.roleDesc,
                        roleType: that.roleForm.roleType,
                        isAllDataPerm: that.roleForm.isAllDataPerm,
                        isAllAppPerm: that.roleForm.isAllAppPerm,
                        dataPerm: that.roleForm.dataPerm,
                        appPerm: that.roleForm.appPerm,
                        actionPerm: that.roleForm.actionPerm
                    };
                    if (that.isUser){
                      data.roleName = that.userid;
                    }
                    if (!that.isOlderVersion){
                      let dataPermArr = [];
                      Object.keys(that.dataActionPerm).forEach((key) => {
                        if (key.length == 36){
                          let obj = {
                            id:key,
                            actionPerm: that.dataActionPerm[key].join(",")
                          }
                          dataPermArr.push(obj);
                        }
                      })
                      data.dataPerm = dataPermArr;
                    }
                    // 保存
                    that.loading = true;
                    that.buttonDisabled = true;
                    const params = {
                        url:'jd',
                        data:{
                            cmd: 'com.actionsoft.apps.coe.pal.cooperation_role_create_or_update_data_save',
                            data: JSON.stringify(data)
                        }
                    };
                    awsuiAxios.post(params).then(function (ro) {
                        that.loading = false;
                        if (ro.result == 'ok') {
                            that.$message({
                                message: '保存成功',
                                type: 'success'
                            });
                            that.$emit('getResult', 'ok');
                            // 清空所有数据
                            that.clearAllData();
                        } else {
                            that.$message({
                                message: ro.msg,
                                type: 'warning'
                            });
                        }

                    }).catch(error=>{
                        console.log(error);
                        that.loading = false;
                        that.buttonDisabled = false;
                    })
                } else {
                    that.$emit('cancel');
                    // 清空所有数据
                    that.clearAllData();
                }
            },
            initRoleSidebar() {
                this.drawerBodyHeight = (document.documentElement.clientHeight) - 53 - 1 - 32 - parseInt(this.footerHeight) + 'px';
            },
            openNode(obj, node, tree) {// 打开一只模型文件

            },
            expandNode(obj, node, tree) {// 展开节点

            },
            closeNode(obj, node, tree) {// 关闭时清空，下次展开重新请求动态加载
              node.childNodes = [];
              node.loaded = false;
            },
            checkedNode(data, checked, subChecked) {// 节点选中事件
              // 获取所有子节点
              const that = this;
              const params = {
                url:'jd',
                data:{
                  cmd: 'com.actionsoft.apps.coe.pal.cooperation_repository_all_childern_data_query',
                  wsId: that.wsId,
                  teamId: that.teamId,
                  pid: data.id
                }
              };
              awsuiAxios.post(params).then(function (ro) {
                // debugger;
                const childVerIds = ro.data;
                const currVerId = data.versionId;
                if (checked) {// 选中
                  const checkedVerIds = that.roleForm.dataPerm;

                  //当前节点处理
                  if (checkedVerIds.indexOf(currVerId) == -1) {
                    checkedVerIds.push(currVerId);
                    Object.assign(that.dataActionPerm,{[currVerId]:[]})
                  }
                  //当前下属节点处理
                  for (let i = 0; i < childVerIds.length; i++) {
                    if (checkedVerIds.indexOf(childVerIds[i]) == -1) {
                      checkedVerIds.push(childVerIds[i]);
                      Object.assign(that.dataActionPerm,{[childVerIds[i]]:[]})
                    }
                  }
                  that.$refs.tree.setCheckedKeys(checkedVerIds);

                  //全选检测
                  checkedVerIds.forEach(currVerId=>{
                    let checkedNodes = that.$refs.tree.getCheckedNodes();
                    //全选编辑检测
                    if (that.checkAllUpdate){
                      setTimeout(()=>{
                        that.pushArr(that.dataActionPerm[currVerId],'w');
                        checkedNodes.forEach(node=>{
                          that.pushArr(node.dataActionPerm,'w')
                        })
                      },100)
                    }
                    //全选删除检测
                    if (that.checkAllDelete){
                      setTimeout(()=>{
                        that.pushArr(that.dataActionPerm[currVerId],'d');
                        checkedNodes.forEach(node=>{
                          that.pushArr(node.dataActionPerm,'d')
                        })
                      },100)
                    }
                    //全选版本检测
                    if (that.checkAllVersion){
                      setTimeout(()=>{
                        that.pushArr(that.dataActionPerm[currVerId],'v');
                        checkedNodes.forEach(node=>{
                          that.pushArr(node.dataActionPerm,'v')
                        })
                      },100)
                    }
                  })

                } else {// 取消选中
                  const checkedVerIds = that.roleForm.dataPerm;
                  const checkedActions = that.dataActionPerm;
                  const tempArr = [];
                  const tempActions = {};
                  for (let i = 0; i < checkedVerIds.length; i++) {
                    if (checkedVerIds[i] != currVerId && childVerIds.indexOf(checkedVerIds[i]) == -1) {
                      tempArr.push(checkedVerIds[i]);
                    }
                  }
                  Object.keys(checkedActions).forEach((key) => {
                    if (key != currVerId && childVerIds.indexOf(key) == -1) {
                      Object.assign(tempActions,{[key]:checkedActions[key]})
                    }
                  })

                  that.roleForm.dataPerm = tempArr;
                  that.dataActionPerm = tempActions;
                  that.$refs.tree.setCheckedKeys([]);
                }

                //计算流程全选按钮
                let num = 0;
                that.roleForm.dataPerm.forEach(item=>{
                  if (item.length == 36){
                    num++;
                  }
                })
                that.checkAllProcess = num == that.teamPermFileSize;

              }).catch(error=>{
                console.log(error);
              })
            },
            loadNode(node, resolve) {
              const that = this;
              that.loading = true;
              const data = {
                url:'jd',
                data:{
                  cmd: 'com.actionsoft.apps.coe.pal.cooperation_repository_tree_component_subjson',
                  wsId: that.wsId,
                  teamId: that.teamId,
                  categorys: that.categorys,
                  pid: ''
                }
              };
              if (node.level === 0) {
                // 获取根目录
                data.data.pid = that.pid;
              } else {
                // 获取其他目录
                data.data.pid = node.data.id;
              }
              // 查询数据
              awsuiAxios.post(data).then(function (ro) {
                let data = ro.data;
                for (let i = 0; i < data.length; i++) {
                  let item = data[i];
                  Object.assign(item,{dataActionPermOpts: that.dataActionPermOpts})
                  if (that.dataActionPerm[item.versionId] != undefined){
                    Object.assign(item,{dataActionPerm:that.dataActionPerm[item.versionId]})
                  }else {
                    Object.assign(item,{dataActionPerm:[]})
                  }
                }
                resolve(data);
                that.loading = false;
                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);
              })
            },
            handleCheckedActionChange(node){
              // console.log("changeChecked",node);
              const  that = this;
              setTimeout(()=>{
                if (that.dataActionPerm[node.data.versionId] != undefined){
                  that.dataActionPerm[node.data.versionId] = node.data.dataActionPerm;
                }

                //编辑全选
                let wPermNum = that.getActionPermNum("w");
                that.checkAllUpdate = wPermNum == that.teamPermFileSize;
                let dPermNum = that.getActionPermNum("d");
                that.checkAllDelete = dPermNum == that.teamPermFileSize;
                let vPermNum = that.getActionPermNum("v");
                that.checkAllVersion = vPermNum == that.teamPermFileSize;
              },100)

            },
            checkBoxChangeHandle(data,dataAction){
              let dataActionPerm = data.dataActionPerm;

              //选中删除与版本控制
              let flag =  dataActionPerm.includes('d') || dataActionPerm.includes('v')
              if ((dataAction.label == 'd' || dataAction.label == 'v') && flag){
                if (!dataActionPerm.includes('w')){
                  dataActionPerm.push('w');
                }
              }

              //将w勾选掉后处理
              if(dataAction.label == 'w'){
                if (dataActionPerm.includes('d')){
                  this.removeArr(dataActionPerm,'d')
                }
                if (dataActionPerm.includes('v')){
                  this.removeArr(dataActionPerm,'v')
                }
              }
            },
            checkAllProcessChange(value){
              const that = this;

              if (value){//选中
                const params = {
                  url:'jd',
                  data:{
                    cmd: 'com.actionsoft.apps.coe.pal.cooperation_repository_all_childern_data_query',
                    wsId: that.wsId,
                    teamId: that.teamId,
                    pid: ''
                  }
                };
                awsuiAxios.post(params).then(ro=>{
                  const childVerIds = ro.data;

                  const checkedVerIds = that.roleForm.dataPerm;
                  for (let i = 0; i < childVerIds.length; i++) {
                    if (checkedVerIds.indexOf(childVerIds[i]) == -1) {
                      checkedVerIds.push(childVerIds[i]);
                      Object.assign(that.dataActionPerm,{[childVerIds[i]]:[]})
                    }
                  }
                  that.$refs.tree.setCheckedKeys(checkedVerIds);
                }).catch(error=>{
                  console.log(error);
                })
              }else {
                that.roleForm.dataPerm = [];
                that.dataActionPerm = {};
                that.$refs.tree.setCheckedKeys([]);
              }
            },
            checkAllUpdateChange(value){
              this.checkAllActionChange(value,'w')
            },
            checkAllDeleteChange(value){
              this.checkAllActionChange(value,'d')
            },
            checkAllVersionChange(value){
              this.checkAllActionChange(value,'v')
            },
            checkAllActionChange(flag,str){
              let actionPerm = this.dataActionPerm;
              let checkedNodes = this.$refs.tree.getCheckedNodes();

              if (flag){
                //选中
                Object.keys(actionPerm).forEach(key=>{
                  this.pushArr(actionPerm[key],str);
                  if (str == 'd' || str == 'v'){
                    this.pushArr(actionPerm[key],'w');
                  }
                })
                //el 节点处理
                checkedNodes.forEach(node=>{
                  this.pushArr(node.dataActionPerm,str);
                  if (str == 'd' || str == 'v'){
                    this.checkBoxChangeHandle(node,{label:str})
                  }
                })
              }else {
                //去掉勾选
                Object.keys(actionPerm).forEach(key=>{
                  this.removeArr(actionPerm[key],str);
                  if (str == 'w'){
                    this.removeArr(actionPerm[key],'d');
                    this.removeArr(actionPerm[key],'v');
                  }
                })
                checkedNodes.forEach(node=>{
                  this.checkBoxChangeHandle(node,{label:str})
                  this.removeArr(node.dataActionPerm,str)
                })
              }
              //重新计算全选编辑
              let wPermNum = this.getActionPermNum("w");
              this.checkAllUpdate = wPermNum == this.teamPermFileSize;
              let dPermNum = this.getActionPermNum("d");
              this.checkAllDelete = dPermNum == this.teamPermFileSize;
              let vPermNum = this.getActionPermNum("v");
              this.checkAllVersion = vPermNum == this.teamPermFileSize;
            },
            pushArr(arr,str){
              if (!arr.includes(str)){
                arr.push(str)
              }
            },
            removeArr(arr,str){
              if (arr.includes(str)){
                arr.splice(arr.indexOf(str),1)
              }
            },
            getActionPermNum(str){
              let num = 0;
              let actionPerm = this.dataActionPerm;
              Object.keys(actionPerm).forEach(key=>{
                if (actionPerm[key].includes(str)){
                  num++;
                }
              })
              return num;
            }
        },
        watch: {
            visible(val) {
                this.sidebarVisible = val;
                if (val) {// 打开
                    this.initParams();
                    this.initData();
                } else {// 关闭
                }
            }
        }
    }
</script>

<style scoped>
.allGroup{
  display: flex;
}.allGroup .processAll{
  margin-left: 5px;
}
.allGroup .actionGroup{
  flex: 1;
  text-align: right;
  padding-right: 1px;
}
</style>