@pisell/pisellos 2.0.24 → 2.0.26
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.
- package/dist/modules/Date/index.d.ts +2 -0
- package/dist/modules/Date/index.js +70 -34
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Schedule/types.d.ts +1 -0
- package/dist/solution/BookingByStep/index.d.ts +25 -4
- package/dist/solution/BookingByStep/index.js +358 -27
- package/dist/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/dist/solution/BookingByStep/utils/resources.js +100 -1
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +25 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +225 -0
- package/lib/modules/Date/index.d.ts +2 -0
- package/lib/modules/Date/index.js +23 -10
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Schedule/types.d.ts +1 -0
- package/lib/solution/BookingByStep/index.d.ts +25 -4
- package/lib/solution/BookingByStep/index.js +280 -34
- package/lib/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/lib/solution/BookingByStep/utils/resources.js +73 -2
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +25 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +170 -0
- package/package.json +1 -1
|
@@ -782,4 +782,103 @@ export var checkSubResourcesCapacity = function checkSubResourcesCapacity(resour
|
|
|
782
782
|
}
|
|
783
783
|
});
|
|
784
784
|
}
|
|
785
|
-
};
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* @title: 根据日期范围过滤日程
|
|
789
|
+
*
|
|
790
|
+
* @export
|
|
791
|
+
* @param {any[]} schedule
|
|
792
|
+
* @param {string} startDate
|
|
793
|
+
* @param {string} endDate
|
|
794
|
+
* @return {*}
|
|
795
|
+
*/
|
|
796
|
+
export function filterScheduleByDateRange(schedule, startDate, endDate) {
|
|
797
|
+
if (!(schedule !== null && schedule !== void 0 && schedule.length)) return [];
|
|
798
|
+
var start = new Date(startDate);
|
|
799
|
+
var end = new Date(endDate);
|
|
800
|
+
return schedule.filter(function (item) {
|
|
801
|
+
var itemDate = new Date(item.date);
|
|
802
|
+
return itemDate >= start && itemDate <= end;
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* 传入商品数据,返回基于商品配置的提前量的最早开始日期和最晚结束日期
|
|
808
|
+
*
|
|
809
|
+
* @export
|
|
810
|
+
* @param {ProductData} product
|
|
811
|
+
* @return {*}
|
|
812
|
+
*/
|
|
813
|
+
export function checkSessionProductLeadTime(product) {
|
|
814
|
+
var latestStartDate = ''; // 最晚开始日期
|
|
815
|
+
var earliestEndDate = ''; // 最早结束日期
|
|
816
|
+
var _product$cut_off_time = product.cut_off_time,
|
|
817
|
+
future_day = _product$cut_off_time.future_day,
|
|
818
|
+
unit = _product$cut_off_time.unit,
|
|
819
|
+
unit_type = _product$cut_off_time.unit_type;
|
|
820
|
+
// 预定天数存在,则开始计算从当前时间开始往后推预定天数作为结束时间
|
|
821
|
+
if (future_day) {
|
|
822
|
+
var endDate = dayjs().add(future_day, 'day');
|
|
823
|
+
if (!earliestEndDate || endDate.isBefore(dayjs(earliestEndDate), 'day')) {
|
|
824
|
+
earliestEndDate = endDate.format('YYYY-MM-DD');
|
|
825
|
+
}
|
|
826
|
+
} else if (future_day === 0) {
|
|
827
|
+
var _endDate = dayjs();
|
|
828
|
+
if (!earliestEndDate || _endDate.isBefore(dayjs(earliestEndDate), 'day')) {
|
|
829
|
+
earliestEndDate = _endDate.format('YYYY-MM-DD');
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
// 如果存在提前预约时间,则开始计算从当前时间开始往后推提前预约时间作为开始时间
|
|
833
|
+
if (unit && unit_type) {
|
|
834
|
+
var startDate = dayjs(dayjs().add(unit, unit_type).format('YYYY-MM-DD'));
|
|
835
|
+
if (!latestStartDate || startDate.isAfter(dayjs(latestStartDate), 'day')) {
|
|
836
|
+
latestStartDate = startDate.format('YYYY-MM-DD');
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return {
|
|
840
|
+
latestStartDate: latestStartDate,
|
|
841
|
+
earliestEndDate: earliestEndDate
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* 基于商品的 resources 配置,返回可选择的资源的 id 列表
|
|
847
|
+
*
|
|
848
|
+
* @export
|
|
849
|
+
* @param {ProductData} product
|
|
850
|
+
* @return {*}
|
|
851
|
+
*/
|
|
852
|
+
export function getResourcesIdsByProduct(product) {
|
|
853
|
+
var _product$product_reso, _product$product_reso2;
|
|
854
|
+
var tempResourceIds = [];
|
|
855
|
+
product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 || (_product$product_reso = _product$product_reso.resources) === null || _product$product_reso === void 0 || (_product$product_reso2 = _product$product_reso.forEach) === null || _product$product_reso2 === void 0 || _product$product_reso2.call(_product$product_reso, function (resource) {
|
|
856
|
+
if ((resource === null || resource === void 0 ? void 0 : resource.status) == 1) {
|
|
857
|
+
var _resource$default_res, _resource$optional_re;
|
|
858
|
+
if (resource !== null && resource !== void 0 && (_resource$default_res = resource.default_resource) !== null && _resource$default_res !== void 0 && _resource$default_res.length) {
|
|
859
|
+
tempResourceIds.push.apply(tempResourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.default_resource));
|
|
860
|
+
} else if (resource !== null && resource !== void 0 && (_resource$optional_re = resource.optional_resource) !== null && _resource$optional_re !== void 0 && _resource$optional_re.length) {
|
|
861
|
+
tempResourceIds.push.apply(tempResourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.optional_resource));
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
});
|
|
865
|
+
return tempResourceIds;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* 资源排序,把单个资源靠前,组合资源排在后面
|
|
870
|
+
*
|
|
871
|
+
* @export
|
|
872
|
+
* @param {ResourceItem[]} resourcesList
|
|
873
|
+
* @return {*}
|
|
874
|
+
*/
|
|
875
|
+
export function sortCombinedResources(resourcesList) {
|
|
876
|
+
var newResourcesList = _toConsumableArray(resourcesList);
|
|
877
|
+
newResourcesList.sort(function (a, b) {
|
|
878
|
+
var _a$metadata2, _b$metadata2;
|
|
879
|
+
var aIsCombined = ((_a$metadata2 = a.metadata) === null || _a$metadata2 === void 0 || (_a$metadata2 = _a$metadata2.combined_resource) === null || _a$metadata2 === void 0 ? void 0 : _a$metadata2.status) === 1;
|
|
880
|
+
var bIsCombined = ((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 || (_b$metadata2 = _b$metadata2.combined_resource) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.status) === 1;
|
|
881
|
+
return aIsCombined === bIsCombined ? 0 : aIsCombined ? 1 : -1;
|
|
882
|
+
});
|
|
883
|
+
return newResourcesList;
|
|
884
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ResourceItem, TimeSliceItem } from "./resources";
|
|
2
|
+
/**
|
|
3
|
+
* 计算资源在指定时间段内的总可用时间(以分钟为单位)
|
|
4
|
+
* @param resource 需要计算可用时间的资源
|
|
5
|
+
* @param timeSlots 要检查可用性的时间段
|
|
6
|
+
* @param currentCapacity 当前预约所需的容量
|
|
7
|
+
* @returns 总可用时间(分钟)
|
|
8
|
+
*/
|
|
9
|
+
export declare function calculateResourceAvailableTime({ resource, timeSlots, currentCapacity, }: {
|
|
10
|
+
resource: ResourceItem;
|
|
11
|
+
timeSlots: TimeSliceItem;
|
|
12
|
+
currentCapacity?: number;
|
|
13
|
+
}): number;
|
|
14
|
+
/**
|
|
15
|
+
* 查找最快可用的资源,如果有多个资源在相同时间点可用,则选择空闲时间最长的资源
|
|
16
|
+
* @param resources 资源列表
|
|
17
|
+
* @param currentCapacity 当前预约所需的容量
|
|
18
|
+
* @param countMap 已预约数量映射
|
|
19
|
+
* @returns 最快可用的资源
|
|
20
|
+
*/
|
|
21
|
+
export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, }: {
|
|
22
|
+
resources: ResourceItem[];
|
|
23
|
+
currentCapacity?: number;
|
|
24
|
+
countMap?: Record<number, number>;
|
|
25
|
+
}): ResourceItem | null;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
import dayjs from "dayjs";
|
|
5
|
+
/**
|
|
6
|
+
* 计算资源在指定时间段内的总可用时间(以分钟为单位)
|
|
7
|
+
* @param resource 需要计算可用时间的资源
|
|
8
|
+
* @param timeSlots 要检查可用性的时间段
|
|
9
|
+
* @param currentCapacity 当前预约所需的容量
|
|
10
|
+
* @returns 总可用时间(分钟)
|
|
11
|
+
*/
|
|
12
|
+
export function calculateResourceAvailableTime(_ref) {
|
|
13
|
+
var resource = _ref.resource,
|
|
14
|
+
timeSlots = _ref.timeSlots,
|
|
15
|
+
_ref$currentCapacity = _ref.currentCapacity,
|
|
16
|
+
currentCapacity = _ref$currentCapacity === void 0 ? 1 : _ref$currentCapacity;
|
|
17
|
+
// 过滤出与给定日期相同的资源时间
|
|
18
|
+
var matchingTimes = resource.times.filter(function (time) {
|
|
19
|
+
return dayjs(time.start_at).isSame(dayjs(timeSlots.start_at), 'day');
|
|
20
|
+
});
|
|
21
|
+
if (matchingTimes.length === 0) return 0;
|
|
22
|
+
var totalAvailableMinutes = 0;
|
|
23
|
+
var _iterator = _createForOfIteratorHelper(matchingTimes),
|
|
24
|
+
_step;
|
|
25
|
+
try {
|
|
26
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
27
|
+
var _time$event_list;
|
|
28
|
+
var time = _step.value;
|
|
29
|
+
// 计算实际重叠的时间段
|
|
30
|
+
var overlapStart = dayjs(time.start_at).isAfter(dayjs(timeSlots.start_at)) ? dayjs(time.start_at) : dayjs(timeSlots.start_at);
|
|
31
|
+
var overlapEnd = dayjs(time.end_at).isBefore(dayjs(timeSlots.end_at)) ? dayjs(time.end_at) : dayjs(timeSlots.end_at);
|
|
32
|
+
|
|
33
|
+
// 如果没有预约事件,整个重叠时间段都是可用的
|
|
34
|
+
if (!((_time$event_list = time.event_list) !== null && _time$event_list !== void 0 && _time$event_list.length)) {
|
|
35
|
+
totalAvailableMinutes += overlapEnd.diff(overlapStart, 'minute');
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 处理时间段内的每个预约事件
|
|
40
|
+
var currentTime = overlapStart;
|
|
41
|
+
var _iterator2 = _createForOfIteratorHelper(time.event_list),
|
|
42
|
+
_step2;
|
|
43
|
+
try {
|
|
44
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
45
|
+
var event = _step2.value;
|
|
46
|
+
var eventStart = dayjs(event.start_at);
|
|
47
|
+
var eventEnd = dayjs(event.end_at);
|
|
48
|
+
|
|
49
|
+
// 如果事件在当前时间之前,跳过
|
|
50
|
+
if (eventEnd.isBefore(currentTime)) continue;
|
|
51
|
+
|
|
52
|
+
// 如果事件开始时间在重叠结束时间之后,可以添加剩余时间
|
|
53
|
+
if (eventStart.isAfter(overlapEnd)) {
|
|
54
|
+
totalAvailableMinutes += overlapEnd.diff(currentTime, 'minute');
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 如果事件开始时间在当前时间之后,添加事件开始前的时间
|
|
59
|
+
if (eventStart.isAfter(currentTime)) {
|
|
60
|
+
totalAvailableMinutes += eventStart.diff(currentTime, 'minute');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 对于单个预约类型,整个事件时间都是不可用的
|
|
64
|
+
if (resource.resourceType === 'single') {
|
|
65
|
+
currentTime = eventEnd;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 对于多个预约类型,检查容量
|
|
70
|
+
if (resource.resourceType === 'multiple') {
|
|
71
|
+
var remainingCapacity = (resource.capacity || 0) - (event.pax || 0);
|
|
72
|
+
if (remainingCapacity >= currentCapacity) {
|
|
73
|
+
// 如果剩余容量足够,这个时间段仍然是可用的
|
|
74
|
+
totalAvailableMinutes += eventEnd.diff(eventStart, 'minute');
|
|
75
|
+
}
|
|
76
|
+
currentTime = eventEnd;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 添加最后一个事件之后的剩余时间
|
|
81
|
+
} catch (err) {
|
|
82
|
+
_iterator2.e(err);
|
|
83
|
+
} finally {
|
|
84
|
+
_iterator2.f();
|
|
85
|
+
}
|
|
86
|
+
if (currentTime.isBefore(overlapEnd)) {
|
|
87
|
+
totalAvailableMinutes += overlapEnd.diff(currentTime, 'minute');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch (err) {
|
|
91
|
+
_iterator.e(err);
|
|
92
|
+
} finally {
|
|
93
|
+
_iterator.f();
|
|
94
|
+
}
|
|
95
|
+
return totalAvailableMinutes;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 查找最快可用的资源,如果有多个资源在相同时间点可用,则选择空闲时间最长的资源
|
|
100
|
+
* @param resources 资源列表
|
|
101
|
+
* @param currentCapacity 当前预约所需的容量
|
|
102
|
+
* @param countMap 已预约数量映射
|
|
103
|
+
* @returns 最快可用的资源
|
|
104
|
+
*/
|
|
105
|
+
export function findFastestAvailableResource(_ref2) {
|
|
106
|
+
var resources = _ref2.resources,
|
|
107
|
+
_ref2$currentCapacity = _ref2.currentCapacity,
|
|
108
|
+
currentCapacity = _ref2$currentCapacity === void 0 ? 1 : _ref2$currentCapacity,
|
|
109
|
+
_ref2$countMap = _ref2.countMap,
|
|
110
|
+
countMap = _ref2$countMap === void 0 ? {} : _ref2$countMap;
|
|
111
|
+
var currentTime = dayjs();
|
|
112
|
+
var fastestTime = null;
|
|
113
|
+
var fastestResources = [];
|
|
114
|
+
|
|
115
|
+
// 遍历所有资源,找到最快可用的时间点
|
|
116
|
+
var _iterator3 = _createForOfIteratorHelper(resources),
|
|
117
|
+
_step3;
|
|
118
|
+
try {
|
|
119
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
120
|
+
var _resource = _step3.value;
|
|
121
|
+
// 获取资源当天的时间段
|
|
122
|
+
var todayTimes = _resource.times.filter(function (time) {
|
|
123
|
+
return dayjs(time.start_at).isSame(currentTime, 'day');
|
|
124
|
+
});
|
|
125
|
+
if (todayTimes.length === 0) continue;
|
|
126
|
+
|
|
127
|
+
// 按开始时间排序
|
|
128
|
+
todayTimes.sort(function (a, b) {
|
|
129
|
+
return dayjs(a.start_at).diff(dayjs(b.start_at));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// 找到第一个可用的时间段
|
|
133
|
+
var _iterator4 = _createForOfIteratorHelper(todayTimes),
|
|
134
|
+
_step4;
|
|
135
|
+
try {
|
|
136
|
+
var _loop = function _loop() {
|
|
137
|
+
var time = _step4.value;
|
|
138
|
+
var startTime = dayjs(time.start_at);
|
|
139
|
+
|
|
140
|
+
// 如果开始时间在当前时间之前,跳过
|
|
141
|
+
if (startTime.isBefore(currentTime)) return 0; // continue
|
|
142
|
+
|
|
143
|
+
// 检查这个时间段是否可用
|
|
144
|
+
if (_resource.resourceType === 'single') {
|
|
145
|
+
var _time$event_list2;
|
|
146
|
+
// 单个预约类型:检查是否有预约
|
|
147
|
+
var hasBooking = (_time$event_list2 = time.event_list) === null || _time$event_list2 === void 0 ? void 0 : _time$event_list2.some(function (event) {
|
|
148
|
+
return dayjs(event.start_at).isSame(startTime);
|
|
149
|
+
});
|
|
150
|
+
if (!hasBooking) {
|
|
151
|
+
if (!fastestTime || startTime.isSame(fastestTime)) {
|
|
152
|
+
fastestTime = startTime;
|
|
153
|
+
fastestResources.push(_resource);
|
|
154
|
+
} else if (startTime.isBefore(fastestTime)) {
|
|
155
|
+
fastestTime = startTime;
|
|
156
|
+
fastestResources = [_resource];
|
|
157
|
+
}
|
|
158
|
+
return 1; // break
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
var _time$event_list3;
|
|
162
|
+
// 多个预约类型:检查容量
|
|
163
|
+
var totalCapacity = _resource.capacity || 0;
|
|
164
|
+
var usedCapacity = ((_time$event_list3 = time.event_list) === null || _time$event_list3 === void 0 ? void 0 : _time$event_list3.reduce(function (sum, event) {
|
|
165
|
+
return dayjs(event.start_at).isSame(startTime) ? sum + (event.pax || 0) : sum;
|
|
166
|
+
}, 0)) || 0;
|
|
167
|
+
var remainingCapacity = totalCapacity - usedCapacity;
|
|
168
|
+
if (remainingCapacity >= (countMap[_resource.id] || 0) + currentCapacity) {
|
|
169
|
+
if (!fastestTime || startTime.isSame(fastestTime)) {
|
|
170
|
+
fastestTime = startTime;
|
|
171
|
+
fastestResources.push(_resource);
|
|
172
|
+
} else if (startTime.isBefore(fastestTime)) {
|
|
173
|
+
fastestTime = startTime;
|
|
174
|
+
fastestResources = [_resource];
|
|
175
|
+
}
|
|
176
|
+
return 1; // break
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
_ret;
|
|
181
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
182
|
+
_ret = _loop();
|
|
183
|
+
if (_ret === 0) continue;
|
|
184
|
+
if (_ret === 1) break;
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
_iterator4.e(err);
|
|
188
|
+
} finally {
|
|
189
|
+
_iterator4.f();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 如果没有找到可用资源,返回null
|
|
194
|
+
} catch (err) {
|
|
195
|
+
_iterator3.e(err);
|
|
196
|
+
} finally {
|
|
197
|
+
_iterator3.f();
|
|
198
|
+
}
|
|
199
|
+
if (!fastestTime || fastestResources.length === 0) return null;
|
|
200
|
+
|
|
201
|
+
// 如果只有一个最快可用的资源,直接返回
|
|
202
|
+
if (fastestResources.length === 1) return fastestResources[0];
|
|
203
|
+
|
|
204
|
+
// 如果有多个最快可用的资源,比较它们的空闲时间
|
|
205
|
+
var maxIdleTime = 0;
|
|
206
|
+
var selectedResource = null;
|
|
207
|
+
for (var _i = 0, _fastestResources = fastestResources; _i < _fastestResources.length; _i++) {
|
|
208
|
+
var resource = _fastestResources[_i];
|
|
209
|
+
var idleTime = calculateResourceAvailableTime({
|
|
210
|
+
resource: resource,
|
|
211
|
+
timeSlots: {
|
|
212
|
+
start_time: fastestTime.format('HH:mm'),
|
|
213
|
+
end_time: fastestTime.format('HH:mm'),
|
|
214
|
+
start_at: fastestTime,
|
|
215
|
+
end_at: fastestTime
|
|
216
|
+
},
|
|
217
|
+
currentCapacity: (countMap[resource.id] || 0) + currentCapacity
|
|
218
|
+
});
|
|
219
|
+
if (idleTime > maxIdleTime) {
|
|
220
|
+
maxIdleTime = idleTime;
|
|
221
|
+
selectedResource = resource;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return selectedResource;
|
|
225
|
+
}
|
|
@@ -15,6 +15,8 @@ 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
|
+
setDateList(dateList: ITime[]): void;
|
|
19
|
+
fetchResourceDates(params: IGetAvailableTimeListParams): Promise<any>;
|
|
18
20
|
getResourceAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
|
|
19
21
|
clearDateRange(): void;
|
|
20
22
|
storeChange(): void;
|
|
@@ -65,18 +65,13 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
65
65
|
getDateList() {
|
|
66
66
|
return this.store.dateList;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
setDateList(dateList) {
|
|
69
|
+
this.store.dateList = dateList;
|
|
70
|
+
}
|
|
71
|
+
async fetchResourceDates(params) {
|
|
72
|
+
const { url, query } = params;
|
|
71
73
|
const fetchUrl = url || "/schedule/resource/list";
|
|
72
74
|
const { start_date, end_date, resource_ids } = query || {};
|
|
73
|
-
if (!start_date || !end_date) {
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
let dates = (0, import_utils.generateMonthDates)(start_date, end_date, type);
|
|
77
|
-
if (!(resource_ids == null ? void 0 : resource_ids.length)) {
|
|
78
|
-
return (0, import_utils.disableAllDates)(dates);
|
|
79
|
-
}
|
|
80
75
|
try {
|
|
81
76
|
const res = await this.request.get(fetchUrl, {
|
|
82
77
|
start_date,
|
|
@@ -86,6 +81,24 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
86
81
|
}, {
|
|
87
82
|
useCache: true
|
|
88
83
|
});
|
|
84
|
+
return res;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async getResourceAvailableTimeList(params) {
|
|
90
|
+
var _a;
|
|
91
|
+
const { query, rules, type } = params;
|
|
92
|
+
const { start_date, end_date, resource_ids } = query || {};
|
|
93
|
+
if (!start_date || !end_date) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
let dates = (0, import_utils.generateMonthDates)(start_date, end_date, type);
|
|
97
|
+
if (!(resource_ids == null ? void 0 : resource_ids.length)) {
|
|
98
|
+
return (0, import_utils.disableAllDates)(dates);
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const res = await this.fetchResourceDates(params);
|
|
89
102
|
if (!((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.length)) {
|
|
90
103
|
return (0, import_utils.disableAllDates)(dates);
|
|
91
104
|
}
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -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:
|
|
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,30 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
221
221
|
* @memberof BookingByStepImpl
|
|
222
222
|
*/
|
|
223
223
|
getResourcesByCartItemAndCode(cartItemId: string, resourceCode: string): any;
|
|
224
|
+
/**
|
|
225
|
+
* 根据日期范围批量获取时间槽
|
|
226
|
+
* @param params 参数对象
|
|
227
|
+
* @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
|
|
228
|
+
*/
|
|
229
|
+
getTimeslotsScheduleByDateRange({ startDate, endDate, scheduleIds, resources, }: {
|
|
230
|
+
startDate: string;
|
|
231
|
+
endDate: string;
|
|
232
|
+
scheduleIds?: number[];
|
|
233
|
+
resources?: ProductResourceItem[];
|
|
234
|
+
}): Promise<Record<string, TimeSliceItem[]>>;
|
|
224
235
|
getAvailableDateForSession(params?: {
|
|
225
236
|
startDate?: string;
|
|
226
237
|
endDate?: string;
|
|
227
238
|
type?: 'month';
|
|
228
|
-
}): Promise<
|
|
239
|
+
}): Promise<{
|
|
240
|
+
dateList: ITime[];
|
|
241
|
+
firstAvailableDate: ITime | undefined;
|
|
242
|
+
}>;
|
|
243
|
+
getAvailableDateForSessionOptimize(params?: {
|
|
244
|
+
startDate?: string;
|
|
245
|
+
endDate?: string;
|
|
246
|
+
}): Promise<{
|
|
247
|
+
dateList: any;
|
|
248
|
+
firstAvailableDate: any;
|
|
249
|
+
}>;
|
|
229
250
|
}
|