<style>
  .examConfig .Period-rules {
    display: flex;
    margin-bottom: 24px;
    padding-left: 20px;
  }

  .examConfig .Period_Spreate {
    flex: 1;
    width: 50%;
    min-width: 400px;
    margin-right: 32px;
  }

  .examConfig .Period-rule-title {
    color: #646a73;
    margin-bottom: 4px;
    white-space: nowrap;
  }

  .examConfig .Period-info-icon {
    margin-left: 8px;
    color: #8f959e;
    line-height: 1;
    vertical-align: top;
  }

  .process_Btn_List {
    display: flex;
    justify-content: flex-end;
    padding: 20px;
  }

  .processBtn_Cancel {
    width: 90px;
    height: 35px;
    border: 1px solid #a1aab2;
    color: #000000;
    background-color: #fff;
    text-align: center;
    line-height: 35px;
    border-radius: 5px;
    cursor: pointer;
    margin-right: 20px;
  }

  .processBtn_Save {
    width: 90px;
    height: 35px;
    background-color: #2961fe;
    color: #fff;
    text-align: center;
    line-height: 35px;
    border-radius: 5px;
    cursor: pointer;
  }

  .baseSetForm_Dialog {
    margin: 20px;
  }

  .examConfig_title {
    font-size: 14px;
    color: #1f2329;
    margin-bottom: 20px;
  }

  .Period-alert {
    padding: 9px 16px;
    border-radius: 4px;
    background-color: #f0f4ff;
    line-height: 22px;
    color: #1f2329;
    display: flex;
    align-items: center;
    margin-top: 20px;
    margin-bottom: 12px;
    font-size: 13px;
  }

  .Okr_Length {
    font-weight: 500;
    color: #1f2329;
  }

  .FormItem-asterisk {
    position: relative;
    top: 3px;
    margin-left: 3px;
    color: #f54a45;
    line-height: 1;
  }

  .baseSetForm_Dialog .el-radio {
    display: block;
    margin-bottom: 15px;
  }

  .exam-tip {
    white-space: nowrap;
    font-size: 10px;
    color: #A8A8B3;
    margin-top:5px;
  }

