<template>
  <div>
    <el-dialog
      v-if="type === 103"
      :model-value="type === 103"
      :title="title"
      :before-close="fnClose"
    >
      <el-space wrap>
        <el-button type="primary" v-print="'#printContent'">打印</el-button>
      </el-space>
      <br /><br />
      <div id="printContent">
        <div>
          <el-text>单位名称:{{ CORP_NAME }}</el-text>
        </div>
        <br />
        <div>
          <el-text>任务名称:{{ data.taskInfo.STUDY_NAME }}</el-text>
        </div>
        <div style="text-align: center">
          <el-text size="large">{{ data.paperInfo.EXAMNAME }}</el-text>
        </div>
        <div style="text-align: center">
          <el-text size="small">
            (满分:{{ data.paperInfo.EXAMSCORE }}分)
          </el-text>
        </div>
        <div v-if="data.paperInfo.selectList.length > 0" style="color: white">
          <el-divider content-position="left">单选题</el-divider>
          <template
            v-for="(item, index) in data.paperInfo.selectList"
            :key="item.QUESTION_ID"
          >
            {{ index + 1 }}.{{ item.QUESTIONDRY }}
            <el-row>
              <el-col :span="2"></el-col>
              <el-col :span="22">
                <p>A.{{ item.OPTIONA }}</p>
                <p>B.{{ item.OPTIONB }}</p>
                <p>C.{{ item.OPTIONC }}</p>
                <p>D.{{ item.OPTIOND }}</p>
              </el-col>
            </el-row>
          </template>
        </div>
        <div v-if="data.paperInfo.multiList.length > 0" style="color: white">
          <el-divider content-position="left">多选题</el-divider>
          <template
            v-for="(item, index) in data.paperInfo.multiList"
            :key="item.QUESTION_ID"
          >
            {{ index + 1 }}.{{ item.QUESTIONDRY }}
            <el-row>
              <el-col :span="2"></el-col>
              <el-col :span="22">
                <p>A.{{ item.OPTIONA }}</p>
                <p>B.{{ item.OPTIONB }}</p>
                <p>C.{{ item.OPTIONC }}</p>
                <p>D.{{ item.OPTIOND }}</p>
              </el-col>
            </el-row>
          </template>
        </div>
        <div v-if="data.paperInfo.judgeList.length > 0" style="color: white">
          <el-divider content-position="left">判断题</el-divider>
          <template
            v-for="(item, index) in data.paperInfo.judgeList"
            :key="item.QUESTION_ID"
          >
            {{ index + 1 }}.{{ item.QUESTIONDRY }}
            <el-row>
              <el-col :span="2"></el-col>
              <el-col :span="22">
                <p>A.{{ item.OPTIONA }}</p>
                <p>B.{{ item.OPTIONB }}</p>
              </el-col>
            </el-row>
          </template>
        </div>
      </div>
      <template #footer>
        <el-button @click="fnClose">关闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { getStudyTaskInfo, getPaperByTaskId } from "@/request/archives.js";
import { reactive } from "vue";
import { useVModels } from "@vueuse/core";
import { useUserStore } from "@/pinia/user.js";

const props = defineProps({
  title: {
    type: String,
    required: false,
    default: "",
  },
  year: {
    type: String,
    required: false,
    default: "",
  },
  type: {
    type: Number,
    required: true,
  },
  studyTaskId: {
    type: String,
    required: false,
    default: "",
  },
});
const { title, type, studyTaskId } = useVModels(props);

const userStore = useUserStore();
const CORP_NAME = userStore.getUserInfo.CORP_NAME;

const data = reactive({
  taskInfo: {},
  paperInfo: {
    selectList: [],
    multiList: [],
    judgeList: [],
  },
});

const emits = defineEmits(["update:visible"]);

const fnClose = () => {
  emits("update:current", undefined);
};

const fnGetStudyTaskInfo = async () => {
  if (studyTaskId && studyTaskId.value && studyTaskId.value.length > 0) {
    const respData = await getStudyTaskInfo({
      STUDYTASK_ID: studyTaskId.value,
    });
    if (respData && respData.pd) {
      data.taskInfo = respData.pd;
    }
  }
};
await fnGetStudyTaskInfo();

const fnGetPaperByTaskId = async () => {
  if (studyTaskId && studyTaskId.value && studyTaskId.value.length > 0) {
    const respData = await getPaperByTaskId({
      STUDYTASK_ID: studyTaskId.value,
    });
    if (respData.paper) {
      if (respData.paper) {
        data.paperInfo = respData.paper;
      }
      data.paperInfo.selectList = [];
      data.paperInfo.multiList = [];
      data.paperInfo.judgeList = [];
      if (respData.questionList && respData.questionList.length > 0) {
        respData.questionList.forEach((question) => {
          if (question.QUESTIONTYPE === "1") {
            data.paperInfo.selectList.push(question);
          } else if (question.QUESTIONTYPE === "2") {
            data.paperInfo.multiList.push(question);
          } else if (question.QUESTIONTYPE === "3") {
            data.paperInfo.judgeList.push(question);
          }
        });
      }
    }
  }
};
await fnGetPaperByTaskId();
</script>

<style scoped lang="scss"></style>
