import createAxios from '@/utils/request'; import { downloadBlob } from '@/api/common/download.ts'; import type { IBillPrepare, IPurchaseCell, IPurchaseDetail, IPurchaseStoreSummary, PurchaseExportType, } from '@/domain/iPurchaseOrder.ts'; /** 订单商品参数修改 */ export interface PurchaseRowUpdateParams { product_name: string; supplier_id: number; product_spec: string; unit: string; cost_price: number; } /** 修改门店订单明细参数 */ export interface PurchaseCellUpdateParams { quantity: number; price: number; weight?: number; } /** 生成账单:单个门店的配送费/周转筐/托盘数量 */ export interface BillGenerateStoreParams { store_id: number; delivery_fee: number; box_num: number; tray_num: number; } /** 生成采购单 */ 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 }, }); } /** 采购单详情 */ export async function getPurchaseDetail(id: number) { return createAxios({ url: `/purchase/order/${id}`, method: 'get', }); } /** 商品行修改 */ export async function updatePurchaseRow(purchaseId: number, productId: number, data: PurchaseRowUpdateParams) { return createAxios<{ count: number }>({ url: `/purchase/order/${purchaseId}/row/${productId}`, method: 'put', data, }); } /** 单元格下钻:采购单中某门店某商品的全部订货明细 */ export async function getPurchaseCell(purchaseId: number, productId: number, storeId: number) { return createAxios({ url: `/purchase/order/${purchaseId}/cell`, method: 'get', params: { product_id: productId, store_id: storeId }, }); } /** 门店订单明细修改(订货量、重量、单价),自动重算价格 */ export async function updatePurchaseCellItem(itemId: number, data: PurchaseCellUpdateParams) { return createAxios({ url: `/purchase/order/cell/${itemId}`, method: 'put', data, }); } /** 门店购买详情:采购单内某门店的采购汇总(按商品聚合) */ export async function getPurchaseStoreSummary(purchaseId: number, storeId: number) { return createAxios({ url: `/purchase/order/${purchaseId}/store`, method: 'get', params: { store_id: storeId }, }); } /** 账单生成预览:按门店汇总商品金额(金额只读) */ export async function getBillPrepare(purchaseId: number) { return createAxios({ url: `/purchase/order/${purchaseId}/bill/prepare`, method: 'get', }); } /** 生成账单:已完成采购单按门店各生成一张(关联采购单全部订单,金额由系统汇总不可修改) */ export async function generateBill(purchaseId: number, stores: BillGenerateStoreParams[]) { return createAxios<{ count: number }>({ url: `/purchase/order/${purchaseId}/bill`, method: 'post', data: { stores }, }); } /** C2/C3 导出采购单(Excel 表格):type=all 全品类 / category 仅蔬果分类 */ export async function exportPurchase(id: number, type: PurchaseExportType = 'all') { return downloadBlob( `/purchase/order/${id}/export`, { type }, `采购单_${id}.xlsx`, ); }