<script lang="ts" setup>
import { ref } from 'vue';

import { Page } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';

import { Button } from 'ant-design-vue';

import { statisticsApi } from '#/api/statistics';

// 下载全部报表
const downloadAllReportsLoading = ref(false);
async function downloadAllReports() {
  downloadAllReportsLoading.value = true;
  try {
    // 下载全部报表
    const Blob = await statisticsApi.downloadAllMonthIncomeStatistics();

    downloadFileFromBlobPart({
      source: Blob,
      fileName: '财务报表.xlsx',
    });
  } catch (error) {
    console.error('下载全部报表失败:', error);
  } finally {
    downloadAllReportsLoading.value = false;
  }
}
</script>

<template>
  <Page auto-content-height>
    <div class="flex h-full rounded-md bg-white p-4">
      <Button type="primary" :loading="downloadAllReportsLoading" @click="downloadAllReports">
        下载报表
      </Button>
    </div>
  </Page>
</template>

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