@pisell/pisellos 0.0.115 → 0.0.117

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 +16 -35
  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 +3 -2
  19. package/dist/modules/Product/index.d.ts +1 -1
  20. package/dist/modules/Product/types.d.ts +4 -0
  21. package/dist/modules/Product/utils.d.ts +17 -0
  22. package/dist/modules/Product/utils.js +41 -0
  23. package/dist/solution/BookingByStep/index.d.ts +25 -0
  24. package/dist/solution/BookingByStep/index.js +320 -58
  25. package/dist/solution/BookingByStep/utils/timeslots.d.ts +25 -0
  26. package/dist/solution/BookingByStep/utils/timeslots.js +209 -0
  27. package/lib/modules/Cart/index.js +14 -25
  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 +2 -1
  45. package/lib/modules/Product/index.d.ts +1 -1
  46. package/lib/modules/Product/types.d.ts +4 -0
  47. package/lib/modules/Product/utils.d.ts +17 -0
  48. package/lib/modules/Product/utils.js +46 -0
  49. package/lib/solution/BookingByStep/index.d.ts +25 -0
  50. package/lib/solution/BookingByStep/index.js +181 -23
  51. package/lib/solution/BookingByStep/utils/timeslots.d.ts +25 -0
  52. package/lib/solution/BookingByStep/utils/timeslots.js +159 -0
  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
@@ -37,6 +37,8 @@ import { getResourcesMap } from "../../modules/Resource/utils";
37
37
  import { cloneDeep } from 'lodash-es';
38
38
  import { calcCalendarDataByScheduleResult, calcMinTimeMaxTimeBySchedules, getAllSortedDateRanges } from "../../modules/Schedule/utils";
39
39
  import { disableAllDates, disableDatesBeforeOneDay, generateMonthDates, handleAvailableDateByResource } from "../../modules/Date/utils";
40
+ import { areAllNormalProducts, isNormalProduct } from "../../modules/Product/utils";
41
+ import { calculateResourceAvailableTime, findFastestAvailableResource } from "./utils/timeslots";
40
42
  export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
41
43
  _inherits(BookingByStepImpl, _BaseModule);
42
44
  var _super = _createSuper(BookingByStepImpl);
@@ -544,26 +546,48 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
544
546
  key: "storeProduct",
