@pisell/pisellos 3.0.34 → 3.0.36

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 (55) hide show
  1. package/dist/modules/Cart/index.js +20 -34
  2. package/dist/modules/Cart/utils/cartAccount.d.ts +21 -0
  3. package/dist/modules/Cart/utils/cartAccount.js +52 -0
  4. package/dist/modules/Cart/utils/cartDate.d.ts +31 -0
  5. package/dist/modules/Cart/utils/cartDate.js +55 -0
  6. package/dist/modules/Cart/utils/cartDiscount.d.ts +19 -0
  7. package/dist/modules/Cart/utils/cartDiscount.js +35 -0
  8. package/dist/modules/Cart/utils/cartNote.d.ts +19 -0
  9. package/dist/modules/Cart/utils/cartNote.js +29 -0
  10. package/dist/modules/Cart/utils/cartProduct.d.ts +107 -0
  11. package/dist/modules/Cart/{utils.js → utils/cartProduct.js} +77 -416
  12. package/dist/modules/Cart/utils/cartRelationForms.d.ts +26 -0
  13. package/dist/modules/Cart/utils/cartRelationForms.js +29 -0
  14. package/dist/modules/Cart/utils/cartResource.d.ts +21 -0
  15. package/dist/modules/Cart/utils/cartResource.js +102 -0
  16. package/dist/modules/Cart/utils/index.d.ts +34 -0
  17. package/dist/modules/Cart/utils/index.js +63 -0
  18. package/dist/modules/Order/index.js +10 -4
  19. package/dist/modules/Product/types.d.ts +4 -0
  20. package/dist/modules/Product/utils.d.ts +17 -0
  21. package/dist/modules/Product/utils.js +41 -0
  22. package/dist/modules/Schedule/index.d.ts +2 -0
  23. package/dist/modules/Schedule/index.js +10 -0
  24. package/dist/modules/Schedule/types.d.ts +1 -0
  25. package/dist/solution/BookingByStep/index.d.ts +10 -4
  26. package/dist/solution/BookingByStep/index.js +267 -122
  27. package/lib/modules/Cart/index.js +16 -24
  28. package/lib/modules/Cart/utils/cartAccount.d.ts +21 -0
  29. package/lib/modules/Cart/utils/cartAccount.js +65 -0
  30. package/lib/modules/Cart/utils/cartDate.d.ts +31 -0
  31. package/lib/modules/Cart/utils/cartDate.js +75 -0
  32. package/lib/modules/Cart/utils/cartDiscount.d.ts +19 -0
  33. package/lib/modules/Cart/utils/cartDiscount.js +52 -0
  34. package/lib/modules/Cart/utils/cartNote.d.ts +19 -0
  35. package/lib/modules/Cart/utils/cartNote.js +46 -0
  36. package/lib/modules/Cart/utils/cartProduct.d.ts +107 -0
  37. package/lib/modules/Cart/{utils.js → utils/cartProduct.js} +78 -328
  38. package/lib/modules/Cart/utils/cartRelationForms.d.ts +26 -0
  39. package/lib/modules/Cart/utils/cartRelationForms.js +48 -0
  40. package/lib/modules/Cart/utils/cartResource.d.ts +21 -0
  41. package/lib/modules/Cart/utils/cartResource.js +124 -0
  42. package/lib/modules/Cart/utils/index.d.ts +34 -0
  43. package/lib/modules/Cart/utils/index.js +91 -0
  44. package/lib/modules/Order/index.js +7 -3
  45. package/lib/modules/Product/types.d.ts +4 -0
  46. package/lib/modules/Product/utils.d.ts +17 -0
  47. package/lib/modules/Product/utils.js +46 -0
  48. package/lib/modules/Schedule/index.d.ts +2 -0
  49. package/lib/modules/Schedule/index.js +6 -0
  50. package/lib/modules/Schedule/types.d.ts +1 -0
  51. package/lib/solution/BookingByStep/index.d.ts +10 -4
  52. package/lib/solution/BookingByStep/index.js +156 -75
  53. package/package.json +1 -1
  54. package/dist/modules/Cart/utils.d.ts +0 -257
  55. package/lib/modules/Cart/utils.d.ts +0 -257
