@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
@@ -0,0 +1,345 @@
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 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ import dayjs from "dayjs";
8
+ /**
9
+ * 生成一个唯一的 ID
10
+ */
11
+ export var getUniqueId = function getUniqueId() {
12
+ var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
13
+ var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 11;
14
+ return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
15
+ };
16
+
17
+ /**
18
+ * 创建购物车原始数据
19
+ */
20
+ export var createCartItemOrigin = function createCartItemOrigin() {
21
+ return {
22
+ // 新增为0
23
+ id: 0,
24
+ // 数量 固定为1
25
+ number: 1,
26
+ // 客户端报名所有活动;
27
+ registration_type: "all",
28
+ // 暂时不用
29
+ relation_products: [],
30
+ // 固定
31
+ is_all: false,
32
+ // 商品相关
33
+ product: null,
34
+ // 时长类型
35
+ sub_type: null,
36
+ // 时长
37
+ duration: null,
38
+ // 资源相关
39
+ // 资源状态 -固定
40
+ like_status: "common",
41
+ // 资源类型 - 固定
42
+ relation_type: "form",
43
+ // 所选资源
44
+ resources: null,
45
+ // 日程id - 固定
46
+ schedule_id: 0,
47
+ // 所选开始时间
48
+ start_date: null,
49
+ // 所选开始时间
50
+ start_time: null,
51
+ // 所选开始时间
52
+ select_date: null,
53
+ // 所选结束时间
54
+ end_time: null,
55
+ // 所选结束时间
56
+ end_date: null,
57
+ // 额外信息
58
+ metadata: {}
59
+
60
+ // holder相关
61
+ // holder: null,
62
+ };
63
+ };
64
+
65
+ /**
66
+ * 格式化商品到购物车
67
+ * @param product 商品
68
+ * @returns 格式化后的商品
69
+ */
70
+ export var formatProductToCartItem = function formatProductToCartItem(params) {
71
+ var cartItem = params.cartItem,
72
+ product = params.product,
73
+ bundle = params.bundle,
74
+ options = params.options;
75
+ if (product) {
76
+ cartItem.id = product === null || product === void 0 ? void 0 : product.id;
77
+ cartItem.name = product === null || product === void 0 ? void 0 : product.title;
78
+ cartItem.price = product === null || product === void 0 ? void 0 : product.price;
79
+ cartItem.total = getProductTotalPrice({
80
+ product: product,
81
+ bundle: bundle,
82
+ options: options
83
+ });
84
+ cartItem.origin_total = getProductOriginTotalPrice({
85
+ product: product,
86
+ bundle: bundle,
87
+ options: options
88
+ });
89
+ cartItem.num = 1;
90
+ cartItem.image = product === null || product === void 0 ? void 0 : product.cover;
91
+ cartItem.like_status = "common";
92
+ cartItem.duration = product === null || product === void 0 ? void 0 : product.duration;
93
+ cartItem.isNormalProduct = isNormalProduct(product);
94
+ cartItem.is_charge_tax = product === null || product === void 0 ? void 0 : product.is_charge_tax;
95
+ }
96
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
97
+ cartItem.bundle = formatBundle(bundle);
98
+ }
99
+ if (options !== null && options !== void 0 && options.length) {
100
+ cartItem.options = formatOptions(options);
101
+ }
102
+ var oringin = formatProductToCartItemOrigin(params);
103
+ cartItem._origin = oringin;
104
+ return cartItem;
105
+ };
106
+ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigin(params) {
107
+ var cartItem = params.cartItem,
108
+ product = params.product,
109
+ bundle = params.bundle,
110
+ options = params.options;
111
+ var origin = cartItem._origin;
112
+ if (product) {
113
+ var _origin$product, _origin$product2, _product$duration, _product$duration2;
114
+ origin.product = _objectSpread(_objectSpread({}, origin.product || {}), {}, {
115
+ num: 1,
116
+ product_id: product.id,
117
+ product_variant_id: (product === null || product === void 0 ? void 0 : product.product_variant_id) || 0,
118
+ product_bundle: ((_origin$product = origin.product) === null || _origin$product === void 0 ? void 0 : _origin$product.product_bundle) || [],
119
+ product_option_item: ((_origin$product2 = origin.product) === null || _origin$product2 === void 0 ? void 0 : _origin$product2.product_option_item) || []
120
+ });
121
+ // 时长类型
122
+ origin.sub_type = product === null || product === void 0 || (_product$duration = product.duration) === null || _product$duration === void 0 ? void 0 : _product$duration.type;
123
+ // 时长
124
+ origin.duration = product === null || product === void 0 || (_product$duration2 = product.duration) === null || _product$duration2 === void 0 ? void 0 : _product$duration2.value;
125
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
126
+ origin.product.product_bundle = formatBundleToOrigin(bundle);
127
+ }
128
+ if (options !== null && options !== void 0 && options.length) {
129
+ origin.product.product_option_item = formatOptionsToOrigin(options);
130
+ }
131
+ }
132
+ return origin;
133
+ };
134
+
135
+ /**
136
+ * 格式化账户到购物车
137
+ * @param account 账户
138
+ * @returns 格式化后的账户
139
+ */
140
+ export var formatAccountToCartItem = function formatAccountToCartItem(params) {
141
+ var cartItem = params.cartItem,
142
+ account = params.account;
143
+ if (account) {
144
+ cartItem.holder_id = account.id;
145
+ cartItem.holder_title = account.username;
146
+ }
147
+ var oringin = formatAccountToCartItemOrigin(params);
148
+ cartItem._origin = oringin;
149
+ return cartItem;
150
+ };
151
+ export var formatAccountToCartItemOrigin = function formatAccountToCartItemOrigin(params) {
152
+ var cartItem = params.cartItem,
153
+ account = params.account;
154
+ var origin = cartItem._origin;
155
+ if (account) {
156
+ origin.metadata.account = account;
157
+ }
158
+ return origin;
159
+ };
160
+
161
+ /**
162
+ * 格式化资源到购物车
163
+ * @param resource 资源
164
+ * @returns 格式化后的资源
165
+ */
166
+ export var formatResourceToCartItem = function formatResourceToCartItem(params) {
167
+ var cartItem = params.cartItem,
168
+ resources = params.resources;
169
+ if (resources && resources !== null && resources !== void 0 && resources.length) {
170
+ var firstResource = resources[0];
171
+ cartItem.resource_id = firstResource === null || firstResource === void 0 ? void 0 : firstResource.id;
172
+ cartItem.relation_form_name = firstResource === null || firstResource === void 0 ? void 0 : firstResource.main_field;
173
+ if (firstResource.startTime && firstResource.endTime) {
174
+ cartItem.start_date = dayjs(firstResource.startTime).format("YYYY-MM-DD");
175
+ cartItem.start_time = dayjs(firstResource.startTime).format("HH:mm");
176
+ cartItem.end_date = dayjs(firstResource.endTime).format("YYYY-MM-DD");
177
+ cartItem.end_time = dayjs(firstResource.endTime).format("HH:mm");
178
+ }
179
+ }
180
+ var oringin = formatResourceToCartItemOrigin(params);
181
+ cartItem._origin = oringin;
182
+ return cartItem;
183
+ };
184
+ export var formatResourceToCartItemOrigin = function formatResourceToCartItemOrigin(params) {
185
+ var cartItem = params.cartItem,
186
+ resources = params.resources;
187
+ var origin = cartItem._origin;
188
+ if (resources && resources !== null && resources !== void 0 && resources.length) {
189
+ origin.resources = [];
190
+ // 接口只需要部分字段,需要处理
191
+ resources.forEach(function (resource) {
192
+ origin.resources.push({
193
+ relation_type: "form",
194
+ like_status: "common",
195
+ id: resource.id,
196
+ main_field: resource.main_field,
197
+ resourceType: resource.resourceType,
198
+ form_id: resource.form_id,
199
+ relation_id: resource.id,
200
+ capacity: (resource === null || resource === void 0 ? void 0 : resource.capacity) || 0
201
+ });
202
+ });
203
+ var _resources$ = resources[0],
204
+ startTime = _resources$.startTime,
205
+ endTime = _resources$.endTime;
206
+ if (startTime && endTime) {
207
+ origin.select_date = dayjs(startTime).format("YYYY-MM-DD");
208
+ origin.start_date = dayjs(startTime).format("YYYY-MM-DD");
209
+ origin.start_time = dayjs(startTime).format("HH:mm");
210
+ origin.end_date = dayjs(endTime).format("YYYY-MM-DD");
211
+ origin.end_time = dayjs(endTime).format("HH:mm");
212
+ }
213
+ }
214
+ return origin;
215
+ };
216
+
217
+ /**
218
+ * 格式化套餐规格信息
219
+ * @param options 套餐规格信息
220
+ * @returns 格式化后的套餐规格信息
221
+ */
222
+ export var formatOptions = function formatOptions(options) {
223
+ if (!(options !== null && options !== void 0 && options.length)) return [];
224
+ return options.map(function (item) {
225
+ return {
226
+ id: item === null || item === void 0 ? void 0 : item.id,
227
+ name: item === null || item === void 0 ? void 0 : item.name,
228
+ num: item === null || item === void 0 ? void 0 : item.num,
229
+ price: item === null || item === void 0 ? void 0 : item.price,
230
+ total: item === null || item === void 0 ? void 0 : item.price,
231
+ origin_total: item === null || item === void 0 ? void 0 : item.original_price
232
+ };
233
+ });
234
+ };
235
+ export var formatOptionsToOrigin = function formatOptionsToOrigin(options) {
236
+ if (!(options !== null && options !== void 0 && options.length)) {
237
+ return [];
238
+ }
239
+ return options.map(function (d) {
240
+ return {
241
+ num: d.num,
242
+ option_group_item_id: d.product_option_item_id,
243
+ option_group_id: d.option_group_id
244
+ };
245
+ });
246
+ };
247
+
248
+ /**
249
+ * 格式化商品套餐信息
250
+ * @param bundle 商品套餐信息
251
+ * @returns 格式化后的商品套餐信息
252
+ */
253
+ export var formatBundle = function formatBundle(bundle) {
254
+ if (!(bundle !== null && bundle !== void 0 && bundle.length)) return [];
255
+ return bundle.map(function (item) {
256
+ return {
257
+ id: item === null || item === void 0 ? void 0 : item.id,
258
+ title: item === null || item === void 0 ? void 0 : item.title,
259
+ num: item === null || item === void 0 ? void 0 : item.num,
260
+ price: item === null || item === void 0 ? void 0 : item.price,
261
+ total: item === null || item === void 0 ? void 0 : item.price,
262
+ price_type: item === null || item === void 0 ? void 0 : item.price_type,
263
+ bundle_sum_price: item === null || item === void 0 ? void 0 : item.bundle_sum_price,
264
+ bundle_sum_type: item === null || item === void 0 ? void 0 : item.bundle_sum_type,
265
+ options: formatOptions(item === null || item === void 0 ? void 0 : item.option)
266
+ };
267
+ });
268
+ };
269
+ export var formatBundleToOrigin = function formatBundleToOrigin(bundle) {
270
+ if (!(bundle !== null && bundle !== void 0 && bundle.length)) return [];
271
+ return bundle.map(function (d) {
272
+ return {
273
+ bundle_group_id: d.group_id,
274
+ bundle_id: d.id,
275
+ bundle_product_id: (d === null || d === void 0 ? void 0 : d._bundle_product_id) || (d === null || d === void 0 ? void 0 : d.product_id),
276
+ bundle_variant_id: d.bundle_variant_id,
277
+ num: d.num,
278
+ extension_id: d.extension_id,
279
+ extension_type: d.extension_type,
280
+ option: formatOptionsToOrigin(d.option)
281
+ };
282
+ });
283
+ };
284
+
285
+ /**
286
+ * 判断是否是普通商品
287
+ * @param product 商品
288
+ * @returns 是否是普通商品
289
+ */
290
+ export var isNormalProduct = function isNormalProduct(product) {
291
+ return (product === null || product === void 0 ? void 0 : product.extension_type) !== "product_appointment";
292
+ };
293
+
294
+ /**
295
+ * 获取商品总价
296
+ * @param item 商品
297
+ * @returns 商品总价
298
+ */
299
+ export var getProductTotalPrice = function getProductTotalPrice(params) {
300
+ var product = params.product,
301
+ bundle = params.bundle,
302
+ options = params.options;
303
+ var price = Number(product.price);
304
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
305
+ price = bundle.reduce(function (accumulator, currentValue) {
306
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
307
+ }, price);
308
+ }
309
+
310
+ // 单规格
311
+ if (options !== null && options !== void 0 && options.length) {
312
+ price = options.reduce(function (accumulator, currentValue) {
313
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
314
+ }, price);
315
+ }
316
+ return price;
317
+ };
318
+
319
+ /**
320
+ * 获取商品原始总价
321
+ * @param item 商品
322
+ * @returns 商品原始总价
323
+ */
324
+ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(params) {
325
+ var product = params.product,
326
+ bundle = params.bundle,
327
+ options = params.options;
328
+ var price = Number(product.original_price);
329
+ if (isNaN(price) || price === 0) {
330
+ return undefined;
331
+ }
332
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
333
+ price = bundle.reduce(function (accumulator, currentValue) {
334
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
335
+ }, price);
336
+ }
337
+
338
+ // 单规格
339
+ if (options !== null && options !== void 0 && options.length) {
340
+ price = options.reduce(function (accumulator, currentValue) {
341
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
342
+ }, price);
343
+ }
344
+ return price;
345
+ };
@@ -1,17 +1,16 @@
1
- import { Module, PisellCore, ModuleOptions } from '../../types';
2
- import { BaseModule } from '../BaseModule';
3
- import { TimeSlot, DateModuleAPI } from './types';
1
+ import { Module, PisellCore, ModuleOptions } from "../../types";
2
+ import { BaseModule } from "../BaseModule";
3
+ import { DateModuleAPI, IGetAvailableTimeListParams, ITime } from "./types";
4
4
  export declare class DateModule extends BaseModule implements Module, DateModuleAPI {
5
5
  protected defaultName: string;
6
6
  protected defaultVersion: string;
7
- private state;
7
+ private store;
8
+ private request;
8
9
  constructor(name?: string, version?: string);
9
- initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
10
- setDate(date: Date): Promise<void>;
11
- setTimeSlot(timeSlot: TimeSlot): Promise<void>;
12
- getSelectedDate(): Date | null;
13
- getSelectedTimeSlot(): TimeSlot | null;
14
- getAvailableTimeSlots(): TimeSlot[];
15
- isDateAvailable(date: Date): boolean;
16
- isTimeSlotAvailable(timeSlot: TimeSlot): boolean;
10
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
11
+ setDateRange(dateRange: ITime[]): void;
12
+ getDateRange(): ITime[];
13
+ getMonthDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
14
+ getDateList(): Promise<ITime[]>;
15
+ getAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
17
16
  }
