@pisell/pisellos 3.0.32 → 3.0.34

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.
@@ -27,12 +27,17 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
27
27
  import { BaseModule } from "../../modules/BaseModule";
28
28
  import { BookingByStepHooks, createModule } from "./types";
29
29
  import { getAvailableProductResources } from "./utils/products";
30
- import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, formatDefaultCapacitys, getSumCapacity, checkSubResourcesCapacity, getOthersCartSelectedResources } from "./utils/resources";
30
+ import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, formatDefaultCapacitys, getSumCapacity, checkSubResourcesCapacity, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, getResourcesIdsByProduct, sortCombinedResources } from "./utils/resources";
31
31
  import dayjs from 'dayjs';
32
+ import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
33
+ import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
34
+ dayjs.extend(isSameOrBefore);
35
+ dayjs.extend(isSameOrAfter);
32
36
  import { getResourcesMap } from "../../modules/Resource/utils";
33
37
  import { cloneDeep } from 'lodash-es';
34
38
  import { calcCalendarDataByScheduleResult, calcMinTimeMaxTimeBySchedules, getAllSortedDateRanges } from "../../modules/Schedule/utils";
35
- import { disableAllDates, disableDatesBeforeOneDay, generateMonthDates } from "../../modules/Date/utils";
39
+ import { disableAllDates, disableDatesBeforeOneDay, generateMonthDates, handleAvailableDateByResource } from "../../modules/Date/utils";
40
+ import { calculateResourceAvailableTime, findFastestAvailableResource } from "./utils/timeslots";
36
41
  export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
37
42
  _inherits(BookingByStepImpl, _BaseModule);
38
43
  var _super = _createSuper(BookingByStepImpl);
@@ -267,7 +272,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
267
272
  key: "loadProductByScheduleDate",
268
273
  value: function () {
269
274
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
270
- var date, product_ids, _ref2$category_ids, category_ids, scheduleList, scheduleIds;
275
+ var _product_ids;
276
+ var date, product_ids, _ref2$category_ids, category_ids, scheduleList, scheduleIds, _schedule$product_ids, schedule;
271
277
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
272
278
  while (1) switch (_context3.prev = _context3.next) {
273
279
  case 0:
@@ -288,17 +294,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
288
294
  return n.date === date;
289
295
  }).flatMap(function (n) {
290
296
  return n.schedule_id;
291
- });
292
- _context3.next = 6;
297
+ }).filter(function (n) {
298
+ return n !== null && n !== undefined;
299
+ }); // 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
300
+ if (!((_product_ids = product_ids) !== null && _product_ids !== void 0 && _product_ids.length)) {
301
+ schedule = scheduleList.find(function (n) {
302
+ return n.date === date;
303
+ });
304
+ if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
305
+ product_ids = schedule.product_ids;
306
+ }
307
+ }
308
+ _context3.next = 7;
293
309
  return this.loadProducts({
294
310
  schedule_ids: scheduleIds,
295
311
  product_ids: product_ids,
296
312
  category_ids: category_ids,
297
313
  schedule_date: date
298
314
  });
299
- case 6:
300
- return _context3.abrupt("return", _context3.sent);
301
315
  case 7:
316
+ return _context3.abrupt("return", _context3.sent);
317
+ case 8:
302
318
  case "end":
303
319
  return _context3.stop();
304
320
  }
@@ -321,7 +337,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
321
337
  // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
322
338
  cartItems = this.store.cart.getItems();
323
339
  if (!cartItems.length) {
324
- _context5.next = 25;
340
+ _context5.next = 24;
325
341
  break;
326
342
  }
327
343
  userPlugin = this.core.getPlugin('user');
@@ -413,8 +429,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
413
429
  _iterator.f();
414
430
  return _context5.finish(21);
415
431
  case 24:
416
- ;
417
- case 25:
418
432
  case "end":
419
433
  return _context5.stop();
420
434
  }
@@ -1241,7 +1255,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1241
1255
  var _item$_origin$resourc;
1242
1256
  var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1243
1257
  // 检查当前资源是否与目标资源的任何资源匹配
