108 lines
3.1 KiB
TypeScript
108 lines
3.1 KiB
TypeScript
import createAxios from '@/utils/request';
|
|
import { downloadBlob } from '@/api/common/download.ts';
|
|
import type {
|
|
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 PurchaseContainerOrderParams {
|
|
order_id: 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<IPurchaseDetail>({
|
|
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<IPurchaseCell>({
|
|
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<IPurchaseStoreSummary>({
|
|
url: `/purchase/order/${purchaseId}/store`,
|
|
method: 'get',
|
|
params: { store_id: storeId },
|
|
});
|
|
}
|
|
|
|
/** 采购单周转框/托盘合并记录修改:按门店覆盖全部订单逐笔更新(自动重算附加金额与订单总金额) */
|
|
export async function updatePurchaseContainer(
|
|
purchaseId: number,
|
|
storeId: number,
|
|
orders: PurchaseContainerOrderParams[],
|
|
) {
|
|
return createAxios({
|
|
url: `/purchase/order/${purchaseId}/container/${storeId}`,
|
|
method: 'put',
|
|
data: { orders },
|
|
});
|
|
}
|
|
|
|
/** C2/C3 导出采购单(Excel 表格):type=all 全品类 / category 仅蔬果分类 */
|
|
export async function exportPurchase(id: number, type: PurchaseExportType = 'all') {
|
|
return downloadBlob(
|
|
`/purchase/order/${id}/export`,
|
|
{ type },
|
|
`采购单_${id}.xlsx`,
|
|
);
|
|
}
|