@pisell/pisellos 3.0.5 → 3.0.6

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 (146) hide show
  1. package/dist/modules/Account/index.d.ts +2 -6
  2. package/dist/modules/Account/index.js +21 -103
  3. package/dist/modules/Account/types.d.ts +12 -1
  4. package/dist/modules/AccountList/index.d.ts +20 -1
  5. package/dist/modules/AccountList/index.js +243 -75
  6. package/dist/modules/AccountList/types.d.ts +33 -1
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/AccountList/utils.d.ts +9 -0
  9. package/dist/modules/AccountList/utils.js +25 -0
  10. package/dist/modules/BaseModule.d.ts +2 -2
  11. package/dist/modules/BaseModule.js +1 -1
  12. package/dist/modules/Cart/index.d.ts +8 -5
  13. package/dist/modules/Cart/index.js +101 -25
  14. package/dist/modules/Cart/types.d.ts +82 -5
  15. package/dist/modules/Cart/types.js +22 -0
  16. package/dist/modules/Cart/utils.d.ts +106 -13
  17. package/dist/modules/Cart/utils.js +289 -76
  18. package/dist/modules/Date/index.d.ts +6 -6
  19. package/dist/modules/Date/index.js +41 -58
  20. package/dist/modules/Date/types.d.ts +22 -6
  21. package/dist/modules/Date/utils.d.ts +4 -3
  22. package/dist/modules/Date/utils.js +81 -30
  23. package/dist/modules/Discount/index.d.ts +4 -4
  24. package/dist/modules/Discount/index.js +11 -11
  25. package/dist/modules/Order/index.d.ts +11 -5
  26. package/dist/modules/Order/index.js +47 -18
  27. package/dist/modules/Order/types.d.ts +10 -3
  28. package/dist/modules/Order/utils.d.ts +10 -0
  29. package/dist/modules/Order/utils.js +15 -0
  30. package/dist/modules/Product/index.d.ts +14 -1
  31. package/dist/modules/Product/index.js +35 -0
  32. package/dist/modules/Product/types.d.ts +27 -3
  33. package/dist/modules/ProductList/index.js +11 -5
  34. package/dist/modules/Resource/types.d.ts +1 -0
  35. package/dist/modules/Resource/utils.js +1 -1
  36. package/dist/modules/Rules/index.d.ts +3 -3
  37. package/dist/modules/Rules/index.js +121 -53
  38. package/dist/modules/Rules/types.d.ts +5 -1
  39. package/dist/modules/Schedule/index.d.ts +18 -0
  40. package/dist/modules/Schedule/index.js +111 -0
  41. package/dist/modules/Schedule/type.d.ts +157 -0
  42. package/dist/modules/Schedule/type.js +1 -0
  43. package/dist/modules/Schedule/types.d.ts +182 -0
  44. package/dist/modules/Schedule/types.js +1 -0
  45. package/dist/modules/Schedule/utils.d.ts +67 -0
  46. package/dist/modules/Schedule/utils.js +729 -0
  47. package/dist/modules/Step/index.d.ts +14 -3
  48. package/dist/modules/Step/index.js +54 -2
  49. package/dist/modules/Summary/index.d.ts +12 -5
  50. package/dist/modules/Summary/index.js +33 -7
  51. package/dist/modules/Summary/types.d.ts +23 -2
  52. package/dist/modules/Summary/utils.d.ts +14 -4
  53. package/dist/modules/Summary/utils.js +46 -4
  54. package/dist/modules/index.d.ts +10 -0
  55. package/dist/modules/index.js +11 -1
  56. package/dist/plugins/index.d.ts +3 -3
  57. package/dist/plugins/request.d.ts +3 -3
  58. package/dist/plugins/request.js +30 -30
  59. package/dist/plugins/shopStore.d.ts +1 -1
  60. package/dist/solution/BookingByStep/index.d.ts +97 -24
  61. package/dist/solution/BookingByStep/index.js +1024 -322
  62. package/dist/solution/BookingByStep/types.d.ts +3 -10
  63. package/dist/solution/BookingByStep/types.js +11 -15
  64. package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
  65. package/dist/solution/BookingByStep/utils/products.js +3 -0
  66. package/dist/solution/BookingByStep/utils/resources.d.ts +60 -6
  67. package/dist/solution/BookingByStep/utils/resources.js +293 -52
  68. package/dist/solution/ShopDiscount/index.d.ts +4 -4
  69. package/dist/solution/ShopDiscount/index.js +16 -16
  70. package/dist/solution/ShopDiscount/types.d.ts +2 -2
  71. package/dist/solution/ShopDiscount/utils.js +1 -1
  72. package/lib/core/index.js +7 -2
  73. package/lib/modules/Account/index.d.ts +2 -6
  74. package/lib/modules/Account/index.js +15 -30
  75. package/lib/modules/Account/types.d.ts +12 -1
  76. package/lib/modules/AccountList/index.d.ts +20 -1
  77. package/lib/modules/AccountList/index.js +122 -13
  78. package/lib/modules/AccountList/types.d.ts +33 -1
  79. package/lib/modules/AccountList/utils.d.ts +9 -0
  80. package/lib/modules/AccountList/utils.js +39 -0
  81. package/lib/modules/BaseModule.d.ts +2 -2
  82. package/lib/modules/BaseModule.js +14 -3
  83. package/lib/modules/Cart/index.d.ts +8 -5
  84. package/lib/modules/Cart/index.js +81 -8
  85. package/lib/modules/Cart/types.d.ts +82 -5
  86. package/lib/modules/Cart/types.js +20 -2
  87. package/lib/modules/Cart/utils.d.ts +106 -13
  88. package/lib/modules/Cart/utils.js +188 -45
  89. package/lib/modules/Date/index.d.ts +6 -6
  90. package/lib/modules/Date/index.js +13 -28
  91. package/lib/modules/Date/types.d.ts +22 -6
  92. package/lib/modules/Date/utils.d.ts +4 -3
  93. package/lib/modules/Date/utils.js +47 -13
  94. package/lib/modules/Discount/index.d.ts +4 -4
  95. package/lib/modules/Discount/index.js +9 -2
  96. package/lib/modules/Guests/index.js +4 -1
  97. package/lib/modules/Order/index.d.ts +11 -5
  98. package/lib/modules/Order/index.js +24 -3
  99. package/lib/modules/Order/types.d.ts +10 -3
  100. package/lib/modules/Order/utils.d.ts +10 -0
  101. package/lib/modules/Order/utils.js +45 -0
  102. package/lib/modules/Payment/index.js +1 -6
  103. package/lib/modules/Product/index.d.ts +14 -1
  104. package/lib/modules/Product/index.js +19 -0
  105. package/lib/modules/Product/types.d.ts +27 -3
  106. package/lib/modules/ProductList/index.js +21 -7
  107. package/lib/modules/Resource/index.js +4 -1
  108. package/lib/modules/Resource/types.d.ts +1 -0
  109. package/lib/modules/Resource/utils.js +7 -4
  110. package/lib/modules/Rules/index.d.ts +3 -3
  111. package/lib/modules/Rules/index.js +118 -43
  112. package/lib/modules/Rules/types.d.ts +5 -1
  113. package/lib/modules/Schedule/index.d.ts +18 -0
  114. package/lib/modules/Schedule/index.js +81 -0
  115. package/lib/modules/Schedule/type.d.ts +157 -0
  116. package/lib/modules/Schedule/type.js +17 -0
  117. package/lib/modules/Schedule/types.d.ts +182 -0
  118. package/lib/modules/Schedule/types.js +17 -0
  119. package/lib/modules/Schedule/utils.d.ts +67 -0
  120. package/lib/modules/Schedule/utils.js +600 -0
  121. package/lib/modules/Step/index.d.ts +14 -3
  122. package/lib/modules/Step/index.js +38 -1
  123. package/lib/modules/Summary/index.d.ts +12 -5
  124. package/lib/modules/Summary/index.js +15 -1
  125. package/lib/modules/Summary/types.d.ts +23 -2
  126. package/lib/modules/Summary/utils.d.ts +14 -4
  127. package/lib/modules/Summary/utils.js +30 -1
  128. package/lib/modules/index.d.ts +10 -0
  129. package/lib/modules/index.js +21 -1
  130. package/lib/plugins/index.d.ts +3 -3
  131. package/lib/plugins/request.d.ts +3 -3
  132. package/lib/plugins/request.js +48 -11
  133. package/lib/plugins/shopStore.d.ts +1 -1
  134. package/lib/solution/BookingByStep/index.d.ts +97 -24
  135. package/lib/solution/BookingByStep/index.js +693 -145
  136. package/lib/solution/BookingByStep/types.d.ts +3 -10
  137. package/lib/solution/BookingByStep/types.js +37 -14
  138. package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
  139. package/lib/solution/BookingByStep/utils/products.js +3 -0
  140. package/lib/solution/BookingByStep/utils/resources.d.ts +60 -6
  141. package/lib/solution/BookingByStep/utils/resources.js +286 -54
  142. package/lib/solution/BuyTickets/index.js +34 -20
  143. package/lib/solution/ShopDiscount/index.d.ts +4 -4
  144. package/lib/solution/ShopDiscount/index.js +10 -2
  145. package/lib/solution/ShopDiscount/types.d.ts +2 -2
  146. package/package.json +4 -2
