<template>
  <div class="fullHeight">
    <div class="rightPanel whiteBlock" v-if="safetyRiskDetailShow == 0">
      <div>
        <div class="sidebar_btn">
          <p class="pageTitle">人员出勤设置</p>
        </div>
        <el-collapse v-model="activeNames">
          <el-collapse-item title="自动退场设置" name="1">
            <div class="collapse-box2">
              <div class="collapse-box">
                <div>
                  <el-select
                    filterable
                    multiple
                    collapse-tags
                    :clearable="true"
                    v-model="dangerReviewInfo.enterpriseIds"
                    placeholder="全部企业"
                    @change="changeCompany"
                    size="medium"
                  >
                    <el-option
                      :label="item.enterpriseName"
                      :value="item.id"
                      v-for="item in enterpriseListData"
                      :key="item.id"
                    ></el-option>
                  </el-select>
                  <el-select
                    filterable
                    multiple
                    collapse-tags
                    :clearable="true"
                    v-model="dangerReviewInfo.teamIds"
                    size="medium"
                    placeholder="全部班组"
                  >
                    <el-option
                      :label="item.teamName"
                      :value="item.id"
                      v-for="item in teamListData"
                      :key="item.id"
                    ></el-option>
                  </el-select>
                  <el-select
                    filterable
                    multiple
                    collapse-tags
                    :clearable="true"
                    v-model="dangerReviewInfo.departmentIds"
                    size="medium"
                    placeholder="全部部门"
                  >
                    <el-option
                      :label="item.departmentName"
                      :value="item.id"
                      v-for="item in departmentListData"
                      :key="item.id"
                    ></el-option>
                  </el-select>
                  <el-select
                    filterable
                    multiple
                    collapse-tags
                    :clearable="true"
                    v-model="dangerReviewInfo.workerIds"
                    size="medium"
                    placeholder="全部人员"
                  >
                    <el-option
                      :label="item.workerName"
                      :value="item.workerId"
                      v-for="item in projectChilderUserList"
                      :key="item.workerId"
                    ></el-option>
                  </el-select>
                </div>
                <div>
                  <div>人员未打卡超过</div>
                  <el-input-number
                    size="medium"
                    :controls="false"
                    v-model="dangerReviewInfo.exitIfAbsenceDay"
                    controls-position="right"
                    placeholder="请输入"
                  ></el-input-number>
                  <div>天系统将自动将人员退场</div>
                </div>
              </div>
              <div>
                <el-button
                  size="medium"
                  type="primary"
                  @click="saveConfigClick(1)"
                  >保存</el-button
                >
                <div>
                  <el-switch v-model="dangerReviewInfo.enable"></el-switch>
                </div>
              </div>
            </div>
            <div>
              是否将此处退场人员拉入黑名库
              <el-checkbox v-model="dangerReviewInfo.enableBlack"></el-checkbox>
            </div>
            <div class="collapse-box1">
              <div><i class="el-icon-warning-outline"></i></div>
              <div>
                此设置默认关闭，启用此设置后，系统定时检测当指定人员超过指定天数未有考勤记录上传时，则自动退场人员，再次进场需手动处理。
              </div>
            </div>
          </el-collapse-item>
        </el-collapse>
      </div>
    </div>
  </div>
