71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
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 合并「已接单」门店订单生成采购单(order_ids 为空 = 全部已接单;生成后源订单转采购中) */
|
|
export async function generatePurchase(purchase_date: string, order_ids?: number[]) {
|
|
return createAxios<{ id: number; purchase_no: string }>({
|
|
url: '/purchase/order/generate',
|
|
method: 'post',
|
|
data: { purchase_date, order_ids },
|
|
});
|
|
}
|
|
|
|
/** 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<IAllocationResult>({
|
|
url: `/purchase/order/${id}/allocation`,
|
|
method: 'get',
|
|
});
|
|
}
|
|
|
|
export type { IPurchaseOrderItem };
|