@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorkjs/hive-biz",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "util function",
5
5
  "main": "dist/hive-biz.esm.js",
6
6
  "module": "dist/hive-biz.esm.js",
@@ -1,12 +1,28 @@
1
1
  export interface IFormatAvailableRepeatOptions {
2
+ /** 重复类型:0 每天 / 1 每周 / 2 每月 */
2
3
  repeatType?: number;
4
+ /** 周几或每月几号;周:0-6,月:1-28。也可传接口 JSON 字符串 */
3
5
  repeatValue?: Array<number | string> | string;
6
+ /** 日内时段,一维 [start, end, ...],单位分钟 */
4
7
  minuteSegments?: Array<number | string> | string;
5
8
  }
9
+ /** 00:00-24:00 或 00:00-23:59 都视为全天 */
6
10
  export declare function isFullDayMinuteSegment(start: number, end: number): boolean;
11
+ /**
12
+ * 接口里的周几 / 日期 / 时段可能是 number[] 或 JSON 字符串。
13
+ * formatItem 原样搬运即可,这里统一收成 number[]。
14
+ */
7
15
  export declare function parseCouponNumberList(value?: Array<number | string> | string): number[];
16
+ /** 仅日期部分,不含时段。按天且未选具体日时返回空,由调用方补「每天」 */
8
17
  export declare function formatAvailableRepeatDateText(options?: IFormatAvailableRepeatOptions): string;
18
+ /**
19
+ * 日期 + 时段拼成一句,次卡列表等场景用。
20
+ * 例:工作日08:00-11:00;都空时「全天」
21
+ */
9
22
  export declare function formatAvailableRepeatText(options?: IFormatAvailableRepeatOptions): string;
