@pisell/pisellos 3.0.31 → 3.0.33

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
  }
@@ -1793,6 +1807,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1793
1807
  // .format("HH:mm");
1794
1808
  // 根据 start_time 和 end_time 去匹配资源
1795
1809
  var targetResource = null;
1810
+ var targetResourceTime = 0;
1796
1811
  var _iterator3 = _createForOfIteratorHelper(resources),
1797
1812
  _step3;
1798
1813
  try {
@@ -1835,8 +1850,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1835
1850
  }
1836
1851
  return res.usable;
1837
1852
  });
1838
- if (canUseTime && !n.onlyComputed) {
1853
+ var currentResourceIdleTime = calculateResourceAvailableTime({
1854
+ resource: n,
1855
+ timeSlots: timeSlots,
1856
+ currentCapacity: totalCapacity + (capacity || 0)
1857
+ });
1858
+ if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
1839
1859
  targetResource = n;
1860
+ targetResourceTime = currentResourceIdleTime;
1840
1861
  return 1; // break
1841
1862
  }
1842
1863
  },
@@ -2034,7 +2055,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2034
2055
  })) {
2035
2056
  return;
2036
2057
  }
2037
- var targetResource = targetRenderList[0];
2058
+ var fastestResource = findFastestAvailableResource({
2059
+ resources: targetRenderList,
2060
+ currentCapacity: currentCapacity,
2061
+ countMap: selectResourcesMap
2062
+ });
2063
+ var targetResource = fastestResource || targetRenderList[0];
2038
2064
  targetResource.capacity = currentCapacity;
2039
2065
  // 在这里处理 children 的数据
2040
2066
  checkSubResourcesCapacity(targetResource);
@@ -2330,7 +2356,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2330
2356
  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
2357
  var minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, date);
2332
2358
  var scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime);
2333
- console.log('scheduleTimeSlots:', scheduleTimeSlots, productResources);
2334
2359
  // 当前所有待选择资源的集合,先提出来,提升性能
2335
2360
  var allProductResources = productResources.flatMap(function (n) {
2336
2361
  return n.renderList;
@@ -2501,7 +2526,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2501
2526
  *
2502
2527
  * @param {string} cartItemId
2503
2528
  * @param {string} resourceCode
2504
- * @return {*}
2529
+ * @return {*}
2505
2530
  * @memberof BookingByStepImpl
2506
2531
  */
2507
2532
  }, {
@@ -2604,25 +2629,78 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2604
2629
  }
2605
2630
  return targetResource.renderList;
2606
2631
  }
