<template>
  <div class="school-set-recognition part-box part-box-pad">
    <el-form
      ref="modalFormComp"
      :model="modalForm"
      :rules="rules"
      label-width="160px"
    >
      <el-form-item label="扩展算法：" prop="extendAlgorithm">
        <el-radio-group v-model="modalForm.extendAlgorithm">
          <el-radio
            v-for="item in OPEN_STATUS"
            :key="item.value"
            :label="item.value"
            >{{ item.label }}</el-radio
          >
        </el-radio-group>
        <br />
        <p class="tips-info">
          （开启扩展算法后会对答题卡使用第二套算法进行识别，识别结果仅记录做研发分析，不影响正式算法识别结果）
        </p>
        <el-radio-group v-model="modalForm.extendAlgorithmType">
          <el-radio :key="1" :label="1">仅识别正式算法有嫌疑的题</el-radio>
          <el-radio :key="2" :label="2">识别全部答题卡</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="客观题检查扩展条件：">
        <el-checkbox v-model="modalForm.avoidSingleChoice">
          单选题有且仅有一个识别答案不进客观题检查
        </el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" :loading="loading" @click="confirm"
          >保存</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { OPEN_STATUS } from "@/constants/enumerate";
import {
  schoolSetRecognitionInfo,
  schoolSetRecognitionUpdate,
} from "../../api";

export default {
  name: "SchoolSetRecognition",
  props: {
    school: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      modalForm: {
        // 扩展算法
        extendAlgorithm: false,
        extendAlgorithmType: 1,
        avoidSingleChoice: false,
      },
      OPEN_STATUS,
      loading: false,
      rules: {
        extendAlgorithm: [{ required: true, message: "请选择扩展算法" }],
        extendAlgorithmType: [
          { required: true, message: "请选择扩展算法类型" },
        ],
      },
    };
  },
  mounted() {
    this.initData();
  },
  methods: {
    async initData() {
      const data = await schoolSetRecognitionInfo(this.school.id);
      this.modalForm = data.result || {};
    },
    async confirm() {
      const valid = await this.$refs.modalFormComp.validate().catch(() => {});
      if (!valid) return;

      if (this.loading) return;
      this.loading = true;
      const datas = {
        ...this.modalForm,
        schoolId: this.school.id,
      };
      const res = await schoolSetRecognitionUpdate(datas).catch(() => {});
      this.loading = false;
      if (!res) return;

      this.$message.success("修改成功！");
      this.initData();
    },
  },
};
</script>
