<template>
  <div style="height: 100%" class="role-authorization">
    <CSTable
      v-if="loadTree"
      ref="csTable"
      style="height: 100%"
      :tableData="tableData"
      :tableConfig="tableConfig"
    ></CSTable>
    <el-dialog
      :title="$t(selectPeople)"
      :visible.sync="selectUserFlag"
      width="860px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      custom-class="el-dialog-width-1200"
    >
      <ChooseUser :role-user-list="roleUserList" :system-user-id="'672888303978721280'"  @clearRoleUserListFunc="clearRoleUserList" v-if="selectUserFlag" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">{{
          $t("cs.common.button.cancel")
        }}</el-button>
        <el-button type="primary" @click="submitChooseRole">{{
          $t("cs.common.button.ok")
        }}</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :title="$t(lookAllPeopleTitle)"
      :visible.sync="lookPeopleFlag"
      width="912px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      custom-class="el-dialog-width-1200"
    >
      <LookAllPeopleDialog :people-list="lookPeopleList" :system-user-id="'672888303978721280'"  :id-prop-name="'participationUserId'" :prop-name="'participationUserName'"  v-if="lookPeopleFlag" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="closePeopleDialog">{{
          $t("cs.common.button.cancel")
        }}</el-button>
        <el-button type="primary" @click="submitLookPeople">{{
          $t("cs.common.button.ok")
        }}</el-button>
      </div>
    </el-dialog>
    <el-drawer
      size="900px"
      :title="$t(dataAuthorizationDialogTitle)"
      :visible.sync="dataAuthorizationFlag"
      :modal="false"
      custom-class="custom-class"
      :before-close="closeDataAuthorizationDialog">
      <DataAuthorizationDialog :authority-data-category-list="authorityDataCategoryList" :role-id="roleId" authority-type="1" v-if="dataAuthorizationFlag" />
      <div class="dialog-footer">
        <el-button @click="closeDataAuthorizationDialog">{{
          $t("cs.common.button.cancel")
        }}</el-button>
        <el-button type="primary" @click="submitDataAuthorizationDialog">{{
          $t("cs.common.button.ok")
        }}</el-button>
      </div>
    </el-drawer>
    <el-drawer
      size="640px"
      :title="$t(menuAuthorizationDialogTitle)"
      :visible.sync="menuAuthorizationFlag"
      custom-class="custom-class"
      :modal="false"
      :before-close="closeMenuAuthorizationDialog">
      <MenuAuthorizationDialog :menu-id-list="menuIdList" :role-id="roleId" authority-type="1" v-if="menuAuthorizationFlag" />
      <div class="dialog-footer">
        <el-button @click="closeMenuAuthorizationDialog">{{
          $t("cs.common.button.cancel")
        }}</el-button>
        <el-button type="primary" @click="submitMenuAuthorizationDialog">{{
          $t("cs.common.button.ok")
        }}</el-button>
      </div>
    </el-drawer>
  </div>
