<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <a-button type="primary" v-auth="'xslmes:mes_xsl_raw_material_summary:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls">
          导出
        </a-button>
        <super-query :config="superQueryConfig" @search="handleSuperQuery" />
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="xslmes-mesXslRawMaterialSummary" setup>
  import { reactive } from 'vue';
  import { BasicTable } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, searchFormSchema, superQuerySchema } from './MesXslRawMaterialSummary.data';
  import { list, getExportUrl } from './MesXslRawMaterialSummary.api';

  const queryParam = reactive<any>({});

  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '原材料汇总',
      api: list,
      columns,
      canResize: true,
      formConfig: {
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam);
      },
    },
    exportConfig: {
      name: '原材料汇总',
      url: getExportUrl,
      params: queryParam,
    },
  });

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

  function handleSuperQuery(params) {
    Object.keys(params).forEach((k) => {
      queryParam[k] = params[k];
    });
    reload();
  }
</script>
