@pisell/pisellos 3.0.64 → 3.0.66
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.js +4 -0
- package/dist/solution/BookingByStep/index.d.ts +16 -4
- package/dist/solution/BookingByStep/index.js +702 -110
- package/dist/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/dist/solution/BookingByStep/utils/capacity.js +230 -1
- package/dist/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/dist/solution/BookingByStep/utils/resources.js +1 -1
- package/dist/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/dist/solution/BookingByStep/utils/stock.js +126 -0
- package/lib/modules/Date/index.js +3 -0
- package/lib/solution/BookingByStep/index.d.ts +16 -4
- package/lib/solution/BookingByStep/index.js +387 -9
- package/lib/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/lib/solution/BookingByStep/utils/capacity.js +166 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/lib/solution/BookingByStep/utils/resources.js +2 -0
- package/lib/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/lib/solution/BookingByStep/utils/stock.js +89 -0
- package/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
5
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
2
6
|
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; } } }; }
|
|
3
7
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
8
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -27,7 +31,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
27
31
|
import { BaseModule } from "../../modules/BaseModule";
|
|
28
32
|
import { BookingByStepHooks, createModule } from "./types";
|
|
29
33
|
import { getAvailableProductResources } from "./utils/products";
|
|
30
|
-
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime,
|
|
34
|
+
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
|
|
31
35
|
import dayjs from 'dayjs';
|
|
32
36
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
33
37
|
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
@@ -40,7 +44,8 @@ import { handleAvailableDateByResource } from "../../modules/Date/utils";
|
|
|
40
44
|
import { areAllNormalProducts, isNormalProduct } from "../../modules/Product/utils";
|
|
41
45
|
import { calculateResourceAvailableTime, filterConditionTimeSlots, findFastestAvailableResource } from "./utils/timeslots";
|
|
42
46
|
import { updateAllCartItemPrice } from "../../modules/Cart/utils/changePrice";
|
|
43
|
-
import { getCapacityInfoByCartItem, checkSubResourcesCapacity, checkResourceCanUseByCapacity } from "./utils/capacity";
|
|
47
|
+
import { getCapacityInfoByCartItem, checkSubResourcesCapacity, checkResourceCanUseByCapacity, getResourcesIdsByProduct, checkTimeSlotCapacity } from "./utils/capacity";
|
|
48
|
+
import { checkProductStock } from "./utils/stock";
|
|
44
49
|
export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
45
50
|
_inherits(BookingByStepImpl, _BaseModule);
|
|
46
51
|
var _super = _createSuper(BookingByStepImpl);
|
|
@@ -1101,29 +1106,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1101
1106
|
*/
|
|
1102
1107
|
}, {
|
|
1103
1108
|
key: "storeProduct",
|
|
1104
|
-
value:
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
account: activeAccount
|
|
1115
|
-
});
|
|
1116
|
-
case 2:
|
|
1117
|
-
case "end":
|
|
1118
|
-
return _context24.stop();
|
|
1119
|
-
}
|
|
1120
|
-
}, _callee24, this);
|
|
1121
|
-
}));
|
|
1122
|
-
function storeProduct(_x18) {
|
|
1123
|
-
return _storeProduct.apply(this, arguments);
|
|
1124
|
-
}
|
|
1125
|
-
return storeProduct;
|
|
1126
|
-
}()
|
|
1109
|
+
value: function storeProduct(productData) {
|
|
1110
|
+
// 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
|
|
1111
|
+
var activeAccount = this.getActiveAccount();
|
|
1112
|
+
// 直接调用 addProductToCart,不传递 date 参数以避免日期检查逻辑
|
|
1113
|
+
return this.addProductToCart({
|
|
1114
|
+
product: productData,
|
|
1115
|
+
account: activeAccount
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1127
1119
|
/**
|
|
1128
1120
|
* 往购物车加商品数据
|
|
1129
1121
|
*
|
|
@@ -1139,7 +1131,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1139
1131
|
* @return {*}
|
|
1140
1132
|
* @memberof BookingByStepImpl
|
|
1141
1133
|
*/
|
|
1142
|
-
)
|
|
1143
1134
|
}, {
|
|
1144
1135
|
key: "addProductToCart",
|
|
1145
1136
|
value: function addProductToCart(_ref6) {
|
|
@@ -1157,6 +1148,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1157
1148
|
var productData = _objectSpread(_objectSpread({}, origin), {}, {
|
|
1158
1149
|
product_variant_id: product_variant_id
|
|
1159
1150
|
});
|
|
1151
|
+
|
|
1152
|
+
// 库存检测
|
|
1153
|
+
var currentCartItems = this.store.cart.getItems();
|
|
1154
|
+
var stockCheckResult = checkProductStock({
|
|
1155
|
+
productData: productData,
|
|
1156
|
+
product_variant_id: product_variant_id,
|
|
1157
|
+
quantity: quantity,
|
|
1158
|
+
bundle: bundle,
|
|
1159
|
+
currentCartItems: currentCartItems
|
|
1160
|
+
});
|
|
1161
|
+
|
|
1162
|
+
// 如果库存检测失败,直接返回
|
|
1163
|
+
if (!stockCheckResult.success) {
|
|
1164
|
+
return stockCheckResult;
|
|
1165
|
+
}
|
|
1160
1166
|
if (!account) {
|
|
1161
1167
|
var activeAccount = this.getActiveAccount();
|
|
1162
1168
|
if (activeAccount) {
|
|
@@ -1169,7 +1175,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1169
1175
|
account: account || undefined
|
|
1170
1176
|
});
|
|
1171
1177
|
if (flag) {
|
|
1172
|
-
return
|
|
1178
|
+
return {
|
|
1179
|
+
success: true
|
|
1180
|
+
};
|
|
1173
1181
|
}
|
|
1174
1182
|
var addItemParams = {
|
|
1175
1183
|
product: productData,
|
|
@@ -1187,6 +1195,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1187
1195
|
date: date
|
|
1188
1196
|
});
|
|
1189
1197
|
this.store.cart.addItem(addItemParams);
|
|
1198
|
+
return {
|
|
1199
|
+
success: true
|
|
1200
|
+
};
|
|
1190
1201
|
}
|
|
1191
1202
|
|
|
1192
1203
|
/**
|
|
@@ -2039,7 +2050,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2039
2050
|
// item._origin.resources?.forEach((n: any) => {
|
|
2040
2051
|
// resourceIds.push(n.relation_id);
|
|
2041
2052
|
// });
|
|
2042
|
-
if (item.resource_id) {
|
|
2053
|
+
if (item.resource_id && !resourceIds.includes(item.resource_id)) {
|
|
2043
2054
|
resourceIds.push(item.resource_id);
|
|
2044
2055
|
}
|
|
2045
2056
|
resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.resources) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.find(function (n) {
|
|
@@ -2134,6 +2145,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2134
2145
|
return 0;
|
|
2135
2146
|
}, 0);
|
|
2136
2147
|
}
|
|
2148
|
+
// 计算容量的辅助函数
|
|
2149
|
+
var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
|
|
2150
|
+
return items.reduce(function (total, item) {
|
|
2151
|
+
return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
|
|
2152
|
+
}, 0);
|
|
2153
|
+
};
|
|
2154
|
+
|
|
2155
|
+
// 如果是多个预约,去要求助几个 holder 下最大的需求容量capacity
|
|
2156
|
+
var maxCapacity = 1;
|
|
2157
|
+
if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
|
|
2158
|
+
accountList.forEach(function (account) {
|
|
2159
|
+
var accountCartItems = _this12.store.cart.getCartByAccount(account.getId());
|
|
2160
|
+
var currentCapacity = calculateCapacityFromCartItems(accountCartItems);
|
|
2161
|
+
if (currentCapacity > maxCapacity) {
|
|
2162
|
+
maxCapacity = currentCapacity;
|
|
2163
|
+
}
|
|
2164
|
+
});
|
|
2165
|
+
} else {
|
|
2166
|
+
maxCapacity = calculateCapacityFromCartItems(cartItems);
|
|
2167
|
+
}
|
|
2137
2168
|
var timeSlots = getTimeSlicesByResources({
|
|
2138
2169
|
resourceIds: resourceIds,
|
|
2139
2170
|
resourcesMap: resourcesMap,
|
|
@@ -2141,6 +2172,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2141
2172
|
currentDate: dateRange[0].date,
|
|
2142
2173
|
split: 10,
|
|
2143
2174
|
resourcesUseableMap: resourcesUseableMap,
|
|
2175
|
+
capacity: maxCapacity,
|
|
2144
2176
|
cut_off_time: maxCutOffTime,
|
|
2145
2177
|
hasFlexibleDuration: hasFlexibleDuration,
|
|
2146
2178
|
operating_day_boundary: operating_day_boundary,
|
|
@@ -2242,12 +2274,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2242
2274
|
});
|
|
2243
2275
|
});
|
|
2244
2276
|
}
|
|
2245
|
-
}, {
|
|
2246
|
-
key: "clearCache",
|
|
2247
|
-
value: function clearCache() {}
|
|
2248
|
-
}, {
|
|
2249
|
-
key: "clearCacheByModule",
|
|
2250
|
-
value: function clearCacheByModule(module) {}
|
|
2251
2277
|
}, {
|
|
2252
2278
|
key: "getScheduleDataByIds",
|
|
2253
2279
|
value: function getScheduleDataByIds(scheduleIds) {
|
|
@@ -2278,42 +2304,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2278
2304
|
}, {
|
|
2279
2305
|
key: "openProductDetail",
|
|
2280
2306
|
value: function () {
|
|
2281
|
-
var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2307
|
+
var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(productId) {
|
|
2282
2308
|
var targetProductData, newScheduleArr, dateRange;
|
|
2283
|
-
return _regeneratorRuntime().wrap(function
|
|
2284
|
-
while (1) switch (
|
|
2309
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2310
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
2285
2311
|
case 0:
|
|
2286
|
-
|
|
2312
|
+
_context24.next = 2;
|
|
2287
2313
|
return this.store.products.getProduct(productId);
|
|
2288
2314
|
case 2:
|
|
2289
|
-
targetProductData =
|
|
2315
|
+
targetProductData = _context24.sent;
|
|
2290
2316
|
if (!targetProductData) {
|
|
2291
|
-
|
|
2317
|
+
_context24.next = 17;
|
|
2292
2318
|
break;
|
|
2293
2319
|
}
|
|
2294
2320
|
this.store.currentProduct = targetProductData;
|
|
2295
2321
|
this.store.currentProductMeta = {};
|
|
2296
2322
|
// 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
|
|
2297
2323
|
if (!targetProductData['schedule.ids']) {
|
|
2298
|
-
|
|
2324
|
+
_context24.next = 12;
|
|
2299
2325
|
break;
|
|
2300
2326
|
}
|
|
2301
2327
|
newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
|
|
2302
2328
|
if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
|
|
2303
2329
|
this.store.currentProductMeta.schedule = newScheduleArr;
|
|
2304
|
-
|
|
2330
|
+
_context24.next = 17;
|
|
2305
2331
|
break;
|
|
2306
2332
|
case 12:
|
|
2307
2333
|
if (!targetProductData.duration) {
|
|
2308
|
-
|
|
2334
|
+
_context24.next = 17;
|
|
2309
2335
|
break;
|
|
2310
2336
|
}
|
|
2311
2337
|
dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
|
|
2312
2338
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
2313
|
-
|
|
2339
|
+
_context24.next = 16;
|
|
2314
2340
|
break;
|
|
2315
2341
|
}
|
|
2316
|
-
return
|
|
2342
|
+
return _context24.abrupt("return");
|
|
2317
2343
|
case 16:
|
|
2318
2344
|
// this.store.date.getResourceDates({
|
|
2319
2345
|
// query: {
|
|
@@ -2329,11 +2355,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2329
2355
|
});
|
|
2330
2356
|
case 17:
|
|
2331
2357
|
case "end":
|
|
2332
|
-
return
|
|
2358
|
+
return _context24.stop();
|
|
2333
2359
|
}
|
|
2334
|
-
},
|
|
2360
|
+
}, _callee24, this);
|
|
2335
2361
|
}));
|
|
2336
|
-
function openProductDetail(
|
|
2362
|
+
function openProductDetail(_x18) {
|
|
2337
2363
|
return _openProductDetail.apply(this, arguments);
|
|
2338
2364
|
}
|
|
2339
2365
|
return openProductDetail;
|
|
@@ -2346,10 +2372,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2346
2372
|
}
|
|
2347
2373
|
this.store.currentProduct = undefined;
|
|
2348
2374
|
}
|
|
2375
|
+
|
|
2376
|
+
// 通过商品和 schedule 来获取视频可用的时间片、时间片内资源可用的数据
|
|
2349
2377
|
}, {
|
|
2350
2378
|
key: "getTimeslotBySchedule",
|
|
2351
2379
|
value: function getTimeslotBySchedule(_ref10) {
|
|
2352
|
-
var _this$store$currentPr2,
|
|
2380
|
+
var _this$store$currentPr2,
|
|
2381
|
+
_targetProductData$pr,
|
|
2382
|
+
_this14 = this;
|
|
2353
2383
|
var date = _ref10.date,
|
|
2354
2384
|
scheduleIds = _ref10.scheduleIds,
|
|
2355
2385
|
resources = _ref10.resources,
|
|
@@ -2456,6 +2486,138 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2456
2486
|
}
|
|
2457
2487
|
}
|
|
2458
2488
|
});
|
|
2489
|
+
// 容量检测
|
|
2490
|
+
var cartItems = _this14.store.cart.getItems();
|
|
2491
|
+
productResources.forEach(function (n) {
|
|
2492
|
+
// 单个预约检测规则:
|
|
2493
|
+
// 1、跟我一样的商品同一时间在购物车里不可以超过我最少的那种资源的关联的资源个数
|
|
2494
|
+
// 2、跟我不一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,她配置了几个资源的个数+我配置了几个资源的个数,然后购物车里有几个这样的商品,对应的资源做一个去重,不超过这个去重以后的总数
|
|
2495
|
+
if (n.type === 'single') {
|
|
2496
|
+
var currentResourcesSet = new Set([].concat(_toConsumableArray(n.optional_resource), _toConsumableArray(n.default_resource)));
|
|
2497
|
+
// 规则 1
|
|
2498
|
+
var sameCartItems = cartItems.filter(function (m) {
|
|
2499
|
+
var _m$_productOrigin, _targetProductData$id;
|
|
2500
|
+
return ((_m$_productOrigin = m._productOrigin) === null || _m$_productOrigin === void 0 || (_m$_productOrigin = _m$_productOrigin.id) === null || _m$_productOrigin === void 0 ? void 0 : _m$_productOrigin.toString()) === (targetProductData === null || targetProductData === void 0 || (_targetProductData$id = targetProductData.id) === null || _targetProductData$id === void 0 ? void 0 : _targetProductData$id.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
|
|
2501
|
+
});
|
|
2502
|
+
if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
|
|
2503
|
+
bookingLeft = 0;
|
|
2504
|
+
count = 0;
|
|
2505
|
+
}
|
|
2506
|
+
// 规则 2
|
|
2507
|
+
var otherCartItems = cartItems.filter(function (m) {
|
|
2508
|
+
var _m$_productOrigin2, _targetProductData$id2;
|
|
2509
|
+
return ((_m$_productOrigin2 = m._productOrigin) === null || _m$_productOrigin2 === void 0 || (_m$_productOrigin2 = _m$_productOrigin2.id) === null || _m$_productOrigin2 === void 0 ? void 0 : _m$_productOrigin2.toString()) !== (targetProductData === null || targetProductData === void 0 || (_targetProductData$id2 = targetProductData.id) === null || _targetProductData$id2 === void 0 ? void 0 : _targetProductData$id2.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
|
|
2510
|
+
});
|
|
2511
|
+
otherCartItems.forEach(function (m) {
|
|
2512
|
+
var _m$_productOrigin3;
|
|
2513
|
+
var sameTypeResources = (_m$_productOrigin3 = m._productOrigin) === null || _m$_productOrigin3 === void 0 || (_m$_productOrigin3 = _m$_productOrigin3.product_resource) === null || _m$_productOrigin3 === void 0 || (_m$_productOrigin3 = _m$_productOrigin3.resources) === null || _m$_productOrigin3 === void 0 ? void 0 : _m$_productOrigin3.find(function (m) {
|
|
2514
|
+
return m.type === n.type;
|
|
2515
|
+
});
|
|
2516
|
+
var sameTypeResourcesSet = new Set([].concat(_toConsumableArray((sameTypeResources === null || sameTypeResources === void 0 ? void 0 : sameTypeResources.optional_resource) || []), _toConsumableArray((sameTypeResources === null || sameTypeResources === void 0 ? void 0 : sameTypeResources.default_resource) || [])));
|
|
2517
|
+
// 把sameTypeResourcesSet 加到currentResourcesSet
|
|
2518
|
+
sameTypeResourcesSet.forEach(function (resource) {
|
|
2519
|
+
return currentResourcesSet.add(resource);
|
|
2520
|
+
});
|
|
2521
|
+
});
|
|
2522
|
+
// 先确定是否每一个currentResourcesSet在这个时间点的 event_list 都是空的,如果不是空的还需要把他踢出currentResourcesSet
|
|
2523
|
+
var currentDataResources = _this14.store.date.getResourcesListByDate(dayjs(item.start).format('YYYY-MM-DD'));
|
|
2524
|
+
currentDataResources === null || currentDataResources === void 0 || currentDataResources.forEach(function (m) {
|
|
2525
|
+
if (currentResourcesSet.has(m.id)) {
|
|
2526
|
+
var mTimes = m.times.filter(function (n) {
|
|
2527
|
+
return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
|
|
2528
|
+
});
|
|
2529
|
+
if (!mTimes.length || mTimes.some(function (n) {
|
|
2530
|
+
return n.event_list.length;
|
|
2531
|
+
})) {
|
|
2532
|
+
currentResourcesSet.delete(m.id);
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
2536
|
+
if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
|
|
2537
|
+
bookingLeft = 0;
|
|
2538
|
+
count = 0;
|
|
2539
|
+
}
|
|
2540
|
+
} else {
|
|
2541
|
+
// 多个预约的检测规则:
|
|
2542
|
+
// 规则1、跟我一样的商品同一时间在购物车需要的容量总数不可以超过我配置的资源的 capacity 之和
|
|
2543
|
+
var _sameCartItems = cartItems.filter(function (m) {
|
|
2544
|
+
var _m$_productOrigin4, _targetProductData$id3;
|
|
2545
|
+
return ((_m$_productOrigin4 = m._productOrigin) === null || _m$_productOrigin4 === void 0 || (_m$_productOrigin4 = _m$_productOrigin4.id) === null || _m$_productOrigin4 === void 0 ? void 0 : _m$_productOrigin4.toString()) === (targetProductData === null || targetProductData === void 0 || (_targetProductData$id3 = targetProductData.id) === null || _targetProductData$id3 === void 0 ? void 0 : _targetProductData$id3.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
|
|
2546
|
+
});
|
|
2547
|
+
var sameCartNeedCapacity = _sameCartItems.reduce(function (acc, curr) {
|
|
2548
|
+
return acc + getCapacityInfoByCartItem(curr).currentCapacity;
|
|
2549
|
+
}, 0);
|
|
2550
|
+
var currentProductResourcesCapacity = n.renderList.reduce(function (acc, curr) {
|
|
2551
|
+
return !curr.onlyComputed ? acc + curr.capacity || 0 : acc;
|
|
2552
|
+
}, 0);
|
|
2553
|
+
if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
|
|
2554
|
+
bookingLeft = 0;
|
|
2555
|
+
count = 0;
|
|
2556
|
+
}
|
|
2557
|
+
// 规则2、不管是不是跟我一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,把所有购物车的 capacity 之和 和 所有当前类型资源的 capacity 之和比较,如果超过了resourcesCapacity,则不可用
|
|
2558
|
+
// const otherCartItems = cartItems.filter((m) => m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && m.start_time === item.start && m.end_time === item.end);
|
|
2559
|
+
var otherSameTimesCartItems = cartItems.filter(function (m) {
|
|
2560
|
+
return "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
|
|
2561
|
+
});
|
|
2562
|
+
var otherCartNeedCapacity = otherSameTimesCartItems.reduce(function (acc, curr) {
|
|
2563
|
+
return acc + getCapacityInfoByCartItem(curr).currentCapacity;
|
|
2564
|
+
}, 0);
|
|
2565
|
+
var allRenderList = _toConsumableArray(n.renderList.filter(function (m) {
|
|
2566
|
+
return !m.onlyComputed;
|
|
2567
|
+
}));
|
|
2568
|
+
otherSameTimesCartItems.forEach(function (m) {
|
|
2569
|
+
var _m$_productOrigin5;
|
|
2570
|
+
var productResources = getResourcesByProduct(getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []), ((_m$_productOrigin5 = m._productOrigin) === null || _m$_productOrigin5 === void 0 || (_m$_productOrigin5 = _m$_productOrigin5.product_resource) === null || _m$_productOrigin5 === void 0 ? void 0 : _m$_productOrigin5.resources) || [], selectedResources, 1);
|
|
2571
|
+
productResources.forEach(function (m) {
|
|
2572
|
+
if (m.id === n.id) {
|
|
2573
|
+
m.renderList.forEach(function (n) {
|
|
2574
|
+
if (!n.onlyComputed && !allRenderList.find(function (m) {
|
|
2575
|
+
return m.id === n.id;
|
|
2576
|
+
})) {
|
|
2577
|
+
allRenderList.push(n);
|
|
2578
|
+
}
|
|
2579
|
+
});
|
|
2580
|
+
}
|
|
2581
|
+
});
|
|
2582
|
+
});
|
|
2583
|
+
var currentTypeResourcesCapacity = allRenderList.reduce(function (acc, curr) {
|
|
2584
|
+
return acc + curr.capacity || 0;
|
|
2585
|
+
}, 0);
|
|
2586
|
+
// 计算当前时间段内所有资源的已使用容量
|
|
2587
|
+
var usedCapacity = allRenderList.reduce(function (acc, curr) {
|
|
2588
|
+
var mTimes = curr.times.filter(function (n) {
|
|
2589
|
+
return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
|
|
2590
|
+
});
|
|
2591
|
+
// 这里为什么要设置个 map,因为有可能日程有重叠,所以要把重叠的 event_list 去除
|
|
2592
|
+
var mSet = new Map();
|
|
2593
|
+
mTimes.forEach(function (n) {
|
|
2594
|
+
// acc += n.event_list?.reduce((acc: any, curr: any) => acc + curr.pax, 0);
|
|
2595
|
+
// mSet.set(n)
|
|
2596
|
+
n.event_list.forEach(function (m) {
|
|
2597
|
+
// 需要确认 m 的时间段是否和 item 的时间段有交集
|
|
2598
|
+
if (isConflict({
|
|
2599
|
+
start_at: m.start_at,
|
|
2600
|
+
end_at: m.end_at
|
|
2601
|
+
}, {
|
|
2602
|
+
start_at: dayjs(item.start),
|
|
2603
|
+
end_at: dayjs(item.end)
|
|
2604
|
+
})) {
|
|
2605
|
+
mSet.set(m.id, m.pax || 1);
|
|
2606
|
+
}
|
|
2607
|
+
});
|
|
2608
|
+
});
|
|
2609
|
+
acc += Array.from(mSet.values()).reduce(function (acc, curr) {
|
|
2610
|
+
return acc + curr;
|
|
2611
|
+
}, 0);
|
|
2612
|
+
return acc;
|
|
2613
|
+
}, 0);
|
|
2614
|
+
// 如果已使用容量超过了当前类型资源的容量,则不可用
|
|
2615
|
+
if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
|
|
2616
|
+
bookingLeft = 0;
|
|
2617
|
+
count = 0;
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
});
|
|
2459
2621
|
var startDayJs = dayjs(item.start);
|
|
2460
2622
|
var endDayJs = dayjs(item.end);
|
|
2461
2623
|
return {
|
|
@@ -2469,6 +2631,436 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2469
2631
|
});
|
|
2470
2632
|
return formatScheduleTimeSlots;
|
|
2471
2633
|
}
|
|
2634
|
+
|
|
2635
|
+
// 提供给 UI的方法,当前步骤是选择商品,下一步不管是什么都需要在这里做一次检测
|
|
2636
|
+
// 时长类商品关联的资源为多个预约时,在点击进入"选择资源"步骤之前,需要检测当前所有资源的总容量
|
|
2637
|
+
// 选择商品数量大于所有资源配置的总容量时,不能进入下一步,需要在"选择商品"这一步时提示。
|
|
2638
|
+
// 注意 资源分为多个种类,需要每个种类单独检测,不能一股脑把所有资源的容量加起来检测
|
|
2639
|
+
/**
|
|
2640
|
+
* 找到多个资源的公共可用时间段
|
|
2641
|
+
*/
|
|
2642
|
+
}, {
|
|
2643
|
+
key: "findCommonAvailableTimeSlots",
|
|
2644
|
+
value: function findCommonAvailableTimeSlots(resources) {
|
|
2645
|
+
if (resources.length === 0) return [];
|
|
2646
|
+
console.log("\u8BA1\u7B97 ".concat(resources.length, " \u4E2A\u8D44\u6E90\u7684\u516C\u5171\u65F6\u95F4\u6BB5"));
|
|
2647
|
+
|
|
2648
|
+
// 收集所有资源的时间段,转换为统一的时间格式
|
|
2649
|
+
var allTimeSlots = resources.map(function (resource) {
|
|
2650
|
+
return resource.times.map(function (time) {
|
|
2651
|
+
return {
|
|
2652
|
+
start: dayjs(time.start_at),
|
|
2653
|
+
end: dayjs(time.end_at)
|
|
2654
|
+
};
|
|
2655
|
+
});
|
|
2656
|
+
});
|
|
2657
|
+
console.log('所有资源的时间段:', allTimeSlots.map(function (slots) {
|
|
2658
|
+
return slots.map(function (slot) {
|
|
2659
|
+
return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
|
|
2660
|
+
});
|
|
2661
|
+
}));
|
|
2662
|
+
|
|
2663
|
+
// 找到公共时间段的交集
|
|
2664
|
+
var commonSlots = allTimeSlots[0]; // 从第一个资源的时间段开始
|
|
2665
|
+
console.log('初始公共时间段:', commonSlots.map(function (slot) {
|
|
2666
|
+
return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
|
|
2667
|
+
}));
|
|
2668
|
+
|
|
2669
|
+
// 与其他资源的时间段求交集
|
|
2670
|
+
var _loop2 = function _loop2() {
|
|
2671
|
+
var currentResourceSlots = allTimeSlots[i];
|
|
2672
|
+
var intersections = [];
|
|
2673
|
+
|
|
2674
|
+
// 计算当前公共时间段与下一个资源时间段的交集
|
|
2675
|
+
commonSlots.forEach(function (commonSlot) {
|
|
2676
|
+
currentResourceSlots.forEach(function (currentSlot) {
|
|
2677
|
+
var overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
|
|
2678
|
+
var overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
|
|
2679
|
+
|
|
2680
|
+
// 如果有重叠时间且重叠时间大于0
|
|
2681
|
+
if (overlapStart.isBefore(overlapEnd)) {
|
|
2682
|
+
intersections.push({
|
|
2683
|
+
start: overlapStart,
|
|
2684
|
+
end: overlapEnd
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
});
|
|
2688
|
+
});
|
|
2689
|
+
commonSlots = intersections;
|
|
2690
|
+
console.log("\u4E0E\u8D44\u6E90".concat(i, "\u6C42\u4EA4\u96C6\u540E\u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonSlots.map(function (slot) {
|
|
2691
|
+
return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
|
|
2692
|
+
}));
|
|
2693
|
+
|
|
2694
|
+
// 如果没有公共时间段,直接返回
|
|
2695
|
+
if (commonSlots.length === 0) {
|
|
2696
|
+
console.log('没有找到公共时间段');
|
|
2697
|
+
return {
|
|
2698
|
+
v: []
|
|
2699
|
+
};
|
|
2700
|
+
}
|
|
2701
|
+
},
|
|
2702
|
+
_ret2;
|
|
2703
|
+
for (var i = 1; i < allTimeSlots.length; i++) {
|
|
2704
|
+
_ret2 = _loop2();
|
|
2705
|
+
if (_ret2) return _ret2.v;
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
// 格式化返回结果
|
|
2709
|
+
var result = commonSlots.map(function (slot) {
|
|
2710
|
+
return {
|
|
2711
|
+
startTime: slot.start.format('HH:mm'),
|
|
2712
|
+
endTime: slot.end.format('HH:mm')
|
|
2713
|
+
};
|
|
2714
|
+
});
|
|
2715
|
+
console.log('最终公共时间段:', result);
|
|
2716
|
+
return result;
|
|
2717
|
+
}
|
|
2718
|
+
}, {
|
|
2719
|
+
key: "checkMaxDurationCapacity",
|
|
2720
|
+
value: function checkMaxDurationCapacity() {
|
|
2721
|
+
var _this15 = this;
|
|
2722
|
+
var cartItems = cloneDeep(this.store.cart.getItems());
|
|
2723
|
+
if (cartItems.length === 0) return {
|
|
2724
|
+
success: true,
|
|
2725
|
+
minAvailableCount: 0
|
|
2726
|
+
};
|
|
2727
|
+
|
|
2728
|
+
// 将购物车商品分为有时间的和没有时间的
|
|
2729
|
+
var itemsWithTime = [];
|
|
2730
|
+
var itemsWithoutTime = [];
|
|
2731
|
+
// 记录每种资源类型的可用数量
|
|
2732
|
+
var availableCountsByResourceType = [];
|
|
2733
|
+
cartItems.forEach(function (cartItem) {
|
|
2734
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
2735
|
+
itemsWithTime.push(cartItem);
|
|
2736
|
+
} else {
|
|
2737
|
+
itemsWithoutTime.push(cartItem);
|
|
2738
|
+
}
|
|
2739
|
+
});
|
|
2740
|
+
|
|
2741
|
+
// 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
|
|
2742
|
+
var processedItemsWithoutTime = [];
|
|
2743
|
+
if (itemsWithoutTime.length > 0) {
|
|
2744
|
+
// 按资源类型分组处理没有时间的商品
|
|
2745
|
+
var itemsByResourceType = {};
|
|
2746
|
+
itemsWithoutTime.forEach(function (cartItem) {
|
|
2747
|
+
var _cartItem$_productOri10;
|
|
2748
|
+
if (!cartItem._productOrigin) return;
|
|
2749
|
+
var resourceTypes = ((_cartItem$_productOri10 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.resources) || [];
|
|
2750
|
+
resourceTypes.forEach(function (resourceType) {
|
|
2751
|
+
if (resourceType.status === 1) {
|
|
2752
|
+
var _resourceType$id;
|
|
2753
|
+
var resourceCode = resourceType.code || ((_resourceType$id = resourceType.id) === null || _resourceType$id === void 0 ? void 0 : _resourceType$id.toString());
|
|
2754
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
2755
|
+
itemsByResourceType[resourceCode] = [];
|
|
2756
|
+
}
|
|
2757
|
+
// 避免重复添加同一个商品
|
|
2758
|
+
if (!itemsByResourceType[resourceCode].find(function (item) {
|
|
2759
|
+
return item._id === cartItem._id;
|
|
2760
|
+
})) {
|
|
2761
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
});
|
|
2765
|
+
});
|
|
2766
|
+
|
|
2767
|
+
// 为每种资源类型检查容量
|
|
2768
|
+
var dateRange = this.store.date.getDateRange();
|
|
2769
|
+
if (!dateRange || dateRange.length === 0) return {
|
|
2770
|
+
success: false,
|
|
2771
|
+
minAvailableCount: 0
|
|
2772
|
+
};
|
|
2773
|
+
var resourcesDates = this.store.date.getDateList();
|
|
2774
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
2775
|
+
return n.date === dateRange[0].date;
|
|
2776
|
+
});
|
|
2777
|
+
if (!targetResourceDate) return {
|
|
2778
|
+
success: false,
|
|
2779
|
+
minAvailableCount: 0
|
|
2780
|
+
};
|
|
2781
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
2782
|
+
|
|
2783
|
+
// 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
|
|
2784
|
+
var resourceCodeToFormIdMap = {};
|
|
2785
|
+
|
|
2786
|
+
// 遍历购物车中的商品,收集所有资源类型配置
|
|
2787
|
+
Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
|
|
2788
|
+
var _cartItem$_productOri11;
|
|
2789
|
+
if ((_cartItem$_productOri11 = cartItem._productOrigin) !== null && _cartItem$_productOri11 !== void 0 && (_cartItem$_productOri11 = _cartItem$_productOri11.product_resource) !== null && _cartItem$_productOri11 !== void 0 && _cartItem$_productOri11.resources) {
|
|
2790
|
+
cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
|
|
2791
|
+
// 只处理启用的资源类型 (status === 1)
|
|
2792
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
2793
|
+
var _resourceConfig$id, _resourceConfig$resou;
|
|
2794
|
+
var formId = ((_resourceConfig$id = resourceConfig.id) === null || _resourceConfig$id === void 0 ? void 0 : _resourceConfig$id.toString()) || ((_resourceConfig$resou = resourceConfig.resource_type_id) === null || _resourceConfig$resou === void 0 ? void 0 : _resourceConfig$resou.toString());
|
|
2795
|
+
if (formId) {
|
|
2796
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
});
|
|
2800
|
+
}
|
|
2801
|
+
});
|
|
2802
|
+
var hasCapacityIssue = false;
|
|
2803
|
+
var resourceCapacityInfo = [];
|
|
2804
|
+
|
|
2805
|
+
// 用于跟踪已处理的商品,避免重复添加
|
|
2806
|
+
var processedCartItemIds = new Set();
|
|
2807
|
+
|
|
2808
|
+
// 先检查所有资源类型,收集可用数量信息
|
|
2809
|
+
var _loop3 = function _loop3() {
|
|
2810
|
+
var _resourceTypeConfig;
|
|
2811
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
2812
|
+
resourceCode = _Object$entries$_i[0],
|
|
2813
|
+
items = _Object$entries$_i[1];
|
|
2814
|
+
// 获取该资源类型对应的 form_id
|
|
2815
|
+
var targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
2816
|
+
if (!targetFormId) {
|
|
2817
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
|
|
2818
|
+
return {
|
|
2819
|
+
v: {
|
|
2820
|
+
success: false,
|
|
2821
|
+
minAvailableCount: 0
|
|
2822
|
+
}
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
|
|
2826
|
+
// 获取该资源类型的所有资源
|
|
2827
|
+
var resourcesOfThisType = [];
|
|
2828
|
+
items.forEach(function (cartItem) {
|
|
2829
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
2830
|
+
productResourceIds.forEach(function (resourceId) {
|
|
2831
|
+
var _resource$form_id;
|
|
2832
|
+
var resource = resourcesMap[resourceId];
|
|
2833
|
+
if (resource && ((_resource$form_id = resource.form_id) === null || _resource$form_id === void 0 ? void 0 : _resource$form_id.toString()) === targetFormId) {
|
|
2834
|
+
// 避免重复添加同一个资源
|
|
2835
|
+
if (!resourcesOfThisType.find(function (r) {
|
|
2836
|
+
return r.id === resource.id;
|
|
2837
|
+
})) {
|
|
2838
|
+
resourcesOfThisType.push(resource);
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
});
|
|
2842
|
+
});
|
|
2843
|
+
if (resourcesOfThisType.length === 0) {
|
|
2844
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
|
|
2845
|
+
return {
|
|
2846
|
+
v: {
|
|
2847
|
+
success: false,
|
|
2848
|
+
minAvailableCount: 0
|
|
2849
|
+
}
|
|
2850
|
+
};
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
// 检查资源类型(单个预约 vs 多个预约)
|
|
2854
|
+
// 从商品配置中获取资源类型信息
|
|
2855
|
+
var resourceTypeConfig = null;
|
|
2856
|
+
var _iterator3 = _createForOfIteratorHelper(items),
|
|
2857
|
+
_step3;
|
|
2858
|
+
try {
|
|
2859
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
2860
|
+
var _cartItem$_productOri12;
|
|
2861
|
+
var cartItem = _step3.value;
|
|
2862
|
+
if ((_cartItem$_productOri12 = cartItem._productOrigin) !== null && _cartItem$_productOri12 !== void 0 && (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) !== null && _cartItem$_productOri12 !== void 0 && _cartItem$_productOri12.resources) {
|
|
2863
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
2864
|
+
return r.code === resourceCode && r.status === 1;
|
|
2865
|
+
});
|
|
2866
|
+
if (resourceTypeConfig) break;
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
} catch (err) {
|
|
2870
|
+
_iterator3.e(err);
|
|
2871
|
+
} finally {
|
|
2872
|
+
_iterator3.f();
|
|
2873
|
+
}
|
|
2874
|
+
var isMultipleBooking = ((_resourceTypeConfig = resourceTypeConfig) === null || _resourceTypeConfig === void 0 ? void 0 : _resourceTypeConfig.type) === 'multiple';
|
|
2875
|
+
var totalAvailable;
|
|
2876
|
+
var requiredAmount;
|
|
2877
|
+
var availableAmount;
|
|
2878
|
+
if (isMultipleBooking) {
|
|
2879
|
+
// 多个预约:计算容量
|
|
2880
|
+
totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
|
|
2881
|
+
return sum + (resource.capacity || 0);
|
|
2882
|
+
}, 0);
|
|
2883
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
2884
|
+
var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
|
|
2885
|
+
currentCapacity = _getCapacityInfoByCar7.currentCapacity;
|
|
2886
|
+
return sum + currentCapacity;
|
|
2887
|
+
}, 0);
|
|
2888
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2889
|
+
} else {
|
|
2890
|
+
// 单个预约:计算资源个数
|
|
2891
|
+
totalAvailable = resourcesOfThisType.length;
|
|
2892
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
2893
|
+
return sum + (cartItem.num || 1);
|
|
2894
|
+
}, 0);
|
|
2895
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
// 记录资源容量信息
|
|
2899
|
+
resourceCapacityInfo.push({
|
|
2900
|
+
code: resourceCode,
|
|
2901
|
+
available: availableAmount,
|
|
2902
|
+
total: totalAvailable,
|
|
2903
|
+
required: requiredAmount,
|
|
2904
|
+
isMultiple: isMultipleBooking
|
|
2905
|
+
});
|
|
2906
|
+
availableCountsByResourceType.push(availableAmount);
|
|
2907
|
+
|
|
2908
|
+
// 检查是否有容量问题
|
|
2909
|
+
if (requiredAmount > totalAvailable) {
|
|
2910
|
+
hasCapacityIssue = true;
|
|
2911
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
// 为通过检测的商品分配一个公共可用时间段
|
|
2915
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
|
|
2916
|
+
return {
|
|
2917
|
+
id: r.id,
|
|
2918
|
+
times: r.times.map(function (t) {
|
|
2919
|
+
return "".concat(t.start_at, " - ").concat(t.end_at);
|
|
2920
|
+
})
|
|
2921
|
+
};
|
|
2922
|
+
}));
|
|
2923
|
+
|
|
2924
|
+
// 找到所有资源都可用的时间段
|
|
2925
|
+
var commonTimeSlots = _this15.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
2926
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
|
|
2927
|
+
if (commonTimeSlots.length === 0) {
|
|
2928
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
|
|
2929
|
+
return {
|
|
2930
|
+
v: {
|
|
2931
|
+
success: false,
|
|
2932
|
+
minAvailableCount: 0
|
|
2933
|
+
}
|
|
2934
|
+
};
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
// 使用第一个公共可用时间段,但只处理未处理过的商品
|
|
2938
|
+
var firstCommonSlot = commonTimeSlots[0];
|
|
2939
|
+
console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
|
|
2940
|
+
items.forEach(function (cartItem) {
|
|
2941
|
+
// 只处理未处理过的商品,避免重复添加
|
|
2942
|
+
if (!processedCartItemIds.has(cartItem._id)) {
|
|
2943
|
+
processedCartItemIds.add(cartItem._id);
|
|
2944
|
+
var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
|
|
2945
|
+
start_date: dateRange[0].date,
|
|
2946
|
+
start_time: firstCommonSlot.startTime,
|
|
2947
|
+
end_time: firstCommonSlot.endTime,
|
|
2948
|
+
end_date: dateRange[0].date
|
|
2949
|
+
});
|
|
2950
|
+
processedItemsWithoutTime.push(processedItem);
|
|
2951
|
+
}
|
|
2952
|
+
});
|
|
2953
|
+
},
|
|
2954
|
+
_ret3;
|
|
2955
|
+
for (var _i = 0, _Object$entries = Object.entries(itemsByResourceType); _i < _Object$entries.length; _i++) {
|
|
2956
|
+
_ret3 = _loop3();
|
|
2957
|
+
if (_ret3) return _ret3.v;
|
|
2958
|
+
}
|
|
2959
|
+
|
|
2960
|
+
// 如果有容量问题,找出限制最严格的资源类型,返回其总容量
|
|
2961
|
+
if (hasCapacityIssue) {
|
|
2962
|
+
// 找出超出容量的资源类型中,总容量最少的那个
|
|
2963
|
+
var overCapacityResources = resourceCapacityInfo.filter(function (info) {
|
|
2964
|
+
return info.required > info.total;
|
|
2965
|
+
});
|
|
2966
|
+
if (overCapacityResources.length > 0) {
|
|
2967
|
+
var _minTotalCapacity = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
|
|
2968
|
+
return info.total;
|
|
2969
|
+
})));
|
|
2970
|
+
return {
|
|
2971
|
+
success: false,
|
|
2972
|
+
minAvailableCount: _minTotalCapacity
|
|
2973
|
+
};
|
|
2974
|
+
}
|
|
2975
|
+
// 如果没有超出容量的(理论上不应该发生),返回总容量最少的
|
|
2976
|
+
var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
|
|
2977
|
+
return info.total;
|
|
2978
|
+
})));
|
|
2979
|
+
return {
|
|
2980
|
+
success: false,
|
|
2981
|
+
minAvailableCount: minTotalCapacity
|
|
2982
|
+
};
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
|
|
2986
|
+
// 合并所有商品(有时间的 + 处理后的没有时间的)
|
|
2987
|
+
var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
|
|
2988
|
+
|
|
2989
|
+
// 按时间段分组检查
|
|
2990
|
+
var cartItemsByTimeSlot = {};
|
|
2991
|
+
allProcessedItems.forEach(function (cartItem) {
|
|
2992
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
|
|
2993
|
+
var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
|
|
2994
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
2995
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
2996
|
+
}
|
|
2997
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
2998
|
+
});
|
|
2999
|
+
// 检查每个时间段是否有足够的资源容量
|
|
3000
|
+
var _loop4 = function _loop4() {
|
|
3001
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
3002
|
+
timeSlotKey = _Object$entries2$_i[0],
|
|
3003
|
+
itemsInTimeSlot = _Object$entries2$_i[1];
|
|
3004
|
+
var _timeSlotKey$split = timeSlotKey.split('_'),
|
|
3005
|
+
_timeSlotKey$split2 = _slicedToArray(_timeSlotKey$split, 4),
|
|
3006
|
+
startDate = _timeSlotKey$split2[0],
|
|
3007
|
+
startTime = _timeSlotKey$split2[1],
|
|
3008
|
+
endDate = _timeSlotKey$split2[2],
|
|
3009
|
+
endTime = _timeSlotKey$split2[3];
|
|
3010
|
+
var timeSlotStart = "".concat(startDate, " ").concat(startTime);
|
|
3011
|
+
var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
|
|
3012
|
+
|
|
3013
|
+
// 获取这个时间段所有商品涉及的资源
|
|
3014
|
+
var allResourcesForTimeSlot = [];
|
|
3015
|
+
var resourcesIdSet = new Set();
|
|
3016
|
+
|
|
3017
|
+
// 获取资源数据
|
|
3018
|
+
var dateRange = _this15.store.date.getDateRange();
|
|
3019
|
+
var resourcesDates = _this15.store.date.getDateList();
|
|
3020
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
3021
|
+
return n.date === startDate;
|
|
3022
|
+
});
|
|
3023
|
+
if (!targetResourceDate) return 0; // continue
|
|
3024
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
3025
|
+
itemsInTimeSlot.forEach(function (cartItem) {
|
|
3026
|
+
if (!cartItem._productOrigin) return;
|
|
3027
|
+
|
|
3028
|
+
// 获取商品的资源配置
|
|
3029
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
3030
|
+
productResourceIds.forEach(function (resourceId) {
|
|
3031
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
3032
|
+
resourcesIdSet.add(resourceId);
|
|
3033
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
3034
|
+
}
|
|
3035
|
+
});
|
|
3036
|
+
});
|
|
3037
|
+
|
|
3038
|
+
// 按资源类型分组检查容量
|
|
3039
|
+
if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
|
|
3040
|
+
// 如果有可用数量记录,返回最小值;否则返回 0
|
|
3041
|
+
var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3042
|
+
return {
|
|
3043
|
+
v: {
|
|
3044
|
+
success: false,
|
|
3045
|
+
minAvailableCount: _minAvailableCount
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
}
|
|
3049
|
+
},
|
|
3050
|
+
_ret4;
|
|
3051
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(cartItemsByTimeSlot); _i2 < _Object$entries2.length; _i2++) {
|
|
3052
|
+
_ret4 = _loop4();
|
|
3053
|
+
if (_ret4 === 0) continue;
|
|
3054
|
+
if (_ret4) return _ret4.v;
|
|
3055
|
+
}
|
|
3056
|
+
|
|
3057
|
+
// 全部通过检测,返回成功和最小可用数量
|
|
3058
|
+
var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3059
|
+
return {
|
|
3060
|
+
success: true,
|
|
3061
|
+
minAvailableCount: minAvailableCount
|
|
3062
|
+
};
|
|
3063
|
+
}
|
|
2472
3064
|
}, {
|
|
2473
3065
|
key: "setOtherData",
|
|
2474
3066
|
value: function setOtherData(key, value) {
|
|
@@ -2490,41 +3082,41 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2490
3082
|
}, {
|
|
2491
3083
|
key: "getProductTypeById",
|
|
2492
3084
|
value: function () {
|
|
2493
|
-
var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3085
|
+
var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(id) {
|
|
2494
3086
|
var productData, _productData$schedule;
|
|
2495
|
-
return _regeneratorRuntime().wrap(function
|
|
2496
|
-
while (1) switch (
|
|
3087
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
3088
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
2497
3089
|
case 0:
|
|
2498
|
-
|
|
3090
|
+
_context25.next = 2;
|
|
2499
3091
|
return this.store.products.getProduct(id);
|
|
2500
3092
|
case 2:
|
|
2501
|
-
productData =
|
|
3093
|
+
productData = _context25.sent;
|
|
2502
3094
|
if (!productData) {
|
|
2503
|
-
|
|
3095
|
+
_context25.next = 9;
|
|
2504
3096
|
break;
|
|
2505
3097
|
}
|
|
2506
3098
|
if (!productData.duration) {
|
|
2507
|
-
|
|
3099
|
+
_context25.next = 6;
|
|
2508
3100
|
break;
|
|
2509
3101
|
}
|
|
2510
|
-
return
|
|
3102
|
+
return _context25.abrupt("return", 'duration');
|
|
2511
3103
|
case 6:
|
|
2512
3104
|
if (!((_productData$schedule = productData['schedule.ids']) !== null && _productData$schedule !== void 0 && _productData$schedule.length)) {
|
|
2513
|
-
|
|
3105
|
+
_context25.next = 8;
|
|
2514
3106
|
break;
|
|
2515
3107
|
}
|
|
2516
|
-
return
|
|
3108
|
+
return _context25.abrupt("return", 'session');
|
|
2517
3109
|
case 8:
|
|
2518
|
-
return
|
|
3110
|
+
return _context25.abrupt("return", 'normal');
|
|
2519
3111
|
case 9:
|
|
2520
|
-
return
|
|
3112
|
+
return _context25.abrupt("return", 'normal');
|
|
2521
3113
|
case 10:
|
|
2522
3114
|
case "end":
|
|
2523
|
-
return
|
|
3115
|
+
return _context25.stop();
|
|
2524
3116
|
}
|
|
2525
|
-
},
|
|
3117
|
+
}, _callee25, this);
|
|
2526
3118
|
}));
|
|
2527
|
-
function getProductTypeById(
|
|
3119
|
+
function getProductTypeById(_x19) {
|
|
2528
3120
|
return _getProductTypeById.apply(this, arguments);
|
|
2529
3121
|
}
|
|
2530
3122
|
return getProductTypeById;
|
|
@@ -2540,7 +3132,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2540
3132
|
}, {
|
|
2541
3133
|
key: "getResourcesByCartItemAndCode",
|
|
2542
3134
|
value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
2543
|
-
var _cartItem$
|
|
3135
|
+
var _cartItem$_productOri13;
|
|
2544
3136
|
var dateRange = this.store.date.getDateRange();
|
|
2545
3137
|
var resources = [];
|
|
2546
3138
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
@@ -2563,16 +3155,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2563
3155
|
});
|
|
2564
3156
|
if (!cartItem) return [];
|
|
2565
3157
|
var selectedResources = [];
|
|
2566
|
-
var
|
|
2567
|
-
currentCapacity =
|
|
2568
|
-
formatCapacity =
|
|
3158
|
+
var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
|
|
3159
|
+
currentCapacity = _getCapacityInfoByCar8.currentCapacity,
|
|
3160
|
+
formatCapacity = _getCapacityInfoByCar8.formatCapacity;
|
|
2569
3161
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
2570
3162
|
if (cartItem.holder_id) {
|
|
2571
3163
|
selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
|
|
2572
3164
|
} else {
|
|
2573
3165
|
selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
|
|
2574
3166
|
}
|
|
2575
|
-
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$
|
|
3167
|
+
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 || (_cartItem$_productOri13 = _cartItem$_productOri13.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [], selectedResources, currentCapacity);
|
|
2576
3168
|
var targetResource = productResources.find(function (resource) {
|
|
2577
3169
|
return resource.code === resourceCode;
|
|
2578
3170
|
});
|
|
@@ -2595,7 +3187,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2595
3187
|
});
|
|
2596
3188
|
if (mTimes.length === 0) return false;
|
|
2597
3189
|
var canUseArr = mTimes.map(function (item) {
|
|
2598
|
-
var _cartItem$
|
|
3190
|
+
var _cartItem$_productOri14;
|
|
2599
3191
|
var res = getIsUsableByTimeItem({
|
|
2600
3192
|
timeSlice: {
|
|
2601
3193
|
start_time: startTime.format('HH:mm'),
|
|
@@ -2607,7 +3199,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2607
3199
|
resource: m,
|
|
2608
3200
|
currentCount: currentCapacity || 0,
|
|
2609
3201
|
resourcesUseableMap: resourcesUseableMap,
|
|
2610
|
-
cut_off_time: (_cartItem$
|
|
3202
|
+
cut_off_time: (_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.cut_off_time
|
|
2611
3203
|
});
|
|
2612
3204
|
if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
|
|
2613
3205
|
resourcesUseableMap[m.id] = res.usable;
|
|
@@ -2621,12 +3213,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2621
3213
|
});
|
|
2622
3214
|
} else {
|
|
2623
3215
|
targetResource.renderList = targetResource.renderList.filter(function (n) {
|
|
2624
|
-
var _cartItem$
|
|
3216
|
+
var _cartItem$_productOri15;
|
|
2625
3217
|
var recordCount = n.capacity || 0;
|
|
2626
3218
|
if (n.onlyComputed) return false;
|
|
2627
3219
|
var timeSlots = getTimeSlicesByResource({
|
|
2628
3220
|
resource: n,
|
|
2629
|
-
duration: ((_cartItem$
|
|
3221
|
+
duration: ((_cartItem$_productOri15 = cartItem._productOrigin) === null || _cartItem$_productOri15 === void 0 || (_cartItem$_productOri15 = _cartItem$_productOri15.duration) === null || _cartItem$_productOri15 === void 0 ? void 0 : _cartItem$_productOri15.value) || 10,
|
|
2630
3222
|
split: 10,
|
|
2631
3223
|
currentDate: dateRange[0].date
|
|
2632
3224
|
});
|
|
@@ -2644,10 +3236,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2644
3236
|
}, {
|
|
2645
3237
|
key: "getTimeslotsScheduleByDateRange",
|
|
2646
3238
|
value: (function () {
|
|
2647
|
-
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2648
|
-
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results,
|
|
2649
|
-
return _regeneratorRuntime().wrap(function
|
|
2650
|
-
while (1) switch (
|
|
3239
|
+
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref11) {
|
|
3240
|
+
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i3, _dates, date;
|
|
3241
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
3242
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
2651
3243
|
case 0:
|
|
2652
3244
|
startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
|
|
2653
3245
|
console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
|
|
@@ -2666,22 +3258,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2666
3258
|
}
|
|
2667
3259
|
// 如果不支持 Web Worker,使用同步方式处理
|
|
2668
3260
|
results = {};
|
|
2669
|
-
for (
|
|
2670
|
-
date = _dates[
|
|
3261
|
+
for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
|
|
3262
|
+
date = _dates[_i3];
|
|
2671
3263
|
results[date] = this.getTimeslotBySchedule({
|
|
2672
3264
|
date: date,
|
|
2673
3265
|
scheduleIds: scheduleIds,
|
|
2674
3266
|
resources: resources
|
|
2675
3267
|
});
|
|
2676
3268
|
}
|
|
2677
|
-
return
|
|
3269
|
+
return _context26.abrupt("return", results);
|
|
2678
3270
|
case 9:
|
|
2679
3271
|
case "end":
|
|
2680
|
-
return
|
|
3272
|
+
return _context26.stop();
|
|
2681
3273
|
}
|
|
2682
|
-
},
|
|
3274
|
+
}, _callee26, this);
|
|
2683
3275
|
}));
|
|
2684
|
-
function getTimeslotsScheduleByDateRange(
|
|
3276
|
+
function getTimeslotsScheduleByDateRange(_x20) {
|
|
2685
3277
|
return _getTimeslotsScheduleByDateRange.apply(this, arguments);
|
|
2686
3278
|
}
|
|
2687
3279
|
return getTimeslotsScheduleByDateRange;
|
|
@@ -2689,7 +3281,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2689
3281
|
}, {
|
|
2690
3282
|
key: "getAvailableDateForSessionOptimize",
|
|
2691
3283
|
value: function () {
|
|
2692
|
-
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3284
|
+
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
2693
3285
|
var _this$store$currentPr3, _this$store$currentPr4, _tempProducts;
|
|
2694
3286
|
var params,
|
|
2695
3287
|
startDate,
|
|
@@ -2708,12 +3300,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2708
3300
|
openResources,
|
|
2709
3301
|
allProductResources,
|
|
2710
3302
|
targetSchedules,
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
return _regeneratorRuntime().wrap(function
|
|
2714
|
-
while (1) switch (
|
|
3303
|
+
_loop5,
|
|
3304
|
+
_args28 = arguments;
|
|
3305
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context28) {
|
|
3306
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
2715
3307
|
case 0:
|
|
2716
|
-
params =
|
|
3308
|
+
params = _args28.length > 0 && _args28[0] !== undefined ? _args28[0] : {};
|
|
2717
3309
|
// 开始日期如果小于今天,直接以今天当做开始日期
|
|
2718
3310
|
startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
|
|
2719
3311
|
if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
|
|
@@ -2738,15 +3330,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2738
3330
|
// 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
|
|
2739
3331
|
cache = (_this$store$currentPr3 = this.store.currentProductMeta) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3['timeSlotBySchedule'];
|
|
2740
3332
|
if (!cache) {
|
|
2741
|
-
|
|
3333
|
+
_context28.next = 13;
|
|
2742
3334
|
break;
|
|
2743
3335
|
}
|
|
2744
3336
|
if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
|
|
2745
|
-
|
|
3337
|
+
_context28.next = 13;
|
|
2746
3338
|
break;
|
|
2747
3339
|
}
|
|
2748
3340
|
this.store.date.setDateList(cache.dateList);
|
|
2749
|
-
return
|
|
3341
|
+
return _context28.abrupt("return", {
|
|
2750
3342
|
dateList: cache.dateList,
|
|
2751
3343
|
firstAvailableDate: cache.firstAvailableDate
|
|
2752
3344
|
});
|
|
@@ -2756,7 +3348,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2756
3348
|
schedule = (_this$store$currentPr4 = this.store.currentProductMeta) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4['schedule'];
|
|
2757
3349
|
filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
|
|
2758
3350
|
tempResourceIds = getResourcesIdsByProduct(tempProducts);
|
|
2759
|
-
|
|
3351
|
+
_context28.next = 19;
|
|
2760
3352
|
return this.store.date.fetchResourceDates({
|
|
2761
3353
|
query: {
|
|
2762
3354
|
start_date: startDate || '',
|
|
@@ -2765,7 +3357,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2765
3357
|
}
|
|
2766
3358
|
});
|
|
2767
3359
|
case 19:
|
|
2768
|
-
res =
|
|
3360
|
+
res = _context28.sent;
|
|
2769
3361
|
// 2. 商品 schedule 数据,确定日程在每一天的时间片
|
|
2770
3362
|
// 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
|
|
2771
3363
|
dates = [];
|
|
@@ -2785,10 +3377,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2785
3377
|
}
|
|
2786
3378
|
});
|
|
2787
3379
|
targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
|
|
2788
|
-
|
|
3380
|
+
_loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
|
|
2789
3381
|
var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
|
|
2790
|
-
return _regeneratorRuntime().wrap(function
|
|
2791
|
-
while (1) switch (
|
|
3382
|
+
return _regeneratorRuntime().wrap(function _loop5$(_context27) {
|
|
3383
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
2792
3384
|
case 0:
|
|
2793
3385
|
currentDateStr = currentDate.format('YYYY-MM-DD');
|
|
2794
3386
|
status = 'available'; // 1. 检查商品的提前量等情况是否满足
|
|
@@ -2880,32 +3472,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2880
3472
|
|
|
2881
3473
|
// 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
|
|
2882
3474
|
if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
|
|
2883
|
-
|
|
3475
|
+
_context27.next = 9;
|
|
2884
3476
|
break;
|
|
2885
3477
|
}
|
|
2886
|
-
return
|
|
3478
|
+
return _context27.abrupt("return", 1);
|
|
2887
3479
|
case 9:
|
|
2888
3480
|
currentDate = dayjs(currentDate).add(1, 'day');
|
|
2889
3481
|
case 10:
|
|
2890
3482
|
case "end":
|
|
2891
|
-
return
|
|
3483
|
+
return _context27.stop();
|
|
2892
3484
|
}
|
|
2893
|
-
},
|
|
3485
|
+
}, _loop5);
|
|
2894
3486
|
});
|
|
2895
3487
|
case 28:
|
|
2896
3488
|
if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
|
|
2897
|
-
|
|
3489
|
+
_context28.next = 34;
|
|
2898
3490
|
break;
|
|
2899
3491
|
}
|
|
2900
|
-
return
|
|
3492
|
+
return _context28.delegateYield(_loop5(), "t0", 30);
|
|
2901
3493
|
case 30:
|
|
2902
|
-
if (!
|
|
2903
|
-
|
|
3494
|
+
if (!_context28.t0) {
|
|
3495
|
+
_context28.next = 32;
|
|
2904
3496
|
break;
|
|
2905
3497
|
}
|
|
2906
|
-
return
|
|
3498
|
+
return _context28.abrupt("break", 34);
|
|
2907
3499
|
case 32:
|
|
2908
|
-
|
|
3500
|
+
_context28.next = 28;
|
|
2909
3501
|
break;
|
|
2910
3502
|
case 34:
|
|
2911
3503
|
// 最终把资源数据也加到日期内
|
|
@@ -2920,15 +3512,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2920
3512
|
startDate: startDate,
|
|
2921
3513
|
endDate: dayjs(currentDate).format('YYYY-MM-DD')
|
|
2922
3514
|
};
|
|
2923
|
-
return
|
|
3515
|
+
return _context28.abrupt("return", {
|
|
2924
3516
|
dateList: dates,
|
|
2925
3517
|
firstAvailableDate: firstAvailableDate
|
|
2926
3518
|
});
|
|
2927
3519
|
case 39:
|
|
2928
3520
|
case "end":
|
|
2929
|
-
return
|
|
3521
|
+
return _context28.stop();
|
|
2930
3522
|
}
|
|
2931
|
-
},
|
|
3523
|
+
}, _callee27, this);
|
|
2932
3524
|
}));
|
|
2933
3525
|
function getAvailableDateForSessionOptimize() {
|
|
2934
3526
|
return _getAvailableDateForSessionOptimize.apply(this, arguments);
|