<template>
  <div class="single-question">
    <div class="type">【多选】</div>
    <div class="title">{{ item.questionName }}</div>
    <div class="option-list">
      <div
        v-for="opt in item.qaAnswerList"
        class="option"
        :class="[{isChecked},{isActive:activeIdMap.some(o=>o===opt.answerId)},{right:opt.rightFlag}]"
        :key="opt.answerId"
        @click="handleChoose(opt)"
      >
        <span class="option-text">{{ opt.answerName }}</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  model: {
    prop: "value",
    event: "change",
  },
  props: {
    value: {
      type: [String, Number],
      default: "",
    },
    isChecked: {
      type: Boolean,
      default: false
    },
    item: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      activeIdMap: []
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    handleChoose(opt) {
      // 如果已经判卷，不要再可以选择
      if (this.isChecked) return false;
      if (this.activeIdMap.some(o => o === opt.answerId)) {
        const i = this.activeIdMap.findIndex(o => o === opt.answerId);
        this.activeIdMap.splice(i, 1);
      } else {
        this.activeIdMap.push(opt.answerId)
      }
      this.$emit("change", this.item, this.activeIdMap);
    }
  },
  watch:{
    item(val){
      this.activeIdMap = [];
    }
  }
};
</script>
<style lang="scss" scoped>
.single-question {

  .type {
    color: #092643;
  }

  .title {
    margin: 0.2rem;
    font-weight: bolder;
    font-size: 0.41rem;
    color: #092643;
    line-height: 0.6rem;
    text-align: left;
    word-break: break-all;
  }

  .option-list {
    width: 6.42rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: .4rem auto auto;
    word-break: break-all;
    // 选项
    .option {
      width: 6.42rem;
      height: 0.9rem;
      line-height: 0.9rem;
      font-size: 0.28rem;
      color: #464646;
      margin-bottom: 0.22rem;
      border-radius: 0.45rem;
      background: #eaebf0;
      text-align: left;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      word-break: break-all;

      &:before {
        content: '';
        background-color: white;
        width: 0.48rem;
        height: 0.48rem;
        border-radius: 0.48rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background-position: center center;
        background-repeat: no-repeat;
        margin-left: 0.2rem;
        margin-right: 0.1rem;
        visibility: hidden;
        flex-shrink: 0;
        flex-grow: 0;
      }

      .option-text {
        flex-shrink: 0;
        flex-grow: 0;
        width: 5.5rem;
        overflow: hidden;
      }
    }

    // 选中的状态
    .option.isActive {
      background-color: #495975;
      color: #fff;
    }

    .option.isChecked {
      &:before {
        visibility: hidden;
      }
    }

    // 答错的
    .option.isChecked.isActive {
      color: #fff;
      background-color: #e34c4b;

      &:before {
        visibility: visible;
        background-size: 0.28rem 0.28rem;
        background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/160618/1/25613/701/61b0ade0E10bbd3f3/4ff790c26b2f4770.png);
      }
    }

    // 答对的
    .option.isChecked.isActive.right {
      color: #fff;
      background-color: #495975;

      &:before {
        visibility: visible;
        background-size: 0.36rem 0.29rem;
        background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/209568/6/11943/599/61b0ada1E934f6d46/e5fa9b28be5d18fe.png);
      }
    }

    // 正确的，没选的
    .option.isChecked.right {
      background-color: #eaebf0;

      &:before {
        visibility: visible;
        background-size: 0.36rem 0.29rem;
        background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/209568/6/11943/599/61b0ada1E934f6d46/e5fa9b28be5d18fe.png);
      }
    }
  }

}
</style>