545
547
  value: function () {
546
548
  var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(productData) {
547
- var activeAccount, _ref4, bundle, options, origin, product_variant_id, product, addCartItem;
549
+ var activeAccount, _ref4, bundle, options, origin, product_variant_id, _ref4$quantity, quantity, rowKey, cartItems, targetCartItem, product, addCartItem;
548
550
  return _regeneratorRuntime().wrap(function _callee7$(_context8) {
549
551
  while (1) switch (_context8.prev = _context8.next) {
550
552
  case 0:
551
553
  // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
552
554
  activeAccount = this.getActiveAccount();
553
- _ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id;
555
+ _ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id, _ref4$quantity = _ref4.quantity, quantity = _ref4$quantity === void 0 ? 1 : _ref4$quantity, rowKey = _ref4.rowKey; // 检查购物车里是否已经存在 rowKey相同的数据,如果是则更新数量
556
+ cartItems = this.store.cart.getItems();
557
+ if (!rowKey) {
558
+ _context8.next = 8;
559
+ break;
560
+ }
561
+ targetCartItem = cartItems.find(function (n) {
562
+ var _n$_productOrigin;
563
+ return ((_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.rowKey) === rowKey;
564
+ });
565
+ if (!(targetCartItem && isNormalProduct(targetCartItem._productOrigin))) {
566
+ _context8.next = 8;
567
+ break;
568
+ }
569
+ this.store.cart.updateItem({
570
+ _id: targetCartItem._id,
571
+ product: _objectSpread({}, targetCartItem._productOrigin),
572
+ quantity: (targetCartItem.num || 1) + quantity
573
+ });
574
+ return _context8.abrupt("return");
575
+ case 8:
554
576
  product = _objectSpread(_objectSpread({}, origin), {}, {
555
- product_variant_id: product_variant_id
577
+ product_variant_id: product_variant_id,
578
+ rowKey: rowKey
556
579
  });
557
580
  addCartItem = {
558
581
  product: product,
559
582
  bundle: bundle,
560
- options: options
583
+ options: options,
584
+ quantity: quantity
561
585
  };
562
586
  if (activeAccount) {
563
587
  addCartItem.account = activeAccount;
564
588
  }
565
589
  this.store.cart.addItem(addCartItem);
566
- case 6:
590
+ case 12:
567
591
  case "end":
568
592
  return _context8.stop();
569
593
  }
@@ -734,7 +758,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
734
758
  key: "fetchHolderAccountsAsync",
735
759
  value: (function () {
736
760
  var _fetchHolderAccountsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
737
- var cartItems, _this$store$date$getD, date, _cartItems$;
761
+ var cartItems, _this$store$date$getD, date, normalProductCartItem;
738
762
  return _regeneratorRuntime().wrap(function _callee11$(_context12) {
739
763
  while (1) switch (_context12.prev = _context12.next) {
740
764
  case 0:
@@ -743,7 +767,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
743
767
  date = (_this$store$date$getD = this.store.date.getDateRange()) === null || _this$store$date$getD === void 0 || (_this$store$date$getD = _this$store$date$getD[0]) === null || _this$store$date$getD === void 0 ? void 0 : _this$store$date$getD.date;
744
768
  if (!date) {
745
769
  // 如果没有日期,则应该是 session 类先选商品的流程,直接从购物车里拿 start_date
746
- date = (cartItems === null || cartItems === void 0 || (_cartItems$ = cartItems[0]) === null || _cartItems$ === void 0 ? void 0 : _cartItems$.start_date) || '';
770
+ // 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
771
+ normalProductCartItem = cartItems.find(function (n) {
772
+ return !isNormalProduct(n._productOrigin);
773
+ });
774
+ date = (normalProductCartItem === null || normalProductCartItem === void 0 ? void 0 : normalProductCartItem.start_date) || '';
747
775
  }
748
776
  this.updateQuotationPriceAndCart(date);
749
777
  }
@@ -978,7 +1006,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
978
1006
  value: function () {
979
1007
  var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(accountId, accountInfo) {
980
1008
  var _this5 = this;
981
- var account, stateAccountId, cartItems, _this$store$date$getD2, date, _cartItems$2;
1009
+ var account, stateAccountId, cartItems, _this$store$date$getD2, date, normalProductCartItem;
982
1010
  return _regeneratorRuntime().wrap(function _callee18$(_context19) {
983
1011
  while (1) switch (_context19.prev = _context19.next) {
984
1012
  case 0:
@@ -1005,7 +1033,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1005
1033
  date = (_this$store$date$getD2 = this.store.date.getDateRange()) === null || _this$store$date$getD2 === void 0 || (_this$store$date$getD2 = _this$store$date$getD2[0]) === null || _this$store$date$getD2 === void 0 ? void 0 : _this$store$date$getD2.date;
1006
1034
  if (!date) {
1007
1035
  // 如果没有日期,则应该是 session 类先选商品的流程,直接从购物车里拿 start_date
1008
- date = (cartItems === null || cartItems === void 0 || (_cartItems$2 = cartItems[0]) === null || _cartItems$2 === void 0 ? void 0 : _cartItems$2.start_date) || '';
1036
+ // 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
1037
+ normalProductCartItem = cartItems.find(function (n) {
1038
+ return !isNormalProduct(n._productOrigin);
1039
+ });
1040
+ date = (normalProductCartItem === null || normalProductCartItem === void 0 ? void 0 : normalProductCartItem.start_date) || '';
1009
1041
  }
1010
1042
  this.updateQuotationPriceAndCart(date);
1011
1043
  }
@@ -1114,14 +1146,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1114
1146
  item._origin.number = currentCapacity;
1115
1147
  }
1116
1148
  });
1117
- type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking';
1149
+ type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking'; // 如果购物车里全都是普通商品,type 也应该为 virtual
1150
+ if (areAllNormalProducts(newCartItems.map(function (n) {
1151
+ return n._productOrigin;
1152
+ }))) {
1153
+ type = 'virtual';
1154
+ }
1118
1155
  return _context22.abrupt("return", this.store.order.submitOrder({
1119
1156
  query: {
1120
1157
  cartItems: newCartItems,
1121
1158
  type: type
1122
1159
  }
1123
1160
  }));
1124
- case 5:
1161
+ case 6:
1125
1162
  case "end":
1126
1163
  return _context22.stop();
1127
1164
  }
@@ -1265,7 +1302,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1265
1302
  var _item$_origin$resourc;
1266
1303
  var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1267
1304
  // 检查当前资源是否与目标资源的任何资源匹配
1268
- return !targetCartItem._origin.resources.some(function (targetRes) {
1305
+ // 目标资源,应该只取跟当前 m.form_id 相同的资源
1306
+ var sameFormIdResources = targetCartItem._origin.resources.filter(function (n) {
1307
+ return n.form_id === m.form_id;
1308
+ });
1309
+ if (!(sameFormIdResources !== null && sameFormIdResources !== void 0 && sameFormIdResources.length)) {
1310
+ return true;
1311
+ }
1312
+ return !sameFormIdResources.some(function (targetRes) {
1269
1313
  // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1270
1314
  if (targetRes.resourceType !== 'single') {
1271
1315
  var _item$_productOrigin2;
@@ -1279,10 +1323,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1279
1323
  var originResource = allOriginResources.find(function (n) {
1280
1324
  return n.id === targetRes.id;
1281
1325
  });
1282
- if (currentResourcesCapacityMap[targetRes.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1326
+ if (currentResourcesCapacityMap[m.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1283
1327
  return true;
1284
1328
  }
1285
- currentResourcesCapacityMap[targetRes.id] += _currentCapacity;
1329
+ currentResourcesCapacityMap[m.id] += _currentCapacity;
1286
1330
  return false;
1287
1331
  }
1288
1332
  if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
@@ -1429,7 +1473,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1429
1473
  });
1430
1474
  }
1431
1475
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1432
- var cartItems = this.store.cart.getItems();
1476
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1477
+ return !isNormalProduct(n._productOrigin);
1478
+ });
1433
1479
  var arr = [];
1434
1480
  cartItems.forEach(function (cartItem) {
1435
1481
  var _cartItem$_productOri, _cartItem$_productOri2;
@@ -1554,7 +1600,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1554
1600
  });
1555
1601
  }
1556
1602
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1557
- var cartItems = this.store.cart.getItems();
1603
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1604
+ return !isNormalProduct(n._productOrigin);
1605
+ });
1558
1606
  var arr = [];
1559
1607
  cartItems.forEach(function (cartItem) {
1560
1608
  var _cartItem$_productOri5, _cartItem$_productOri6;
@@ -1668,7 +1716,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1668
1716
  key: "getResourcesListByCartItem",
1669
1717
  value: function getResourcesListByCartItem(id) {
1670
1718
  var _targetCartItem$_prod2, _targetCartItem$_prod3;
1671
- var cartItems = cloneDeep(this.store.cart.getItems());
1719
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1720
+ return !isNormalProduct(n._productOrigin);
1721
+ });
1672
1722
  var dateRange = this.store.date.getDateRange();
1673
1723
  var resources = [];
1674
1724
  dateRange.forEach(function (n) {
@@ -1747,6 +1797,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1747
1797
  timeSlots = _ref8.timeSlots,
1748
1798
  countMap = _ref8.countMap,
1749
1799
  capacity = _ref8.capacity;
1800
+ if (isNormalProduct(cartItem._productOrigin)) {
1801
+ return {};
1802
+ }
1750
1803
  var dateRange = this.store.date.getDateRange();
1751
1804
  var cartItems = cloneDeep(this.store.cart.getItems());
1752
1805
  // 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
@@ -1759,8 +1812,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1759
1812
  }
1760
1813
  // duration=所有商品时间的集合
1761
1814
  var duration = accountCartItems.reduce(function (acc, n) {
1762
- var _n$_productOrigin$dur, _n$_productOrigin;
1763
- return acc + ((_n$_productOrigin$dur = (_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 || (_n$_productOrigin = _n$_productOrigin.duration) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.value) !== null && _n$_productOrigin$dur !== void 0 ? _n$_productOrigin$dur : 0);
1815
+ var _n$_productOrigin$dur, _n$_productOrigin2;
1816
+ return acc + ((_n$_productOrigin$dur = (_n$_productOrigin2 = n._productOrigin) === null || _n$_productOrigin2 === void 0 || (_n$_productOrigin2 = _n$_productOrigin2.duration) === null || _n$_productOrigin2 === void 0 ? void 0 : _n$_productOrigin2.value) !== null && _n$_productOrigin$dur !== void 0 ? _n$_productOrigin$dur : 0);
1764
1817
  }, 0);
1765
1818
  // 正常来说,能进这个业务的所有商品的 duration 类型都是一样的,所以这里取第一个商品的 duration 类型
1766
1819
  // let durationType = accountCartItems[0]?._productOrigin?.duration?.type ?? "minutes";
@@ -1817,6 +1870,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1817
1870
  // .format("HH:mm");
1818
1871
  // 根据 start_time 和 end_time 去匹配资源
1819
1872
  var targetResource = null;
1873
+ var targetResourceTime = 0;
1820
1874
  var _iterator3 = _createForOfIteratorHelper(resources),
1821
1875
  _step3;
1822
1876
  try {
@@ -1859,8 +1913,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1859
1913
  }
1860
1914
  return res.usable;
1861
1915
  });
1862
- if (canUseTime && !n.onlyComputed) {
1916
+ var currentResourceIdleTime = calculateResourceAvailableTime({
1917
+ resource: n,
1918
+ timeSlots: timeSlots,
1919
+ currentCapacity: totalCapacity + (capacity || 0)
1920
+ });
1921
+ if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
1863
1922
  targetResource = n;
1923
+ targetResourceTime = currentResourceIdleTime;
1864
1924
  return 1; // break
1865
1925
  }
1866
1926
  },
@@ -2058,7 +2118,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2058
2118
  })) {
2059
2119
  return;
2060
2120
  }
2061
- var targetResource = targetRenderList[0];
2121
+ var fastestResource = findFastestAvailableResource({
2122
+ resources: targetRenderList,
2123
+ currentCapacity: currentCapacity,
2124
+ countMap: selectResourcesMap
2125
+ });
2126
+ var targetResource = fastestResource || targetRenderList[0];
2062
2127
  targetResource.capacity = currentCapacity;
2063
2128
  // 在这里处理 children 的数据
2064
2129
  checkSubResourcesCapacity(targetResource);
@@ -2080,7 +2145,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2080
2145
  }
2081
2146
  });
2082
2147
  };
2083
- var cartItems = cloneDeep(this.store.cart.getItems());
2148
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2149
+ return !isNormalProduct(n._productOrigin);
2150
+ });
2084
2151
 
