@pisell/pisellos 2.1.17 → 2.1.19

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.
@@ -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, getResourcesIdsByProduct, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection } from "./utils/resources";
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: (function () {
1105
- var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(productData) {
1106
- var activeAccount;
1107
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1108
- while (1) switch (_context24.prev = _context24.next) {
1109
- case 0:
1110
- // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
1111
- activeAccount = this.getActiveAccount(); // 直接调用 addProductToCart,不传递 date 参数以避免日期检查逻辑
1112
- this.addProductToCart({
1113
- product: productData,
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
  /**
@@ -2250,12 +2261,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2250
2261
  });
2251
2262
  });
2252
2263
  }
2253
- }, {
2254
- key: "clearCache",
2255
- value: function clearCache() {}
2256
- }, {
2257
- key: "clearCacheByModule",
2258
- value: function clearCacheByModule(module) {}
2259
2264
  }, {
2260
2265
  key: "getScheduleDataByIds",
2261
2266
  value: function getScheduleDataByIds(scheduleIds) {
@@ -2286,42 +2291,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2286
2291
  }, {
2287
2292
  key: "openProductDetail",
2288
2293
  value: function () {
2289
- var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(productId) {
2294
+ var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(productId) {
2290
2295
  var targetProductData, newScheduleArr, dateRange;
2291
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2292
- while (1) switch (_context25.prev = _context25.next) {
2296
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2297
+ while (1) switch (_context24.prev = _context24.next) {
2293
2298
  case 0:
2294
- _context25.next = 2;
2299
+ _context24.next = 2;
2295
2300
  return this.store.products.getProduct(productId);
2296
2301
  case 2:
2297
- targetProductData = _context25.sent;
2302
+ targetProductData = _context24.sent;
2298
2303
  if (!targetProductData) {
2299
- _context25.next = 17;
2304
+ _context24.next = 17;
2300
2305
  break;
2301
2306
  }
2302
2307
  this.store.currentProduct = targetProductData;
2303
2308
  this.store.currentProductMeta = {};
2304
2309
  // 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
2305
2310
  if (!targetProductData['schedule.ids']) {
2306
- _context25.next = 12;
2311
+ _context24.next = 12;
2307
2312
  break;
2308
2313
  }
2309
2314
  newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
2310
2315
  if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
2311
2316
  this.store.currentProductMeta.schedule = newScheduleArr;
2312
- _context25.next = 17;
2317
+ _context24.next = 17;
2313
2318
  break;
2314
2319
  case 12:
2315
2320
  if (!targetProductData.duration) {
2316
- _context25.next = 17;
2321
+ _context24.next = 17;
2317
2322
  break;
2318
2323
  }
2319
2324
  dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
2320
2325
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
2321
- _context25.next = 16;
2326
+ _context24.next = 16;
2322
2327
  break;
2323
2328
  }
2324
- return _context25.abrupt("return");
2329
+ return _context24.abrupt("return");
2325
2330
  case 16:
2326
2331
  // this.store.date.getResourceDates({
2327
2332
  // query: {
@@ -2337,11 +2342,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2337
2342
  });
2338
2343
  case 17:
2339
2344
  case "end":
2340
- return _context25.stop();
2345
+ return _context24.stop();
2341
2346
  }
2342
- }, _callee25, this);
2347
+ }, _callee24, this);
2343
2348
  }));
2344
- function openProductDetail(_x19) {
2349
+ function openProductDetail(_x18) {
2345
2350
  return _openProductDetail.apply(this, arguments);
2346
2351
  }
2347
2352
  return openProductDetail;
@@ -2354,10 +2359,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2354
2359
  }
2355
2360
  this.store.currentProduct = undefined;
2356
2361
  }
2362
+
2363
+ // 通过商品和 schedule 来获取视频可用的时间片、时间片内资源可用的数据
2357
2364
  }, {
2358
2365
  key: "getTimeslotBySchedule",
2359
2366
  value: function getTimeslotBySchedule(_ref10) {
2360
- var _this$store$currentPr2, _targetProductData$pr;
2367
+ var _this$store$currentPr2,
2368
+ _targetProductData$pr,
2369
+ _this14 = this;
2361
2370
  var date = _ref10.date,
2362
2371
  scheduleIds = _ref10.scheduleIds,
2363
2372
  resources = _ref10.resources,
@@ -2464,6 +2473,129 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2464
2473
  }
2465
2474
  }
2466
2475
  });
2476
+ // 容量检测
2477
+ var cartItems = _this14.store.cart.getItems();
2478
+ productResources.forEach(function (n) {
2479
+ // 单个预约检测规则:
2480
+ // 1、跟我一样的商品同一时间在购物车里不可以超过我最少的那种资源的关联的资源个数
2481
+ // 2、跟我不一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,她配置了几个资源的个数+我配置了几个资源的个数,然后购物车里有几个这样的商品,对应的资源做一个去重,不超过这个去重以后的总数
2482
+ if (n.type === 'single') {
2483
+ var currentResourcesSet = new Set([].concat(_toConsumableArray(n.optional_resource), _toConsumableArray(n.default_resource)));
2484
+ // 规则 1
2485
+ var sameCartItems = cartItems.filter(function (m) {
2486
+ var _m$_productOrigin, _targetProductData$id;
2487
+ 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;
2488
+ });
2489
+ if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
2490
+ bookingLeft = 0;
2491
+ count = 0;
2492
+ }
2493
+ // 规则 2
2494
+ var otherCartItems = cartItems.filter(function (m) {
2495
+ var _m$_productOrigin2, _targetProductData$id2;
2496
+ 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;
2497
+ });
2498
+ otherCartItems.forEach(function (m) {
2499
+ var _m$_productOrigin3;
2500
+ 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) {
2501
+ return m.type === n.type;
2502
+ });
2503
+ 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) || [])));
2504
+ // 把sameTypeResourcesSet 加到currentResourcesSet
2505
+ sameTypeResourcesSet.forEach(function (resource) {
2506
+ return currentResourcesSet.add(resource);
2507
+ });
2508
+ });
2509
+ // 先确定是否每一个currentResourcesSet在这个时间点的 event_list 都是空的,如果不是空的还需要把他踢出currentResourcesSet
2510
+ var currentDataResources = _this14.store.date.getResourcesListByDate(dayjs(item.start).format('YYYY-MM-DD'));
2511
+ currentDataResources === null || currentDataResources === void 0 || currentDataResources.forEach(function (m) {
2512
+ if (currentResourcesSet.has(m.id)) {
2513
+ var mTimes = m.times.filter(function (n) {
2514
+ 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');
2515
+ });
2516
+ if (!mTimes.length || mTimes.some(function (n) {
2517
+ return n.event_list.length;
2518
+ })) {
2519
+ currentResourcesSet.delete(m.id);
2520
+ }
2521
+ }
2522
+ });
2523
+ if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
2524
+ bookingLeft = 0;
2525
+ count = 0;
2526
+ }
2527
+ } else {
2528
+ // 多个预约的检测规则:
2529
+ // 规则1、跟我一样的商品同一时间在购物车需要的容量总数不可以超过我配置的资源的 capacity 之和
2530
+ var _sameCartItems = cartItems.filter(function (m) {
2531
+ var _m$_productOrigin4, _targetProductData$id3;
2532
+ 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;
2533
+ });
2534
+ var sameCartNeedCapacity = _sameCartItems.reduce(function (acc, curr) {
2535
+ return acc + getCapacityInfoByCartItem(curr).currentCapacity;
2536
+ }, 0);
2537
+ var currentProductResourcesCapacity = n.renderList.reduce(function (acc, curr) {
2538
+ return !curr.onlyComputed ? acc + curr.capacity || 0 : acc;
2539
+ }, 0);
2540
+ if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
2541
+ bookingLeft = 0;
2542
+ count = 0;
2543
+ }
2544
+ // 规则2、不管是不是跟我一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,把所有购物车的 capacity 之和 和 所有当前类型资源的 capacity 之和比较,如果超过了resourcesCapacity,则不可用
2545
+ // const otherCartItems = cartItems.filter((m) => m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && m.start_time === item.start && m.end_time === item.end);
2546
+ var otherSameTimesCartItems = cartItems.filter(function (m) {
2547
+ return "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2548
+ });
2549
+ var otherCartNeedCapacity = otherSameTimesCartItems.reduce(function (acc, curr) {
2550
+ return acc + getCapacityInfoByCartItem(curr).currentCapacity;
2551
+ }, 0);
2552
+ var allRenderList = _toConsumableArray(n.renderList.filter(function (m) {
2553
+ return !m.onlyComputed;
2554
+ }));
2555
+ otherSameTimesCartItems.forEach(function (m) {
2556
+ var _m$_productOrigin5;
2557
+ 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);
2558
+ productResources.forEach(function (m) {
2559
+ if (m.id === n.id) {
2560
+ m.renderList.forEach(function (n) {
2561
+ if (!n.onlyComputed && !allRenderList.find(function (m) {
2562
+ return m.id === n.id;
2563
+ })) {
2564
+ allRenderList.push(n);
2565
+ }
2566
+ });
2567
+ }
2568
+ });
2569
+ });
2570
+ var currentTypeResourcesCapacity = allRenderList.reduce(function (acc, curr) {
2571
+ return acc + curr.capacity || 0;
2572
+ }, 0);
2573
+ // 计算当前时间段内所有资源的已使用容量
2574
+ var usedCapacity = allRenderList.reduce(function (acc, curr) {
2575
+ var mTimes = curr.times.filter(function (n) {
2576
+ 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');
2577
+ });
2578
+ // 这里为什么要设置个 map,因为有可能日程有重叠,所以要把重叠的 event_list 去除
2579
+ var mSet = new Map();
2580
+ mTimes.forEach(function (n) {
2581
+ // acc += n.event_list?.reduce((acc: any, curr: any) => acc + curr.pax, 0);
2582
+ // mSet.set(n)
2583
+ n.event_list.forEach(function (m) {
2584
+ mSet.set(m.id, m.pax || 1);
2585
+ });
2586
+ });
2587
+ acc += Array.from(mSet.values()).reduce(function (acc, curr) {
2588
+ return acc + curr;
2589
+ }, 0);
2590
+ return acc;
2591
+ }, 0);
2592
+ // 如果已使用容量超过了当前类型资源的容量,则不可用
2593
+ if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
2594
+ bookingLeft = 0;
2595
+ count = 0;
2596
+ }
2597
+ }
2598
+ });
2467
2599
  var startDayJs = dayjs(item.start);
2468
2600
  var endDayJs = dayjs(item.end);
2469
2601
  return {
@@ -2477,6 +2609,436 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2477
2609
  });
2478
2610
  return formatScheduleTimeSlots;
2479
2611
  }
2612
+
2613
+ // 提供给 UI的方法,当前步骤是选择商品,下一步不管是什么都需要在这里做一次检测
2614
+ // 时长类商品关联的资源为多个预约时,在点击进入"选择资源"步骤之前,需要检测当前所有资源的总容量
2615
+ // 选择商品数量大于所有资源配置的总容量时,不能进入下一步,需要在"选择商品"这一步时提示。
2616
+ // 注意 资源分为多个种类,需要每个种类单独检测,不能一股脑把所有资源的容量加起来检测
2617
+ /**
2618
+ * 找到多个资源的公共可用时间段
2619
+ */
2620
+ }, {
2621
+ key: "findCommonAvailableTimeSlots",
2622
+ value: function findCommonAvailableTimeSlots(resources) {
2623
+ if (resources.length === 0) return [];
2624
+ console.log("\u8BA1\u7B97 ".concat(resources.length, " \u4E2A\u8D44\u6E90\u7684\u516C\u5171\u65F6\u95F4\u6BB5"));
2625
+
2626
+ // 收集所有资源的时间段,转换为统一的时间格式
2627
+ var allTimeSlots = resources.map(function (resource) {
2628
+ return resource.times.map(function (time) {
2629
+ return {
2630
+ start: dayjs(time.start_at),
2631
+ end: dayjs(time.end_at)
2632
+ };
2633
+ });
2634
+ });
2635
+ console.log('所有资源的时间段:', allTimeSlots.map(function (slots) {
2636
+ return slots.map(function (slot) {
2637
+ return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
2638
+ });
2639
+ }));
2640
+
2641
+ // 找到公共时间段的交集
2642
+ var commonSlots = allTimeSlots[0]; // 从第一个资源的时间段开始
2643
+ console.log('初始公共时间段:', commonSlots.map(function (slot) {
2644
+ return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
2645
+ }));
2646
+
2647
+ // 与其他资源的时间段求交集
2648
+ var _loop2 = function _loop2() {
2649
+ var currentResourceSlots = allTimeSlots[i];
2650
+ var intersections = [];
2651
+
2652
+ // 计算当前公共时间段与下一个资源时间段的交集
2653
+ commonSlots.forEach(function (commonSlot) {
2654
+ currentResourceSlots.forEach(function (currentSlot) {
2655
+ var overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
2656
+ var overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
2657
+
2658
+ // 如果有重叠时间且重叠时间大于0
2659
+ if (overlapStart.isBefore(overlapEnd)) {
2660
+ intersections.push({
2661
+ start: overlapStart,
2662
+ end: overlapEnd
2663
+ });
2664
+ }
2665
+ });
2666
+ });
2667
+ commonSlots = intersections;
2668
+ console.log("\u4E0E\u8D44\u6E90".concat(i, "\u6C42\u4EA4\u96C6\u540E\u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonSlots.map(function (slot) {
2669
+ return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
2670
+ }));
2671
+
2672
+ // 如果没有公共时间段,直接返回
2673
+ if (commonSlots.length === 0) {
2674
+ console.log('没有找到公共时间段');
2675
+ return {
2676
+ v: []
2677
+ };
2678
+ }
2679
+ },
2680
+ _ret2;
2681
+ for (var i = 1; i < allTimeSlots.length; i++) {
2682
+ _ret2 = _loop2();
2683
+ if (_ret2) return _ret2.v;
2684
+ }
2685
+
2686
+ // 格式化返回结果
2687
+ var result = commonSlots.map(function (slot) {
2688
+ return {
2689
+ startTime: slot.start.format('HH:mm'),
2690
+ endTime: slot.end.format('HH:mm')
2691
+ };
2692
+ });
2693
+ console.log('最终公共时间段:', result);
2694
+ return result;
2695
+ }
2696
+ }, {
2697
+ key: "checkMaxDurationCapacity",
2698
+ value: function checkMaxDurationCapacity() {
2699
+ var _this15 = this;
2700
+ var cartItems = cloneDeep(this.store.cart.getItems());
2701
+ if (cartItems.length === 0) return {
2702
+ success: true,
2703
+ minAvailableCount: 0
2704
+ };
2705
+
2706
+ // 将购物车商品分为有时间的和没有时间的
2707
+ var itemsWithTime = [];
2708
+ var itemsWithoutTime = [];
2709
+ // 记录每种资源类型的可用数量
2710
+ var availableCountsByResourceType = [];
2711
+ cartItems.forEach(function (cartItem) {
2712
+ if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
2713
+ itemsWithTime.push(cartItem);
2714
+ } else {
2715
+ itemsWithoutTime.push(cartItem);
2716
+ }
2717
+ });
2718
+
2719
+ // 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
2720
+ var processedItemsWithoutTime = [];
2721
+ if (itemsWithoutTime.length > 0) {
2722
+ // 按资源类型分组处理没有时间的商品
2723
+ var itemsByResourceType = {};
2724
+ itemsWithoutTime.forEach(function (cartItem) {
2725
+ var _cartItem$_productOri10;
2726
+ if (!cartItem._productOrigin) return;
2727
+ var resourceTypes = ((_cartItem$_productOri10 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.resources) || [];
2728
+ resourceTypes.forEach(function (resourceType) {
2729
+ if (resourceType.status === 1) {
2730
+ var _resourceType$id;
2731
+ var resourceCode = resourceType.code || ((_resourceType$id = resourceType.id) === null || _resourceType$id === void 0 ? void 0 : _resourceType$id.toString());
2732
+ if (!itemsByResourceType[resourceCode]) {
2733
+ itemsByResourceType[resourceCode] = [];
2734
+ }
2735
+ // 避免重复添加同一个商品
2736
+ if (!itemsByResourceType[resourceCode].find(function (item) {
2737
+ return item._id === cartItem._id;
2738
+ })) {
2739
+ itemsByResourceType[resourceCode].push(cartItem);
2740
+ }
2741
+ }
2742
+ });
2743
+ });
2744
+
2745
+ // 为每种资源类型检查容量
2746
+ var dateRange = this.store.date.getDateRange();
2747
+ if (!dateRange || dateRange.length === 0) return {
2748
+ success: false,
2749
+ minAvailableCount: 0
2750
+ };
2751
+ var resourcesDates = this.store.date.getDateList();
2752
+ var targetResourceDate = resourcesDates.find(function (n) {
2753
+ return n.date === dateRange[0].date;
2754
+ });
2755
+ if (!targetResourceDate) return {
2756
+ success: false,
2757
+ minAvailableCount: 0
2758
+ };
2759
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
2760
+
2761
+ // 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
2762
+ var resourceCodeToFormIdMap = {};
2763
+
2764
+ // 遍历购物车中的商品,收集所有资源类型配置
2765
+ Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
2766
+ var _cartItem$_productOri11;
2767
+ if ((_cartItem$_productOri11 = cartItem._productOrigin) !== null && _cartItem$_productOri11 !== void 0 && (_cartItem$_productOri11 = _cartItem$_productOri11.product_resource) !== null && _cartItem$_productOri11 !== void 0 && _cartItem$_productOri11.resources) {
2768
+ cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
2769
+ // 只处理启用的资源类型 (status === 1)
2770
+ if (resourceConfig.status === 1 && resourceConfig.code) {
2771
+ var _resourceConfig$id, _resourceConfig$resou;
2772
+ 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());
2773
+ if (formId) {
2774
+ resourceCodeToFormIdMap[resourceConfig.code] = formId;
2775
+ }
2776
+ }
2777
+ });
2778
+ }
2779
+ });
2780
+ var hasCapacityIssue = false;
2781
+ var resourceCapacityInfo = [];
2782
+
2783
+ // 用于跟踪已处理的商品,避免重复添加
2784
+ var processedCartItemIds = new Set();
2785
+
2786
+ // 先检查所有资源类型,收集可用数量信息
2787
+ var _loop3 = function _loop3() {
2788
+ var _resourceTypeConfig;
2789
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
2790
+ resourceCode = _Object$entries$_i[0],
2791
+ items = _Object$entries$_i[1];
2792
+ // 获取该资源类型对应的 form_id
2793
+ var targetFormId = resourceCodeToFormIdMap[resourceCode];
2794
+ if (!targetFormId) {
2795
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
2796
+ return {
2797
+ v: {
2798
+ success: false,
2799
+ minAvailableCount: 0
2800
+ }
2801
+ };
2802
+ }
2803
+
2804
+ // 获取该资源类型的所有资源
2805
+ var resourcesOfThisType = [];
2806
+ items.forEach(function (cartItem) {
2807
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
2808
+ productResourceIds.forEach(function (resourceId) {
2809
+ var _resource$form_id;
2810
+ var resource = resourcesMap[resourceId];
2811
+ if (resource && ((_resource$form_id = resource.form_id) === null || _resource$form_id === void 0 ? void 0 : _resource$form_id.toString()) === targetFormId) {
2812
+ // 避免重复添加同一个资源
2813
+ if (!resourcesOfThisType.find(function (r) {
2814
+ return r.id === resource.id;
2815
+ })) {
2816
+ resourcesOfThisType.push(resource);
2817
+ }
2818
+ }
2819
+ });
2820
+ });
2821
+ if (resourcesOfThisType.length === 0) {
2822
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
2823
+ return {
2824
+ v: {
2825
+ success: false,
2826
+ minAvailableCount: 0
2827
+ }
2828
+ };
2829
+ }
2830
+
2831
+ // 检查资源类型(单个预约 vs 多个预约)
2832
+ // 从商品配置中获取资源类型信息
2833
+ var resourceTypeConfig = null;
2834
+ var _iterator3 = _createForOfIteratorHelper(items),
2835
+ _step3;
2836
+ try {
2837
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2838
+ var _cartItem$_productOri12;
2839
+ var cartItem = _step3.value;
2840
+ if ((_cartItem$_productOri12 = cartItem._productOrigin) !== null && _cartItem$_productOri12 !== void 0 && (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) !== null && _cartItem$_productOri12 !== void 0 && _cartItem$_productOri12.resources) {
2841
+ resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
2842
+ return r.code === resourceCode && r.status === 1;
2843
+ });
2844
+ if (resourceTypeConfig) break;
2845
+ }
2846
+ }
2847
+ } catch (err) {
2848
+ _iterator3.e(err);
2849
+ } finally {
2850
+ _iterator3.f();
2851
+ }
2852
+ var isMultipleBooking = ((_resourceTypeConfig = resourceTypeConfig) === null || _resourceTypeConfig === void 0 ? void 0 : _resourceTypeConfig.type) === 'multiple';
2853
+ var totalAvailable;
2854
+ var requiredAmount;
2855
+ var availableAmount;
2856
+ if (isMultipleBooking) {
2857
+ // 多个预约:计算容量
2858
+ totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
2859
+ return sum + (resource.capacity || 0);
2860
+ }, 0);
2861
+ requiredAmount = items.reduce(function (sum, cartItem) {
2862
+ var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
2863
+ currentCapacity = _getCapacityInfoByCar7.currentCapacity;
2864
+ return sum + currentCapacity;
2865
+ }, 0);
2866
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
2867
+ } else {
2868
+ // 单个预约:计算资源个数
2869
+ totalAvailable = resourcesOfThisType.length;
2870
+ requiredAmount = items.reduce(function (sum, cartItem) {
2871
+ return sum + (cartItem.num || 1);
2872
+ }, 0);
2873
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
2874
+ }
2875
+
2876
+ // 记录资源容量信息
2877
+ resourceCapacityInfo.push({
2878
+ code: resourceCode,
2879
+ available: availableAmount,
2880
+ total: totalAvailable,
2881
+ required: requiredAmount,
2882
+ isMultiple: isMultipleBooking
2883
+ });
2884
+ availableCountsByResourceType.push(availableAmount);
2885
+
2886
+ // 检查是否有容量问题
2887
+ if (requiredAmount > totalAvailable) {
2888
+ hasCapacityIssue = true;
2889
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
2890
+ }
2891
+
2892
+ // 为通过检测的商品分配一个公共可用时间段
2893
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
2894
+ return {
2895
+ id: r.id,
2896
+ times: r.times.map(function (t) {
2897
+ return "".concat(t.start_at, " - ").concat(t.end_at);
2898
+ })
2899
+ };
2900
+ }));
2901
+
2902
+ // 找到所有资源都可用的时间段
2903
+ var commonTimeSlots = _this15.findCommonAvailableTimeSlots(resourcesOfThisType);
2904
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
2905
+ if (commonTimeSlots.length === 0) {
2906
+ console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
2907
+ return {
2908
+ v: {
2909
+ success: false,
2910
+ minAvailableCount: 0
2911
+ }
2912
+ };
2913
+ }
2914
+
2915
+ // 使用第一个公共可用时间段,但只处理未处理过的商品
2916
+ var firstCommonSlot = commonTimeSlots[0];
2917
+ console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
2918
+ items.forEach(function (cartItem) {
2919
+ // 只处理未处理过的商品,避免重复添加
2920
+ if (!processedCartItemIds.has(cartItem._id)) {
2921
+ processedCartItemIds.add(cartItem._id);
2922
+ var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
2923
+ start_date: dateRange[0].date,
2924
+ start_time: firstCommonSlot.startTime,
2925
+ end_time: firstCommonSlot.endTime,
2926
+ end_date: dateRange[0].date
2927
+ });
2928
+ processedItemsWithoutTime.push(processedItem);
2929
+ }
2930
+ });
2931
+ },
2932
+ _ret3;
2933
+ for (var _i = 0, _Object$entries = Object.entries(itemsByResourceType); _i < _Object$entries.length; _i++) {
2934
+ _ret3 = _loop3();
2935
+ if (_ret3) return _ret3.v;
2936
+ }
2937
+
2938
+ // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
2939
+ if (hasCapacityIssue) {
2940
+ // 找出超出容量的资源类型中,总容量最少的那个
2941
+ var overCapacityResources = resourceCapacityInfo.filter(function (info) {
2942
+ return info.required > info.total;
2943
+ });
2944
+ if (overCapacityResources.length > 0) {
2945
+ var _minTotalCapacity = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
2946
+ return info.total;
2947
+ })));
2948
+ return {
2949
+ success: false,
2950
+ minAvailableCount: _minTotalCapacity
2951
+ };
2952
+ }
2953
+ // 如果没有超出容量的(理论上不应该发生),返回总容量最少的
2954
+ var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
2955
+ return info.total;
2956
+ })));
2957
+ return {
2958
+ success: false,
2959
+ minAvailableCount: minTotalCapacity
2960
+ };
2961
+ }
2962
+ }
2963
+
2964
+ // 合并所有商品(有时间的 + 处理后的没有时间的)
2965
+ var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
2966
+
2967
+ // 按时间段分组检查
2968
+ var cartItemsByTimeSlot = {};
2969
+ allProcessedItems.forEach(function (cartItem) {
2970
+ if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
2971
+ var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
2972
+ if (!cartItemsByTimeSlot[timeSlotKey]) {
2973
+ cartItemsByTimeSlot[timeSlotKey] = [];
2974
+ }
2975
+ cartItemsByTimeSlot[timeSlotKey].push(cartItem);
2976
+ });
2977
+ // 检查每个时间段是否有足够的资源容量
2978
+ var _loop4 = function _loop4() {
2979
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
2980
+ timeSlotKey = _Object$entries2$_i[0],
2981
+ itemsInTimeSlot = _Object$entries2$_i[1];
2982
+ var _timeSlotKey$split = timeSlotKey.split('_'),
2983
+ _timeSlotKey$split2 = _slicedToArray(_timeSlotKey$split, 4),
2984
+ startDate = _timeSlotKey$split2[0],
2985
+ startTime = _timeSlotKey$split2[1],
2986
+ endDate = _timeSlotKey$split2[2],
2987
+ endTime = _timeSlotKey$split2[3];
2988
+ var timeSlotStart = "".concat(startDate, " ").concat(startTime);
2989
+ var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
2990
+
2991
+ // 获取这个时间段所有商品涉及的资源
2992
+ var allResourcesForTimeSlot = [];
2993
+ var resourcesIdSet = new Set();
2994
+
2995
+ // 获取资源数据
2996
+ var dateRange = _this15.store.date.getDateRange();
2997
+ var resourcesDates = _this15.store.date.getDateList();
2998
+ var targetResourceDate = resourcesDates.find(function (n) {
2999
+ return n.date === startDate;
3000
+ });
3001
+ if (!targetResourceDate) return 0; // continue
3002
+ var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3003
+ itemsInTimeSlot.forEach(function (cartItem) {
3004
+ if (!cartItem._productOrigin) return;
3005
+
3006
+ // 获取商品的资源配置
3007
+ var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3008
+ productResourceIds.forEach(function (resourceId) {
3009
+ if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
3010
+ resourcesIdSet.add(resourceId);
3011
+ allResourcesForTimeSlot.push(resourcesMap[resourceId]);
3012
+ }
3013
+ });
3014
+ });
3015
+
3016
+ // 按资源类型分组检查容量
3017
+ if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
3018
+ // 如果有可用数量记录,返回最小值;否则返回 0
3019
+ var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3020
+ return {
3021
+ v: {
3022
+ success: false,
3023
+ minAvailableCount: _minAvailableCount
3024
+ }
3025
+ };
3026
+ }
3027
+ },
3028
+ _ret4;
3029
+ for (var _i2 = 0, _Object$entries2 = Object.entries(cartItemsByTimeSlot); _i2 < _Object$entries2.length; _i2++) {
3030
+ _ret4 = _loop4();
3031
+ if (_ret4 === 0) continue;
3032
+ if (_ret4) return _ret4.v;
3033
+ }
3034
+
3035
+ // 全部通过检测,返回成功和最小可用数量
3036
+ var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3037
+ return {
3038
+ success: true,
3039
+ minAvailableCount: minAvailableCount
3040
+ };
3041
+ }
2480
3042
  }, {
2481
3043
  key: "setOtherData",
2482
3044
  value: function setOtherData(key, value) {
@@ -2498,41 +3060,41 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2498
3060
  }, {
2499
3061
  key: "getProductTypeById",
2500
3062
  value: function () {
2501
- var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(id) {
3063
+ var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(id) {
2502
3064
  var productData, _productData$schedule;
2503
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2504
- while (1) switch (_context26.prev = _context26.next) {
3065
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3066
+ while (1) switch (_context25.prev = _context25.next) {
2505
3067
  case 0:
2506
- _context26.next = 2;
3068
+ _context25.next = 2;
2507
3069
  return this.store.products.getProduct(id);
2508
3070
  case 2:
2509
- productData = _context26.sent;
3071
+ productData = _context25.sent;
2510
3072
  if (!productData) {
2511
- _context26.next = 9;
3073
+ _context25.next = 9;
2512
3074
  break;
2513
3075
  }
2514
3076
  if (!productData.duration) {
2515
- _context26.next = 6;
3077
+ _context25.next = 6;
2516
3078
  break;
2517
3079
  }
2518
- return _context26.abrupt("return", 'duration');
3080
+ return _context25.abrupt("return", 'duration');
2519
3081
  case 6:
2520
3082
  if (!((_productData$schedule = productData['schedule.ids']) !== null && _productData$schedule !== void 0 && _productData$schedule.length)) {
2521
- _context26.next = 8;
3083
+ _context25.next = 8;
2522
3084
  break;
2523
3085
  }
2524
- return _context26.abrupt("return", 'session');
3086
+ return _context25.abrupt("return", 'session');
2525
3087
  case 8:
2526
- return _context26.abrupt("return", 'normal');
3088
+ return _context25.abrupt("return", 'normal');
2527
3089
  case 9:
2528
- return _context26.abrupt("return", 'normal');
3090
+ return _context25.abrupt("return", 'normal');
2529
3091
  case 10:
2530
3092
  case "end":
2531
- return _context26.stop();
3093
+ return _context25.stop();
2532
3094
  }
2533
- }, _callee26, this);
3095
+ }, _callee25, this);
2534
3096
  }));
