import { useMessage } from '@eciol/ant-ui'; import { request } from '@eciol/request'; import { blobToJson, downloadByData, replaceVariables } from '@eciol/shared'; import { FilterJson } from '@/api'; import { useUserStoreWithOut } from '@/store/modules/user'; import { generateFileName } from '@/utils'; import { VoucherService } from './typing'; enum Api { GetVoucherList = '/api/Voucher/QueryPage', ExportVoucher = '/api/Voucher/{orgid}/export-non-check', } /** * 凭证列表 * @param data */ function getVoucherList(data: VoucherService.GetVoucherListParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: Api.GetVoucherList, data: { ...data, orgId: getCompanyId }, }, { showLoading: true, }, ); } /** * 凭证导出 */ async function exportVoucher(data: FilterJson['filtersConditions']) { const { createMessage } = useMessage(); const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: replaceVariables(Api.ExportVoucher, { orgid: getCompanyId }), data, responseType: 'blob', }, { showLoading: true, 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: 'Voucher', suffix: 'xlsx' })); createMessage.success('导出成功'); } export { exportVoucher, getVoucherList }; export type { VoucherService } from './typing';