@pisell/pisellos 0.0.271 → 0.0.273
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/Order/index.js +5 -8
- package/dist/modules/Rules/index.js +2 -0
- package/dist/solution/BookingByStep/index.d.ts +9 -4
- package/dist/solution/BookingByStep/index.js +362 -106
- package/dist/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/dist/solution/BookingByStep/utils/capacity.js +189 -1
- package/dist/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/dist/solution/BookingByStep/utils/stock.js +126 -0
- package/lib/modules/Order/index.js +4 -3
- package/lib/modules/Rules/index.js +2 -0
- package/lib/solution/BookingByStep/index.d.ts +9 -4
- package/lib/solution/BookingByStep/index.js +185 -8
- package/lib/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/lib/solution/BookingByStep/utils/capacity.js +136 -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 } 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
|
/**
|
|
@@ -2253,12 +2264,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2253
2264
|
});
|
|
2254
2265
|
});
|
|
2255
2266
|
}
|
|
2256
|
-
}, {
|
|
2257
|
-
key: "clearCache",
|
|
2258
|
-
value: function clearCache() {}
|
|
2259
|
-
}, {
|
|
2260
|
-
key: "clearCacheByModule",
|
|
2261
|
-
value: function clearCacheByModule(module) {}
|
|
2262
2267
|
}, {
|
|
2263
2268
|
key: "getScheduleDataByIds",
|
|
2264
2269
|
value: function getScheduleDataByIds(scheduleIds) {
|
|
@@ -2289,42 +2294,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2289
2294
|
}, {
|
|
2290
2295
|
key: "openProductDetail",
|
|
2291
2296
|
value: function () {
|
|
2292
|
-
var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2297
|
+
var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(productId) {
|
|
2293
2298
|
var targetProductData, newScheduleArr, dateRange;
|
|
2294
|
-
return _regeneratorRuntime().wrap(function
|
|
2295
|
-
while (1) switch (
|
|
2299
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2300
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
2296
2301
|
case 0:
|
|
2297
|
-
|
|
2302
|
+
_context24.next = 2;
|
|
2298
2303
|
return this.store.products.getProduct(productId);
|
|
2299
2304
|
case 2:
|
|
2300
|
-
targetProductData =
|
|
2305
|
+
targetProductData = _context24.sent;
|
|
2301
2306
|
if (!targetProductData) {
|
|
2302
|
-
|
|
2307
|
+
_context24.next = 17;
|
|
2303
2308
|
break;
|
|
2304
2309
|
}
|
|
2305
2310
|
this.store.currentProduct = targetProductData;
|
|
2306
2311
|
this.store.currentProductMeta = {};
|
|
2307
2312
|
// 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
|
|
2308
2313
|
if (!targetProductData['schedule.ids']) {
|
|
2309
|
-
|
|
2314
|
+
_context24.next = 12;
|
|
2310
2315
|
break;
|
|
2311
2316
|
}
|
|
2312
2317
|
newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
|
|
2313
2318
|
if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
|
|
2314
2319
|
this.store.currentProductMeta.schedule = newScheduleArr;
|
|
2315
|
-
|
|
2320
|
+
_context24.next = 17;
|
|
2316
2321
|
break;
|
|
2317
2322
|
case 12:
|
|
2318
2323
|
if (!targetProductData.duration) {
|
|
2319
|
-
|
|
2324
|
+
_context24.next = 17;
|
|
2320
2325
|
break;
|
|
2321
2326
|
}
|
|
2322
2327
|
dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
|
|
2323
2328
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
2324
|
-
|
|
2329
|
+
_context24.next = 16;
|
|
2325
2330
|
break;
|
|
2326
2331
|
}
|
|
2327
|
-
return
|
|
2332
|
+
return _context24.abrupt("return");
|
|
2328
2333
|
case 16:
|
|
2329
2334
|
// this.store.date.getResourceDates({
|
|
2330
2335
|
// query: {
|
|
@@ -2340,11 +2345,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2340
2345
|
});
|
|
2341
2346
|
case 17:
|
|
2342
2347
|
case "end":
|
|
2343
|
-
return
|
|
2348
|
+
return _context24.stop();
|
|
2344
2349
|
}
|
|
2345
|
-
},
|
|
2350
|
+
}, _callee24, this);
|
|
2346
2351
|
}));
|
|
2347
|
-
function openProductDetail(
|
|
2352
|
+
function openProductDetail(_x18) {
|
|
2348
2353
|
return _openProductDetail.apply(this, arguments);
|
|
2349
2354
|
}
|
|
2350
2355
|
return openProductDetail;
|
|
@@ -2357,10 +2362,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2357
2362
|
}
|
|
2358
2363
|
this.store.currentProduct = undefined;
|
|
2359
2364
|
}
|
|
2365
|
+
|
|
2366
|
+
// 通过商品和 schedule 来获取视频可用的时间片、时间片内资源可用的数据
|
|
2360
2367
|
}, {
|
|
2361
2368
|
key: "getTimeslotBySchedule",
|
|
2362
2369
|
value: function getTimeslotBySchedule(_ref10) {
|
|
2363
|
-
var _this$store$currentPr2,
|
|
2370
|
+
var _this$store$currentPr2,
|
|
2371
|
+
_targetProductData$pr,
|
|
2372
|
+
_this14 = this;
|
|
2364
2373
|
var date = _ref10.date,
|
|
2365
2374
|
scheduleIds = _ref10.scheduleIds,
|
|
2366
2375
|
resources = _ref10.resources,
|
|
@@ -2467,6 +2476,91 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2467
2476
|
}
|
|
2468
2477
|
}
|
|
2469
2478
|
});
|
|
2479
|
+
// 容量检测
|
|
2480
|
+
var cartItems = _this14.store.cart.getItems();
|
|
2481
|
+
productResources.forEach(function (n) {
|
|
2482
|
+
// 单个预约检测规则:
|
|
2483
|
+
// 1、跟我一样的商品同一时间在购物车里不可以超过我最少的那种资源的关联的资源个数
|
|
2484
|
+
// 2、跟我不一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,她配置了几个资源的个数+我配置了几个资源的个数,然后购物车里有几个这样的商品,对应的资源做一个去重,不超过这个去重以后的总数
|
|
2485
|
+
if (n.type === 'single') {
|
|
2486
|
+
var currentResourcesSet = new Set([].concat(_toConsumableArray(n.optional_resource), _toConsumableArray(n.default_resource)));
|
|
2487
|
+
// 规则 1
|
|
2488
|
+
var sameCartItems = cartItems.filter(function (m) {
|
|
2489
|
+
var _m$_productOrigin, _targetProductData$id;
|
|
2490
|
+
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;
|
|
2491
|
+
});
|
|
2492
|
+
if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size) {
|
|
2493
|
+
bookingLeft = 0;
|
|
2494
|
+
}
|
|
2495
|
+
// 规则 2
|
|
2496
|
+
var otherCartItems = cartItems.filter(function (m) {
|
|
2497
|
+
var _m$_productOrigin2, _targetProductData$id2;
|
|
2498
|
+
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;
|
|
2499
|
+
});
|
|
2500
|
+
otherCartItems.forEach(function (m) {
|
|
2501
|
+
var _m$_productOrigin3;
|
|
2502
|
+
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) {
|
|
2503
|
+
return m.type === n.type;
|
|
2504
|
+
});
|
|
2505
|
+
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) || [])));
|
|
2506
|
+
// 把sameTypeResourcesSet 加到currentResourcesSet
|
|
2507
|
+
sameTypeResourcesSet.forEach(function (resource) {
|
|
2508
|
+
return currentResourcesSet.add(resource);
|
|
2509
|
+
});
|
|
2510
|
+
});
|
|
2511
|
+
if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
|
|
2512
|
+
bookingLeft = 0;
|
|
2513
|
+
}
|
|
2514
|
+
} else {
|
|
2515
|
+
// 多个预约的检测规则:
|
|
2516
|
+
// 规则1、跟我一样的商品同一时间在购物车需要的容量总数不可以超过我配置的资源的 capacity 之和
|
|
2517
|
+
var _sameCartItems = cartItems.filter(function (m) {
|
|
2518
|
+
var _m$_productOrigin4, _targetProductData$id3;
|
|
2519
|
+
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;
|
|
2520
|
+
});
|
|
2521
|
+
var sameCartNeedCapacity = _sameCartItems.reduce(function (acc, curr) {
|
|
2522
|
+
return acc + getCapacityInfoByCartItem(curr).currentCapacity;
|
|
2523
|
+
}, 0);
|
|
2524
|
+
var currentProductResourcesCapacity = n.renderList.reduce(function (acc, curr) {
|
|
2525
|
+
return !curr.onlyComputed ? acc + curr.capacity || 0 : acc;
|
|
2526
|
+
}, 0);
|
|
2527
|
+
if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
|
|
2528
|
+
bookingLeft = 0;
|
|
2529
|
+
}
|
|
2530
|
+
// 规则2、不管是不是跟我一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,把所有购物车的 capacity 之和 和 所有当前类型资源的 capacity 之和比较,如果超过了resourcesCapacity,则不可用
|
|
2531
|
+
// const otherCartItems = cartItems.filter((m) => m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && m.start_time === item.start && m.end_time === item.end);
|
|
2532
|
+
var otherSameTimesCartItems = cartItems.filter(function (m) {
|
|
2533
|
+
return "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
|
|
2534
|
+
});
|
|
2535
|
+
var otherCartNeedCapacity = otherSameTimesCartItems.reduce(function (acc, curr) {
|
|
2536
|
+
return acc + getCapacityInfoByCartItem(curr).currentCapacity;
|
|
2537
|
+
}, 0);
|
|
2538
|
+
var allRenderList = _toConsumableArray(n.renderList.filter(function (m) {
|
|
2539
|
+
return !m.onlyComputed;
|
|
2540
|
+
}));
|
|
2541
|
+
otherSameTimesCartItems.forEach(function (m) {
|
|
2542
|
+
var _m$_productOrigin5;
|
|
2543
|
+
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);
|
|
2544
|
+
productResources.forEach(function (m) {
|
|
2545
|
+
if (m.id === n.id) {
|
|
2546
|
+
m.renderList.forEach(function (n) {
|
|
2547
|
+
if (!n.onlyComputed && !allRenderList.find(function (m) {
|
|
2548
|
+
return m.id === n.id;
|
|
2549
|
+
})) {
|
|
2550
|
+
allRenderList.push(n);
|
|
2551
|
+
}
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
});
|
|
2555
|
+
});
|
|
2556
|
+
var currentTypeResourcesCapacity = allRenderList.reduce(function (acc, curr) {
|
|
2557
|
+
return acc + curr.capacity || 0;
|
|
2558
|
+
}, 0);
|
|
2559
|
+
if (sameCartNeedCapacity + otherCartNeedCapacity >= currentTypeResourcesCapacity) {
|
|
2560
|
+
bookingLeft = 0;
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
});
|
|
2470
2564
|
var startDayJs = dayjs(item.start);
|
|
2471
2565
|
var endDayJs = dayjs(item.end);
|
|
2472
2566
|
return {
|
|
@@ -2480,6 +2574,168 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2480
2574
|
});
|
|
2481
2575
|
return formatScheduleTimeSlots;
|
|
2482
2576
|
}
|
|
2577
|
+
|
|
2578
|
+
// 提供给 UI的方法,当前步骤是选择商品,下一步不管是什么都需要在这里做一次检测
|
|
2579
|
+
// 时长类商品关联的资源为多个预约时,在点击进入"选择资源"步骤之前,需要检测当前所有资源的总容量
|
|
2580
|
+
// 选择商品数量大于所有资源配置的总容量时,不能进入下一步,需要在"选择商品"这一步时提示。
|
|
2581
|
+
// 注意 资源分为多个种类,需要每个种类单独检测,不能一股脑把所有资源的容量加起来检测
|
|
2582
|
+
}, {
|
|
2583
|
+
key: "checkMaxDurationCapacity",
|
|
2584
|
+
value: function checkMaxDurationCapacity() {
|
|
2585
|
+
var _this15 = this;
|
|
2586
|
+
var cartItems = cloneDeep(this.store.cart.getItems());
|
|
2587
|
+
if (cartItems.length === 0) return true;
|
|
2588
|
+
|
|
2589
|
+
// 将购物车商品分为有时间的和没有时间的
|
|
2590
|
+
var itemsWithTime = [];
|
|
2591
|
+
var itemsWithoutTime = [];
|
|
2592
|
+
cartItems.forEach(function (cartItem) {
|
|
2593
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
2594
|
+
itemsWithTime.push(cartItem);
|
|
2595
|
+
} else {
|
|
2596
|
+
itemsWithoutTime.push(cartItem);
|
|
2597
|
+
}
|
|
2598
|
+
});
|
|
2599
|
+
|
|
2600
|
+
// 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
|
|
2601
|
+
var processedItemsWithoutTime = [];
|
|
2602
|
+
if (itemsWithoutTime.length > 0) {
|
|
2603
|
+
// 按资源类型分组处理没有时间的商品
|
|
2604
|
+
var itemsByResourceType = {};
|
|
2605
|
+
itemsWithoutTime.forEach(function (cartItem) {
|
|
2606
|
+
var _cartItem$_productOri10;
|
|
2607
|
+
if (!cartItem._productOrigin) return;
|
|
2608
|
+
var resourceTypes = ((_cartItem$_productOri10 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.resources) || [];
|
|
2609
|
+
resourceTypes.forEach(function (resourceType) {
|
|
2610
|
+
if (resourceType.status === 1) {
|
|
2611
|
+
var _resourceType$id;
|
|
2612
|
+
var resourceCode = resourceType.code || ((_resourceType$id = resourceType.id) === null || _resourceType$id === void 0 ? void 0 : _resourceType$id.toString());
|
|
2613
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
2614
|
+
itemsByResourceType[resourceCode] = [];
|
|
2615
|
+
}
|
|
2616
|
+
// 避免重复添加同一个商品
|
|
2617
|
+
if (!itemsByResourceType[resourceCode].find(function (item) {
|
|
2618
|
+
return item._id === cartItem._id;
|
|
2619
|
+
})) {
|
|
2620
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
});
|
|
2624
|
+
});
|
|
2625
|
+
|
|
2626
|
+
// 为每种资源类型获取公共可用时间
|
|
2627
|
+
var _loop2 = function _loop2() {
|
|
2628
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
2629
|
+
resourceCode = _Object$entries$_i[0],
|
|
2630
|
+
items = _Object$entries$_i[1];
|
|
2631
|
+
try {
|
|
2632
|
+
var commonTimeSlots = _this15.getTimeSlotByAllResources(resourceCode);
|
|
2633
|
+
if (commonTimeSlots && commonTimeSlots.length > 0) {
|
|
2634
|
+
// 使用第一个可用时间片
|
|
2635
|
+
var firstTimeSlot = commonTimeSlots[0];
|
|
2636
|
+
var startDate = dayjs(firstTimeSlot.start_at).format('YYYY-MM-DD');
|
|
2637
|
+
var startTime = firstTimeSlot.start_time;
|
|
2638
|
+
var endTime = firstTimeSlot.end_time;
|
|
2639
|
+
|
|
2640
|
+
// 为这些商品设置时间信息(创建副本,不修改原始数据)
|
|
2641
|
+
items.forEach(function (cartItem) {
|
|
2642
|
+
var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
|
|
2643
|
+
start_date: startDate,
|
|
2644
|
+
start_time: startTime,
|
|
2645
|
+
end_time: endTime,
|
|
2646
|
+
end_date: startDate
|
|
2647
|
+
});
|
|
2648
|
+
processedItemsWithoutTime.push(processedItem);
|
|
2649
|
+
});
|
|
2650
|
+
} else {
|
|
2651
|
+
// 如果没有公共可用时间,说明容量不足
|
|
2652
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4"));
|
|
2653
|
+
return {
|
|
2654
|
+
v: false
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
} catch (error) {
|
|
2658
|
+
console.warn("\u83B7\u53D6\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u53EF\u7528\u65F6\u95F4\u5931\u8D25:"), error);
|
|
2659
|
+
// 如果获取公共时间失败,继续处理其他资源类型
|
|
2660
|
+
return 0; // continue
|
|
2661
|
+
}
|
|
2662
|
+
},
|
|
2663
|
+
_ret2;
|
|
2664
|
+
for (var _i = 0, _Object$entries = Object.entries(itemsByResourceType); _i < _Object$entries.length; _i++) {
|
|
2665
|
+
_ret2 = _loop2();
|
|
2666
|
+
if (_ret2 === 0) continue;
|
|
2667
|
+
if (_ret2) return _ret2.v;
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
// 合并所有商品(有时间的 + 处理后的没有时间的)
|
|
2672
|
+
var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
|
|
2673
|
+
|
|
2674
|
+
// 按时间段分组检查
|
|
2675
|
+
var cartItemsByTimeSlot = {};
|
|
2676
|
+
allProcessedItems.forEach(function (cartItem) {
|
|
2677
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
|
|
2678
|
+
var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
|
|
2679
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
2680
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
2681
|
+
}
|
|
2682
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
2683
|
+
});
|
|
2684
|
+
|
|
2685
|
+
// 检查每个时间段是否有足够的资源容量
|
|
2686
|
+
var _loop3 = function _loop3() {
|
|
2687
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
2688
|
+
timeSlotKey = _Object$entries2$_i[0],
|
|
2689
|
+
itemsInTimeSlot = _Object$entries2$_i[1];
|
|
2690
|
+
var _timeSlotKey$split = timeSlotKey.split('_'),
|
|
2691
|
+
_timeSlotKey$split2 = _slicedToArray(_timeSlotKey$split, 4),
|
|
2692
|
+
startDate = _timeSlotKey$split2[0],
|
|
2693
|
+
startTime = _timeSlotKey$split2[1],
|
|
2694
|
+
endDate = _timeSlotKey$split2[2],
|
|
2695
|
+
endTime = _timeSlotKey$split2[3];
|
|
2696
|
+
var timeSlotStart = "".concat(startDate, " ").concat(startTime);
|
|
2697
|
+
var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
|
|
2698
|
+
|
|
2699
|
+
// 获取这个时间段所有商品涉及的资源
|
|
2700
|
+
var allResourcesForTimeSlot = [];
|
|
2701
|
+
var resourcesIdSet = new Set();
|
|
2702
|
+
|
|
2703
|
+
// 获取资源数据
|
|
2704
|
+
var dateRange = _this15.store.date.getDateRange();
|
|
2705
|
+
var resourcesDates = _this15.store.date.getDateList();
|
|
2706
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
2707
|
+
return n.date === startDate;
|
|
2708
|
+
});
|
|
2709
|
+
if (!targetResourceDate) return 0; // continue
|
|
2710
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
2711
|
+
itemsInTimeSlot.forEach(function (cartItem) {
|
|
2712
|
+
if (!cartItem._productOrigin) return;
|
|
2713
|
+
|
|
2714
|
+
// 获取商品的资源配置
|
|
2715
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
2716
|
+
productResourceIds.forEach(function (resourceId) {
|
|
2717
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
2718
|
+
resourcesIdSet.add(resourceId);
|
|
2719
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
2720
|
+
}
|
|
2721
|
+
});
|
|
2722
|
+
});
|
|
2723
|
+
|
|
2724
|
+
// 按资源类型分组检查容量
|
|
2725
|
+
if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
|
|
2726
|
+
return {
|
|
2727
|
+
v: false
|
|
2728
|
+
};
|
|
2729
|
+
}
|
|
2730
|
+
},
|
|
2731
|
+
_ret3;
|
|
2732
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(cartItemsByTimeSlot); _i2 < _Object$entries2.length; _i2++) {
|
|
2733
|
+
_ret3 = _loop3();
|
|
2734
|
+
if (_ret3 === 0) continue;
|
|
2735
|
+
if (_ret3) return _ret3.v;
|
|
2736
|
+
}
|
|
2737
|
+
return true;
|
|
2738
|
+
}
|
|
2483
2739
|
}, {
|
|
2484
2740
|
key: "setOtherData",
|
|
2485
2741
|
value: function setOtherData(key, value) {
|
|
@@ -2501,41 +2757,41 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2501
2757
|
}, {
|
|
2502
2758
|
key: "getProductTypeById",
|
|
2503
2759
|
value: function () {
|
|
2504
|
-
var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2760
|
+
var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(id) {
|
|
2505
2761
|
var productData, _productData$schedule;
|
|
2506
|
-
return _regeneratorRuntime().wrap(function
|
|
2507
|
-
while (1) switch (
|
|
2762
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
2763
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
2508
2764
|
case 0:
|
|
2509
|
-
|
|
2765
|
+
_context25.next = 2;
|
|
2510
2766
|
return this.store.products.getProduct(id);
|
|
2511
2767
|
case 2:
|
|
2512
|
-
productData =
|
|
2768
|
+
productData = _context25.sent;
|
|
2513
2769
|
if (!productData) {
|
|
2514
|
-
|
|
2770
|
+
_context25.next = 9;
|
|
2515
2771
|
break;
|
|
2516
2772
|
}
|
|
2517
2773
|
if (!productData.duration) {
|
|
2518
|
-
|
|
2774
|
+
_context25.next = 6;
|
|
2519
2775
|
break;
|
|
2520
2776
|
}
|
|
2521
|
-
return
|
|
2777
|
+
return _context25.abrupt("return", 'duration');
|
|
2522
2778
|
case 6:
|
|
2523
2779
|
if (!((_productData$schedule = productData['schedule.ids']) !== null && _productData$schedule !== void 0 && _productData$schedule.length)) {
|
|
2524
|
-
|
|
2780
|
+
_context25.next = 8;
|
|
2525
2781
|
break;
|
|
2526
2782
|
}
|
|
2527
|
-
return
|
|
2783
|
+
return _context25.abrupt("return", 'session');
|
|
2528
2784
|
case 8:
|
|
2529
|
-
return
|
|
2785
|
+
return _context25.abrupt("return", 'normal');
|
|
2530
2786
|
case 9:
|
|
2531
|
-
return
|
|
2787
|
+
return _context25.abrupt("return", 'normal');
|
|
2532
2788
|
case 10:
|
|
2533
2789
|
case "end":
|
|
2534
|
-
return
|
|
2790
|
+
return _context25.stop();
|
|
2535
2791
|
}
|
|
2536
|
-
},
|
|
2792
|
+
}, _callee25, this);
|
|
2537
2793
|
}));
|
|
2538
|
-
function getProductTypeById(
|
|
2794
|
+
function getProductTypeById(_x19) {
|
|
2539
2795
|
return _getProductTypeById.apply(this, arguments);
|
|
2540
2796
|
}
|
|
2541
2797
|
return getProductTypeById;
|
|
@@ -2551,7 +2807,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2551
2807
|
}, {
|
|
2552
2808
|
key: "getResourcesByCartItemAndCode",
|
|
2553
2809
|
value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
2554
|
-
var _cartItem$
|
|
2810
|
+
var _cartItem$_productOri11;
|
|
2555
2811
|
var dateRange = this.store.date.getDateRange();
|
|
2556
2812
|
var resources = [];
|
|
2557
2813
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
@@ -2583,7 +2839,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2583
2839
|
} else {
|
|
2584
2840
|
selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
|
|
2585
2841
|
}
|
|
2586
|
-
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$
|
|
2842
|
+
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri11 = cartItem._productOrigin) === null || _cartItem$_productOri11 === void 0 || (_cartItem$_productOri11 = _cartItem$_productOri11.product_resource) === null || _cartItem$_productOri11 === void 0 ? void 0 : _cartItem$_productOri11.resources) || [], selectedResources, currentCapacity);
|
|
2587
2843
|
var targetResource = productResources.find(function (resource) {
|
|
2588
2844
|
return resource.code === resourceCode;
|
|
2589
2845
|
});
|
|
@@ -2606,7 +2862,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2606
2862
|
});
|
|
2607
2863
|
if (mTimes.length === 0) return false;
|
|
2608
2864
|
var canUseArr = mTimes.map(function (item) {
|
|
2609
|
-
var _cartItem$
|
|
2865
|
+
var _cartItem$_productOri12;
|
|
2610
2866
|
var res = getIsUsableByTimeItem({
|
|
2611
2867
|
timeSlice: {
|
|
2612
2868
|
start_time: startTime.format('HH:mm'),
|
|
@@ -2618,7 +2874,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2618
2874
|
resource: m,
|
|
2619
2875
|
currentCount: currentCapacity || 0,
|
|
2620
2876
|
resourcesUseableMap: resourcesUseableMap,
|
|
2621
|
-
cut_off_time: (_cartItem$
|
|
2877
|
+
cut_off_time: (_cartItem$_productOri12 = cartItem._productOrigin) === null || _cartItem$_productOri12 === void 0 ? void 0 : _cartItem$_productOri12.cut_off_time
|
|
2622
2878
|
});
|
|
2623
2879
|
if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
|
|
2624
2880
|
resourcesUseableMap[m.id] = res.usable;
|
|
@@ -2632,12 +2888,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2632
2888
|
});
|
|
2633
2889
|
} else {
|
|
2634
2890
|
targetResource.renderList = targetResource.renderList.filter(function (n) {
|
|
2635
|
-
var _cartItem$
|
|
2891
|
+
var _cartItem$_productOri13;
|
|
2636
2892
|
var recordCount = n.capacity || 0;
|
|
2637
2893
|
if (n.onlyComputed) return false;
|
|
2638
2894
|
var timeSlots = getTimeSlicesByResource({
|
|
2639
2895
|
resource: n,
|
|
2640
|
-
duration: ((_cartItem$
|
|
2896
|
+
duration: ((_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 || (_cartItem$_productOri13 = _cartItem$_productOri13.duration) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.value) || 10,
|
|
2641
2897
|
split: 10,
|
|
2642
2898
|
currentDate: dateRange[0].date
|
|
2643
2899
|
});
|
|
@@ -2655,10 +2911,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2655
2911
|
}, {
|
|
2656
2912
|
key: "getTimeslotsScheduleByDateRange",
|
|
2657
2913
|
value: (function () {
|
|
2658
|
-
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2659
|
-
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results,
|
|
2660
|
-
return _regeneratorRuntime().wrap(function
|
|
2661
|
-
while (1) switch (
|
|
2914
|
+
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref11) {
|
|
2915
|
+
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i3, _dates, date;
|
|
2916
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2917
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
2662
2918
|
case 0:
|
|
2663
2919
|
startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
|
|
2664
2920
|
console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
|
|
@@ -2677,22 +2933,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2677
2933
|
}
|
|
2678
2934
|
// 如果不支持 Web Worker,使用同步方式处理
|
|
2679
2935
|
results = {};
|
|
2680
|
-
for (
|
|
2681
|
-
date = _dates[
|
|
2936
|
+
for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
|
|
2937
|
+
date = _dates[_i3];
|
|
2682
2938
|
results[date] = this.getTimeslotBySchedule({
|
|
2683
2939
|
date: date,
|
|
2684
2940
|
scheduleIds: scheduleIds,
|
|
2685
2941
|
resources: resources
|
|
2686
2942
|
});
|
|
2687
2943
|
}
|
|
2688
|
-
return
|
|
2944
|
+
return _context26.abrupt("return", results);
|
|
2689
2945
|
case 9:
|
|
2690
2946
|
case "end":
|
|
2691
|
-
return
|
|
2947
|
+
return _context26.stop();
|
|
2692
2948
|
}
|
|
2693
|
-
},
|
|
2949
|
+
}, _callee26, this);
|
|
2694
2950
|
}));
|
|
2695
|
-
function getTimeslotsScheduleByDateRange(
|
|
2951
|
+
function getTimeslotsScheduleByDateRange(_x20) {
|
|
2696
2952
|
return _getTimeslotsScheduleByDateRange.apply(this, arguments);
|
|
2697
2953
|
}
|
|
2698
2954
|
return getTimeslotsScheduleByDateRange;
|
|
@@ -2700,7 +2956,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2700
2956
|
}, {
|
|
2701
2957
|
key: "getAvailableDateForSessionOptimize",
|
|
2702
2958
|
value: function () {
|
|
2703
|
-
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2959
|
+
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
2704
2960
|
var _this$store$currentPr3, _this$store$currentPr4, _tempProducts;
|
|
2705
2961
|
var params,
|
|
2706
2962
|
startDate,
|
|
@@ -2719,12 +2975,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2719
2975
|
openResources,
|
|
2720
2976
|
allProductResources,
|
|
2721
2977
|
targetSchedules,
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
return _regeneratorRuntime().wrap(function
|
|
2725
|
-
while (1) switch (
|
|
2978
|
+
_loop4,
|
|
2979
|
+
_args28 = arguments;
|
|
2980
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context28) {
|
|
2981
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
2726
2982
|
case 0:
|
|
2727
|
-
params =
|
|
2983
|
+
params = _args28.length > 0 && _args28[0] !== undefined ? _args28[0] : {};
|
|
2728
2984
|
// 开始日期如果小于今天,直接以今天当做开始日期
|
|
2729
2985
|
startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
|
|
2730
2986
|
if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
|
|
@@ -2749,15 +3005,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2749
3005
|
// 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
|
|
2750
3006
|
cache = (_this$store$currentPr3 = this.store.currentProductMeta) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3['timeSlotBySchedule'];
|
|
2751
3007
|
if (!cache) {
|
|
2752
|
-
|
|
3008
|
+
_context28.next = 13;
|
|
2753
3009
|
break;
|
|
2754
3010
|
}
|
|
2755
3011
|
if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
|
|
2756
|
-
|
|
3012
|
+
_context28.next = 13;
|
|
2757
3013
|
break;
|
|
2758
3014
|
}
|
|
2759
3015
|
this.store.date.setDateList(cache.dateList);
|
|
2760
|
-
return
|
|
3016
|
+
return _context28.abrupt("return", {
|
|
2761
3017
|
dateList: cache.dateList,
|
|
2762
3018
|
firstAvailableDate: cache.firstAvailableDate
|
|
2763
3019
|
});
|
|
@@ -2767,7 +3023,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2767
3023
|
schedule = (_this$store$currentPr4 = this.store.currentProductMeta) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4['schedule'];
|
|
2768
3024
|
filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
|
|
2769
3025
|
tempResourceIds = getResourcesIdsByProduct(tempProducts);
|
|
2770
|
-
|
|
3026
|
+
_context28.next = 19;
|
|
2771
3027
|
return this.store.date.fetchResourceDates({
|
|
2772
3028
|
query: {
|
|
2773
3029
|
start_date: startDate || '',
|
|
@@ -2776,7 +3032,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2776
3032
|
}
|
|
2777
3033
|
});
|
|
2778
3034
|
case 19:
|
|
2779
|
-
res =
|
|
3035
|
+
res = _context28.sent;
|
|
2780
3036
|
// 2. 商品 schedule 数据,确定日程在每一天的时间片
|
|
2781
3037
|
// 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
|
|
2782
3038
|
dates = [];
|
|
@@ -2796,10 +3052,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2796
3052
|
}
|
|
2797
3053
|
});
|
|
2798
3054
|
targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
|
|
2799
|
-
|
|
3055
|
+
_loop4 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop4() {
|
|
2800
3056
|
var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
|
|
2801
|
-
return _regeneratorRuntime().wrap(function
|
|
2802
|
-
while (1) switch (
|
|
3057
|
+
return _regeneratorRuntime().wrap(function _loop4$(_context27) {
|
|
3058
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
2803
3059
|
case 0:
|
|
2804
3060
|
currentDateStr = currentDate.format('YYYY-MM-DD');
|
|
2805
3061
|
status = 'available'; // 1. 检查商品的提前量等情况是否满足
|
|
@@ -2891,32 +3147,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2891
3147
|
|
|
2892
3148
|
// 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
|
|
2893
3149
|
if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
|
|
2894
|
-
|
|
3150
|
+
_context27.next = 9;
|
|
2895
3151
|
break;
|
|
2896
3152
|
}
|
|
2897
|
-
return
|
|
3153
|
+
return _context27.abrupt("return", 1);
|
|
2898
3154
|
case 9:
|
|
2899
3155
|
currentDate = dayjs(currentDate).add(1, 'day');
|
|
2900
3156
|
case 10:
|
|
2901
3157
|
case "end":
|
|
2902
|
-
return
|
|
3158
|
+
return _context27.stop();
|
|
2903
3159
|
}
|
|
2904
|
-
},
|
|
3160
|
+
}, _loop4);
|
|
2905
3161
|
});
|
|
2906
3162
|
case 28:
|
|
2907
3163
|
if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
|
|
2908
|
-
|
|
3164
|
+
_context28.next = 34;
|
|
2909
3165
|
break;
|
|
2910
3166
|
}
|
|
2911
|
-
return
|
|
3167
|
+
return _context28.delegateYield(_loop4(), "t0", 30);
|
|
2912
3168
|
case 30:
|
|
2913
|
-
if (!
|
|
2914
|
-
|
|
3169
|
+
if (!_context28.t0) {
|
|
3170
|
+
_context28.next = 32;
|
|
2915
3171
|
break;
|
|
2916
3172
|
}
|
|
2917
|
-
return
|
|
3173
|
+
return _context28.abrupt("break", 34);
|
|
2918
3174
|
case 32:
|
|
2919
|
-
|
|
3175
|
+
_context28.next = 28;
|
|
2920
3176
|
break;
|
|
2921
3177
|
case 34:
|
|
2922
3178
|
// 最终把资源数据也加到日期内
|
|
@@ -2931,15 +3187,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2931
3187
|
startDate: startDate,
|
|
2932
3188
|
endDate: dayjs(currentDate).format('YYYY-MM-DD')
|
|
2933
3189
|
};
|
|
2934
|
-
return
|
|
3190
|
+
return _context28.abrupt("return", {
|
|
2935
3191
|
dateList: dates,
|
|
2936
3192
|
firstAvailableDate: firstAvailableDate
|
|
2937
3193
|
});
|
|
2938
3194
|
case 39:
|
|
2939
3195
|
case "end":
|
|
2940
|
-
return
|
|
3196
|
+
return _context28.stop();
|
|
2941
3197
|
}
|
|
2942
|
-
},
|
|
3198
|
+
}, _callee27, this);
|
|
2943
3199
|
}));
|
|
2944
3200
|
function getAvailableDateForSessionOptimize() {
|
|
2945
3201
|
return _getAvailableDateForSessionOptimize.apply(this, arguments);
|