@pisell/pisellos 2.0.18 → 2.0.20

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.
@@ -209,7 +209,18 @@ export var handleAvailableDatesByRules = function handleAvailableDatesByRules(da
209
209
  var disabledDate = _objectSpread(_objectSpread({}, date), {}, {
210
210
  status: 'unavailable'
211
211
  });
212
-
212
+ var hasScheduleConfig = rules.find(function (n) {
213
+ var _n$schedule;
214
+ return (_n$schedule = n.schedule) === null || _n$schedule === void 0 ? void 0 : _n$schedule.length;
215
+ });
216
+ // 如果外面穿了 schedule,但是这个时候scheduleMap为空,则设置为不可用
217
+ // 这种情况为,商品设置了 5.1-5.31 可用,资源设置了 5.1-6.30 可用,session 类商品详情弹窗里里看到的6 月以后的日期都应该是不可用的
218
+ if (Object.keys(scheduleMap).length === 0 && hasScheduleConfig) {
219
+ return _objectSpread(_objectSpread({}, date), {}, {
220
+ color: '',
221
+ status: 'unavailable'
222
+ });
223
+ }
213
224
  // 根据日程判断日期是否可用
214
225
  if (Object.keys(scheduleMap).length) {
215
226
  var schedule = scheduleMap[date.date];
@@ -243,7 +243,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
243
243
 
244
244
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
245
245
  sortedProductList.forEach(function (originProduct) {
246
- var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5;
246
+ var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
247
247
  var product = _this3.hooks.getProduct(originProduct);
248
248
  if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length && product !== null && product !== void 0 && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.every(function (discount) {
249
249
  return discount.id && discount.type === 'good_pass';
@@ -271,7 +271,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
271
271
  var selectedDiscount = applicableDiscounts[0];
272
272
 
273
273
  // 如果是手动折扣,则不适用优惠券
274
- var isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && !((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length);
274
+ var isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || (product === null || product === void 0 || (_product$discount_lis6 = product.discount_list) === null || _product$discount_lis6 === void 0 || (_product$discount_lis7 = _product$discount_lis6.every) === null || _product$discount_lis7 === void 0 ? void 0 : _product$discount_lis7.call(_product$discount_lis6, function (item) {
275
+ return item.type === 'product';
276
+ })));
275
277
 
276
278
  // 勾选时覆盖手动折扣
277
279
  if (options !== null && options !== void 0 && options.discountId && (options === null || options === void 0 ? void 0 : options.discountId) === (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.id)) {
@@ -716,7 +716,7 @@ export function getAllSortedDateRanges(schedules) {
716
716
  }
717
717
 
718
718
  // 按照开始时间和时长排序
719
- return allDateRanges.sort(function (a, b) {
719
+ var sortedDateRanges = allDateRanges.sort(function (a, b) {
720
720
  // 首先按开始时间排序
721
721
  var startTimeCompare = dayjs(a.start).valueOf() - dayjs(b.start).valueOf();
722
722
  if (startTimeCompare !== 0) return startTimeCompare;
@@ -726,4 +726,13 @@ export function getAllSortedDateRanges(schedules) {
726
726
  var durationB = dayjs(b.end).valueOf() - dayjs(b.start).valueOf();
727
727
  return durationA - durationB;
728
728
  });
729
+
730
+ // 排序完了,还需要做个去重,如果有开始时间结束时间完全一致的,则只保留一个
731
+ // 需要使用 dayjs 的 isSame 方法来判断
732
+ var uniqueDateRanges = sortedDateRanges.filter(function (range, index, self) {
733
+ return index === self.findIndex(function (t) {
734
+ return dayjs(t.start).isSame(dayjs(range.start)) && dayjs(t.end).isSame(dayjs(range.end));
735
+ });
736
+ });
737
+ return uniqueDateRanges;
729
738
  }
@@ -112,8 +112,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
112
112
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
113
113
  }
114
114
  });
115
+ this.loadAllSchedule();
115
116
  this.core.effects.emit(BookingByStepHooks.onInited, {});
116
- case 15:
117
+ case 16:
117
118
  case "end":
118
119
  return _context.stop();
119
120
  }
@@ -215,6 +216,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
215
216
  });
216
217
  if (schedule_ids_data.length) {
217
218
  schedule_ids = schedule_ids_data;
219
+ } else if (schedule_date) {
220
+ // 后端说如果 schedule_ids 如果为空,需要给[0]
221
+ schedule_ids = [0];
218
222
  }
219
223
  }
220
224
  _context2.next = 4;
@@ -306,7 +310,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
306
310
  while (1) switch (_context4.prev = _context4.next) {
307
311
  case 0:
308
312
  _context4.next = 2;
309
- return this.request.get("/schedule?num=999");
313
+ return this.request.get("/schedule", {
314
+ num: 999
315
+ }, {
316
+ useCache: true
317
+ });
310
318
  case 2:
311
319
  scheduleList = _context4.sent;
312
320
  this.store.schedule.setScheduleList(((_scheduleList$data = scheduleList.data) === null || _scheduleList$data === void 0 ? void 0 : _scheduleList$data.list) || []);
@@ -1069,72 +1077,75 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1069
1077
  if (n.resource) allOriginResources.push.apply(allOriginResources, _toConsumableArray(n.resource));
1070
1078
  });
1071
1079
  }
