<template>
  <div class="analysis-contianer" :style="{minHeight:windowHeight+'px'}" v-if="loaded">
    <!-- 头部标题 -->
    <div class="collectBank-box__head">
      <van-nav-bar :title="paper_title" left-arrow @click-left="onClickLeft()" class="van-nav-new"/>
    </div>
    <swiper :options="swiperOption" v-if="anliysisList.length">
      <swiper-slide v-for="(item,i) in anliysisList" :key="i">
        <analysis-item :iscorrect="iscorrect" :item="item" :level="1"/>
        <div v-if="item.tktype==6">
          <div v-for="(child,c) in item.tkinfo.childtk" :key="c">
            <!--组合题部分-->
            <analysis-item
              :item="child"
              :iscorrect="iscorrect"
              :number="`${c+1})`"
              :class="c < item.tkinfo.childtk.length-1 && 'ktj-line'"
              :parenttkid="item.tkid"
            />
          </div>
        </div>
      </swiper-slide>
    </swiper>
    <Nodata  v-else/>
  </div>
</template>

<script>
import { GetRecordDetail, GetTestTk } from "@/api/paper";
import AnalysisItem from "./PaperComponent/AnalysisItem";

export default {
  /**试卷解析 */
  name: "PaperAnalysis",
  components: {
    AnalysisItem
  },
  data() {
    return {
      loaded: false,
      windowHeight: window.innerHeight,
      swiperOption: {
        slidesPerView: 1,
        spaceBetween: 0,
        autoHeight: true
      },
      /**答题id */
      answerId: this.$route.query.id,
      /**阅卷状态 */
      iscorrect: -1,
      /**
       * 解析列表
       */
      anliysisList: [],

      /**收藏解析 做题解析*/
      moduleName: this.$route.name,
      /**
       * 标题
       */
      paper_title:this.$route.query.title,

    };
  },
  activated() {

    document.title = "查看试卷解析";
    this.answerId = this.$route.query.id;
    this.anliysisList = [];
    this.moduleName = this.$route.name;
    let API;
    let params = {};
    if (this.moduleName == "analysis") {
      API = GetRecordDetail;
      params = {
        id: this.answerId,
        categoryid: this.$route.query.categoryid,
        paperid:this.$route.query.paperid,
        type: this.$route.query.type || 1 //1整卷 2随机、错题
      };
    } else if (this.moduleName == "ErrorAnaysis") {
      API = GetTestTk;
      params = {
        categoryid: this.$route.query.categoryid
      };
    }
    if (!API) {
      return;
    }
    this.$showLoading();
    API(params).then(res => {
      if (res.result) {
        let _anliysisList = [];
        res.data.map(item => {
          item.tklist.map(tk => {
            if (tk.tktype == 6) {
              tk.tkinfo.childtk.map(child => {
                /**即时显示答题对错状态 */
                child.showAnswerStatus = true;
                /**禁止改变答案 */
                child.changeAnswer = false;
              });
            }
            /**即时显示答题对错状态 */
            tk.showAnswerStatus = true;
            /**禁止改变答案 */
            tk.changeAnswer = false;
            _anliysisList.push(tk);
          });
        });
        this.iscorrect = 1;
        this.anliysisList = _anliysisList;
      }else{
        this.iscorrect = 0;
        this.$toast(res.msg).then(()=>{
          this.$router.back();
        });
      }
      this.loaded = true;
      this.$hideLoading();
    });
  },
  methods:{
    /**返回上一页 */
    onClickLeft() {
      this.$router.go(-1);
    },
  }
};
</script>
<style scoped>
.van-icon-arrow-left {
  color: #4d4c4c !important;
}
.analysis-contianer {
  background: #fff;
  padding: 0 15px;
}
</style>