185 lines
5.8 KiB
TypeScript
185 lines
5.8 KiB
TypeScript
import createAxios from '@/utils/request';
|
|
import { downloadBlob } from '@/api/common/download.ts';
|
|
import type {
|
|
IBillPrepare,
|
|
IPurchaseCell,
|
|
IPurchaseDetail,
|
|
IPurchaseStoreSummary,
|
|
PurchaseStoreItemAddParams,
|
|
PurchaseStoreItemUpdateParams,
|
|
} 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;
|
|
/** 售后金额(可正负,计入总金额;正数=加收,负数=售后减免) */
|
|
after_sale?: number;
|
|
/** 备注 */
|
|
remark?: string;
|
|
}
|
|
|
|
|
|
/** 生成采购单 */
|
|
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 togglePurchaseItemCheck(purchaseId: number, productId: number) {
|
|
return createAxios<{ checked: boolean }>({
|
|
url: `/purchase/order/${purchaseId}/check/${productId}`,
|
|
method: 'put',
|
|
});
|
|
}
|
|
|
|
/** 批量设置单品「已对账」标记(全选:checked=true 批量标记,false 批量取消) */
|
|
export async function batchPurchaseItemCheck(purchaseId: number, productIds: number[], checked: boolean) {
|
|
return createAxios<{ count: number }>({
|
|
url: `/purchase/order/${purchaseId}/check`,
|
|
method: 'put',
|
|
data: { product_ids: productIds, checked },
|
|
});
|
|
}
|
|
|
|
/** 门店订单明细修改(订货量、重量、单价),自动重算价格 */
|
|
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 getBillPrepare(purchaseId: number) {
|
|
return createAxios<IBillPrepare>({
|
|
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 },
|
|
});
|
|
}
|
|
|
|
/** 门店购买详情:新增单品(挂靠该门店在采购单中的最新一笔订单) */
|
|
export async function addPurchaseStoreItem(purchaseId: number, storeId: number, data: PurchaseStoreItemAddParams) {
|
|
return createAxios<{ id: number }>({
|
|
url: `/purchase/order/${purchaseId}/store/${storeId}/item`,
|
|
method: 'post',
|
|
data,
|
|
});
|
|
}
|
|
|
|
/** 门店购买详情:修改单品(数量/称重/单价;同商品多笔订单明细时合并到最早一条) */
|
|
export async function updatePurchaseStoreItem(
|
|
purchaseId: number,
|
|
storeId: number,
|
|
productId: number,
|
|
data: PurchaseStoreItemUpdateParams,
|
|
) {
|
|
return createAxios({
|
|
url: `/purchase/order/${purchaseId}/store/${storeId}/item/${productId}`,
|
|
method: 'put',
|
|
data,
|
|
});
|
|
}
|
|
|
|
/** 门店购买详情:移除单品 */
|
|
export async function removePurchaseStoreItem(purchaseId: number, storeId: number, productId: number) {
|
|
return createAxios({
|
|
url: `/purchase/order/${purchaseId}/store/${storeId}/item/${productId}`,
|
|
method: 'delete',
|
|
});
|
|
}
|
|
|
|
/** 导出采购单商品明细(系统全部商品行,支持按供应商筛选) */
|
|
export async function exportPurchase(id: number, supplierId?: number) {
|
|
return downloadBlob(
|
|
`/purchase/order/${id}/export`,
|
|
supplierId ? { supplier_id: supplierId } : {},
|
|
`采购单_${id}.xlsx`,
|
|
);
|
|
}
|
|
|
|
/** 导出门店购买详情(多工作表;storeId 单门店导出) */
|
|
export async function exportPurchaseStores(id: number, storeId?: number) {
|
|
return downloadBlob(
|
|
`/purchase/order/${id}/exportStores`,
|
|
storeId ? { store_id: storeId } : {},
|
|
`门店购买详情_${id}.xlsx`,
|
|
);
|
|
}
|
|
|
|
/** 导出供应商采购明细(多工作表;supplierId 单供应商导出) */
|
|
export async function exportPurchaseSuppliers(id: number, supplierId?: number) {
|
|
return downloadBlob(
|
|
`/purchase/order/${id}/exportSuppliers`,
|
|
supplierId ? { supplier_id: supplierId } : {},
|
|
`供应商采购明细_${id}.xlsx`,
|
|
);
|
|
}
|