1072
- // 更新购物车后,需要判定购物车里是否存在多个账号选择了相同资源的情况,如果是,且资源是单个预约,则要把选择了相同资源的 product._origin.resources 给去除
1073
- var cartItems = this.store.cart.getItems();
1074
- cartItems.forEach(function (item) {
1075
- if (item._id !== targetCartItem._id) {
1076
- var _item$_origin$resourc;
1077
- var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1078
- // 检查当前资源是否与目标资源的任何资源匹配
1079
- return !targetCartItem._origin.resources.some(function (targetRes) {
1080
- // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1081
- if (targetRes.resourceType !== 'single') {
1082
- var _item$_productOrigin2;
1083
- var _formatCapacity = formatDefaultCapacitys({
1084
- capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1085
- product_bundle: item._origin.product.product_bundle
1086
- });
1087
- var _currentCapacity = getSumCapacity({
1088
- capacity: _formatCapacity
1089
- });
1090
- var originResource = allOriginResources.find(function (n) {
1091
- return n.id === targetRes.id;
1092
- });
1093
- if (currentResourcesCapacityMap[targetRes.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1094
- return true;
1080
+ // 只有在更新资源的时候做这个判断,其他情况下不做处理
1081
+ if (params.resources) {
1082
+ // 更新购物车后,需要判定购物车里是否存在多个账号选择了相同资源的情况,如果是,且资源是单个预约,则要把选择了相同资源的 product._origin.resources 给去除
1083
+ var cartItems = this.store.cart.getItems();
1084
+ cartItems.forEach(function (item) {
1085
+ if (item._id !== targetCartItem._id) {
1086
+ var _item$_origin$resourc;
1087
+ var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1088
+ // 检查当前资源是否与目标资源的任何资源匹配
1089
+ return !targetCartItem._origin.resources.some(function (targetRes) {
1090
+ // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1091
+ if (targetRes.resourceType !== 'single') {
1092
+ var _item$_productOrigin2;
1093
+ var _formatCapacity = formatDefaultCapacitys({
1094
+ capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1095
+ product_bundle: item._origin.product.product_bundle
1096
+ });
1097
+ var _currentCapacity = getSumCapacity({
1098
+ capacity: _formatCapacity
1099
+ });
1100
+ var originResource = allOriginResources.find(function (n) {
1101
+ return n.id === targetRes.id;
1102
+ });
1103
+ if (currentResourcesCapacityMap[targetRes.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1104
+ return true;
1105
+ }
1106
+ currentResourcesCapacityMap[targetRes.id] += _currentCapacity;
1107
+ return false;
1108
+ }
1109
+ if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1110
+ var _targetRes$metadata$c, _m$metadata$combined_;
1111
+ // 检查主资源ID是否匹配
1112
+ if (targetRes.id === m.id) return true;
1113
+ // 检查组合资源的情况
1114
+ if (((_targetRes$metadata$c = targetRes.metadata.combined_resource) === null || _targetRes$metadata$c === void 0 ? void 0 : _targetRes$metadata$c.status) === 1 && (
1115
+ // 如果现在选择的是组合资源,需要判断
1116
+ // 1、当前其他购物车里是否选了当前组合资源的子资源
1117
+ // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
1118
+ targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some(function (n) {
1119
+ return m.metadata.combined_resource.resource_ids.includes(n);
1120
+ }))) return true;
1121
+ if (((_m$metadata$combined_ = m.metadata.combined_resource) === null || _m$metadata$combined_ === void 0 ? void 0 : _m$metadata$combined_.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id)) return true;
1095
1122
  }
1096
- currentResourcesCapacityMap[targetRes.id] += _currentCapacity;
1097
1123
  return false;
1098
- }
1099
- if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1100
- var _targetRes$metadata$c, _m$metadata$combined_;
1101
- // 检查主资源ID是否匹配
1102
- if (targetRes.id === m.id) return true;
1103
- // 检查组合资源的情况
1104
- if (((_targetRes$metadata$c = targetRes.metadata.combined_resource) === null || _targetRes$metadata$c === void 0 ? void 0 : _targetRes$metadata$c.status) === 1 && (
1105
- // 如果现在选择的是组合资源,需要判断
1106
- // 1、当前其他购物车里是否选了当前组合资源的子资源
1107
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
1108
- targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some(function (n) {
1109
- return m.metadata.combined_resource.resource_ids.includes(n);
1110
- }))) return true;
1111
- if (((_m$metadata$combined_ = m.metadata.combined_resource) === null || _m$metadata$combined_ === void 0 ? void 0 : _m$metadata$combined_.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id)) return true;
1112
- }
1113
- return false;
1114
- });
1115
- });
1116
- // session 类商品应该只调用清空 resource 的方法
1117
- if (item.start_time) {
1118
- var start_time = item.start_time;
1119
- var end_time = item.end_time;
1120
- var start_date = item.start_date;
1121
- var end_date = item.end_date;
1122
- _this5.store.cart.updateItem({
1123
- _id: item._id,
1124
- resources: resources,
1125
- date: {
1126
- startTime: dayjs("".concat(start_date, " ").concat(start_time)).format('YYYY-MM-DD HH:mm'),
1127
- endTime: dayjs("".concat(end_date, " ").concat(end_time)).format('YYYY-MM-DD HH:mm')
1128
- }
1129
- });
1130
- } else {
1131
- _this5.store.cart.updateItem({
1132
- _id: item._id,
1133
- resources: resources
1124
+ });
1134
1125
  });
1126
+ // session 类商品应该只调用清空 resource 的方法
1127
+ if (item.start_time) {
1128
+ var start_time = item.start_time;
1129
+ var end_time = item.end_time;
1130
+ var start_date = item.start_date;
1131
+ var end_date = item.end_date;
1132
+ _this5.store.cart.updateItem({
1133
+ _id: item._id,
1134
+ resources: resources,
1135
+ date: {
1136
+ startTime: dayjs("".concat(start_date, " ").concat(start_time)).format('YYYY-MM-DD HH:mm'),
1137
+ endTime: dayjs("".concat(end_date, " ").concat(end_time)).format('YYYY-MM-DD HH:mm')
1138
+ }
1139
+ });
1140
+ } else {
1141
+ _this5.store.cart.updateItem({
1142
+ _id: item._id,
1143
+ resources: resources
1144
+ });
1145
+ }
1135
1146
  }
1136
- }
1137
- });
1147
+ });
1148
+ }
1138
1149
  }