1244
- return !targetCartItem._origin.resources.some(function (targetRes) {
1258
+ // 目标资源,应该只取跟当前 m.form_id 相同的资源
1259
+ var sameFormIdResources = targetCartItem._origin.resources.filter(function (n) {
1260
+ return n.form_id === m.form_id;
1261
+ });
1262
+ if (!(sameFormIdResources !== null && sameFormIdResources !== void 0 && sameFormIdResources.length)) {
1263
+ return true;
1264
+ }
1265
+ return !sameFormIdResources.some(function (targetRes) {
1245
1266
  // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1246
1267
  if (targetRes.resourceType !== 'single') {
1247
1268
  var _item$_productOrigin2;
@@ -1255,10 +1276,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1255
1276
  var originResource = allOriginResources.find(function (n) {
1256
1277
  return n.id === targetRes.id;
1257
1278
  });
1258
- if (currentResourcesCapacityMap[targetRes.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1279
+ if (currentResourcesCapacityMap[m.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1259
1280
  return true;
1260
1281
  }
1261
- currentResourcesCapacityMap[targetRes.id] += _currentCapacity;
1282
+ currentResourcesCapacityMap[m.id] += _currentCapacity;
1262
1283
  return false;
1263
1284
  }
1264
1285
  if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
@@ -1793,6 +1814,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1793
1814
  // .format("HH:mm");
1794
1815
  // 根据 start_time 和 end_time 去匹配资源
1795
1816
  var targetResource = null;
1817
+ var targetResourceTime = 0;
1796
1818
  var _iterator3 = _createForOfIteratorHelper(resources),
1797
1819
  _step3;
1798
1820
  try {
@@ -1835,8 +1857,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1835
1857
  }
1836
1858
  return res.usable;
1837
1859
  });
1838
- if (canUseTime && !n.onlyComputed) {
1860
+ var currentResourceIdleTime = calculateResourceAvailableTime({
1861
+ resource: n,
1862
+ timeSlots: timeSlots,
1863
+ currentCapacity: totalCapacity + (capacity || 0)
1864
+ });
1865
+ if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
1839
1866
  targetResource = n;
1867
+ targetResourceTime = currentResourceIdleTime;
1840
1868
  return 1; // break
1841
1869
  }
1842
1870
  },
@@ -2034,7 +2062,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2034
2062
  })) {
2035
2063
  return;
2036
2064
  }
2037
- var targetResource = targetRenderList[0];
2065
+ var fastestResource = findFastestAvailableResource({
2066
+ resources: targetRenderList,
2067
+ currentCapacity: currentCapacity,
2068
+ countMap: selectResourcesMap
2069
+ });
2070
+ var targetResource = fastestResource || targetRenderList[0];
2038
2071
  targetResource.capacity = currentCapacity;
2039
2072
  // 在这里处理 children 的数据
2040
2073
  checkSubResourcesCapacity(targetResource);
@@ -2330,7 +2363,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2330
2363
  var productResources = getResourcesByProduct(resourcesMap, resources || ((_this$store$currentPr2 = this.store.currentProduct) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.getData()) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.product_resource) === null || _this$store$currentPr2 === void 0 ? void 0 : _this$store$currentPr2.resources) || [], selectedResources, 1);
2331
2364
  var minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, date);
2332
2365
  var scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime);
2333
- console.log('scheduleTimeSlots:', scheduleTimeSlots, productResources);
2334
2366
  // 当前所有待选择资源的集合,先提出来,提升性能
2335
2367
  var allProductResources = productResources.flatMap(function (n) {
2336
2368
  return n.renderList;
@@ -2501,7 +2533,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2501
2533
  *
2502
2534
  * @param {string} cartItemId
2503
2535
  * @param {string} resourceCode
2504
- * @return {*}
2536
+ * @return {*}
2505
2537
  * @memberof BookingByStepImpl
2506
2538
  */
2507
2539
  }, {
@@ -2604,25 +2636,78 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2604
2636
  }
2605
2637
  return targetResource.renderList;
2606
2638
  }
