<!--
 * @description: 
 -->
<template>
  <div>
    <div class="type">
      <div class="bg">
        <div v-if="resultDetail" class="question-type">
          {{ resultDetail.quType }}
        </div>
      </div>
      <div v-if="resultDetail" class="bg1">

        <div v-if="resultDetail" class="question-type">
          第{{ resultDetail.eroTpqSort + 1 }}题

        </div>
      </div>
    </div>
    <div class="question">
      <template>
        <div v-if="resultDetail" class="question-title">{{ resultDetail.title }}</div>
        <div class="question-answer">
          <div class="question-answer-item">
            <div v-if="resultDetail.answer" v-for="(el, idx) in resultDetail.answer"
              :class="{ active: el.eroConnNo !== '-1' }" class="question-answer-item-title">
              <span class="num">{{ getOptionLabel(el.eroSort) }}</span>
              {{ el.eroQoOption }}
            </div>
          </div>
        </div>
      </template>

      <view class="correct-answer" v-if="resultDetail.answer">
        <text class="label">正确答案：</text>
        <text>{{correctOptions.map(opt => getOptionLabel(opt.eroSort)).join(',')}}</text>

      </view>


    </div>
  </div>
</template>

<script>
export default {
  name: "QuestionResult",
  computed: {
    correctOptions() {
      return this.resultDetail?.answer?.filter(item => item.eroQoCorrect) ?? [];
    }
  },

  data() {
    return {
      resultDetail: {},
      activeIndex: [],
      currentQuestion: 0
    }
  },
  onLoad() {
    console.log("answerList", answerList)
  },
  methods: {
    getOptionLabel(index) {
      return String.fromCharCode(65 + index); // 65 是 'A' 的 Unicode 编码
    },
    chooseAnswer(el, index, idx) {
      this.$set(this.activeIndex, index, { "quId": el.quId, "eroConnNo": idx, "eroSort": el.num });
      this.$emit("chooseAnswer", this.activeIndex)
    },

    initResult(data) {
      console.log("22222")
      this.resultDetail = data;
      console.log("this.resultDetail", this.resultDetail)

      //  this.currentQuestion = idx; // 更新当前题目索引
      //   this.$emit("currentQuestion", this.currentQuestion); // 向父组件传递新的题目索引
    }
  }
}
</script>

<style lang="scss" scoped>
.type {
  position: relative;
  height: 120rpx;
  padding: 0 42rpx;
  overflow: hidden;

  .bg {
    position: absolute;
    left: 0;
    width: 60%;
    height: 100%;
    background: linear-gradient(-130deg, transparent 80rpx, #D2EBFA 0, #D2EBFA 0);
    border-radius: 56rpx 256rpx 0 0;
    z-index: 1;
    padding: 40rpx 0 0 28rpx;
  }

  .bg1 {
    position: absolute;
    width: 50%;
    top: 20rpx;
    right: 0;
    height: 100%;
    background: linear-gradient(180deg, #4583F0 0%, #4883F6 100%);
    border-radius: 56rpx 56rpx 0 0;
    padding: 40rpx 0 0 42rpx;

    .question-type {
      padding-right: 28rpx;
      font-weight: bold;
      font-size: 32rpx;
      color: #FFFFFF;
      line-height: 40rpx;
      text-align: right;

      span {
        font-size: 26rpx;
        color: rgba(255, 255, 255, 0.6);
        line-height: 32rpx;
      }
    }
  }

  .question-type {
    font-size: 40rpx;
    line-height: 48rpx;
    color: #496CF4;

    span {
      margin-left: 14rpx;
      font-size: 26rpx;
      color: #6896F6;
      line-height: 30rpx;
    }
  }
}

.question {
  padding: 56rpx 48rpx;
  background: #FFFFFF;
  border-radius: 0 32rpx 32rpx 32rpx;
  box-shadow: 0 8rpx 20rpx 0 rgba(0, 0, 0, 0.06);

  .question-title {
    font-weight: 400;
    font-size: 32rpx;
    color: #3D3D3D;
    line-height: 38rpx;
  }

  .question-answer-item-title {
    display: flex;
    align-items: center;
    background: #F1F7FE;
    border-radius: 80rpx;
    padding: 16rpx 48rpx 16rpx 16rpx;
    font-size: 28rpx;
    color: #3D3D3D;
    line-height: 34rpx;
    margin-top: 36rpx;
    border: 2rpx solid rgba(255, 255, 255, 0.5);

    .num {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 64rpx;
      height: 64rpx;
      background: linear-gradient(135deg, #6E9BFC 0%, #496CF4 100%);
      box-shadow: 4rpx 4rpx 16rpx 0 rgba(76, 112, 246, 0.3);
      border-radius: 80rpx;
      margin-right: 24rpx;
      font-size: 28rpx;
      color: #FFFFFF;
    }

    &.active {
      background: #F1F7FE;
      box-shadow: 0 0 20rpx 0 rgba(76, 112, 246, 0.6);
      border-radius: 80rpx;
      border-color: rgba(76, 112, 246, 0.5);
      position: relative;

      &:after {
        content: "";
        position: absolute;
        right: 48rpx;
        display: inline-flex;
        width: 48rpx;
        height: 48rpx;
        background: url("../../../static/images/dui.png") no-repeat;
        background-size: 100%;
      }
    }
  }
}

.choose-question {
  display: flex;
  gap: 32rpx;
  padding-top: 32rpx;

  .btn {
    flex: 1;
  }
}

.btn,
.time {
  margin: 36rpx 0;
  border-radius: 80rpx;
  font-weight: bold;
  font-size: 32rpx;
  color: #FFFFFF;
  text-align: center;

  &.none {
    margin-bottom: 0;
  }
}

.btn {
  border: 2px solid #fff;
  padding: 18rpx 0;
  background: linear-gradient(135deg, #6E9BFC 0%, #496CF4 100%);

  &.line {
    background: inherit;
    border-color: #496CF4;
    color: #496CF4;
  }
}

.time {
  margin: 32rpx 0;
  color: #333333;
}

.tips {
  font-weight: 400;
  font-size: 24rpx;
  color: #999999;
  text-align: center;
  position: relative;

  &:after {
    content: "";
    display: inline-block;
    width: 100%;
    position: absolute;
    top: 50%;
    left: 0;
    border-bottom: 2rpx dashed #E5E5E5;
    transform: translateY(-50%);
  }

  span {
    position: relative;
    padding: 0 8rpx;
    background: #fff;
    z-index: 2;
  }

  .correct-answer {
    margin-top: 40rpx;
    font-size: 32rpx;
    color: #4CAF50;
  }
}
</style>