zhengyiming
2 天以前 1d472eb06970c85b0edfb58871956bc2c8d69916
packages/components/src/Sku/sku.ts
@@ -6,6 +6,7 @@
    disable: boolean;
    id: string;
    name: string;
    price: number;
  }[];
};
@@ -15,3 +16,25 @@
  skuId: string;
  name: string;
};
export class SkuUtils {
  static DefaultSkuSpecId = 'spec';
  static getCurrentSku(skuList: SkuItem[], goods: Goods) {
    const sku = skuList.find((item) => item.id === goods.skuId);
    return sku;
  }
  static getCurrentSpecSkuItem(skuList: SkuItem[]) {
    const sku = skuList.find((item) => item.id === this.DefaultSkuSpecId);
    return sku;
  }
  static getCurrentActiveSpec(skuList: SkuItem[]) {
    const sku = this.getCurrentSpecSkuItem(skuList);
    if (sku) {
      return sku.list.find((item) => item.active);
    }
    return null;
  }
}