</template>
<script scoped>
import ChooseUser from "../../../BusinessCommon/Components/ChooseUser.vue";
import CSTable from "../../../BusinessCommon/Components/CSTable.vue";
import LookAllPeopleDialog from "../../../BusinessCommon/Components/LookAllPeopleDialog.vue";
import DataAuthorizationDialog from "../../../BusinessCommon/Components/DataAuthorizationDialog.vue";
import MenuAuthorizationDialog from "../../../BusinessCommon/Components/MenuAuthorizationDialog.vue";
import CoreAPI from "../../../Common/JS/CoreAPI";
export default {
  name: "RoleAuthorizationTable",
  components: { ChooseUser, DataAuthorizationDialog, MenuAuthorizationDialog, LookAllPeopleDialog, CSTable },
  props: {},
  data() {
    return {
      activeName: "second",
      loadTree: false,
      infiniteScrollLoadDataIndex: 0,
      infiniteScrollLoadDataAntiShake: true,
      selectUserFlag: false,
      lookPeopleFlag: false,
      dataAuthorizationFlag: false,
      menuAuthorizationFlag: false,
      dataAuthorizationDialogTitle: "cs.authorityManage.authorization.dataAuthorization",
      menuAuthorizationDialogTitle: "cs.authorityManage.authorization.menuAuthorization",
      selectPeople: "cs.authorityManage.authorization.selectPeople",
      lookAllPeopleTitle: "cs.authorityManage.authorization.people",
      tableData: [],
      tableConfig: {
        operationArea: {
          buttonList: [
            {
              prop: "cs.common.button.insert", // 按钮名称
              disabled: false, // 是否禁用
              clickFunc: this.addTemplate // 点击事件
            },
            {
              prop: "cs.common.button.delete", // 按钮名称
              disabled: true, // 是否禁用
              clickFunc: this.removeTemplate // 点击事件
            },
            {
              prop: "cs.authorityManage.authorization.batchMenuAuthorization", // 按钮名称
              disabled: true, // 是否禁用
              clickFunc: this.showBatchMenuAuthorizationDialog // 点击事件
            }
          ]
        },
        queryConditionArea: {
          queryList: [
            {
              type: 'label',
              labelName: "cs.common.text.roleName",
              labelFilterFieldName: 'name',
              filtersValue: '',// 查询值
              labelFilterShowType: 'input'
            }
          ],
          searchFunc: this.listSearch // 查询按钮调用方法
        },
        // 列配置
        tableContentArea: {
          customColumnAddButtonHeight: "80",
          cancelFirstSelectionFixed: true,
          columns: [
            // 文本形式
            {
              label: "cs.authorityManage.authorization.roleName",
              prop: "name",
              type: "input",
              width: 280,
              showOverflowTooltip: true,
              inputChange: this.inputUpdateVerify
            },
            {
              label: "cs.authorityManage.authorization.rolePersonnel",
              prop: "roleUserList",
              showNameProp: "participationUserName",
              userIdProp: "participationUserId",
              type: "role",
              showOverflowTooltip: false,
              rolePeopleFunc: this.rolePeopleFunc,
              addRolePeopleFunc: this.addRolePeopleFunc,
              deleteRolePeopleFunc: this.deleteRolePeopleFunc,
              systemUserId: '672888303978721280'
            },
            {
              label: "cs.authorityManage.authorization.menuAuthorization",
              type: "link",
              iconName: "el-icon-key",
              width: 180,
              minWidth: 180,
              align: "left",
              linkList: [
                {
                  linkName: "cs.authorityManage.authorization.unauthorized,cs.authorityManage.authorization.authorized", // 链接名称  对应数据的属性名称
                  color: "#303133,#1890ff",
                  prop: "isMenuAuthority",
                  clickFunc: this.showMenuAuthorizationDialog
                }
              ],
              underline: false
            }
          ],
          handleSelectAll: this.handleSelectAll,
          needTip: true, 
          needSelection: true, // 选填  是否需要显示列表多选
          handleSelectionChange: this.multipleSelectionChange // 当选择项发生变化时会触发该事件 返回参数: 选中的行
        },
        // 无限滚动加载      ps:无限滚动加载和分页区域  选其一就行
        infiniteScrollLoadData: this.infiniteScrollLoadData, // 选填 无限滚动 加载数据方法
        infiniteScrollLoadDataDisable: false, // 选填 无限滚动加载是否禁用
        // 整行焦点离开
        leaveCurrentRowFunc: this.leaveCurrentRowFunc,
        isNeewCancelStopPropagation: true
      },
      multipleSelection: [],
      sortModels: [],
      filterModel: {
        filterGroupModel: [
          {
            filterFields: [],
            logicType: 0
          }
        ]
      },
      roleUserList: [],
      authorityDataCategoryList: [],
      menuIdList: [],
      lookPeopleList: []
    };
  },
  methods: {
    infiniteScrollLoadData() {
      let _this = this;
      if (_this.infiniteScrollLoadDataAntiShake) {
        _this.infiniteScrollLoadDataAntiShake = false;
        _this.getAuthorizeRoleList(true);
      }
    },
    getAuthorizeRoleList(isInfinite) {
      let _this = this;
      let postData = {
        pageIndex: _this.infiniteScrollLoadDataIndex,
        pageSize: 30,
        filterModel: _this.filterModel,
        sortModels: _this.sortModels,
        systemId: CloudServiceCommon.Props.systemId
      };
      CoreAPI.getAuthorizeRoleList(postData).then(
        function (res) {
          _this.infiniteScrollLoadDataAntiShake = true;
          if (res.length < 30) {
            _this.tableConfig.infiniteScrollLoadDataDisable = true;
          }
          if (res.length < 1 && _this.infiniteScrollLoadDataIndex == 0) {
            return (_this.tableData = []);
          }
          _this.infiniteScrollLoadDataIndex++;
          _this.handleTableData(res);
          for (let i = 0; i < res.length; i++) {
            res[i].customRowConfigData = {};
            _this.defaultDisabled(res[i])
            if (isInfinite) {
              _this.tableData.push(res[i]);
            }
          }
          if (!isInfinite) {
            _this.tableData = res;
          }
          CloudServiceCommon.Methods.selectTableCheckBoxService({
              // 选中的数据
              oldSelectList: _this.multipleSelection,
              // 最新的tableData
              newData: _this.tableData,
              // 行数据唯一id的属性名称
              targetId: 'id',
              // 列表配置
              tableConfig: _this.tableConfig,
              disableRowTarget: { prop: 'isDefault', value: '1' }
          })
        },
        function (error) {
          _this.infiniteScrollLoadDataAntiShake = true;
          _this.$message.error(error.msg);
        }
      );
    },
    handleTableData(tableData) {
      tableData?.forEach(function(item) {
        item.roleUserList?.forEach(function(target) {
          target.isDefault = item.isDefault
        })
      })
      console.log(tableData)
    },
    defaultDisabled(obj) {
      //管理员账号禁止选中
      if (obj.isDefault == "1") {
          obj.customRowConfigData = {
              disabledList: {
                  selectionDisabled: true,
              }
          }
      }
    },
    //首选项多选列表 this.tableData
    multipleSelectionChange(val) {
      let _this = this;
      if (val.length == 0) {
        this.tableConfig.operationArea.buttonList[1].disabled = true;
        this.tableConfig.operationArea.buttonList[2].disabled = true;
        this.tableConfig.operationArea.buttonList[3] ? this.tableConfig.operationArea.buttonList[3].disabled = true : ''
      } else {
        this.tableConfig.operationArea.buttonList[1].disabled = false;
        this.tableConfig.operationArea.buttonList[2].disabled = false;
        this.tableConfig.operationArea.buttonList[3] ? this.tableConfig.operationArea.buttonList[3].disabled = false : ''
      }
      CloudServiceCommon.Methods.findSelectTableNotChooseList({
        // 选中的数据
        oldSelectList: val,
        // tableData 最新的数据
        newData: _this.tableData,
        // 行数据唯一id的属性名称
        targetId: 'id',
        // 列表配置
        tableConfig: _this.tableConfig,
        allSelectList: _this.multipleSelection
      })
      if(_this.tableConfig.tableContentArea.isChooseAllSelect && !_this.filterModel.filterGroupModel[0].filterFields.length) {
        CoreAPI.getRoleIdsBySystemId(CloudServiceCommon.Props.systemId).then(function(res){
          _this.allIdList = res
          let notChooseNum = _this.tableConfig.tableContentArea.selectionNotChooseList.length
          _this.tableConfig.tableContentArea.allDataNum = res.length - notChooseNum
          _this.$refs.csTable.refreshTableTip()
        })
      }else if(_this.tableConfig.tableContentArea.isChooseAllSelect && _this.filterModel.filterGroupModel[0].filterFields.length){
        let postData = {
          filterModel: _this.filterModel,
          systemId: CloudServiceCommon.Props.systemId
        };
        CoreAPI.getAuthorizeRoleList(postData).then(function(res) {
          _this.allIdList = []
          if(res && res.length) {
            res.forEach(function(target) {
              _this.allIdList.push(target.id)
            })
          }
          let notChooseNum = _this.tableConfig.tableContentArea.selectionNotChooseList.length
          _this.tableConfig.tableContentArea.allDataNum = res.length - notChooseNum
          _this.$refs.csTable.refreshTableTip()
        })
      }else{
        _this.tableConfig.tableContentArea.allDataNum = val.length == 0 ? val.length : _this.multipleSelection.length
        _this.$refs.csTable.refreshTableTip()
      }
    },
    handleSelectAll(val) {
      console.log(val)
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    showMenuAuthorizationDialog(row) {
      let _this = this;
      console.log(row)
      _this.isBatch = 1;
      _this.roleIdList = [row.id]
      _this.roleId = row.id
      _this.menuIdList = [];
      _this.menuAuthorizationFlag = true;
    },
    showBatchMenuAuthorizationDialog() {
      let _this = this;
      _this.isBatch = 0;
      _this.menuIdList = [];
      _this.roleId = '0';
      _this.roleIdList = []
      if(_this.tableConfig.tableContentArea.isChooseAllSelect) {
        let nowAllIds = JSON.parse(JSON.stringify(_this.allIdList))
        if(_this.tableConfig.tableContentArea.selectionNotChooseList && _this.tableConfig.tableContentArea.selectionNotChooseList.length) {
          _this.tableConfig.tableContentArea.selectionNotChooseList.forEach(function(item) {
            nowAllIds.indexOf(item) != '-1' ? nowAllIds.splice(nowAllIds.indexOf(item), 1) : ''
          })
        }
        _this.roleIdList = nowAllIds
      }else{
        _this.multipleSelection.forEach(function(item) {
          _this.roleIdList.push(item.id)
        })
      }
      console.log(_this.roleIdList)
      _this.menuAuthorizationFlag = true;
    },
    codeTableBlur() {
      return new Promise(function (resolve) {
        resolve(true);
      });
    },
    inputUpdateVerify(value, item) {
      let _this = this;
      let verificationVal = true;
      return new Promise(function (resolve) {
        switch (item.prop) {
          case "name":
            if (value == "" || !value) {
              _this.$message.error(
                _this.$t("cs.common.verification.verifyIsNull", {
                  verifyName: `【${_this.$t(
                    "cs.common.text.roleName"
                  )}】`
                })
              );
              verificationVal = false;
            } else if (CloudServiceCommon.Methods.getRealLength(value) > 100) {
              _this.$message.error(
                _this.$t("cs.common.verification.verifyLength", {
                  verifyName: `【${_this.$t(
                    "cs.common.text.roleName"
                  )}】`,
                  total: 50
                })
              );
              verificationVal = false;
              // } else if (CloudServiceCommon.Methods.isContainSpecialChar(value)) {
              //     //验证不能是特殊字符
              //     _this.$message.error(
              //         _this.$t("cs.common.verification.verifySpecialCharacters", {
              //             verifyName: `【${_this.$t("cs.collection.collectionTools.templateName")}】`
              //         })
              //     );
              //     verificationVal = false;
            }
            break;
          default:
            break;
        }
        resolve(verificationVal);
      });
    },
    //失去焦点
    leaveCurrentRowFunc(row, isNowAdd) {
      let _this = this;
      return new Promise(function (resolve) {
        if (isNowAdd) {
          let fileMsg = _this.addVerify(row);
          if (fileMsg) {
            let postData = {
                "name": row.name,
                "systemId": CloudServiceCommon.Props.systemId,
                "description": "",
                "isDefault": 0,
                "userIdRecord": CloudServiceCommon.User.userId,
                "orgIdRecord": CloudServiceCommon.User.organizationId
            };
            CoreAPI.addAuthorizeRole(postData).then(
              function (addResault) {
                if (addResault) {
                    _this.$message({
                        type: "success",
                        message: _this.$t(
                        "cs.common.message.operationSuccessConfirmation",
                        {
                            operate: _this.$t("cs.common.button.add")
                        }
                        )
                    });
                    _this.tableDataInitItem = {
                        name: "",
                        customRowConfigData: {
                        }
                    }
                    _this.infiniteScrollLoadDataIndex = 0;
                    _this.tableConfig.infiniteScrollLoadDataDisable = false;
                    _this.infiniteScrollLoadDataAntiShake = false;
                    _this.getAuthorizeRoleList(false);
                    resolve(true);
                }
              },
              function (error) {
                _this.$message.error(error.msg);
                resolve(false);
              }
            );
          } else {
            resolve(false);
          }
        } else {
          var isPass = true;
          for (let key in row.customRowConfigData.inputIsPassList) {
            // 如果值为false  则说明有验证未通过的输入框
            if (!row.customRowConfigData.inputIsPassList[key]) {
              isPass = false;
              resolve(false);
              break;
            }
          }
          // 单元格都验证通过  返回true
          if (isPass) {
            _this.updateAuthorizeRoleFunc(row, resolve);
          }
        }
      });
    },
    updateAuthorizeRoleFunc(row, resolve) {
      let _this = this;
      var updatePostData = {
        "id": row.id,
        "name": row.name,
        "code": row.name,
        "systemId": CloudServiceCommon.Props.systemId,
        "description": row.description,
        "userIdRecord": row.userIdRecord,
        "orgIdRecord": row.orgIdRecord
      }
      CoreAPI.updateAuthorizeRole(updatePostData).then(function () {
        _this.$message({
          type: "success",
          message: _this.$t('cs.common.message.operationSuccessConfirmation', {
            operate: _this.$t('cs.common.button.save')
          })
        });

        if (resolve) {
          resolve(true)
        }
      }, function (reject) {
        _this.$message.error(reject.msg)
        resolve(false)
      })
    },
    addTemplate(val) {
      let _this = this;
      _this.tableDataInitItem = {
        name: "",
        customRowConfigData: {
            alwaysShowInputBox: true
        }
      }
        _this.tableData.unshift(_this.tableDataInitItem);
        _this.$refs.csTable.addStart(val.event);
      
    },
    //列表添加和修改时的验证方法
    addVerify(row) {
      // let id = row.id;
      let templateName = row.name;

      if (templateName == "" || !templateName) {
        this.$message.error(
          this.$t("cs.common.verification.verifyIsNull", { verifyName: `【${this.$t("cs.common.text.roleName")}】` })
        );
        return;
      }
      if (CloudServiceCommon.Methods.getRealLength(templateName) > 100) {
        this.$message.error(
          this.$t("cs.common.verification.verifyLength", {
            verifyName: `【${this.$t("cs.common.text.roleName")}】`,
            total: 50
          })
        );
        return;
      }
      return true;
    },
    //删除所选操作
    removeTemplate() {
      let _this = this;
      this.$confirm(
        _this.$t("cs.common.message.operationConfirmation", {
          operate: _this.$t("cs.common.button.delete")
        }),
        _this.$t("cs.common.text.tips"),
        {
          type: "warning",
          closeOnClickModal: false,
          closeOnPressEscape: false
        }
      ).then(() => {
        var postData = CloudServiceCommon.Methods.commonDeleteParameter({
          tableConfig: _this.tableConfig,
          filterModel: _this.filterModel,
          selectList: _this.multipleSelection,
          target: 'id'
        })
        postData.systemId = CloudServiceCommon.Props.systemId
        CoreAPI.batchDeleteAuthorizeRole(postData).then(function (delReasult) {
          if (delReasult) {
            _this.multipleSelection.forEach(item => {
              _this.tableData = _this.tableData.filter(items => items.id != item.id);
              _this.tableConfig.tableContentArea.selectionList = _this.tableConfig.tableContentArea.selectionList.filter(items => items.id != item.id);
            });
            _this.tableConfig.tableContentArea.isChooseAllSelect = false;
            _this.tableConfig.tableContentArea.selectionNotChooseList = []
            // _this.infiniteScrollLoadDataIndex = 0;
            // _this.tableConfig.infiniteScrollLoadDataDisable = false;
            // _this.infiniteScrollLoadDataAntiShake = false;
            // _this.getExcelTemplatesResault(false)
            _this.$message({
              type: "success",
              message: _this.$t("cs.common.message.operationSuccessConfirmation", {
                operate: _this.$t("cs.common.button.delete")
              })
            });
          }
        })
      });
    },
    //查询
    listSearch(searchValue) {
      // _this.getExcelTemplates(res,true)
      let _this = this;
      _this.filterModel.filterGroupModel[0].filterFields = []
      if (searchValue.filterGroupModel[0].filterFields.length) {
        searchValue.filterGroupModel[0].filterFields.forEach(item => {
          _this.filterModel.filterGroupModel[0].filterFields.push(item)
        })
      // 查询返回的过滤模型如果为空则初始化过滤模型字段
       } else if (!searchValue.filterGroupModel[0].filterFields.length && _this.filterModel.filterGroupModel[0].filterFields.length>0){
        // _this.filterModel.filterGroupModel[0].filterFields = [_this.filterModel.filterGroupModel[0].filterFields[0]]
        _this.filterModel.filterGroupModel[0].filterFields = []
      }
      
      _this.infiniteScrollLoadDataIndex = 0;
      _this.tableConfig.infiniteScrollLoadDataDisable = false;
      _this.infiniteScrollLoadDataAntiShake = false;
      _this.multipleSelection = []
      _this.tableConfig.tableContentArea.allDataNum && _this.$refs.csTable.refreshTableTip()
      _this.tableConfig.tableContentArea.allDataNum = 0
      _this.getAuthorizeRoleList(false)
      this.tableConfig.tableContentArea.isChooseAllSelect = false;
      this.tableConfig.tableContentArea.selectionNotChooseList = [];
      this.multipleSelection = [];
    },
    rolePeopleFunc(row, item) {
      let _this = this;
      _this.lookPeopleList = row.roleUserList ? JSON.parse(JSON.stringify(row.roleUserList)) : []
      _this.roleId = row.id
      _this.roleNode = row
      _this.lookAllPeopleTitle = `【${row.name}】${_this.$t('cs.authorityManage.authorization.rolePersonnel')}`
      _this.lookPeopleFlag = true;
    },
    addRolePeopleFunc(row, item) {
      let _this = this;
      _this.roleUserList = row.roleUserList ? JSON.parse(JSON.stringify(row.roleUserList)) : []
      _this.roleId = row.id
      _this.roleNode = row
      _this.selectUserFlag = true;
    },
    deleteRolePeopleFunc(row, item, roleItem) {
      row.roleUserList.forEach(function(target, index) {
        if(target.participationUserId == roleItem.participationUserId) {
          row.roleUserList.splice(index, 1)
        }
      })
      let postData = {
        "roleId": row.id,
        "userList": row.roleUserList,
        "userIdRecord": CloudServiceCommon.User.userId,
        "orgIdRecord": CloudServiceCommon.User.organizationId
      }
      CoreAPI.addAuthorizeRoleUser(postData).then(function(res){
        console.log(res)
      })
    },
    closeDialog() {
      let _this = this;
      _this.selectUserFlag = false;
    },
    closePeopleDialog() {
      let _this = this;
      _this.lookPeopleFlag = false;
    },
    submitLookPeople() {
      let _this = this;
      console.log(_this.lookPeopleList)
      let postData = {
        "roleId": this.roleId,
        "userList": this.lookPeopleList,
        "userIdRecord": CloudServiceCommon.User.userId,
        "orgIdRecord": CloudServiceCommon.User.organizationId
      }
      CoreAPI.addAuthorizeRoleUser(postData).then(function(res){
        _this.lookPeopleFlag = false;
        _this.infiniteScrollLoadDataIndex = 0;
        _this.tableConfig.infiniteScrollLoadDataDisable = false;
        _this.infiniteScrollLoadDataAntiShake = false;
        _this.getAuthorizeRoleList(false);
      })
    },
    submit() {
      console.log(this.roleUserList)
    },
    submitChooseRole() {
      console.log(this.roleUserList)
      let _this = this;
      let postData = {
        "roleId": this.roleId,
        "userList": this.roleUserList,
        "userIdRecord": CloudServiceCommon.User.userId,
        "orgIdRecord": CloudServiceCommon.User.organizationId
      }
      CoreAPI.addAuthorizeRoleUser(postData).then(function(res){
        _this.selectUserFlag = false;
        _this.infiniteScrollLoadDataIndex = 0;
        _this.tableConfig.infiniteScrollLoadDataDisable = false;
        _this.infiniteScrollLoadDataAntiShake = false;
        _this.getAuthorizeRoleList(false);
      })
    },
    dataAuthorizationFunc(row) {
      let _this = this;
      console.log(row)
      _this.isBatch = 1;
      _this.roleIdList = [row.id]
      _this.roleId = row.id
      _this.authorityDataCategoryList = [];
      _this.dataAuthorizationFlag = true;
    },
    showBatchDataAuthorizationDialog(row) {
      let _this = this;
      _this.isBatch = 0;
      _this.authorityDataCategoryList = [];
      _this.roleId = '0';
      _this.roleIdList = []
      _this.multipleSelection.forEach(function(item) {
        _this.roleIdList.push(item.id)
      })
      _this.dataAuthorizationFlag = true;
    },
    clearRoleUserList() {
      let _this = this;
      if(_this.roleNode.isDefault) {
        for(var i = 0; i < _this.roleUserList.length; i++) {
          if(_this.roleUserList[i].participationUserId != '672888303978721280') {
            _this.roleUserList.splice(i, 1)
            i--
          }
        }
      }else{
        _this.roleUserList = []
      }
    },
    closeDataAuthorizationDialog(){
      let _this = this;
      _this.dataAuthorizationFlag = false;  
    },
    closeMenuAuthorizationDialog(){
      let _this = this;
      _this.menuAuthorizationFlag = false;  
    },
    submitDataAuthorizationDialog(){
      let _this = this;
      // 判断数据授权返回的数据是不是空权限
      _this.authorityDataCategoryList.forEach(function(target) {
          if(target.dataAuthorityItemList && target.dataAuthorityItemList.length) {
              let hasAuthorize = false;
              target.dataAuthorityItemList.forEach(function(item){
                  if(item.funcCodeList.length) {
                      hasAuthorize = true
                  }
              })
              !hasAuthorize ? target.dataAuthorityItemList = [] : ''
          }
      })
      let postData = {
        "systemId": CloudServiceCommon.Props.systemId,
        "authorityType": 1,
        "isBatch": _this.isBatch,
        "authorityDataCategoryList": _this.authorityDataCategoryList,
        "roleIdList": _this.roleIdList,
        "userIdList": [],
        "orgIdList": [],
        "userIdRecord": CloudServiceCommon.User.userId,
        "orgIdRecord": CloudServiceCommon.User.organizationId
      }
      CoreAPI.saveDataAuthority(postData).then(function(res) {
        _this.infiniteScrollLoadDataIndex = 0;
        _this.tableConfig.infiniteScrollLoadDataDisable = false;
        _this.infiniteScrollLoadDataAntiShake = false;
        _this.getAuthorizeRoleList(false);
        _this.dataAuthorizationFlag = false;  
      })
    },
    submitMenuAuthorizationDialog(){
      let _this = this;
      let postData = {
        "systemId": CloudServiceCommon.Props.systemId,
        "authorityType": 1,
        "isBatch": _this.isBatch,
        "authItemIdList": _this.menuIdList,
        "roleIdList": _this.roleIdList,
        "userIdList": [],
        "orgIdList": [],
        "userIdRecord": CloudServiceCommon.User.userId,
        "orgIdRecord": CloudServiceCommon.User.organizationId
      }
      CoreAPI.saveAuthority(postData).then(function(res) {
        _this.menuAuthorizationFlag = false;  
        // if(_this.menuIdList.length > 0) {
          // !_this.isBatch ? console.log('批量') : console.log(‘单个’)
          _this.infiniteScrollLoadDataIndex = 0;
          _this.tableConfig.infiniteScrollLoadDataDisable = false;
          _this.infiniteScrollLoadDataAntiShake = false;
          _this.getAuthorizeRoleList(false);
        // }
      })
    },
    getAuthorityDataCategoryBySystemId: function() {
      let _this = this;
      CoreAPI.getAuthorityDataCategoryBySystemId(CloudServiceCommon.Props.systemId).then(function (res) {
          if(res && res.length) {
              _this.tableConfig.tableContentArea.columns.push(
                  {
                    label: "cs.authorityManage.authorization.dataAuthorization",
                    type: "link",
                    iconName: "el-icon-key",
                    width: 180,
                    minWidth: 180,
                    align: "left",
                    linkList: [
                      {
                        linkName: "cs.authorityManage.authorization.unauthorized,cs.authorityManage.authorization.authorized", // 链接名称  对应数据的属性名称
                        color: "#303133,#1890ff",
                        prop: "isDataAuthority",
                        clickFunc: _this.dataAuthorizationFunc
                      }
                    ],
                    underline: false
                  }
              )
              _this.tableConfig.operationArea.buttonList.push({
                  prop: "cs.authorityManage.authorization.batchDataAuthorization", // 按钮名称
                  disabled: true, // 是否禁用
                  clickFunc: _this.showBatchDataAuthorizationDialog // 点击事件
              })
          }
          _this.loadTree = true;
      }).catch(err => {
          _this.loadTree = true;
          if (err.code) {
              this.$message.error(
                  this.$t(`cs.common.errorCode.${err.code}`).indexOf(err.code) == -1 ? this.$t(`cs.common.errorCode.${err.code}`) : err.msg
              );
          }
          CloudServiceCommon.Log.debug(err);
      });
    }
  },
  created() {
    let _this = this;
    _this.getAuthorityDataCategoryBySystemId();
  }
};
</script>
<style lang="less" scoped>
.role-authorization {
  /deep/.custom-class { 
    .el-drawer__body {
      padding: 0 25px;
    }
    .dialog-footer {
      margin-bottom: -32px;
      padding: 20px 32px;
      width: 100%;
      box-sizing: border-box;
      padding: 10px 20px 20px;
      text-align: right;
      padding-right: 0;
    }
  }
  /deep/.el-drawer__header {
    padding: 20px 24px 0;
    height: 64px;
    margin-bottom: 12px;
    padding-top: 0;
  }
  /deep/.el-drawer__header>:first-child {
    color: #303133;
    font-size: 18px;
  }
  /deep/.menu-authorization-dialog-main  .el-tree--highlight-current div.el-tree-node.is-current>.el-tree-node__content {
    color: #606266;
  }
  /deep/div.table .el-table td {
    padding: 24px 0;
  }
}
</style>