﻿<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>
    <MesToMcsMixPlanModal @register="registerModal" />
  </div>
</template>

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

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

  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: 'MES下发混炼计划',
      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: 'MES下发混炼计划', 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>