1139
1150
 
1140
1151
  // 删除购物车里某个商品
@@ -1285,6 +1296,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1285
1296
  return false;
1286
1297
  }
1287
1298
  var canUseArr = mTimes.map(function (item) {
1299
+ var _cartItem$_productOri3;
1288
1300
  var res = getIsUsableByTimeItem({
1289
1301
  timeSlice: {
1290
1302
  start_time: startTime.format('HH:mm'),
@@ -1295,7 +1307,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1295
1307
  time: item,
1296
1308
  resource: m,
1297
1309
  currentCount: currentCapacity || 0,
1298
- resourcesUseableMap: resourcesUseableMap
1310
+ resourcesUseableMap: resourcesUseableMap,
1311
+ cut_off_time: (_cartItem$_productOri3 = cartItem._productOrigin) === null || _cartItem$_productOri3 === void 0 ? void 0 : _cartItem$_productOri3.cut_off_time
1299
1312
  });
1300
1313
  // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1301
1314
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
@@ -1315,13 +1328,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1315
1328
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1316
1329
  // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1317
1330
  item.renderList = item.renderList.filter(function (n) {
1318
- var _cartItem$_productOri3;
1331
+ var _cartItem$_productOri4;
1319
1332
  var recordCount = n.capacity || 0;
1320
1333
  if (n.onlyComputed) return false;
1321
1334
  // 查一下这个资源基于商品的可用时间片
1322
1335
  var timeSlots = getTimeSlicesByResource({
1323
1336
  resource: n,
1324
- duration: ((_cartItem$_productOri3 = cartItem._productOrigin) === null || _cartItem$_productOri3 === void 0 || (_cartItem$_productOri3 = _cartItem$_productOri3.duration) === null || _cartItem$_productOri3 === void 0 ? void 0 : _cartItem$_productOri3.value) || 0,
1337
+ duration: ((_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 || (_cartItem$_productOri4 = _cartItem$_productOri4.duration) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.value) || 0,
1325
1338
  split: 10,
1326
1339
  currentDate: dateRange[0].date
1327
1340
  });
@@ -1365,10 +1378,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1365
1378
  var cartItems = this.store.cart.getItems();
1366
1379
  var arr = [];
1367
1380
  cartItems.forEach(function (cartItem) {
1368
- var _cartItem$_productOri4, _cartItem$_productOri5;
1381
+ var _cartItem$_productOri5, _cartItem$_productOri6;
1369
1382
  var selectedResources = [];
1370
1383
  var formatCapacity = formatDefaultCapacitys({
1371
- capacity: (_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.capacity,
1384
+ capacity: (_cartItem$_productOri5 = cartItem._productOrigin) === null || _cartItem$_productOri5 === void 0 ? void 0 : _cartItem$_productOri5.capacity,
1372
1385
  product_bundle: cartItem._origin.product.product_bundle
1373
1386
  });
1374
1387
  cartItem._origin.metadata.capacity = formatCapacity;
@@ -1380,7 +1393,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1380
1393
  } else {
1381
1394
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1382
1395
  }
1383
- var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri5 = cartItem._productOrigin) === null || _cartItem$_productOri5 === void 0 || (_cartItem$_productOri5 = _cartItem$_productOri5.product_resource) === null || _cartItem$_productOri5 === void 0 ? void 0 : _cartItem$_productOri5.resources) || [], selectedResources, currentCapacity);
1396
+ var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri6 = cartItem._productOrigin) === null || _cartItem$_productOri6 === void 0 || (_cartItem$_productOri6 = _cartItem$_productOri6.product_resource) === null || _cartItem$_productOri6 === void 0 ? void 0 : _cartItem$_productOri6.resources) || [], selectedResources, currentCapacity);
1384
1397
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1385
1398
  if (cartItem._origin.start_time) {
1386
1399
  var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
@@ -1408,6 +1421,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1408
1421
  return false;
1409
1422
  }
1410
1423
  var canUseArr = mTimes.map(function (item) {
1424
+ var _cartItem$_productOri7;
1411
1425
  var res = getIsUsableByTimeItem({
1412
1426
  timeSlice: {
1413
1427
  start_time: startTime.format('HH:mm'),
@@ -1418,7 +1432,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1418
1432
  time: item,
1419
1433
  resource: m,
1420
1434
  currentCount: currentCapacity || 0,
1421
- resourcesUseableMap: resourcesUseableMap
1435
+ resourcesUseableMap: resourcesUseableMap,
1436
+ cut_off_time: (_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.cut_off_time
1422
1437
  });
1423
1438
  // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1424
1439
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
@@ -1438,13 +1453,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1438
1453
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1439
1454
  // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1440
1455
  item.renderList = item.renderList.filter(function (n) {
1441
- var _cartItem$_productOri6;
1456
+ var _cartItem$_productOri8;
1442
1457
  var recordCount = n.capacity || 0;
1443
1458
  if (n.onlyComputed) return false;
1444
1459
  // 查一下这个资源基于商品的可用时间片
1445
1460
  var timeSlots = getTimeSlicesByResource({
1446
1461
  resource: n,
1447
- duration: ((_cartItem$_productOri6 = cartItem._productOrigin) === null || _cartItem$_productOri6 === void 0 || (_cartItem$_productOri6 = _cartItem$_productOri6.duration) === null || _cartItem$_productOri6 === void 0 ? void 0 : _cartItem$_productOri6.value) || 0,
1462
+ duration: ((_cartItem$_productOri8 = cartItem._productOrigin) === null || _cartItem$_productOri8 === void 0 || (_cartItem$_productOri8 = _cartItem$_productOri8.duration) === null || _cartItem$_productOri8 === void 0 ? void 0 : _cartItem$_productOri8.value) || 0,
1448
1463
  split: 10,
1449
1464
  currentDate: dateRange[0].date
1450
1465
  });
@@ -1546,7 +1561,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1546
1561
  }, {
1547
1562
  key: "autoSelectAccountResources",
1548
1563
  value: function autoSelectAccountResources(_ref8) {
1549
- var _cartItem$_productOri7, _allProductResources$;
1564
+ var _cartItem$_productOri9, _allProductResources$;
1550
1565
  var cartItem = _ref8.cartItem,
1551
1566
  holder_id = _ref8.holder_id,
1552
1567
  resources_code = _ref8.resources_code,
@@ -1595,7 +1610,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1595
1610
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1596
1611
  var allCartItems = cloneDeep(this.store.cart.getItems());
1597
1612
  var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1598
- var allProductResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 || (_cartItem$_productOri7 = _cartItem$_productOri7.product_resource) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.resources) || [], selectedResources, 1);
1613
+ var allProductResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri9 = cartItem._productOrigin) === null || _cartItem$_productOri9 === void 0 || (_cartItem$_productOri9 = _cartItem$_productOri9.product_resource) === null || _cartItem$_productOri9 === void 0 ? void 0 : _cartItem$_productOri9.resources) || [], selectedResources, 1);
1599
1614
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1600
1615
  return n.code === resources_code;
1601
1616
  })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
@@ -1645,12 +1660,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1645
1660
  return 0; // continue
1646
1661
  }
1647
1662
  var canUseTime = mTimes.find(function (item) {
1663
+ var _cartItem$_productOri10;
1648
1664
  var res = getIsUsableByTimeItem({
1649
1665
  timeSlice: timeSlots,
1650
1666
  time: item,
1651
1667
  resource: n,
1652
1668
  currentCount: recordCount + (capacity || 0),
1653
- resourcesUseableMap: resourcesUseableMap
1669
+ resourcesUseableMap: resourcesUseableMap,
1670
+ cut_off_time: (_cartItem$_productOri10 = cartItem._productOrigin) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.cut_off_time
1654
1671
  });
1655
1672
  // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1656
1673
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
@@ -1745,16 +1762,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1745
1762
  };
1746
1763
  }
1747
1764
  if (recordTimeSlots) {
1748
- var _item$_productOrigin4;
1765
+ var _item$_productOrigin4, _item$_productOrigin5;
1749
1766
  // 同一账号下,如果当前商品不是第一个,则需要根据上一个商品的 end_time 和 duration 计算出当前商品的 start_time 和 end_time
1750
1767
  // 前提:当前资源是单个预约才需要这么做
1751
1768
  var currentResourceConfig = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.product_resource) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.resources) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.find(function (n) {
1752
1769
  return n.code === resources_code;
1753
1770
  });