2535
- function getProductTypeById(_x20) {
3097
+ function getProductTypeById(_x19) {
2536
3098
  return _getProductTypeById.apply(this, arguments);
2537
3099
  }
2538
3100
  return getProductTypeById;
@@ -2548,7 +3110,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2548
3110
  }, {
2549
3111
  key: "getResourcesByCartItemAndCode",
2550
3112
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
2551
- var _cartItem$_productOri10;
3113
+ var _cartItem$_productOri13;
2552
3114
  var dateRange = this.store.date.getDateRange();
2553
3115
  var resources = [];
2554
3116
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -2571,16 +3133,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2571
3133
  });
2572
3134
  if (!cartItem) return [];
2573
3135
  var selectedResources = [];
2574
- var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
2575
- currentCapacity = _getCapacityInfoByCar7.currentCapacity,
2576
- formatCapacity = _getCapacityInfoByCar7.formatCapacity;
3136
+ var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3137
+ currentCapacity = _getCapacityInfoByCar8.currentCapacity,
3138
+ formatCapacity = _getCapacityInfoByCar8.formatCapacity;
2577
3139
  cartItem._origin.metadata.capacity = formatCapacity;
2578
3140
  if (cartItem.holder_id) {
2579
3141
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
2580
3142
  } else {
2581
3143
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
2582
3144
  }
