<template>
  <div class="card_box">
    <div class="head" id="top-view2">
      <i class="el-icon-arrow-left"></i>
    </div>
    <div id="bottom-view2">
      <div class="card_con">
        <div class="flag">
          <ul>
            <li>
              <div class="circle active1"></div>
              <div class="txt">已答</div>
            </li>
            <li>
              <div class="circle active2"></div>
              <div class="txt">标记</div>
            </li>
            <li>
              <div class="circle active3"></div>
              <div class="txt">未答</div>
            </li>
          </ul>
        </div>
        <div class="question">
          <template v-for="(item, index) in dataList">
            <div :key="index">
              <div class="title">{{ questionType[item.type] }}</div>
              <ul>
                <template v-for="(cItem, cIndex) in item.question_list">
                  <!-- <li class="active2">{{ cItem.num }}</li> -->
                  <template v-if="requestData[item.id]">
                    <template v-if="requestData[item.id][cItem.id]">
                      <template v-if="requestData[item.id][cItem.id].sign">
                        <li @click="go(cItem.id)" :data-id="cItem.id" :key="cIndex" class="active2">{{ cItem.num }}</li>
                      </template>
                      <template v-else>
                        <li @click="go(cItem.id)" :data-id="cItem.id" v-if="requestData[item.id][cItem.id].answer.length != 0" :key="cIndex" class="active1">{{ cItem.num }}</li>
                        <li @click="go(cItem.id)" :data-id="cItem.id" v-else :key="cIndex" class="active3">{{ cItem.num }}</li>
                      </template>
                    </template>
                    <template v-else>
                      <li @click="go(cItem.id)" :data-id="cItem.id" :key="cIndex" class="active3">{{ cItem.num }}</li>
                    </template>
                  </template>
                  <template v-else>
                    <li @click="go(cItem.id)" :data-id="cItem.id" :key="cIndex" class="active3">{{ cItem.num }}</li>
                  </template>
                </template>
              </ul>
            </div>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    questionsData: {
      type: Object,
      default () {
        return {}
      }
    },
    requestData: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  mounted() {
    // this.scrollDom()
  },
  data() {
    return {
      countIndex: 1,
      questionType: {
        1: '单选题：',
        2: '多选题：',
        5: '案例题：',
        6: '判断题：'
      }
    }
  },
  methods: {
    go(id) {
      this.$emit('cardChange', id)
      this.$emit('showCard')
    },
    scrollDom() {
      const topViewH = document.getElementById('top-view2').offsetHeight
      const clientHeight = document.documentElement.clientHeight
      const bottomView = document.getElementById('bottom-view2')
      bottomView.style.height = (clientHeight - topViewH) + 'px'
      console.log(bottomView.style.height)
    }
  },
  computed: {
    changeData() {
      return this.questionsData
    },
    dataList() {
      let num = 1
      return this.questionsData.questions.map(item => {
        item.question_list.map((subitem, index) => {
          subitem.num = num + index
          return subitem
        })
        num += item.question_list.length
        return item
      })
    }
  },
  watch: {
    changeData: {
      handler(newV, oldV) {
        this.$forceUpdate()
      },
      deep: true
    }
  }
}
</script>
<style lang="scss" scoped>
.card_box{
  width: 100%;
  height: 100%;
  background: #fff;
  .card_con{
    padding: 0 .4rem;
    overflow-y: scroll;
    .flag{
      border-bottom: 0.01rem solid #EEEEEE;
      ul{
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        justify-content: center;
        li{
          margin: 0 .4rem 0.1rem .4rem;
          text-align: center;
          .circle{
            width: .6rem;
            height: .6rem;
            border-radius: 50%;
            font-size: .26rem;
            text-align: center;
            line-height: .6rem;
            color: #fff;
          }
          .active1{
            background: #67C23A;
          }
          .active2{
            background:rgba(255,128,0,1);
          }
          .active3{
            background:rgba(204,204,204,1);
          }
          .txt{
            color: #222222;
            font-size: .26rem;
            margin-top: 0.1rem;
          }
        }
      }
    }
    .question{
      .title{
        font-size: .3rem;
        color: #333333;
        margin-top: .1rem;
        margin-bottom: .4rem;
      }
      ul{
        list-style: none;
        margin: 0;
        padding: 0 0.6rem;
        border-bottom: 0.01rem solid #EEEEEE;
        display: flex;
        flex-wrap: wrap;
        li{
          width: .6rem;
          height: .6rem;
          border-radius: 50%;
          font-size: .26rem;
          text-align: center;
          line-height: .6rem;
          color: #fff;
          margin-right: .6rem;
          margin-bottom: .4rem;
        }
        :nth-child(5n+5){
          margin: 0;
        }
        .active1{
            background: #67C23A;
          }
        .active2{
          background:rgba(255,128,0,1);
        }
        .active3{
          background:rgba(204,204,204,1);
        }
      }
    }
  }
}
.head{
  color: #222;
  display: flex;
  padding: .4rem 0;
  align-items: center;
  i{
    font-size: .35rem;
    margin-left: .28rem;
  }
  .title{
    margin-left: .03rem;
    font-size: .3rem;
  }
}
#bottom-view2{
  overflow: scroll;
}
</style>
