<template>
  <BasicTable @register="registerTable">
    <template #toolbar>
      <PermissionBtn @btn-event="onBtnClicked" />
    </template>
  </BasicTable>
</template>

<script setup lang="ts">
import {} from "vue"
import { PermissionBtn } from '@/components/PermissionBtn/index';
import { BasicTable, useTable, TableAction } from '@/components/Table';
import { columns, searchFormSchema } from './utils'
import { LoadPunchRecordPage } from '@/api/illegalconstruction/statistical'
import { getAppEnvConfig } from '@/utils/env';
import axios from "axios";
const { VITE_GLOB_API_URL } = getAppEnvConfig();
const [registerTable, { setTableData, reload, clearSelectedRowKeys, setPagination, setLoading }] =useTable({
  title: '巡查台账清单',
  api: LoadPunchRecordPage,
  columns,
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
  },
  rowKey: 'id',
  useSearchForm: true,
  showTableSetting: true,
  bordered: true,
  // 搜索
  handleSearchInfoFn(info) {
    return info;
  },
  // actionColumn: {
  //   width: 80,
  //   title: '操作',
  //   dataIndex: 'action',
  //   fixed: 'right',
  // },
});
const onBtnClicked = (domId) => {
  switch (domId) {
    case 'btnExport':
      axios({
        method: 'get',
        url: VITE_GLOB_API_URL + '/api/MiViolationReport/ExportPunchRecordDetails',
        headers: {
          'X-Token': localStorage.getItem('X-Token'),
        },
        responseType: 'blob',
      }).then((res) => {
        const elink = document.createElement('a');
        elink.download = '巡查台账清单' + new Date().getTime() + '.xls';
        elink.style.display = 'none';
        elink.href = URL.createObjectURL(res.data);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href);
        document.body.removeChild(elink);
      });
      break;
    default:
      break;
  }
}
</script>

<style lang="scss" scoped></style>
