import { get, post, put, del } from '@/utils/request' import type { StockItemLine, StockItemPayload } from './stockOrder' /** 入库单(单据头) */ export interface InboundOrder { id: number bill_no: string principal_id: number /** 所属货主(下属公司ID),跟随仓库 */ subsidiary_id?: number | null /** 所属货主名称(列表/详情接口返回) */ subsidiary_name?: string shop_id: number | null inbound_type: string status: number warehouse_id: number | null warehouse?: { id: number; code: string; name: string } | null shop?: { id: number; name: string } | null creator?: { id: number; nickname?: string | null; username: string } | null /** 创建人展示名(员工名称,后端按 principal_users.name 解析) */ creator_name?: string auditor?: { id: number; nickname?: string | null; username: string } | null /** 审核人展示名(员工名称) */ auditor_name?: string audit_by?: number | null audit_time?: string | null supplier?: string | null supplier_code?: string | null operator?: string | null operator_code?: string | null operate_time?: string | null purchase_order_code?: string | null expect_start_time?: string | null expect_end_time?: string | null logistics_code?: string | null logistics_name?: string | null express_code?: string | null /** 发件人信息(仅本地留存:WMS 入库单报文不识别,不下发) */ sender_info?: Record | null /** 收件人信息(仅本地留存:WMS 入库单报文不识别,不下发) */ receiver_info?: Record | null /** 扩展属性(仅本地留存:不下发) */ extend_props?: Record | null pushed_at?: string | null wms_push_result?: { success?: boolean code?: string | number | null message?: string | null flag?: string | null entryOrderCode?: string warehouseApiId?: number apiType?: string response?: unknown error?: string pushedAt?: string } | null item_total: number | string item_kind: number | null total_amount: number | string remark?: string | null void_at?: string | null void_by?: number | null void_reason?: string | null voider?: { id: number; nickname?: string | null; username: string } | null /** 作废人展示名(员工名称) */ voider_name?: string items?: StockItemLine[] created_at?: string updated_at?: string } /** 明细行(创建时随单提交) */ export interface InboundItemInput { product_id?: number | null name?: string | null code?: string | null spec?: string | null unit?: string | null quantity?: number price?: number | null inventory_type?: 'ZP' | 'CC' remark?: string | null } /** 创建 / 更新载荷 */ export interface InboundOrderPayload { warehouse_id?: number | null shop_id?: number | null inbound_type?: string status?: number supplier?: string | null supplier_code?: string | null operate_time?: string | null purchase_order_code?: string | null expect_start_time?: string | null expect_end_time?: string | null logistics_code?: string | null logistics_name?: string | null express_code?: string | null total_amount?: number remark?: string | null items?: InboundItemInput[] } /** 明细提交(含库存类型 ZP 正品 / CC 残次) */ export type InboundItemPayload = StockItemPayload & { inventory_type?: 'ZP' | 'CC' } export const inboundOrderApi = { getList: (params?: object) => get<{ list: InboundOrder[]; total: number; page: number; pageSize: number }>('/inbound-orders', params), get: (id: number) => get(`/inbound-orders/${id}`), create: (data: InboundOrderPayload) => post<{ id: number }>('/inbound-orders', data), update: (id: number, data: Partial) => put<{ id: number }>(`/inbound-orders/${id}`, data), audit: (id: number) => post<{ id: number }>(`/inbound-orders/${id}/audit`), push: (id: number) => post<{ id: number; reused?: boolean }>(`/inbound-orders/${id}/push`), complete: (id: number) => post<{ id: number }>(`/inbound-orders/${id}/complete`), cancel: (id: number) => post<{ id: number }>(`/inbound-orders/${id}/cancel`), restore: (id: number) => post<{ id: number }>(`/inbound-orders/${id}/restore`), /** 作废:仅「已审核(2)」可作废,记录作废人/时间/原因,不可恢复 */ voidOrder: (id: number, data?: { void_reason?: string }) => post<{ id: number }>(`/inbound-orders/${id}/void`, data || {}), /** 驳回:已审核(2)/已推送(3) 且未完成 -> 回到待入库(1),已推送的先走接口取消外部单据 */ reject: (id: number) => post<{ id: number bill_no?: string cancel?: { attempted: boolean; success: boolean; orderType?: string; message?: string } }>(`/inbound-orders/${id}/reject`), remove: (id: number) => del<{ id: number }>(`/inbound-orders/${id}`), /** 明细列表(复用通用 stock_items,bill_type=1 入库) */ getItems: (billId: number, params?: object) => get<{ list: StockItemLine[]; total: number; page: number; pageSize: number }>('/stock-items', { bill_id: billId, bill_type: 1, ...params, }), createItem: (data: InboundItemPayload) => post<{ id: number }>('/stock-items', { ...data, bill_type: 1 }), updateItem: (id: number, data: Partial) => put<{ id: number }>(`/stock-items/${id}`, data), removeItem: (id: number) => del<{ id: number }>(`/stock-items/${id}`), }