@@ -1,7 +1,5 @@
1
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
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 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; }
4
- 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; }
5
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); } }
6
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); }); }; }
7
5
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -17,8 +15,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
17
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; }
18
16
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
19
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 dayjs from "dayjs";
20
19
  import { BaseModule } from "../BaseModule";
21
- import { DateHooks } from "./types";
20
+ import { disableAllDates, generateMonthDates, handleAvailableDateByResource, handleAvailableDatesByRules } from "./utils";
22
21
  export var DateModule = /*#__PURE__*/function (_BaseModule) {
23
22
  _inherits(DateModule, _BaseModule);
24
23
  var _super = _createSuper(DateModule);
@@ -26,13 +25,10 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
26
25
  var _this;
27
26
  _classCallCheck(this, DateModule);
28
27
  _this = _super.call(this, name, version);
29
- _defineProperty(_assertThisInitialized(_this), "defaultName", 'date');
30
- _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
31
- _defineProperty(_assertThisInitialized(_this), "state", {
32
- selectedDate: null,
33
- selectedTimeSlot: null,
34
- availableTimeSlots: []
35
- });
28
+ _defineProperty(_assertThisInitialized(_this), "defaultName", "date");
29
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
30
+ _defineProperty(_assertThisInitialized(_this), "store", void 0);
31
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
36
32
  return _this;
37
33
  }
