@pisell/pisellos 0.0.9 → 0.0.11

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.
Files changed (136) hide show
  1. package/dist/core/index.js +4 -1
  2. package/dist/effects/index.d.ts +1 -1
  3. package/dist/effects/index.js +3 -3
  4. package/dist/modules/Account/index.d.ts +5 -3
  5. package/dist/modules/Account/index.js +23 -36
  6. package/dist/modules/Account/types.d.ts +2 -1
  7. package/dist/modules/AccountList/index.d.ts +2 -0
  8. package/dist/modules/AccountList/index.js +34 -11
  9. package/dist/modules/Cart/index.d.ts +17 -11
  10. package/dist/modules/Cart/index.js +179 -121
  11. package/dist/modules/Cart/types.d.ts +98 -9
  12. package/dist/modules/Cart/types.js +8 -0
  13. package/dist/modules/Cart/utils.d.ts +114 -0
  14. package/dist/modules/Cart/utils.js +345 -0
  15. package/dist/modules/Date/index.d.ts +11 -12
  16. package/dist/modules/Date/index.js +104 -60
  17. package/dist/modules/Date/types.d.ts +51 -20
  18. package/dist/modules/Date/types.js +2 -5
  19. package/dist/modules/Date/utils.d.ts +35 -0
  20. package/dist/modules/Date/utils.js +211 -0
  21. package/dist/modules/Discount/index.d.ts +26 -0
  22. package/dist/modules/Discount/index.js +234 -0
  23. package/dist/modules/Discount/types.d.ts +66 -0
  24. package/dist/modules/Discount/types.js +5 -0
  25. package/dist/modules/Order/index.d.ts +16 -12
  26. package/dist/modules/Order/index.js +38 -166
  27. package/dist/modules/Order/types.d.ts +18 -41
  28. package/dist/modules/Order/types.js +0 -14
  29. package/dist/modules/Payment/index.d.ts +0 -2
  30. package/dist/modules/Payment/index.js +45 -76
  31. package/dist/modules/Payment/types.d.ts +0 -2
  32. package/dist/modules/Payment/types.js +2 -0
  33. package/dist/modules/Product/types.d.ts +50 -1
  34. package/dist/modules/ProductList/index.d.ts +1 -0
  35. package/dist/modules/ProductList/index.js +23 -2
  36. package/dist/modules/ProductList/types.d.ts +1 -0
  37. package/dist/modules/Resource/types.d.ts +6 -2
  38. package/dist/modules/Rules/index.d.ts +32 -0
  39. package/dist/modules/Rules/index.js +423 -0
  40. package/dist/modules/Rules/types.d.ts +46 -0
  41. package/dist/modules/Rules/types.js +5 -0
  42. package/dist/modules/Summary/index.d.ts +13 -0
  43. package/dist/modules/Summary/index.js +80 -0
  44. package/dist/modules/Summary/types.d.ts +13 -0
  45. package/dist/modules/Summary/types.js +1 -0
  46. package/dist/modules/Summary/utils.d.ts +19 -0
  47. package/dist/modules/Summary/utils.js +56 -0
  48. package/dist/plugins/index.d.ts +3 -2
  49. package/dist/plugins/index.js +2 -1
  50. package/dist/plugins/request.d.ts +4 -3
  51. package/dist/plugins/request.js +30 -30
  52. package/dist/plugins/shopStore.d.ts +4 -0
  53. package/dist/plugins/shopStore.js +1 -0
  54. package/dist/solution/BookingByStep/index.d.ts +73 -10
  55. package/dist/solution/BookingByStep/index.js +641 -74
  56. package/dist/solution/BookingByStep/types.d.ts +2 -0
  57. package/dist/solution/BookingByStep/types.js +11 -8
  58. package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
  59. package/dist/solution/BookingByStep/utils/products.js +47 -0
  60. package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
  61. package/dist/solution/BookingByStep/utils/resources.js +144 -79
  62. package/dist/solution/ShopDiscount/index.d.ts +50 -0
  63. package/dist/solution/ShopDiscount/index.js +546 -0
  64. package/dist/solution/ShopDiscount/types.d.ts +24 -0
  65. package/dist/solution/ShopDiscount/types.js +10 -0
  66. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  67. package/dist/solution/ShopDiscount/utils.js +7 -0
  68. package/dist/solution/index.d.ts +1 -0
  69. package/dist/solution/index.js +2 -1
  70. package/lib/core/index.js +1 -1
  71. package/lib/effects/index.d.ts +1 -1
  72. package/lib/effects/index.js +1 -1
  73. package/lib/modules/Account/index.d.ts +5 -3
  74. package/lib/modules/Account/index.js +14 -3
  75. package/lib/modules/Account/types.d.ts +2 -1
  76. package/lib/modules/AccountList/index.d.ts +2 -0
  77. package/lib/modules/AccountList/index.js +17 -0
  78. package/lib/modules/Cart/index.d.ts +17 -11
  79. package/lib/modules/Cart/index.js +72 -21
  80. package/lib/modules/Cart/types.d.ts +98 -9
  81. package/lib/modules/Cart/utils.d.ts +114 -0
  82. package/lib/modules/Cart/utils.js +320 -0
  83. package/lib/modules/Date/index.d.ts +11 -12
  84. package/lib/modules/Date/index.js +50 -31
  85. package/lib/modules/Date/types.d.ts +51 -20
  86. package/lib/modules/Date/types.js +0 -4
  87. package/lib/modules/Date/utils.d.ts +35 -0
  88. package/lib/modules/Date/utils.js +167 -0
  89. package/lib/modules/Discount/index.d.ts +26 -0
  90. package/lib/modules/Discount/index.js +118 -0
  91. package/lib/modules/Discount/types.d.ts +66 -0
  92. package/lib/modules/Discount/types.js +33 -0
  93. package/lib/modules/Order/index.d.ts +16 -12
  94. package/lib/modules/Order/index.js +23 -51
  95. package/lib/modules/Order/types.d.ts +18 -41
  96. package/lib/modules/Payment/index.d.ts +0 -2
  97. package/lib/modules/Payment/index.js +6 -17
  98. package/lib/modules/Payment/types.d.ts +0 -2
  99. package/lib/modules/Product/types.d.ts +50 -1
  100. package/lib/modules/ProductList/index.d.ts +1 -0
  101. package/lib/modules/ProductList/index.js +6 -1
  102. package/lib/modules/ProductList/types.d.ts +1 -0
  103. package/lib/modules/Resource/types.d.ts +6 -2
  104. package/lib/modules/Rules/index.d.ts +32 -0
  105. package/lib/modules/Rules/index.js +283 -0
  106. package/lib/modules/Rules/types.d.ts +46 -0
  107. package/lib/modules/Rules/types.js +33 -0
  108. package/lib/modules/Summary/index.d.ts +13 -0
  109. package/lib/modules/Summary/index.js +49 -0
  110. package/lib/modules/Summary/types.d.ts +13 -0
  111. package/lib/modules/Summary/types.js +17 -0
  112. package/lib/modules/Summary/utils.d.ts +19 -0
  113. package/lib/modules/Summary/utils.js +79 -0
  114. package/lib/plugins/index.d.ts +3 -2
  115. package/lib/plugins/index.js +3 -1
  116. package/lib/plugins/request.d.ts +4 -3
  117. package/lib/plugins/request.js +4 -20
  118. package/lib/plugins/shopStore.d.ts +4 -0
  119. package/lib/plugins/shopStore.js +17 -0
  120. package/lib/solution/BookingByStep/index.d.ts +73 -10
  121. package/lib/solution/BookingByStep/index.js +452 -20
  122. package/lib/solution/BookingByStep/types.d.ts +2 -0
  123. package/lib/solution/BookingByStep/types.js +3 -0
  124. package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
  125. package/lib/solution/BookingByStep/utils/products.js +60 -0
  126. package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
  127. package/lib/solution/BookingByStep/utils/resources.js +106 -49
  128. package/lib/solution/ShopDiscount/index.d.ts +50 -0
  129. package/lib/solution/ShopDiscount/index.js +321 -0
  130. package/lib/solution/ShopDiscount/types.d.ts +24 -0
  131. package/lib/solution/ShopDiscount/types.js +38 -0
  132. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  133. package/lib/solution/ShopDiscount/utils.js +32 -0
  134. package/lib/solution/index.d.ts +1 -0
  135. package/lib/solution/index.js +3 -1
  136. package/package.json +8 -7
