<template>
  <el-dialog
    :title="title"
    :model-value="type === 103"
    width="1100px"
    @close="fnClose"
  >
    <div class="tr mb">
      <el-button type="primary" @click="fnExport">导出</el-button>
    </div>
    <h2 class="tc">
      {{ data.info.EXAMNAME }}
    </h2>
    <div class="tc mt">(满分:{{ data.info.EXAMSCORE || 0 }}分)</div>
    <div class="items mt-20 p-20">
      <div
        v-for="(item, index) in data.questionList"
        :key="item.QUESTION_ID"
        class="item ptb-20"
      >
        <div class="mt-10">
          {{ index + 1 }}.
          <span v-if="item.QUESTIONTYPE === '1'"> (单选题) </span>
          <span v-if="item.QUESTIONTYPE === '2'"> (多选题) </span>
          <span v-if="item.QUESTIONTYPE === '3'"> (判断题) </span>
          {{ item.QUESTIONDRY }}
          <span class="ml-10">
            (题目分值：{{ item.SCORE }} 正确答案：{{ item.ANSWER }})
          </span>
        </div>
        <div class="mt-10 ml-30">
          <el-radio-group
            v-if="item.QUESTIONTYPE === '1'"
            disabled
            :model-value="item.ANSWER"
          >
            <el-radio value="A">A.{{ item.OPTIONA }}</el-radio>
            <el-radio value="B">B.{{ item.OPTIONB }}</el-radio>
            <el-radio value="C">C.{{ item.OPTIONC }}</el-radio>
            <el-radio value="D">D.{{ item.OPTIOND }}</el-radio>
          </el-radio-group>
          <el-checkbox-group
            v-if="item.QUESTIONTYPE === '2'"
            disabled
            :model-value="item.ANSWER?.split('')"
          >
            <el-checkbox value="A">A.{{ item.OPTIONA }}</el-checkbox>
            <el-checkbox value="B">B.{{ item.OPTIONB }}</el-checkbox>
            <el-checkbox value="C">C.{{ item.OPTIONC }}</el-checkbox>
            <el-checkbox value="D">D.{{ item.OPTIOND }}</el-checkbox>
          </el-checkbox-group>
          <el-radio-group
            v-if="item.QUESTIONTYPE === '3'"
            disabled
            :model-value="item.ANSWER"
          >
            <el-radio value="A">A.{{ item.OPTIONA }}</el-radio>
            <el-radio value="B">B.{{ item.OPTIONB }}</el-radio>
          </el-radio-group>
        </div>
      </div>
    </div>
    <template #footer>
      <el-button @click="fnClose">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { reactive, watchEffect } from "vue";
import { ElMessageBox } from "element-plus";
import {
  getClassPaper,
  downloadExaminationpaper,
} from "@/request/training_archive_management.js";

const props = defineProps({
  type: {
    type: Number,
    required: true,
  },
  title: {
    type: String,
    required: true,
  },
  clazzId: {
    type: String,
    required: true,
  },
  stageexampaperinputId: {
    type: String,
    required: true,
  },
});
const data = reactive({
  questionList: [],
  info: {},
});
const emits = defineEmits(["update:type"]);
const fnGetData = async () => {
  const resData = await getClassPaper({
    STAGEEXAMPAPERINPUT_ID: props.stageexampaperinputId,
  });
  data.info = resData.paper;
  data.questionList = resData.questionList;
};

watchEffect(() => {
  if (props.type === 103) fnGetData();
});
const fnExport = async () => {
  await ElMessageBox.confirm("确定要导出吗？", { type: "warning" });
  await downloadExaminationpaper({
    CLASS_ID: props.clazzId,
    STAGEEXAMPAPERINPUT_ID: props.stageexampaperinputId,
  });
  await ElMessageBox.confirm("导出后请前往档案下载中下载该档案！", "温馨提示", {
    type: "info",
  });
};
const fnClose = () => {
  emits("update:type", 0);
};
</script>

<style scoped lang="scss">
.items {
  border: 1px solid var(--el-border-color);

  .item {
    border-bottom: 1px dashed #ebeef5;

    &:first-child {
      padding-top: 0;
    }

    &:last-child {
      border-bottom: none;
    }
  }
}
:deep {
  .el-radio-group {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .el-radio-group .el-radio {
    width: 25%;
    margin-right: 0;
    height: auto;
    min-height: 30px;
  }
  .el-radio__input.is-disabled + span.el-radio__label {
    white-space: break-spaces;
    word-break: break-all;
    line-height: 20px;
  }
}
</style>
