<!--阅读理解-->
<style>
  .v_readingComprehensioQuestion {
    width: 100%;
  }


  .v_readingComprehensioQuestion .clozeTest_question_tit {
    width: 50%;
    height: 40px;
    background: #F7F8FA;
    padding: 0 20px;
    line-height: 40px;
    font-size: 14px;
    color: #646873;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
  }

  .v_readingComprehensioQuestion .clozeTest_question_tit i {
    color: #acbfd9;
    cursor: pointer;
  }

  .v_readingComprehensioQuestionBold {
    font-weight: bold;
    height:40px;
  }

</style>
<template>
  <div class="v_readingComprehensioQuestion">
 
    <template v-if="data&&data.QuestionContentObj&&data.QuestionContentObj.length>0">
      <table class="common_TiTable">
        <tbody v-for="(item,index) in data.QuestionContentObj" :key="index">
          <tr>
            <th colspan="2" style="text-align:left;">
              <div class="clozeTest_question_tit">
                <div>
                  第{{index+1}}小题<span style="color:#A8A8B3;">({{item.QuestionName}})</span><template v-if="isShowScore">
                    （{{item.SubScore}}分）</template>
                </div>
                <div>
                </div>
              </div>
            </th>
          </tr>
          <tr>
            <td colspan="2">
              <div style="margin:16px 0;" v-html="item.SubTitle"></div>
            </td>
          </tr>
          <!--选择题-->
          <template
            v-if="item.QuestionKey=='single' ||item.QuestionKey=='multiple'|| item.QuestionKey=='single-number'">
            <tr v-for="(subItem,subIndex) in item.SubAnwser" :key="subIndex">
              <td style="width:40px;text-align:center;">
                <template v-if="item.QuestionKey=='single'|| item.QuestionKey=='single-number'">
                  <template v-if="isOperate">
                    <div class="Answer_List2" style="cursor:pointer;" @click="ChangeItem(item,subItem)"
                      :class="{'Is_Answer':subItem.IsAnswer }">
                      {{subItem.Name}}
                    </div>
                  </template>
                  <template v-else>
                    <div class="Answer_List2">
                      {{subItem.Name}}
                    </div>
                  </template>
                </template>
                <template v-else-if="item.QuestionKey=='multiple'">
                  <template v-if="isOperate">
                    <div class="Answer_List" style="cursor:pointer;" @click="changeMutile(subItem)"
                      :class="{'Is_Answer':subItem.IsAnswer}">
                      {{subItem.Name}}
                    </div>
                  </template>
                  <template v-else>
                    <div class="Answer_List2">
                      {{subItem.Name}}
                    </div>
                  </template>
                </template>
              </td>
              <td>
                <div class="InpDIV" style="border:0;margin-top:-2px;" v-html="subItem.Content">
                </div>
              </td>
            </tr>
            <tr v-if="isShowAnswer">
              <td colspan="2" class="v_readingComprehensioQuestionBold">
                答案: {{data.QuestionAnswerList[index].SubAnswer}}
              </td>
            </tr>
            <tr v-if="isShowStudentAnswer">
              <td colspan="2" class="v_readingComprehensioQuestionBold" :style="{color:data.QuestionAnswerList[index].SubAnswer ==data.AnswerList[index].SubAnswer?'#67c23a':'red'}">
                学生答案: {{data.AnswerList[index].SubAnswer}}
              </td>
            </tr>
            <tr v-if="isShowStudentAnswer">
              <td colspan="2">
                <q-input v-if="isEditStudentScore" filled style="width:180px"
                  v-model="data.AnswerList[index].StudentScore" label="得分：" maxlength="20" @input="getQuestionScore" />
                <span v-else class="v_readingComprehensioQuestionBold">考生得分：{{data.AnswerList[index].StudentScore}}</span>
              </td>
            </tr>
          </template>
          <!--填空题-->
          <template v-if="item.QuestionKey=='fill-in'">
            <template v-if="isOperate">
              <tr v-for="(subItem,subIndex) in item.SubAnwser" :key="subIndex">
                <td style="width:50px;text-align:center;padding-top:8px;">
                  第{{subIndex+1}}空
                </td>
                <td>
                  <el-input v-model="subItem.Content" :placeholder="'请填写第 '+(subIndex+1)+' 空答案'"> </el-input>
                </td>
              </tr>
            </template>
            <tr v-if="isShowAnswer">
              <td colspan="2" class="v_readingComprehensioQuestionBold">
                答案: {{data.QuestionAnswerList[index].SubAnswer}}
              </td>
            </tr>
            <tr v-if="isShowStudentAnswer">
              <td colspan="2" class="v_readingComprehensioQuestionBold" :style="{color:data.QuestionAnswerList[index].SubAnswer ==data.AnswerList[index].SubAnswer?'#67c23a':'red'}">
                学生答案: {{data.AnswerList[index].SubAnswer}}
              </td>
            </tr>
            <tr v-if="isShowStudentAnswer">
              <td colspan="2">
                <q-input v-if="isEditStudentScore" filled style="width:180px"
                  v-model="data.AnswerList[index].StudentScore" label="得分：" maxlength="20" @input="getQuestionScore" />
                <span v-else class="v_readingComprehensioQuestionBold">考生得分：{{data.AnswerList[index].StudentScore}}</span>
              </td>
            </tr>
          </template>
          <!--判断题-->
          <template v-if="item.QuestionKey=='judge'">
            <template v-if="isOperate">
              <tr v-for="(subItem,subIndex) in item.SubAnwser" :key="subIndex">
                <td style="width:50px;">
                  <div class="Answer_List" @click="ChangeItem(item,subItem)" :class="{'Is_Answer':subItem.IsAnswer}">
                    {{subItem.Name}}
                  </div>
                </td>
                <td colspan="2" style="text-align:left;vertical-align:middle;">
                  {{subItem.Content}}
                </td>
              </tr>
            </template>
            <template v-else>
              <tr v-for="(subItem,subIndex) in item.SubAnwser" :key="subIndex">
                <td style="width:50px;">
                  <div class="Answer_List2">
                    {{subItem.Name}}
                  </div>
                </td>
                <td style="text-align:left;vertical-align:middle;">
                  {{subItem.Content}}
                </td>
              </tr>
            </template>
            <tr v-if="isShowAnswer">
              <td colspan="2" style="height:40px" class="v_readingComprehensioQuestionBold">
                答案: {{data.QuestionAnswerList[index].SubAnswer}}
              </td>
            </tr>
            <tr v-if="isShowStudentAnswer">
              <td colspan="2" style="height:40px" class="v_readingComprehensioQuestionBold" :style="{color:data.QuestionAnswerList[index].SubAnswer ==data.AnswerList[index].SubAnswer?'#67c23a':'red'}">
                学生答案: {{data.AnswerList[index].SubAnswer}}
              </td>
            </tr>
            <tr v-if="isShowStudentAnswer">
              <td colspan="2" style="height:40px">
                <q-input v-if="isEditStudentScore" filled style="width:180px"
                  v-model="data.AnswerList[index].StudentScore" label="得分：" maxlength="20" @input="getQuestionScore" />
                <span v-else class="v_readingComprehensioQuestionBold">考生得分：{{data.AnswerList[index].StudentScore}}</span>
              </td>
            </tr>
          </template>
          <!--简答题-->
          <template v-if="item.QuestionKey=='short-answer'">
            <template v-if="isOperate">
              <tr v-for="(subItem,subIndex) in item.SubAnwser" :key="subIndex">
                <td colspan="2">
                  <el-input v-model="subItem.Content" :placeholder="'请填写第简答题答案'"> </el-input>
                </td>
              </tr>
            </template>
            <tr v-if="isShowAnswer">
              <td colspan="2" class="v_readingComprehensioQuestionBold">
                答案: {{data.QuestionAnswerList[index].SubAnswer}}
              </td>
            </tr>
            <tr v-if="isShowStudentAnswer">
              <td colspan="2" class="v_readingComprehensioQuestionBold" :style="{color:data.QuestionAnswerList[index].SubAnswer ==data.AnswerList[index].SubAnswer?'#67c23a':'red'}">
                学生答案: {{data.AnswerList[index].SubAnswer}}
              </td>
            </tr>
            <tr v-if="isShowStudentAnswer">
              <td colspan="2">
                <q-input v-if="isEditStudentScore" filled style="width:180px"
                  v-model="data.AnswerList[index].StudentScore" label="得分：" maxlength="20" @input="getQuestionScore" />
                <span v-else class="v_readingComprehensioQuestionBold">考生得分：{{data.AnswerList[index].StudentScore}}</span>
              </td>
            </tr>
          </template>
        </tbody>
      </table>
    </template>
  </div>
