import { useMessage } from '@eciol/ant-ui'; import { request } from '@eciol/request'; import { blobToJson, downloadByData, replaceVariables } from '@eciol/shared'; import { useUserStoreWithOut } from '@/store/modules/user'; import { generateFileName } from '@/utils'; import type { DownloadInvoiceService } from './typing'; enum Api { GetDownloadInvoiceGstVatList = '/api/InvoiceGSTVAT/QueryPage', DownloadInvoiceGstVat = '/api/InvoiceGSTVAT/{orgid}/export-gstvat', DownloadInvoiceGstVatSelected = '/api/InvoiceGSTVAT/export-gstvatchoice', } /** * 申请下载InvoiceGSTVAT文件列表 * @param data */ function getDownloadInvoiceGstVatList(data: DownloadInvoiceService.GetDownloadInvoiceListParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: Api.GetDownloadInvoiceGstVatList, data: { ...data, orgId: getCompanyId }, }, { showLoading: true, }, ); } /** * 下载 */ async function downloadInvoiceGstVat(data) { const { createMessage } = useMessage(); const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: replaceVariables(Api.DownloadInvoiceGstVat, { orgid: getCompanyId }), data, responseType: 'blob', }, { showLoading: true, loadingTip: 'DOWNLOAD', successMessage: '下载成功', successMessageMode: 'message', isTransformResponse: false, }, ); if (_data.type === 'application/json') { const result = await blobToJson(_data); createMessage.error(result.message); return false; } downloadByData(_data, generateFileName({ fileName: 'gstvat', suffix: 'zip' })); createMessage.success('导出成功'); } /** * 下载 */ async function downloadInvoiceGstVatSelected(data) { const { createMessage } = useMessage(); const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: Api.DownloadInvoiceGstVatSelected, data: { ...data, orgId: getCompanyId }, responseType: 'blob', }, { showLoading: true, loadingTip: 'DOWNLOAD', successMessage: '下载成功', successMessageMode: 'message', isTransformResponse: false, }, ); if (_data.type === 'application/json') { const result = await blobToJson(_data); createMessage.error(result.message); return false; } downloadByData(_data, generateFileName({ fileName: 'gstvat', suffix: 'zip' })); createMessage.success('导出成功'); } export { downloadInvoiceGstVat, downloadInvoiceGstVatSelected, getDownloadInvoiceGstVatList };