<template>
  <div>
    <a-row style="margin-bottom: 15px;">
      <a-button icon="plus" @click="handlerGoExam" type="primary">模拟测试</a-button>
    </a-row>
    <a-table :columns="columns" :data-source="dataList" rowKey="id">
      <template slot="timeSlot" slot-scope="text, record">
        {{ record.timeSlot }}
      </template>
      <span slot="action" slot-scope="text, record">
        <a @click="handlerDetail(record)">查看详情</a>
      </span>
    </a-table>
  </div>
</template>

<script>
import { reqSimulateTestList } from '@/api/mycourse/index'
export default {
  data () {
    return {
      columns: [
        { dataIndex: 'testName', title: '课程' },
        { dataIndex: 'assessMode', title: '考核方式', align: 'center' },
        { dataIndex: 'testManner', title: '考试方式', align: 'center' },
        { dataIndex: 'submitWay', title: '提交形式', align: 'center' },
        {
          dataIndex: 'timeSlot',
          title: '考试时间段',
          align: 'center',
          scopedSlots: { customRender: 'timeSlot' }
        },
        {
          dataIndex: 'examTime',
          title: '考试时长',
          align: 'center',
          customRender: value => `${value || 0}分钟`
        },
        {
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],
      dataList: []
    }
  },
  mounted () {
    this.initData()
  },
  methods: {
    initData () {
      const { person } = this.$store.state.user
      reqSimulateTestList({ personId: person.id, projectId: this.$route.query.courseId }).then(
        res => {
          // console.log('模拟', res)
          this.dataList = res.data
        }
      )
    },
    handlerGoExam () {
      this.$router.push({
        path: '/myexamDetail',
        query: { type: 'test', projectId: this.$route.query.courseId }
      })
    },
    handlerDetail (data) {
      this.$router.push({
        path: '/myreport',
        query: { type: 'practice', reportId: data.reportId }
      })
    }
  }
}
</script>

<style></style>
