@yorkjs/hive-biz 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,16 @@
1
1
  import { ICartListItem, IProductSelectedCustomizationItem } from './type';
2
2
  import { ICountChangeResult, IAddToCartParamsResult, ICustomSpecSelectorView, ICustomSpecSelectorOptions, IFetchCustomCartCountParams, IFetchCartCountResult, IFetchMemberPriceParams } from './type';
3
+ /**
4
+ * 做法加料商品规格选择器
5
+ *
6
+ * 设计原则:类内部不发起任何接口请求,所有数据处理逻辑封装在此,
7
+ * 网络请求由 UI 层发起,将结果通过公开方法回填。
8
+ *
9
+ * 与 ComboSpecSelector 的差异:
10
+ * - productData 已包含做法数据,初始化时无需额外接口
11
+ * - 支持活动 sku(promotionActivityProduct)
12
+ * - 购物车参数含 product_customization_item_list
13
+ */
3
14
  export declare class CustomSpecSelector {
4
15
  private product;
5
16
  private promotionActivityProduct;
@@ -29,33 +40,81 @@ export declare class CustomSpecSelector {
29
40
  private negativeStockSaleEnabled?;
30
41
  private onChange;
31
42
  constructor(options: ICustomSpecSelectorOptions);
43
+ /**
44
+ * 设置购物车列表,当购物车数据变化时调用
45
+ * 会根据当前选中的规格和做法重新匹配购物车数据
46
+ */
32
47
  setCartList(cartList: ICartListItem[]): void;
48
+ /**
49
+ * 初始化(做法加料商品无需额外接口请求,productData 已包含全部数据)
50
+ * 调用后触发 onChange,UI 可通过 getView() 拿到渲染数据;
51
+ * 但购物车数据需 UI 层调用 buildCartCountParams() 拿参数后自行请求。
52
+ */
33
53
  init(): void;
34
54
  getView(): ICustomSpecSelectorView;
55
+ /**
56
+ * 选择规格(纯数据处理)
57
+ * @returns needFetchCart 是否需要刷新购物车数(为 true 时同样需要重新请求会员价);cartParams 购物车查询参数
58
+ */
35
59
  handleSelectSpecs(isOption: boolean, value: string, index: number): {
36
60
  needFetchCart: boolean;
37
61
  cartParams: IFetchCustomCartCountParams;
38
62
  };
63
+ /**
64
+ * 用购物车查询结果更新内部状态
65
+ */
39
66
  updateCartCountData(result: IFetchCartCountResult): void;
67
+ /**
68
+ * 用会员价查询结果更新内部状态,由 UI 层请求会员价接口后调用
69
+ * @param price 会员价,请求失败或无会员价时传 undefined
70
+ */
40
71
  updateMemberPrice(price: number | undefined): void;
72
+ /**
73
+ * 做法选中变化(纯数据处理)
74
+ * @returns isValid 校验是否通过;cartParams 若通过则返回购物车查询参数
75
+ */
41
76
  handleCustomizationItemListSelect(customizationItemList: IProductSelectedCustomizationItem[][]): {
42
77
  isValid: boolean;
43
78
  cartParams?: IFetchCustomCartCountParams;
44
79
  };
80
+ /**
81
+ * 数量变化(纯逻辑,返回操作结果供 UI 决策)
82
+ */
45
83
  handleProductCountChange(count: number, type: string): ICountChangeResult;
84
+ /**
85
+ * 加入购物车前校验,返回提交所需参数
86
+ * 由 UI 层使用参数调用 addToCart 接口
87
+ */
46
88
  getAddToCartParams(productId: number, promotionActivityProductId?: number): IAddToCartParamsResult;
47
89
  getSalePrice(): number;
48
90
  getOriginalPrice(): number;
49
91
  getMemberPrice(): number | undefined;
50
92
  getSelectedSpecAndCustomization(): string;
51
93
  buildCartCountParams(): IFetchCustomCartCountParams;
94
+ /**
95
+ * 构造会员价查询参数(供 UI 层使用)
96
+ * sku 未选中时返回 undefined
97
+ */
52
98
  buildMemberPriceParams(): IFetchMemberPriceParams | undefined;
53
99
  private _initProductData;
54
100
  private _updateSkuData;
55
101
  private _checkProductCount;
56
102
  private _selectSpec;
57
103
  private _notifyChange;
104
+ /**
105
+ * 获取当前 sku 类型,活动 sku 返回活动类型,否则返回商城类型
106
+ */
58
107
  private _getSkuType;
108
+ /**
109
+ * 从购物车列表中查找匹配的购物车项
110
+ * 匹配逻辑:
111
+ * 1. 判断购物车商品是否是当前商品(优先使用活动商品 id 比较)
112
+ * 2. 判断 sku_id 是否一样(优先使用活动 sku_id)
113
+ * 3. 比较做法值列表是否相等(数组长度一致,且 id 和 count 一致)
114
+ */
59
115
  private _findSkuCartItem;
116
+ /**
117
+ * 更新当前 sku 对应的购物车数据
118
+ */
60
119
  private _updateSkuCartItem;
61
120
  }
@@ -1,17 +1,26 @@
1
1
  import { ISpecList, ISkuCombination, IProductSpecItem } from './type';
2
2
  export interface ISpecSelectorOptions {
3
+ /** 规格组列表,包含每组规格标题和可选值 */
3
4
  productSpecGroupList: ISpecList[];
5
+ /** 格式化后的 sku 组合列表 */
4
6
  skuListAfter: ISkuCombination[];
7
+ /** 活动规格列表,二维数组,与 productSpecGroupList 下标对应 */
5
8
  activitySpecList?: IProductSpecItem[][];
6
9
  }
7
10
  export interface ISpecItemState {
11
+ /** 规格值 */
8
12
  value: string;
13
+ /** 是否可选(未被禁用) */
9
14
  isEnabled: boolean;
15
+ /** 是否已选中 */
10
16
  isActive: boolean;
17
+ /** 是否是活动规格 */
11
18
  isActivitySpec: boolean;
12
19
  }
13
20
  export interface ISpecGroupState {
21
+ /** 规格组标题 */
14
22
  title: string;
23
+ /** 该组下所有规格项的状态 */
15
24
  items: ISpecItemState[];
16
25
  }
17
26
  export declare class SpecSelector {
@@ -20,10 +29,38 @@ export declare class SpecSelector {
20
29
  private activitySpecList;
21
30
  private specAdjoinMatrix;
22
31
  constructor(options: ISpecSelectorOptions);
32
+ /**
33
+ * 判断某个规格值是否是活动规格
34
+ * @param listIndex 规格组下标
35
+ * @param value 规格值
36
+ */
23
37
  isActivitySpec(listIndex: number, value: string): boolean;
38
+ /**
39
+ * 根据当前已选规格,获取所有规格组的渲染状态
40
+ * @param selectedSpecs 当前已选规格值数组
41
+ */
24
42
  getSpecGroupStateList(selectedSpecs: string[]): ISpecGroupState[];
43
+ /**
44
+ * 根据当前已选规格,获取可选规格值列表(扁平数组)
45
+ * @param selectedSpecs 当前已选规格值数组
46
+ */
25
47
  getOptionSpecs(selectedSpecs: string[]): string[];
48
+ /**
49
+ * 处理规格选择/取消选择,返回新的已选规格数组
50
+ * @param isEnabled 当前规格是否可选
51
+ * @param value 被点击的规格值
52
+ * @param groupIndex 规格组下标
53
+ * @param selectedSpecs 当前已选规格值数组
54
+ */
26
55
  toggleSpec(isEnabled: boolean, value: string, groupIndex: number, selectedSpecs: string[]): string[];
56
+ /**
57
+ * 根据当前已选规格找到匹配的 sku 组合
58
+ * @param selectedSpecs 当前已选规格值数组
59
+ */
27
60
  findMatchedSku(selectedSpecs: string[]): ISkuCombination | undefined;
61
+ /**
62
+ * 判断规格是否已全部选完
63
+ * @param selectedSpecs 当前已选规格值数组
64
+ */
28
65
  isAllSpecSelected(selectedSpecs: string[]): boolean;
29
66
  }
@@ -257,17 +257,26 @@ export interface IProductSpecGroup {
257
257
  has_image: number;
258
258
  items: IProductSpecItem[];
259
259
  }
260
+ /**
261
+ * 做法值基础接口定义
262
+ */
260
263
  export interface ICustomizationItemBase {
261
264
  id: number;
262
265
  name: string;
263
266
  increase_type: number;
264
267
  increase_sale_price: number;
265
268
  }
269
+ /**
270
+ * 做法值接口定义
271
+ */
266
272
  export interface ICustomizationBase {
267
273
  id: number;
268
274
  name: string;
269
275
  count_type: number;
270
276
  }
277
+ /**
278
+ * 做法项接口定义 - 做法设置页面
279
+ */
271
280
  export interface ICustomizationItem {
272
281
  id: number;
273
282
  customization_item: ICustomizationItemBase;
@@ -278,6 +287,9 @@ export interface ICustomizationItem {
278
287
  min_count: number;
279
288
  max_count: number;
280
289
  }
290
+ /**
291
+ * 做法组接口定义 - 做法设置页面
292
+ */
281
293
  export interface IProductCustomizationGroupItem {
282
294
  id: number;
283
295
  customization: ICustomizationBase;
@@ -340,17 +352,21 @@ export interface IAddCartParams {
340
352
  productCustomizationItemList?: ISubmitSelectedCustomizationItem[];
341
353
  skuComboItemList?: ISelectSkuComboItem[][];
342
354
  }
355
+ /** 数量变化操作结果 */
343
356
  export interface ICountChangeResult {
344
357
  isValid: boolean;
345
358
  errMsg?: string;
359
+ /** 需要修改购物车时,由 UI 层调用 changeCartCount 接口传入 */
346
360
  cartItem?: ICartListItem;
347
361
  count?: number;
348
362
  }
363
+ /** 加入购物车前校验结果 */
349
364
  export interface IAddToCartParamsResult {
350
365
  isValid: boolean;
351
366
  errMsg?: string;
352
367
  params?: IAddCartParams;
353
368
  }
369
+ /** 套餐商品 Selector 初始化选项 */
354
370
  export interface IComboSpecSelectorOptions {
355
371
  productData: {
356
372
  product: IProduct;
@@ -364,6 +380,7 @@ export interface IComboSpecSelectorOptions {
364
380
  onChange: SelectorChangeCallback;
365
381
  validateComboGroupList: () => string;
366
382
  }
383
+ /** 做法加料商品 Selector 初始化选项 */
367
384
  export interface ICustomSpecSelectorOptions {
368
385
  productData: {
369
386
  product: IProduct;
@@ -378,6 +395,7 @@ export interface ICustomSpecSelectorOptions {
378
395
  channel1Type: number;
379
396
  onChange: SelectorChangeCallback;
380
397
  }
398
+ /** 套餐商品 UI 渲染数据 */
381
399
  export interface IComboSpecSelectorView {
382
400
  product: IProduct;
383
401
  skuId: number;
@@ -393,8 +411,10 @@ export interface IComboSpecSelectorView {
393
411
  maxCount: number;
394
412
  isComponentLoading: boolean;
395
413
  visibleComboInfo: boolean;
414
+ /** 会员价,sku 变化后重置为 undefined,需 UI 层重新请求回填 */
396
415
  memberPrice: number | undefined;
397
416
  }
417
+ /** 做法加料商品 UI 渲染数据 */
398
418
  export interface ICustomSpecSelectorView {
399
419
  product: IProduct;
400
420
  promotionActivityProduct: IPromotionActivityProduct | undefined;
@@ -412,9 +432,11 @@ export interface ICustomSpecSelectorView {
412
432
  cartCount: number;
413
433
  maxCount: number;
414
434
  cartItem: ICartListItem | undefined;
435
+ /** 会员价,sku 变化后重置为 undefined,需 UI 层重新请求回填 */
415
436
  memberPrice: number | undefined;
416
437
  }
417
438
  export type SelectorChangeCallback = () => void;
439
+ /** 套餐商品购物车查询参数 */
418
440
  export interface IFetchCartCountParams {
419
441
  channel1_type: number;
420
442
  checked: number;
@@ -423,6 +445,7 @@ export interface IFetchCartCountParams {
423
445
  sku_combo_item_list: string;
424
446
  cart: number;
425
447
  }
448
+ /** 做法加料商品购物车查询参数 */
426
449
  export interface IFetchCustomCartCountParams {
427
450
  channel1_type: number;
428
451
  checked: number;
@@ -431,6 +454,7 @@ export interface IFetchCustomCartCountParams {
431
454
  product_customization_item_list: string;
432
455
  cart: number;
433
456
  }
457
+ /** 购物车查询返回结果 */
434
458
  export interface IFetchCartCountResult {
435
459
  cart?: {
436
460
  id: number;
@@ -439,6 +463,7 @@ export interface IFetchCartCountResult {
439
463
  };
440
464
  [key: string]: any;
441
465
  }
466
+ /** 会员价查询参数 */
442
467
  export interface IFetchMemberPriceParams {
443
468
  sku_id: number;
444
469
  sku_type: number;
@@ -3,6 +3,9 @@ export default class SpecAdjoinMatrix extends AdjoinMatrix {
3
3
  specList: never[];
4
4
  specCombinationList: never[];
5
5
  constructor(specList: any, specCombinationList: any);
6
+ /**
7
+ * 根据可选规格组合填写邻接矩阵的值
8
+ */
6
9
  initSpec(): void;
7
10
  initSameLevel(): void;
8
11
  getSpecsOptions(params: any): string[];