</template>
<script>
import { getDictionaryItemApi } from "@/assets/js/api/companyDiagram";
import {
  saveWorkerExitConfigApi,
  getWorkerExitConfigListApi,
} from "@/assets/js/api/safeManage";
import {
  getProjectChilderSystemUserPageListApi,
  getProjectChilderSystemUserListApi,
} from "@/assets/js/api/configManage.js";
import {
  getDepartmentInfoList,
  getTeamInfoList,
  getEnterpriseInfoList,
  getEnterpriseTypeList,
} from "@/assets/js/api/laborPerson";
export default {
  data() {
    return {
      pageInfo: {
        pageNo: 1, //页数
        pageSize: 10, //条数
        total: 0, //总条数
      },
      riskListForm: {
        region: "",
        name: "",
      },
      defaultExpandAll: false,
      projectSn: "",
      riskDialogVisible: false,
      riskDialogLoading: false,
      riskDialogTitle: "",
      riskDialogForm: {
        nodeName: "",
        driverType: 3,
      },
      riskDialogFormRules: {
        nodeName: [
          { required: true, message: "请输入节点名称", trigger: "blur" },
        ],
      },
      safetyRiskDetailShow: 0,
      activeNames: [],
      dangerReviewInfo: {
        exitIfAbsenceDay: "",
        enable: false,
        enableBlack: false,
        enterpriseIds: [],
        teamIds: [],
        departmentIds: [],
        workerIds: [],
      },
      enterpriseListData: [],
      teamListData: [],
      departmentListData: [],
      projectChilderUserList: [],
    };
  },
  created() {
    this.projectSn = this.$store.state.projectSn;
    this.getXzSecurityDangerReviewVerifyList();
    this.getCompanyList();
    this.getTeamList();
    this.getDepartmentList();
    this.getUpdatePersonListFn();
  },
  mounted() {},
  methods: {
    getXzSecurityDangerReviewVerifyList() {
      getWorkerExitConfigListApi({
        sn: this.projectSn,
        companyProjectType: 2,
      }).then((res) => {
        if (res.code == 200) {
          if (!res.result || res.result.length == 0) return;
          const data = res.result[0];
          this.dangerReviewInfo = {
            ...data,
            enable: data.enable == 1 ? true : false,
            enableBlack: data.enableBlack == 1 ? true : false,
            enterpriseIds: data.enterpriseIds
              ? data.enterpriseIds.split(",")
              : [],
            teamIds: data.teamIds ? data.teamIds.split(",") : [],
            departmentIds: data.departmentIds
              ? data.departmentIds.split(",")
              : [],
            workerIds: data.workerIds ? data.workerIds.split(",") : [],
          };
        }
      });
    },
    saveConfigClick(type) {
      let params = {
        ...this.dangerReviewInfo,
        enable: this.dangerReviewInfo.enable ? 1 : 0,
        enableBlack: this.dangerReviewInfo.enableBlack ? 1 : 0,
        enterpriseIds: this.dangerReviewInfo.enterpriseIds.join(","),
        teamIds: this.dangerReviewInfo.teamIds.join(","),
        departmentIds: this.dangerReviewInfo.departmentIds.join(","),
        workerIds: this.dangerReviewInfo.workerIds.join(","),
        projectSn: this.projectSn,
      };
      saveWorkerExitConfigApi(params).then((res) => {
        console.log(res);
        if (res.code && res.success) {
          // '保存成功！'
          this.$message.success(this.$t("message.highModulus.saveSuccessMsg"));
          this.getXzSecurityDangerReviewVerifyList();
        }
      });
    },
    handleValue(val) {
      this.safetyRiskDetailShow = val;
    },
    changeCompany() {
      this.dangerReviewInfo.departmentIds = [];
      this.dangerReviewInfo.teamIds = [];
      this.dangerReviewInfo.workerIds = [];
      this.getDepartmentList();
      this.getTeamList();
      this.getUpdatePersonListFn();
    },
    //获取所属 企业下拉
    getCompanyList() {
      let data = {
        projectSn: this.projectSn,
        enterpriseName: "",
        userEnterpriseId: this.$store.state.userInfo.userEnterpriseId,
      };
      getEnterpriseInfoList(data).then((res) => {
        this.enterpriseListData = res.result;
      });
    },
    //获取 部门 列表
    getDepartmentList() {
      let data = {
        enterpriseId: this.dangerReviewInfo.enterpriseIds.join(","),
        projectSn: this.projectSn,
      };
      getDepartmentInfoList(data).then((res) => {
        this.departmentListData = res.result.list;
      });
    },
    //获取企业的 - 班组列表
    getTeamList() {
      let data = {
        enterpriseId: this.dangerReviewInfo.enterpriseIds.join(","),
        projectSn: this.projectSn,
      };
      getTeamInfoList(data).then((res) => {
        this.teamListData = res.result.list;
      });
    },
    // 分页获取人员列表信息
    getUpdatePersonListFn() {
      let data = {
        projectSn: this.$store.state.projectSn,
        enterpriseId: this.dangerReviewInfo.enterpriseIds.join(","),
        pageNo: 1,
        pageSize: -1,
        // departmentTeamName: this.dealForm.departmentTeamName,
      };
      getProjectChilderSystemUserPageListApi(data).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.projectChilderUserList = res.result.records;
        }
      });
    },
  },
  watch: {},
};
</script>
<style lang="less" scoped>
/deep/ .el-collapse {
  .collapse-box1 {
    display: flex;
    font-size: 14px;
    // padding-top: 20px;
    > div:last-child {
      margin-left: 4px;
    }
    > div {
      color: #ffa026;
    }
  }
  .collapse-box2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    > div:last-child {
      display: flex;
      align-items: center;
      > div:last-child {
        display: flex;
        align-items: center;
        .el-switch {
          margin: 0 15px;
        }
      }
    }
    .collapse-box {
      display: flex;
      align-items: center;
      font-size: 14px;
      > div:last-child {
        display: flex;
        align-items: center;
        margin-left: 50px;
        flex: 1;
        .el-input-number {
          width: 192px;
          margin: 0 10px 0 8px;
        }
      }
      > div:first-child {
        display: flex;
        align-items: center;
        .el-select {
          width: 200px;
          margin-right: 16px;
        }
        .el-switch {
          margin: 0 14px;
        }
      }
    }
  }

  .el-collapse-item__header {
    padding: 10px 15px;
    font-size: 16px;
    height: initial;
    line-height: initial;
  }
  .el-collapse-item__wrap {
    padding: 10px 15px;
    background-color: #fafafa;
  }
  .el-collapse-item__content {
    padding-bottom: 10px;
  }
}
.tables-box {
  .table_box:nth-child(odd) {
    background-color: #f5f7fa;
  }
  .table_box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
  }
}