@@ -1,17 +1,25 @@
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
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ 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."); }
4
+ 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); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ 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; }
2
8
  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
9
  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
10
  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
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
12
  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";
13
+ import dayjs from 'dayjs';
14
+ import Decimal from 'decimal.js';
15
+
8
16
  /**
9
17
  * 生成一个唯一的 ID
10
18
  */
11
19
  export var getUniqueId = function getUniqueId() {
12
- var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
20
+ var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
13
21
  var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 11;
14
- return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
22
+ return prefix + (Math.random() + '').replace(/\D/g, '').substring(0, maxLength);
15
23
  };
16
24
 
17
25
  /**
@@ -24,7 +32,7 @@ export var createCartItemOrigin = function createCartItemOrigin() {
24
32
  // 数量 固定为1
25
33
  number: 1,
26
34
  // 客户端报名所有活动;
27
- registration_type: "all",
35
+ registration_type: 'all',
28
36
  // 暂时不用
29
37
  relation_products: [],
30
38
  // 固定
@@ -37,9 +45,9 @@ export var createCartItemOrigin = function createCartItemOrigin() {
37
45
  duration: null,
38
46
  // 资源相关
39
47
  // 资源状态 -固定
40
- like_status: "common",
41
- // 资源类型
42
- relation_type: "",
48
+ like_status: 'common',
49
+ // 资源类型 - 固定--谭景琳备注:马天宇说现在平行资源是不传这个的
50
+ // relation_type: "form",
43
51
  // 所选资源
44
52
  resources: null,
45
53
  // 日程id - 固定
@@ -55,10 +63,9 @@ export var createCartItemOrigin = function createCartItemOrigin() {
55
63
  // 所选结束时间
56
64
  end_date: null,
57
65
  // 额外信息
58
- metadata: {}
59
-
66
+ metadata: {},
60
67
  // holder相关
61
- // holder: null,
68
+ holder: null
62
69
  };
63
70
  };
64
71
 
@@ -68,27 +75,31 @@ export var createCartItemOrigin = function createCartItemOrigin() {
68
75
  * @returns 格式化后的商品
69
76
  */
