import createAxios from '@/utils/request'; import type { ExportFormat, IAllocationResult, IPurchaseOrderItem, PurchaseExportType, } from '@/domain/iPurchaseOrder.ts'; import { downloadBlob } from '@/api/common/download.ts'; export interface PurchaseItemUpdateParams { product_name?: string; product_spec?: string; price: number | string; quantity: number | string; weight?: number | string; remark?: string; } /** C1 按门店订单汇总生成采购单 */ export async function generatePurchase(purchase_date: string) { return createAxios<{ id: number; purchase_no: string }>({ url: '/purchase/order/generate', method: 'post', data: { purchase_date }, }); } /** C2/C3 导出采购单(blob 下载) */ export async function exportPurchase(id: number, type: PurchaseExportType, format: ExportFormat) { return downloadBlob( `/purchase/order/${id}/export`, { type, format }, `采购单_${id}.${format}` ); } /** C4 修改采购明细(amount 由后端重算) */ export async function updatePurchaseItem(id: number, data: PurchaseItemUpdateParams) { return createAxios<{ amount: string }>({ url: `/purchase/order/item/${id}`, method: 'put', data, }); } /** C5/C6 明细发送供应商 */ export async function sendPurchaseItem(id: number) { return createAxios({ url: `/purchase/order/item/${id}/send`, method: 'put', }); } /** D3 执行金额分摊 */ export async function allocatePurchase(id: number) { return createAxios<{ count: number }>({ url: `/purchase/order/${id}/allocate`, method: 'post', }); } /** 分摊结果(按门店 / 按商品聚合) */ export async function getAllocation(id: number) { return createAxios({ url: `/purchase/order/${id}/allocation`, method: 'get', }); } export type { IPurchaseOrderItem };