@pisell/pisellos 0.0.107 → 0.0.109
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/solution/BookingByStep/index.d.ts +9 -7
- package/dist/solution/BookingByStep/index.js +206 -42
- package/dist/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/dist/solution/BookingByStep/utils/resources.js +100 -1
- 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/solution/BookingByStep/index.d.ts +9 -7
- package/lib/solution/BookingByStep/index.js +193 -49
- package/lib/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/lib/solution/BookingByStep/utils/resources.js +73 -2
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -113,32 +113,23 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
113
113
|
return this.store.dateList;
|
|
114
114
|
}
|
|
115
115
|
}, {
|
|
116
|
-
key: "
|
|
116
|
+
key: "setDateList",
|
|
117
|
+
value: function setDateList(dateList) {
|
|
118
|
+
this.store.dateList = dateList;
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "fetchResourceDates",
|
|
117
122
|
value: function () {
|
|
118
|
-
var
|
|
119
|
-
var url, query,
|
|
123
|
+
var _fetchResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
|
|
124
|
+
var url, query, fetchUrl, _ref, start_date, end_date, resource_ids, res;
|
|
120
125
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
121
126
|
while (1) switch (_context3.prev = _context3.next) {
|
|
122
127
|
case 0:
|
|
123
|
-
url = params.url, query = params.query
|
|
128
|
+
url = params.url, query = params.query;
|
|
124
129
|
fetchUrl = url || '/schedule/resource/list';
|
|
125
130
|
_ref = query || {}, start_date = _ref.start_date, end_date = _ref.end_date, resource_ids = _ref.resource_ids;
|
|
126
|
-
|
|
127
|
-
|
|
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;
|
|
131
|
+
_context3.prev = 3;
|
|
132
|
+
_context3.next = 6;
|
|
142
133
|
return this.request.get(fetchUrl, {
|
|
143
134
|
start_date: start_date,
|
|
144
135
|
end_date: end_date,
|
|
@@ -147,14 +138,59 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
147
138
|
}, {
|
|
148
139
|
useCache: true
|
|
149
140
|
});
|
|
150
|
-
case
|
|
141
|
+
case 6:
|
|
151
142
|
res = _context3.sent;
|
|
143
|
+
return _context3.abrupt("return", res);
|
|
144
|
+
case 10:
|
|
145
|
+
_context3.prev = 10;
|
|
146
|
+
_context3.t0 = _context3["catch"](3);
|
|
147
|
+
console.error(_context3.t0);
|
|
148
|
+
case 13:
|
|
149
|
+
case "end":
|
|
150
|
+
return _context3.stop();
|
|
151
|
+
}
|
|
152
|
+
}, _callee3, this, [[3, 10]]);
|
|
153
|
+
}));
|
|
154
|
+
function fetchResourceDates(_x4) {
|
|
155
|
+
return _fetchResourceDates.apply(this, arguments);
|
|
156
|
+
}
|
|
157
|
+
return fetchResourceDates;
|
|
158
|
+
}()
|
|
159
|
+
}, {
|
|
160
|
+
key: "getResourceAvailableTimeList",
|
|
161
|
+
value: function () {
|
|
162
|
+
var _getResourceAvailableTimeList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
163
|
+
var query, rules, type, _ref2, start_date, end_date, resource_ids, dates, _res$data, res;
|
|
164
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
165
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
166
|
+
case 0:
|
|
167
|
+
query = params.query, rules = params.rules, type = params.type;
|
|
168
|
+
_ref2 = query || {}, start_date = _ref2.start_date, end_date = _ref2.end_date, resource_ids = _ref2.resource_ids;
|
|
169
|
+
if (!(!start_date || !end_date)) {
|
|
170
|
+
_context4.next = 4;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
return _context4.abrupt("return", []);
|
|
174
|
+
case 4:
|
|
175
|
+
// 1.生成当前月份的所有日期,默认都是可用的
|
|
176
|
+
dates = generateMonthDates(start_date, end_date, type); // 如果没有资源或者结束日期在今天之前,则所有日期均不可用
|
|
177
|
+
if (resource_ids !== null && resource_ids !== void 0 && resource_ids.length) {
|
|
178
|
+
_context4.next = 7;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
return _context4.abrupt("return", disableAllDates(dates));
|
|
182
|
+
case 7:
|
|
183
|
+
_context4.prev = 7;
|
|
184
|
+
_context4.next = 10;
|
|
185
|
+
return this.fetchResourceDates(params);
|
|
186
|
+
case 10:
|
|
187
|
+
res = _context4.sent;
|
|
152
188
|
if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.length) {
|
|
153
|
-
|
|
189
|
+
_context4.next = 13;
|
|
154
190
|
break;
|
|
155
191
|
}
|
|
156
|
-
return
|
|
157
|
-
case
|
|
192
|
+
return _context4.abrupt("return", disableAllDates(dates));
|
|
193
|
+
case 13:
|
|
158
194
|
// 2.根据资源times判定哪些日期内存在可用资源
|
|
159
195
|
dates = handleAvailableDateByResource(res.data, dates);
|
|
160
196
|
|
|
@@ -162,19 +198,19 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
162
198
|
if (rules !== null && rules !== void 0 && rules.length) {
|
|
163
199
|
dates = handleAvailableDatesByRules(dates, rules);
|
|
164
200
|
}
|
|
165
|
-
return
|
|
166
|
-
case
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
console.log('getAvailableTimeList_error',
|
|
170
|
-
return
|
|
171
|
-
case
|
|
201
|
+
return _context4.abrupt("return", dates);
|
|
202
|
+
case 18:
|
|
203
|
+
_context4.prev = 18;
|
|
204
|
+
_context4.t0 = _context4["catch"](7);
|
|
205
|
+
console.log('getAvailableTimeList_error', _context4.t0);
|
|
206
|
+
return _context4.abrupt("return", disableAllDates(dates));
|
|
207
|
+
case 22:
|
|
172
208
|
case "end":
|
|
173
|
-
return
|
|
209
|
+
return _context4.stop();
|
|
174
210
|
}
|
|
175
|
-
},
|
|
211
|
+
}, _callee4, this, [[7, 18]]);
|
|
176
212
|
}));
|
|
177
|
-
function getResourceAvailableTimeList(
|
|
213
|
+
function getResourceAvailableTimeList(_x5) {
|
|
178
214
|
return _getResourceAvailableTimeList.apply(this, arguments);
|
|
179
215
|
}
|
|
180
216
|
return getResourceAvailableTimeList;
|
|
@@ -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[];
|
|
@@ -211,7 +211,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
211
211
|
}): void;
|
|
212
212
|
setOtherData(key: string, value: any): void;
|
|
213
213
|
getOtherData(key: string): any;
|
|
214
|
-
getProductTypeById(id: number): Promise<"
|
|
214
|
+
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
215
215
|
/**
|
|
216
216
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
217
217
|
*
|
|
@@ -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
|
-
|
|
224
|
+
getAvailableDateForSessionOptimize(params?: {
|
|
225
225
|
startDate?: string;
|
|
226
226
|
endDate?: string;
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
}): Promise<{
|
|
228
|
+
dateList: any;
|
|
229
|
+
firstAvailableDate: any;
|
|
230
|
+
}>;
|
|
229
231
|
}
|
|
@@ -27,12 +27,16 @@ 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";
|
|
36
40
|
export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
37
41
|
_inherits(BookingByStepImpl, _BaseModule);
|
|
38
42
|
var _super = _createSuper(BookingByStepImpl);
|
|
@@ -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 =
|
|
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,226 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2605
2606
|
return targetResource.renderList;
|
|
2606
2607
|
}
|
|
2607
2608
|
}, {
|
|
2608
|
-
key: "
|
|
2609
|
+
key: "getAvailableDateForSessionOptimize",
|
|
2609
2610
|
value: function () {
|
|
2610
|
-
var
|
|
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
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
resourcesMap,
|
|
2618
|
+
schedule,
|
|
2619
|
+
filteredSchedule,
|
|
2620
|
+
tempResourceIds,
|
|
2620
2621
|
res,
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
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 =
|
|
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
|
|
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
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
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:
|
|
2648
|
-
}
|
|
2649
|
-
rules: rules,
|
|
2650
|
-
type: type
|
|
2666
|
+
resource_ids: tempResourceIds
|
|
2667
|
+
}
|
|
2651
2668
|
});
|
|
2652
|
-
case
|
|
2653
|
-
res =
|
|
2654
|
-
|
|
2655
|
-
|
|
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
|
+
dates = handleAvailableDateByResource(res.data, dates);
|
|
2806
|
+
this.store.date.setDateList(dates);
|
|
2807
|
+
|
|
2808
|
+
// 缓存这次结果,以防后面他小幅度范围内去修改天数
|
|
2809
|
+
(_this$store$currentPr6 = this.store.currentProduct) === null || _this$store$currentPr6 === void 0 || _this$store$currentPr6.setOtherParams('timeSlotBySchedule', {
|
|
2810
|
+
dateList: dates,
|
|
2811
|
+
firstAvailableDate: firstAvailableDate,
|
|
2812
|
+
startDate: startDate,
|
|
2813
|
+
endDate: endDate
|
|
2814
|
+
});
|
|
2815
|
+
return _context30.abrupt("return", {
|
|
2816
|
+
dateList: dates,
|
|
2817
|
+
firstAvailableDate: firstAvailableDate
|
|
2818
|
+
});
|
|
2819
|
+
case 32:
|
|
2656
2820
|
case "end":
|
|
2657
|
-
return
|
|
2821
|
+
return _context30.stop();
|
|
2658
2822
|
}
|
|
2659
2823
|
}, _callee28, this);
|
|
2660
2824
|
}));
|
|
2661
|
-
function
|
|
2662
|
-
return
|
|
2825
|
+
function getAvailableDateForSessionOptimize() {
|
|
2826
|
+
return _getAvailableDateForSessionOptimize.apply(this, arguments);
|
|
2663
2827
|
}
|
|
2664
|
-
return
|
|
2828
|
+
return getAvailableDateForSessionOptimize;
|
|
2665
2829
|
}()
|
|
2666
2830
|
}]);
|
|
2667
2831
|
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 {};
|