2085
2152
  // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
2086
2153
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
@@ -2101,12 +2168,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2101
2168
  value: function getTimeSlotByAllResources(resources_code) {
2102
2169
  var _dateRange,
2103
2170
  _this10 = this,
2104
- _cartItems$3,
2105
- _cartItems$4;
2171
+ _cartItems$,
2172
+ _cartItems$2;
2106
2173
  var dateRange = this.store.date.getDateRange();
2107
2174
  // 取出购物车中所有一已选择的第一步资源
2108
2175
  var resources = [];
2109
- var cartItems = cloneDeep(this.store.cart.getItems());
2176
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2177
+ return !isNormalProduct(n._productOrigin);
2178
+ });
2110
2179
  // if (cartItems?.[0].start_date) return [];
2111
2180
  var resourceIds = [];
2112
2181
  var resourcesTypeId = undefined;
@@ -2185,18 +2254,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2185
2254
  }
2186
2255
  // 如果 cartItem 上既没有时间,也没有资源,认为外部属于异常调用,直接丢一个空数组出去
2187
2256
  // 同时 session 类商品的流程也不应该调用这个方法
2188
- if (!(cartItems !== null && cartItems !== void 0 && (_cartItems$3 = cartItems[0]) !== null && _cartItems$3 !== void 0 && _cartItems$3.start_date) && !(cartItems !== null && cartItems !== void 0 && (_cartItems$4 = cartItems[0]) !== null && _cartItems$4 !== void 0 && _cartItems$4.resource_id) || !(cartItems !== null && cartItems !== void 0 && cartItems[0].duration)) {
2257
+ if (!(cartItems !== null && cartItems !== void 0 && (_cartItems$ = cartItems[0]) !== null && _cartItems$ !== void 0 && _cartItems$.start_date) && !(cartItems !== null && cartItems !== void 0 && (_cartItems$2 = cartItems[0]) !== null && _cartItems$2 !== void 0 && _cartItems$2.resource_id) || !(cartItems !== null && cartItems !== void 0 && cartItems[0].duration)) {
2189
2258
  return [];
2190
2259
  }
2191
2260
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].start_date && !dateRange) {
2192
- var _cartItems$5, _cartItems$6;
2261
+ var _cartItems$3, _cartItems$4;
2193
2262
  dateRange = [{
2194
2263
  date: cartItems === null || cartItems === void 0 ? void 0 : cartItems[0].start_date,
2195
2264
  status: 'available',
2196
2265
  week: '',
2197
2266
  weekNum: 0
2198
2267
  }, {
2199
- date: (cartItems === null || cartItems === void 0 || (_cartItems$5 = cartItems[0]) === null || _cartItems$5 === void 0 ? void 0 : _cartItems$5.end_date) || (cartItems === null || cartItems === void 0 || (_cartItems$6 = cartItems[0]) === null || _cartItems$6 === void 0 ? void 0 : _cartItems$6.start_date) || '',
2268
+ date: (cartItems === null || cartItems === void 0 || (_cartItems$3 = cartItems[0]) === null || _cartItems$3 === void 0 ? void 0 : _cartItems$3.end_date) || (cartItems === null || cartItems === void 0 || (_cartItems$4 = cartItems[0]) === null || _cartItems$4 === void 0 ? void 0 : _cartItems$4.start_date) || '',
2200
2269
  status: 'available',
2201
2270
  week: '',
2202
2271
  weekNum: 0
@@ -2221,7 +2290,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2221
2290
  value: function submitTimeSlot(timeSlots) {
2222
2291
  var _this11 = this;
2223
2292
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
2224
- var cartItems = cloneDeep(this.store.cart.getItems());
2293
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2294
+ return !isNormalProduct(n._productOrigin);
2295
+ });
2225
2296
 
2226
2297
  // 按账号分组
2227
2298
  var itemsByAccount = cartItems.reduce(function (acc, item) {
@@ -2446,7 +2517,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2446
2517
  bundle = _ref14.bundle,
2447
2518
  options = _ref14.options,
2448
2519
  origin = _ref14.origin,
2449
- product_variant_id = _ref14.product_variant_id;
2520
+ product_variant_id = _ref14.product_variant_id,
2521
+ rowKey = _ref14.rowKey,
2522
+ _ref14$quantity = _ref14.quantity,
2523
+ quantity = _ref14$quantity === void 0 ? 1 : _ref14$quantity;
2450
2524
  var productData = _objectSpread(_objectSpread({}, origin), {}, {
2451
2525
  product_variant_id: product_variant_id
2452
2526
  });
@@ -2456,17 +2530,36 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2456
2530
  account = activeAccount;
2457
2531
  }
2458
2532
  }
2533
+ if (rowKey) {
2534
+ var cartItems = this.store.cart.getItems();
2535
+ var targetCartItem = cartItems.find(function (n) {
2536
+ var _n$_productOrigin3;
2537
+ return ((_n$_productOrigin3 = n._productOrigin) === null || _n$_productOrigin3 === void 0 ? void 0 : _n$_productOrigin3.rowKey) === rowKey;
2538
+ });
2539
+ if (targetCartItem && isNormalProduct(targetCartItem._productOrigin)) {
2540
+ this.store.cart.updateItem({
2541
+ _id: targetCartItem._id,
2542
+ product: _objectSpread(_objectSpread({}, targetCartItem._productOrigin), {}, {
2543
+ quantity: (targetCartItem.num || 1) + quantity
2544
+ })
2545
+ });
2546
+ return;
2547
+ }
2548
+ }
2459
2549
  this.store.cart.addItem({
2460
2550
  product: productData,
2461
2551
  date: date,
2462
2552
  account: account,
2463
2553
  bundle: bundle,
2464
- options: options
2554
+ options: options,
2555
+ quantity: quantity
2465
2556
  });
2466
2557
  // 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
2467
2558
  if (date) {
2468
- var cartItems = cloneDeep(this.store.cart.getItems());
2469
- var cartItemsByDate = cartItems.filter(function (n) {
2559
+ var _cartItems = this.store.cart.getItems().filter(function (n) {
2560
+ return !isNormalProduct(n._productOrigin);
2561
+ });
2562
+ var cartItemsByDate = _cartItems.filter(function (n) {
2470
2563
  return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
2471
2564
  });
2472
2565
  if (cartItemsByDate.length) {
@@ -2550,7 +2643,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2550
2643
  });
2551
2644
  }
2552
2645
  var resourcesMap = getResourcesMap(cloneDeep(resources));
2553
- var cartItems = this.store.cart.getItems();
2646
+ var cartItems = this.store.cart.getItems().filter(function (n) {
2647
+ return !isNormalProduct(n._productOrigin);
2648
+ });
2554
2649
  var cartItem = cartItems.find(function (item) {
2555
2650
  return item._id === cartItemId;
2556
2651
  });
@@ -2632,10 +2727,153 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2632
2727
  }
2633
2728
  return targetResource.renderList;
2634
2729
  }
2730
+
2731
+ /**
2732
+ * 根据日期范围批量获取时间槽
2733
+ * @param params 参数对象
2734
+ * @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
2735
+ */
2736
+ }, {
2737
+ key: "getTimeslotsScheduleByDateRange",
2738
+ value: (function () {
2739
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(_ref15) {
2740
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i, _dates, date;
2741
+ return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2742
+ while (1) switch (_context29.prev = _context29.next) {
2743
+ case 0:
2744
+ startDate = _ref15.startDate, endDate = _ref15.endDate, scheduleIds = _ref15.scheduleIds, resources = _ref15.resources;
2745
+ console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
2746
+ startDate: startDate,
2747
+ endDate: endDate,
2748
+ scheduleIds: scheduleIds,
2749
+ resources: resources
2750
+ });
2751
+ // 生成日期范围内的所有日期
2752
+ dates = [];
2753
+ currentDate = dayjs(startDate);
2754
+ end = dayjs(endDate);
2755
+ while (currentDate.isSameOrBefore(end)) {
2756
+ dates.push(currentDate.format('YYYY-MM-DD'));
2757
+ currentDate = currentDate.add(1, 'day');
2758
+ }
2759
+ // 如果不支持 Web Worker,使用同步方式处理
2760
+ results = {};
2761
+ for (_i = 0, _dates = dates; _i < _dates.length; _i++) {
2762
+ date = _dates[_i];
2763
+ results[date] = this.getTimeslotBySchedule({
2764
+ date: date,
2765
+ scheduleIds: scheduleIds,
2766
+ resources: resources
2767
+ });
2768
+ }
2769
+ return _context29.abrupt("return", results);
2770
+ case 9:
2771
+ case "end":
2772
+ return _context29.stop();
2773
+ }
2774
+ }, _callee28, this);
2775
+ }));
2776
+ function getTimeslotsScheduleByDateRange(_x21) {
2777
+ return _getTimeslotsScheduleByDateRange.apply(this, arguments);
2778
+ }
2779
+ return getTimeslotsScheduleByDateRange;
2780
+ }())
2781
+ }, {
2782
+ key: "getAvailableDateForSession",
2783
+ value: function () {
2784
+ var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2785
+ var params,
2786
+ startDate,
2787
+ endDate,
2788
+ type,
2789
+ tempProducts,
2790
+ _ref16,
2791
+ resourceIds,
2792
+ rules,
2793
+ resourcesMap,
2794
+ res,
2795
+ dateListWithTimeSlots,
2796
+ firstAvailableDate,
2797
+ _args30 = arguments;
2798
+ return _regeneratorRuntime().wrap(function _callee29$(_context30) {
2799
+ while (1) switch (_context30.prev = _context30.next) {
2800
+ case 0:
2801
+ params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
2802
+ // 开始日期如果小于今天,直接以今天当做开始日期
2803
+ startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2804
+ if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
2805
+ startDate = dayjs().format('YYYY-MM-DD');
2806
+ }
2807
+ // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2808
+ endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2809
+ tempProducts = []; // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2810
+ if (this.store.currentProduct) {
2811
+ tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
2812
+ _schedule: this.store.currentProduct.getOtherParams()['schedule']
2813
+ })];
2814
+ }
2815
+ // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
2816
+ _ref16 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref16.resourceIds, rules = _ref16.rules, resourcesMap = _ref16.resourcesMap;
2817
+ this.otherParams.currentResourcesMap = resourcesMap;
2818
+ _context30.next = 10;
2819
+ return this.store.date.getResourceDates({
2820
+ query: {
2821
+ start_date: startDate || '',
2822
+ end_date: endDate || '',
2823
+ resource_ids: resourceIds
2824
+ },
2825
+ rules: rules,
2826
+ type: type
2827
+ });
2828
+ case 10:
2829
+ res = _context30.sent;
2830
+ if (!this.store.currentProduct) {
2831
+ _context30.next = 16;
2832
+ break;
2833
+ }
2834
+ _context30.next = 14;
2835
+ return this.getTimeslotsScheduleByDateRange({
2836
+ startDate: startDate || '',
2837
+ endDate: endDate || ''
2838
+ });
2839
+ case 14:
2840
+ dateListWithTimeSlots = _context30.sent;
2841
+ res.forEach(function (n) {
2842
+ if (!dateListWithTimeSlots[n.date]) {
2843
+ n.status = 'unavailable';
2844
+ } else {
2845
+ var allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(function (d) {
2846
+ return d.count;
2847
+ });
2848
+ if (!allTimeSlotsCanUse) {
2849
+ n.status = 'unavailable';
2850
+ }
2851
+ }
2852
+ });
2853
+ case 16:
2854
+ // 找到第一个可用的日期返回给 UI
2855
+ firstAvailableDate = res.find(function (n) {
2856
+ return n.status === 'available';
2857
+ });
2858
+ return _context30.abrupt("return", {
2859
+ dateList: res,
2860
+ firstAvailableDate: firstAvailableDate
2861
+ });
2862
+ case 18:
2863
+ case "end":
2864
+ return _context30.stop();
2865
+ }
2866
+ }, _callee29, this);
2867
+ }));
2868
+ function getAvailableDateForSession() {
2869
+ return _getAvailableDateForSession.apply(this, arguments);
2870
+ }
2871
+ return getAvailableDateForSession;
2872
+ }()
2635
2873
  }, {
2636
2874
  key: "getAvailableDateForSessionOptimize",
2637
2875
  value: function () {
2638
- var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2876
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2639
2877
  var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2640
2878
  var params,
2641
2879
  cache,
@@ -2653,22 +2891,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2653
2891
  allProductResources,
2654
2892
  targetSchedules,
2655
2893
  _loop3,
2656
- _args30 = arguments;
2657
- return _regeneratorRuntime().wrap(function _callee28$(_context30) {
2658
- while (1) switch (_context30.prev = _context30.next) {
2894
+ _args32 = arguments;
2895
+ return _regeneratorRuntime().wrap(function _callee30$(_context32) {
2896
+ while (1) switch (_context32.prev = _context32.next) {
2659
2897
  case 0:
2660
- params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
2898
+ params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
2661
2899
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2662
2900
  cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
2663
2901
  if (!cache) {
2664
- _context30.next = 5;
2902
+ _context32.next = 5;
2665
2903
  break;
2666
2904
  }
2667
2905
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2668
- _context30.next = 5;
2906
+ _context32.next = 5;
2669
2907
  break;
2670
2908
  }
2671
- return _context30.abrupt("return", {
2909
+ return _context32.abrupt("return", {
2672
2910
  dateList: cache.dateList,
2673
2911
  firstAvailableDate: cache.firstAvailableDate
2674
2912
  });
@@ -2685,7 +2923,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2685
2923
  schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
2686
2924
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2687
2925
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2688
- _context30.next = 14;
2926
+ _context32.next = 14;
2689
2927
  return this.store.date.fetchResourceDates({
2690
2928
  query: {
2691
2929
  start_date: startDate || '',
@@ -2694,7 +2932,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2694
2932
  }
2695
2933
  });
2696
2934
  case 14:
2697
- res = _context30.sent;
2935
+ res = _context32.sent;
2698
2936
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2699
2937
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2700
2938
  dates = [];
@@ -2707,8 +2945,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2707
2945
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
2708
2946
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
2709
2947
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
2710
- return _regeneratorRuntime().wrap(function _loop3$(_context29) {
2711
- while (1) switch (_context29.prev = _context29.next) {
2948
+ return _regeneratorRuntime().wrap(function _loop3$(_context31) {
2949
+ while (1) switch (_context31.prev = _context31.next) {
2712
2950
  case 0:
2713
2951
  currentDateStr = currentDate.format('YYYY-MM-DD');
2714
2952
  status = 'available'; // 1. 检查商品的提前量等情况是否满足
@@ -2800,32 +3038,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2800
3038
 
2801
3039
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
2802
3040
  if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 14)) {
2803
- _context29.next = 9;
3041
+ _context31.next = 9;
2804
3042
  break;
2805
3043
  }
2806
- return _context29.abrupt("return", 1);
3044
+ return _context31.abrupt("return", 1);
2807
3045
  case 9:
2808
3046
  currentDate = dayjs(currentDate).add(1, 'day');
2809
3047
  case 10:
2810
3048
  case "end":
2811
- return _context29.stop();
3049
+ return _context31.stop();
2812
3050
  }
2813
3051
  }, _loop3);
2814
3052
  });
2815
3053
  case 22:
2816
3054
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2817
- _context30.next = 28;
3055
+ _context32.next = 28;
2818
3056
  break;
2819
3057
  }
2820
- return _context30.delegateYield(_loop3(), "t0", 24);
3058
+ return _context32.delegateYield(_loop3(), "t0", 24);
2821
3059
  case 24:
2822
- if (!_context30.t0) {
2823
- _context30.next = 26;
3060
+ if (!_context32.t0) {
3061
+ _context32.next = 26;
2824
3062
  break;
2825
3063
  }
2826
- return _context30.abrupt("break", 28);
3064
+ return _context32.abrupt("break", 28);
2827
3065
  case 26:
2828
- _context30.next = 22;
3066
+ _context32.next = 22;
2829
3067
  break;
2830
3068
  case 28:
2831
3069
  // 最终把资源数据也加到日期内
@@ -2839,21 +3077,45 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2839
3077
  startDate: startDate,
2840
3078
  endDate: endDate
2841
3079
  });
2842
- return _context30.abrupt("return", {
3080
+ return _context32.abrupt("return", {
2843
3081
  dateList: dates,
2844
3082
  firstAvailableDate: firstAvailableDate
2845
3083
  });
2846
3084
  case 32:
2847
3085
  case "end":
2848
- return _context30.stop();
3086
+ return _context32.stop();
2849
3087
  }
2850
- }, _callee28, this);
3088
+ }, _callee30, this);
2851
3089
  }));