38
34
  _createClass(DateModule, [{
@@ -43,10 +39,9 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
43
39
  while (1) switch (_context.prev = _context.next) {
44
40
  case 0:
45
41
  this.core = core;
46
- if (options !== null && options !== void 0 && options.initialState) {
47
- this.state = _objectSpread(_objectSpread({}, this.state), options.initialState);
48
- }
49
- case 2:
42
+ this.store = options.store;
43
+ this.request = this.core.getPlugin("request");
44
+ case 3:
50
45
  case "end":
51
46
  return _context.stop();
52
47
  }
@@ -58,76 +53,125 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
58
53
  return initialize;
59
54
  }()
60
55
  }, {
61
- key: "setDate",
56
+ key: "setDateRange",
57
+ value: function setDateRange(dateRange) {
58
+ this.store.dateRange = dateRange;
59
+ }
60
+ }, {
61
+ key: "getDateRange",
62
+ value: function getDateRange() {
63
+ return this.store.dateRange;
64
+ }
65
+ }, {
66
+ key: "getMonthDates",
62
67
  value: function () {
63
- var _setDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(date) {
68
+ var _getMonthDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
69
+ var dates;
64
70
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
65
71
  while (1) switch (_context2.prev = _context2.next) {
66
72
  case 0:
67
- this.state.selectedDate = date;
68
- _context2.next = 3;
69
- return this.core.effects.emit(DateHooks.OnDateChange, date);
70
- case 3:
73
+ _context2.next = 2;
74
+ return this.getAvailableTimeList(params);
75
+ case 2:
76
+ dates = _context2.sent;
77
+ this.store.dateList = dates;
78
+ return _context2.abrupt("return", dates);
79
+ case 5:
71
80
  case "end":
72
81
  return _context2.stop();
73
82
  }
74
83
  }, _callee2, this);
75
84
  }));