2639
+
2640
+ /**
2641
+ * 根据日期范围批量获取时间槽
2642
+ * @param params 参数对象
2643
+ * @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
2644
+ */
2645
+ }, {
2646
+ key: "getTimeslotsScheduleByDateRange",
2647
+ value: (function () {
2648
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(_ref15) {
2649
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i, _dates, date;
2650
+ return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2651
+ while (1) switch (_context29.prev = _context29.next) {
2652
+ case 0:
2653
+ startDate = _ref15.startDate, endDate = _ref15.endDate, scheduleIds = _ref15.scheduleIds, resources = _ref15.resources;
2654
+ console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
2655
+ startDate: startDate,
2656
+ endDate: endDate,
2657
+ scheduleIds: scheduleIds,
2658
+ resources: resources
2659
+ });
2660
+ // 生成日期范围内的所有日期
2661
+ dates = [];
2662
+ currentDate = dayjs(startDate);
2663
+ end = dayjs(endDate);
2664
+ while (currentDate.isSameOrBefore(end)) {
2665
+ dates.push(currentDate.format('YYYY-MM-DD'));
2666
+ currentDate = currentDate.add(1, 'day');
2667
+ }
2668
+ // 如果不支持 Web Worker,使用同步方式处理
2669
+ results = {};
2670
+ for (_i = 0, _dates = dates; _i < _dates.length; _i++) {
2671
+ date = _dates[_i];
2672
+ results[date] = this.getTimeslotBySchedule({
2673
+ date: date,
2674
+ scheduleIds: scheduleIds,
2675
+ resources: resources
2676
+ });
2677
+ }
2678
+ return _context29.abrupt("return", results);
2679
+ case 9:
2680
+ case "end":
2681
+ return _context29.stop();
2682
+ }
2683
+ }, _callee28, this);
2684
+ }));
2685
+ function getTimeslotsScheduleByDateRange(_x21) {
2686
+ return _getTimeslotsScheduleByDateRange.apply(this, arguments);
2687
+ }
2688
+ return getTimeslotsScheduleByDateRange;
2689
+ }())
2607
2690
  }, {
2608
2691
  key: "getAvailableDateForSession",
2609
2692
  value: function () {
2610
- var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2693
+ var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2611
2694
  var params,
2612
2695
  startDate,
2613
2696
  endDate,
2614
2697
  type,
2615
2698
  tempProducts,
2616
- _ref15,
2699
+ _ref16,
2617
2700
  resourceIds,
2618
2701
  rules,
2619
2702
  resourcesMap,
2620
2703
  res,
2621
- _args29 = arguments;
2622
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2623
- while (1) switch (_context29.prev = _context29.next) {
2704
+ dateListWithTimeSlots,
2705
+ firstAvailableDate,
2706
+ _args30 = arguments;
2707
+ return _regeneratorRuntime().wrap(function _callee29$(_context30) {
2708
+ while (1) switch (_context30.prev = _context30.next) {
2624
2709
  case 0:
2625
- params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
2710
+ params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
2626
2711
  // 开始日期如果小于今天,直接以今天当做开始日期
2627
2712
  startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2628
2713
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -2637,9 +2722,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2637
2722
  })];
2638
2723
  }
2639
2724
  // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
2640
- _ref15 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref15.resourceIds, rules = _ref15.rules, resourcesMap = _ref15.resourcesMap;
2725
+ _ref16 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref16.resourceIds, rules = _ref16.rules, resourcesMap = _ref16.resourcesMap;
2641
2726
  this.otherParams.currentResourcesMap = resourcesMap;
2642
- _context29.next = 10;
2727
+ _context30.next = 10;
2643
2728
  return this.store.date.getResourceDates({
2644
2729
  query: {
2645
2730
  start_date: startDate || '',
@@ -2650,19 +2735,272 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2650
2735
  type: type
2651
2736
  });
2652
2737
  case 10:
2653
- res = _context29.sent;
2654
- return _context29.abrupt("return", res);
2655
- case 12:
2738
+ res = _context30.sent;
2739
+ if (!this.store.currentProduct) {
2740
+ _context30.next = 16;
2741
+ break;
2742
+ }
2743
+ _context30.next = 14;
2744
+ return this.getTimeslotsScheduleByDateRange({
2745
+ startDate: startDate || '',
2746
+ endDate: endDate || ''
2747
+ });
2748
+ case 14:
2749
+ dateListWithTimeSlots = _context30.sent;
2750
+ res.forEach(function (n) {
2751
+ if (!dateListWithTimeSlots[n.date]) {
2752
+ n.status = 'unavailable';
2753
+ } else {
2754
+ var allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(function (d) {
2755
+ return d.count;
2756
+ });
2757
+ if (!allTimeSlotsCanUse) {
2758
+ n.status = 'unavailable';
2759
+ }
2760
+ }
2761
+ });
2762
+ case 16:
2763
+ // 找到第一个可用的日期返回给 UI
2764
+ firstAvailableDate = res.find(function (n) {
2765
+ return n.status === 'available';
2766
+ });
2767
+ return _context30.abrupt("return", {
2768
+ dateList: res,
2769
+ firstAvailableDate: firstAvailableDate
2770
+ });
2771
+ case 18:
2656
2772
  case "end":
2657
- return _context29.stop();
2773
+ return _context30.stop();
2658
2774
  }
2659
- }, _callee28, this);
2775
+ }, _callee29, this);
2660
2776
  }));
