﻿<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
        <super-query :config="superQueryConfig" @search="handleSuperQuery" />
      </template>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <McsToMesCheckScaleLogModal @register="registerModal" />
  </div>
</template>

<script lang="ts" name="xslmes-mcs-mcsToMesCheckScaleLog" setup>
  import { reactive } from 'vue';
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import McsToMesCheckScaleLogModal from './components/McsToMesCheckScaleLogModal.vue';
  import { columns, searchFormSchema } from './McsToMesCheckScaleLog.data';
  import { list, getExportUrl } from './McsToMesCheckScaleLog.api';

  const queryParam = reactive<any>({});
  const [registerModal, { openModal }] = useModal();

  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '称量校验日志',
      api: list,
      columns,
      canResize: true,
      formConfig: {
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
        fieldMapToTime: [
          ['writeTime', ['writeTime_begin', 'writeTime_end'], 'YYYY-MM-DD HH:mm:ss'],
          ['cdate', ['cdate_begin', 'cdate_end'], 'YYYY-MM-DD HH:mm:ss'],
        ],
      },
      actionColumn: { width: 80, fixed: 'right' },
      beforeFetch: (params) => Object.assign(params, queryParam),
    },
    exportConfig: { name: '称量校验日志', url: getExportUrl, params: queryParam },
  });

  const [registerTable, { reload }] = tableContext;
  const superQueryConfig = reactive({});

  function handleSuperQuery(params) {
    Object.keys(params).map((k) => { queryParam[k] = params[k]; });
    reload();
  }

  function handleDetail(record: Recordable) {
    openModal(true, { record, isUpdate: true, showFooter: false });
  }

  function getTableAction(record) {
    return [{ label: '详情', onClick: handleDetail.bind(null, record) }];
  }
</script>
