import type IProductCategory from '@/domain/iProductCategory.ts'; import type ISupplier from '@/domain/iSupplier.ts'; import type {ISysFileInfo} from "@/domain/iSysFile.ts"; /** 商品等级价格行(null = 该等级未设定价格,编辑时移除该行) */ export interface IProductPrice { id?: number; product_id?: number; level_id?: number; /** 单价:固定价=实际单价;成本百分比=等价固定价 */ price?: string | number | null; /** 计价类型:0 固定价(默认) 1 成本百分比 */ price_type?: number; /** 成本上浮百分点(price_type=1 时生效,如 30 = 上浮 30%) */ percent?: string | number | null; /** 实际销售价(模型换算:百分比 = 成本价 × (100 + percent) / 100) */ actual_price?: string | number; level?: { id: number; name: string }; } /** 商品档案 */ export default interface IProduct { /** 商品ID */ id?: number; /** 分类ID */ category_id?: number; /** 供应商ID */ supplier_id?: number; /** 商品名称 */ name?: string; /** 规格/包规 */ spec?: string; /** 计价单位 */ unit?: string; /** 封面 */ image_ids?: string; images_arr?: ISysFileInfo[]; /** 商品图文详情(富文本 HTML) */ content?: string; /** 排序 */ sort?: number; /** 保质期 */ shelf_life?: number; /** 库存 */ stock?: number; /** 状态 */ status?: number; /** 成本价(元,成本百分比计价的基数) */ cost_price?: string | number; /** 描述 */ remark?: string; /** 分类关联数据 */ category?: IProductCategory; /** 供应商关联数据 */ supplier?: ISupplier; /** 多等级价格 */ prices?: IProductPrice[]; /** 创建时间 */ created_at?: string; } export const PRODUCT_STATUS_MAP: Record = { 0: { text: '下架', color: 'default' }, 1: { text: '上架', color: 'success' }, }; /** * 价格矩阵行:固定列 + price_{level_id}(实际价)/ price_type_{level_id} / percent_{level_id} 动态列 */ export type IPriceMatrixRow = { id: number; name: string; spec?: string; unit?: string; /** 成本价(null = 未设置或已清除) */ cost_price?: string | number | null; } & Record; export interface IPriceMatrix { levels: { id: number; name: string }[]; rows: IPriceMatrixRow[]; total: number; } /** * 批量调价更新行(三类,可混合同一行): * - 成本行 { product_id, cost_price } * - 固定价行 { product_id, level_id, price_type: 0, price } * - 百分比行 { product_id, level_id, price_type: 1, percent }(price 可选,等价固定价) */ export interface IBatchPriceUpdate { product_id: number; /** 成本价(成本行) */ cost_price?: number; /** 客户等级ID(等级价格行) */ level_id?: number; /** 计价类型:0 固定价(默认) 1 成本百分比 */ price_type?: number; /** 固定价 / 百分比行的等价固定价 */ price?: number; /** 成本上浮百分点(price_type=1 时必填) */ percent?: number; }