1754
- if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single') {
1755
- var _item$_productOrigin$, _item$_productOrigin5, _ref9, _item$_productOrigin6, _item$_productOrigin$2, _item$_productOrigin7, _ref10, _item$_productOrigin8;
1756
- var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref9 = (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.type) !== null && _ref9 !== void 0 ? _ref9 : 'minutes');
1757
- var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref10 = (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.duration) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
1771
+ // 只有 duration 类商品需要这个操作
1772
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single' && (_item$_productOrigin5 = item._productOrigin) !== null && _item$_productOrigin5 !== void 0 && _item$_productOrigin5.duration) {
1773
+ var _item$_productOrigin$, _item$_productOrigin6, _ref9, _item$_productOrigin7, _item$_productOrigin$2, _item$_productOrigin8, _ref10, _item$_productOrigin9;
1774
+ var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref9 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.type) !== null && _ref9 !== void 0 ? _ref9 : 'minutes');
1775
+ var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.duration) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref10 = (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.duration) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
1758
1776
  recordTimeSlots = {
1759
1777
  start_time: start_at.format('HH:mm'),
1760
1778
  end_time: end_at.format('HH:mm'),
@@ -1796,12 +1814,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1796
1814
  errorList.push(item._id);
1797
1815
  }
1798
1816
  } else {
1799
- var _item$_productOrigin9, _productResources$fin;
1817
+ var _item$_productOrigin10, _productResources$fin;
1800
1818
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1801
1819
  var allCartItems = cloneDeep(_this8.store.cart.getItems());
1802
1820
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1803
1821
  var selectedResources = [];
1804
- var _resources = cloneDeep(((_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.product_resource) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.resources) || []);
1822
+ var _resources = cloneDeep(((_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.product_resource) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.resources) || []);
1805
1823
  var currentResourcesRenderList = [];
1806
1824
  _resources.forEach(function (n) {
1807
1825
  var _n$renderList;
@@ -1900,11 +1918,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1900
1918
  // if (cartItems?.[0].start_date) return [];
1901
1919
  var resourceIds = [];
1902
1920
  var resourcesTypeId = undefined;
1921
+ var isSingleResource = false;
1903
1922
  cartItems.forEach(function (item) {
1904
- var _item$_productOrigin10, _item$_productOrigin11;
1905
- (_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.product_resource) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.resources) === null || _item$_productOrigin10 === void 0 || _item$_productOrigin10.forEach(function (n) {
1923
+ var _item$_productOrigin11, _item$_productOrigin12;
1924
+ (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.product_resource) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.resources) === null || _item$_productOrigin11 === void 0 || _item$_productOrigin11.forEach(function (n) {
1906
1925
  if (n.code === resources_code) {
1907
1926
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1927
+ isSingleResource = n.type === 'single';
1908
1928
  }
1909
1929
  });
1910
1930
  // item._origin.resources?.forEach((n: any) => {
@@ -1913,9 +1933,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1913
1933
  if (item.resource_id) {
1914
1934
  resourceIds.push(item.resource_id);
1915
1935
  }
1916
- resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.product_resource) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.resources) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.find(function (n) {
1936
+ resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.product_resource) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.resources) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.find(function (n) {
1917
1937
  return n.code === resources_code;
1918
- })) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.id;
1938
+ })) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.id;
1919
1939
  });