23
+ /**
24
+ * 使用次数限制。例:每日2次、每周3次、每月5次;都没有则「不限制」
25
+ */
10
26
  export declare function formatUseLimitText(options?: {
11
27
  daily?: number | string;
12
28
  weekly?: number | string;
@@ -1,25 +1,62 @@
1
+ /** 折扣券。对齐 coupon_type = 1,走折扣票面 */
1
2
  export declare const COUPON_TYPE_DISCOUNT = 1;
3
+ /** 满减券。对齐 coupon_type = 2,走金额票面 */
2
4
  export declare const COUPON_TYPE_AMOUNT = 2;
5
+ /** 配送券。对齐 coupon_type = 3,走金额票面 */
3
6
  export declare const COUPON_TYPE_FREIGHT = 3;
7
+ /** 使用门槛:按金额。对齐 threshold_type */
4
8
  export declare const COUPON_THRESHOLD_TYPE_AMOUNT = 1;
9
+ /** 使用门槛:按件数。对齐 threshold_type */
5
10
  export declare const COUPON_THRESHOLD_TYPE_COUNT = 2;
6
- export declare const COUPON_EXPIRE_START_TYPE_NOW = 1;
7
- export declare const COUPON_EXPIRE_START_TYPE_FUTURE = 2;
8
- export declare const COUPON_EXPIRE_END_TYPE_FOREVER = 1;
9
- export declare const COUPON_EXPIRE_END_TYPE_FUTURE = 2;
10
- export declare const COUPON_EXPIRE_END_TYPE_EXTEND = 3;
11
+ /** 生效开始:立即。对齐 effective_start_type */
12
+ export declare const COUPON_EFFECTIVE_START_TYPE_NOW = 1;
13
+ /** 生效开始:指定时间。对齐 effective_start_type */
14
+ export declare const COUPON_EFFECTIVE_START_TYPE_FUTURE = 2;
15
+ /** 生效结束:永久。对齐 effective_end_type */
16
+ export declare const COUPON_EFFECTIVE_END_TYPE_FOREVER = 1;
17
+ /** 生效结束:指定时间。对齐 effective_end_type */
18
+ export declare const COUPON_EFFECTIVE_END_TYPE_FUTURE = 2;
19
+ /** 生效结束:领取后延长 N 天。对齐 effective_end_type */
20
+ export declare const COUPON_EFFECTIVE_END_TYPE_EXTEND = 3;
21
+ /** 可用日期:按天(每天)。对齐 available_repeat_type */
11
22
  export declare const COUPON_AVAILABLE_REPEAT_TYPE_DAILY = 0;
23
+ /** 可用日期:按周。对齐 available_repeat_type */
12
24
  export declare const COUPON_AVAILABLE_REPEAT_TYPE_WEEKLY = 1;
25
+ /** 可用日期:按月。对齐 available_repeat_type */
13
26
  export declare const COUPON_AVAILABLE_REPEAT_TYPE_MONTHLY = 2;
27
+ /** 券实例状态:待生效。对齐 coupon.status */
14
28
  export declare const COUPON_STATUS_PENDING = 1;
29
+ /** 券实例状态:已生效。对齐 coupon.status */
15
30
  export declare const COUPON_STATUS_ENABLED = 2;
31
+ /** 券实例状态:已使用。对齐 coupon.status */
16
32
  export declare const COUPON_STATUS_USED = 3;
33
+ /** 券实例状态:已过期。对齐 coupon.status */
17
34
  export declare const COUPON_STATUS_EXPIRED = 4;
35
+ /** 券实例状态:已注销。对齐 coupon.status */
18
36
  export declare const COUPON_STATUS_CANCELED = 5;
37
+ /** 券实例状态:已锁定。对齐 coupon.status */
19
38
  export declare const COUPON_STATUS_LOCKED = 6;
39
+ /** 券模板状态:草稿。对齐 coupon_template.status */
40
+ export declare const COUPON_TEMPLATE_STATUS_DRAFT = 1;
41
+ /** 券模板状态:已上线。对齐 coupon_template.status */
42
+ export declare const COUPON_TEMPLATE_STATUS_ONLINE = 2;
43
+ /** 券模板状态:已下线。对齐 coupon_template.status */
44
+ export declare const COUPON_TEMPLATE_STATUS_OFFLINE = 3;
45
+ /** 券模板状态:已过期。对齐 coupon_template.status */
46
+ export declare const COUPON_TEMPLATE_STATUS_EXPIRED = 4;
47
+ /** 接口没给 available_error 时,按已知状态补不可用原因 */
48
+ export declare const COUPON_TEMPLATE_STATUS_UNAVAILABLE_ERROR: Record<number, string>;
49
+ /** 券实例独有状态:已注销 / 已锁定。数字不与模板冲突 */
50
+ export declare const COUPON_STATUS_UNAVAILABLE_ERROR: Record<number, string>;
51
+ /** 可用券展开:使用规则等额外信息 */
20
52
  export declare const COUPON_EXPAND_TYPE_EXTRA = "extra";
53
+ /** 不可用券展开:本单不可用原因 */
21
54
  export declare const COUPON_EXPAND_TYPE_REASON = "reason";
55
+ /** 没有可展开内容 */
22
56
  export declare const COUPON_EXPAND_TYPE_NONE = "none";
57
+ /** confirm 未选券时的默认提示 */
23
58
  export declare const COUPON_CONFIRM_EMPTY_MSG = "\u8BF7\u9009\u62E9\u4F18\u60E0\u5238";
24
- export declare const COUPON_EXPIRE_DISPLAY_DEADLINE = "deadline";
25
- export declare const COUPON_EXPIRE_DISPLAY_VALIDITY = "validity";
59
+ /** 实例票面:过期时间展示具体截止日期 */
60
+ export declare const COUPON_EXPIRE_MODE_DEADLINE = "deadline";
61
+ /** 模板票面:有效期,按次卡同一套开始/结束类型拼文案 */
62
+ export declare const COUPON_EXPIRE_MODE_VALIDITY = "validity";
@@ -1,21 +1,47 @@
1
1
  import { ICouponConfirmResult, ICouponSelectorOptions, ICouponSelectorView } from './type';
2
+ /**
3
+ * 优惠券选择器(无 UI、不发请求)。
4
+ *
5
+ * 列表来源由调用方决定:静态 list 或接口拉完后 setList / appendList。
6
+ * formatItem 只把后端字段收到 ICoupon(数字 / 枚举即可);
7
+ * 门槛、过期、可用日期/时间、使用限制由 couponUtil 格式化,getView 产出 contentLines / expandLines。
8
+ */
2
9
  export declare class CouponSelector {
3
10
  private list;
4
11
  private selectedId?;
12
+ /**
13
+ * 调用方传入的回显 id。
14
+ * 接口列表异步到达前不要丢掉;分页补齐后继续用它匹配。
15
+ */
16
+ private preferredSelectedId?;
5
17
  private expandedIds;
6
18
  private formatItem?;
7
- private expandOne;
8
- private expireDisplay?;
19
+ private exclusiveExpand;
20
+ private expireMode?;
9
21
  private onChange;
10
22
  constructor(options: ICouponSelectorOptions);
23
+ /** 全量替换列表,并清掉已不存在的选中 / 展开 */
11
24
  setList(list: any[]): void;
25
+ /** 分页追加。追加后仍按可用在前重排 */
12
26
  appendList(list: any[]): void;
27
+ /** 当前列表票面快照,给 CouponCard 渲染 */
13
28
  getView(): ICouponSelectorView;
29
+ /**
30
+ * 点票面。
31
+ * 可用:选中,再点取消;不可用:不选中,只展开原因。
32
+ */
14
33
  select(id: string | number): void;
34
+ /** 点箭头,只切换展开,不改变选中 */
15
35
  toggleExpand(id: string | number): void;
36
+ /** 确认选中。未选可用券时 isValid 为 false */
16
37
  confirm(): ICouponConfirmResult;
17
38
  private _toViewItem;
18
39
  private _findCoupon;
40
+ /** 0 / 空字符串视为未选 */
41
+ private _normalizeSelectedId;
42
+ /** 列表尚未包含该券时先留着 preferred,等 setList / appendList 再匹配 */
43
+ private _syncSelectedId;
44
+ /** 回显只认当前列表里的可用券 */
19
45
  private _pickValidSelectedId;
20
46
  private _isExpanded;
21
47
  private _setExpanded;
@@ -1,34 +1,89 @@
1
- import { CouponExpandType, CouponExpireDisplay, CouponFormatItem, ICoupon, ICouponKvLine, ICouponViewItem } from './type';
1
+ import { CouponExpandType, CouponExpireMode, CouponFormatItem, ICoupon, ICouponKvLine, ICouponViewItem } from './type';
2
+ /** id 统一转字符串再比,避免 number / string 回显对不上 */
2
3
  export declare function isSameCouponId(a?: string | number, b?: string | number): boolean;
3
- export declare function isCouponStatusExpired(status?: number): boolean;
4
- export declare function resolveCouponAvailable(coupon: Pick<ICoupon, 'status' | 'available'>): boolean;
4
+ /**
5
+ * 可用态。
6
+ * 1. availableError 有值:一定不可用
7
+ * 2. 带了 status 则只有 2(已上线 / 已生效)可用
8
+ * 3. 没带 status:没有 availableError 则可用(兼容列表只筛 status、项上不回传该字段)
9
+ */
10
+ export declare function resolveCouponAvailable(coupon: Pick<ICoupon, 'availableError' | 'status'>): boolean;
11
+ /**
12
+ * 展开用的不可用原因。
13
+ * 接口 availableError 优先;没有时按已知状态补文案(草稿/下线/过期/注销/锁定),其它灰态不展开。
14
+ */
15
+ export declare function resolveCouponAvailableError(coupon: Pick<ICoupon, 'availableError' | 'status'>): string;
16
+ /**
17
+ * 原始列表 → 标准 ICoupon。
18
+ * 有 formatItem 就逐项转换(返回空则跳过);没有则把项当作已是 ICoupon。
19
+ * 未带 original 时自动挂上原始 item。可用券排在不可用前面,组内保持原相对顺序。
20
+ */
5
21
  export declare function formatCouponList(rawList?: any[], formatItem?: CouponFormatItem): ICoupon[];
22
+ /**
23
+ * 是否走折扣票面(折)。
24
+ * couponType === 1 为折扣;2/3 为金额。
25
+ */
6
26
  export declare function isCouponDiscountBenefit(coupon: ICoupon): boolean;
27
+ /** 票面数字。满减走 formatAmount;折扣走 formatDiscount,只返回数字部分 */
7
28
  export declare function formatCouponAmountValue(coupon: ICoupon): string;
29
+ /** 票面左侧前缀。满减 / 配送为 ¥,折扣为空 */
8
30
  export declare function formatCouponAmountPrefix(coupon: ICoupon): string;
31
+ /** 票面右侧单位。折扣为「折」,满减 / 配送为空 */
9
32
  export declare function formatCouponAmountSuffix(coupon: ICoupon): string;
33
+ /**
34
+ * 门槛展示值(不含「使用门槛:」)。
35
+ * 由 thresholdType + thresholdValue 生成;0 为无门槛。
36
+ */
10
37
  export declare function formatCouponThreshold(coupon: ICoupon): string;
38
+ /**
39
+ * 过期时间展示值(不含「过期时间:」)。
40
+ * 给已发出的券实例用,只展示截止日期年月日时分,或永久有效。
41
+ */
11
42
  export declare function formatCouponExpireText(coupon: ICoupon): string;
43
+ /**
44
+ * 有效期展示值(不含「有效期:」)。
45
+ * 给发券选模板用,字段和次卡同一套开始/结束类型,不把「领取后 N 天」折成当前时间。
46
+ */
12
47
  export declare function formatCouponValidityText(coupon: ICoupon): string;
48
+ /** 可用日期。按天未选具体日时为「每天」 */
13
49
  export declare function formatCouponAvailableDateText(coupon: ICoupon): string;
50
+ /** 可用时段。空或全天时段走 hive formatMinuteSegments,空数组为「全天」 */
14
51
  export declare function formatCouponAvailableTimeText(coupon: ICoupon): string;
52
+ /** 使用限制展示值(不含「使用限制:」)。无限制时为「不限制」 */
15
53
  export declare function formatCouponUseLimitText(coupon: ICoupon): string;
54
+ /** 把键值行拼成「键:值」;label 为空时只返回 value */
16
55
  export declare function formatCouponKvText(line: ICouponKvLine): string;
17
- export declare function getCouponContentLines(coupon: ICoupon, expireDisplay?: CouponExpireDisplay): ICouponKvLine[];
56
+ /** 票面信息区:使用门槛、过期时间 / 有效期 */
57
+ export declare function getCouponContentLines(coupon: ICoupon, expireMode?: CouponExpireMode): ICouponKvLine[];
58
+ /** 是否带了可用日期 / 时段,用来决定要不要生成展开行 */
18
59
  export declare function hasCouponAvailableRepeat(coupon: ICoupon): boolean;
60
+ /** 是否带了使用限制字段(含 0,表示明确「不限制」也要展示) */
19
61
  export declare function hasCouponUseLimit(coupon: ICoupon): boolean;
62
+ /** 把「键:值」拆回键值行;没有分隔符则整句当 value */
20
63
  export declare function parseCouponKvLine(text: string): ICouponKvLine;
64
+ /** 展开区键值行。extra 走 extraLines 或生成规则,reason 为本单不可用原因 */
21
65
  export declare function getCouponExpandKvLines(coupon: ICoupon): ICouponKvLine[];
66
+ /** 当前券应展示的展开类型:extra / reason / none */
22
67
  export declare function getCouponExpandType(coupon: ICoupon): CouponExpandType;
68
+ /** 展开区展示文案。reason 只出原因正文,extra 为「键:值」 */
23
69
  export declare function getCouponExpandLines(coupon: ICoupon): string[];
70
+ /**
71
+ * ICoupon → 票面数据。选券弹层和单独挂 CouponCard 共用。
72
+ * selected / expanded 由调用方控制,available 由 availableError + status 推出。
73
+ */
24
74
  export declare function formatCouponViewItem(coupon: ICoupon, state?: {
25
75
  selected?: boolean;
26
76
  expanded?: boolean;
27
- expireDisplay?: CouponExpireDisplay;
77
+ expireMode?: CouponExpireMode;
28
78
  }): ICouponViewItem;
79
+ /**
80
+ * 原始项或 ICoupon → 票面。
81
+ * 有 formatItem 时先映射;没有则把 source 当 ICoupon。
82
+ * formatItem 跳过该项时返回 undefined。
83
+ */
29
84
  export declare function toCouponViewItem(source: any, state?: {
30
85
  selected?: boolean;
31
86
  expanded?: boolean;
32
87
  formatItem?: CouponFormatItem;
33
- expireDisplay?: CouponExpireDisplay;
88
+ expireMode?: CouponExpireMode;
34
89
  }): ICouponViewItem | undefined;
@@ -1,69 +1,182 @@
1
1
  import { COUPON_EXPAND_TYPE_EXTRA, COUPON_EXPAND_TYPE_NONE, COUPON_EXPAND_TYPE_REASON } from './constant';
2
- export type CouponExpireDisplay = 'deadline' | 'validity';
2
+ /**
3
+ * 票面过期 / 有效期展示模式。
4
+ * - deadline:已领券实例,展示「过期时间」+ 截止日期
5
+ * - validity:发券模板,展示「有效期」+ 次卡同一套开始/结束类型文案
6
+ */
7
+ export type CouponExpireMode = 'deadline' | 'validity';
8
+ /**
9
+ * 调用方把接口原始项收到标准券结构。
10
+ * 返回空则跳过该项。H5 桥只能传函数字符串,由 APP createFunction 还原。
11
+ */
3
12
  export type CouponFormatItem = (item: any) => ICoupon | null | undefined;
13
+ /**
14
+ * 展开区类型。
15
+ * extra:可用券的使用规则;reason:不可用原因;none:没有可展开内容。
16
+ */
4
17
  export type CouponExpandType = typeof COUPON_EXPAND_TYPE_EXTRA | typeof COUPON_EXPAND_TYPE_REASON | typeof COUPON_EXPAND_TYPE_NONE;
18
+ /**
19
+ * 选券内部标准结构。后端字段未知时由 formatItem 映射到这里,
20
+ * UI 只消费 getView() 里的展示字段。
21
+ *
22
+ * 文案分两层:
23
+ * - formatItem 只搬数字 / 枚举(可过 App 桥),不要拼「使用门槛:xxx」
24
+ * - 标签和格式化在 couponUtil;extraLines 有值时覆盖展开区
25
+ */
5
26
  export interface ICoupon {
27
+ /** 券 / 模板 id,对齐 coupon.id / coupon_template.id */
6
28
  id: string | number;
29
+ /** 券名称,对齐 title */
7
30
  title: string;
8
- status?: number;
9
- available?: boolean;
10
- couponType?: number;
11
- amount?: number;
12
- discount?: number;
13
- thresholdType?: number;
14
- thresholdValue?: number;
15
- thresholdAmount?: number;
16
- thresholdText?: string;
17
- expireStartType?: number;
18
- expireStartTime?: number;
19
- expireEndType?: number;
20
- expireEndTime?: number;
21
- expireDays?: number;
22
- expireText?: string;
31
+ /**
32
+ * 券状态,对齐 coupon.status / coupon_template.status。
33
+ * 模板:1 草稿 / 2 已上线 / 3 已下线 / 4 已过期。
34
+ * 仅在带了 status 时:为 2 且没有 availableError 才可选;availableError 优先于 status。
35
+ * 没带 status 且没有 availableError 时视为可用。
36
+ */
37
+ status: number;
38
+ /**
39
+ * 券业务类型,对齐 coupon_type:1 折扣 / 2 满减 / 3 配送。
40
+ * 1 走折扣票面,2/3 走金额票面。
41
+ */
42
+ couponType: number;
43
+ /**
44
+ * 券面值,对齐 coupon_value。
45
+ * couponType 1 为折扣万分比(9000 → 9折);2/3 为金额最小单位。
46
+ */
47
+ couponValue: number;
48
+ /**
49
+ * 门槛类型,必传,对齐 threshold_type:1 金额 / 2 件数。
50
+ * 与 thresholdValue 一起生成门槛文案。
51
+ */
52
+ thresholdType: number;
53
+ /**
54
+ * 门槛值,必传,对齐 threshold_value。
55
+ * thresholdType 1 为金额最小单位,2 为件数;0 视为无门槛。
56
+ */
57
+ thresholdValue: number;
58
+ /**
59
+ * 生效开始类型,对齐 effective_start_type:
60
+ * 1 立即 / 2 指定时间。发券模板 expireMode: validity 时使用。
61
+ */
62
+ effectiveStartType?: number;
63
+ /** 生效开始时间戳,对齐 effective_start_time。effectiveStartType 为 2 时有值 */
64
+ effectiveStartTime?: number;
65
+ /**
66
+ * 生效结束类型,对齐 effective_end_type:
67
+ * 1 永久 / 2 指定时间 / 3 领取后延长 N 天。
68
+ */
69
+ effectiveEndType?: number;
70
+ /** 生效结束时间戳,对齐 effective_end_time。券实例票面截止日期优先用这个 */
71
+ effectiveEndTime?: number;
72
+ /** 领取后有效天数,对齐 effective_end_days。effectiveEndType 为 3 时有值 */
73
+ effectiveEndDays?: number;
74
+ /**
75
+ * 可用日期重复类型,对齐 available_repeat_type:
76
+ * 0 按天 / 1 按周 / 2 按月。
77
+ */
23
78
  availableRepeatType?: number;
79
+ /**
80
+ * 可用日期取值,对齐 available_repeat_value。
81
+ * 按周为周几 0-6,按月为 1-28 号。数组或 JSON 字符串均可。
82
+ */
24
83
  availableRepeatValue?: Array<number | string> | string;
84
+ /**
85
+ * 可用时段,对齐 available_minute_segments。
86
+ * 一维 [start, end, ...],单位分钟。数组或 JSON 字符串均可。
87
+ */
25
88
  availableMinuteSegments?: Array<number | string> | string;
26
- useLimitDaily?: number;
27
- useLimitWeekly?: number;
28
- useLimitMonthly?: number;
29
- extraLines?: string[];
30
- unavailableReason?: string;
89
+ /** 每人每日使用次数上限,对齐 per_user_use_limit_count_daily。0 或不传表示不限制 */
90
+ useLimitCountDaily?: number;
91
+ /** 每人每周使用次数上限,对齐 per_user_use_limit_count_weekly。0 或不传表示不限制 */
92
+ useLimitCountWeekly?: number;
93
+ /** 每人每月使用次数上限,对齐 per_user_use_limit_count_monthly。0 或不传表示不限制 */
94
+ useLimitCountMonthly?: number;
95
+ /**
96
+ * 本单不可用原因,对齐 available_error。
97
+ * 有值则一定不可用(优先于 status),并作为展开原因。
98
+ * 接口没返回时,按 status 补原因(草稿 / 已下线 / 已过期 / 已注销 / 已锁定)。
99
+ */
100
+ availableError?: string;
101
+ /**
102
+ * 确定时随 ICoupon 回传。
103
+ * formatItem 未填时自动挂列表原始 item(接口 list 那一行,原样引用)。
104
+ */
31
105
  original?: any;
106
+ /**
107
+ * 覆盖整段展开文案。有值时不再用可用日期/时间/使用限制生成。
108
+ * 建议已是「键:值」;也可只传值。
109
+ */
110
+ extraLines?: string[];
32
111
  }
112
+ /** 票面 / 展开区的键值行 */
33
113
  export interface ICouponKvLine {
114
+ /** 标签,如「使用门槛」。空则只展示 value */
34
115
  label: string;
116
+ /** 展示值,如「满20元」 */
35
117
  value: string;
36
118
  }
119
+ /**
120
+ * 票面展示数据。选券弹层和单独挂 CouponCard 都吃这个结构。
121
+ * 金额拆成 prefix / value / suffix,方便 ¥、数字、折用不同字号。
122
+ */
37
123
  export interface ICouponViewItem {
124
+ /** 标准券数据,确认时回传;点选/展开用 coupon.id */
38
125
  coupon: ICoupon;
126
+ /** 当前是否选中 */
39
127
  selected: boolean;
128
+ /** 当前是否展开详情 */
40
129
  expanded: boolean;
130
+ /** 是否可选、非灰态。availableError 优先,否则 status 为 2 才可用 */
41
131
  available: boolean;
132
+ /** 票面左侧前缀,满减为 ¥,折扣为空 */
42
133
  amountPrefix: string;
134
+ /** 票面数字,如 5 或 9 */
43
135
  amountValue: string;
136
+ /** 票面右侧单位,折扣为 折,满减为空 */
44
137
  amountSuffix: string;
138
+ /** 券名称,来自 coupon.title */
45
139
  title: string;
140
+ /** 票面信息区,已拼成「键:值」,含使用门槛、过期时间 / 有效期 */
46
141
  contentLines: string[];
47
- thresholdText: string;
48
- expireText: string;
142
+ /** 展开区类型:extra 使用规则 / reason 不可用原因 / none 无展开 */
49
143
  expandType: CouponExpandType;
144
+ /** 展开区文案。reason 时为原因正文,extra 时为「键:值」 */
50
145
  expandLines: string[];
51
146
  }
147
+ /** CouponSelector.getView() 的列表快照 */
52
148
  export interface ICouponSelectorView {
149
+ /** 当前列表票面,可用券在前 */
53
150
  items: ICouponViewItem[];
151
+ /** 当前选中的券 id */
54
152
  selectedId?: string | number;
153
+ /** 当前选中的标准券;未选则为空 */
55
154
  selectedCoupon?: ICoupon;
56
155
  }
156
+ /** CouponSelector 构造参数 */
57
157
  export interface ICouponSelectorOptions {
158
+ /** 初始列表;静态数据或接口第一页 */
58
159
  list?: any[];
160
+ /** 回显选中的券 id */
59
161
  value?: string | number;
162
+ /** 把接口原始项收到 ICoupon;不传则把 list 项当作已是 ICoupon */
60
163
  formatItem?: CouponFormatItem;
61
- expandOne?: boolean;
62
- expireDisplay?: CouponExpireDisplay;
164
+ /** true 时展开互斥,同时只展开一张,默认 false */
165
+ exclusiveExpand?: boolean;
166
+ /**
167
+ * deadline:过期时间 + 截止日期(实例,默认)。
168
+ * validity:有效期 + 次卡开始/结束类型文案(发券模板)。
169
+ */
170
+ expireMode?: CouponExpireMode;
171
+ /** 选中 / 展开 / 列表变化时通知 UI 重绘 */
63
172
  onChange: () => void;
64
173
  }
174
+ /** confirm() 的结果 */
65
175
  export interface ICouponConfirmResult {
176
+ /** 是否选中了可用券 */
66
177
  isValid: boolean;
178
+ /** 未选中时的提示,如「请选择优惠券」 */
67
179
  errMsg?: string;
180
+ /** 选中的标准券,含 original */
68
181
  coupon?: ICoupon;
69
182
  }
@@ -1,5 +1,11 @@
1
1
  import { ICartListItem, ISelectSkuComboItem } from './type';
2
2
  import { ICountChangeResult, IAddToCartParamsResult, IComboSpecSelectorView, IComboSpecSelectorOptions, IFetchCartCountParams, IFetchMemberPriceParams, IMallSkuDetailDataForCombo } from './type';
3
+ /**
4
+ * 套餐商品规格选择器
5
+ *
6
+ * 设计原则:类内部不发起任何接口请求,所有数据处理逻辑封装在此,
7
+ * 网络请求由 UI 层发起,将结果通过公开方法回填。
8
+ */
3
9
  export declare class ComboSpecSelector {
4
10
  private product;
5
11
  private specImage;
@@ -33,18 +39,49 @@ export declare class ComboSpecSelector {
33
39
  private _initSkuId;
34
40
  private _validateComboGroupList;
35
41
  constructor(options: IComboSpecSelectorOptions);
42
+ /** 获取初始 sku 列表(供 UI 在调用 fetchSkuDetail 前获取初始 skuId) */
36
43
  getInitialSkuId(): number;
44
+ /**
45
+ * 初始化,接收 UI 层拉取的 sku 详情数据
46
+ * 调用后触发 onChange,UI 可通过 getView() 拿到渲染数据
47
+ */
37
48
  init(skuDetailData: IMallSkuDetailDataForCombo): void;
49
+ /**
50
+ * 同步最新的购物车列表
51
+ * cartList 更新后调用此方法,会重新计算当前 skuId 在购物车中的数量
52
+ */
38
53
  syncCartList(cartList: ICartListItem[]): void;
39
54
  getView(): IComboSpecSelectorView;
55
+ /**
56
+ * 选择规格(纯数据处理)
57
+ * @returns needFetchSkuDetail 是否需要重新拉取 sku 详情(为 true 时同样需要重新请求会员价);skuId 目标 skuId
58
+ */
40
59
  handleSelectSpecs(isOption: boolean, value: string, index: number): {
41
60
  needFetchSkuDetail: boolean;
42
61
  skuId: number;
43
62
  };
63
+ /**
64
+ * 用新的 sku 详情数据更新内部状态
65
+ * (规格切换后,UI 调用 fetchSkuDetail 接口拿到数据后传入此方法)
66
+ */
44
67
  updateSkuDetailData(skuDetailData: IMallSkuDetailDataForCombo): void;
68
+ /**
69
+ * 用会员价查询结果更新内部状态,由 UI 层请求会员价接口后调用
70
+ * @param price 会员价,请求失败或无会员价时传 undefined
71
+ */
45
72
  updateMemberPrice(price: number | undefined): void;
73
+ /**
74
+ * 套餐选中变化(纯数据处理)
75
+ */
46
76
  handleSelectComboData(skuComboItemList: ISelectSkuComboItem[][]): void;
77
+ /**
78
+ * 数量变化(纯逻辑,返回操作结果供 UI 决策)
79
+ */
47
80
  handleProductCountChange(count: number, type: string): ICountChangeResult;
81
+ /**
82
+ * 加入购物车前校验,返回提交所需参数
83
+ * 由 UI 层使用参数调用 addToCart 接口
84
+ */
48
85
  getAddToCartParams(productId: number, promotionActivityProductId?: number): IAddToCartParamsResult;
49
86
  handleShowComboInfo(): void;
50
87
  handleCloseComboInfo(): void;
@@ -52,14 +89,31 @@ export declare class ComboSpecSelector {
52
89
  getOriginalPrice(): number;
53
90
  getMemberPrice(): number | undefined;
54
91
  buildCartCountParams(): IFetchCartCountParams;
92
+ /**
93
+ * 构造会员价查询参数(供 UI 层使用)
94
+ * sku 未选中时返回 undefined
95
+ */
55
96
  buildMemberPriceParams(): IFetchMemberPriceParams | undefined;
56
97
  private _initProductData;
57
98
  private _initSkuDetail;
58
99
  private _updateSkuData;
59
100
  private _checkProductCount;
101
+ /**
102
+ * 内部规格选择逻辑(被 handleSelectSpecs 和 init 时复用)
103
+ * @returns 是否发生了选中变化
104
+ */
60
105
  private _selectSpec;
106
+ /**
107
+ * 刷新当前 skuId 对应的购物车数据
108
+ */
61
109
  private _refreshCartItem;
110
+ /**
111
+ * 根据 skuId 和当前 skuComboItemList 从 cartList 中查找匹配的购物车项
112
+ */
62
113
  private _findSkuCartItem;
114
+ /**
115
+ * 校验套餐分组是否满足要求,返回错误信息(空字符串表示校验通过)
116
+ */
63
117
  private _validateCombo;
64
118
  private _notifyChange;
65
119
  }
@@ -21,8 +21,11 @@ export declare function checkGroupCanMinusCount(comboGroupItem: ISkuComboGroupIt
21
21
  export declare function checkIsFixedSelectNeedSelectSku(comboItem: ISkuComboItem): boolean;
22
22
  export declare function checkIsUseSelectSkuBtn(comboItem: ISkuComboItem): boolean;
23
23
  export declare function getSkuComboItemGroup(skuComboItemList: ICartSkuComboItem[]): ISkuComboGroupList[];
24
+ /** 将购物车数据回填到 comboGroupList */
24
25
  export declare function reconstructComboGroupList(comboGroupList: ISkuComboGroupItem[], skuComboItemList?: ICartSkuComboItem[]): ISkuComboGroupItem[];
26
+ /** 格式化当前选中的 skuComboItemList(二维数组) */
25
27
  export declare function formatSelectSkuComboItemList(comboGroupList: ISkuComboGroupItem[]): ISelectSkuComboItem[][];
28
+ /** 校验 comboGroupList 选中是否合法,合法返回 '',否则返回错误信息 */
26
29
  export declare function validateComboGroupList(comboGroupList: ISkuComboGroupItem[], skuComboItemList?: ISelectSkuComboItem[][]): string;
27
30
  export declare function formatComboGroupItemSelectTips(comboGroupItem: ISkuComboGroupItem): string;
28
31
  export declare function generateCartSkuComboItemList(skuComboItemList: ISelectSkuComboItem[][] | undefined): ICartSkuComboItem[];