@pisell/pisellos 0.0.106 → 0.0.108

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.
@@ -15,6 +15,7 @@ export declare class DateModule extends BaseModule implements Module, DateModule
15
15
  getDateRange(): ITime[];
16
16
  getResourceDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
17
17
  getDateList(): ITime[];
18
+ fetchResourceDates(params: IGetAvailableTimeListParams): Promise<any>;
18
19
  getResourceAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
19
20
  clearDateRange(): void;
20
21
  storeChange(): void;
@@ -113,32 +113,18 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
113
113
  return this.store.dateList;
114
114
  }
115
115
  }, {
116
- key: "getResourceAvailableTimeList",
116
+ key: "fetchResourceDates",
117
117
  value: function () {
118
- var _getResourceAvailableTimeList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
119
- var url, query, rules, type, fetchUrl, _ref, start_date, end_date, resource_ids, dates, _res$data, res;
118
+ var _fetchResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
119
+ var url, query, fetchUrl, _ref, start_date, end_date, resource_ids, res;
120
120
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
121
121
  while (1) switch (_context3.prev = _context3.next) {
122
122
  case 0:
123
- url = params.url, query = params.query, rules = params.rules, type = params.type;
123
+ url = params.url, query = params.query;
124
124
  fetchUrl = url || '/schedule/resource/list';
125
125
  _ref = query || {}, start_date = _ref.start_date, end_date = _ref.end_date, resource_ids = _ref.resource_ids;
126
- if (!(!start_date || !end_date)) {
127
- _context3.next = 5;
128
- break;
129
- }
130
- return _context3.abrupt("return", []);
131
- case 5:
132
- // 1.生成当前月份的所有日期,默认都是可用的
133
- dates = generateMonthDates(start_date, end_date, type); // 如果没有资源或者结束日期在今天之前,则所有日期均不可用
134
- if (resource_ids !== null && resource_ids !== void 0 && resource_ids.length) {
135
- _context3.next = 8;
136
- break;
137
- }
138
- return _context3.abrupt("return", disableAllDates(dates));
139
- case 8:
140
- _context3.prev = 8;
141
- _context3.next = 11;
126
+ _context3.prev = 3;
127
+ _context3.next = 6;
142
128
  return this.request.get(fetchUrl, {
143
129
  start_date: start_date,
144
130
  end_date: end_date,
@@ -147,14 +133,59 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
147
133
  }, {
148
134
  useCache: true
149
135
  });
150
- case 11:
136
+ case 6:
151
137
  res = _context3.sent;
138
+ return _context3.abrupt("return", res);
139
+ case 10:
140
+ _context3.prev = 10;
141
+ _context3.t0 = _context3["catch"](3);
142
+ console.error(_context3.t0);
143
+ case 13:
144
+ case "end":
145
+ return _context3.stop();
146
+ }
147
+ }, _callee3, this, [[3, 10]]);
148
+ }));
149
+ function fetchResourceDates(_x4) {
150
+ return _fetchResourceDates.apply(this, arguments);
151
+ }
152
+ return fetchResourceDates;
153
+ }()
154
+ }, {
155
+ key: "getResourceAvailableTimeList",
156
+ value: function () {
157
+ var _getResourceAvailableTimeList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
158
+ var query, rules, type, _ref2, start_date, end_date, resource_ids, dates, _res$data, res;
159
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
160
+ while (1) switch (_context4.prev = _context4.next) {
161
+ case 0:
162
+ query = params.query, rules = params.rules, type = params.type;
163
+ _ref2 = query || {}, start_date = _ref2.start_date, end_date = _ref2.end_date, resource_ids = _ref2.resource_ids;
164
+ if (!(!start_date || !end_date)) {
165
+ _context4.next = 4;
166
+ break;
167
+ }
168
+ return _context4.abrupt("return", []);
169
+ case 4:
170
+ // 1.生成当前月份的所有日期,默认都是可用的
171
+ dates = generateMonthDates(start_date, end_date, type); // 如果没有资源或者结束日期在今天之前,则所有日期均不可用
172
+ if (resource_ids !== null && resource_ids !== void 0 && resource_ids.length) {
173
+ _context4.next = 7;
174
+ break;
175
+ }
176
+ return _context4.abrupt("return", disableAllDates(dates));
177
+ case 7:
178
+ _context4.prev = 7;
179
+ _context4.next = 10;
180
+ return this.fetchResourceDates(params);
181
+ case 10:
182
+ res = _context4.sent;
152
183
  if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.length) {
153
- _context3.next = 14;
184
+ _context4.next = 13;
154
185
  break;
155
186
  }
156
- return _context3.abrupt("return", disableAllDates(dates));
157
- case 14:
187
+ return _context4.abrupt("return", disableAllDates(dates));
188
+ case 13:
158
189
  // 2.根据资源times判定哪些日期内存在可用资源
159
190
  dates = handleAvailableDateByResource(res.data, dates);
160
191
 
@@ -162,19 +193,19 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
162
193
  if (rules !== null && rules !== void 0 && rules.length) {
163
194
  dates = handleAvailableDatesByRules(dates, rules);
164
195
  }
165
- return _context3.abrupt("return", dates);
166
- case 19:
167
- _context3.prev = 19;
168
- _context3.t0 = _context3["catch"](8);
169
- console.log('getAvailableTimeList_error', _context3.t0);
170
- return _context3.abrupt("return", disableAllDates(dates));
171
- case 23:
196
+ return _context4.abrupt("return", dates);
197
+ case 18:
198
+ _context4.prev = 18;
199
+ _context4.t0 = _context4["catch"](7);
200
+ console.log('getAvailableTimeList_error', _context4.t0);
201
+ return _context4.abrupt("return", disableAllDates(dates));
202
+ case 22:
172
203
  case "end":
173
- return _context3.stop();
204
+ return _context4.stop();
174
205
  }
175
- }, _callee3, this, [[8, 19]]);
206
+ }, _callee4, this, [[7, 18]]);
176
207
  }));
