<template>
  <a-card :bordered="false" title="人员档案">
    <div class="table-page-search-wrapper">
      <SearchCom :form="queryParam" :list="queryOptions" :orgTree="orgTreeOptions" @search="handleRefresh" @reset="() => {queryParam = {}, handleRefresh()}"></SearchCom>
      <div style="width: 100%; height: 32px; margin-bottom: 8px;">
        <a-button type="primary" :style="{float: 'right'}">导出</a-button>
      </div>
    </div>
    <s-table ref="table" size="small" rowKey="id" :columns="columns" :data="loadData" :pageNum="Number(this.$route.query.archivesUserPageNum) || 1">
      <template slot="action" slot-scope="text, record">
        <a-dropdown v-if="hasPerm('archives:user:autotrain:list') || hasPerm('archives:user:terminaltrain:list') || hasPerm('archives:user:selfStudy:list') || hasPerm('archives:user:violation:list')">
          <a class="ant-dropdown-link">操作
            <a-icon type="down" />
          </a>
          <a-menu slot="overlay">
            <a-menu-item v-if="hasPerm('archives:user:autotrain:list') || hasPerm('archives:user:terminaltrain:list')">
              <a href="javascript:;" @click="archivesProject(record)">项目档案</a>
            </a-menu-item>
            <a-menu-item v-if="hasPerm('archives:user:selfStudy:list')">
              <a href="javascript:;" @click="archivesSelfStudy(record)">自学档案</a>
            </a-menu-item>
            <a-menu-item v-if="hasPerm('archives:user:violation:list')">
              <a href="javascript:;" @click="archivesViolation(record)">违章档案</a>
            </a-menu-item>
            <a-menu-item>
              <a-popconfirm title="确认导出?" cancelText="取消" okText="确认" @confirm="() => handleDelete(record)">
                <a href="javascript:;">　导出　</a>
              </a-popconfirm>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
      </template>
    </s-table>
  </a-card>
</template>

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

export default {
  components: { STable, SearchCom },
  data() {
    return {
      queryParam: { name: this.$route.query.archivesUserName || '', orgId: this.$route.query.archivesUserOrgId || '' },
      columns: [
        { title: '姓名', width: '100px', align: 'center', dataIndex: 'name', key: 'name' },
        { title: '受训角色', width: 'auto', align: 'center', dataIndex: 'roleName', key: 'roleName' },
        { title: '单位信息', width: 'auto', align: 'center', dataIndex: 'dwOrgName', key: 'dwOrgName' },
        { title: '部门信息', width: 'auto', align: 'center', dataIndex: 'bmOrgName', key: 'bmOrgName' },
        { title: '年度学时要求/时', width: 'auto', align: 'center', dataIndex: 'yearClassHourRequire', key: 'yearClassHourRequire' },
        { title: '年度学时', width: 'auto', align: 'center', dataIndex: 'yearClassHour', key: 'yearClassHour' },
        { title: '累计学时', width: 'auto', align: 'center', dataIndex: 'addUpClassHour', key: 'addUpClassHour' },
        { title: '项目学时', width: 'auto', align: 'center', dataIndex: 'projectClassHour', key: 'projectClassHour' },
        { title: '操作', width: '70px', key: 'operation', align: 'center', scopedSlots: { customRender: 'action' } }
      ],
      loadData: parameter => { return getArchivesUserList(Object.assign(parameter, this.queryParam)).then(res => { return res }) }
    }
  },
  computed: {
    queryOptions: function () {
      return [
        { type: 'input', placeholder: '人员姓名', key: 'name' }
      ]
    },
    orgTreeOptions: () => {
      return { ifshow: true, formKey: 'orgId', startOrganizationId: '', defaultOrganizationId: '' };
    }
  },
  methods: {
    handleRefresh() {
      this.$refs.table.refresh(true)
    },
    // 项目档案 按钮
    archivesProject(record) {
      this.$router.push({
        path: '/archives/user/Project', query: {
          id: record.id,
          archivesUserName: this.queryParam.name,
          archivesUserOrgId: this.queryParam.orgId,
          archivesUserPageNum: this.$refs.table.localPagination.current
        }
      });
    },
    // 自学档案 按钮
    archivesSelfStudy(record) {
      this.$router.push({
        path: '/archives/user/SelfStudy', query: {
          id: record.id,
          archivesUserName: this.queryParam.name,
          archivesUserOrgId: this.queryParam.orgId,
          archivesUserPageNum: this.$refs.table.localPagination.current
        }
      });
    },
    // 违章档案 按钮
    archivesViolation(record) {
      this.$router.push({
        path: '/archives/user/Violation', query: {
          id: record.id,
          archivesUserName: this.queryParam.name,
          archivesUserOrgId: this.queryParam.orgId,
          archivesUserPageNum: this.$refs.table.localPagination.current
        }
      });
    }
  }
}
</script>
<style scoped>
.table-page-search-wrapper-button-group {
  width: 100%;
  margin-bottom: 8px;
}
.ant-card-body {
  padding: 15px;
}
</style>