add product sku
This commit is contained in:
+36
-6
@@ -1,4 +1,4 @@
|
||||
import type { Product, ProductCategoryStatus, ProductStatus, ProductType, StockOperationType } from "@/types/Product";
|
||||
import type { Product, ProductCategoryStatus, ProductSku, ProductSpec, ProductSpecValue, ProductStatus, ProductType, StockOperationType } from "@/types/Product";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment.ts";
|
||||
|
||||
/** 生成产品域写操作的幂等请求号。一次失败重试应复用调用方已经生成的请求号。 */
|
||||
@@ -44,8 +44,8 @@ export function normalizeProductQuantity(value: number | string): string | undef
|
||||
}
|
||||
|
||||
/** 根据产品数量规则返回数量控件步长。允许小数时固定步进 0.1。 */
|
||||
export function getProductQuantityStep(product?: Pick<Product, "allowDecimalQuantity">): number {
|
||||
return product?.allowDecimalQuantity ? .1 : 1;
|
||||
export function getProductQuantityStep(sku?: Pick<ProductSku, "allowDecimalQuantity">): number {
|
||||
return sku?.allowDecimalQuantity ? .1 : 1;
|
||||
}
|
||||
|
||||
export function getProductTypeText(type?: ProductType): string {
|
||||
@@ -83,7 +83,7 @@ export function getStockOperationText(type?: StockOperationType): string {
|
||||
} as Record<string, string>)[type || ""] || "未知操作";
|
||||
}
|
||||
|
||||
export function getProductPhotoURL(item: Pick<Product, "attachmentList">): string {
|
||||
export function getProductPhotoURL(item: Pick<Product | ProductSku, "attachmentList">): string {
|
||||
const attachment = item.attachmentList?.find(item => item.attachType === "PHOTO" && !!item.id);
|
||||
return attachment?.id ? getAttachmentReadURL(attachment.id, 128) : "";
|
||||
}
|
||||
@@ -97,6 +97,36 @@ export function getProductQuantityText(value?: number | string | null): string {
|
||||
}
|
||||
|
||||
/** 从产品单位列表中获取基础单位名称。 */
|
||||
export function getProductBaseUnitName(product?: Product): string {
|
||||
return product?.unitList?.find(unit => unit.isBase)?.name || "";
|
||||
export function getProductBaseUnitName(sku?: ProductSku): string {
|
||||
return sku?.unitList?.find(unit => unit.isBase)?.name || "";
|
||||
}
|
||||
|
||||
/** 组合产品名、SKU 名称和规格摘要,供选品后的业务页面统一展示。 */
|
||||
export function getProductSkuText(productName: string | undefined, sku?: Pick<ProductSku, "name" | "specSummary">): string {
|
||||
const skuText = sku?.specSummary || sku?.name;
|
||||
return skuText && skuText !== productName ? `${productName || "未命名产品"} · ${skuText}` : productName || "未命名产品";
|
||||
}
|
||||
|
||||
export type ProductSkuSpecEntry = {
|
||||
specName: string;
|
||||
valueName: string;
|
||||
};
|
||||
|
||||
type ProductEditorSpec = Pick<ProductSpec, "name"> & {
|
||||
valueList?: Array<Pick<ProductSpecValue, "id" | "name"> & { clientKey?: string }>;
|
||||
};
|
||||
|
||||
/** 根据 SKU 保存的规格值 ID,返回可直接展示的规格项和规格值。 */
|
||||
export function getProductSkuSpecEntries(sku: Pick<ProductSku, "specValueIdList">, specList: ProductEditorSpec[]): ProductSkuSpecEntry[] {
|
||||
const valueIdSet = new Set(sku.specValueIdList || []);
|
||||
return specList.flatMap((spec, specIndex) => {
|
||||
const value = (spec.valueList || []).find(item => valueIdSet.has(item.id || item.clientKey || ""));
|
||||
if (!value) {
|
||||
return [];
|
||||
}
|
||||
return [{
|
||||
specName: spec.name.trim() || `规格项 ${specIndex + 1}`,
|
||||
valueName: value.name.trim() || "未命名规格值"
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user