<template>
  <div class="taba">
    <!-- 提示 -->
    <p class="msg">
      <span>{{msg}}</span>
      <span class="link">继续练习</span>
    </p>
    <!-- table -->
    <Table
      v-for='(item,index) in tableData'
      :key="index"
      :Data="item"
      @Func="Success"
    />
  </div>
</template>
<script>
const Table = () => import("@/components/Table/index")
import Home from '@/api/home'
export default {
  components: {
    Table
  },
  data () {
    return {
      msg: `于2021-04-28 15:23:16最后练习到 飞机 > XX机第3道选择题，点击`,//信息提示
      tableData: []
    }
  },
  created () {
    Home.mock_examination_a().then(res => {
      let { data } = res, tableData = [];
      try {
        tableData = data.map(item => {
          let Obj = { id: item.id, name: item.name, data: item.chapters };
          return Obj
        })
        this.tableData = tableData;
      } catch (err) {
        this.$message.error(`数据处理：${err}`);
      }
    })
  },
  methods: {
    Success (data) {
      let { type, data: obj } = data, query = {};
      if (type == 'th') {
        query = { subject: obj.id, chapter: '' };
      } else {
        query = { subject: obj.subject_id, chapter: obj.id }
      }
      Home.exam(query).then(res => {
        let { practise } = res.data;
        this.$router.push({ path: '/exam', query: { practise } });
      })
    }
  }
}
</script>
<style lang="less" scoped>
.taba {
  .msg {
    color: #777;
    font-size: 14px;
    .link {
      color: #67c23a;
      margin-left: 5px;
      cursor: pointer;
    }
  }
}
</style>