wupengfei
3 天以前 45fc1e0bffad810357bd050b6df31fa6ef82aa41
packages/components/src/Sku/sku.ts
@@ -6,12 +6,35 @@
    disable: boolean;
    id: string;
    name: string;
    price: number;
  }[];
};
export type Goods = {
  imagePath: string;
  price: string;
  price: number;
  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;
  }
}