70
77
  export var formatProductToCartItem = function formatProductToCartItem(params) {
78
+ var _product$custom_depos;
71
79
  var cartItem = params.cartItem,
72
80
  product = params.product,
73
81
  bundle = params.bundle,
74
82
  options = params.options;
83
+ var num = 1; // 当前按照单个商品加入购物车
75
84
  if (product) {
76
85
  cartItem.id = product === null || product === void 0 ? void 0 : product.id;
77
86
  cartItem.name = product === null || product === void 0 ? void 0 : product.title;
78
87
  cartItem.price = product === null || product === void 0 ? void 0 : product.price;
88
+ cartItem.num = num;
79
89
  cartItem.total = getProductTotalPrice({
80
90
  product: product,
81
91
  bundle: bundle,
82
- options: options
92
+ options: options,
93
+ num: num
83
94
  });
84
95
  cartItem.origin_total = getProductOriginTotalPrice({
85
96
  product: product,
86
97
  bundle: bundle,
87
- options: options
98
+ options: options,
99
+ num: num
88
100
  });
89
- cartItem.num = 1;
90
101
  cartItem.image = product === null || product === void 0 ? void 0 : product.cover;
91
- cartItem.like_status = "common";
102
+ cartItem.like_status = 'common';
92
103
  cartItem.duration = product === null || product === void 0 ? void 0 : product.duration;
93
104
  cartItem.isNormalProduct = isNormalProduct(product);
94
105
  cartItem.is_charge_tax = product === null || product === void 0 ? void 0 : product.is_charge_tax;
@@ -99,6 +110,17 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
99
110
  if (options !== null && options !== void 0 && options.length) {
100
111
  cartItem.options = formatOptions(options);
101
112
  }
113
+
114
+ // 如果商品有定金规则,则计算定金
115
+ if ((product === null || product === void 0 || (_product$custom_depos = product.custom_deposit_data) === null || _product$custom_depos === void 0 ? void 0 : _product$custom_depos.has_deposit) == 1) {
116
+ cartItem.deposit = getProductDeposit({
117
+ cartItem: cartItem,
118
+ product: product,
119
+ bundle: bundle,
120
+ options: options,
121
+ num: num
122
+ });
123
+ }
102
124
  var oringin = formatProductToCartItemOrigin(params);
103
125
  cartItem._origin = oringin;
104
126
  return cartItem;
@@ -183,7 +205,19 @@ export var formatAccountToCartItemOrigin = function formatAccountToCartItemOrigi
183
205
  account = params.account;
184
206
  var origin = cartItem._origin;
185
207
  if (account) {
186
- origin.metadata.account = account;
208
+ if ((account === null || account === void 0 ? void 0 : account.type) === 'holder') {
209
+ var _ref = (account === null || account === void 0 ? void 0 : account._origin) || {},
210
+ customer_id = _ref.customer_id,
211
+ form_id = _ref.form_id,
212
+ form_record_id = _ref.form_record_id;
213
+ origin.holder = {
214
+ customer_id: customer_id,
215
+ form_id: form_id,
216
+ form_record: form_record_id ? [form_record_id] : null
217
+ };
218
+ } else {
219
+ origin.metadata.account = account;
220
+ }
187
221
  }
188
222
  return origin;
189
223
  };
@@ -201,10 +235,10 @@ export var formatResourceToCartItem = function formatResourceToCartItem(params)
201
235
  cartItem.resource_id = firstResource === null || firstResource === void 0 ? void 0 : firstResource.id;
202
236
  cartItem.relation_form_name = firstResource === null || firstResource === void 0 ? void 0 : firstResource.main_field;
203
237
  if (firstResource.startTime && firstResource.endTime) {
204
- cartItem.start_date = dayjs(firstResource.startTime).format("YYYY-MM-DD");
205
- cartItem.start_time = dayjs(firstResource.startTime).format("HH:mm");
206
- cartItem.end_date = dayjs(firstResource.endTime).format("YYYY-MM-DD");
207
- cartItem.end_time = dayjs(firstResource.endTime).format("HH:mm");
238
+ cartItem.start_date = dayjs(firstResource.startTime).format('YYYY-MM-DD');
239
+ cartItem.start_time = dayjs(firstResource.startTime).format('HH:mm');
240
+ cartItem.end_date = dayjs(firstResource.endTime).format('YYYY-MM-DD');
241
+ cartItem.end_time = dayjs(firstResource.endTime).format('HH:mm');
208
242
  }
209
243
  } else {
210
244
  cartItem.resource_id = undefined;
@@ -226,27 +260,40 @@ export var formatResourceToCartItemOrigin = function formatResourceToCartItemOri
226
260
  if (resources && resources !== null && resources !== void 0 && resources.length) {
227
261
  origin.resources = [];
228
262
  // 接口只需要部分字段,需要处理
229
- resources.forEach(function (resource) {
230
- origin.resources.push({
231
- relation_type: "form",
232
- like_status: "common",
233
- id: resource.id,
234
- main_field: resource.main_field,
235
- resourceType: resource.resourceType,
236
- form_id: resource.form_id,
237
- relation_id: resource.id,
238
- capacity: (resource === null || resource === void 0 ? void 0 : resource.capacity) || 0
263
+ var checkResourcesFormat = function checkResourcesFormat(resources, arr) {
264
+ resources.forEach(function (resource) {
265
+ var _resource$children;
266
+ var childArr = [];
267
+ if (resource !== null && resource !== void 0 && (_resource$children = resource.children) !== null && _resource$children !== void 0 && _resource$children.length) {
268
+ checkResourcesFormat(resource.children, childArr);
269
+ }
270
+ var obj = {
271
+ relation_type: 'form',
272
+ like_status: 'common',
273
+ id: resource.id,
274
+ main_field: resource.main_field,
275
+ resourceType: resource.resourceType,
276
+ form_id: resource.form_id,
277
+ relation_id: resource.id,
278
+ capacity: (resource === null || resource === void 0 ? void 0 : resource.capacity) || 0,
279
+ metadata: (resource === null || resource === void 0 ? void 0 : resource.metadata) || {} // 后端可以在这里挂一个前端用于计算的数据
280
+ };
281
+ if (childArr.length) {
282
+ obj.children = childArr;
283
+ }
284
+ arr.push(obj);
239
285
  });
240
- });
286
+ };
287
+ checkResourcesFormat(resources, origin.resources);
241
288
  var _resources$ = resources[0],
242
289
  startTime = _resources$.startTime,
243
290
  endTime = _resources$.endTime;
244
291
  if (startTime && endTime) {
245
- origin.select_date = dayjs(startTime).format("YYYY-MM-DD");
246
- origin.start_date = dayjs(startTime).format("YYYY-MM-DD");
247
- origin.start_time = dayjs(startTime).format("HH:mm");
248
- origin.end_date = dayjs(endTime).format("YYYY-MM-DD");
249
- origin.end_time = dayjs(endTime).format("HH:mm");
292
+ origin.select_date = dayjs(startTime).format('YYYY-MM-DD');
293
+ origin.start_date = dayjs(startTime).format('YYYY-MM-DD');
294
+ origin.start_time = dayjs(startTime).format('HH:mm');
295
+ origin.end_date = dayjs(endTime).format('YYYY-MM-DD');
296
+ origin.end_time = dayjs(endTime).format('HH:mm');
250
297
  }
251
298
  } else if ((resources === null || resources === void 0 ? void 0 : resources.length) === 0) {
252
299
  origin.resources = [];
@@ -260,53 +307,58 @@ export var formatResourceToCartItemOrigin = function formatResourceToCartItemOri
260
307
  };
261
308
 
262
309
  /**
263
- * 从购物车中删除资源相关信息
264
- * @param cartItem 购物车
265
- * @returns 删除后的购物车
310
+ * 格式化关联表单到购物车
311
+ * @param params 参数
312
+ * @returns 格式化后的购物车
266
313
  */
267
- export var deleteResourceFromCartItem = function deleteResourceFromCartItem(cartItem) {
268
- // 删除UI层的数据
269
- cartItem.resource_id = undefined;
270
- cartItem.relation_form_name = undefined;
271
- cartItem.start_date = undefined;
272
- cartItem.start_time = undefined;
273
- cartItem.end_date = undefined;
274
- cartItem.end_time = undefined;
275
-
276
- // 删除资源原始数据
277
- delete cartItem._resourceOrigin;
278
-
279
- // 删除原始数据
280
- cartItem._origin.resources = null;
281
- cartItem._origin.select_date = null;
282
- cartItem._origin.start_date = null;
283
- cartItem._origin.start_time = null;
284
- cartItem._origin.end_date = null;
285
- cartItem._origin.end_time = null;
314
+ export var formatRelationFormsToCartItem = function formatRelationFormsToCartItem(params) {
315
+ var cartItem = params.cartItem;
316
+ var oringin = formatRelationFormsToCartItemOrigin(params);
317
+ cartItem._origin = oringin;
286
318
  return cartItem;
287
319
  };
320
+ export var formatRelationFormsToCartItemOrigin = function formatRelationFormsToCartItemOrigin(params) {
321
+ var cartItem = params.cartItem,
322
+ relationForms = params.relationForms;
323
+ var origin = cartItem._origin;
324
+ origin.relation_forms = relationForms;
325
+ return origin;
326
+ };
288
327
 
289
328
  /**
290
- * 从购物车中删除时间
291
- * @param cartItem 购物车
292
- * @returns 删除后的购物车
329
+ * 格式化日期到购物车
330
+ * @param date 开始时间和结束时间
331
+ * @returns 格式化后的日期
293
332
  */
294
- export var deleteTimeFromCartItem = function deleteTimeFromCartItem(cartItem) {
295
- // 删除UI层的数据
296
- cartItem.start_date = undefined;
297
- cartItem.start_time = undefined;
298
- cartItem.end_date = undefined;
299
- cartItem.end_time = undefined;
300
-
301
- // 删除原始数据
302
- cartItem._origin.select_date = null;
303
- cartItem._origin.start_date = null;
304
- cartItem._origin.start_time = null;
305
- cartItem._origin.end_date = null;
306
- cartItem._origin.end_time = null;
333
+ export var formatDateToCartItem = function formatDateToCartItem(params) {
334
+ var cartItem = params.cartItem,
335
+ date = params.date;
336
+ cartItem.start_date = dayjs(date.startTime).format('YYYY-MM-DD');
337
+ cartItem.start_time = dayjs(date.startTime).format('HH:mm');
338
+ cartItem.end_date = dayjs(date.endTime).format('YYYY-MM-DD');
339
+ cartItem.end_time = dayjs(date.endTime).format('HH:mm');
340
+ var oringin = formatDateToCartItemOrigin(params);
341
+ cartItem._origin = oringin;
307
342
  return cartItem;
308
343
  };
309
344
 
345
+ /**
346
+ * 格式化日期到购物车原始数据
347
+ * @param date 开始时间和结束时间
348
+ * @returns 格式化后的日期原始数据
349
+ */
350
+ export var formatDateToCartItemOrigin = function formatDateToCartItemOrigin(params) {
351
+ var cartItem = params.cartItem,
352
+ date = params.date;
353
+ var origin = cartItem._origin;
354
+ origin.select_date = dayjs(date.startTime).format('YYYY-MM-DD');
355
+ origin.start_date = dayjs(date.startTime).format('YYYY-MM-DD');
356
+ origin.start_time = dayjs(date.startTime).format('HH:mm');
357
+ origin.end_date = dayjs(date.endTime).format('YYYY-MM-DD');
358
+ origin.end_time = dayjs(date.endTime).format('HH:mm');
359
+ return origin;
360
+ };
361
+
310
362
  /**
311
363
  * 格式化备注到购物车
312
364
  * @param params 参数
@@ -411,11 +463,12 @@ export var formatBundleToOrigin = function formatBundleToOrigin(bundle) {
411
463
  * @returns 是否是普通商品
412
464
  */
413
465
  export var isNormalProduct = function isNormalProduct(product) {
414
- return (product === null || product === void 0 ? void 0 : product.extension_type) !== "product_appointment";
466
+ return (product === null || product === void 0 ? void 0 : product.extension_type) !== 'product_appointment';
415
467
  };
416
468
 
417
469
  /**
418
470
  * 获取商品总价
471
+ * @description 当前总价计算基于商品数量为1
419
472
  * @param item 商品
420
473
  * @returns 商品总价
421
474
  */
@@ -423,6 +476,7 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
423
476
  var product = params.product,
424
477
  bundle = params.bundle,
425
478
  options = params.options;
479
+ var num = params.num || 1;
426
480
  var price = Number(product.price);
427
481
  if (bundle !== null && bundle !== void 0 && bundle.length) {
428
482
  price = bundle.reduce(function (accumulator, currentValue) {
@@ -436,11 +490,12 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
436
490
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
437
491
  }, price);
438
492
  }
439
- return price;
493
+ return price * num;
440
494
  };
441
495
 
442
496
  /**
443
497
  * 获取商品原始总价
498
+ * @description 当前总价计算基于商品数量为1
444
499
  * @param item 商品
445
500
  * @returns 商品原始总价
446
501
  */
@@ -448,6 +503,7 @@ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(para
448
503
  var product = params.product,
449
504
  bundle = params.bundle,
450
505
  options = params.options;
506
+ var num = (params === null || params === void 0 ? void 0 : params.num) || 1;
451
507
  var price = Number(product.original_price);
452
508
  if (isNaN(price) || price === 0) {
453
509
  return undefined;
@@ -464,5 +520,162 @@ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(para
464
520
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
465
521
  }, price);
466
522
  }
467
- return price;
523
+ return price * num;
524
+ };
525
+
526
+ /**
527
+ * 获取商品定金
528
+ * @description 定金基于商品售价来算,最终乘商品数量
529
+ * 1、如果套餐主商品有定金规则,则定金为:(套餐商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
530
+ * 2、如果套餐主商品没有定金规则,子商品有定金规则,则定金为:(套餐子商品售价 * 套餐子商品定金百分比 + 套餐子商品定金固定金额)* 商品数量,最终将所有子商品定金相加
531
+ * 3、普通商品/单规格商品/组合规则商品,定金规则:(商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
532
+ * @param params 参数
533
+ * @returns 商品定金
534
+ */
535
+ export var getProductDeposit = function getProductDeposit(params) {
536
+ var _product$custom_depos2;
537
+ var cartItem = params.cartItem,
538
+ product = params.product,
539
+ bundle = params.bundle,
540
+ options = params.options;
541
+ var num = (params === null || params === void 0 ? void 0 : params.num) || 1;
542
+
543
+ // 判定商品是否有定金规则
544
+ if ((product === null || product === void 0 || (_product$custom_depos2 = product.custom_deposit_data) === null || _product$custom_depos2 === void 0 ? void 0 : _product$custom_depos2.has_deposit) == 1) {
545
+ var protocols = [];
546
+ var total = new Decimal(0);
547
+ var _ref2 = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
548
+ deposit_fixed = _ref2.deposit_fixed,
549
+ deposit_percentage = _ref2.deposit_percentage,
550
+ deposit_policy_data = _ref2.deposit_policy_data;
551
+ // 协议数据
552
+ protocols.push.apply(protocols, _toConsumableArray(deposit_policy_data || []));
553
+ // 判断主商品是否有定金规则
554
+ if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
555
+ var _handleProductDeposit = handleProductDeposit({
556
+ depositData: product === null || product === void 0 ? void 0 : product.custom_deposit_data,
557
+ total: cartItem.total || 0,
558
+ num: num
559
+ }),
560
+ depositTotal = _handleProductDeposit.depositTotal,
561
+ result = _handleProductDeposit.result;
562
+ if (result) {
563
+ total = depositTotal;
564
+ }
565
+ } else {
566
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
567
+ total = bundle.reduce(function (accumulator, currentBundleProduct) {
568
+ var _handleProductDeposit2 = handleProductDeposit({
569
+ depositData: currentBundleProduct === null || currentBundleProduct === void 0 ? void 0 : currentBundleProduct.custom_deposit_data,
570
+ total: currentBundleProduct.price,
571
+ num: currentBundleProduct.num
572
+ }),
573
+ depositTotal = _handleProductDeposit2.depositTotal,
574
+ result = _handleProductDeposit2.result;
575
+ if (result) {
576
+ return accumulator.plus(depositTotal);
577
+ }
578
+ return accumulator;
579
+ }, new Decimal(0));
580
+ }
581
+ }
582
+ return {
583
+ total: total.toNumber(),
584
+ protocols: protocols
585
+ };
586
+ }
587
+ return null;
588
+ };
589
+
590
+ /**
591
+ * 计算商品定金
592
+ * @param params 参数
593
+ * @returns 商品定金
594
+ */
595
+ export var handleProductDeposit = function handleProductDeposit(params) {
596
+ var depositData = params.depositData,
597
+ total = params.total,
598
+ num = params.num;
599
+ if (!depositData) {
600
+ return {
601
+ result: false,
602
+ depositTotal: new Decimal(0)
603
+ };
604
+ }
605
+ var _ref3 = depositData || {},
606
+ deposit_fixed = _ref3.deposit_fixed,
607
+ deposit_percentage = _ref3.deposit_percentage;
608
+ if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
609
+ var depositFixed = Decimal(deposit_fixed || 0);
610
+ var depositPercent = Decimal(deposit_percentage || 0);
611
+ var productTotalPrice = Decimal(total || 0);
612
+ var deposit = depositFixed.plus(depositPercent.times(productTotalPrice));
613
+ return {
614
+ depositTotal: deposit.times(num),
615
+ result: true
616
+ };
617
+ }
618
+ return {
619
+ result: false,
620
+ depositTotal: new Decimal(0)
621
+ };
622
+ };
623
+
624
+ /**
625
+ * 从购物车中删除资源相关信息
626
+ * @param cartItem 购物车
627
+ * @returns 删除后的购物车
628
+ */
629
+ export var deleteResourceFromCartItem = function deleteResourceFromCartItem(cartItem) {
630
+ // 删除UI层的数据
631
+ cartItem.resource_id = undefined;
632
+ cartItem.relation_form_name = undefined;
633
+
634
+ // 删除资源原始数据
635
+ delete cartItem._resourceOrigin;
636
+
637
+ // 删除原始数据
638
+ cartItem._origin.resources = null;
639
+ return cartItem;
640
+ };
641
+
642
+ /**
643
+ * 从购物车中删除时间
644
+ * @param cartItem 购物车
645
+ * @returns 删除后的购物车
646
+ */
647
+ export var deleteTimeFromCartItem = function deleteTimeFromCartItem(cartItem) {
648
+ // 删除UI层的数据
649
+ cartItem.start_date = undefined;
650
+ cartItem.start_time = undefined;
651
+ cartItem.end_date = undefined;
652
+ cartItem.end_time = undefined;
653
+
654
+ // 删除原始数据
655
+ cartItem._origin.select_date = null;
656
+ cartItem._origin.start_date = null;
657
+ cartItem._origin.start_time = null;
658
+ cartItem._origin.end_date = null;
659
+ cartItem._origin.end_time = null;
660
+ return cartItem;
661
+ };
662
+
663
+ /**
664
+ * 从购物车中删除关联表单信息
665
+ * @param cartItem 购物车
666
+ * @returns 删除后的购物车
667
+ */
668
+ export var deleteRelationFormsFromCartItem = function deleteRelationFormsFromCartItem(cartItem) {
669
+ // 删除原始数据
670
+ cartItem._origin.relation_forms = null;
671
+ return cartItem;
672
+ };
673
+ export var deleteHolderFromCartItem = function deleteHolderFromCartItem(cartItem) {
674
+ // 删除UI层的数据
675
+ cartItem.holder_id = undefined;
676
+ cartItem.holder_title = undefined;
677
+
678
+ // 删除原始数据
679
+ cartItem._origin.holder = null;
680
+ return cartItem;
468
681
  };
@@ -1,6 +1,6 @@
1
- import { Module, PisellCore, ModuleOptions } from "../../types";
2
- import { BaseModule } from "../BaseModule";
3
- import { DateModuleAPI, IGetAvailableTimeListParams, ITime } 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;
@@ -13,9 +13,9 @@ export declare class DateModule extends BaseModule implements Module, DateModule
13
13
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
14
14
  setDateRange(dateRange: ITime[]): void;
15
15
  getDateRange(): ITime[];
16
- getMonthDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
17
- getDateList(): Promise<ITime[]>;
18
- getAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
16
+ getResourceDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
17
+ getDateList(): ITime[];
18
+ getResourceAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
19
19
  clearDateRange(): void;
20
20
  storeChange(): void;
21
21
  }