76
- function setDate(_x3) {
77
- return _setDate.apply(this, arguments);
85
+ function getMonthDates(_x3) {
86
+ return _getMonthDates.apply(this, arguments);
78
87
  }
79
- return setDate;
88
+ return getMonthDates;
80
89
  }()
81
90
  }, {
82
- key: "setTimeSlot",
91
+ key: "getDateList",
83
92
  value: function () {
84
- var _setTimeSlot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(timeSlot) {
93
+ var _getDateList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
85
94
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
86
95
  while (1) switch (_context3.prev = _context3.next) {
87
96
  case 0:
88
- this.state.selectedTimeSlot = timeSlot;
89
- _context3.next = 3;
90
- return this.core.effects.emit(DateHooks.OnTimeSlotChange, timeSlot);
91
- case 3:
97
+ return _context3.abrupt("return", this.store.dateList);
98
+ case 1:
92
99
  case "end":
93
100
  return _context3.stop();
94
101
  }
95
102
  }, _callee3, this);
96
103
  }));
97
- function setTimeSlot(_x4) {
98
- return _setTimeSlot.apply(this, arguments);
104
+ function getDateList() {
105
+ return _getDateList.apply(this, arguments);
99
106
  }
100
- return setTimeSlot;
107
+ return getDateList;
101
108
  }()