2632
+
2633
+ /**
2634
+ * 根据日期范围批量获取时间槽
2635
+ * @param params 参数对象
2636
+ * @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
2637
+ */
2638
+ }, {
2639
+ key: "getTimeslotsScheduleByDateRange",
2640
+ value: (function () {
2641
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(_ref15) {
2642
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i, _dates, date;
2643
+ return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2644
+ while (1) switch (_context29.prev = _context29.next) {
2645
+ case 0:
2646
+ startDate = _ref15.startDate, endDate = _ref15.endDate, scheduleIds = _ref15.scheduleIds, resources = _ref15.resources;
2647
+ console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
2648
+ startDate: startDate,
2649
+ endDate: endDate,
2650
+ scheduleIds: scheduleIds,
2651
+ resources: resources
2652
+ });
2653
+ // 生成日期范围内的所有日期
2654
+ dates = [];
2655
+ currentDate = dayjs(startDate);
2656
+ end = dayjs(endDate);
2657
+ while (currentDate.isSameOrBefore(end)) {
2658
+ dates.push(currentDate.format('YYYY-MM-DD'));
2659
+ currentDate = currentDate.add(1, 'day');
2660
+ }
2661
+ // 如果不支持 Web Worker,使用同步方式处理
2662
+ results = {};
2663
+ for (_i = 0, _dates = dates; _i < _dates.length; _i++) {
2664
+ date = _dates[_i];
2665
+ results[date] = this.getTimeslotBySchedule({
2666
+ date: date,
2667
+ scheduleIds: scheduleIds,
2668
+ resources: resources
2669
+ });
2670
+ }
2671
+ return _context29.abrupt("return", results);
2672
+ case 9:
2673
+ case "end":
2674
+ return _context29.stop();
2675
+ }
2676
+ }, _callee28, this);
2677
+ }));
2678
+ function getTimeslotsScheduleByDateRange(_x21) {
2679
+ return _getTimeslotsScheduleByDateRange.apply(this, arguments);
2680
+ }
2681
+ return getTimeslotsScheduleByDateRange;
2682
+ }())
2607
2683
  }, {
2608
2684
  key: "getAvailableDateForSession",
2609
2685
  value: function () {
2610
- var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2686
+ var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2611
2687
  var params,
2612
2688
  startDate,
2613
2689
  endDate,
2614
2690
  type,
2615
2691
  tempProducts,
2616
- _ref15,
2692
+ _ref16,
2617
2693
  resourceIds,
2618
2694
  rules,
2619
2695
  resourcesMap,
2620
2696
  res,
2621
- _args29 = arguments;
2622
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2623
- while (1) switch (_context29.prev = _context29.next) {
2697
+ dateListWithTimeSlots,
2698
+ firstAvailableDate,
2699
+ _args30 = arguments;
2700
+ return _regeneratorRuntime().wrap(function _callee29$(_context30) {
2701
+ while (1) switch (_context30.prev = _context30.next) {
2624
2702
  case 0:
2625
- params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
2703
+ params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
2626
2704
  // 开始日期如果小于今天,直接以今天当做开始日期
2627
2705
  startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2628
2706
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -2637,9 +2715,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2637
2715
  })];
2638
2716
  }
2639
2717
  // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
2640
- _ref15 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref15.resourceIds, rules = _ref15.rules, resourcesMap = _ref15.resourcesMap;
2718
+ _ref16 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref16.resourceIds, rules = _ref16.rules, resourcesMap = _ref16.resourcesMap;
2641
2719
  this.otherParams.currentResourcesMap = resourcesMap;
2642
- _context29.next = 10;
2720
+ _context30.next = 10;
2643
2721
  return this.store.date.getResourceDates({
2644
2722
  query: {
2645
2723
  start_date: startDate || '',
@@ -2650,19 +2728,272 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2650
2728
  type: type
2651
2729
  });
2652
2730
  case 10:
2653
- res = _context29.sent;
2654
- return _context29.abrupt("return", res);
2655
- case 12:
2731
+ res = _context30.sent;
2732
+ if (!this.store.currentProduct) {
2733
+ _context30.next = 16;
2734
+ break;
2735
+ }
2736
+ _context30.next = 14;
2737
+ return this.getTimeslotsScheduleByDateRange({
2738
+ startDate: startDate || '',
2739
+ endDate: endDate || ''
2740
+ });
2741
+ case 14:
2742
+ dateListWithTimeSlots = _context30.sent;
2743
+ res.forEach(function (n) {
2744
+ if (!dateListWithTimeSlots[n.date]) {
2745
+ n.status = 'unavailable';
2746
+ } else {
2747
+ var allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(function (d) {
2748
+ return d.count;
2749
+ });
2750
+ if (!allTimeSlotsCanUse) {
2751
+ n.status = 'unavailable';
2752
+ }
2753
+ }
2754
+ });
2755
+ case 16:
2756
+ // 找到第一个可用的日期返回给 UI
2757
+ firstAvailableDate = res.find(function (n) {
2758
+ return n.status === 'available';
2759
+ });
2760
+ return _context30.abrupt("return", {
2761
+ dateList: res,
2762
+ firstAvailableDate: firstAvailableDate
2763
+ });
2764
+ case 18:
2656
2765
  case "end":
2657
- return _context29.stop();
2766
+ return _context30.stop();
2658
2767
  }
2659
- }, _callee28, this);
2768
+ }, _callee29, this);
2660
2769
  }));
2661
2770
  function getAvailableDateForSession() {
2662
2771
  return _getAvailableDateForSession.apply(this, arguments);
2663
2772
  }
2664
2773
  return getAvailableDateForSession;
2665
2774
  }()