</style>
<template>
  <div class="page-body">
    <div class="examConfig">
      <div style="text-align: right">
        <q-btn color="accent" size="sm" class="q-mr-md" @click="geteject" label="修改基础配置" />
      </div>
      <div class="Period-rules">
        <div class="Period_Spreate">
          <div class="Period-rule-title">
            <div>是否开启组卷审批</div>
            <div class="exam-tip">开启后教师组卷不能直接生成使用，需要等待主管审核</div>
          </div>
          <div>
            <span v-if="baseObj.IsOpenZuJuan === 1">是</span>
            <span v-if="baseObj.IsOpenZuJuan === 0">否</span>
          </div>
        </div>
        <div class="Period_Spreate col-6">
          <div class="Period-rule-title">
            <div>是否开启自动阅卷</div>
            <div class="exam-tip">考试不能直接发起，需要等待主管审核通过后自动化发布</div>
          </div>
          <div>
            <span v-if="baseObj.IsOpenAutoMarking === 1">是</span>
            <span v-if="baseObj.IsOpenAutoMarking === 0">否</span>
          </div>
        </div>
      </div>
      <div class="Period-rules">
        <div class="Period_Spreate">
          <div class="Period-rule-title">
            <div>是否开启考试申请</div>
            <div class="exam-tip">注意：开启后系统将对所有试卷内的客观题进行自动阅卷</div>
          </div>
          <div>
            <span v-if="baseObj.IsOpenExamApply === 1">是</span>
            <span v-if="baseObj.IsOpenExamApply === 0">否</span>
          </div>
        </div>
        <div class="Period_Spreate" v-if="baseObj.IsOpenZuJuan === 1">
          <div class="Period-rule-title">组卷审核人</div>
          <div>
            {{ baseObj.ZuJuanReviewerName }}
          </div>
        </div>
      </div>
      <div class="Period-rules" v-if="baseObj.IsOpenExamApply === 1">
        <div class="Period_Spreate">
          <div class="Period-rule-title">考试申请审核人</div>
          <div>{{ baseObj.ExamApplyReviewerName }}</div>
        </div>
      </div>
    </div>
    <q-dialog v-model="isShowBaseSet" maximized full-height seamless position="right" @hide="closeProcess">
      <q-card style="margin-top: 61px; width: 500px" class="no-border-radius classinfo_Dialog">
        <div class="baseSetForm_Dialog">
          <div class="cycle_Title">考试配置</div>
          <div class="examConfig_title" style="margin-top:10px;">
            是否开启组卷审批
            <el-switch style="margin-left: 10px" v-model="addMsg.IsOpenZuJuan" :active-value="1" :inactive-value="0"></el-switch>
          </div>
          <div v-if="baseObj.IsOpenZuJuan === 1">
            <q-select filled stack-label :dense="false" v-model="addMsg.ZuJuanReviewer" :options="EmployeeListOption"
              option-value="Id" option-label="EmployeeName" emit-value map-options label="组卷审核人" clearable use-input
              :rules="[(val) => !!val || '请选择组卷审核人']" @filter="filterFn" ref="ZuJuanReviewer">
              <template v-slot:no-option>
                <q-item>
                  <q-item-section class="text-grey">
                    未找到相关数据
                  </q-item-section>
                </q-item>
              </template>
            </q-select>
          </div>
          <div class="examConfig_title">
            是否开启考试申请
            <el-switch style="margin-left: 10px" v-model="addMsg.IsOpenExamApply" :active-value="1" :inactive-value="0"></el-switch>
          </div>
          <div v-if="baseObj.IsOpenExamApply === 1">
            <q-select filled stack-label :dense="false" v-model="addMsg.ExamApplyReviewer" :options="EmployeeListOption"
              option-value="Id" option-label="EmployeeName" emit-value map-options label="考试申请审核人" clearable use-input
              :rules="[(val) => !!val || '请选择考试申请审核人']" @filter="filterFn" ref="ExamApplyReviewer">
              <template v-slot:no-option>
                <q-item>
                  <q-item-section class="text-grey">
                    未找到相关数据
                  </q-item-section>
                </q-item>
              </template>
            </q-select>
          </div>
          <div class="examConfig_title">
            是否开启自动阅卷
            <el-switch style="margin-left: 10px" v-model="addMsg.IsOpenAutoMarking" :active-value="1"
              :inactive-value="0"></el-switch>
          </div>
        </div>
        <div class="process_Btn_List">
          <div class="processBtn_Cancel" @click="closeProcess">关闭</div>
          <div class="processBtn_Save" @click="setBaseInfo">确定</div>
        </div>
      </q-card>
      <div class="dialog-out-close" @click="closeProcess" style="
          height: 40px !important;
          border-top-left-radius: 4px !important;
          border-bottom-left-radius: 4px !important;
        ">
        <q-icon name="iconfont icon-jujue1" size="26px" />
      </div>
    </q-dialog>
  </div>
