oms/frontend/src/api/stockOrder.ts
liufumingren a51cb4df15 feat(frontend): 初始化 Vue3 + Vite 前端工程与业务页面
- 工程脚手架:Vite、TypeScript 配置、路由、Pinia store(auth/principal/menu)、请求封装
- 布局与通用组件:BasicLayout、SideMenu、DataTable/VirtualTable、VirtualSelect、ProductSelect、ImageUploader 等
- 业务页面:登录、首页、商品、店铺、店铺商品、组合商品、仓库/接口配置、库存、入库单、出库单、发货单(列表 + 创建)、外部接口、主体/主体用户、个人资料
- API 层:api/*.ts 与后端接口一一对应
2026-09-13 02:23:51 +08:00

137 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { get, post, put, del } from '@/utils/request'
/** 单据类型:1入库 2出库 */
export const STOCK_BILL_TYPE = { inbound: 1, outbound: 2 } as const
export type StockBillType = 1 | 2
/** 出入库明细行 */
export interface StockItemLine {
id: number
principal_id: number
bill_type: number
bill_id: number
shop_id: number | null
product_id: number | null
combo_product_id: number | null
shop_product_id: number | null
name: string | null
code: string | null
spec: string | null
unit: string | null
quantity: number | string
/** 应/已数量(系统维护:应=明细数量,已=WMS 回推),只读 */
plan_in_qty?: number | string
actual_in_qty?: number | string
plan_out_qty?: number | string
actual_out_qty?: number | string
price: number | string | null
total_amount: number | string
remark: string | null
inventory_type?: string | null
product?: { id: number; item_code: string; item_name: string; sku_property: string | null } | null
comboProduct?: { id: number; code: string; name: string } | null
}
/** 明细提交载荷 */
export interface StockItemPayload {
bill_id?: number
bill_type?: number
shop_id?: number | null
product_id?: number | null
combo_product_id?: number | null
shop_product_id?: number | null
name?: string | null
code?: string | null
spec?: string | null
unit?: string | null
quantity?: number
price?: number | null
remark?: string | null
}
/** 出入库单据(单据头) */
export interface StockOrder {
id: number
bill_no: string
principal_id: number
shop_id: number | null
inbound_type?: number
outbound_type?: number
status: number
supplier?: string | null
customer?: string | null
operator?: string | null
total_amount: number | string
remark?: string | null
created_by?: number | null
creator?: { id: number; nickname?: string | null; username?: string } | null
warehouse_id?: number | null
warehouse?: { id: number; code: string; name: string } | null
item_total?: number | string
item_kind?: number | null
shop?: { id: number; name: string } | null
items?: StockItemLine[]
created_at?: string
updated_at?: string
}
/** 单据提交载荷 */
export interface StockOrderPayload {
shop_id?: number | null
warehouse_id?: number | null
inbound_type?: number
outbound_type?: number
status?: number
supplier?: string | null
customer?: string | null
operator?: string | null
total_amount?: number
remark?: string
items?: StockItemPayload[]
}
export interface StockOrderApi {
getList: (params?: object) => Promise<{ list: StockOrder[]; total: number; page: number; pageSize: number }>
create: (data: StockOrderPayload) => Promise<{ id: number }>
update: (id: number, data: Partial<StockOrderPayload>) => Promise<{ id: number }>
audit: (id: number) => Promise<{ id: number }>
push: (id: number) => Promise<{ id: number }>
complete: (id: number) => Promise<{ id: number }>
cancel: (id: number) => Promise<{ id: number }>
restore: (id: number) => Promise<{ id: number }>
remove: (id: number) => Promise<{ id: number }>
getItems: (billId: number, params?: object) => Promise<{ list: StockItemLine[]; total: number; page: number; pageSize: number }>
createItem: (data: StockItemPayload) => Promise<{ id: number }>
updateItem: (id: number, data: Partial<StockItemPayload>) => Promise<{ id: number }>
removeItem: (id: number) => Promise<{ id: number }>
}
/**
* 按单据类型生成出入库 API(入库/出库共用同一套逻辑,仅 base 路径与 bill_type 不同)
* @param billType 1入库 2出库
*/
export function createStockOrderApi(billType: StockBillType): StockOrderApi {
const base = billType === STOCK_BILL_TYPE.inbound ? '/inbound-orders' : '/outbound-orders'
return {
getList: (params) =>
get<{ list: StockOrder[]; total: number; page: number; pageSize: number }>(base, params),
create: (data) => post<{ id: number }>(base, data),
update: (id, data) => put<{ id: number }>(`${base}/${id}`, data),
audit: (id) => post<{ id: number }>(`${base}/${id}/audit`),
push: (id) => post<{ id: number }>(`${base}/${id}/push`),
complete: (id) => post<{ id: number }>(`${base}/${id}/complete`),
cancel: (id) => post<{ id: number }>(`${base}/${id}/cancel`),
restore: (id) => post<{ id: number }>(`${base}/${id}/restore`),
remove: (id) => del<{ id: number }>(`${base}/${id}`),
getItems: (billId, params) =>
get<{ list: StockItemLine[]; total: number; page: number; pageSize: number }>('/stock-items', {
bill_id: billId,
bill_type: billType,
...params,
}),
createItem: (data) => post<{ id: number }>('/stock-items', { ...data, bill_type: billType }),
updateItem: (id, data) => put<{ id: number }>(`/stock-items/${id}`, data),
removeItem: (id) => del<{ id: number }>(`/stock-items/${id}`),
}
}