2583
- var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri10 = cartItem._productOrigin) === null || _cartItem$_productOri10 === void 0 || (_cartItem$_productOri10 = _cartItem$_productOri10.product_resource) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.resources) || [], selectedResources, currentCapacity);
3145
+ 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);
2584
3146
  var targetResource = productResources.find(function (resource) {
2585
3147
  return resource.code === resourceCode;
2586
3148
  });
@@ -2603,7 +3165,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2603
3165
  });
2604
3166
  if (mTimes.length === 0) return false;
2605
3167
  var canUseArr = mTimes.map(function (item) {
2606
- var _cartItem$_productOri11;
3168
+ var _cartItem$_productOri14;
2607
3169
  var res = getIsUsableByTimeItem({
2608
3170
  timeSlice: {
2609
3171
  start_time: startTime.format('HH:mm'),
@@ -2615,7 +3177,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2615
3177
  resource: m,
2616
3178
  currentCount: currentCapacity || 0,
2617
3179
  resourcesUseableMap: resourcesUseableMap,
2618
- cut_off_time: (_cartItem$_productOri11 = cartItem._productOrigin) === null || _cartItem$_productOri11 === void 0 ? void 0 : _cartItem$_productOri11.cut_off_time
3180
+ cut_off_time: (_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.cut_off_time
2619
3181
  });
2620
3182
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2621
3183
  resourcesUseableMap[m.id] = res.usable;
@@ -2629,12 +3191,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2629
3191
  });
2630
3192
  } else {
2631
3193
  targetResource.renderList = targetResource.renderList.filter(function (n) {
2632
- var _cartItem$_productOri12;
3194
+ var _cartItem$_productOri15;
2633
3195
  var recordCount = n.capacity || 0;
2634
3196
  if (n.onlyComputed) return false;
2635
3197
  var timeSlots = getTimeSlicesByResource({
2636
3198
  resource: n,
2637
- duration: ((_cartItem$_productOri12 = cartItem._productOrigin) === null || _cartItem$_productOri12 === void 0 || (_cartItem$_productOri12 = _cartItem$_productOri12.duration) === null || _cartItem$_productOri12 === void 0 ? void 0 : _cartItem$_productOri12.value) || 10,
3199
+ 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,
2638
3200
  split: 10,
2639
3201
  currentDate: dateRange[0].date
2640
3202
  });
@@ -2652,10 +3214,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2652
3214
  }, {
2653
3215
  key: "getTimeslotsScheduleByDateRange",
2654
3216
  value: (function () {
2655
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(_ref11) {
2656
- var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i, _dates, date;
2657
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2658
- while (1) switch (_context27.prev = _context27.next) {
3217
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref11) {
3218
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i3, _dates, date;
3219
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3220
+ while (1) switch (_context26.prev = _context26.next) {
2659
3221
  case 0:
2660
3222
  startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
2661
3223
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
@@ -2674,22 +3236,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2674
3236
  }
2675
3237
  // 如果不支持 Web Worker,使用同步方式处理
2676
3238
  results = {};
2677
- for (_i = 0, _dates = dates; _i < _dates.length; _i++) {
2678
- date = _dates[_i];
3239
+ for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
3240
+ date = _dates[_i3];
2679
3241
  results[date] = this.getTimeslotBySchedule({
2680
3242
  date: date,
2681
3243
  scheduleIds: scheduleIds,
2682
3244
  resources: resources
2683
3245
  });
2684
3246
  }
2685
- return _context27.abrupt("return", results);
3247
+ return _context26.abrupt("return", results);
2686
3248
  case 9:
2687
3249
  case "end":
2688
- return _context27.stop();
3250
+ return _context26.stop();
2689
3251
  }
2690
- }, _callee27, this);
3252
+ }, _callee26, this);
2691
3253
  }));