@@ -43,6 +43,7 @@ var import_utils = require("../../modules/Resource/utils");
43
43
  var import_lodash_es = require("lodash-es");
44
44
  var import_utils2 = require("../../modules/Schedule/utils");
45
45
  var import_utils3 = require("../../modules/Date/utils");
46
+ var import_utils4 = require("../../modules/Product/utils");
46
47
  var import_timeslots = require("./utils/timeslots");
47
48
  import_dayjs.default.extend(import_isSameOrBefore.default);
48
49
  import_dayjs.default.extend(import_isSameOrAfter.default);
@@ -162,19 +163,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
162
163
  async loadProducts({
163
164
  category_ids = [],
164
165
  product_ids = [],
165
- collection = [],
166
- schedule_ids = [],
167
- schedule_date
166
+ collection = []
167
+ // schedule_ids = [],
168
+ // schedule_date,
168
169
  }) {
169
170
  var _a;
170
- if (!(schedule_ids == null ? void 0 : schedule_ids.length)) {
171
- const schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map((n) => n.id);
172
- if (schedule_ids_data.length) {
173
- schedule_ids = schedule_ids_data;
174
- } else if (schedule_date) {
175
- schedule_ids = [0];
176
- }
177
- }
178
171
  let userPlugin = this.core.getPlugin("user");
179
172
  let customer_id = void 0;
180
173
  try {
@@ -187,12 +180,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
187
180
  {
188
181
  open_quotation: 1,
189
182
  open_bundle: 0,
190
- extension_type: [
191
- "product_appointment",
192
- "appointment_ticket",
193
- "session_product",
194
- "session_ticket",
195
- "normal"
183
+ exclude_extension_type: [
184
+ "product_party",
185
+ "product_event",
186
+ "product_series_event",
187
+ "product_package_ticket",
188
+ "ticket",
189
+ "event_item"
196
190
  ],
197
191
  with: ["category", "collection", "resourceRelation"],
198
192
  status: "published",
@@ -202,9 +196,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
202
196
  category_ids,
203
197
  ids: product_ids,
204
198
  collection,
205
- front_end_cache_id: this.cacheId,
206
- client_schedule_ids: schedule_ids,
207
- schedule_date
199
+ front_end_cache_id: this.cacheId
200
+ // client_schedule_ids: schedule_ids,
201
+ // schedule_date,
208
202
  },
209
203
  { useCache: true }
210
204
  );
@@ -213,7 +207,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
213
207
  }
214
208
  async loadProductByScheduleDate({
215
209
  date,
216
- product_ids,
210
+ product_ids = [],
217
211
  category_ids = []
218
212
  }) {
219
213
  var _a;
@@ -222,18 +216,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
222
216
  { date, status: "available", week: "", weekNum: 0 },
223
217
  { date, status: "available", week: "", weekNum: 0 }
224
218
  ]);
225
- const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id).filter((n) => n !== null && n !== void 0);
226
219
  if (!(product_ids == null ? void 0 : product_ids.length)) {
227
220
  const schedule = scheduleList.find((n) => n.date === date);
228
221
  if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
229
222
  product_ids = schedule.product_ids;
230
223
  }
231
224
  }
225
+ const otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
226
+ const allProductIds = [...product_ids, ...otherProductsIds].filter(
227
+ (n, index, self) => self.indexOf(n) === index
228
+ );
232
229
  return await this.loadProducts({
233
- schedule_ids: scheduleIds,
234
- product_ids,
235
- category_ids,
236
- schedule_date: date
230
+ // schedule_ids: scheduleIds,
231
+ product_ids: allProductIds,
232
+ category_ids
233
+ // schedule_date: date,
237
234
  });