</template>
<script>
  import {
    setExaminationConfigure,
    getExaminationConfigureModel,
  } from "../../api/system/exam";
  import {
    queryEmployee
  } from "../../api/users/user"; //获取业务员
  export default {
    meta: {
      title: "考试设置",
    },
    data() {
      return {
        isShowBaseSet: false,
        baseObj: {},
        addMsg: {},
        //   ZuJuanReviewerName: "", //组卷审核人姓名
        //   ExamApplyReviewerName: "", //考试申请审核人姓名
        EmployeeListOption: [],
        allEmployeeListOption: [],
      };
    },
    mounted() {
      this.getEmployee();
    },
    methods: {
      //获取考试配置信息
      getData() {
        getExaminationConfigureModel({}).then((res) => {
          if (res.Code == 1) {
            this.baseObj = res.Data;
            this.baseObj.ZuJuanReviewerName = this.getName(
              res.Data.ZuJuanReviewer
            );
            this.baseObj.ExamApplyReviewerName = this.getName(
              res.Data.ExamApplyReviewer
            );
            this.addMsg = res.Data;
          }
        });
      },

      //关闭流程设置
      closeProcess() {
        this.isShowBaseSet = false;
      },
      geteject() {
        this.isShowBaseSet = true;
      },
      //设置考试信息
      setBaseInfo() {
        //都选否 直接保存
        if(this.addMsg.IsOpenZuJuan==0&&this.addMsg.IsOpenExamApply==0){
          setExaminationConfigure(this.addMsg).then((res) => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: "iconfont icon-chenggong",
                color: "accent",
                timeout: 2000,
                message: "数据保存成功！",
                position: "top",
              });
              this.getData();
              this.isShowBaseSet = false;
            }
          });
        }
        //只选择了开启组卷审批
        if(this.addMsg.IsOpenZuJuan==1&&this.addMsg.IsOpenExamApply==0){
          this.$refs.ZuJuanReviewer.validate();
          this.addMsg.ZuJuanReviewerName = this.getName(
            this.addMsg.ZuJuanReviewer
          );
          if(!this.$refs.ZuJuanReviewer.hasError){
            setExaminationConfigure(this.addMsg).then((res) => {
              if (res.Code == 1) {
                this.$q.notify({
                  icon: "iconfont icon-chenggong",
                  color: "accent",
                  timeout: 2000,
                  message: "数据保存成功！",
                  position: "top",
                });
                this.getData();
                this.isShowBaseSet = false;
              }
            });
          }
        }
        //组卷审批关闭 开起考试
        if(this.addMsg.IsOpenZuJuan==0&&this.addMsg.IsOpenExamApply==1){
          this.$refs.ExamApplyReviewer.validate();
          this.addMsg.ExamApplyReviewerName = this.getName(
            this.addMsg.ExamApplyReviewer
          );
          if(!this.$refs.ExamApplyReviewer.hasError){
            setExaminationConfigure(this.addMsg).then((res) => {
              if (res.Code == 1) {
                this.$q.notify({
                  icon: "iconfont icon-chenggong",
                  color: "accent",
                  timeout: 2000,
                  message: "数据保存成功！",
                  position: "top",
                });
                this.getData();
                this.isShowBaseSet = false;
              }
            });
          }
        }
        //组卷审批 开启考试同时打开
        if(this.addMsg.IsOpenZuJuan==1&&this.addMsg.IsOpenExamApply==1){
          this.$refs.ZuJuanReviewer.validate();
          this.$refs.ExamApplyReviewer.validate();
          if (
            !this.$refs.ZuJuanReviewer.hasError &&
            !this.$refs.ExamApplyReviewer.hasError
          ) {
            this.addMsg.ZuJuanReviewerName = this.getName(
              this.addMsg.ZuJuanReviewer
            );
            this.addMsg.ExamApplyReviewerName = this.getName(
              this.addMsg.ExamApplyReviewer
            );
            setExaminationConfigure(this.addMsg).then((res) => {
              if (res.Code == 1) {
                this.$q.notify({
                  icon: "iconfont icon-chenggong",
                  color: "accent",
                  timeout: 2000,
                  message: "数据保存成功！",
                  position: "top",
                });
                this.getData();
                this.isShowBaseSet = false;
              }
            });
          }
        }
      },
      //获取业务员
      getEmployee(id) {
        var qMsg = {
          Dept_Id: 0,
        };
        qMsg.Dept_Id = id;
        queryEmployee(qMsg)
          .then((res) => {
            if (res.Code == 1) {
              this.EmployeeListOption = res.Data;
              this.allEmployeeListOption = res.Data;
              this.getData();
            }
          })
          .catch(() => {});
      },
      //筛选员工
      filterFn(val, update) {
        update(() => {
          if (val === "") {
            this.EmployeeListOption = JSON.parse(
              JSON.stringify(this.allEmployeeListOption)
            );
          } else {
            const needle = val.toLowerCase();
            this.EmployeeListOption = this.allEmployeeListOption.filter(
              (v) => v.EmployeeName.toLowerCase().indexOf(needle) > -1
            );
          }
        });
      },
      //根据Id取名字
      getName(id) {
        let name = "";
        this.allEmployeeListOption.map((item) => {
          if (id == item.Id) {
            name = item.EmployeeName;
          }
        });
        return name;
      },
    },
  };

</script>
