<template>
  <a-card :bordered="false" title="培训详情">
    <template slot="extra">
      <a-button size="small" @click="close">返回</a-button>
    </template>
    <div class="table-page-search-wrapper">
      <SearchCom :form="queryParam" :list="queryOptions" @search="handleRefresh" @reset="() => {queryParam = {}, handleRefresh()}"></SearchCom>
    </div>
    <s-table ref="table" size="default" rowKey="id" :columns="columns" :data="loadData"></s-table>
  </a-card>
</template>

<script>
import { STable, SearchCom } from '@/components'
import { getArchivesUserAutoTrainDetailList } from '@/api/archives/user'

export default {
  components: { STable, SearchCom },
  data() {
    return {
      queryParam: { personId: this.$route.query.personId, projectId: this.$route.query.projectId, courseName: '' },
      columns: [
        { title: '课程名称', width: 'auto', align: 'center', dataIndex: 'courseName', key: 'courseName' },
        { title: '应修学时', width: 'auto', align: 'center', dataIndex: 'mustClassHour', key: 'mustClassHour' },
        { title: '已修学时', width: 'auto', align: 'center', dataIndex: 'alreadyClassHour', key: 'alreadyClassHour' },
        { title: '总题量', width: 'auto', align: 'center', dataIndex: 'addUpExercises', key: 'addUpExercises' },
        { title: '已答题量', width: 'auto', align: 'center', dataIndex: 'alreadyExercises', key: 'alreadyExercises' },
        { title: '答对题量', width: 'auto', align: 'center', dataIndex: 'yesExercises', key: 'yesExercises' },
        { title: '答对正确率', width: 'auto', align: 'center', dataIndex: 'yesRate', key: 'yesRate' },
        {
          title: '完成状态', width: 'auto', align: 'center', dataIndex: 'finishState', key: 'finishState', customRender: (text, record, index) => {
            // 完成状态 0-未完成 1-已完成
            if (text == 0) return '未完成'; else if (text == 1) return '已完成';
          }
        }
      ],
      loadData: parameter => { return getArchivesUserAutoTrainDetailList(Object.assign(parameter, this.queryParam)).then(res => { return res }) }
    }
  },
  computed: {
    queryOptions: function () {
      return [
        { type: 'input', placeholder: '课程名称', key: 'courseName' },
      ]
    }
  },
  methods: {
    handleRefresh() {
      this.queryParam.personId = this.$route.query.personId;
      this.queryParam.projectId = this.$route.query.projectId;
      this.$refs.table.refresh(true)
    },
    // 返回 按钮
    close() {
      this.$router.push({
        path: '/archives/user/Project', query: {
          id: this.$route.query.personId,
          archivesUserName: this.$route.query.archivesUserName,
          archivesUserOrgId: this.$route.query.archivesUserOrgId,
          archivesUserPageNum: this.$route.query.archivesUserPageNum,
          archivesUserProjectTable1ProjectName: this.$route.query.archivesUserProjectTable1ProjectName,
          archivesUserProjectTable1FinishState: this.$route.query.archivesUserProjectTable1FinishState,
          archivesUserProjectTable1PageNum: this.$route.query.archivesUserProjectTable1PageNum,
          defaultActiveKey: this.$route.query.defaultActiveKey
        }
      });
    }
  }
}
</script>