1920
1940
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
1921
1941
  if ((_dateRange = dateRange) !== null && _dateRange !== void 0 && (_dateRange = _dateRange[0]) !== null && _dateRange !== void 0 && (_dateRange = _dateRange.resource) !== null && _dateRange !== void 0 && _dateRange.length) {
@@ -1935,8 +1955,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1935
1955
  var checkDuration = function checkDuration(cartItems) {
1936
1956
  var accountDuration = 0;
1937
1957
  cartItems.forEach(function (item) {
1938
- var _item$_productOrigin$3, _item$_productOrigin12;
1939
- accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.duration) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1958
+ // 单个预约累加账号 多个预约取最大值
1959
+ if (isSingleResource) {
1960
+ var _item$_productOrigin$3, _item$_productOrigin13;
1961
+ accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin13 = item._productOrigin) === null || _item$_productOrigin13 === void 0 || (_item$_productOrigin13 = _item$_productOrigin13.duration) === null || _item$_productOrigin13 === void 0 ? void 0 : _item$_productOrigin13.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1962
+ } else {
1963
+ var _item$_productOrigin$4, _item$_productOrigin14;
1964
+ if (accountDuration < ((_item$_productOrigin$4 = (_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 || (_item$_productOrigin14 = _item$_productOrigin14.duration) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0)) {
1965
+ var _item$_productOrigin$5, _item$_productOrigin15;
1966
+ accountDuration = (_item$_productOrigin$5 = (_item$_productOrigin15 = item._productOrigin) === null || _item$_productOrigin15 === void 0 || (_item$_productOrigin15 = _item$_productOrigin15.duration) === null || _item$_productOrigin15 === void 0 ? void 0 : _item$_productOrigin15.value) !== null && _item$_productOrigin$5 !== void 0 ? _item$_productOrigin$5 : 0;
1967
+ }
1968
+ }
1940
1969
  });
1941
1970
  if (accountDuration > duration) {
1942
1971
  duration = accountDuration;
@@ -2006,9 +2035,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2006
2035
  var _newResources$;
2007
2036
  var newResources = cloneDeep(item._origin.resources);
2008
2037
  newResources.forEach(function (resource) {
2009
- var _item$_productOrigin$4, _item$_productOrigin13, _ref11, _item$_productOrigin14;
2038
+ var _item$_productOrigin$6, _item$_productOrigin16, _ref11, _item$_productOrigin17;
2010
2039
  resource.startTime = currentStartTime;
2011
- resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_item$_productOrigin13 = item._productOrigin) === null || _item$_productOrigin13 === void 0 || (_item$_productOrigin13 = _item$_productOrigin13.duration) === null || _item$_productOrigin13 === void 0 ? void 0 : _item$_productOrigin13.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref11 = (_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 || (_item$_productOrigin14 = _item$_productOrigin14.duration) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes').format('YYYY-MM-DD HH:mm');
2040
+ resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$6 = (_item$_productOrigin16 = item._productOrigin) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.duration) === null || _item$_productOrigin16 === void 0 ? void 0 : _item$_productOrigin16.value) !== null && _item$_productOrigin$6 !== void 0 ? _item$_productOrigin$6 : 0, (_ref11 = (_item$_productOrigin17 = item._productOrigin) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.duration) === null || _item$_productOrigin17 === void 0 ? void 0 : _item$_productOrigin17.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes').format('YYYY-MM-DD HH:mm');
2012
2041
  delete resource.times;
2013
2042
  });
2014
2043
  _this10.store.cart.updateItem({
@@ -37,6 +37,11 @@ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, curren
37
37
  future_day: number;
38
38
  unit: number;
39
39
  unit_type: string;
40
+ type: string;
41
+ ongoing?: {
42
+ type: string;
43
+ unit: number;
44
+ } | undefined;
40
45
  } | undefined;
41
46
  }) => {
42
47
  afterToDay: boolean;
@@ -190,14 +190,32 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
190
190
  };
191
191
  // 最早可预约时间为 当前日期之后并且提前量之后
192
192
  var earliest = dayjs();
193
+ var canBookingForOngoing = false;
193
194
  var _ref3 = cut_off_time || {},
194
195
  unit = _ref3.unit,