238
235
  }
239
236
  async updateQuotationPriceAndCart(date) {
@@ -305,7 +302,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
305
302
  custom_page_id,
306
303
  channel
307
304
  }) {
308
- var _a;
305
+ var _a, _b, _c;
309
306
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
310
307
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
311
308
  }
@@ -315,7 +312,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
315
312
  return dates;
316
313
  }
317
314
  const res = await this.request.get(
318
- `/schedule/product/availability`,
315
+ `/schedule/product/availability/v2`,
319
316
  {
320
317
  start_date: startDate,
321
318
  end_date: endDate,
@@ -324,26 +321,51 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
324
321
  }
325
322
  );
326
323
  this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
327
- if (!((_a = res.data.date_list) == null ? void 0 : _a.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
324
+ this.store.schedule.setOtherProductsIds(res.data.other_product_ids || []);
325
+ if (!((_a = res.data.date_list) == null ? void 0 : _a.length) && !((_b = res.data.other_product_ids) == null ? void 0 : _b.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
328
326
  return dates;
329
327
  }
330
- res.data.date_list.forEach((n) => {
331
- const index = dates.findIndex((m) => m.date === n.date);
332
- if (index !== -1) {
333
- dates[index].status = "available";
334
- }
335
- });
328
+ if ((_c = res.data.other_product_ids) == null ? void 0 : _c.length) {
329
+ dates.forEach((n) => {
330
+ n.status = "available";
331
+ });
332
+ } else {
333
+ res.data.date_list.forEach((n) => {
334
+ const index = dates.findIndex((m) => m.date === n.date);
335
+ if (index !== -1) {
336
+ dates[index].status = "available";
337
+ }
338
+ });
339
+ }
336
340
  dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
337
341
  return dates;
338
342
  }
339
343
  async storeProduct(productData) {
340
344
  const activeAccount = this.getActiveAccount();
341
- const { bundle, options, origin, product_variant_id } = productData || {};
342
- const product = { ...origin, product_variant_id };
345
+ const { bundle, options, origin, product_variant_id, quantity = 1, rowKey } = productData || {};
346
+ const cartItems = this.store.cart.getItems();
347
+ if (rowKey) {
348
+ const targetCartItem = cartItems.find((n) => {
349
+ var _a;
350
+ return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
351
+ });
352
+ if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
353
+ this.store.cart.updateItem({
354
+ _id: targetCartItem._id,
355
+ product: {
356
+ ...targetCartItem._productOrigin
357
+ },
358
+ quantity: (targetCartItem.num || 1) + quantity
359
+ });
360
+ return;
361
+ }
362
+ }
363
+ const product = { ...origin, product_variant_id, rowKey };
343
364
  const addCartItem = {
344
365
  product,
345
366
  bundle,
346
- options
367
+ options,
368
+ quantity
347
369
  };
348
370
  if (activeAccount) {
349
371
  addCartItem.account = activeAccount;
@@ -412,12 +434,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
412
434
  * @param params
413
435
  */
414
436
  async fetchHolderAccountsAsync(params) {
415
- var _a, _b, _c;
437
+ var _a, _b;
416
438
  const cartItems = this.store.cart.getItems();
417
439
  if (cartItems.length) {
418
440
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
419
441
  if (!date) {
420
- date = ((_c = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _c.start_date) || "";
442
+ const normalProductCartItem = cartItems.find((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
443
+ date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
421
444
  }
422
445
  this.updateQuotationPriceAndCart(date);
423
446
  }
@@ -504,7 +527,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
504
527
  }
505
528
  // 如果用户登录
506
529
  async setLoginAccount(accountId, accountInfo) {
507
- var _a, _b, _c;
530
+ var _a, _b;
508
531
  const account = this.store.accountList.getAccount(accountId);
509
532
  if (account) {
510
533
  let stateAccountId = account.getId();
@@ -523,7 +546,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
523
546
  if (cartItems.length) {
524
547
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
525
548
  if (!date) {
526
- date = ((_c = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _c.start_date) || "";
549
+ const normalProductCartItem = cartItems.find((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
550
+ date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
527
551
  }
528
552
  this.updateQuotationPriceAndCart(date);
529
553
  }
@@ -576,7 +600,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
576
600
  item._origin.number = currentCapacity;
577
601
  }
578
602
  });
579
- const type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
603
+ let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
604
+ if ((0, import_utils4.areAllNormalProducts)(newCartItems.map((n) => n._productOrigin))) {
605
+ type = "virtual";
606
+ }
580
607
  return this.store.order.submitOrder({ query: { cartItems: newCartItems, type } });
581
608
  }
582
609
  // 拉起支付模块
@@ -753,7 +780,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
753
780
  * @returns 不符合条件的购物车商品ID列表
754
781
  */
755
782
  checkCartItems(type) {
756
- const cartItems = this.store.cart.getItems();
783
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
757
784
  const errorCartItemIds = [];
758
785
  cartItems.forEach((cartItem) => {
759
786
  const result = this.store.cart.checkCartItemByType(cartItem, type);
@@ -792,7 +819,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
792
819
  });
793
820
  }
794
821
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
795
- const cartItems = this.store.cart.getItems();
822
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
796
823
  const arr = [];
797
824
  cartItems.forEach((cartItem) => {
798
825
  var _a, _b, _c;
@@ -921,7 +948,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
921
948
  });
922
949
  }
923
950
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
924
- const cartItems = this.store.cart.getItems();
951
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
925
952
  const arr = [];
926
953
  cartItems.forEach((cartItem) => {
927
954
  var _a, _b, _c;
@@ -1035,7 +1062,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1035
1062
  // 给单个购物车里的商品获取资源列表
1036
1063
  getResourcesListByCartItem(id) {
1037
1064
  var _a, _b, _c;
1038
- const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1065
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1039
1066
  const dateRange = this.store.date.getDateRange();
1040
1067
  const resources = [];
1041
1068
  dateRange.forEach((n) => {
@@ -1118,6 +1145,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1118
1145
  capacity
1119
1146
  }) {
1120
1147
  var _a, _b, _c;
1148
+ if ((0, import_utils4.isNormalProduct)(cartItem._productOrigin)) {
1149
+ return {};
1150
+ }
1121
1151
  const dateRange = this.store.date.getDateRange();
1122
1152
  const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1123
1153
  let accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
@@ -1276,8 +1306,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1276
1306
  const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
1277
1307
  (n) => n.code === resources_code
1278
1308
  );
1279
- const resourceBookingType = (currentResourceConfig == null ? void 0 : currentResourceConfig.type) || "single";
1280
- if (index !== 0 && recordTimeSlots && resourceBookingType === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
1309
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
1281
1310
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
1282
1311
  ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) ?? 0,
1283
1312
  ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.type) ?? "minutes"
@@ -1422,7 +1451,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1422
1451
  }
1423
1452
  });
1424
1453
  };
1425
- const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1454
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1426
1455
  if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1427
1456
  accountList.forEach((account) => {
1428
1457
  const cartItems2 = this.store.cart.getCartByAccount(account.getId());
@@ -1438,7 +1467,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1438
1467
  var _a, _b, _c, _d, _e, _f;
1439
1468
  let dateRange = this.store.date.getDateRange();
1440
1469
  const resources = [];
1441
- const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1470
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1442
1471
  const resourceIds = [];
1443
1472
  let resourcesTypeId = void 0;
1444
1473
  let isSingleResource = false;
@@ -1536,7 +1565,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1536
1565
  }
1537
1566
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车
1538
1567
  submitTimeSlot(timeSlots) {
1539
- const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1568
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1540
1569
  const itemsByAccount = cartItems.reduce(
1541
1570
  (acc, item) => {
1542
1571
  const holderId = item.holder_id;
@@ -1622,7 +1651,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1622
1651
  resources,
1623
1652
  product
1624
1653
  }) {
1625
- var _a, _b, _c;
1654
+ var _a, _b, _c, _d, _e, _f;
1626
1655
  const targetProduct = this.store.currentProduct;
1627
1656
  const targetProductData = product || (targetProduct == null ? void 0 : targetProduct.getData());
1628
1657
  let targetSchedules = [];
@@ -1656,18 +1685,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1656
1685
  const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1657
1686
  let allProductResources = productResources.flatMap((n) => n.renderList);
1658
1687
  allProductResources.sort((a, b) => {
1659
- var _a2, _b2, _c2, _d;
1688
+ var _a2, _b2, _c2, _d2;
1660
1689
  const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1661
- const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1690
+ const bIsCombined = ((_d2 = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d2.status) === 1;
1662
1691
  if (aIsCombined && !bIsCombined)
1663
1692
  return 1;
1664
1693
  if (!aIsCombined && bIsCombined)
1665
1694
  return -1;
1666
1695
  return 0;
1667
1696
  });
1697
+ const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find((n) => n.status === 1)) == null ? void 0 : _f.id;
1668
1698
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1669
1699
  const resourcesUseableMap = {};
1670
1700
  let count = 0;
1701
+ let bookingLeft = 0;
1671
1702
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1672
1703
  let currentResourcesCount = 0;
1673
1704
  const currentResourcesTimeSlotCanUsedArr = [];
@@ -1699,10 +1730,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1699
1730
  }
1700
1731
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1701
1732
  });
1702
- if (!currentResourcesTimeSlotCanUsedArr.some(
1703
- (n) => n === false
1704
- ) && currentResourcesCount >= count) {
1705
- count = currentResourcesCount;
1733
+ if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false) && m.form_id === firstEnabledResourceId) {
1734
+ if (currentResourcesCount >= count) {
1735
+ count = currentResourcesCount;
1736
+ }
1737
+ if (!m.onlyComputed) {
1738
+ bookingLeft += 1;
1739
+ }
1706
1740
  }
1707
1741
  });
1708
1742
  const startDayJs = (0, import_dayjs.default)(item.start);
@@ -1712,7 +1746,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1712
1746
  end_time: endDayJs.format("HH:mm"),
1713
1747
  start_at: startDayJs,
1714
1748
  end_at: endDayJs,
1715
- count
1749
+ count,
1750
+ left: bookingLeft
1716
1751
  };
