import { useMessage } from '@eciol/ant-ui'; import { request } from '@eciol/request'; import { blobToJson, downloadByData, replaceVariables } from '@eciol/shared'; import type { FilterJson } from '@/api'; import { useUserStoreWithOut } from '@/store/modules/user'; import { generateFileName } from '@/utils'; import type { CancellationService } from './typing'; enum Api { GetCancellationList = '/api/RecMatch/QueryPage', GetInvoiceList = '/api/RecMatch/{orgId}/GetInvoiceList', GetInvoiceDetail = '/api/RecMatch/{orgId}/{id}/GetDetail', SaveCancellation = '/api/RecMatch/{orgId}/Save', GetEditInfo = '/api/RecMatch/{orgId}/{id}/GetEdit', InvoiceSubmit = '/api/RecMatch/{orgId}/{billId}/{procInstId}/Submit', DeApply = '/api/RecMatch/{orgId}/{billId}/DeApply', GetFinanceApproveInfo = '/api/openapi/GetReceiveApproveRole/{id}/{type}', ExportCancellation = '/api/RecMatch/{id}/export-match', SendEmail = '/api/RecMatch/ResendEmail/{billId}', } /** * 核销单列表 * @param data */ function getCancellationList(data: CancellationService.GetCancellationListParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: Api.GetCancellationList, data: { ...data, orgId: getCompanyId }, }, { showLoading: true, }, ); } /** * 核销单创建获取销售发票列表 */ function getCancelInvoiceList(data: CancellationService.GetInvoiceListParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.GetInvoiceList, { orgId: getCompanyId }), data, }, { showLoading: true, }, ); } /** * 获取核销单详细 * @param id */ function getCancelInvoiceDetail(id: number) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.GetInvoiceDetail, { id, orgId: getCompanyId }), }, { showLoading: true, }, ); } /** * 保存核销单核销信息 * @param data */ function saveCancellation(data: CancellationService.SaveCancellationParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.SaveCancellation, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '保存成功', successMessageMode: 'message', }, ); } /** * 获取核销单编辑信息 * @param id */ function getEditInfo(id: number) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.GetEditInfo, { id, orgId: getCompanyId }), }, { showLoading: true, }, ); } /** * 提交审核 */ function submitCancellation(billId: number, procInstId: string) { const { getCompanyId } = useUserStoreWithOut(); return request.put( { url: replaceVariables(Api.InvoiceSubmit, { billId, orgId: getCompanyId, procInstId }), }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '提交审核成功', successMessageMode: 'message', }, ); } function deApplyCancellation(billId: number) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.DeApply, { billId, orgId: getCompanyId }), }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '反审核成功', successMessageMode: 'message', }, ); } function sendEmail(billId: number) { return request.post( { url: replaceVariables(Api.SendEmail, { billId }), }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '补发邮件成功', successMessageMode: 'message', }, ); } function getFinanceApproveInfo(id: number, type: 1 | 2) { return request.get<{ companyID: number; financeRoleID: number }>( { url: replaceVariables(Api.GetFinanceApproveInfo, { id, type }), }, {}, ); } /** * 导出 */ async function exportCancellation(data: FilterJson['filtersConditions'], id: string) { const { createMessage } = useMessage(); // const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: replaceVariables(Api.ExportCancellation, { id }), 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: 'Cancellation', suffix: 'xlsx' })); createMessage.success('导出成功'); } export { deApplyCancellation, exportCancellation, getCancelInvoiceDetail, getCancelInvoiceList, getCancellationList, getEditInfo, getFinanceApproveInfo, saveCancellation, sendEmail, submitCancellation, }; export type { CancellationService } from './typing';