<template>
  <el-dialog
    class="modify-mark-params"
    :visible.sync="modalIsShow"
    title="评卷员设置"
    top="0"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    fullscreen
    @open="visibleChange"
    @close="dialogClose"
  >
    <div class="mark-body" v-if="dataReady">
      <mark-paper-marker
        ref="MarkPaperMarker"
        :datas="infos"
        only-marker
      ></mark-paper-marker>
    </div>

    <div slot="footer"></div>
  </el-dialog>
</template>

<script>
import MarkPaperMarker from "./MarkParamMarker.vue";
// import paramData from "./paramData";
import { calcSum } from "@/plugins/utils";

export default {
  name: "modify-paper-marker",
  components: { MarkPaperMarker },
  props: {
    instance: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      modalIsShow: false,
      infos: {
        basicPaperInfo: {},
        paperStructureInfo: [],
        groupInfo: [],
        paperStat: {},
      },
      dataReady: false,
    };
  },
  methods: {
    dialogClose() {
      this.dataReady = false;
      this.$emit("close");
    },
    visibleChange() {
      if (!this.instance.paperInfoJson) return;

      const { paperStructureInfo, groupInfo } = JSON.parse(
        this.instance.paperInfoJson
      );
      this.infos = {
        paperStructureInfo: [
          ...paperStructureInfo.objectiveQuestionList,
          ...paperStructureInfo.subjectiveQuestionList,
        ],
        groupInfo,
        basicPaperInfo: { ...this.instance },
      };
      this.infos.paperStat = this.statPaperStructure(
        this.infos.paperStructureInfo
      );

      this.dataReady = true;
    },
    statPaperStructure(paperStructureInfo) {
      const questionCount = paperStructureInfo.length;

      const subjectiveQuestionCount = paperStructureInfo.filter(
        (item) => item.qType === "subjective"
      ).length;

      return {
        questionCount,
        paperTotalScore: calcSum(
          paperStructureInfo.map((item) => item.totalScore || 0)
        ),
        subjectiveQuestionCount,
        objectiveQuestionCount: questionCount - subjectiveQuestionCount,
        structChanged: false,
      };
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
  },
};
</script>