1717
1752
  });
1718
1753
  return formatScheduleTimeSlots;
@@ -1722,7 +1757,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1722
1757
  date,
1723
1758
  account
1724
1759
  }) {
1725
- const { bundle, options, origin, product_variant_id } = product || {};
1760
+ const { bundle, options, origin, product_variant_id, rowKey, quantity = 1 } = product || {};
1726
1761
  const productData = { ...origin, product_variant_id };
1727
1762
  if (!account) {
1728
1763
  const activeAccount = this.getActiveAccount();
@@ -1730,15 +1765,33 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1730
1765
  account = activeAccount;
1731
1766
  }
1732
1767
  }
1768
+ if (rowKey) {
1769
+ const cartItems = this.store.cart.getItems();
1770
+ const targetCartItem = cartItems.find((n) => {
1771
+ var _a;
1772
+ return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
1773
+ });
1774
+ if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
1775
+ this.store.cart.updateItem({
1776
+ _id: targetCartItem._id,
1777
+ product: {
1778
+ ...targetCartItem._productOrigin,
1779
+ quantity: (targetCartItem.num || 1) + quantity
1780
+ }
1781
+ });
1782
+ return;
1783
+ }
1784
+ }
1733
1785
  this.store.cart.addItem({
1734
1786
  product: productData,
1735
1787
  date,
1736
1788
  account,
1737
1789
  bundle,
1738
- options
1790
+ options,
1791
+ quantity
1739
1792
  });
