zhengyiming
昨天 1d472eb06970c85b0edfb58871956bc2c8d69916
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export type SkuItem = {
  id: string;
  name: string;
  list: {
    active: boolean;
    disable: boolean;
    id: string;
    name: string;
    price: number;
  }[];
};
 
export type Goods = {
  imagePath: string;
  price: string;
  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;
  }
}