</template>
<script>
  export default {
    props: {
      questionObj: {
        type: Object,
      },
      //是否显示答案和解析
      isShowAnswer: {
        type: Boolean,
        default: false,
      },
      //是否可操作(PC端考试使用【可以点击选中】)
      isOperate: {
        type: Boolean,
        default: false,
      },
      //是否显示学生答案
      isShowStudentAnswer: {
        type: Boolean,
        default: false
      },
      //是否显示小题分数
      isShowScore: {
        type: Boolean,
        default: false,
      },
      //是否可以编辑学生得分
      isEditStudentScore: {
        type: Boolean,
        default: false,
      }
    },
    data() {
      return {
        data: this.questionObj,
      };
    },

    methods: {
      //单选和判断题
      ChangeItem(item, subItem) {
        if (item.SubAnwser && item.SubAnwser.length > 0) {
          item.SubAnwser.forEach(childItem => {
            childItem.IsAnswer = false;
          })
        }
        subItem.IsAnswer = true;
      },
      //多选题
      changeMutile(subItem) {
        subItem.IsAnswer = !subItem.IsAnswer;
      },
      //调用父组件计算学生分数
      getQuestionScore() {
        this.$emit('getScore');
      },
    },
    mounted() {

    },
    watch: {
      isShowAnswer: {
        handler(newValue) {

        },
        deep: true
      },
    }
  };

</script>
