| | |
| | | import type { PageParam, PageResult } from '../../../../packages/effects/request/src'; |
| | | import type { PageParam, PageResult } from '@vben/request'; |
| | | |
| | | import { requestClient } from '#/api/request'; |
| | | |
| | |
| | | id?: number; // 编号 |
| | | no?: string; // 申请编号 |
| | | status?: number; // 状态:0未提交 10审批中 20审核通过 30审核不通过 40已取消 |
| | | processInstanceId?: string; // 工作流编号 |
| | | requestUserId?: number; // 申请人编号 |
| | | requestUserName?: string; // 申请人名称 |
| | | requestDeptId?: number; // 申请部门编号 |
| | |
| | | supplierId?: number; // 供应商编号 |
| | | supplierName?: string; // 供应商名称 |
| | | discountPercent?: number; // 优惠率 |
| | | fileUrl?: string; // 附件地址 |
| | | attachmentList?: { id: number; name?: string; url?: string }[]; // 附件列表 |
| | | remark?: string; // 备注 |
| | | totalCount?: number; // 总数量 |
| | | totalPrice?: number; // 总金额 |
| | | productNames?: string; // 产品名称列表 |
| | | orderId?: number; // 生成的采购订单编号 |
| | | orderNo?: string; // 生成的采购订单号 |
| | | processInstanceId?: number; // 审批流程实例编号 |
| | | items?: PurchaseRequestItem[]; // 申请明细 |
| | | createTime?: string; // 创建时间 |
| | | } |
| | |
| | | return requestClient.put('/erp/purchase-request/submit', null, { params: { id, processDefinitionKey } }); |
| | | } |
| | | |
| | | /** 重置被驳回的采购申请为草稿状态 */ |
| | | export function resetPurchaseRequestStatus(id: number) { |
| | | return requestClient.put('/erp/purchase-request/reset-status', null, { params: { id } }); |
| | | } |
| | | |
| | | /** 生成采购订单 */ |
| | | export function generatePurchaseOrder(id: number, supplierId: number) { |
| | | return requestClient.post<number>('/erp/purchase-request/generate-order', null, { params: { id, supplierId } }); |
| | |
| | | export function getApproveProcessList(id: number) { |
| | | return requestClient.get(`/erp/purchase-request/approve-process-list`, { params: { id } }); |
| | | } |
| | | |
| | | /** BPM 流程实例状态 → 业务状态映射 */ |
| | | export const BPM_STATUS_TO_BIZ: Record<number, number> = { |
| | | 1: 10, // RUNNING → 审批中 |
| | | 2: 20, // APPROVE → 审核通过 |
| | | 3: 30, // REJECT → 审核不通过 |
| | | 4: 40, // CANCEL → 已取消 |
| | | }; |
| | | |
| | | /** |
| | | * 同步采购申请的业务状态(根据 BPM 流程实例实际状态) |
| | | * 用于修复后端监听器未正确回写导致的业务状态不一致问题 |
| | | */ |
| | | export async function syncPurchaseRequestStatus(items: ErpPurchaseRequestApi.PurchaseRequest[]) { |
| | | const processingItems = items.filter( |
| | | (item) => item.status === 10 && item.processInstanceId, |
| | | ); |
| | | if (processingItems.length === 0) return; |
| | | |
| | | const { getApprovalDetail } = await import('#/api/bpm/processInstance'); |
| | | for (const item of processingItems) { |
| | | try { |
| | | const detail = await getApprovalDetail({ |
| | | processInstanceId: item.processInstanceId, |
| | | }); |
| | | const bizStatus = BPM_STATUS_TO_BIZ[detail.processInstance?.status]; |
| | | if (bizStatus && bizStatus !== 10) { |
| | | item.status = bizStatus; |
| | | } |
| | | } catch { |
| | | // 查询失败时保持原有状态 |
| | | } |
| | | } |
| | | } |