mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 05:09:21 +08:00
feat: SKU 增加单件实重 weight_g,为按重算快递费预留
This commit is contained in:
@@ -11,6 +11,8 @@ export namespace ProductSkuDTO {
|
||||
name: string;
|
||||
/** SKU 编码 */
|
||||
skuCode?: string;
|
||||
/** 单件实重(克);空=未填 */
|
||||
weightG?: number | null;
|
||||
/** 商品成本 */
|
||||
productCost: number;
|
||||
/** 运费成本 */
|
||||
@@ -31,6 +33,8 @@ export namespace ProductSkuDTO {
|
||||
name: string;
|
||||
/** SKU 编码 */
|
||||
skuCode?: string;
|
||||
/** 单件实重(克);空=未填 */
|
||||
weightG?: number | null;
|
||||
/** 商品成本 */
|
||||
productCost: number;
|
||||
/** 运费成本 */
|
||||
|
||||
@@ -17,6 +17,8 @@ export namespace ProductSkuVO {
|
||||
name: string;
|
||||
/** SKU 编码 */
|
||||
skuCode?: string;
|
||||
/** 单件实重(克);空=未填 */
|
||||
weightG?: number | null;
|
||||
/** 规格组合键;空=未结构化 */
|
||||
specCombinationKey?: string;
|
||||
/** 已绑规格值 */
|
||||
|
||||
@@ -58,6 +58,8 @@ export namespace ProductDTO {
|
||||
name: string;
|
||||
/** SKU 编码 */
|
||||
skuCode?: string;
|
||||
/** 单件实重(克);空=未填;界面按 kg 录入后换算 */
|
||||
weightG?: number | null;
|
||||
/** 商品成本 */
|
||||
productCost: number;
|
||||
/** 运费成本 */
|
||||
@@ -78,6 +80,8 @@ export namespace ProductDTO {
|
||||
name: string;
|
||||
/** SKU 编码 */
|
||||
skuCode?: string;
|
||||
/** 单件实重(克);空=未填 */
|
||||
weightG?: number | null;
|
||||
/** 商品成本 */
|
||||
productCost: number;
|
||||
/** 运费成本 */
|
||||
@@ -98,6 +102,8 @@ export namespace ProductDTO {
|
||||
name: string;
|
||||
/** SKU 编码 */
|
||||
skuCode?: string;
|
||||
/** 单件实重(克);空=未填 */
|
||||
weightG?: number | null;
|
||||
/** 商品成本 */
|
||||
productCost: number;
|
||||
/** 运费成本 */
|
||||
|
||||
@@ -82,6 +82,8 @@ export namespace ProductVO {
|
||||
name: string;
|
||||
/** SKU 编码 */
|
||||
skuCode?: string;
|
||||
/** 单件实重(克);空=未填 */
|
||||
weightG?: number | null;
|
||||
/** 规格组合键;空=未结构化 */
|
||||
specCombinationKey?: string;
|
||||
/** 已绑规格值 */
|
||||
|
||||
@@ -64,6 +64,17 @@ const skuColumns = [
|
||||
key: 'name',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '重量',
|
||||
dataIndex: 'weightG',
|
||||
key: 'weightG',
|
||||
width: 90,
|
||||
customRender: ({ record }: { record: ProductVO.SkuInfo }) => {
|
||||
if (record.weightG == null) return '-';
|
||||
const kg = Number(record.weightG) / 1000;
|
||||
return `${kg.toFixed(3)} kg`;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '商品成本',
|
||||
dataIndex: 'productCost',
|
||||
|
||||
@@ -207,6 +207,8 @@ type SkuFormRow = ProductDTO.Sku & {
|
||||
_clientKey?: string;
|
||||
id?: number;
|
||||
costEffectiveFrom?: string;
|
||||
/** 界面录入用 kg;提交时换算为 weightG */
|
||||
weightKg?: number | null;
|
||||
/** 规格组合键;空=未结构化 */
|
||||
specCombinationKey?: string;
|
||||
/** 已绑规格值 */
|
||||
@@ -223,8 +225,22 @@ function isPersistedSkuId(id?: number) {
|
||||
return id != null && id > 0;
|
||||
}
|
||||
|
||||
/** 库内克 → 界面千克 */
|
||||
function gramsToKg(weightG?: number | null): number | null {
|
||||
if (weightG == null || Number.isNaN(Number(weightG))) return null;
|
||||
return Number(weightG) / 1000;
|
||||
}
|
||||
|
||||
/** 界面千克 → 库内克(四舍五入到整数克) */
|
||||
function kgToGrams(weightKg?: number | null): number | null {
|
||||
if (weightKg == null || Number.isNaN(Number(weightKg))) return null;
|
||||
const g = Math.round(Number(weightKg) * 1000);
|
||||
return g > 0 ? g : null;
|
||||
}
|
||||
|
||||
function mapSkuFields(spec: ProductVO.SkuInfo): ProductDTO.Sku & {
|
||||
costEffectiveFrom?: string;
|
||||
weightKg?: number | null;
|
||||
imageUrl?: string;
|
||||
specCombinationKey?: string;
|
||||
specValues?: ProductVO.SkuInfo['specValues'];
|
||||
@@ -232,6 +248,8 @@ function mapSkuFields(spec: ProductVO.SkuInfo): ProductDTO.Sku & {
|
||||
return {
|
||||
name: spec.name || spec.skuCode || '',
|
||||
skuCode: spec.skuCode || '',
|
||||
weightG: spec.weightG ?? null,
|
||||
weightKg: gramsToKg(spec.weightG),
|
||||
productCost: spec.productCost ?? 0,
|
||||
shippingCost: spec.shippingCost ?? 0,
|
||||
otherCost: spec.otherCost ?? 0,
|
||||
@@ -403,16 +421,11 @@ async function handleSubmit() {
|
||||
mainImageId: submitData.mainImageId,
|
||||
specs: specsPayload,
|
||||
...(skus.value.length > 0 && {
|
||||
skus: skus.value.map(
|
||||
({
|
||||
_clientKey: _c,
|
||||
_previewUrl: _p,
|
||||
newImageFile: _f,
|
||||
imageUrl: _u,
|
||||
id: _id,
|
||||
...rest
|
||||
}) => rest,
|
||||
),
|
||||
skus: skus.value.map((row) => {
|
||||
const payload = toSkuUpdatePayload(row);
|
||||
const { id: _id, ...createSku } = payload;
|
||||
return createSku;
|
||||
}),
|
||||
}),
|
||||
};
|
||||
const createResult = await createProductApi(createData);
|
||||
@@ -535,6 +548,8 @@ const defaultSku = (): SkuFormRow => ({
|
||||
id: 0,
|
||||
name: '',
|
||||
skuCode: '',
|
||||
weightG: null,
|
||||
weightKg: null,
|
||||
productCost: 0,
|
||||
shippingCost: 0,
|
||||
otherCost: 0,
|
||||
@@ -607,6 +622,7 @@ function toSkuUpdatePayload(row: SkuFormRow): ProductDTO.UpdateSku {
|
||||
id: isPersistedSkuId(row.id) ? Number(row.id) : 0,
|
||||
name: row.name,
|
||||
skuCode: row.skuCode ?? '',
|
||||
weightG: kgToGrams(row.weightKg),
|
||||
productCost: row.productCost ?? 0,
|
||||
shippingCost: row.shippingCost ?? 0,
|
||||
otherCost: row.otherCost ?? 0,
|
||||
@@ -887,6 +903,27 @@ const skuColumns = [
|
||||
record: SkuFormRow;
|
||||
}) => renderSkuTextInput(record, 'skuCode', '请输入SKU 编码', '与同品 SKU 编码重复'),
|
||||
},
|
||||
{
|
||||
title: '重量(kg)',
|
||||
dataIndex: 'weightKg',
|
||||
key: 'weightKg',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: SkuFormRow }) =>
|
||||
h(InputNumber, {
|
||||
value: record.weightKg ?? undefined,
|
||||
placeholder: 'kg',
|
||||
min: 0.001,
|
||||
max: 500,
|
||||
step: 0.001,
|
||||
precision: 3,
|
||||
style: { width: '100%' },
|
||||
'onUpdate:value': (value: null | number) => {
|
||||
record.weightKg = value;
|
||||
record.weightG = kgToGrams(value);
|
||||
touchSkuRows();
|
||||
},
|
||||
} as any),
|
||||
},
|
||||
{
|
||||
title: '规格',
|
||||
key: 'specValues',
|
||||
@@ -1012,6 +1049,7 @@ function openBindSpec(record: SkuFormRow) {
|
||||
productName: formData.value.name || '',
|
||||
name: record.name,
|
||||
skuCode: record.skuCode,
|
||||
weightG: kgToGrams(record.weightKg) ?? record.weightG ?? null,
|
||||
productCost: record.productCost ?? 0,
|
||||
shippingCost: record.shippingCost,
|
||||
otherCost: record.otherCost,
|
||||
|
||||
Reference in New Issue
Block a user