177
- function getResourceAvailableTimeList(_x4) {
208
+ function getResourceAvailableTimeList(_x5) {
178
209
  return _getResourceAvailableTimeList.apply(this, arguments);
179
210
  }
180
211
  return getResourceAvailableTimeList;
@@ -76,7 +76,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
76
76
  var is_deposit = 0; // 是否存在定金,0 不存在,1 存在
77
77
  if (params.cartItems.length > 0) {
78
78
  params.cartItems.forEach(function (item) {
79
- var _item$_productOrigin;
80
79
  if (!item._origin.duration) {
81
80
  var _generateDuration = generateDuration(item),
82
81
  duration = _generateDuration.duration,
@@ -84,8 +83,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
84
83
  item._origin.duration = duration;
85
84
  item._origin.sub_type = durationType;
86
85
  }
87
- // 如果 item.extension_type === normal,视为普通商品
88
- if (((_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.extension_type) === 'normal') {
86
+ // 零售都视为普通商品
87
+ if (order.type === 'virtual') {
89
88
  var _order$relation_forms;
90
89
  order.relation_products.push(item._origin.product);
91
90
  var relationForms = item._origin.relation_forms || [];
@@ -5,7 +5,7 @@ import { BookingByStepState } from './types';
5
5
  import { CartItem, IUpdateItemParams, ProductData, ProductResourceItem, ECartItemInfoType, ECartItemCheckType } from '../../modules';
6
6
  import { Account } from '../../modules/Account/types';
7
7
  import { IStep } from '../../modules/Step/tyeps';
8
- import { TimeSliceItem } from './utils/resources';
8
+ import { TimeSliceItem, ResourceItem } from './utils/resources';
9
9
  import { ITime } from '../../modules/Date/types';
10
10
  import dayjs from 'dayjs';
11
11
  import { IHolder, IFetchHolderAccountsParams } from '../../modules/AccountList/types';
@@ -153,7 +153,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
153
153
  id: number | undefined;
154
154
  _id: string;
155
155
  product: ProductData | undefined;
156
- resources: import("./utils/resources").ResourceItem[];
156
+ resources: ResourceItem[];
157
157
  holder_id: string | number | undefined;
158
158
  holder_name: string | undefined;
159
159
  } | undefined;
@@ -189,7 +189,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
189
189
  private getScheduleDataByIds;
190
190
  openProductDetail(productId: number): Promise<void>;
191
191
  closeProductDetail(): void;
192
- getTimeslotBySchedule({ date, scheduleIds, resources, product }: {
192
+ getTimeslotBySchedule({ date, scheduleIds, resources, product, }: {
193
193
  date: string;
194
194
  scheduleIds?: number[];
195
195
  resources?: ProductResourceItem[];
@@ -221,9 +221,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
221
221
  * @memberof BookingByStepImpl
222
222
  */
223
223
  getResourcesByCartItemAndCode(cartItemId: string, resourceCode: string): any;
224
- getAvailableDateForSession(params?: {
224
+ getAvailableDateForSessionOptimize(params?: {
225
225
  startDate?: string;
226
226
  endDate?: string;
227
- type?: 'month';
228
- }): Promise<ITime[]>;
227
+ }): Promise<{
228
+ dateList: any;
229
+ firstAvailableDate: any;
230
+ }>;
229
231
  }
@@ -27,8 +27,12 @@ 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";
@@ -321,7 +325,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
321
325
  // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
322
326
  cartItems = this.store.cart.getItems();
323
327
  if (!cartItems.length) {
324
- _context5.next = 25;
328
+ _context5.next = 24;
325
329
  break;
326
330
  }
327
331
  userPlugin = this.core.getPlugin('user');
@@ -413,8 +417,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
413
417
  _iterator.f();
414
418
  return _context5.finish(21);
415
419
  case 24:
416
- ;
417
- case 25:
418
420
  case "end":
419
421
  return _context5.stop();
420
422
  }
@@ -2330,7 +2332,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2330
2332
  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
2333
  var minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, date);
2332
2334
  var scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime);
2333
- console.log('scheduleTimeSlots:', scheduleTimeSlots, productResources);
2334
2335
  // 当前所有待选择资源的集合,先提出来,提升性能
2335
2336
  var allProductResources = productResources.flatMap(function (n) {
2336
2337
  return n.renderList;
@@ -2501,7 +2502,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2501
2502
  *
2502
2503
  * @param {string} cartItemId
2503
2504
  * @param {string} resourceCode
2504
- * @return {*}
2505
+ * @return {*}
2505
2506
  * @memberof BookingByStepImpl
2506
2507
  */
2507
2508
  }, {
@@ -2605,63 +2606,222 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2605
2606
  return targetResource.renderList;
2606
2607
  }
2607
2608
  }, {
2608
- key: "getAvailableDateForSession",
2609
+ key: "getAvailableDateForSessionOptimize",
2609
2610
  value: function () {
2610
- var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2611
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2612
+ var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2611
2613
  var params,
2614
+ cache,
2612
2615
  startDate,
2613
2616
  endDate,
2614
- type,
2615
2617
  tempProducts,
2616
- _ref15,
2617
- resourceIds,
2618
- rules,
2619
- resourcesMap,
2618
+ schedule,
2619
+ filteredSchedule,
2620
+ tempResourceIds,
2620
2621
  res,
2621
- _args29 = arguments;
2622
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2623
- while (1) switch (_context29.prev = _context29.next) {
2622
+ dates,
2623
+ currentDate,
2624
+ firstAvailableDate,
2625
+ openResources,
2626
+ allProductResources,
2627
+ targetSchedules,
2628
+ _loop3,
2629
+ _args30 = arguments;
2630
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
2631
+ while (1) switch (_context30.prev = _context30.next) {
2624
2632
  case 0:
2625
- params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
2633
+ params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
2634
+ // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2635
+ cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
2636
+ if (!cache) {
2637
+ _context30.next = 5;
2638
+ break;
2639
+ }
2640
+ if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2641
+ _context30.next = 5;
2642
+ break;
2643
+ }
2644
+ return _context30.abrupt("return", {
2645
+ dateList: cache.dateList,
2646
+ firstAvailableDate: cache.firstAvailableDate
2647
+ });
2648
+ case 5:
2626
2649
  // 开始日期如果小于今天,直接以今天当做开始日期
2627
- startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2650
+ startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2628
2651
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
2629
2652
  startDate = dayjs().format('YYYY-MM-DD');
2630
2653
  }
2631
2654
  // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2632
2655
  endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2633
- tempProducts = []; // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2634
- if (this.store.currentProduct) {
2635
- tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
2636
- _schedule: this.store.currentProduct.getOtherParams()['schedule']
2637
- })];
2638
- }
2639
- // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
2640
- _ref15 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref15.resourceIds, rules = _ref15.rules, resourcesMap = _ref15.resourcesMap;
2641
- this.otherParams.currentResourcesMap = resourcesMap;
2642
- _context29.next = 10;
2643
- return this.store.date.getResourceDates({
2656
+ // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2657
+ tempProducts = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getData();
2658
+ schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
2659
+ filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2660
+ tempResourceIds = getResourcesIdsByProduct(tempProducts);
2661
+ _context30.next = 14;
2662
+ return this.store.date.fetchResourceDates({
2644
2663
  query: {
2645
2664
  start_date: startDate || '',
2646
2665
  end_date: endDate || '',
2647
- resource_ids: resourceIds
2648
- },
2649
- rules: rules,
2650
- type: type
2666
+ resource_ids: tempResourceIds
2667
+ }
2651
2668
  });
2652
- case 10:
2653
- res = _context29.sent;
2654
- return _context29.abrupt("return", res);
2655
- case 12:
2669
+ case 14:
2670
+ res = _context30.sent;
2671
+ // 2. 商品 schedule 数据,确定日程在每一天的时间片
2672
+ // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2673
+ dates = [];
2674
+ currentDate = dayjs(startDate);
2675
+ firstAvailableDate = ''; // 预处理,获取商品下启用的资源类型,后面只需要遍历这些资源的资源列表即可
2676
+ 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) {
2677
+ return m.status === 1;
2678
+ })) || []; // res.data 返回的一定是启用商品的资源列表,不需要再过滤了
2679
+ allProductResources = sortCombinedResources(res.data);
2680
+ targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
2681
+ _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
2682
+ var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
2683
+ return _regeneratorRuntime().wrap(function _loop3$(_context29) {
2684
+ while (1) switch (_context29.prev = _context29.next) {
2685
+ case 0:
2686
+ currentDateStr = currentDate.format('YYYY-MM-DD');
2687
+ status = 'available'; // 1. 检查商品的提前量等情况是否满足
2688
+ _checkSessionProductL = checkSessionProductLeadTime(tempProducts), latestStartDate = _checkSessionProductL.latestStartDate, earliestEndDate = _checkSessionProductL.earliestEndDate;
2689
+ if (latestStartDate || earliestEndDate) {
2690
+ // 如果时间在最早开始时间之前,则设置为不可用
2691
+ if (latestStartDate && dayjs(currentDate).isBefore(latestStartDate, 'day')) {
2692
+ status = 'unavailable';
2693
+ }
2694
+ // 如果时间在最早结束时间之后,则设置为不可用
2695
+ if (earliestEndDate && dayjs(currentDate).isAfter(earliestEndDate, 'day')) {
2696
+ status = 'unavailable';
2697
+ }
2698
+ }
2699
+ // 2. 检查 schedule 数据,确定 schedule 里没有这一天,或者这一天的isExcluded: true ,则不可用
2700
+ if (status === 'available') {
2701
+ scheduleByDate = filteredSchedule.find(function (n) {
2702
+ return n.date === currentDateStr;
2703
+ });
2704
+ if (!scheduleByDate || scheduleByDate !== null && scheduleByDate !== void 0 && scheduleByDate.isExcluded) {
2705
+ status = 'unavailable';
2706
+ }
2707
+ }
2708
+
2709
+ // 3. 检查这一天的 schedule 时间片里资源是否有可用的,每个时间片下每种资源只需找到第一个可用的即可
2710
+ if (status === 'available') {
2711
+ minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, currentDateStr);
2712
+ scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime); // 同一天内多个时间片下 只要有一个可用则视为可用
2713
+ timesSlotCanUse = scheduleTimeSlots.some(function (item) {
2714
+ // 用来计算资源的可使用情况,针对单个schedule 时间片
2715
+ var resourcesUseableMap = {};
2716
+ // 遍历产品下启用的资源
2717
+ // 必须要保证每种类型的资源都至少有一个能够在对应时间点被选择
2718
+ return openResources.every(function (resource) {
2719
+ // 获取当前资源类型的资源列表
2720
+ var currentResourcesList = allProductResources.filter(function (n) {
2721
+ return n.form_id === resource.resource_type_id;
2722
+ });
2723
+ return currentResourcesList === null || currentResourcesList === void 0 ? void 0 : currentResourcesList.some(function (m) {
2724
+ // 遍历所有资源的上工时间片
2725
+ // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
2726
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2727
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
2728
+ var mTimes = m.times.filter(function (n) {
2729
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
2730
+ });
2731
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2732
+ if (mTimes.length === 0) {
2733
+ return;
2734
+ }
2735
+ var targetCanUseTimes = mTimes.some(function (childTiem) {
2736
+ var _tempProducts2;
2737
+ // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
2738
+ var res = getIsUsableByTimeItem({
2739
+ timeSlice: {
2740
+ start_time: item.start,
2741
+ end_time: item.end,
2742
+ start_at: dayjs(item.start),
2743
+ end_at: dayjs(item.end)
2744
+ },
2745
+ time: childTiem,
2746
+ resource: m,
2747
+ currentCount: 1,
2748
+ resourcesUseableMap: resourcesUseableMap,
2749
+ cut_off_time: (_tempProducts2 = tempProducts) === null || _tempProducts2 === void 0 ? void 0 : _tempProducts2.cut_off_time
2750
+ });
2751
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2752
+ resourcesUseableMap[m.id] = res.usable;
2753
+ }
2754
+ return res.usable && !m.onlyComputed;
2755
+ });
2756
+ return targetCanUseTimes;
2757
+ });
2758
+ });
2759
+ });
2760
+ if (!timesSlotCanUse) {
2761
+ status = 'unavailable';
2762
+ }
2763
+ if (status === 'available' && !firstAvailableDate) {
2764
+ firstAvailableDate = currentDateStr;
2765
+ }
2766
+ }
2767
+ dates.push({
2768
+ date: dayjs(currentDate).format('YYYY-MM-DD'),
2769
+ week: dayjs(currentDate).format('ddd'),
2770
+ weekNum: dayjs(currentDate).day(),
2771
+ status: status
2772
+ });
2773
+
2774
+ // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
2775
+ if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 14)) {
2776
+ _context29.next = 9;
2777
+ break;
2778
+ }
2779
+ return _context29.abrupt("return", 1);
2780
+ case 9:
2781
+ currentDate = dayjs(currentDate).add(1, 'day');
2782
+ case 10:
2783
+ case "end":
2784
+ return _context29.stop();
2785
+ }
2786
+ }, _loop3);
2787
+ });
2788
+ case 22:
2789
+ if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2790
+ _context30.next = 28;
2791
+ break;
2792
+ }
2793
+ return _context30.delegateYield(_loop3(), "t0", 24);
2794
+ case 24:
2795
+ if (!_context30.t0) {
2796
+ _context30.next = 26;
2797
+ break;
2798
+ }
2799
+ return _context30.abrupt("break", 28);
2800
+ case 26:
2801
+ _context30.next = 22;
2802
+ break;
2803
+ case 28:
2804
+ // 缓存这次结果,以防后面他小幅度范围内去修改天数
2805
+ (_this$store$currentPr6 = this.store.currentProduct) === null || _this$store$currentPr6 === void 0 || _this$store$currentPr6.setOtherParams('timeSlotBySchedule', {
2806
+ dateList: dates,
2807
+ firstAvailableDate: firstAvailableDate,
2808
+ startDate: startDate,
2809
+ endDate: endDate
2810
+ });
2811
+ return _context30.abrupt("return", {
2812
+ dateList: dates,
2813
+ firstAvailableDate: firstAvailableDate
2814
+ });
2815
+ case 30:
2656
2816
  case "end":
2657
- return _context29.stop();
2817
+ return _context30.stop();
2658
2818
  }
2659
2819
  }, _callee28, this);
2660
2820
  }));
2661
- function getAvailableDateForSession() {
2662
- return _getAvailableDateForSession.apply(this, arguments);
2821
+ function getAvailableDateForSessionOptimize() {
2822
+ return _getAvailableDateForSessionOptimize.apply(this, arguments);
2663
2823
  }
2664
- return getAvailableDateForSession;
2824
+ return getAvailableDateForSessionOptimize;
2665
2825
  }()
2666
2826
  }]);
2667
2827
  return BookingByStepImpl;
@@ -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 {};