2852
3090
  function getAvailableDateForSessionOptimize() {
2853
3091
  return _getAvailableDateForSessionOptimize.apply(this, arguments);
2854
3092
  }
2855
3093
  return getAvailableDateForSessionOptimize;
2856
3094
  }()
3095
+ }, {
3096
+ key: "isCartAllNormalProducts",
3097
+ value: function isCartAllNormalProducts() {
3098
+ var cartItems = this.store.cart.getItems().filter(function (n) {
3099
+ return !isNormalProduct(n._productOrigin);
3100
+ });
3101
+ return !cartItems.length;
3102
+ }
3103
+ }, {
3104
+ key: "isCartHasDurationProduct",
3105
+ value: function isCartHasDurationProduct() {
3106
+ var cartItems = this.store.cart.getItems().filter(function (n) {
3107
+ return !isNormalProduct(n._productOrigin);
3108
+ });
3109
+ return cartItems.some(function (n) {
3110
+ var _n$_productOrigin4;
3111
+ return (_n$_productOrigin4 = n._productOrigin) === null || _n$_productOrigin4 === void 0 ? void 0 : _n$_productOrigin4.duration;
3112
+ });
3113
+ }
3114
+ }, {
3115
+ key: "isTargetNormalProduct",
3116
+ value: function isTargetNormalProduct(product) {
3117
+ return isNormalProduct(product);
3118
+ }
2857
3119
  }]);
2858
3120
  return BookingByStepImpl;
2859
3121
  }(BaseModule);