<!--分录题-->
<style>
  .entryProblemQuestion {
    width: 100%;
  }

  .entrytk_info {
    color: #A8A8B3;
    font-size: 12px;
    line-height: 24px;
    cursor: default;
  }

</style>
<template>
  <div class="entryProblemQuestion">
    <table v-if="data&&data.length>0" class="common_TiTable">
      <tr v-for="(item,index) in data">
        <td style="width:40px;text-align:center;padding-top:8px;">
          第{{index+1}}空</el-checkbox>
        </td>
        <td>
          <div class="InpDIV" v-html="item.Content" v-if="commonIndex!=index" @click="changeEdit(index)"></div>
          <UeEditor v-model="item.Content" :config="config" v-else></UeEditor>
        </td>
        <td style="width:40px;text-align:center;">
          <i class="iconfont icon-guanbi Tiku_DelIcon" @click="deleteOpion(index)"></i>
        </td>
      </tr>
    </table>
    <br />
    <a class="addTiMuList" @click="addOption()">
      <i class="iconfont icon-add"></i>添加更多
    </a>
    <br />
    <br />
    <el-checkbox v-model="setOption.IsMutex" :true-label="1" :false-label="0"><span
        style="font-size:12px;">答案顺序打乱也判正确</span></el-checkbox>
    <br />
    <br />
    <div class="entrytk_info">
      1. 一个空有多种答案时请用";"隔开。如：水;H2O
      <br />
      2. 若试题答案是数字，可设置范围，两个数字之间用"-"。如：1-9，学生填写1到9之间的数字都算正确（包括1和9）
    </div>
  </div>
</template>
<script>
  import UeEditor from '../editor/UeEditor'
  export default {
    props: {
      questionData: {
        type: Array,
      },
      setOption: {
        type: Object,
      }
    },
    components: {
      UeEditor
    },
    data() {
      return {
        data: this.questionData,
        config: {
          initialFrameWidth: null,
          initialFrameHeight: 80,
        },
        commonIndex: -1,
      };
    },
    created() {},
    methods: {
      //删除选项
      deleteOpion(index) {
        this.$q.dialog({
          title: "删除小题",
          message: "确实要删除该选项吗？",
          persistent: true,
          cancel: {
            label: "取消",
            flat: true
          },
          ok: {
            label: "确认",
            flat: true,
            focus: true
          }
        }).onOk(() => {
          this.data.splice(index, 1);
          this.commonIndex = -1;
        });
      },
      //新增选项
      addOption() {
        this.data.push({
          Content: "",
        });
      },
      //获取答案
      getAnswer() {
        if (this.data && this.data.length > 0) {
          var answer = "";
          this.data.forEach(item => {
            answer += "★" + item.Content;
          })
          if (answer != "") {
            answer = answer.substring(1);
          }
          this.setOption.Answer = answer;
        }
      },
      //返回数据到父组件
      returnDataToParent() {
        this.getAnswer();
        this.$emit('getChild', this.data);
      },
      changeEdit(index) {
        this.commonIndex = index;
      }
    },
    mounted() {

    },
    watch: {
      data: {
        handler(newValue) {
          this.returnDataToParent();
        },
        deep: true
      },
    }
  };

</script>