102
109
  }, {
103
- key: "getSelectedDate",
104
- value: function getSelectedDate() {
105
- return this.state.selectedDate;
106
- }
107
- }, {
108
- key: "getSelectedTimeSlot",
109
- value: function getSelectedTimeSlot() {
110
- return this.state.selectedTimeSlot;
111
- }
112
- }, {
113
- key: "getAvailableTimeSlots",
114
- value: function getAvailableTimeSlots() {
115
- return this.state.availableTimeSlots;
116
- }
117
- }, {
118
- key: "isDateAvailable",
119
- value: function isDateAvailable(date) {
120
- return this.state.availableTimeSlots.some(function (slot) {
121
- return slot.start.getDate() === date.getDate() && slot.start.getMonth() === date.getMonth() && slot.start.getFullYear() === date.getFullYear() && slot.isAvailable;
122
- });
123
- }
124
- }, {
125
- key: "isTimeSlotAvailable",
126
- value: function isTimeSlotAvailable(timeSlot) {
127
- return this.state.availableTimeSlots.some(function (slot) {
128
- return slot.start.getTime() === timeSlot.start.getTime() && slot.end.getTime() === timeSlot.end.getTime() && slot.isAvailable;
129
- });
130
- }
110
+ key: "getAvailableTimeList",
111
+ value: function () {
112
+ var _getAvailableTimeList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
113
+ var url, query, rules, fetchUrl, _ref, start_date, end_date, resource_ids, dates, _res$data, res;
114
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
115
+ while (1) switch (_context4.prev = _context4.next) {
116
+ case 0:
117
+ url = params.url, query = params.query, rules = params.rules;
118
+ fetchUrl = url || "/schedule/resource/list";
119
+ _ref = query || {}, start_date = _ref.start_date, end_date = _ref.end_date, resource_ids = _ref.resource_ids;
120
+ if (!(!start_date || !end_date)) {
121
+ _context4.next = 5;
122
+ break;
123
+ }
124
+ return _context4.abrupt("return", []);
125
+ case 5:
126
+ // 1.生成当前月份的所有日期,默认都是可用的
127
+ dates = generateMonthDates(start_date, end_date); // 如果没有资源或者结束日期在今天之前,则所有日期均不可用
128
+ if (!(!(resource_ids !== null && resource_ids !== void 0 && resource_ids.length) || dayjs(end_date).isBefore(dayjs()))) {
129
+ _context4.next = 8;
130
+ break;
131
+ }
132
+ return _context4.abrupt("return", disableAllDates(dates));
133
+ case 8:
134
+ _context4.prev = 8;
135
+ _context4.next = 11;
136
+ return this.request.get(fetchUrl, {
137
+ start_date: start_date,
138
+ end_date: end_date,
139
+ resource_ids: resource_ids
140
+ }, {
141
+ useCache: true
142
+ });
143
+ case 11:
144
+ res = _context4.sent;
145
+ if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.length) {
146
+ _context4.next = 14;
147
+ break;
148
+ }
149
+ return _context4.abrupt("return", disableAllDates(dates));
150
+ case 14:
151
+ // 2.根据资源times判定哪些日期内存在可用资源
152
+ dates = handleAvailableDateByResource(res.data, dates);
153
+
154
+ // 3.根据提前量和当前日期判定哪些日期可用
155
+ if (rules !== null && rules !== void 0 && rules.length) {
156
+ dates = handleAvailableDatesByRules(dates, rules);
157
+ }
158
+ return _context4.abrupt("return", dates);
159
+ case 19:
160
+ _context4.prev = 19;
161
+ _context4.t0 = _context4["catch"](8);
162
+ console.log("getAvailableTimeList_error", _context4.t0);
163
+ return _context4.abrupt("return", disableAllDates(dates));
164
+ case 23:
165
+ case "end":
166
+ return _context4.stop();
167
+ }
168
+ }, _callee4, this, [[8, 19]]);
169
+ }));
170
+ function getAvailableTimeList(_x4) {
171
+ return _getAvailableTimeList.apply(this, arguments);
172
+ }
173
+ return getAvailableTimeList;
174
+ }()
131
175
  }]);
132
176
  return DateModule;
133
177
  }(BaseModule);