195
- unit_type = _ref3.unit_type;
196
- if (unit) {
197
- earliest = earliest.add(unit, unit_type);
196
+ unit_type = _ref3.unit_type,
197
+ type = _ref3.type,
198
+ ongoing = _ref3.ongoing;
199
+ // 允许购买已开始的活动
200
+ if (type === 'ongoing' && (ongoing === null || ongoing === void 0 ? void 0 : ongoing.type) === 'after_start') {
201
+ // 如果timeSlice.start_at 小于当前时间,判断当前时间是否在如果timeSlice.start_at+ongoing.unit之间
202
+ // 即,如果现在是15:30,timeSlice.start_at是15:00,ongoing.unit是60分钟,则允许预约
203
+ if (dayjs(timeSlice.start_at).isBefore(dayjs())) {
204
+ if (earliest.isBefore(dayjs(timeSlice.start_at).add(ongoing.unit, 'minute'))) {
205
+ canBookingForOngoing = true;
206
+ }
207
+ }
208
+ } else if (type === 'ongoing' && (ongoing === null || ongoing === void 0 ? void 0 : ongoing.type) === 'before_end') {
209
+ if (dayjs(timeSlice.end_at).isAfter(earliest)) {
210
+ canBookingForOngoing = true;
211
+ }
212
+ } else {
213
+ if (unit) {
214
+ earliest = earliest.add(unit, unit_type);
215
+ }
198
216
  }
199
217
  // 不可预约提前量时间之前的
200
- if (!checkAfterToDay(timeSlice.start_at, earliest)) {
218
+ if (!checkAfterToDay(timeSlice.start_at, earliest) && !canBookingForOngoing) {
201
219
  return status;
202
220
  }
203
221
  status.afterToDay = true;
@@ -155,6 +155,13 @@ var handleAvailableDatesByRules = (dates, rules) => {
155
155
  newDates = newDates.map((date) => {
156
156
  var _a;
157
157
  const disabledDate = { ...date, status: "unavailable" };
158
+ const hasScheduleConfig = rules.find((n) => {
159
+ var _a2;
160
+ return (_a2 = n.schedule) == null ? void 0 : _a2.length;
161
+ });
162
+ if (Object.keys(scheduleMap).length === 0 && hasScheduleConfig) {
163
+ return { ...date, color: "", status: "unavailable" };
164
+ }
158
165
  if (Object.keys(scheduleMap).length) {
159
166
  const schedule = scheduleMap[date.date];
160
167
  if (!schedule || (schedule == null ? void 0 : schedule.isExcluded)) {
@@ -154,7 +154,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
154
154
  });
155
155
  });
156
156
  sortedProductList.forEach((originProduct) => {
157
- var _a, _b, _c;
157
+ var _a, _b, _c, _d, _e;
158
158
  const product = this.hooks.getProduct(originProduct);
159
159
  if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && discount.type === "good_pass"))) {
160
160
  processedProductsMap.set(product._id, originProduct);
@@ -172,7 +172,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
172
172
  return false;
173
173
  });
174
174
  const selectedDiscount = applicableDiscounts[0];
175
- let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && !((_c = product.discount_list) == null ? void 0 : _c.length);
175
+ let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (!((_c = product.discount_list) == null ? void 0 : _c.length) || ((_e = (_d = product == null ? void 0 : product.discount_list) == null ? void 0 : _d.every) == null ? void 0 : _e.call(_d, (item) => item.type === "product")));
176
176
  if ((options == null ? void 0 : options.discountId) && (options == null ? void 0 : options.discountId) === (selectedDiscount == null ? void 0 : selectedDiscount.id)) {
177
177
  isManualDiscount = false;
178
178
  }
@@ -573,7 +573,7 @@ function getAllSortedDateRanges(schedules) {
573
573
  console.log("No dateRanges found in schedules:", schedules);
574
574
  return [];
575
575
  }
576
- return allDateRanges.sort((a, b) => {
576
+ let sortedDateRanges = allDateRanges.sort((a, b) => {
577
577
  const startTimeCompare = (0, import_dayjs.default)(a.start).valueOf() - (0, import_dayjs.default)(b.start).valueOf();
578
578
  if (startTimeCompare !== 0)
579
579
  return startTimeCompare;
@@ -581,6 +581,10 @@ function getAllSortedDateRanges(schedules) {
581
581
  const durationB = (0, import_dayjs.default)(b.end).valueOf() - (0, import_dayjs.default)(b.start).valueOf();
582
582
  return durationA - durationB;
583
583
  });
584
+ const uniqueDateRanges = sortedDateRanges.filter(
585
+ (range, index, self) => index === self.findIndex((t) => (0, import_dayjs.default)(t.start).isSame((0, import_dayjs.default)(range.start)) && (0, import_dayjs.default)(t.end).isSame((0, import_dayjs.default)(range.end)))
586
+ );
587
+ return uniqueDateRanges;
584
588
  }
585
589
  // Annotate the CommonJS export names for ESM import in node:
586
590
  0 && (module.exports = {
@@ -102,6 +102,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
102
102
  throw new Error(`模块 ${step} 不存在`);
103
103
  }
104
104
  });
105
+ this.loadAllSchedule();
105
106
  this.core.effects.emit(import_types.BookingByStepHooks.onInited, {});
106
107
  }
107
108
  // 初始化step
@@ -164,6 +165,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
164
165
  const schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map((n) => n.id);
165
166
  if (schedule_ids_data.length) {
166
167
  schedule_ids = schedule_ids_data;
168
+ } else if (schedule_date) {
169
+ schedule_ids = [0];
167
170
  }
168
171
  }
169
172
  const productsData = await this.request.post(
@@ -214,7 +217,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
214
217
  // 加载当前店铺下所有 schedule
215
218
  async loadAllSchedule() {
216
219
  var _a;
217
- const scheduleList = await this.request.get(`/schedule?num=999`);
220
+ const scheduleList = await this.request.get(`/schedule`, { num: 999 }, { useCache: true });
218
221
  this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
219
222
  }
220
223
  // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
@@ -527,69 +530,71 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
527
530
  allOriginResources.push(...n.resource);
528
531
  });
529
532
  }