@@ -1,33 +1,64 @@
1
1
  export declare enum DateHooks {
2
- OnDateChange = "date:onDateChange",
3
- OnTimeSlotChange = "date:onTimeSlotChange",
4
- OnGetDateList = "date:onGetDateList"
5
2
  }
6
3
  /**
7
- * 时间槽位
4
+ * 日期模块状态
8
5
  */
9
- export interface TimeSlot {
10
- start: Date;
11
- end: Date;
12
- isAvailable: boolean;
6
+ export interface DateState {
7
+ /**
8
+ * 可用时间列表
9
+ */
10
+ dateList: ITime[];
11
+ /**
12
+ * 日期范围
13
+ */
14
+ dateRange: ITime[];
13
15
  }
14
16
  /**
15
- * 日期模块状态
17
+ * 时间
16
18
  */
17
- export interface DateState {
18
- selectedDate: Date | null;
19
- selectedTimeSlot: TimeSlot | null;
20
- availableTimeSlots: TimeSlot[];
19
+ export interface ITime {
20
+ date: string;
21
+ week: string;
22
+ weekNum: number;
23
+ status: "unavailable" | "available";
24
+ resource?: any[];
21
25
  }
22
26
  /**
23
27
  * 日期模块 API
24
28
  */
25
29
  export interface DateModuleAPI {
26
- setDate: (date: Date) => Promise<void>;
27
- setTimeSlot: (timeSlot: TimeSlot) => Promise<void>;
28
- getSelectedDate: () => Date | null;
29
- getSelectedTimeSlot: () => TimeSlot | null;
30
- getAvailableTimeSlots: () => TimeSlot[];
31
- isDateAvailable: (date: Date) => boolean;
32
- isTimeSlotAvailable: (timeSlot: TimeSlot) => boolean;
30
+ /**
31
+ * 获取可用时间列表
32
+ */
33
+ getAvailableTimeList: (params: IGetAvailableTimeListParams) => Promise<ITime[]>;
34
+ /**
35
+ * 设置日期范围
36
+ */
37
+ setDateRange: (range: ITime[]) => void;
38
+ /**
39
+ * 获取月份日期
40
+ */
41
+ getMonthDates: (params: IGetAvailableTimeListParams) => Promise<ITime[]>;
42
+ }
43
+ export interface IGetAvailableTimeListParams {
44
+ url?: string;
45
+ query?: {
46
+ start_date: string;
47
+ end_date: string;
48
+ resource_ids?: Array<number | string>;
49
+ };
50
+ rules?: Array<{
51
+ /**
52
+ * 提前量
53
+ */
54
+ cut_off_time?: {
55
+ future_day?: number;
56
+ unit?: number;
57
+ unit_type?: "minutes" | "hours" | "days";
58
+ };
59
+ /**
60
+ * 资源ID
61
+ */
62
+ resourceFormIds?: number[];
63
+ }>;
33
64
  }
@@ -1,16 +1,13 @@
1
1
  export var DateHooks = /*#__PURE__*/function (DateHooks) {
2
- DateHooks["OnDateChange"] = "date:onDateChange";
3
- DateHooks["OnTimeSlotChange"] = "date:onTimeSlotChange";
4
- DateHooks["OnGetDateList"] = "date:onGetDateList";
5
2
  return DateHooks;
6
3
  }({});
7
4
 
8
5
  /**
9
- * 时间槽位
6
+ * 日期模块状态
10
7
  */
11
8
 
12
9
  /**
13
- * 日期模块状态
10
+ * 时间
14
11
  */
15
12
 
16
13
  /**
@@ -0,0 +1,35 @@
1
+ import { IGetAvailableTimeListParams, ITime } from "./types";
2
+ /**
3
+ * 生成当前月份的所有日期
4
+ * @param startDate 开始日期
5
+ * @param endDate 结束日期
6
+ * @returns 日期列表
7
+ */
8
+ export declare const generateMonthDates: (startDate: string, endDate: string) => ITime[];
9
+ /**
10
+ * 禁用所有日期
11
+ * @param dates 日期列表
12
+ * @returns 日期列表
13
+ */
14
+ export declare const disableAllDates: (dates: ITime[]) => ITime[];
15
+ /**
16
+ * 禁用某一天之前的日期,如不传则默认今天
17
+ * @param dates 日期列表
18
+ * @param oneDay 日期
19
+ * @returns 日期列表
20
+ */
21
+ export declare const disableDatesBeforeOneDay: (dates: ITime[], oneDay?: string) => ITime[];
22
+ /**
23
+ * 根据资源中的日期处理出每个日期下存在的可用资源,根据form_id进行分类
24
+ * @param resources 资源列表
25
+ * @param dates 日期列表
26
+ * @returns 日期列表
27
+ */
28
+ export declare const handleAvailableDateByResource: (resources: any[], dates: ITime[]) => ITime[];
29
+ /**
30
+ * 根据规则判定哪些日期是可用的
31
+ * @param dates 日期列表
32
+ * @param rules 提前量规则
33
+ * @returns 日期列表
34
+ */
35
+ export declare const handleAvailableDatesByRules: (dates: ITime[], rules: IGetAvailableTimeListParams["rules"]) => ITime[];
@@ -0,0 +1,211 @@
1
+ var _excluded = ["form_id", "id", "times"];
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
+ import dayjs from "dayjs";
17
+ /**
18
+ * 生成当前月份的所有日期
19
+ * @param startDate 开始日期
20
+ * @param endDate 结束日期
21
+ * @returns 日期列表
22
+ */
23
+ export var generateMonthDates = function generateMonthDates(startDate, endDate) {
24
+ var start = dayjs(startDate).format("YYYY-MM-01");
25
+ var end = dayjs(endDate).format("YYYY-MM-DD");
26
+ var dates = [];
27
+ var currentDate = dayjs(start);
28
+ while (dayjs(currentDate).isBefore(dayjs(end)) || dayjs(currentDate).isSame(dayjs(end))) {
29
+ dates.push({
30
+ date: dayjs(currentDate).format("YYYY-MM-DD"),
31
+ week: dayjs(currentDate).format("ddd"),
32
+ weekNum: dayjs(currentDate).day(),
33
+ status: "available"
34
+ });
35
+ currentDate = dayjs(currentDate).add(1, "day");
36
+ }
37
+ return dates;
38
+ };
39
+
40
+ /**
41
+ * 禁用所有日期
42
+ * @param dates 日期列表
43
+ * @returns 日期列表
44
+ */
45
+ export var disableAllDates = function disableAllDates(dates) {
46
+ return dates.map(function (date) {
47
+ return _objectSpread(_objectSpread({}, date), {}, {
48
+ status: "unavailable"
49
+ });
50
+ });
51
+ };
52
+
53
+ /**
54
+ * 禁用某一天之前的日期,如不传则默认今天
55
+ * @param dates 日期列表
56
+ * @param oneDay 日期
57
+ * @returns 日期列表
58
+ */
59
+ export var disableDatesBeforeOneDay = function disableDatesBeforeOneDay(dates, oneDay) {
60
+ var day = oneDay ? dayjs(oneDay).format("YYYY-MM-DD") : dayjs().format("YYYY-MM-DD");
61
+ return dates.map(function (date) {
62
+ if (dayjs(date.date).isBefore(day)) {
63
+ return _objectSpread(_objectSpread({}, date), {}, {
64
+ status: "unavailable"
65
+ });
66
+ } else {
67
+ return date;
68
+ }
69
+ });
70
+ };
71
+
72
+ /**
73
+ * 根据资源中的日期处理出每个日期下存在的可用资源,根据form_id进行分类
74
+ * @param resources 资源列表
75
+ * @param dates 日期列表
76
+ * @returns 日期列表
77
+ */
78
+ export var handleAvailableDateByResource = function handleAvailableDateByResource(resources, dates) {
79
+ var dateMap = {};
80
+ resources.forEach(function (resource) {
81
+ var form_id = resource.form_id,
82
+ id = resource.id,
83
+ times = resource.times,
84
+ others = _objectWithoutProperties(resource, _excluded);
85
+ times.forEach(function (time) {
86
+ var start_at = time.start_at;
87
+ var date = dayjs(start_at).format("YYYY-MM-DD");
88
+ if (!dateMap[date]) {
89
+ dateMap[date] = [_objectSpread(_objectSpread({
90
+ form_id: form_id,
91
+ id: id
92
+ }, others), {}, {
93
+ times: [time]
94
+ })];
95
+ } else {
96
+ var _dateMap$date$filter;
97
+ var temp = (_dateMap$date$filter = dateMap[date].filter(function (item) {
98
+ return item.id === id;
99
+ })) === null || _dateMap$date$filter === void 0 ? void 0 : _dateMap$date$filter[0];
100
+ if (temp) {
101
+ temp.times.push(time);
102
+ } else {
103
+ dateMap[date].push(_objectSpread(_objectSpread({
104
+ form_id: form_id,
105
+ id: id
106
+ }, others), {}, {
107
+ times: [time]
108
+ }));
109
+ }
110
+ }
111
+ });
112
+ });
113
+ return dates.map(function (date) {
114
+ var resource = dateMap[date.date];
115
+ if (resource) {
116
+ return _objectSpread(_objectSpread({}, date), {}, {
117
+ resource: resource
118
+ });
119
+ } else {
120
+ return _objectSpread(_objectSpread({}, date), {}, {
121
+ status: "unavailable",
122
+ resource: []
123
+ });
124
+ }
125
+ });
126
+ };
127
+
128
+ /**
129
+ * 根据规则判定哪些日期是可用的
130
+ * @param dates 日期列表
131
+ * @param rules 提前量规则
132
+ * @returns 日期列表
133
+ */
134
+ export var handleAvailableDatesByRules = function handleAvailableDatesByRules(dates, rules) {
135
+ var newDates = disableDatesBeforeOneDay(dates);
136
+ if (!(rules !== null && rules !== void 0 && rules.length)) {
137
+ return newDates;
138
+ }
139
+ var latestStartDate = ""; // 最晚开始日期
140
+ var earliestEndDate = ""; // 最早结束日期
141
+ var resourceFormIds = [];
142
+ rules.forEach(function (rule) {
143
+ var _rule$resourceFormIds;
144
+ var _ref = (rule === null || rule === void 0 ? void 0 : rule.cut_off_time) || {},
145
+ future_day = _ref.future_day,
146
+ unit = _ref.unit,
147
+ unit_type = _ref.unit_type;
148
+ // 预定天数存在,则开始计算从当前时间开始往后推预定天数作为结束时间
149
+ if (future_day) {
150
+ var endDate = dayjs().add(future_day, "day");
151
+ if (!earliestEndDate || endDate.isBefore(dayjs(earliestEndDate))) {
152
+ earliestEndDate = endDate.format("YYYY-MM-DD");
153
+ }
154
+ } else if (future_day === 0) {
155
+ var _endDate = dayjs();
156
+ if (!earliestEndDate || _endDate.isBefore(dayjs(earliestEndDate))) {
157
+ earliestEndDate = _endDate.format("YYYY-MM-DD");
158
+ }
159
+ }
160
+
161
+ // 如果存在提前预约时间,则开始计算从当前时间开始往后推提前预约时间作为开始时间
162
+ if (unit && unit_type) {
163
+ var startDate = dayjs(dayjs().add(unit, unit_type).format("YYYY-MM-DD"));
164
+ if (!latestStartDate || startDate.isAfter(dayjs(latestStartDate))) {
165
+ latestStartDate = startDate.format("YYYY-MM-DD");
166
+ }
167
+ }
168
+ if (rule !== null && rule !== void 0 && (_rule$resourceFormIds = rule.resourceFormIds) !== null && _rule$resourceFormIds !== void 0 && _rule$resourceFormIds.length) {
169
+ // 去重
170
+ resourceFormIds = _toConsumableArray(new Set([].concat(_toConsumableArray(resourceFormIds), _toConsumableArray(rule === null || rule === void 0 ? void 0 : rule.resourceFormIds))));
171
+ }
172
+ });
173
+ newDates = newDates.map(function (date) {
174
+ var _date$resource, _resourceFormIds;
175
+ var disabledDate = _objectSpread(_objectSpread({}, date), {}, {
176
+ status: "unavailable"
177
+ });
178
+ if (!(date !== null && date !== void 0 && (_date$resource = date.resource) !== null && _date$resource !== void 0 && _date$resource.length)) {
179
+ return disabledDate;
180
+ }
181
+ if (latestStartDate || earliestEndDate) {
182
+ // 如果时间在最早开始时间之前,则设置为不可用
183
+ if (latestStartDate && dayjs(date.date).isBefore(latestStartDate)) {
184
+ return disabledDate;
185
+ }
186
+ // 如果时间在最早结束时间之后,则设置为不可用
187
+ if (earliestEndDate && dayjs(date.date).isAfter(earliestEndDate)) {
188
+ return disabledDate;
189
+ }
190
+ }
191
+
192
+ // 如果存在资源form_id,则开始计算资源form_id在日期上是否全部存在
193
+ if ((_resourceFormIds = resourceFormIds) !== null && _resourceFormIds !== void 0 && _resourceFormIds.length) {
194
+ var hasReourceCount = 0;
195
+ resourceFormIds.forEach(function (formId) {
196
+ var _date$resource2;
197
+ if ((date === null || date === void 0 || (_date$resource2 = date.resource) === null || _date$resource2 === void 0 ? void 0 : _date$resource2.find(function (item) {
198
+ return item.form_id === formId;
199
+ })) !== undefined) {
200
+ hasReourceCount++;
201
+ }
202
+ });
203
+ // 如果所需要的资源在日期上不足,则设置为不可用
204
+ if (hasReourceCount < resourceFormIds.length) {
205
+ return disabledDate;
206
+ }
207
+ }
208
+ return date;
209
+ });
210
+ return newDates;
211
+ };
@@ -0,0 +1,26 @@
1
+ import { Module, PisellCore, ModuleOptions } from "../../types";
2
+ import { BaseModule } from "../BaseModule";
3
+ import { Discount, DiscountModuleAPI } from "./types";
4
+ export declare class DiscountModule extends BaseModule implements Module, DiscountModuleAPI {
5
+ protected defaultName: string;
6
+ protected defaultVersion: string;
7
+ private request;
8
+ private window;
9
+ private store;
10
+ constructor(name?: string, version?: string);
11
+ initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
12
+ setDiscountList(discountList: Discount[]): Promise<void>;
13
+ getDiscountList(): Discount[];
14
+ loadPrepareConfig(params: {
15
+ action?: "create";
16
+ with_good_pass: 0 | 1;
17
+ customer_id: number;
18
+ }): Promise<Discount[]>;
19
+ batchSearch(code: string): Promise<Discount[]>;
20
+ filterEnabledDiscountList(discountList: Discount[]): Discount[];
21
+ uniqueByProductId(discountList: Discount[]): Discount[];
22
+ filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
23
+ calcDiscountApplicableProductTotalPrice(discount: Discount): number;
24
+ destroy(): Promise<void>;
25
+ clear(): Promise<void>;
26
+ }
@@ -0,0 +1,234 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
9
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
10
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
12
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
13
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
14
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
+ import { uniqueById } from "../../solution/ShopDiscount/utils";
19
+ import { BaseModule } from "../BaseModule";
20
+ import { DiscountHooks } from "./types";
21
+ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
22
+ _inherits(DiscountModule, _BaseModule);
23
+ var _super = _createSuper(DiscountModule);
24
+ function DiscountModule(name, version) {
25
+ var _this;
26
+ _classCallCheck(this, DiscountModule);
27
+ _this = _super.call(this, name, version);
28
+ _defineProperty(_assertThisInitialized(_this), "defaultName", "discount");
29
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
30
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
31
+ _defineProperty(_assertThisInitialized(_this), "window", void 0);
32
+ _defineProperty(_assertThisInitialized(_this), "store", void 0);
33
+ return _this;
34
+ }
35
+ _createClass(DiscountModule, [{
36
+ key: "initialize",
37
+ value: function () {
38
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
39
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
40
+ while (1) switch (_context.prev = _context.next) {
41
+ case 0:
42
+ this.core = core;
43
+ this.store = options === null || options === void 0 ? void 0 : options.store;
44
+
45
+ // 获取依赖的插件
46
+ this.request = core.getPlugin("request");
47
+ this.window = core.getPlugin("window");
48
+ if (this.request) {
49
+ _context.next = 6;
50
+ break;
51
+ }
52
+ throw new Error("discount模块需要 request 插件支持");
53
+ case 6:
54
+ if (this.window) {
55
+ _context.next = 8;
56
+ break;
57
+ }
58
+ throw new Error("discount模块需要 window 插件支持");
59
+ case 8:
60
+ case "end":
61
+ return _context.stop();
62
+ }
63
+ }, _callee, this);
64
+ }));
65
+ function initialize(_x, _x2) {
66
+ return _initialize.apply(this, arguments);
67
+ }
68
+ return initialize;
69
+ }()
70
+ }, {
71
+ key: "setDiscountList",
72
+ value: function () {
73
+ var _setDiscountList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(discountList) {
74
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
75
+ while (1) switch (_context2.prev = _context2.next) {
76
+ case 0:
77
+ this.store.discountList = discountList;
78
+ _context2.next = 3;
79
+ return this.core.effects.emit(DiscountHooks.OnDiscountListChange, discountList);
80
+ case 3:
81
+ case "end":
82
+ return _context2.stop();
83
+ }
84
+ }, _callee2, this);
85
+ }));
86
+ function setDiscountList(_x3) {
87
+ return _setDiscountList.apply(this, arguments);
88
+ }
89
+ return setDiscountList;
90
+ }()
91
+ }, {
92
+ key: "getDiscountList",
93
+ value: function getDiscountList() {
94
+ return this.store.discountList;
95
+ }
96
+ }, {
97
+ key: "loadPrepareConfig",
98
+ value: function () {
99
+ var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
100
+ var _prepareConfig$data;
101
+ var prepareConfig, goodPassList;
102
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
103
+ while (1) switch (_context3.prev = _context3.next) {
104
+ case 0:
105
+ _context3.next = 2;
106
+ return this.request.post("/order/prepare/config", params);
107
+ case 2:
108
+ prepareConfig = _context3.sent;
109
+ goodPassList = this.uniqueByProductId(this.filterEnabledDiscountList((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data = prepareConfig.data) === null || _prepareConfig$data === void 0 ? void 0 : _prepareConfig$data.good_pass_list) || []) || []) || [];
110
+ return _context3.abrupt("return", goodPassList);
111
+ case 5:
112
+ case "end":
113
+ return _context3.stop();
114
+ }
115
+ }, _callee3, this);
116
+ }));
117
+ function loadPrepareConfig(_x4) {
118
+ return _loadPrepareConfig.apply(this, arguments);
119
+ }
120
+ return loadPrepareConfig;
121
+ }()
122
+ }, {
123
+ key: "batchSearch",
124
+ value: function () {
125
+ var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(code) {
126
+ var result, resultDiscountList;
127
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
128
+ while (1) switch (_context4.prev = _context4.next) {
129
+ case 0:
130
+ _context4.next = 2;
131
+ return this.request.get("/machinecode/batch-search", {
132
+ code: code,
133
+ translate_flag: 1,
134
+ tag: "good_pass",
135
+ available: 1,
136
+ relation_product: 1
137
+ });
138
+ case 2:
139
+ result = _context4.sent;
140
+ resultDiscountList = this.uniqueByProductId(this.filterEnabledDiscountList((result === null || result === void 0 ? void 0 : result.data) || []) || []) || [];
141
+ return _context4.abrupt("return", resultDiscountList);
142
+ case 5:
143
+ case "end":
144
+ return _context4.stop();
145
+ }
146
+ }, _callee4, this);
147
+ }));
148
+ function batchSearch(_x5) {
149
+ return _batchSearch.apply(this, arguments);
150
+ }
151
+ return batchSearch;
152
+ }()
153
+ }, {
154
+ key: "filterEnabledDiscountList",
155
+ value: function filterEnabledDiscountList(discountList) {
156
+ return discountList.filter(function (discount) {
157
+ return discount.limit_status === "enable" && Number((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0) - Number((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0) > 0;
158
+ });
159
+ }
160
+
161
+ // 根据productIds去重
162
+ }, {
163
+ key: "uniqueByProductId",
164
+ value: function uniqueByProductId(discountList) {
165
+ return uniqueById(discountList, "product_id");
166
+ }
167
+ }, {
168
+ key: "filterDiscountListByProductIds",
169
+ value: function filterDiscountListByProductIds(discountList, productIds) {
170
+ return discountList.filter(function (discount) {
171
+ var applicableProductIds = discount.applicableProductIds || [];
172
+ return applicableProductIds.some(function (id) {
173
+ return productIds.includes(id);
174
+ });
175
+ });
176
+ }
177
+ }, {
178
+ key: "calcDiscountApplicableProductTotalPrice",
179
+ value: function calcDiscountApplicableProductTotalPrice(discount) {
180
+ if (discount.appliedProductDetails) {
181
+ return discount.appliedProductDetails.reduce(function (total, product) {
182
+ var price = Number(product === null || product === void 0 ? void 0 : product.amount) || 0;
183
+ return total + price;
184
+ }, 0);
185
+ }
186
+ return (discount === null || discount === void 0 ? void 0 : discount.savedAmount) || 0;
187
+ }
188
+ }, {
189
+ key: "destroy",
190
+ value: function () {
191
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
192
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
193
+ while (1) switch (_context5.prev = _context5.next) {
194
+ case 0:
195
+ this.store.discountList = [];
196
+ this.core.effects.offByModuleDestroy(this.name);
197
+ _context5.next = 4;
198
+ return this.core.effects.emit(DiscountHooks.OnDestroy, {});
199
+ case 4:
200
+ console.log("[Discount] 已销毁");
201
+ case 5:
202
+ case "end":
203
+ return _context5.stop();
204
+ }
205
+ }, _callee5, this);
206
+ }));
207
+ function destroy() {
208
+ return _destroy.apply(this, arguments);
209
+ }
210
+ return destroy;
211
+ }()
212
+ }, {
213
+ key: "clear",
214
+ value: function () {
215
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
216
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
217
+ while (1) switch (_context6.prev = _context6.next) {
218
+ case 0:
219
+ this.store.discountList = [];
220
+ console.log("[Discount] clear");
221
+ case 2:
222
+ case "end":
223
+ return _context6.stop();
224
+ }
225
+ }, _callee6, this);
226
+ }));
227
+ function clear() {
228
+ return _clear.apply(this, arguments);
229
+ }
230
+ return clear;
231
+ }()
232
+ }]);
233
+ return DiscountModule;
234
+ }(BaseModule);