1740
1793
  if (date) {
1741
- const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1794
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1742
1795
  const cartItemsByDate = cartItems.filter(
1743
1796
  (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
1744
1797
  );
@@ -1794,7 +1847,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1794
1847
  });
1795
1848
  }
1796
1849
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
1797
- const cartItems = this.store.cart.getItems();
1850
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1798
1851
  const cartItem = cartItems.find((item) => item._id === cartItemId);
1799
1852
  if (!cartItem)
1800
1853
  return [];
@@ -1980,23 +2033,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1980
2033
  }
1981
2034
  async getAvailableDateForSessionOptimize(params = {}) {
1982
2035
  var _a, _b, _c, _d, _e, _f;
1983
- const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
1984
- if (cache) {
1985
- if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
1986
- return {
1987
- dateList: cache.dateList,
1988
- firstAvailableDate: cache.firstAvailableDate
1989
- };
1990
- }
1991
- }
1992
2036
  let { startDate, endDate } = params;
1993
2037
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
1994
2038
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
1995
2039
  }
1996
2040
  endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
1997
2041
  let tempProducts;
1998
- tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
1999
- const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
2042
+ tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
2043
+ const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
2000
2044
  const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
2001
2045
  schedule,
2002
2046
  startDate || "",
@@ -2010,6 +2054,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2010
2054
  resource_ids: tempResourceIds
