<script setup lang="ts">
import { shallowRef, ref } from "vue";
import { ElMessage } from "element-plus";
import searchConfig from "./config/search.config";
import contentConfig from "./config/content.config";
import { httpRequsetExport } from "/@/utils/export";
import { usePageSearch, type PageHooks } from "/@/hooks/page";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
import { PageContentInstance } from "/@/components/PageContent";

const pageContentRef = ref<PageContentInstance | null>(null);
const loading = shallowRef(false);

const hooks: PageHooks = {
  pageSearchHook: () => usePageSearch(undefined, undefined, searchConfig)
};

const callback = {
  onStart: () => (loading.value = true),
  onSuccess: () => (loading.value = false),
  onFail: () => (loading.value = false)
};

async function handleExportAllReport() {
  const params = pageContentRef.value.getBasicParams() || {};
  if (!params.date) {
    ElMessage.warning("请选择导出文件的日期!");
    return;
  }

  await httpRequsetExport({
    url: "saleexportconsultdayexport",
    fileType: "aplication/zip",
    isPurchase: true,
    name: "日报.zip",
    ...callback,
    params
  });
}
</script>

<template>
  <PageContainer
    :hooks="hooks"
    :getContentRef="ref => (pageContentRef = ref)"
    :content-config="contentConfig"
    :search-config="searchConfig"
  >
    <template #content_header>
      <el-button
        @click="handleExportAllReport"
        size="small"
        :icon="useRenderIcon('arrow-up-line')"
        type="primary"
        >导出</el-button
      >
    </template>
  </PageContainer>
</template>