2661
2777
  function getAvailableDateForSession() {
2662
2778
  return _getAvailableDateForSession.apply(this, arguments);
2663
2779
  }
2664
2780
  return getAvailableDateForSession;
2665
2781
  }()
2782
+ }, {
2783
+ key: "getAvailableDateForSessionOptimize",
2784
+ value: function () {
2785
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2786
+ var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2787
+ var params,
2788
+ cache,
2789
+ startDate,
2790
+ endDate,
2791
+ tempProducts,
2792
+ schedule,
2793
+ filteredSchedule,
2794
+ tempResourceIds,
2795
+ res,
2796
+ dates,
2797
+ currentDate,
2798
+ firstAvailableDate,
2799
+ openResources,
2800
+ allProductResources,
2801
+ targetSchedules,
2802
+ _loop3,
2803
+ _args32 = arguments;
2804
+ return _regeneratorRuntime().wrap(function _callee30$(_context32) {
2805
+ while (1) switch (_context32.prev = _context32.next) {
2806
+ case 0:
2807
+ params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
2808
+ // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2809
+ cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
2810
+ if (!cache) {
2811
+ _context32.next = 5;
2812
+ break;
2813
+ }
2814
+ if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2815
+ _context32.next = 5;
2816
+ break;
2817
+ }
2818
+ return _context32.abrupt("return", {
2819
+ dateList: cache.dateList,
2820
+ firstAvailableDate: cache.firstAvailableDate
2821
+ });
2822
+ case 5:
2823
+ // 开始日期如果小于今天,直接以今天当做开始日期
2824
+ startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2825
+ if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
2826
+ startDate = dayjs().format('YYYY-MM-DD');
2827
+ }
2828
+ // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2829
+ endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2830
+ // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2831
+ tempProducts = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getData();
2832
+ schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
2833
+ filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2834
+ tempResourceIds = getResourcesIdsByProduct(tempProducts);
2835
+ _context32.next = 14;
2836
+ return this.store.date.fetchResourceDates({
2837
+ query: {
2838
+ start_date: startDate || '',
2839
+ end_date: endDate || '',
2840
+ resource_ids: tempResourceIds
2841
+ }
2842
+ });
2843
+ case 14:
2844
+ res = _context32.sent;
2845
+ // 2. 商品 schedule 数据,确定日程在每一天的时间片
2846
+ // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2847
+ dates = [];
2848
+ currentDate = dayjs(startDate);
2849
+ firstAvailableDate = ''; // 预处理,获取商品下启用的资源类型,后面只需要遍历这些资源的资源列表即可
2850
+ openResources = ((_tempProducts = tempProducts) === null || _tempProducts === void 0 || (_tempProducts = _tempProducts.product_resource) === null || _tempProducts === void 0 || (_tempProducts = _tempProducts.resources) === null || _tempProducts === void 0 ? void 0 : _tempProducts.filter(function (m) {
2851
+ return m.status === 1;
2852
+ })) || []; // res.data 返回的一定是启用商品的资源列表,不需要再过滤了
2853
+ allProductResources = sortCombinedResources(res.data);
2854
+ targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
2855
+ _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
2856
+ var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
2857
+ return _regeneratorRuntime().wrap(function _loop3$(_context31) {
2858
+ while (1) switch (_context31.prev = _context31.next) {
2859
+ case 0:
2860
+ currentDateStr = currentDate.format('YYYY-MM-DD');
2861
+ status = 'available'; // 1. 检查商品的提前量等情况是否满足
2862
+ _checkSessionProductL = checkSessionProductLeadTime(tempProducts), latestStartDate = _checkSessionProductL.latestStartDate, earliestEndDate = _checkSessionProductL.earliestEndDate;
2863
+ if (latestStartDate || earliestEndDate) {
2864
+ // 如果时间在最早开始时间之前,则设置为不可用
2865
+ if (latestStartDate && dayjs(currentDate).isBefore(latestStartDate, 'day')) {
2866
+ status = 'unavailable';
2867
+ }
2868
+ // 如果时间在最早结束时间之后,则设置为不可用
2869
+ if (earliestEndDate && dayjs(currentDate).isAfter(earliestEndDate, 'day')) {
2870
+ status = 'unavailable';
2871
+ }
2872
+ }
2873
+ // 2. 检查 schedule 数据,确定 schedule 里没有这一天,或者这一天的isExcluded: true ,则不可用
2874
+ if (status === 'available') {
2875
+ scheduleByDate = filteredSchedule.find(function (n) {
2876
+ return n.date === currentDateStr;
2877
+ });
2878
+ if (!scheduleByDate || scheduleByDate !== null && scheduleByDate !== void 0 && scheduleByDate.isExcluded) {
2879
+ status = 'unavailable';
2880
+ }
2881
+ }
2882
+
2883
+ // 3. 检查这一天的 schedule 时间片里资源是否有可用的,每个时间片下每种资源只需找到第一个可用的即可
2884
+ if (status === 'available') {
2885
+ minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, currentDateStr);
2886
+ scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime); // 同一天内多个时间片下 只要有一个可用则视为可用
2887
+ timesSlotCanUse = scheduleTimeSlots.some(function (item) {
2888
+ // 用来计算资源的可使用情况,针对单个schedule 时间片
2889
+ var resourcesUseableMap = {};
2890
+ // 遍历产品下启用的资源
2891
+ // 必须要保证每种类型的资源都至少有一个能够在对应时间点被选择
2892
+ return openResources.every(function (resource) {
2893
+ // 获取当前资源类型的资源列表
2894
+ var currentResourcesList = allProductResources.filter(function (n) {
2895
+ return n.form_id === resource.resource_type_id;
2896
+ });
2897
+ return currentResourcesList === null || currentResourcesList === void 0 ? void 0 : currentResourcesList.some(function (m) {
2898
+ // 遍历所有资源的上工时间片
2899
+ // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
2900
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2901
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
2902
+ var mTimes = m.times.filter(function (n) {
2903
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
2904
+ });
2905
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2906
+ if (mTimes.length === 0) {
2907
+ return;
2908
+ }
2909
+ var targetCanUseTimes = mTimes.some(function (childTiem) {
2910
+ var _tempProducts2;
2911
+ // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
2912
+ var res = getIsUsableByTimeItem({
2913
+ timeSlice: {
2914
+ start_time: item.start,
2915
+ end_time: item.end,
2916
+ start_at: dayjs(item.start),
2917
+ end_at: dayjs(item.end)
2918
+ },
2919
+ time: childTiem,
2920
+ resource: m,
2921
+ currentCount: 1,
2922
+ resourcesUseableMap: resourcesUseableMap,
2923
+ cut_off_time: (_tempProducts2 = tempProducts) === null || _tempProducts2 === void 0 ? void 0 : _tempProducts2.cut_off_time
2924
+ });
2925
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2926
+ resourcesUseableMap[m.id] = res.usable;
2927
+ }
2928
+ return res.usable && !m.onlyComputed;
2929
+ });
2930
+ return targetCanUseTimes;
2931
+ });
2932
+ });
2933
+ });
2934
+ if (!timesSlotCanUse) {
2935
+ status = 'unavailable';
2936
+ }
2937
+ if (status === 'available' && !firstAvailableDate) {
2938
+ firstAvailableDate = currentDateStr;
2939
+ }
2940
+ }
2941
+ dates.push({
2942
+ date: dayjs(currentDate).format('YYYY-MM-DD'),
2943
+ week: dayjs(currentDate).format('ddd'),
2944
+ weekNum: dayjs(currentDate).day(),
2945
+ status: status
2946
+ });
2947
+
2948
+ // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
2949
+ if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 14)) {
2950
+ _context31.next = 9;
2951
+ break;
2952
+ }
2953
+ return _context31.abrupt("return", 1);
2954
+ case 9:
2955
+ currentDate = dayjs(currentDate).add(1, 'day');
2956
+ case 10:
2957
+ case "end":
2958
+ return _context31.stop();
2959
+ }
2960
+ }, _loop3);
2961
+ });
2962
+ case 22:
2963
+ if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2964
+ _context32.next = 28;
2965
+ break;
2966
+ }
2967
+ return _context32.delegateYield(_loop3(), "t0", 24);
2968
+ case 24:
2969
+ if (!_context32.t0) {
2970
+ _context32.next = 26;
2971
+ break;
2972
+ }
2973
+ return _context32.abrupt("break", 28);
2974
+ case 26:
2975
+ _context32.next = 22;
2976
+ break;
2977
+ case 28:
2978
+ // 最终把资源数据也加到日期内
2979
+ dates = handleAvailableDateByResource(res.data, dates);
2980
+ this.store.date.setDateList(dates);
2981
+
2982
+ // 缓存这次结果,以防后面他小幅度范围内去修改天数
2983
+ (_this$store$currentPr6 = this.store.currentProduct) === null || _this$store$currentPr6 === void 0 || _this$store$currentPr6.setOtherParams('timeSlotBySchedule', {
2984
+ dateList: dates,
2985
+ firstAvailableDate: firstAvailableDate,
2986
+ startDate: startDate,
2987
+ endDate: endDate
2988
+ });
2989
+ return _context32.abrupt("return", {
2990
+ dateList: dates,
2991
+ firstAvailableDate: firstAvailableDate
2992
+ });
2993
+ case 32:
2994
+ case "end":
2995
+ return _context32.stop();
2996
+ }
2997
+ }, _callee30, this);
2998
+ }));
2999
+ function getAvailableDateForSessionOptimize() {
3000
+ return _getAvailableDateForSessionOptimize.apply(this, arguments);
3001
+ }
3002
+ return getAvailableDateForSessionOptimize;
3003
+ }()
2666
3004
  }]);
