<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="small" rowKey="id" :columns="columns" :data="loadData"></s-table>
  </a-card>
</template>


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

export default {
  components: { STable, SearchCom },
  data() {
    return {
      queryParam: { userId: this.$route.query.userId, courseName: '' },
      columns: [
        { title: '违章编号', width: 'auto', align: 'center', dataIndex: 'id', key: 'id' },
        { title: '违章时间', width: 'auto', align: 'center', dataIndex: 'time', key: 'time' },
        { title: '违章内容', width: 'auto', align: 'center', dataIndex: 'content', key: 'content' },
        { title: '违章课时', width: 'auto', align: 'center', dataIndex: 'courseName', key: 'courseName' },
      ],
      loadData: parameter => { return getArchivesUserViolationList(Object.assign(parameter, this.queryParam)).then(res => { return res }) }
    }
  },
  computed: {
    queryOptions: function () {
      return [
        { type: 'input', placeholder: '课程名称', key: 'courseName' },
      ]
    }
  },
  methods: {
    handleRefresh() {
      this.queryParam.userId = this.userId;
      this.$refs.table.refresh(true)
    },
    // 返回 按钮
    close() {
      this.$router.push({
        path: '/archives/user/Index', query: {
          archivesUserName: this.$route.query.archivesUserName,
          archivesUserOrgId: this.$route.query.archivesUserOrgId,
          archivesUserPageNum: this.$route.query.archivesUserPageNum
        }
      });
    }
  }
}
</script>