.check_box {
  display: flex;
  font-size: 14px;
  > .el-button:hover {
    color: #5181f6 !important;
  }
  > .el-button {
    padding: 0;
    margin-left: 10px;
  }
  > .el-button:first-child {
    color: #eb4047;
  }
}
.dialog-style {
  .el-input {
    width: 220px;
  }
  .el-form-item {
    margin-bottom: 10px;
  }
}
.sidebar_btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  padding-left: 15px;
  padding-top: 20px;
  .el-button + .el-button {
    margin-left: 8px;
  }
}
.el-form-item--mini.el-form-item {
  margin-bottom: 8px;
}
.flex() {
  display: flex;
  align-items: center;
}
.treeStyle() {
  /deep/.el-tree {
    font-size: 15px;
    width: 100%;
    background-color: transparent;
    .el-tree-node {
      white-space: normal;
      &:focus > .el-tree-node__content {
        background-color: transparent;
      }
      &.is-current > .el-tree-node__content {
        background-color: rgba(81, 129, 246, 0.14);
        color: #5181f6;
      }
    }
    .el-tree-node__content {
      // height: 32px;
      padding: 7px 0;
      height: auto;
      line-height: 16px;
      position: relative;
      // margin-bottom: 7px;
      &:hover {
        background-color: rgba(81, 129, 246, 0.14);
        color: #5181f6;
      }

      .videoName {
        font-size: 14px;
      }
      .projectName {
        font-size: 14px;
        width: calc(100% - 55px);
        display: inline-block;
      }
      .companyName2 {
        font-size: 16px;
        font-weight: bold;
        display: inline-block;
        width: 192px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .el-tree-node__expand-icon {
      font-size: 16px;
      padding: 0 6px;
      &.is-leaf {
        color: transparent !important;
      }
    }
    .treeTitle {
      background-color: #f7f7f7;
      margin-bottom: 10px;
    }
  }
}
.custom-tree-node {
  width: 100%;
}

.projectName {
  // color: #191e3d;
  //   font-size: 15px;
  //   margin-bottom: 8px;
  //   font-weight: 500;
}

.el-icon-view {
  font-size: 16px;
  width: 16px;
  height: 16px;
  margin-left: 10px;
  vertical-align: top;
  display: none;
  position: absolute;
  bottom: 10px;
  right: 10px;
}

.avatar-uploader {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  // overflow: hidden;
  height: 178px;
}

.avatar-uploader:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

.imgBox {
  position: relative;
  .el-icon-error {
    font-size: 20px;
    position: absolute;
    right: -10px;
    top: -10px;
    cursor: pointer;
  }
}

/deep/ .projectDialog .el-dialog {
  margin-top: 20px !important;
  margin-bottom: 0;
  .el-input--medium .el-input__inner {
    // height: 65px;
  }
}
.el-icon-setting {
  font-size: 15px;
  color: #8eb0fa;
}
.tableBtns .el-icon-setting {
  margin-right: 6px;
}
.CheckboxTitle {
  font-size: 14px;
  width: 100%;
  padding: 15px;
}
.zdy-checkbox {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  > label {
    width: 30%;
  }
}
.el-checkbox {
  width: 46%;
  margin: 10px 0;
}

.areaTreeBox {
  float: left;
  position: relative;
  .treeStyle();
}

.areaTreeInner {
  //   background-color: rgba(0, 0, 0, 0.7);
  width: 300px;
  padding: 20px 15px;
  height: calc(100% - 40px);
}
.treeBox {
  height: calc(100% - 42px - 66px - 32px);
  background-color: rgba(216, 216, 216, 0.2);
  padding-top: 10px;
}
.rightPanel {
  float: left;
  width: calc(100%);
  padding: 0 0 20px;
  height: calc(100% - 20px);
  .tabs-content {
    height: calc(100% - 95px);
    /deep/.el-tabs__content {
      height: calc(100% - 50px);
      .el-tab-pane {
        height: 100%;
      }
    }
  }
  .pagerBox {
    margin-top: 18px;
  }
  .pageTitle {
    padding-left: 0.9375rem;
  }
}
.operateBtns {
  float: right; //向右浮动

  i {
    margin-right: 10px;
    cursor: pointer;
  }
}
.plusBtn {
  float: right;
  background-color: #409eff;
  color: white;
  padding: 2px 6px;
  border-radius: 3px;
  margin-top: -6px;
  cursor: pointer;
}
.operation-style {
  .flex();
  justify-content: center;
  .operationText:not(:last-child) {
    margin-right: 10px;
  }
}
.add {
  display: flex;
  align-items: center;
  cursor: pointer;
  :nth-child(2) {
    margin-left: 5px;
  }
}
.select {
  display: flex;
  width: 500px;
  max-height: 380px;
  flex-wrap: wrap;
  align-items: center;
  overflow: auto;
  // div{
  //   margin: 3px 15px;
  // }
  .el-tag {
    margin: 5px 10px;
  }
}
.select::-webkit-scrollbar {
  background-color: rgb(132, 132, 133);
  width: 4px;
}
.select::-webkit-scrollbar-thumb {
  background-color: rgb(80, 78, 252);
}
/deep/ .el-transfer__buttons {
  display: none;
}
/deep/ .el-transfer-panel {
  width: 200px;
  margin: 5px 22px;
}
.leftSelect {
  width: 230px;
  height: 300px;
  display: inline-block;
  position: relative;
  margin: 5px 15px 5px 0;
  border: 1px solid #f4f2f4;
  .title {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding-left: 20px;
    background-color: #f5f5f5;
  }
  .el-autocomplete {
    position: absolute;
    top: 50px;
    left: 25px;
    right: 30px;
    /deep/ .el-input--medium .el-input__inner {
      border-radius: 10px;
      padding: 0 10px;
    }
  }

  .el-checkbox-group {
    height: 190px;
    width: 90%;
    overflow: auto;
    position: absolute;
    top: 95px;
    left: 25px;
    .el-checkbox {
      display: block;
      margin: 0;
    }
  }
  .el-checkbox-group::-webkit-scrollbar {
    background-color: #fff;
    width: 4px;
    border-radius: 5px;
  }
  .el-checkbox-group::-webkit-scrollbar-thumb {
    background-color: #e0e1e3;
    border-radius: 5px;
  }
}
.rightSelect {
  width: 230px;
  height: 300px;
  display: inline-block;
  position: relative;
  margin: 5px 10px 5px 0;
  border: 1px solid #f4f2f4;
  .title {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding-left: 20px;
    background-color: #f5f5f5;
  }
  .rightAllSelect {
    width: 100%;
    height: 230px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 50px;
    .selectItem {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      span {
        margin-left: 30px;
      }
      img {
        cursor: pointer;
        display: none;
        margin-right: 20px;
      }
    }
    .selectItem:hover {
      background-color: #ecf4fd;
    }
    .selectItem:hover img {
      display: inline-block;
    }
  }
  .rightAllSelect::-webkit-scrollbar {
    background-color: #fff;
    width: 4px;
    border-radius: 5px;
  }
  .rightAllSelect::-webkit-scrollbar-thumb {
    background-color: #e0e1e3;
    border-radius: 5px;
  }
}
.select-content {
  box-sizing: border-box;
  height: 34px;
  line-height: 34px !important;
  border-radius: 3px;
  border: 1px solid #d7dbe9;
  padding: 0 15px;
  position: relative;
  .tip-text {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
  }
  .select-list {
    width: 100%;
    position: absolute;
    top: 34px;
    left: -3px;
    z-index: 10;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 4px 4px 10px #e3e3e3;
    padding-top: 10px;
    &-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }
}
// 账号审核弹框样式
.auditDialog /deep/ .el-dialog__body {
  padding: 0px;
}
.dialog_content {
  padding: 0px;
  .dialog_content-part {
    padding: 0px 25px;
    .dialog-tip {
      .flex();
      margin-bottom: 5px;
      .el-icon-warning-outline {
        color: #eb474f;
      }
      span {
        color: #eb4047;
        margin-left: 3px;
      }
    }
    .dialog-search {
      .flex();
      span {
        font-family: Source Han Sans CN, Source Han Sans CN;
        font-weight: 500;
        font-size: 16px;
        color: #272d45;
        margin-right: 10px;
        margin-left: 10px;
      }
    }
    .dialog-tree {
      margin: 10px 0px;
      .treeStyle();
      /deep/.el-tree-node__content {
        position: relative;
      }
      /deep/.el-tree-node__content > label.el-checkbox {
        position: absolute;
        right: 0;
      }
    }
  }
  .relative-group {
    height: 60px;
    line-height: 60px;
    border-top: 1px solid #d8dbe8;
  }
}
</style>