2011
2055
  }
2012
2056
  });
2057
+ const cache = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["timeSlotBySchedule"];
2058
+ if (cache) {
2059
+ if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
2060
+ this.store.date.setDateList(cache.dateList);
2061
+ return {
2062
+ dateList: cache.dateList,
2063
+ firstAvailableDate: cache.firstAvailableDate
2064
+ };
2065
+ }
2066
+ }
2013
2067
  let dates = [];
2014
2068
  let currentDate = (0, import_dayjs.default)(startDate);
2015
2069
  let firstAvailableDate = "";
@@ -2017,6 +2071,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2017
2071
  (m) => m.status === 1
2018
2072
  )) || [];
2019
2073
  const allProductResources = (0, import_resources.sortCombinedResources)(res.data);
2074
+ allProductResources.forEach((m) => {
2075
+ var _a2, _b2;
2076
+ const resource = (_b2 = (_a2 = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _a2.resources) == null ? void 0 : _b2.find(
2077
+ (n) => n.id === m.form_id
2078
+ );
2079
+ if (resource) {
2080
+ m.resourceType = resource.type;
2081
+ }
2082
+ });
2020
2083
  const targetSchedules = this.store.schedule.getScheduleListByIds(
2021
2084
  tempProducts["schedule.ids"]
2022
2085
  );
@@ -2114,6 +2177,24 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2114
2177
  firstAvailableDate
2115
2178
  };
2116
2179
  }
2180
+ isCartAllNormalProducts() {
2181
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
2182
+ return !cartItems.length;
2183
+ }
2184
+ isCartHasDurationProduct() {
2185
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
2186
+ return cartItems.some((n) => {
2187
+ var _a;
2188
+ return (_a = n._productOrigin) == null ? void 0 : _a.duration;
2189
+ });
2190
+ }
2191
+ isTargetNormalProduct(product) {
2192
+ return (0, import_utils4.isNormalProduct)(product);
2193
+ }
2194
+ isTargetCartIdNormalProduct(id) {
2195
+ const cartItem = this.store.cart.getItems().find((n) => n._id === id);
2196
+ return cartItem && (0, import_utils4.isNormalProduct)(cartItem._productOrigin);
2197
+ }
2117
2198
  };
2118
2199
  // Annotate the CommonJS export names for ESM import in node:
2119
2200
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.34",
4
+ "version": "3.0.36",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",