2692
- function getTimeslotsScheduleByDateRange(_x21) {
3254
+ function getTimeslotsScheduleByDateRange(_x20) {
2693
3255
  return _getTimeslotsScheduleByDateRange.apply(this, arguments);
2694
3256
  }
2695
3257
  return getTimeslotsScheduleByDateRange;
@@ -2697,7 +3259,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2697
3259
  }, {
2698
3260
  key: "getAvailableDateForSessionOptimize",
2699
3261
  value: function () {
2700
- var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
3262
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2701
3263
  var _this$store$currentPr3, _this$store$currentPr4, _tempProducts;
2702
3264
  var params,
2703
3265
  startDate,
@@ -2716,12 +3278,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2716
3278
  openResources,
2717
3279
  allProductResources,
2718
3280
  targetSchedules,
2719
- _loop2,
2720
- _args29 = arguments;
2721
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2722
- while (1) switch (_context29.prev = _context29.next) {
3281
+ _loop5,
3282
+ _args28 = arguments;
3283
+ return _regeneratorRuntime().wrap(function _callee27$(_context28) {
3284
+ while (1) switch (_context28.prev = _context28.next) {
2723
3285
  case 0:
2724
- params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
3286
+ params = _args28.length > 0 && _args28[0] !== undefined ? _args28[0] : {};
2725
3287
  // 开始日期如果小于今天,直接以今天当做开始日期
2726
3288
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2727
3289
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -2746,15 +3308,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2746
3308
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2747
3309
  cache = (_this$store$currentPr3 = this.store.currentProductMeta) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3['timeSlotBySchedule'];
2748
3310
  if (!cache) {
2749
- _context29.next = 13;
3311
+ _context28.next = 13;
2750
3312
  break;
2751
3313
  }
2752
3314
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2753
- _context29.next = 13;
3315
+ _context28.next = 13;
2754
3316
  break;
2755
3317
  }
2756
3318
  this.store.date.setDateList(cache.dateList);
2757
- return _context29.abrupt("return", {
3319
+ return _context28.abrupt("return", {
2758
3320
  dateList: cache.dateList,
2759
3321
  firstAvailableDate: cache.firstAvailableDate
2760
3322
  });
@@ -2764,7 +3326,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2764
3326
  schedule = (_this$store$currentPr4 = this.store.currentProductMeta) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4['schedule'];
2765
3327
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2766
3328
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2767
- _context29.next = 19;
3329
+ _context28.next = 19;
2768
3330
  return this.store.date.fetchResourceDates({
2769
3331
  query: {
2770
3332
  start_date: startDate || '',
@@ -2773,7 +3335,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2773
3335
  }
2774
3336
  });
2775
3337
  case 19:
2776
- res = _context29.sent;
3338
+ res = _context28.sent;
2777
3339
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2778
3340
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2779
3341
  dates = [];
@@ -2793,10 +3355,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2793
3355
  }
2794
3356
  });
2795
3357
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
2796
- _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
3358
+ _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
2797
3359
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
2798
- return _regeneratorRuntime().wrap(function _loop2$(_context28) {
2799
- while (1) switch (_context28.prev = _context28.next) {
3360
+ return _regeneratorRuntime().wrap(function _loop5$(_context27) {
3361
+ while (1) switch (_context27.prev = _context27.next) {
2800
3362
  case 0:
2801
3363
  currentDateStr = currentDate.format('YYYY-MM-DD');
2802
3364
  status = 'available'; // 1. 检查商品的提前量等情况是否满足
@@ -2888,32 +3450,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2888
3450
 
2889
3451
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
2890
3452
  if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
2891
- _context28.next = 9;
3453
+ _context27.next = 9;
2892
3454
  break;
2893
3455
  }
2894
- return _context28.abrupt("return", 1);
3456
+ return _context27.abrupt("return", 1);
2895
3457
  case 9:
2896
3458
  currentDate = dayjs(currentDate).add(1, 'day');
2897
3459
  case 10:
2898
3460
  case "end":
2899
- return _context28.stop();
3461
+ return _context27.stop();
2900
3462
  }
2901
- }, _loop2);
3463
+ }, _loop5);
2902
3464
  });
2903
3465
  case 28:
2904
3466
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2905
- _context29.next = 34;
3467
+ _context28.next = 34;
2906
3468
  break;
2907
3469
  }
2908
- return _context29.delegateYield(_loop2(), "t0", 30);
3470
+ return _context28.delegateYield(_loop5(), "t0", 30);
2909
3471
  case 30:
2910
- if (!_context29.t0) {
2911
- _context29.next = 32;
3472
+ if (!_context28.t0) {
3473
+ _context28.next = 32;
2912
3474
  break;
2913
3475
  }
2914
- return _context29.abrupt("break", 34);
3476
+ return _context28.abrupt("break", 34);
2915
3477
  case 32:
2916
- _context29.next = 28;
3478
+ _context28.next = 28;
2917
3479
  break;
2918
3480
  case 34:
2919
3481
  // 最终把资源数据也加到日期内
@@ -2928,15 +3490,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2928
3490
  startDate: startDate,
2929
3491
  endDate: dayjs(currentDate).format('YYYY-MM-DD')
2930
3492
  };
2931
- return _context29.abrupt("return", {
3493
+ return _context28.abrupt("return", {
2932
3494
  dateList: dates,
2933
3495
  firstAvailableDate: firstAvailableDate
2934
3496
  });
2935
3497
  case 39:
2936
3498
  case "end":
2937
- return _context29.stop();
3499
+ return _context28.stop();
2938
3500
  }
2939
- }, _callee28, this);
3501
+ }, _callee27, this);
2940
3502
  }));
2941
3503
  function getAvailableDateForSessionOptimize() {
2942
3504
  return _getAvailableDateForSessionOptimize.apply(this, arguments);