2667
3005
  return BookingByStepImpl;
2668
3006
  }(BaseModule);
@@ -1,5 +1,5 @@
1
1
  import { Dayjs } from 'dayjs';
2
- import { CartItem } from '../../../modules';
2
+ import { CartItem, ProductData } from '../../../modules';
3
3
  /**
4
4
  * 1. 获取资源列表
5
5
  * 2. 根据当前选择的商品过滤出来对应的资源列表 getResourcesByProduct
@@ -79,7 +79,7 @@ export declare const formatResources: ({ booking, resources, }: {
79
79
  * @return {*}
80
80
  * @Author: zhiwei.Wang
81
81
  */
82
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time }: {
82
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, }: {
83
83
  resource: ResourceItem;
84
84
  duration: number;
85
85
  split: number;
@@ -133,7 +133,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
133
133
  * @return {*}
134
134
  * @Author: zhiwei.Wang
135
135
  */
136
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time }: {
136
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, }: {
137
137
  resourceIds: number[];
138
138
  resourcesMap: any;
139
139
  duration: number;
@@ -201,4 +201,41 @@ export declare const getSumCapacity: ({ capacity }: {
201
201
  * @Author: jinglin.tan
202
202
  */
203
203
  export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
204
+ /**
205
+ * @title: 根据日期范围过滤日程
206
+ *
207
+ * @export
208
+ * @param {any[]} schedule
209
+ * @param {string} startDate
210
+ * @param {string} endDate
211
+ * @return {*}
212
+ */
213
+ export declare function filterScheduleByDateRange(schedule: any[], startDate: string, endDate: string): any[];
214
+ /**
215
+ * 传入商品数据,返回基于商品配置的提前量的最早开始日期和最晚结束日期
216
+ *
217
+ * @export
218
+ * @param {ProductData} product
219
+ * @return {*}
220
+ */
221
+ export declare function checkSessionProductLeadTime(product: ProductData): {
222
+ latestStartDate: string;
223
+ earliestEndDate: string;
224
+ };
225
+ /**
226
+ * 基于商品的 resources 配置,返回可选择的资源的 id 列表
227
+ *
228
+ * @export
229
+ * @param {ProductData} product
230
+ * @return {*}
231
+ */
232
+ export declare function getResourcesIdsByProduct(product: ProductData): number[];
233
+ /**
234
+ * 资源排序,把单个资源靠前,组合资源排在后面
235
+ *
236
+ * @export
237
+ * @param {ResourceItem[]} resourcesList
238
+ * @return {*}
239
+ */
240
+ export declare function sortCombinedResources(resourcesList: ResourceItem[]): ResourceItem[];
204
241
  export {};