530
- const cartItems = this.store.cart.getItems();
531
- cartItems.forEach((item) => {
532
- var _a2;
533
- if (item._id !== targetCartItem._id) {
534
- const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
535
- return !targetCartItem._origin.resources.some((targetRes) => {
536
- var _a3, _b, _c;
537
- if (targetRes.resourceType !== "single") {
538
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
539
- capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
540
- product_bundle: item._origin.product.product_bundle
541
- });
542
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
543
- const originResource = allOriginResources.find((n) => n.id === targetRes.id);
544
- if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
545
- return true;
533
+ if (params.resources) {
534
+ const cartItems = this.store.cart.getItems();
535
+ cartItems.forEach((item) => {
536
+ var _a2;
537
+ if (item._id !== targetCartItem._id) {
538
+ const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
539
+ return !targetCartItem._origin.resources.some((targetRes) => {
540
+ var _a3, _b, _c;
541
+ if (targetRes.resourceType !== "single") {
542
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
543
+ capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
544
+ product_bundle: item._origin.product.product_bundle
545
+ });
546
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
547
+ const originResource = allOriginResources.find((n) => n.id === targetRes.id);
548
+ if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
549
+ return true;
550
+ }
551
+ currentResourcesCapacityMap[targetRes.id] += currentCapacity;
552
+ return false;
553
+ }
554
+ if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
555
+ if (targetRes.id === m.id)
556
+ return true;
557
+ if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
558
+ // 1、当前其他购物车里是否选了当前组合资源的子资源
559
+ // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
560
+ (targetRes.metadata.combined_resource.resource_ids.includes(
561
+ m.id
562
+ ) || targetRes.metadata.combined_resource.resource_ids.some(
563
+ (n) => {
564
+ return m.metadata.combined_resource.resource_ids.includes(
565
+ n
566
+ );
567
+ }
568
+ )))
569
+ return true;
570
+ if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
571
+ return true;
546
572
  }
547
- currentResourcesCapacityMap[targetRes.id] += currentCapacity;
548
573
  return false;
549
- }
550
- if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
551
- if (targetRes.id === m.id)
552
- return true;
553
- if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
554
- // 1、当前其他购物车里是否选了当前组合资源的子资源
555
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
556
- (targetRes.metadata.combined_resource.resource_ids.includes(
557
- m.id
558
- ) || targetRes.metadata.combined_resource.resource_ids.some(
559
- (n) => {
560
- return m.metadata.combined_resource.resource_ids.includes(
561
- n
562
- );
563
- }
564
- )))
565
- return true;
566
- if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
567
- return true;
568
- }
569
- return false;
570
- });
571
- });
572
- if (item.start_time) {
573
- const start_time = item.start_time;
574
- const end_time = item.end_time;
575
- const start_date = item.start_date;
576
- const end_date = item.end_date;
577
- this.store.cart.updateItem({
578
- _id: item._id,
579
- resources,
580
- date: {
581
- startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format("YYYY-MM-DD HH:mm"),
582
- endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format("YYYY-MM-DD HH:mm")
583
- }
584
- });
585
- } else {
586
- this.store.cart.updateItem({
587
- _id: item._id,
588
- resources
574
+ });
589
575
  });
576
+ if (item.start_time) {
577
+ const start_time = item.start_time;
578
+ const end_time = item.end_time;
579
+ const start_date = item.start_date;
580
+ const end_date = item.end_date;
581
+ this.store.cart.updateItem({
582
+ _id: item._id,
583
+ resources,
584
+ date: {
585
+ startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format("YYYY-MM-DD HH:mm"),
586
+ endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format("YYYY-MM-DD HH:mm")
587
+ }
588
+ });
589
+ } else {
590
+ this.store.cart.updateItem({
591
+ _id: item._id,
592
+ resources
593
+ });
594
+ }
590
595
  }
591
- }
592
- });
596
+ });
597
+ }
593
598
  }
594
599
  // 删除购物车里某个商品
595
600
  deleteCart(cartItemId) {
@@ -725,6 +730,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
725
730
  return false;
726
731
  }
