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 type { PayableService } from './typing'; enum Api { GetBillsPayableList = '/api/BillsPayable/QueryPage', GetBillsPayableDetail = '/api/BillsPayable/{orgId}/{id}', DeleteBillsPayable = '/api/BillsPayable/{orgId}/{id}', JoinBillsPayable = '/api/BillsPayable/{orgId}/{id}/Join', CreateBillsPayable = '/api/BillsPayable/{orgId}', SubmitBillsPayable = '/api/BillsPayable/{orgId}/{id}/submit', ApproveBillsPayable = '/api/BillsPayable/{orgId}/{id}/approve', ReversalBillsPayable = '/api/BillsPayable/{orgId}/{id}/reversal', ExportPayableNonCheck = '/api/BillsPayable/{orgId}/export-non-check', ExportPayableNonFree = '/api/BillsPayable/{orgId}/export-non-fee', ExportPayableNonPaid = '/api/BillsPayable/{orgId}/export-non-paid', ExportPayableIntCheck = '/api/BillsPayable/{orgId}/export-int-check', ExportPayableIntKingdee = '/api/BillsPayable/{orgid}/export-int-kingdee', } /** * 获取应付单列表 */ function getBillsPayableList(data: PayableService.GetBillsPayableListParams) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: Api.GetBillsPayableList, data: { ...data, orgId: getCompanyId }, }, { showLoading: true, }, ); } /** * 获取应付单详情 */ function getBillsPayableDetail(id: number) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.GetBillsPayableDetail, { id, orgId: getCompanyId }), }, { showLoading: true, }, ); } /** * 删除应付单 */ function deleteBillsPayable(id: number) { const { getCompanyId } = useUserStoreWithOut(); return request.delete( { url: replaceVariables(Api.DeleteBillsPayable, { orgId: getCompanyId, id }), }, { showLoading: true, successMessageMode: 'message', successMessage: '删除成功!', }, ); } /** * 应付单加入关联查询 */ function joinBillsPayable(id: number, orgId) { const { getCompanyId } = useUserStoreWithOut(); return request.get( { url: replaceVariables(Api.JoinBillsPayable, { id, orgId: orgId ?? getCompanyId }), }, { showLoading: true, }, ); } /** * 新建应付单 */ function createBillsPayable(data: PayableService.PayableItem) { const { getCompanyId } = useUserStoreWithOut(); return request.post( { url: replaceVariables(Api.CreateBillsPayable, { orgId: getCompanyId }), data, }, { showLoading: true, loadingTip: 'ADD', operationType: 'ADD', }, ); } /** * 提交应付单 */ function submitBillsPayable(id: number) { const { getCompanyId } = useUserStoreWithOut(); return request.put( { url: replaceVariables(Api.SubmitBillsPayable, { orgId: getCompanyId, id }), }, { showLoading: true, loadingTip: 'SUBMIT', operationType: 'SUBMIT', successMessageMode: 'message', }, ); } /** * 审核应付单 */ function approveBillsPayable(id: number) { const { getCompanyId } = useUserStoreWithOut(); return request.put( { url: replaceVariables(Api.ApproveBillsPayable, { orgId: getCompanyId, id }), }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '审核成功', successMessageMode: 'message', }, ); } /** * 红冲应付单 */ function reversalBillsPayable(id: number) { const { getCompanyId } = useUserStoreWithOut(); return request.put( { url: replaceVariables(Api.ReversalBillsPayable, { orgId: getCompanyId, id }), }, { showLoading: true, loadingTip: 'EMPTY', successMessage: '红冲成功', successMessageMode: 'message', }, ); } /** * 导出非关联交易应付单(检查) */ async function exportPayableNonCheck(data: FilterJson['filtersConditions']) { const { createMessage } = useMessage(); const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: replaceVariables(Api.ExportPayableNonCheck, { orgId: getCompanyId }), data, responseType: 'blob', timeout: 5 * 60 * 1000, }, { 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: '非关联交易应付单导出_检查数据使用', suffix: 'xlsx' }), ); createMessage.success('导出成功'); } /** * 导出非关联交易应付单_免费项目_金蝶使用 */ async function exportPayableNonFree(data: FilterJson['filtersConditions']) { const { createMessage } = useMessage(); const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: replaceVariables(Api.ExportPayableNonFree, { orgId: getCompanyId }), data, responseType: 'blob', timeout: 5 * 60 * 1000, }, { 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: '非关联交易应付单_免费项目_金蝶使用', suffix: 'xlsx' }), ); createMessage.success('导出成功'); } /** * 导出非关联交易应付单_收费项目_金蝶使用 */ async function exportPayableNonPaid(data: FilterJson['filtersConditions']) { const { createMessage } = useMessage(); const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: replaceVariables(Api.ExportPayableNonPaid, { orgId: getCompanyId }), data, responseType: 'blob', timeout: 5 * 60 * 1000, }, { 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: '非关联交易应付单_收费项目_金蝶使用', suffix: 'xlsx' }), ); createMessage.success('导出成功'); } /** * 导出关联交易应付单_检查数据使用 */ async function exportPayableIntCheck(data: FilterJson['filtersConditions']) { const { createMessage } = useMessage(); const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: replaceVariables(Api.ExportPayableIntCheck, { orgId: getCompanyId }), data, responseType: 'blob', timeout: 5 * 60 * 1000, }, { 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: '关联交易应付单导出_检查数据使用', suffix: 'xlsx' }), ); createMessage.success('导出成功'); } /** * 导出关联交易应付单_金蝶使用 */ async function exportPayableIntKingdee(data: FilterJson['filtersConditions']) { const { createMessage } = useMessage(); const { getCompanyId } = useUserStoreWithOut(); const _data = await request.post( { url: replaceVariables(Api.ExportPayableIntKingdee, { orgId: getCompanyId }), data, responseType: 'blob', timeout: 5 * 60 * 1000, }, { 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: '关联交易应付单导出_金蝶使用', suffix: 'xlsx' }), ); createMessage.success('导出成功'); } export { approveBillsPayable, createBillsPayable, deleteBillsPayable, exportPayableIntCheck, exportPayableIntKingdee, exportPayableNonCheck, exportPayableNonFree, exportPayableNonPaid, getBillsPayableDetail, getBillsPayableList, joinBillsPayable, reversalBillsPayable, submitBillsPayable, }; export type { PayableService } from './typing';