2775
+ }, {
2776
+ key: "getAvailableDateForSessionOptimize",
2777
+ value: function () {
2778
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2779
+ var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2780
+ var params,
2781
+ cache,
2782
+ startDate,
2783
+ endDate,
2784
+ tempProducts,
2785
+ schedule,
2786
+ filteredSchedule,
2787
+ tempResourceIds,
2788
+ res,
2789
+ dates,
2790
+ currentDate,
2791
+ firstAvailableDate,
2792
+ openResources,
2793
+ allProductResources,
2794
+ targetSchedules,
2795
+ _loop3,
2796
+ _args32 = arguments;
2797
+ return _regeneratorRuntime().wrap(function _callee30$(_context32) {
2798
+ while (1) switch (_context32.prev = _context32.next) {
2799
+ case 0:
2800
+ params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
2801
+ // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2802
+ cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
2803
+ if (!cache) {
2804
+ _context32.next = 5;
2805
+ break;
2806
+ }
2807
+ if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2808
+ _context32.next = 5;
2809
+ break;
2810
+ }
2811
+ return _context32.abrupt("return", {
2812
+ dateList: cache.dateList,
2813
+ firstAvailableDate: cache.firstAvailableDate
2814
+ });
2815
+ case 5:
2816
+ // 开始日期如果小于今天,直接以今天当做开始日期
2817
+ startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2818
+ if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
2819
+ startDate = dayjs().format('YYYY-MM-DD');
2820
+ }
2821
+ // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2822
+ endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2823
+ // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2824
+ tempProducts = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getData();
2825
+ schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
2826
+ filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2827
+ tempResourceIds = getResourcesIdsByProduct(tempProducts);
2828
+ _context32.next = 14;
2829
+ return this.store.date.fetchResourceDates({
2830
+ query: {
2831
+ start_date: startDate || '',
2832
+ end_date: endDate || '',
2833
+ resource_ids: tempResourceIds
2834
+ }
2835
+ });
2836
+ case 14:
2837
+ res = _context32.sent;
2838
+ // 2. 商品 schedule 数据,确定日程在每一天的时间片
2839
+ // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2840
+ dates = [];
2841
+ currentDate = dayjs(startDate);
2842
+ firstAvailableDate = ''; // 预处理,获取商品下启用的资源类型,后面只需要遍历这些资源的资源列表即可
2843
+ 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) {
2844
+ return m.status === 1;
2845
+ })) || []; // res.data 返回的一定是启用商品的资源列表,不需要再过滤了
2846
+ allProductResources = sortCombinedResources(res.data);
2847
+ targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
2848
+ _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
2849
+ var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
2850
+ return _regeneratorRuntime().wrap(function _loop3$(_context31) {
2851
+ while (1) switch (_context31.prev = _context31.next) {
2852
+ case 0:
2853
+ currentDateStr = currentDate.format('YYYY-MM-DD');
2854
+ status = 'available'; // 1. 检查商品的提前量等情况是否满足
2855
+ _checkSessionProductL = checkSessionProductLeadTime(tempProducts), latestStartDate = _checkSessionProductL.latestStartDate, earliestEndDate = _checkSessionProductL.earliestEndDate;
2856
+ if (latestStartDate || earliestEndDate) {
2857
+ // 如果时间在最早开始时间之前,则设置为不可用
2858
+ if (latestStartDate && dayjs(currentDate).isBefore(latestStartDate, 'day')) {
2859
+ status = 'unavailable';
2860
+ }
2861
+ // 如果时间在最早结束时间之后,则设置为不可用
2862
+ if (earliestEndDate && dayjs(currentDate).isAfter(earliestEndDate, 'day')) {
2863
+ status = 'unavailable';
2864
+ }
2865
+ }
2866
+ // 2. 检查 schedule 数据,确定 schedule 里没有这一天,或者这一天的isExcluded: true ,则不可用
2867
+ if (status === 'available') {
2868
+ scheduleByDate = filteredSchedule.find(function (n) {
2869
+ return n.date === currentDateStr;
2870
+ });
2871
+ if (!scheduleByDate || scheduleByDate !== null && scheduleByDate !== void 0 && scheduleByDate.isExcluded) {
2872
+ status = 'unavailable';
2873
+ }
2874
+ }
2875
+
2876
+ // 3. 检查这一天的 schedule 时间片里资源是否有可用的,每个时间片下每种资源只需找到第一个可用的即可
2877
+ if (status === 'available') {
2878
+ minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, currentDateStr);
2879
+ scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime); // 同一天内多个时间片下 只要有一个可用则视为可用
2880
+ timesSlotCanUse = scheduleTimeSlots.some(function (item) {
2881
+ // 用来计算资源的可使用情况,针对单个schedule 时间片
2882
+ var resourcesUseableMap = {};
2883
+ // 遍历产品下启用的资源
2884
+ // 必须要保证每种类型的资源都至少有一个能够在对应时间点被选择
2885
+ return openResources.every(function (resource) {
2886
+ // 获取当前资源类型的资源列表
2887
+ var currentResourcesList = allProductResources.filter(function (n) {
2888
+ return n.form_id === resource.resource_type_id;
2889
+ });
2890
+ return currentResourcesList === null || currentResourcesList === void 0 ? void 0 : currentResourcesList.some(function (m) {
2891
+ // 遍历所有资源的上工时间片
2892
+ // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
2893
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2894
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
2895
+ var mTimes = m.times.filter(function (n) {
2896
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
2897
+ });
2898
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2899
+ if (mTimes.length === 0) {
2900
+ return;
2901
+ }
2902
+ var targetCanUseTimes = mTimes.some(function (childTiem) {
2903
+ var _tempProducts2;
2904
+ // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
2905
+ var res = getIsUsableByTimeItem({
2906
+ timeSlice: {
2907
+ start_time: item.start,
2908
+ end_time: item.end,
2909
+ start_at: dayjs(item.start),
2910
+ end_at: dayjs(item.end)
2911
+ },
2912
+ time: childTiem,
2913
+ resource: m,
2914
+ currentCount: 1,
2915
+ resourcesUseableMap: resourcesUseableMap,
2916
+ cut_off_time: (_tempProducts2 = tempProducts) === null || _tempProducts2 === void 0 ? void 0 : _tempProducts2.cut_off_time
2917
+ });
2918
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2919
+ resourcesUseableMap[m.id] = res.usable;
2920
+ }
2921
+ return res.usable && !m.onlyComputed;
2922
+ });
2923
+ return targetCanUseTimes;
2924
+ });
2925
+ });
2926
+ });
2927
+ if (!timesSlotCanUse) {
2928
+ status = 'unavailable';
2929
+ }
2930
+ if (status === 'available' && !firstAvailableDate) {
2931
+ firstAvailableDate = currentDateStr;
2932
+ }
2933
+ }
2934
+ dates.push({
2935
+ date: dayjs(currentDate).format('YYYY-MM-DD'),
2936
+ week: dayjs(currentDate).format('ddd'),
2937
+ weekNum: dayjs(currentDate).day(),
2938
+ status: status
2939
+ });
2940
+
2941
+ // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
2942
+ if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 14)) {
2943
+ _context31.next = 9;
2944
+ break;
2945
+ }
2946
+ return _context31.abrupt("return", 1);
2947
+ case 9:
2948
+ currentDate = dayjs(currentDate).add(1, 'day');
2949
+ case 10:
2950
+ case "end":
2951
+ return _context31.stop();
2952
+ }
2953
+ }, _loop3);
2954
+ });
2955
+ case 22:
2956
+ if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2957
+ _context32.next = 28;
2958
+ break;
2959
+ }
2960
+ return _context32.delegateYield(_loop3(), "t0", 24);
2961
+ case 24:
2962
+ if (!_context32.t0) {
2963
+ _context32.next = 26;
2964
+ break;
2965
+ }
2966
+ return _context32.abrupt("break", 28);
2967
+ case 26:
2968
+ _context32.next = 22;
2969
+ break;
2970
+ case 28:
2971
+ // 最终把资源数据也加到日期内
2972
+ dates = handleAvailableDateByResource(res.data, dates);
2973
+ this.store.date.setDateList(dates);
2974
+
2975
+ // 缓存这次结果,以防后面他小幅度范围内去修改天数
2976
+ (_this$store$currentPr6 = this.store.currentProduct) === null || _this$store$currentPr6 === void 0 || _this$store$currentPr6.setOtherParams('timeSlotBySchedule', {
2977
+ dateList: dates,
2978
+ firstAvailableDate: firstAvailableDate,
2979
+ startDate: startDate,
2980
+ endDate: endDate
2981
+ });
2982
+ return _context32.abrupt("return", {
2983
+ dateList: dates,
2984
+ firstAvailableDate: firstAvailableDate
2985
+ });
2986
+ case 32:
2987
+ case "end":
2988
+ return _context32.stop();
2989
+ }
2990
+ }, _callee30, this);
2991
+ }));
2992
+ function getAvailableDateForSessionOptimize() {
2993
+ return _getAvailableDateForSessionOptimize.apply(this, arguments);
2994
+ }
2995
+ return getAvailableDateForSessionOptimize;
2996
+ }()
2666
2997
  }]);
2667
2998
  return BookingByStepImpl;
2668
2999
  }(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 {};