export type SkuItem = {
|
id: string;
|
name: string;
|
list: {
|
active: boolean;
|
disable: boolean;
|
id: string;
|
name: string;
|
}[];
|
};
|
|
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;
|
}
|
}
|