727
732
  const canUseArr = mTimes.map((item) => {
733
+ var _a2;
728
734
  const res = (0, import_resources.getIsUsableByTimeItem)({
729
735
  timeSlice: {
730
736
  start_time: startTime.format("HH:mm"),
@@ -735,7 +741,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
735
741
  time: item,
736
742
  resource: m,
737
743
  currentCount: currentCapacity || 0,
738
- resourcesUseableMap
744
+ resourcesUseableMap,
745
+ cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
739
746
  });
740
747
  if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
741
748
  resourcesUseableMap[m.id] = res.usable;
@@ -852,6 +859,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
852
859
  return false;
853
860
  }
854
861
  const canUseArr = mTimes.map((item) => {
862
+ var _a2;
855
863
  const res = (0, import_resources.getIsUsableByTimeItem)({
856
864
  timeSlice: {
857
865
  start_time: startTime.format("HH:mm"),
@@ -862,7 +870,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
862
870
  time: item,
863
871
  resource: m,
864
872
  currentCount: currentCapacity || 0,
865
- resourcesUseableMap
873
+ resourcesUseableMap,
874
+ cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
866
875
  });
867
876
  if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
868
877
  resourcesUseableMap[m.id] = res.usable;
@@ -1056,12 +1065,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1056
1065
  continue;
1057
1066
  }
1058
1067
  const canUseTime = mTimes.find((item) => {
1068
+ var _a2;
1059
1069
  const res = (0, import_resources.getIsUsableByTimeItem)({
1060
1070
  timeSlice: timeSlots,
1061
1071
  time: item,
1062
1072
  resource: n,
1063
1073
  currentCount: recordCount + (capacity || 0),
1064
- resourcesUseableMap
1074
+ resourcesUseableMap,
1075
+ cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
1065
1076
  });
1066
1077
  if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== "capacityOnly") {
1067
1078
  resourcesUseableMap[n.id] = res.usable;
@@ -1114,7 +1125,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1114
1125
  const selectForCartResources = (cartItems2) => {
1115
1126
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
1116
1127
  cartItems2.forEach((item, index) => {
1117
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1128
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1118
1129
  const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
1119
1130
  capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
1120
1131
  product_bundle: item._origin.product.product_bundle
@@ -1130,14 +1141,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1130
1141
  }
1131
1142
  if (recordTimeSlots) {
1132
1143
  const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find((n) => n.code === resources_code);
1133
- if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single") {
1144
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
1134
1145
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
1135
- ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) ?? 0,
1136
- ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.type) ?? "minutes"
1146
+ ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) ?? 0,
1147
+ ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.type) ?? "minutes"
1137
1148
  );
1138
1149
  let end_at = start_at.add(
1139
- ((_j = (_i = item._productOrigin) == null ? void 0 : _i.duration) == null ? void 0 : _j.value) ?? 0,
1140
- ((_l = (_k = item._productOrigin) == null ? void 0 : _k.duration) == null ? void 0 : _l.type) ?? "minutes"
1150
+ ((_k = (_j = item._productOrigin) == null ? void 0 : _j.duration) == null ? void 0 : _k.value) ?? 0,
1151
+ ((_m = (_l = item._productOrigin) == null ? void 0 : _l.duration) == null ? void 0 : _m.type) ?? "minutes"
1141
1152
  );
1142
1153
  recordTimeSlots = {
1143
1154
  start_time: start_at.format("HH:mm"),
@@ -1182,7 +1193,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1182
1193
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1183
1194
  let selectedResources = [];
1184
1195
  const resources2 = (0, import_lodash_es.cloneDeep)(
1185
- ((_n = (_m = item._productOrigin) == null ? void 0 : _m.product_resource) == null ? void 0 : _n.resources) || []
1196
+ ((_o = (_n = item._productOrigin) == null ? void 0 : _n.product_resource) == null ? void 0 : _o.resources) || []
1186
1197
  );
1187
1198
  const currentResourcesRenderList = [];
1188
1199
  resources2.forEach((n) => {
@@ -1230,11 +1241,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1230
1241
  return recordCount >= currentCapacity;
1231
1242
  });
1232
1243
  });
1233
- const targetRenderList = (_o = productResources.find(
1244
+ const targetRenderList = (_p = productResources.find(
1234
1245
  (n) => n.code === resources_code
1235
- )) == null ? void 0 : _o.renderList;
1246
+ )) == null ? void 0 : _p.renderList;
1236
1247
  if (targetRenderList && targetRenderList.length > 0) {
1237
- if ((_p = item._origin.resources) == null ? void 0 : _p.some(
1248
+ if ((_q = item._origin.resources) == null ? void 0 : _q.some(
1238
1249
  (n) => n.form_id === targetRenderList[0].form_id
1239
1250
  )) {
1240
1251
  return;
@@ -1281,11 +1292,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1281
1292
  const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1282
1293
  const resourceIds = [];
1283
1294
  let resourcesTypeId = void 0;
1295
+ let isSingleResource = false;
1284
1296
  cartItems.forEach((item) => {
1285
1297
  var _a2, _b2, _c2, _d2, _e2, _f2, _g;
1286
1298
  (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
1287
1299
  if (n.code === resources_code) {
1288
1300
  resources.push(...n.renderList || []);
1301
+ isSingleResource = n.type === "single";
1289
1302
  }
1290
1303
  });
1291
1304
  if (item.resource_id) {
@@ -1308,8 +1321,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1308
1321
  const checkDuration = (cartItems2) => {
1309
1322
  let accountDuration = 0;
1310
1323
  cartItems2.forEach((item) => {
1311
- var _a2, _b2;
1312
- accountDuration += ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0;
1324
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1325
+ if (isSingleResource) {
1326
+ accountDuration += ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0;
1327
+ } else {
1328
+ if (accountDuration < (((_d2 = (_c2 = item._productOrigin) == null ? void 0 : _c2.duration) == null ? void 0 : _d2.value) ?? 0)) {
1329
+ accountDuration = ((_f2 = (_e2 = item._productOrigin) == null ? void 0 : _e2.duration) == null ? void 0 : _f2.value) ?? 0;
1330
+ }
1331
+ }
1313
1332
  });
1314
1333
  if (accountDuration > duration) {
1315
1334
  duration = accountDuration;
@@ -37,6 +37,11 @@ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, curren
37
37
  future_day: number;
38
38
  unit: number;
39
39
  unit_type: string;
40
+ type: string;
41
+ ongoing?: {
42
+ type: string;
43
+ unit: number;
44
+ } | undefined;
40
45
  } | undefined;
41
46
  }) => {
42
47
  afterToDay: boolean;
@@ -141,11 +141,24 @@ var getIsUsableByTimeItem = ({
141
141
  reason: ""
142
142
  };
143
143
  let earliest = (0, import_dayjs.default)();
144
- const { unit, unit_type } = cut_off_time || {};
145
- if (unit) {
146
- earliest = earliest.add(unit, unit_type);
144
+ let canBookingForOngoing = false;
145
+ const { unit, unit_type, type, ongoing } = cut_off_time || {};
146
+ if (type === "ongoing" && (ongoing == null ? void 0 : ongoing.type) === "after_start") {
147
+ if ((0, import_dayjs.default)(timeSlice.start_at).isBefore((0, import_dayjs.default)())) {
148
+ if (earliest.isBefore((0, import_dayjs.default)(timeSlice.start_at).add(ongoing.unit, "minute"))) {
149
+ canBookingForOngoing = true;
150
+ }
151
+ }
152
+ } else if (type === "ongoing" && (ongoing == null ? void 0 : ongoing.type) === "before_end") {
153
+ if ((0, import_dayjs.default)(timeSlice.end_at).isAfter(earliest)) {
154
+ canBookingForOngoing = true;
155
+ }
156
+ } else {
157
+ if (unit) {
158
+ earliest = earliest.add(unit, unit_type);
159
+ }
147
160
  }
148
- if (!checkAfterToDay(timeSlice.start_at, earliest)) {
161
+ if (!checkAfterToDay(timeSlice.start_at, earliest) && !canBookingForOngoing) {
149
162
  return status;
150
163
  }
151
164
  status.afterToDay = true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.18",
4
+ "version": "2.0.20",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",