@pisell/pisellos 3.0.41 → 3.0.43

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.
Files changed (61) hide show
  1. package/dist/modules/AccountList/index.js +17 -12
  2. package/dist/modules/Cart/index.d.ts +14 -0
  3. package/dist/modules/Cart/index.js +38 -1
  4. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -0
  5. package/dist/modules/Cart/utils/cartProduct.js +28 -8
  6. package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
  7. package/dist/modules/Cart/utils/changePrice.js +104 -0
  8. package/dist/modules/Date/index.js +74 -10
  9. package/dist/modules/Date/types.d.ts +2 -0
  10. package/dist/modules/Discount/index.d.ts +1 -0
  11. package/dist/modules/Discount/index.js +13 -6
  12. package/dist/modules/Discount/types.d.ts +10 -0
  13. package/dist/modules/ProductList/index.d.ts +7 -0
  14. package/dist/modules/ProductList/index.js +102 -39
  15. package/dist/modules/Rules/index.js +218 -80
  16. package/dist/modules/Rules/types.d.ts +7 -1
  17. package/dist/modules/Schedule/index.d.ts +9 -1
  18. package/dist/modules/Schedule/index.js +122 -2
  19. package/dist/modules/Schedule/types.d.ts +13 -0
  20. package/dist/modules/Schedule/utils.js +4 -0
  21. package/dist/solution/BookingByStep/index.d.ts +121 -30
  22. package/dist/solution/BookingByStep/index.js +760 -1065
  23. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  24. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  25. package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
  26. package/dist/solution/BookingByStep/utils/resources.js +39 -95
  27. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  28. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  29. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  30. package/dist/solution/ShopDiscount/index.js +119 -44
  31. package/lib/modules/AccountList/index.js +4 -0
  32. package/lib/modules/Cart/index.d.ts +14 -0
  33. package/lib/modules/Cart/index.js +34 -1
  34. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -0
  35. package/lib/modules/Cart/utils/cartProduct.js +20 -8
  36. package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
  37. package/lib/modules/Cart/utils/changePrice.js +78 -0
  38. package/lib/modules/Date/index.js +62 -5
  39. package/lib/modules/Date/types.d.ts +2 -0
  40. package/lib/modules/Discount/index.d.ts +1 -0
  41. package/lib/modules/Discount/index.js +17 -6
  42. package/lib/modules/Discount/types.d.ts +10 -0
  43. package/lib/modules/ProductList/index.d.ts +7 -0
  44. package/lib/modules/ProductList/index.js +45 -0
  45. package/lib/modules/Rules/index.js +154 -63
  46. package/lib/modules/Rules/types.d.ts +7 -1
  47. package/lib/modules/Schedule/index.d.ts +9 -1
  48. package/lib/modules/Schedule/index.js +79 -1
  49. package/lib/modules/Schedule/types.d.ts +13 -0
  50. package/lib/modules/Schedule/utils.js +4 -1
  51. package/lib/solution/BookingByStep/index.d.ts +121 -30
  52. package/lib/solution/BookingByStep/index.js +395 -585
  53. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  54. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  55. package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
  56. package/lib/solution/BookingByStep/utils/resources.js +21 -58
  57. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  58. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  59. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  60. package/lib/solution/ShopDiscount/index.js +91 -19
  61. package/package.json +1 -1
@@ -27,7 +27,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
27
27
  import { BaseModule } from "../../modules/BaseModule";
28
28
  import { BookingByStepHooks, createModule } from "./types";
29
29
  import { getAvailableProductResources } from "./utils/products";
30
- import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, formatDefaultCapacitys, getSumCapacity, checkSubResourcesCapacity, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, getResourcesIdsByProduct, sortCombinedResources } from "./utils/resources";
30
+ import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, getResourcesIdsByProduct, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection } from "./utils/resources";
31
31
  import dayjs from 'dayjs';
32
32
  import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
33
33
  import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
@@ -36,9 +36,11 @@ dayjs.extend(isSameOrAfter);
36
36
  import { getResourcesMap } from "../../modules/Resource/utils";
37
37
  import { cloneDeep } from 'lodash-es';
38
38
  import { calcCalendarDataByScheduleResult, calcMinTimeMaxTimeBySchedules, getAllSortedDateRanges } from "../../modules/Schedule/utils";
39
- import { disableAllDates, disableDatesBeforeOneDay, generateMonthDates, handleAvailableDateByResource } from "../../modules/Date/utils";
39
+ import { handleAvailableDateByResource } from "../../modules/Date/utils";
40
40
  import { areAllNormalProducts, isNormalProduct } from "../../modules/Product/utils";
41
- import { calculateResourceAvailableTime, findFastestAvailableResource } from "./utils/timeslots";
41
+ import { calculateResourceAvailableTime, filterConditionTimeSlots, findFastestAvailableResource } from "./utils/timeslots";
42
+ import { updateAllCartItemPrice } from "../../modules/Cart/utils/changePrice";
43
+ import { getCapacityInfoByCartItem, checkSubResourcesCapacity, checkResourceCanUseByCapacity } from "./utils/capacity";
42
44
  export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
43
45
  _inherits(BookingByStepImpl, _BaseModule);
44
46
  var _super = _createSuper(BookingByStepImpl);
@@ -124,7 +126,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
124
126
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
125
127
  }
126
128
  });
127
- this.loadAllSchedule();
129
+ this.store.schedule.loadAllSchedule();
128
130
  this.core.effects.emit(BookingByStepHooks.onInited, {});
129
131
  case 18:
130
132
  case "end":
@@ -205,65 +207,40 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
205
207
  this.store.step.updateStep(key, step);
206
208
  }
207
209
 
208
- // 获取购物车里 temp.xxx的方法
209
- // async getStoreCart(key?: string) {
210
- // return this.store.cart.getTemp(key);
211
- // }
212
-
213
- // 加载商品,然后导到商品列表里去
210
+ /**
211
+ *
212
+ * 加载商品,然后导到商品列表里去
213
+ * @param {({
214
+ * category_ids?: number[];
215
+ * product_ids?: number[];
216
+ * collection?: number | string[];
217
+ * schedule_date?: string;
218
+ * })} {
219
+ * category_ids = [],
220
+ * product_ids = [],
221
+ * collection = [],
222
+ * schedule_date,
223
+ * }
224
+ * @return {*}
225
+ * @memberof BookingByStepImpl
226
+ */
214
227
  }, {
215
228
  key: "loadProducts",
216
- value: function () {
229
+ value: (function () {
217
230
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
218
- var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date, userPlugin, customer_id, _userPlugin$get, productsData;
231
+ var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date;
219
232
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
220
233
  while (1) switch (_context2.prev = _context2.next) {
221
234
  case 0:
222
235
  _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, schedule_date = _ref.schedule_date;
223
- // // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
224
- // if (!schedule_ids?.length) {
225
- // const schedule_ids_data = this.store.schedule
226
- // .getScheduleListByIds(schedule_ids)
227
- // .map((n) => n.id);
228
- // if (schedule_ids_data.length) {
229
- // schedule_ids = schedule_ids_data;
230
- // } else if (schedule_date) {
231
- // // 后端说如果 schedule_ids 如果为空,需要给[0]
232
- // schedule_ids = [0];
233
- // }
234
- // }
235
- userPlugin = this.core.getPlugin('user');
236
- customer_id = undefined;
237
- try {
238
- customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get = userPlugin.get()) === null || _userPlugin$get === void 0 ? void 0 : _userPlugin$get.id;
239
- } catch (error) {
240
- console.error(error);
241
- }
242
- // 如果没传schedule_date,则从
243
- _context2.next = 6;
244
- return this.request.post("/product/query", {
245
- open_quotation: 1,
246
- open_bundle: 0,
247
- exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
248
- with: ['category', 'collection', 'resourceRelation'],
249
- status: 'published',
250
- num: 500,
251
- skip: 1,
252
- customer_id: customer_id,
236
+ return _context2.abrupt("return", this.store.products.loadProducts({
253
237
  category_ids: category_ids,
254
- ids: product_ids,
238
+ product_ids: product_ids,
255
239
  collection: collection,
256
- front_end_cache_id: this.cacheId,
257
- // client_schedule_ids: schedule_ids,
258
- schedule_date: schedule_date
259
- }, {
260
- useCache: true
261
- });
262
- case 6:
263
- productsData = _context2.sent;
264
- this.store.products.addProduct(productsData.data.list);
265
- return _context2.abrupt("return", productsData.data.list);
266
- case 9:
240
+ schedule_date: schedule_date,
241
+ cacheId: this.cacheId
242
+ }));
243
+ case 2:
267
244
  case "end":
268
245
  return _context2.stop();
269
246
  }
@@ -274,9 +251,25 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
274
251
  }
275
252
  return loadProducts;
276
253
  }()
254
+ /**
255
+ * 通过 schedule 来读取商品,适用于 session 类商品
256
+ *
257
+ * @param {{
258
+ * date: string;
259
+ * product_ids?: number[];
260
+ * category_ids?: number[];
261
+ * }} {
262
+ * date,
263
+ * product_ids = [],
264
+ * category_ids = [],
265
+ * }
266
+ * @return {*}
267
+ * @memberof BookingByStepImpl
268
+ */
269
+ )
277
270
  }, {
278
271
  key: "loadProductByScheduleDate",
279
- value: function () {
272
+ value: (function () {
280
273
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
281
274
  var _schedule$product_ids;
282
275
  var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, newProductIds, schedule, otherProductsIds, allProductIds;
@@ -321,7 +314,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
321
314
  });
322
315
  _context3.next = 10;
323
316
  return this.loadProducts({
324
- // schedule_ids: scheduleIds,
325
317
  product_ids: allProductIds,
326
318
  category_ids: category_ids,
327
319
  schedule_date: date
@@ -339,29 +331,35 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
339
331
  }
340
332
  return loadProductByScheduleDate;
341
333
  }()
334
+ /**
335
+ * 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
336
+ *
337
+ * @param {string} date
338
+ * @memberof BookingByStepImpl
339
+ */
340
+ )
342
341
  }, {
343
342
  key: "updateQuotationPriceAndCart",
344
- value: function () {
343
+ value: (function () {
345
344
  var _updateQuotationPriceAndCart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(date) {
346
345
  var _this3 = this;
347
- var cartItems, userPlugin, customer_id, _userPlugin$get2, res, _iterator, _step, _loop;
348
- return _regeneratorRuntime().wrap(function _callee4$(_context5) {
349
- while (1) switch (_context5.prev = _context5.next) {
346
+ var cartItems, userPlugin, customer_id, _userPlugin$get, res;
347
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
348
+ while (1) switch (_context4.prev = _context4.next) {
350
349
  case 0:
351
- // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
352
350
  cartItems = this.store.cart.getItems();
353
351
  if (!cartItems.length) {
354
- _context5.next = 25;
352
+ _context4.next = 11;
355
353
  break;
356
354
  }
357
355
  userPlugin = this.core.getPlugin('user');
358
356
  customer_id = undefined;
359
357
  try {
360
- customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get2 = userPlugin.get()) === null || _userPlugin$get2 === void 0 ? void 0 : _userPlugin$get2.id;
358
+ customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get = userPlugin.get()) === null || _userPlugin$get === void 0 ? void 0 : _userPlugin$get.id;
361
359
  } catch (error) {
362
360
  console.error(error);
363
361
  }
364
- _context5.next = 7;
362
+ _context4.next = 7;
365
363
  return this.store.products.loadProductsPrice({
366
364
  ids: cartItems.map(function (n) {
367
365
  return n.id;
@@ -370,280 +368,104 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
370
368
  customer_id: customer_id
371
369
  });
372
370
  case 7:
373
- res = _context5.sent;
374
- _iterator = _createForOfIteratorHelper(cartItems);
375
- _context5.prev = 9;
376
- _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
377
- var _bundle;
378
- var item, targetProduct, cartProduct, productInfo, bundle;
379
- return _regeneratorRuntime().wrap(function _loop$(_context4) {
380
- while (1) switch (_context4.prev = _context4.next) {
381
- case 0:
382
- item = _step.value;
383
- targetProduct = res.find(function (n) {
384
- return n.id === item.id;
385
- });
386
- _context4.next = 4;
387
- return _this3.store.products.getProduct(item.id);
388
- case 4:
389
- cartProduct = _context4.sent;
390
- productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
391
- bundle = item._bundleOrigin;
392
- productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
393
- productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
394
- bundle = (_bundle = bundle) === null || _bundle === void 0 ? void 0 : _bundle.map(function (n) {
395
- var _targetProduct$bundle;
396
- // 更新 bundle 的价格
397
- var targetBundle = targetProduct === null || targetProduct === void 0 || (_targetProduct$bundle = targetProduct.bundle_group) === null || _targetProduct$bundle === void 0 ? void 0 : _targetProduct$bundle.find(function (m) {
398
- return m.id === n.group_id;
399
- });
400
- if (targetBundle) {
401
- var targetBundleItem = targetBundle.bundle_item.find(function (m) {
402
- return m.id === n.id;
403
- });
404
- if (targetBundleItem) {
405
- return _objectSpread(_objectSpread({}, n), {}, {
406
- price: targetBundleItem.price,
407
- base_price: targetBundleItem.base_price
408
- });
409
- }
410
- }
411
- return n;
412
- });
413
- _this3.store.cart.updateItem({
414
- _id: item._id,
415
- product: productInfo,
416
- bundle: bundle
417
- });
418
- case 11:
419
- case "end":
420
- return _context4.stop();
421
- }
422
- }, _loop);
371
+ res = _context4.sent;
372
+ _context4.next = 10;
373
+ return updateAllCartItemPrice(cartItems, res, function (id) {
374
+ return _this3.store.products.getProduct(id);
375
+ }, function (params) {
376
+ return _this3.store.cart.updateItem(params);
423
377
  });
424
- _iterator.s();
425
- case 12:
426
- if ((_step = _iterator.n()).done) {
427
- _context5.next = 16;
428
- break;
429
- }
430
- return _context5.delegateYield(_loop(), "t0", 14);
431
- case 14:
432
- _context5.next = 12;
433
- break;
434
- case 16:
435
- _context5.next = 21;
436
- break;
437
- case 18:
438
- _context5.prev = 18;
439
- _context5.t1 = _context5["catch"](9);
440
- _iterator.e(_context5.t1);
441
- case 21:
442
- _context5.prev = 21;
443
- _iterator.f();
444
- return _context5.finish(21);
445
- case 24:
378
+ case 10:
446
379
  this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
447
- case 25:
380
+ case 11:
448
381
  case "end":
449
- return _context5.stop();
382
+ return _context4.stop();
450
383
  }
451
- }, _callee4, this, [[9, 18, 21, 24]]);
384
+ }, _callee4, this);
452
385
  }));
453
386
  function updateQuotationPriceAndCart(_x5) {
454
387
  return _updateQuotationPriceAndCart.apply(this, arguments);
455
388
  }
456
389
  return updateQuotationPriceAndCart;
457
- }() // 加载当前店铺下所有 schedule
458
- }, {
459
- key: "loadAllSchedule",
460
- value: function () {
461
- var _loadAllSchedule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
462
- var _scheduleList$data;
463
- var scheduleList;
464
- return _regeneratorRuntime().wrap(function _callee5$(_context6) {
465
- while (1) switch (_context6.prev = _context6.next) {
466
- case 0:
467
- _context6.next = 2;
468
- return this.request.get("/schedule", {
469
- num: 999
470
- }, {
471
- useCache: true
472
- });
473
- case 2:
474
- scheduleList = _context6.sent;
475
- this.store.schedule.setScheduleList(((_scheduleList$data = scheduleList.data) === null || _scheduleList$data === void 0 ? void 0 : _scheduleList$data.list) || []);
476
- case 4:
477
- case "end":
478
- return _context6.stop();
479
- }
480
- }, _callee5, this);
481
- }));
482
- function loadAllSchedule() {
483
- return _loadAllSchedule.apply(this, arguments);
484
- }
485
- return loadAllSchedule;
486
- }() // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
390
+ }()
391
+ /**
392
+ * ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
393
+ * 适用于先选日期的流程,确定日期是否可用
394
+ * 已知问题:如果挂接的商品的资源不可用,后端是不会计算的
395
+ *
396
+ * @param {LoadScheduleAvailableDateParams} {
397
+ * startDate,
398
+ * endDate,
399
+ * custom_page_id,
400
+ * channel,
401
+ * }
402
+ * @memberof BookingByStepImpl
403
+ */
404
+ )
487
405
  }, {
488
406
  key: "loadScheduleAvailableDate",
489
- value: function () {
490
- var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref3) {
491
- var _res$data$date_list, _res$data$other_produ, _res$data$other_produ2;
492
- var startDate, endDate, custom_page_id, channel, dates, res;
493
- return _regeneratorRuntime().wrap(function _callee6$(_context7) {
494
- while (1) switch (_context7.prev = _context7.next) {
407
+ value: (function () {
408
+ var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref3) {
409
+ var startDate, endDate, custom_page_id, channel;
410
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
411
+ while (1) switch (_context5.prev = _context5.next) {
495
412
  case 0:
496
413
  startDate = _ref3.startDate, endDate = _ref3.endDate, custom_page_id = _ref3.custom_page_id, channel = _ref3.channel;
497
- // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天,需要把 startDate 置为今天
498
- if (dayjs(startDate).isBefore(dayjs(), 'day')) {
499
- startDate = dayjs().format('YYYY-MM-DD');
500
- }
501
- // 1.生成当前月份的所有日期,默认都不可用
502
- dates = generateMonthDates(startDate, endDate);
503
- dates = disableAllDates(dates);
504
- // 如果 endDate 在今天之前,则不用查接口,直接返回 dates
505
- if (!dayjs(endDate).isBefore(dayjs(), 'day')) {
506
- _context7.next = 6;
507
- break;
508
- }
509
- return _context7.abrupt("return", dates);
510
- case 6:
511
- _context7.next = 8;
512
- return this.request.get("/schedule/product/availability/v2", {
513
- start_date: startDate,
514
- end_date: endDate,
414
+ _context5.next = 3;
415
+ return this.store.schedule.loadScheduleAvailableDate({
416
+ startDate: startDate,
417
+ endDate: endDate,
515
418
  custom_page_id: custom_page_id,
516
419
  channel: channel
517
420
  });
518
- case 8:
519
- res = _context7.sent;
520
- this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
521
- this.store.schedule.setOtherProductsIds(res.data.other_product_ids || []);
522
- // 如果没有schedule或者结束日期在今天之前,则所有日期均不可用
523
- if (!(!((_res$data$date_list = res.data.date_list) !== null && _res$data$date_list !== void 0 && _res$data$date_list.length) && !((_res$data$other_produ = res.data.other_product_ids) !== null && _res$data$other_produ !== void 0 && _res$data$other_produ.length) || dayjs(endDate).isBefore(dayjs(), 'day'))) {
524
- _context7.next = 13;
525
- break;
526
- }
527
- return _context7.abrupt("return", dates);
528
- case 13:
529
- if ((_res$data$other_produ2 = res.data.other_product_ids) !== null && _res$data$other_produ2 !== void 0 && _res$data$other_produ2.length) {
530
- // 如果后端有返回 other_product_ids ,意味着有 duration 商品,则今天以及今天以后的日期均可用
531
- dates.forEach(function (n) {
532
- n.status = 'available';
533
- });
534
- } else {
535
- res.data.date_list.forEach(function (n) {
536
- var index = dates.findIndex(function (m) {
537
- return m.date === n.date;
538
- });
539
- if (index !== -1) {
540
- dates[index].status = 'available';
541
- }
542
- });
543
- }
544
- dates = disableDatesBeforeOneDay(dates);
545
- return _context7.abrupt("return", dates);
546
- case 16:
421
+ case 3:
422
+ return _context5.abrupt("return", _context5.sent);
423
+ case 4:
547
424
  case "end":
548
- return _context7.stop();
425
+ return _context5.stop();
549
426
  }
550
- }, _callee6, this);
427
+ }, _callee5, this);
551
428
  }));
552
429
  function loadScheduleAvailableDate(_x6) {
553
430
  return _loadScheduleAvailableDate.apply(this, arguments);
554
431
  }
555
432
  return loadScheduleAvailableDate;
556
- }()
557
- }, {
558
- key: "storeProduct",
559
- value: function () {
560
- var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(productData) {
561
- var activeAccount, _ref4, bundle, options, origin, product_variant_id, _ref4$quantity, quantity, rowKey, cartItems, targetCartItem, product, addCartItem;
562
- return _regeneratorRuntime().wrap(function _callee7$(_context8) {
563
- while (1) switch (_context8.prev = _context8.next) {
564
- case 0:
565
- // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
566
- activeAccount = this.getActiveAccount();
567
- _ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id, _ref4$quantity = _ref4.quantity, quantity = _ref4$quantity === void 0 ? 1 : _ref4$quantity, rowKey = _ref4.rowKey; // 检查购物车里是否已经存在 rowKey相同的数据,如果是则更新数量
568
- cartItems = this.store.cart.getItems();
569
- if (!rowKey) {
570
- _context8.next = 8;
571
- break;
572
- }
573
- targetCartItem = cartItems.find(function (n) {
574
- var _n$_productOrigin;
575
- return ((_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.rowKey) === rowKey;
576
- });
577
- if (!(targetCartItem && isNormalProduct(targetCartItem._productOrigin))) {
578
- _context8.next = 8;
579
- break;
580
- }
581
- this.store.cart.updateItem({
582
- _id: targetCartItem._id,
583
- product: _objectSpread({}, targetCartItem._productOrigin),
584
- quantity: (targetCartItem.num || 1) + quantity
585
- });
586
- return _context8.abrupt("return");
587
- case 8:
588
- product = _objectSpread(_objectSpread({}, origin), {}, {
589
- product_variant_id: product_variant_id,
590
- rowKey: rowKey
591
- });
592
- addCartItem = {
593
- product: product,
594
- bundle: bundle,
595
- options: options,
596
- quantity: quantity
597
- };
598
- if (activeAccount) {
599
- addCartItem.account = activeAccount;
600
- }
601
- this.store.cart.addItem(addCartItem);
602
- case 12:
603
- case "end":
604
- return _context8.stop();
605
- }
606
- }, _callee7, this);
607
- }));
608
- function storeProduct(_x7) {
609
- return _storeProduct.apply(this, arguments);
610
- }
611
- return storeProduct;
612
433
  }() // 添加单个账户或者 guest
434
+ )
613
435
  }, {
614
436
  key: "addAccount",
615
437
  value: function () {
616
- var _addAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(account, extra) {
438
+ var _addAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(account, extra) {
617
439
  var accountModules, newAccount;
618
- return _regeneratorRuntime().wrap(function _callee8$(_context9) {
619
- while (1) switch (_context9.prev = _context9.next) {
440
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
441
+ while (1) switch (_context6.prev = _context6.next) {
620
442
  case 0:
621
443
  if (!((extra === null || extra === void 0 ? void 0 : extra.type) === 'holder')) {
622
- _context9.next = 5;
444
+ _context6.next = 5;
623
445
  break;
624
446
  }
625
- _context9.next = 3;
447
+ _context6.next = 3;
626
448
  return this.store.accountList.addHolderAccounts({
627
449
  holders: [account],
628
450
  customerId: extra.customerId,
629
451
  type: 'unshift'
630
452
  });
631
453
  case 3:
632
- accountModules = _context9.sent;
633
- return _context9.abrupt("return", accountModules[0].getAccount());
454
+ accountModules = _context6.sent;
455
+ return _context6.abrupt("return", accountModules[0].getAccount());
634
456
  case 5:
635
- _context9.next = 7;
457
+ _context6.next = 7;
636
458
  return this.store.accountList.addAccount(account);
637
459
  case 7:
638
- newAccount = _context9.sent;
639
- return _context9.abrupt("return", newAccount.getAccount());
460
+ newAccount = _context6.sent;
461
+ return _context6.abrupt("return", newAccount.getAccount());
640
462
  case 9:
641
463
  case "end":
642
- return _context9.stop();
464
+ return _context6.stop();
643
465
  }
644
- }, _callee8, this);
466
+ }, _callee6, this);
645
467
  }));
646
- function addAccount(_x8, _x9) {
468
+ function addAccount(_x7, _x8) {
647
469
  return _addAccount.apply(this, arguments);
648
470
  }
649
471
  return addAccount;
@@ -651,13 +473,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
651
473
  }, {
652
474
  key: "addAccounts",
653
475
  value: function () {
654
- var _addAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(accounts, extra) {
655
- var res, _iterator2, _step2, account, accountModule, accountData;
656
- return _regeneratorRuntime().wrap(function _callee9$(_context10) {
657
- while (1) switch (_context10.prev = _context10.next) {
476
+ var _addAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(accounts, extra) {
477
+ var res, _iterator, _step, account, accountModule, accountData;
478
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
479
+ while (1) switch (_context7.prev = _context7.next) {
658
480
  case 0:
659
481
  if (!((extra === null || extra === void 0 ? void 0 : extra.type) === 'holder')) {
660
- _context10.next = 3;
482
+ _context7.next = 3;
661
483
  break;
662
484
  }
663
485
  this.store.accountList.addHolderAccounts({
@@ -665,49 +487,49 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
665
487
  customerId: extra.customerId,
666
488
  type: 'unshift'
667
489
  });
668
- return _context10.abrupt("return");
490
+ return _context7.abrupt("return");
669
491
  case 3:
670
492
  res = [];
671
- _iterator2 = _createForOfIteratorHelper(accounts);
672
- _context10.prev = 5;
673
- _iterator2.s();
493
+ _iterator = _createForOfIteratorHelper(accounts);
494
+ _context7.prev = 5;
495
+ _iterator.s();
674
496
  case 7:
675
- if ((_step2 = _iterator2.n()).done) {
676
- _context10.next = 16;
497
+ if ((_step = _iterator.n()).done) {
498
+ _context7.next = 16;
677
499
  break;
678
500
  }
679
- account = _step2.value;
680
- _context10.next = 11;
501
+ account = _step.value;
502
+ _context7.next = 11;
681
503
  return this.store.accountList.addAccount(account);
682
504
  case 11:
683
- accountModule = _context10.sent;
505
+ accountModule = _context7.sent;
684
506
  accountData = accountModule.getAccount();
685
507
  if (accountData) {
686
508
  res.push(accountData);
687
509
  }
688
510
  case 14:
689
- _context10.next = 7;
511
+ _context7.next = 7;
690
512
  break;
691
513
  case 16:
692
- _context10.next = 21;
514
+ _context7.next = 21;
693
515
  break;
694
516
  case 18:
695
- _context10.prev = 18;
696
- _context10.t0 = _context10["catch"](5);
697
- _iterator2.e(_context10.t0);
517
+ _context7.prev = 18;
518
+ _context7.t0 = _context7["catch"](5);
519
+ _iterator.e(_context7.t0);
698
520
  case 21:
699
- _context10.prev = 21;
700
- _iterator2.f();
701
- return _context10.finish(21);
521
+ _context7.prev = 21;
522
+ _iterator.f();
523
+ return _context7.finish(21);
702
524
  case 24:
703
- return _context10.abrupt("return", res);
525
+ return _context7.abrupt("return", res);
704
526
  case 25:
705
527
  case "end":
706
- return _context10.stop();
528
+ return _context7.stop();
707
529
  }
708
- }, _callee9, this, [[5, 18, 21, 24]]);
530
+ }, _callee7, this, [[5, 18, 21, 24]]);
709
531
  }));
710
- function addAccounts(_x10, _x11) {
532
+ function addAccounts(_x9, _x10) {
711
533
  return _addAccounts.apply(this, arguments);
712
534
  }
713
535
  return addAccounts;
@@ -715,20 +537,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
715
537
  }, {
716
538
  key: "getAccounts",
717
539
  value: function () {
718
- var _getAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
540
+ var _getAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
719
541
  var accounts;
720
- return _regeneratorRuntime().wrap(function _callee10$(_context11) {
721
- while (1) switch (_context11.prev = _context11.next) {
542
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
543
+ while (1) switch (_context8.prev = _context8.next) {
722
544
  case 0:
723
545
  accounts = this.store.accountList.getAccounts();
724
- return _context11.abrupt("return", accounts.map(function (account) {
546
+ return _context8.abrupt("return", accounts.map(function (account) {
725
547
  return account.getAccount();
726
548
  }));
727
549
  case 2:
728
550
  case "end":
729
- return _context11.stop();
551
+ return _context8.stop();
730
552
  }
731
- }, _callee10, this);
553
+ }, _callee8, this);
732
554
  }));
733
555
  function getAccounts() {
734
556
  return _getAccounts.apply(this, arguments);
@@ -752,7 +574,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
752
574
  key: "getActiveAccount",
753
575
  value: function getActiveAccount() {
754
576
  var activeAccount = this.store.accountList.getActiveAccount();
755
- return activeAccount ? activeAccount.getAccount() : null;
577
+ var account = activeAccount === null || activeAccount === void 0 ? void 0 : activeAccount.getAccount();
578
+ return account === null ? undefined : account;
756
579
  }
757
580
  }, {
758
581
  key: "removeAccount",
@@ -769,10 +592,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
769
592
  }, {
770
593
  key: "fetchHolderAccountsAsync",
771
594
  value: (function () {
772
- var _fetchHolderAccountsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
595
+ var _fetchHolderAccountsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
773
596
  var cartItems, _this$store$date$getD, date, normalProductCartItem;
774
- return _regeneratorRuntime().wrap(function _callee11$(_context12) {
775
- while (1) switch (_context12.prev = _context12.next) {
597
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
598
+ while (1) switch (_context9.prev = _context9.next) {
776
599
  case 0:
777
600
  cartItems = this.store.cart.getItems();
778
601
  if (cartItems.length) {
@@ -787,14 +610,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
787
610
  }
788
611
  this.updateQuotationPriceAndCart(date);
789
612
  }
790
- return _context12.abrupt("return", this.store.accountList.fetchHolderAccounts(params));
613
+ return _context9.abrupt("return", this.store.accountList.fetchHolderAccounts(params));
791
614
  case 3:
792
615
  case "end":
793
- return _context12.stop();
616
+ return _context9.stop();
794
617
  }
795
- }, _callee11, this);
618
+ }, _callee9, this);
796
619
  }));
797
- function fetchHolderAccountsAsync(_x12) {
620
+ function fetchHolderAccountsAsync(_x11) {
798
621
  return _fetchHolderAccountsAsync.apply(this, arguments);
799
622
  }
800
623
  return fetchHolderAccountsAsync;
@@ -803,9 +626,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
803
626
  }, {
804
627
  key: "setDateRange",
805
628
  value: function () {
806
- var _setDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(dateRange) {
807
- return _regeneratorRuntime().wrap(function _callee12$(_context13) {
808
- while (1) switch (_context13.prev = _context13.next) {
629
+ var _setDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(dateRange) {
630
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
631
+ while (1) switch (_context10.prev = _context10.next) {
809
632
  case 0:
810
633
  this.store.date.setDateRange(dateRange);
811
634
  // 日期数据变更后,如果购物车里有数据,需要更新购物车里的报价单的价格
@@ -814,11 +637,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
814
637
  }
815
638
  case 2:
816
639
  case "end":
817
- return _context13.stop();
640
+ return _context10.stop();
818
641
  }
819
- }, _callee12, this);
642
+ }, _callee10, this);
820
643
  }));
821
- function setDateRange(_x13) {
644
+ function setDateRange(_x12) {
822
645
  return _setDateRange.apply(this, arguments);
823
646
  }
824
647
  return setDateRange;
@@ -833,16 +656,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
833
656
  }, {
834
657
  key: "getDateRange",
835
658
  value: function () {
836
- var _getDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
837
- return _regeneratorRuntime().wrap(function _callee13$(_context14) {
838
- while (1) switch (_context14.prev = _context14.next) {
659
+ var _getDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
660
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
661
+ while (1) switch (_context11.prev = _context11.next) {
839
662
  case 0:
840
- return _context14.abrupt("return", this.store.date.getDateRange());
663
+ return _context11.abrupt("return", this.store.date.getDateRange());
841
664
  case 1:
842
665
  case "end":
843
- return _context14.stop();
666
+ return _context11.stop();
844
667
  }
845
- }, _callee13, this);
668
+ }, _callee11, this);
846
669
  }));
847
670
  function getDateRange() {
848
671
  return _getDateRange.apply(this, arguments);
@@ -859,7 +682,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
859
682
  }, {
860
683
  key: "getAvailableDate",
861
684
  value: function () {
862
- var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
685
+ var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
863
686
  var _this4 = this,
864
687
  _dateRange$,
865
688
  _dateRange$2,
@@ -869,22 +692,24 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
869
692
  startDate,
870
693
  endDate,
871
694
  type,
695
+ _params$useCache,
696
+ useCache,
872
697
  tempProducts,
873
698
  dateRange,
874
699
  tempStartDate,
875
700
  tempEndDate,
876
- _ref5,
701
+ _ref4,
877
702
  resourceIds,
878
703
  rules,
879
704
  resourcesMap,
880
705
  res,
881
- _args15 = arguments;
882
- return _regeneratorRuntime().wrap(function _callee14$(_context15) {
883
- while (1) switch (_context15.prev = _context15.next) {
706
+ _args12 = arguments;
707
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
708
+ while (1) switch (_context12.prev = _context12.next) {
884
709
  case 0:
885
- params = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
710
+ params = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
886
711
  // 开始日期如果小于今天,直接以今天当做开始日期
887
- products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
712
+ products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type, _params$useCache = params.useCache, useCache = _params$useCache === void 0 ? true : _params$useCache; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
888
713
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
889
714
  startDate = dayjs().format('YYYY-MM-DD');
890
715
  }
@@ -909,15 +734,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
909
734
  tempStartDate = startDate || (dateRange === null || dateRange === void 0 || (_dateRange$ = dateRange[0]) === null || _dateRange$ === void 0 ? void 0 : _dateRange$.date);
910
735
  tempEndDate = endDate || (dateRange === null || dateRange === void 0 || (_dateRange$2 = dateRange[1]) === null || _dateRange$2 === void 0 ? void 0 : _dateRange$2.date) || (dateRange === null || dateRange === void 0 || (_dateRange$3 = dateRange[0]) === null || _dateRange$3 === void 0 ? void 0 : _dateRange$3.date);
911
736
  if (tempProducts.length) {
912
- _context15.next = 11;
737
+ _context12.next = 11;
913
738
  break;
914
739
  }
915
- return _context15.abrupt("return", []);
740
+ return _context12.abrupt("return", []);
916
741
  case 11:
917
742
  // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
918
- _ref5 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref5.resourceIds, rules = _ref5.rules, resourcesMap = _ref5.resourcesMap;
743
+ _ref4 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref4.resourceIds, rules = _ref4.rules, resourcesMap = _ref4.resourcesMap;
919
744
  this.otherParams.currentResourcesMap = resourcesMap;
920
- _context15.next = 15;
745
+ _context12.next = 15;
921
746
  return this.store.date.getResourceDates({
922
747
  url: params.url,
923
748
  query: {
@@ -926,16 +751,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
926
751
  resource_ids: resourceIds
927
752
  },
928
753
  rules: rules,
929
- type: type
754
+ type: type,
755
+ useCache: useCache
930
756
  });
931
757
  case 15:
932
- res = _context15.sent;
933
- return _context15.abrupt("return", res);
758
+ res = _context12.sent;
759
+ return _context12.abrupt("return", res);
934
760
  case 17:
935
761
  case "end":
936
- return _context15.stop();
762
+ return _context12.stop();
937
763
  }
938
- }, _callee14, this);
764
+ }, _callee12, this);
939
765
  }));
940
766
  function getAvailableDate() {
941
767
  return _getAvailableDate.apply(this, arguments);
@@ -948,22 +774,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
948
774
  }, {
949
775
  key: "getSummary",
950
776
  value: (function () {
951
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
777
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
952
778
  var cartItems, summary;
953
- return _regeneratorRuntime().wrap(function _callee15$(_context16) {
954
- while (1) switch (_context16.prev = _context16.next) {
779
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
780
+ while (1) switch (_context13.prev = _context13.next) {
955
781
  case 0:
956
782
  cartItems = this.store.cart.getItems();
957
- _context16.next = 3;
783
+ _context13.next = 3;
958
784
  return this.store.summary.getSummary(cartItems);
959
785
  case 3:
960
- summary = _context16.sent;
961
- return _context16.abrupt("return", summary);
786
+ summary = _context13.sent;
787
+ return _context13.abrupt("return", summary);
962
788
  case 5:
963
789
  case "end":
964
- return _context16.stop();
790
+ return _context13.stop();
965
791
  }
966
- }, _callee15, this);
792
+ }, _callee13, this);
967
793
  }));
968
794
  function getSummary() {
969
795
  return _getSummary.apply(this, arguments);
@@ -977,18 +803,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
977
803
  }, {
978
804
  key: "getProtocol",
979
805
  value: (function () {
980
- var _getProtocol = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(protocolId) {
981
- return _regeneratorRuntime().wrap(function _callee16$(_context17) {
982
- while (1) switch (_context17.prev = _context17.next) {
806
+ var _getProtocol = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(protocolId) {
807
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
808
+ while (1) switch (_context14.prev = _context14.next) {
983
809
  case 0:
984
- return _context17.abrupt("return", this.store.summary.getProtocol(protocolId));
810
+ return _context14.abrupt("return", this.store.summary.getProtocol(protocolId));
985
811
  case 1:
986
812
  case "end":
987
- return _context17.stop();
813
+ return _context14.stop();
988
814
  }
989
- }, _callee16, this);
815
+ }, _callee14, this);
990
816
  }));
991
- function getProtocol(_x14) {
817
+ function getProtocol(_x13) {
992
818
  return _getProtocol.apply(this, arguments);
993
819
  }
994
820
  return getProtocol;
@@ -997,16 +823,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
997
823
  }, {
998
824
  key: "getProducts",
999
825
  value: function () {
1000
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1001
- return _regeneratorRuntime().wrap(function _callee17$(_context18) {
1002
- while (1) switch (_context18.prev = _context18.next) {
826
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
827
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
828
+ while (1) switch (_context15.prev = _context15.next) {
1003
829
  case 0:
1004
- return _context18.abrupt("return", this.store.products.getProducts());
830
+ return _context15.abrupt("return", this.store.products.getProducts());
1005
831
  case 1:
1006
832
  case "end":
1007
- return _context18.stop();
833
+ return _context15.stop();
1008
834
  }
1009
- }, _callee17, this);
835
+ }, _callee15, this);
1010
836
  }));
1011
837
  function getProducts() {
1012
838
  return _getProducts.apply(this, arguments);
@@ -1016,15 +842,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1016
842
  }, {
1017
843
  key: "setLoginAccount",
1018
844
  value: function () {
1019
- var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(accountId, accountInfo) {
845
+ var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(accountId, accountInfo) {
1020
846
  var _this5 = this;
1021
847
  var account, stateAccountId, cartItems, _this$store$date$getD2, date, normalProductCartItem;
1022
- return _regeneratorRuntime().wrap(function _callee18$(_context19) {
1023
- while (1) switch (_context19.prev = _context19.next) {
848
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
849
+ while (1) switch (_context16.prev = _context16.next) {
1024
850
  case 0:
1025
851
  account = this.store.accountList.getAccount(accountId);
1026
852
  if (!account) {
1027
- _context19.next = 11;
853
+ _context16.next = 11;
1028
854
  break;
1029
855
  }
1030
856
  stateAccountId = account.getId();
@@ -1053,17 +879,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1053
879
  }
1054
880
  this.updateQuotationPriceAndCart(date);
1055
881
  }
1056
- _context19.next = 12;
882
+ _context16.next = 12;
1057
883
  break;
1058
884
  case 11:
1059
885
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
1060
886
  case 12:
1061
887
  case "end":
1062
- return _context19.stop();
888
+ return _context16.stop();
1063
889
  }
1064
- }, _callee18, this);
890
+ }, _callee16, this);
1065
891
  }));
1066
- function setLoginAccount(_x15, _x16) {
892
+ function setLoginAccount(_x14, _x15) {
1067
893
  return _setLoginAccount.apply(this, arguments);
1068
894
  }
1069
895
  return setLoginAccount;
@@ -1071,14 +897,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1071
897
  }, {
1072
898
  key: "generateCartData",
1073
899
  value: function () {
1074
- var _generateCartData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1075
- return _regeneratorRuntime().wrap(function _callee19$(_context20) {
1076
- while (1) switch (_context20.prev = _context20.next) {
900
+ var _generateCartData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
901
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
902
+ while (1) switch (_context17.prev = _context17.next) {
1077
903
  case 0:
1078
904
  case "end":
1079
- return _context20.stop();
905
+ return _context17.stop();
1080
906
  }
1081
- }, _callee19);
907
+ }, _callee17);
1082
908
  }));
1083
909
  function generateCartData() {
1084
910
  return _generateCartData.apply(this, arguments);
@@ -1088,23 +914,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1088
914
  }, {
1089
915
  key: "getFreeProduct",
1090
916
  value: function () {
1091
- var _getFreeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(id) {
917
+ var _getFreeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(id) {
1092
918
  var res;
1093
- return _regeneratorRuntime().wrap(function _callee20$(_context21) {
1094
- while (1) switch (_context21.prev = _context21.next) {
919
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
920
+ while (1) switch (_context18.prev = _context18.next) {
1095
921
  case 0:
1096
- _context21.next = 2;
922
+ _context18.next = 2;
1097
923
  return this.request.post("/pay/order/free-pay/".concat(id));
1098
924
  case 2:
1099
- res = _context21.sent;
1100
- return _context21.abrupt("return", res);
925
+ res = _context18.sent;
926
+ return _context18.abrupt("return", res);
1101
927
  case 4:
1102
928
  case "end":
1103
- return _context21.stop();
929
+ return _context18.stop();
1104
930
  }
1105
- }, _callee20, this);
931
+ }, _callee18, this);
1106
932
  }));
1107
- function getFreeProduct(_x17) {
933
+ function getFreeProduct(_x16) {
1108
934
  return _getFreeProduct.apply(this, arguments);
1109
935
  }
1110
936
  return getFreeProduct;
@@ -1127,16 +953,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1127
953
  }, {
1128
954
  key: "submitOrder",
1129
955
  value: function () {
1130
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
956
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1131
957
  var cartItems, newCartItems, type;
1132
- return _regeneratorRuntime().wrap(function _callee21$(_context22) {
1133
- while (1) switch (_context22.prev = _context22.next) {
958
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
959
+ while (1) switch (_context19.prev = _context19.next) {
1134
960
  case 0:
1135
961
  cartItems = this.store.cart.getItems();
1136
962
  newCartItems = cloneDeep(cartItems); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
1137
963
  newCartItems.forEach(function (item) {
1138
964
  if (item._origin.resources && item._origin.resources.length) {
1139
- var _item$_productOrigin, _item$_origin;
965
+ var _item$_origin;
1140
966
  item._origin.resources = item._origin.resources.map(function (n) {
1141
967
  var newResourcesItem = cloneDeep(n);
1142
968
  delete newResourcesItem.id;
@@ -1144,13 +970,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1144
970
  delete newResourcesItem.resourceType;
1145
971
  return _objectSpread({}, newResourcesItem);
1146
972
  });
1147
- var formatCapacity = formatDefaultCapacitys({
1148
- capacity: (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.capacity,
1149
- product_bundle: item._origin.product.product_bundle
1150
- });
1151
- var currentCapacity = getSumCapacity({
1152
- capacity: formatCapacity
1153
- });
973
+ var _getCapacityInfoByCar = getCapacityInfoByCartItem(item),
974
+ currentCapacity = _getCapacityInfoByCar.currentCapacity,
975
+ formatCapacity = _getCapacityInfoByCar.formatCapacity;
1154
976
  if (!((_item$_origin = item._origin) !== null && _item$_origin !== void 0 && _item$_origin.metadata)) {
1155
977
  item._origin.metadata = {};
1156
978
  }
@@ -1164,7 +986,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1164
986
  }))) {
1165
987
  type = 'virtual';
1166
988
  }
1167
- return _context22.abrupt("return", this.store.order.submitOrder({
989
+ return _context19.abrupt("return", this.store.order.submitOrder({
1168
990
  query: {
1169
991
  cartItems: newCartItems,
1170
992
  type: type
@@ -1172,9 +994,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1172
994
  }));
1173
995
  case 6:
1174
996
  case "end":
1175
- return _context22.stop();
997
+ return _context19.stop();
1176
998
  }
1177
- }, _callee21, this);
999
+ }, _callee19, this);
1178
1000
  }));
1179
1001
  function submitOrder() {
1180
1002
  return _submitOrder.apply(this, arguments);
@@ -1184,14 +1006,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1184
1006
  }, {
1185
1007
  key: "pay",
1186
1008
  value: function () {
1187
- var _pay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1188
- return _regeneratorRuntime().wrap(function _callee22$(_context23) {
1189
- while (1) switch (_context23.prev = _context23.next) {
1009
+ var _pay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1010
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1011
+ while (1) switch (_context20.prev = _context20.next) {
1190
1012
  case 0:
1191
1013
  case "end":
1192
- return _context23.stop();
1014
+ return _context20.stop();
1193
1015
  }
1194
- }, _callee22);
1016
+ }, _callee20);
1195
1017
  }));
1196
1018
  function pay() {
1197
1019
  return _pay.apply(this, arguments);
@@ -1201,14 +1023,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1201
1023
  }, {
1202
1024
  key: "getPayInfo",
1203
1025
  value: function () {
1204
- var _getPayInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1205
- return _regeneratorRuntime().wrap(function _callee23$(_context24) {
1206
- while (1) switch (_context24.prev = _context24.next) {
1026
+ var _getPayInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1027
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1028
+ while (1) switch (_context21.prev = _context21.next) {
1207
1029
  case 0:
1208
1030
  case "end":
1209
- return _context24.stop();
1031
+ return _context21.stop();
1210
1032
  }
1211
- }, _callee23);
1033
+ }, _callee21);
1212
1034
  }));
1213
1035
  function getPayInfo() {
1214
1036
  return _getPayInfo.apply(this, arguments);
@@ -1218,15 +1040,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1218
1040
  }, {
1219
1041
  key: "setOtherParams",
1220
1042
  value: function () {
1221
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
1222
- var _ref6,
1223
- _ref6$cover,
1043
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
1044
+ var _ref5,
1045
+ _ref5$cover,
1224
1046
  cover,
1225
- _args25 = arguments;
1226
- return _regeneratorRuntime().wrap(function _callee24$(_context25) {
1227
- while (1) switch (_context25.prev = _context25.next) {
1047
+ _args22 = arguments;
1048
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1049
+ while (1) switch (_context22.prev = _context22.next) {
1228
1050
  case 0:
1229
- _ref6 = _args25.length > 1 && _args25[1] !== undefined ? _args25[1] : {}, _ref6$cover = _ref6.cover, cover = _ref6$cover === void 0 ? false : _ref6$cover;
1051
+ _ref5 = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
1230
1052
  if (cover) {
1231
1053
  this.otherParams = params;
1232
1054
  } else {
@@ -1234,11 +1056,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1234
1056
  }
1235
1057
  case 2:
1236
1058
  case "end":
1237
- return _context25.stop();
1059
+ return _context22.stop();
1238
1060
  }
1239
- }, _callee24, this);
1061
+ }, _callee22, this);
1240
1062
  }));
1241
- function setOtherParams(_x18) {
1063
+ function setOtherParams(_x17) {
1242
1064
  return _setOtherParams.apply(this, arguments);
1243
1065
  }
1244
1066
  return setOtherParams;
@@ -1246,51 +1068,193 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1246
1068
  }, {
1247
1069
  key: "getOtherParams",
1248
1070
  value: function () {
1249
- var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1250
- return _regeneratorRuntime().wrap(function _callee25$(_context26) {
1251
- while (1) switch (_context26.prev = _context26.next) {
1071
+ var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1072
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1073
+ while (1) switch (_context23.prev = _context23.next) {
1252
1074
  case 0:
1253
- return _context26.abrupt("return", this.otherParams);
1075
+ return _context23.abrupt("return", this.otherParams);
1254
1076
  case 1:
1255
1077
  case "end":
1256
- return _context26.stop();
1078
+ return _context23.stop();
1257
1079
  }
1258
- }, _callee25, this);
1080
+ }, _callee23, this);
1259
1081
  }));
1260
1082
  function getOtherParams() {
1261
1083
  return _getOtherParams.apply(this, arguments);
1262
1084
  }
1263
1085
  return getOtherParams;
1264
- }() // 更新购物车
1086
+ }()
1087
+ /**
1088
+ * 往购物车加商品数据(duration 类、普通商品)
1089
+ * 老接口,先不删,怕 UI 有问题,直接桥接到新接口addProductToCart上
1090
+ *
1091
+ * @param {ProductData} productData
1092
+ * @memberof BookingByStepImpl
1093
+ */
1265
1094
  }, {
1266
- key: "updateCart",
1267
- value: function updateCart(params) {
1268
- var _this6 = this;
1269
- var targetCartItem = this.store.cart.getItem(params._id);
1270
- if (!targetCartItem) {
1271
- throw new Error("\u6CA1\u6709\u627E\u5230".concat(params._id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1095
+ key: "storeProduct",
1096
+ value: (function () {
1097
+ var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(productData) {
1098
+ var activeAccount;
1099
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1100
+ while (1) switch (_context24.prev = _context24.next) {
1101
+ case 0:
1102
+ // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
1103
+ activeAccount = this.getActiveAccount(); // 直接调用 addProductToCart,不传递 date 参数以避免日期检查逻辑
1104
+ this.addProductToCart({
1105
+ product: productData,
1106
+ account: activeAccount
1107
+ });
1108
+ case 2:
1109
+ case "end":
1110
+ return _context24.stop();
1111
+ }
1112
+ }, _callee24, this);
1113
+ }));
1114
+ function storeProduct(_x18) {
1115
+ return _storeProduct.apply(this, arguments);
1272
1116
  }
1273
- var currentResourcesCapacityMap = {};
1274
- if (params.resources) {
1275
- var _targetCartItem$_prod;
1276
- var formatCapacity = formatDefaultCapacitys({
1277
- capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
1278
- product_bundle: targetCartItem._origin.product.product_bundle
1117
+ return storeProduct;
1118
+ }()
1119
+ /**
1120
+ * 往购物车加商品数据
1121
+ *
1122
+ * @param {({
1123
+ * product: ProductData;
1124
+ * date?: { startTime: string; endTime: string } | null;
1125
+ * account?: Account | null;
1126
+ * })} {
1127
+ * product,
1128
+ * date,
1129
+ * account,
1130
+ * }
1131
+ * @return {*}
1132
+ * @memberof BookingByStepImpl
1133
+ */
1134
+ )
1135
+ }, {
1136
+ key: "addProductToCart",
1137
+ value: function addProductToCart(_ref6) {
1138
+ var product = _ref6.product,
1139
+ date = _ref6.date,
1140
+ account = _ref6.account;
1141
+ var _ref7 = product || {},
1142
+ bundle = _ref7.bundle,
1143
+ options = _ref7.options,
1144
+ origin = _ref7.origin,
1145
+ product_variant_id = _ref7.product_variant_id,
1146
+ rowKey = _ref7.rowKey,
1147
+ _ref7$quantity = _ref7.quantity,
1148
+ quantity = _ref7$quantity === void 0 ? 1 : _ref7$quantity;
1149
+ var productData = _objectSpread(_objectSpread({}, origin), {}, {
1150
+ product_variant_id: product_variant_id
1151
+ });
1152
+ if (!account) {
1153
+ var activeAccount = this.getActiveAccount();
1154
+ if (activeAccount) {
1155
+ account = activeAccount;
1156
+ }
1157
+ }
1158
+ var flag = this.store.cart.mergeCartItemByRowKey({
1159
+ rowKey: rowKey,
1160
+ quantity: quantity,
1161
+ account: account || undefined
1162
+ });
1163
+ if (flag) {
1164
+ return;
1165
+ }
1166
+ var addItemParams = {
1167
+ product: productData,
1168
+ bundle: bundle,
1169
+ options: options,
1170
+ quantity: quantity
1171
+ };
1172
+ if (date) {
1173
+ addItemParams.date = date;
1174
+ }
1175
+ if (account) {
1176
+ addItemParams.account = account;
1177
+ }
1178
+ this.addProductCheck({
1179
+ date: date
1180
+ });
1181
+ this.store.cart.addItem(addItemParams);
1182
+ }
1183
+
1184
+ /**
1185
+ * 添加完购物车以后做的一些检测,比如日期是否在同一天
1186
+ *
1187
+ * @param {({ date?: { startTime: string; endTime: string } | null })} { date }
1188
+ * @memberof BookingByStepImpl
1189
+ */
1190
+ }, {
1191
+ key: "addProductCheck",
1192
+ value: function addProductCheck(_ref8) {
1193
+ var _this6 = this;
1194
+ var date = _ref8.date;
1195
+ // 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
1196
+ if (date) {
1197
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1198
+ return !isNormalProduct(n._productOrigin);
1279
1199
  });
1280
- var currentCapacity = getSumCapacity({
1281
- capacity: formatCapacity
1200
+ var cartItemsByDate = cartItems.filter(function (n) {
1201
+ return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
1282
1202
  });
1203
+ if (cartItemsByDate.length) {
1204
+ cartItemsByDate.forEach(function (n) {
1205
+ _this6.store.cart.removeItem(n._id);
1206
+ });
1207
+ }
1208
+ }
1209
+ }
1210
+ }, {
1211
+ key: "beforeUpdateCart",
1212
+ value: function beforeUpdateCart(params, targetCartItem) {
1213
+ if (params.resources) {
1214
+ var _getCapacityInfoByCar2 = getCapacityInfoByCartItem(targetCartItem),
1215
+ currentCapacity = _getCapacityInfoByCar2.currentCapacity;
1283
1216
  params.resources = params.resources.map(function (n) {
1284
1217
  n.capacity = currentCapacity || 1;
1285
- currentResourcesCapacityMap[n.id] = currentCapacity;
1286
1218
  checkSubResourcesCapacity(n);
1287
1219
  return n;
1288
1220
  });
1289
1221
  }
1222
+ }
1223
+
1224
+ // 更新购物车
1225
+ }, {
1226
+ key: "updateCart",
1227
+ value: function updateCart(params) {
1228
+ var targetCartItem = this.store.cart.getItem(params._id);
1229
+ if (!targetCartItem) {
1230
+ throw new Error("\u6CA1\u6709\u627E\u5230".concat(params._id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1231
+ }
1232
+ this.beforeUpdateCart(params, targetCartItem);
1290
1233
  this.store.cart.updateItem(params);
1234
+ this.updateCartCheck(params, targetCartItem);
1235
+ }
1236
+
1237
+ /**
1238
+ * 更新购物车以后的一些操作,比如检测资源是否重复,检测资源容量是否足够
1239
+ *
1240
+ * @param {IUpdateItemParams} params
1241
+ * @param {CartItem} targetCartItem
1242
+ * @return {*}
1243
+ * @memberof BookingByStepImpl
1244
+ */
1245
+ }, {
1246
+ key: "updateCartCheck",
1247
+ value: function updateCartCheck(params, targetCartItem) {
1248
+ var _params$resources,
1249
+ _this7 = this;
1250
+ // 零售模板不需要检测
1291
1251
  if (this.otherParams.isRetailTemplate) {
1292
1252
  return;
1293
1253
  }
1254
+ var currentResourcesCapacityMap = {};
1255
+ (_params$resources = params.resources) === null || _params$resources === void 0 || _params$resources.forEach(function (n) {
1256
+ currentResourcesCapacityMap[n.id] = n.capacity;
1257
+ });
1294
1258
  var allOriginResources = [];
1295
1259
  var dateRange = this.store.date.getDateRange();
1296
1260
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -1312,48 +1276,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1312
1276
  cartItems.forEach(function (item) {
1313
1277
  if (item._id !== targetCartItem._id) {
1314
1278
  var _item$_origin$resourc;
1279
+ var _getCapacityInfoByCar3 = getCapacityInfoByCartItem(item),
1280
+ currentCapacity = _getCapacityInfoByCar3.currentCapacity;
1315
1281
  var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1316
1282
  // 检查当前资源是否与目标资源的任何资源匹配
1317
1283
  // 目标资源,应该只取跟当前 m.form_id 相同的资源
1318
- var sameFormIdResources = targetCartItem._origin.resources.filter(function (n) {
1319
- return n.form_id === m.form_id;
1320
- });
1284
+ var sameFormIdResources = filterResourcesByFormItem(targetCartItem._origin.resources, m.form_id);
1321
1285
  if (!(sameFormIdResources !== null && sameFormIdResources !== void 0 && sameFormIdResources.length)) {
1322
1286
  return true;
1323
1287
  }
1324
1288
  return !sameFormIdResources.some(function (targetRes) {
1325
1289
  // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1326
1290
  if (targetRes.resourceType !== 'single') {
1327
- var _item$_productOrigin2;
1328
- var _formatCapacity = formatDefaultCapacitys({
1329
- capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1330
- product_bundle: item._origin.product.product_bundle
1331
- });
1332
- var _currentCapacity = getSumCapacity({
1333
- capacity: _formatCapacity
1334
- });
1335
1291
  var originResource = allOriginResources.find(function (n) {
1336
1292
  return n.id === targetRes.id;
1337
1293
  });
1338
- if (currentResourcesCapacityMap[m.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1339
- return true;
1340
- }
1341
- currentResourcesCapacityMap[m.id] += _currentCapacity;
1342
- return false;
1294
+ var canUse = checkResourceCanUseByCapacity(currentResourcesCapacityMap[m.id] || 0, currentCapacity, originResource === null || originResource === void 0 ? void 0 : originResource.capacity);
1295
+ if (canUse) currentResourcesCapacityMap[m.id] += currentCapacity;
1296
+ return !canUse;
1343
1297
  }
1344
1298
  if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1345
- var _targetRes$metadata$c, _m$metadata$combined_;
1346
- // 检查主资源ID是否匹配
1347
- if (targetRes.id === m.id) return true;
1348
- // 检查组合资源的情况
1349
- if (((_targetRes$metadata$c = targetRes.metadata.combined_resource) === null || _targetRes$metadata$c === void 0 ? void 0 : _targetRes$metadata$c.status) === 1 && (
1350
- // 如果现在选择的是组合资源,需要判断
1351
- // 1、当前其他购物车里是否选了当前组合资源的子资源
1352
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
1353
- targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some(function (n) {
1354
- return m.metadata.combined_resource.resource_ids.includes(n);
1355
- }))) return true;
1356
- if (((_m$metadata$combined_ = m.metadata.combined_resource) === null || _m$metadata$combined_ === void 0 ? void 0 : _m$metadata$combined_.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id)) return true;
1299
+ return checkTwoResourcesIntersection(targetRes, m);
1357
1300
  }
1358
1301
  return false;
1359
1302
  });
@@ -1364,7 +1307,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1364
1307
  var end_time = item.end_time;
1365
1308
  var start_date = item.start_date;
1366
1309
  var end_date = item.end_date;
1367
- _this6.store.cart.updateItem({
1310
+ _this7.store.cart.updateItem({
1368
1311
  _id: item._id,
1369
1312
  resources: resources,
1370
1313
  date: {
@@ -1373,7 +1316,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1373
1316
  }
1374
1317
  });
1375
1318
  } else {
1376
- _this6.store.cart.updateItem({
1319
+ _this7.store.cart.updateItem({
1377
1320
  _id: item._id,
1378
1321
  resources: resources
1379
1322
  });
@@ -1410,10 +1353,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1410
1353
  }, {
1411
1354
  key: "batchUpdateCart",
1412
1355
  value: function batchUpdateCart(paramsList) {
1413
- var _this7 = this;
1356
+ var _this8 = this;
1414
1357
  var cartItems = [];
1415
1358
  paramsList.forEach(function (params) {
1416
- var cartItem = _this7.store.cart.formatCartItem(params);
1359
+ var cartItem = _this8.store.cart.formatCartItem(params);
1417
1360
  cartItems.push(cartItem);
1418
1361
  });
1419
1362
  this.store.cart.batchSetItems(cartItems);
@@ -1441,172 +1384,39 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1441
1384
  }, {
1442
1385
  key: "checkCartItems",
1443
1386
  value: function checkCartItems(type) {
1444
- var _this8 = this;
1445
- // 预约流程中普通商品无需检测这些东西
1446
- var cartItems = this.store.cart.getItems().filter(function (n) {
1447
- return !isNormalProduct(n._productOrigin);
1448
- });
1449
- var errorCartItemIds = [];
1450
- cartItems.forEach(function (cartItem) {
1451
- var result = _this8.store.cart.checkCartItemByType(cartItem, type);
1452
- if (!result) {
1453
- errorCartItemIds.push(cartItem._id);
1454
- }
1455
- });
1456
- return errorCartItemIds;
1457
- }
1458
- }, {
1459
- key: "destroy",
1460
- value: function destroy() {
1461
- var _this$store$cart, _this$store$step, _this$store$products, _this$store$guests, _this$store$date, _this$store$accountLi;
1462
- (_this$store$cart = this.store.cart) === null || _this$store$cart === void 0 || _this$store$cart.destroy();
1463
- (_this$store$step = this.store.step) === null || _this$store$step === void 0 || _this$store$step.destroy();
1464
- (_this$store$products = this.store.products) === null || _this$store$products === void 0 || _this$store$products.destroy();
1465
- (_this$store$guests = this.store.guests) === null || _this$store$guests === void 0 || _this$store$guests.destroy();
1466
- (_this$store$date = this.store.date) === null || _this$store$date === void 0 || _this$store$date.destroy();
1467
- (_this$store$accountLi = this.store.accountList) === null || _this$store$accountLi === void 0 || _this$store$accountLi.destroy();
1468
- this.core.effects.offByModuleDestroy(this.name);
1469
- this.core.unregisterModule(this);
1470
- }
1471
-
1472
- // 获取当前购物车内所有关联的资源列表,拼装数据格式
1473
- }, {
1474
- key: "getResourcesList",
1475
- value: function getResourcesList() {
1476
- var _this9 = this;
1477
- var dateRange = this.store.date.getDateRange();
1478
- var resources = [];
1479
- if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
1480
- dateRange.forEach(function (n) {
1481
- if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1482
- });
1483
- }
1484
- // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1485
- if (!resources.length) {
1486
- var dateList = this.store.date.getDateList();
1487
- dateList.forEach(function (n) {
1488
- if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1489
- });
1490
- }
1491
- var resourcesMap = getResourcesMap(cloneDeep(resources));
1492
- var cartItems = this.store.cart.getItems().filter(function (n) {
1493
- return !isNormalProduct(n._productOrigin);
1494
- });
1495
- var arr = [];
1496
- cartItems.forEach(function (cartItem) {
1497
- var _cartItem$_productOri, _cartItem$_productOri2;
1498
- var selectedResources = [];
1499
- var formatCapacity = formatDefaultCapacitys({
1500
- capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
1501
- product_bundle: cartItem._origin.product.product_bundle
1502
- });
1503
- cartItem._origin.metadata.capacity = formatCapacity;
1504
- var currentCapacity = getSumCapacity({
1505
- capacity: formatCapacity
1506
- });
1507
- if (cartItem.holder_id) {
1508
- selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1509
- } else {
1510
- selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1511
- }
1512
- var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri2 = cartItem._productOrigin) === null || _cartItem$_productOri2 === void 0 || (_cartItem$_productOri2 = _cartItem$_productOri2.product_resource) === null || _cartItem$_productOri2 === void 0 ? void 0 : _cartItem$_productOri2.resources) || [], selectedResources, currentCapacity);
1513
- // 如果购物车里已经有了时间片,则需要按照时间片过滤
1514
- if (cartItem._origin.start_time) {
1515
- var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
1516
- var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
1517
- var resourcesUseableMap = {};
1518
- productResources.forEach(function (n) {
1519
- // 资源排下序,把单个资源靠前,组合资源排在后面
1520
- n.renderList = n.renderList.sort(function (a, b) {
1521
- var _a$metadata, _b$metadata;
1522
- var aIsCombined = ((_a$metadata = a.metadata) === null || _a$metadata === void 0 || (_a$metadata = _a$metadata.combined_resource) === null || _a$metadata === void 0 ? void 0 : _a$metadata.status) === 1;
1523
- var bIsCombined = ((_b$metadata = b.metadata) === null || _b$metadata === void 0 || (_b$metadata = _b$metadata.combined_resource) === null || _b$metadata === void 0 ? void 0 : _b$metadata.status) === 1;
1524
- if (aIsCombined && !bIsCombined) return 1;
1525
- if (!aIsCombined && bIsCombined) return -1;
1526
- return 0;
1527
- });
1528
- n.renderList = n.renderList.filter(function (m) {
1529
- // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1530
- // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1531
- // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1532
- var mTimes = m.times.filter(function (n) {
1533
- return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
1534
- });
1535
- // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1536
- if (mTimes.length === 0) {
1537
- return false;
1538
- }
1539
- var canUseArr = mTimes.map(function (item) {
1540
- var _cartItem$_productOri3;
1541
- var res = getIsUsableByTimeItem({
1542
- timeSlice: {
1543
- start_time: startTime.format('HH:mm'),
1544
- end_time: endTime.format('HH:mm'),
1545
- start_at: startTime,
1546
- end_at: endTime
1547
- },
1548
- time: item,
1549
- resource: m,
1550
- currentCount: currentCapacity || 0,
1551
- resourcesUseableMap: resourcesUseableMap,
1552
- cut_off_time: (_cartItem$_productOri3 = cartItem._productOrigin) === null || _cartItem$_productOri3 === void 0 ? void 0 : _cartItem$_productOri3.cut_off_time
1553
- });
1554
- // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1555
- if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1556
- resourcesUseableMap[m.id] = res.usable;
1557
- }
1558
- return res.usable;
1559
- });
1560
- if (m.onlyComputed) return false;
1561
- // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1562
- return !canUseArr.some(function (n) {
1563
- return n === false;
1564
- });
1565
- });
1566
- });
1567
- } else {
1568
- var _cartItem$_productOri4, _this9$shopStore$get;
1569
- var hasFlexibleDuration = ((_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 || (_cartItem$_productOri4 = _cartItem$_productOri4.duration) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.type) === 'flexible';
1570
- var operating_day_boundary = (_this9$shopStore$get = _this9.shopStore.get('core')) === null || _this9$shopStore$get === void 0 || (_this9$shopStore$get = _this9$shopStore$get.core) === null || _this9$shopStore$get === void 0 ? void 0 : _this9$shopStore$get.operating_day_boundary;
1571
- productResources.forEach(function (item) {
1572
- // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1573
- // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1574
- item.renderList = item.renderList.filter(function (n) {
1575
- var _cartItem$_productOri5, _cartItem$_productOri6;
1576
- var recordCount = n.capacity || 0;
1577
- if (n.onlyComputed) return false;
1578
- // 查一下这个资源基于商品的可用时间片
1579
- var timeSlots = getTimeSlicesByResource({
1580
- resource: n,
1581
- duration: ((_cartItem$_productOri5 = cartItem._productOrigin) === null || _cartItem$_productOri5 === void 0 || (_cartItem$_productOri5 = _cartItem$_productOri5.duration) === null || _cartItem$_productOri5 === void 0 ? void 0 : _cartItem$_productOri5.value) || 10,
1582
- split: 10,
1583
- currentDate: dateRange[0].date,
1584
- hasFlexibleDuration: hasFlexibleDuration,
1585
- cut_off_time: (_cartItem$_productOri6 = cartItem._productOrigin) === null || _cartItem$_productOri6 === void 0 ? void 0 : _cartItem$_productOri6.cut_off_time,
1586
- operating_day_boundary: operating_day_boundary
1587
- });
1588
- return recordCount >= currentCapacity && timeSlots.length > 0;
1589
- });
1590
- });
1387
+ var _this9 = this;
1388
+ // 预约流程中普通商品无需检测这些东西
1389
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1390
+ return !isNormalProduct(n._productOrigin);
1391
+ });
1392
+ var errorCartItemIds = [];
1393
+ cartItems.forEach(function (cartItem) {
1394
+ var result = _this9.store.cart.checkCartItemByType(cartItem, type);
1395
+ if (!result) {
1396
+ errorCartItemIds.push(cartItem._id);
1591
1397
  }
1592
- arr.push({
1593
- id: cartItem.id,
1594
- // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1595
- _id: cartItem._id,
1596
- // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1597
- product: cartItem._productOrigin,
1598
- resources: productResources,
1599
- holder_id: cartItem.holder_id,
1600
- holder_name: cartItem.holder_title
1601
- });
1602
1398
  });
1603
- return arr;
1399
+ return errorCartItemIds;
1400
+ }
1401
+ }, {
1402
+ key: "destroy",
1403
+ value: function destroy() {
1404
+ var _this$store$cart, _this$store$step, _this$store$products, _this$store$guests, _this$store$date, _this$store$accountLi;
1405
+ (_this$store$cart = this.store.cart) === null || _this$store$cart === void 0 || _this$store$cart.destroy();
1406
+ (_this$store$step = this.store.step) === null || _this$store$step === void 0 || _this$store$step.destroy();
1407
+ (_this$store$products = this.store.products) === null || _this$store$products === void 0 || _this$store$products.destroy();
1408
+ (_this$store$guests = this.store.guests) === null || _this$store$guests === void 0 || _this$store$guests.destroy();
1409
+ (_this$store$date = this.store.date) === null || _this$store$date === void 0 || _this$store$date.destroy();
1410
+ (_this$store$accountLi = this.store.accountList) === null || _this$store$accountLi === void 0 || _this$store$accountLi.destroy();
1411
+ this.core.effects.offByModuleDestroy(this.name);
1412
+ this.core.unregisterModule(this);
1604
1413
  }
1605
1414
 
1606
- // 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
1415
+ // 获取当前购物车内所有关联的资源列表,拼装数据格式
1607
1416
  }, {
1608
- key: "checkResourceListForDate",
1609
- value: function checkResourceListForDate() {
1417
+ key: "getResourcesList",
1418
+ value: function getResourcesList() {
1419
+ var _this10 = this;
1610
1420
  var dateRange = this.store.date.getDateRange();
1611
1421
  var resources = [];
1612
1422
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -1614,35 +1424,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1614
1424
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1615
1425
  });
1616
1426
  }
1427
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1428
+ return !isNormalProduct(n._productOrigin);
1429
+ });
1430
+
1617
1431
  // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1618
1432
  if (!resources.length) {
1619
- var dateList = this.store.date.getDateList();
1620
- dateList.forEach(function (n) {
1621
- if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1433
+ // 如果此时购物车里已经有了开始时间,则直接取那天的数据即可
1434
+ var firstDateCartItem = cartItems === null || cartItems === void 0 ? void 0 : cartItems.find(function (n) {
1435
+ return n.start_date;
1622
1436
  });
1437
+ if (firstDateCartItem !== null && firstDateCartItem !== void 0 && firstDateCartItem.start_date) {
1438
+ var dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
1439
+ resources.push.apply(resources, _toConsumableArray(dateResources || []));
1440
+ } else {
1441
+ var dateList = this.store.date.getDateList();
1442
+ dateList.forEach(function (n) {
1443
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1444
+ });
1445
+ }
1623
1446
  }
1624
1447
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1625
- var cartItems = this.store.cart.getItems().filter(function (n) {
1626
- return !isNormalProduct(n._productOrigin);
1627
- });
1628
1448
  var arr = [];
1629
1449
  cartItems.forEach(function (cartItem) {
1630
- var _cartItem$_productOri7, _cartItem$_productOri8;
1450
+ var _cartItem$_productOri;
1631
1451
  var selectedResources = [];
1632
- var formatCapacity = formatDefaultCapacitys({
1633
- capacity: (_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.capacity,
1634
- product_bundle: cartItem._origin.product.product_bundle
1635
- });
1452
+ var _getCapacityInfoByCar4 = getCapacityInfoByCartItem(cartItem),
1453
+ currentCapacity = _getCapacityInfoByCar4.currentCapacity,
1454
+ formatCapacity = _getCapacityInfoByCar4.formatCapacity;
1636
1455
  cartItem._origin.metadata.capacity = formatCapacity;
1637
- var currentCapacity = getSumCapacity({
1638
- capacity: formatCapacity
1639
- });
1640
1456
  if (cartItem.holder_id) {
1641
1457
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1642
1458
  } else {
1643
1459
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1644
1460
  }
1645
- var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri8 = cartItem._productOrigin) === null || _cartItem$_productOri8 === void 0 || (_cartItem$_productOri8 = _cartItem$_productOri8.product_resource) === null || _cartItem$_productOri8 === void 0 ? void 0 : _cartItem$_productOri8.resources) || [], selectedResources, currentCapacity);
1461
+ // TODO:下面这一坨要放到 resources 模块去
1462
+ var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.product_resource) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.resources) || [], selectedResources, currentCapacity);
1646
1463
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1647
1464
  if (cartItem._origin.start_time) {
1648
1465
  var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
@@ -1650,27 +1467,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1650
1467
  var resourcesUseableMap = {};
1651
1468
  productResources.forEach(function (n) {
1652
1469
  // 资源排下序,把单个资源靠前,组合资源排在后面
1653
- n.renderList = n.renderList.sort(function (a, b) {
1654
- var _a$metadata2, _b$metadata2;
1655
- var aIsCombined = ((_a$metadata2 = a.metadata) === null || _a$metadata2 === void 0 || (_a$metadata2 = _a$metadata2.combined_resource) === null || _a$metadata2 === void 0 ? void 0 : _a$metadata2.status) === 1;
1656
- var bIsCombined = ((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 || (_b$metadata2 = _b$metadata2.combined_resource) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.status) === 1;
1657
- if (aIsCombined && !bIsCombined) return 1;
1658
- if (!aIsCombined && bIsCombined) return -1;
1659
- return 0;
1660
- });
1470
+ n.renderList = sortCombinedResources(n.renderList);
1661
1471
  n.renderList = n.renderList.filter(function (m) {
1662
1472
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1663
1473
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1664
1474
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1665
- var mTimes = m.times.filter(function (n) {
1666
- return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
1667
- });
1475
+ var mTimes = filterConditionTimeSlots(m.times, startTime, endTime);
1668
1476
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1669
1477
  if (mTimes.length === 0) {
1670
1478
  return false;
1671
1479
  }
1672
1480
  var canUseArr = mTimes.map(function (item) {
1673
- var _cartItem$_productOri9;
1481
+ var _cartItem$_productOri2;
1674
1482
  var res = getIsUsableByTimeItem({
1675
1483
  timeSlice: {
1676
1484
  start_time: startTime.format('HH:mm'),
@@ -1682,9 +1490,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1682
1490
  resource: m,
1683
1491
  currentCount: currentCapacity || 0,
1684
1492
  resourcesUseableMap: resourcesUseableMap,
1685
- cut_off_time: (_cartItem$_productOri9 = cartItem._productOrigin) === null || _cartItem$_productOri9 === void 0 ? void 0 : _cartItem$_productOri9.cut_off_time
1493
+ cut_off_time: (_cartItem$_productOri2 = cartItem._productOrigin) === null || _cartItem$_productOri2 === void 0 ? void 0 : _cartItem$_productOri2.cut_off_time
1686
1494
  });
1687
- // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1495
+ // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况(因为组合资源还需要判断子资源够不够)
1688
1496
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1689
1497
  resourcesUseableMap[m.id] = res.usable;
1690
1498
  }
@@ -1698,19 +1506,25 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1698
1506
  });
1699
1507
  });
1700
1508
  } else {
1509
+ var _cartItem$_productOri3, _this10$shopStore$get;
1510
+ var hasFlexibleDuration = ((_cartItem$_productOri3 = cartItem._productOrigin) === null || _cartItem$_productOri3 === void 0 || (_cartItem$_productOri3 = _cartItem$_productOri3.duration) === null || _cartItem$_productOri3 === void 0 ? void 0 : _cartItem$_productOri3.type) === 'flexible';
1511
+ var operating_day_boundary = (_this10$shopStore$get = _this10.shopStore.get('core')) === null || _this10$shopStore$get === void 0 || (_this10$shopStore$get = _this10$shopStore$get.core) === null || _this10$shopStore$get === void 0 ? void 0 : _this10$shopStore$get.operating_day_boundary;
1701
1512
  productResources.forEach(function (item) {
1702
1513
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1703
1514
  // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1704
1515
  item.renderList = item.renderList.filter(function (n) {
1705
- var _cartItem$_productOri10;
1516
+ var _cartItem$_productOri4, _cartItem$_productOri5;
1706
1517
  var recordCount = n.capacity || 0;
1707
1518
  if (n.onlyComputed) return false;
1708
1519
  // 查一下这个资源基于商品的可用时间片
1709
1520
  var timeSlots = getTimeSlicesByResource({
1710
1521
  resource: n,
1711
- duration: ((_cartItem$_productOri10 = cartItem._productOrigin) === null || _cartItem$_productOri10 === void 0 || (_cartItem$_productOri10 = _cartItem$_productOri10.duration) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.value) || 10,
1522
+ duration: ((_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 || (_cartItem$_productOri4 = _cartItem$_productOri4.duration) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.value) || 10,
1712
1523
  split: 10,
1713
- currentDate: dateRange[0].date
1524
+ currentDate: dateRange[0].date,
1525
+ hasFlexibleDuration: hasFlexibleDuration,
1526
+ cut_off_time: (_cartItem$_productOri5 = cartItem._productOrigin) === null || _cartItem$_productOri5 === void 0 ? void 0 : _cartItem$_productOri5.cut_off_time,
1527
+ operating_day_boundary: operating_day_boundary
1714
1528
  });
1715
1529
  return recordCount >= currentCapacity && timeSlots.length > 0;
1716
1530
  });
@@ -1721,23 +1535,46 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1721
1535
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1722
1536
  _id: cartItem._id,
1723
1537
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1724
- productResources: productResources
1538
+ product: cartItem._productOrigin,
1539
+ resources: productResources,
1540
+ holder_id: cartItem.holder_id,
1541
+ holder_name: cartItem.holder_title
1725
1542
  });
1726
1543
  });
1727
- // 检查 productResources里是不是每一项资源的 renderList 里都有数据
1728
- var hasResource = arr.every(function (n) {
1729
- return n.productResources.every(function (m) {
1730
- return m.renderList.length > 0;
1544
+ return arr;
1545
+ }
1546
+
1547
+ /**
1548
+ * 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
1549
+ *
1550
+ * @return {*}
1551
+ * @memberof BookingByStepImpl
1552
+ */
1553
+ }, {
1554
+ key: "checkResourceListForDate",
1555
+ value: function checkResourceListForDate() {
1556
+ var resourcesList = this.getResourcesList();
1557
+
1558
+ // 检查每一项资源的 renderList 里是否都有数据
1559
+ var hasResource = resourcesList.every(function (item) {
1560
+ return item.resources.every(function (resource) {
1561
+ return resource.renderList.length > 0;
1731
1562
  });
1732
1563
  });
1733
1564
  return hasResource;
1734
1565
  }
1735
1566
 
1736
- // 给单个购物车里的商品获取资源列表
1567
+ /**
1568
+ * 给单个购物车里的商品获取资源列表,给 UI 用的
1569
+ *
1570
+ * @param {(string | number)} id
1571
+ * @return {*}
1572
+ * @memberof BookingByStepImpl
1573
+ */
1737
1574
  }, {
1738
1575
  key: "getResourcesListByCartItem",
1739
1576
  value: function getResourcesListByCartItem(id) {
1740
- var _targetCartItem$_prod2, _targetCartItem$_prod3;
1577
+ var _targetCartItem$_prod;
1741
1578
  var cartItems = this.store.cart.getItems().filter(function (n) {
1742
1579
  return !isNormalProduct(n._productOrigin);
1743
1580
  });
@@ -1755,19 +1592,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1755
1592
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1756
1593
  }
1757
1594
  var selectedResources = [];
1758
- var formatCapacity = formatDefaultCapacitys({
1759
- capacity: (_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.capacity,
1760
- product_bundle: targetCartItem._origin.product.product_bundle
1761
- });
1762
- var currentCapacity = getSumCapacity({
1763
- capacity: formatCapacity
1764
- });
1595
+ var _getCapacityInfoByCar5 = getCapacityInfoByCartItem(targetCartItem),
1596
+ currentCapacity = _getCapacityInfoByCar5.currentCapacity;
1765
1597
  if (targetCartItem.holder_id) {
1766
1598
  selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1767
1599
  } else {
1768
1600
  selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1769
1601
  }
1770
- var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod3 = targetCartItem._productOrigin) === null || _targetCartItem$_prod3 === void 0 || (_targetCartItem$_prod3 = _targetCartItem$_prod3.product_resource) === null || _targetCartItem$_prod3 === void 0 ? void 0 : _targetCartItem$_prod3.resources) || [], selectedResources, currentCapacity);
1602
+ var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 || (_targetCartItem$_prod = _targetCartItem$_prod.product_resource) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.resources) || [], selectedResources, currentCapacity);
1771
1603
  productResources.forEach(function (item) {
1772
1604
  item.renderList = item.renderList.filter(function (n) {
1773
1605
  var recordCount = n.capacity || 0;
@@ -1789,36 +1621,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1789
1621
  }
1790
1622
  }
1791
1623
 
1792
- // 通过资源列表和指定的资源 id,获取指定资源的时间切片
1793
- }, {
1794
- key: "getResourceTimeSlot",
1795
- value: function getResourceTimeSlot(_ref7) {
1796
- var product = _ref7.product,
1797
- resources = _ref7.resources,
1798
- currentResourceId = _ref7.currentResourceId;
1799
- var dateRange = this.store.date.getDateRange();
1800
- var timeSlots = getTimeSlicesByResource({
1801
- resource: resources.find(function (n) {
1802
- return n.id === currentResourceId;
1803
- }),
1804
- duration: product.duration.value,
1805
- split: 10,
1806
- currentDate: dateRange[0].date
1807
- });
1808
- return timeSlots;
1809
- }
1810
-
1811
1624
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
1812
1625
  }, {
1813
1626
  key: "autoSelectAccountResources",
1814
- value: function autoSelectAccountResources(_ref8) {
1815
- var _cartItem$_productOri11, _allProductResources$;
1816
- var cartItem = _ref8.cartItem,
1817
- holder_id = _ref8.holder_id,
1818
- resources_code = _ref8.resources_code,
1819
- timeSlots = _ref8.timeSlots,
1820
- countMap = _ref8.countMap,
1821
- capacity = _ref8.capacity;
1627
+ value: function autoSelectAccountResources(_ref9) {
1628
+ var _cartItem$_productOri6, _allProductResources$;
1629
+ var cartItem = _ref9.cartItem,
1630
+ holder_id = _ref9.holder_id,
1631
+ resources_code = _ref9.resources_code,
1632
+ timeSlots = _ref9.timeSlots,
1633
+ countMap = _ref9.countMap,
1634
+ capacity = _ref9.capacity;
1822
1635
  if (isNormalProduct(cartItem._productOrigin)) {
1823
1636
  return {};
1824
1637
  }
@@ -1832,10 +1645,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1832
1645
  if (!accountCartItems.length) {
1833
1646
  accountCartItems = cartItems;
1834
1647
  }
1835
- // duration=所有商品时间的集合
1648
+ // duration=所有商品时间的集合,如果是灵活时长,当做占用 10 分钟处理
1836
1649
  var duration = accountCartItems.reduce(function (acc, n) {
1837
- var _n$_productOrigin2;
1838
- return acc + (((_n$_productOrigin2 = n._productOrigin) === null || _n$_productOrigin2 === void 0 || (_n$_productOrigin2 = _n$_productOrigin2.duration) === null || _n$_productOrigin2 === void 0 ? void 0 : _n$_productOrigin2.value) || 10);
1650
+ var _n$_productOrigin;
1651
+ return acc + (((_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 || (_n$_productOrigin = _n$_productOrigin.duration) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.value) || 10);
1839
1652
  }, 0);
1840
1653
  var AllResources = [];
1841
1654
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -1845,23 +1658,31 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1845
1658
  }
1846
1659
  // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1847
1660
  if (!AllResources.length) {
1848
- var dateList = this.store.date.getDateList();
1849
- dateList.forEach(function (n) {
1850
- if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
1661
+ var firstDateCartItem = cartItems === null || cartItems === void 0 ? void 0 : cartItems.find(function (n) {
1662
+ return n.start_date;
1851
1663
  });
1664
+ if (firstDateCartItem !== null && firstDateCartItem !== void 0 && firstDateCartItem.start_date) {
1665
+ var dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
1666
+ AllResources.push.apply(AllResources, _toConsumableArray(dateResources || []));
1667
+ } else {
1668
+ var dateList = this.store.date.getDateList();
1669
+ dateList.forEach(function (n) {
1670
+ if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
1671
+ });
1672
+ }
1852
1673
  }
1853
1674
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1854
1675
  var allCartItems = cloneDeep(this.store.cart.getItems());
1855
1676
  var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1856
- var allProductResources = 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, 1);
1677
+ var allProductResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri6 = cartItem._productOrigin) === null || _cartItem$_productOri6 === void 0 || (_cartItem$_productOri6 = _cartItem$_productOri6.product_resource) === null || _cartItem$_productOri6 === void 0 ? void 0 : _cartItem$_productOri6.resources) || [], selectedResources, 1);
1857
1678
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1858
1679
  return n.code === resources_code;
1859
1680
  })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
1860
1681
  // 资源排下序,把单个资源靠前,组合资源排在后面
1861
1682
  resources.sort(function (a, b) {
1862
- var _a$metadata3, _b$metadata3;
1863
- var aIsCombined = ((_a$metadata3 = a.metadata) === null || _a$metadata3 === void 0 || (_a$metadata3 = _a$metadata3.combined_resource) === null || _a$metadata3 === void 0 ? void 0 : _a$metadata3.status) === 1;
1864
- var bIsCombined = ((_b$metadata3 = b.metadata) === null || _b$metadata3 === void 0 || (_b$metadata3 = _b$metadata3.combined_resource) === null || _b$metadata3 === void 0 ? void 0 : _b$metadata3.status) === 1;
1683
+ var _a$metadata, _b$metadata;
1684
+ var aIsCombined = ((_a$metadata = a.metadata) === null || _a$metadata === void 0 || (_a$metadata = _a$metadata.combined_resource) === null || _a$metadata === void 0 ? void 0 : _a$metadata.status) === 1;
1685
+ var bIsCombined = ((_b$metadata = b.metadata) === null || _b$metadata === void 0 || (_b$metadata = _b$metadata.combined_resource) === null || _b$metadata === void 0 ? void 0 : _b$metadata.status) === 1;
1865
1686
  if (aIsCombined && !bIsCombined) return 1;
1866
1687
  if (!aIsCombined && bIsCombined) return -1;
1867
1688
  return 0;
@@ -1882,11 +1703,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1882
1703
  // 根据 start_time 和 end_time 去匹配资源
1883
1704
  var targetResource = null;
1884
1705
  var targetResourceTime = 0;
1885
- var _iterator3 = _createForOfIteratorHelper(resources),
1886
- _step3;
1706
+ var _iterator2 = _createForOfIteratorHelper(resources),
1707
+ _step2;
1887
1708
  try {
1888
- var _loop2 = function _loop2() {
1889
- var n = _step3.value;
1709
+ var _loop = function _loop() {
1710
+ var n = _step2.value;
1890
1711
  // 如果资源是独占的,并且 countMap 里选择过这个资源,则直接跳过
1891
1712
  // if (n.resourceType === 'single' && countMap[n.id]) {
1892
1713
  // resourcesUseableMap[n.id] = false;
@@ -1914,14 +1735,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1914
1735
  return 0; // continue
1915
1736
  }
1916
1737
  var canUseTime = mTimes.find(function (item) {
1917
- var _cartItem$_productOri12;
1738
+ var _cartItem$_productOri7;
1918
1739
  var res = getIsUsableByTimeItem({
1919
1740
  timeSlice: timeSlots,
1920
1741
  time: item,
1921
1742
  resource: n,
1922
1743
  currentCount: totalCapacity + (capacity || 0),
1923
1744
  resourcesUseableMap: resourcesUseableMap,
1924
- cut_off_time: (_cartItem$_productOri12 = cartItem._productOrigin) === null || _cartItem$_productOri12 === void 0 ? void 0 : _cartItem$_productOri12.cut_off_time
1745
+ cut_off_time: (_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.cut_off_time
1925
1746
  });
1926
1747
  // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1927
1748
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
@@ -1941,15 +1762,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1941
1762
  }
1942
1763
  },
1943
1764
  _ret;
1944
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1945
- _ret = _loop2();
1765
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1766
+ _ret = _loop();
1946
1767
  if (_ret === 0) continue;
1947
1768
  if (_ret === 1) break;
1948
1769
  }
1949
1770
  } catch (err) {
1950
- _iterator3.e(err);
1771
+ _iterator2.e(err);
1951
1772
  } finally {
1952
- _iterator3.f();
1773
+ _iterator2.f();
1953
1774
  }
1954
1775
  return {
1955
1776
  selectedResource: targetResource
@@ -1984,7 +1805,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1984
1805
  key: "autoSelectAllProductResources",
1985
1806
  value: function autoSelectAllProductResources(resources_code, timeSlots) {
1986
1807
  var _dateRange$4,
1987
- _this10 = this;
1808
+ _this11 = this;
1988
1809
  var dateRange = this.store.date.getDateRange();
1989
1810
  var resources = [];
1990
1811
  if (dateRange !== null && dateRange !== void 0 && (_dateRange$4 = dateRange[0]) !== null && _dateRange$4 !== void 0 && _dateRange$4.date) {
@@ -1992,10 +1813,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1992
1813
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1993
1814
  });
1994
1815
  }
1995
- // const resourcesMap = getResourcesMap(cloneDeep(resources));
1996
1816
  // 一个账号一个账号处理
1997
1817
  var errorList = [];
1818
+ // 资源使用情况-单个预约
1998
1819
  var selectResourcesMap = {};
1820
+ // 资源使用情况-多个预约
1999
1821
  var selectResourcesWithTimeSlots = {};
2000
1822
  var accountList = this.store.accountList.getAccounts();
2001
1823
  var selectForCartResources = function selectForCartResources(cartItems) {
@@ -2005,18 +1827,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2005
1827
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
2006
1828
  // 判断购物车里是否有 flexible 类型的商品,如果有则不累加时间
2007
1829
  var hasFlexibleProduct = cartItems.some(function (item) {
2008
- var _item$_productOrigin3;
2009
- return ((_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 || (_item$_productOrigin3 = _item$_productOrigin3.duration) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.type) === 'flexible';
1830
+ var _item$_productOrigin;
1831
+ return ((_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 || (_item$_productOrigin = _item$_productOrigin.duration) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.type) === 'flexible';
2010
1832
  });
2011
1833
  cartItems.forEach(function (item, index) {
2012
- var _item$_productOrigin4;
2013
- var formatCapacity = formatDefaultCapacitys({
2014
- capacity: (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.capacity,
2015
- product_bundle: item._origin.product.product_bundle
2016
- });
2017
- var currentCapacity = getSumCapacity({
2018
- capacity: formatCapacity
2019
- });
1834
+ var _getCapacityInfoByCar6 = getCapacityInfoByCartItem(item),
1835
+ currentCapacity = _getCapacityInfoByCar6.currentCapacity;
2020
1836
  // 如果商品已经有时间数据了,意味着是通过先选日期再选商品流程进来的,相当于时间切片已经选中了
2021
1837
  if (item._origin.start_time && !(timeSlots !== null && timeSlots !== void 0 && timeSlots.start_time)) {
2022
1838
  recordTimeSlots = {
@@ -2027,17 +1843,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2027
1843
  };
2028
1844
  }
2029
1845
  if (recordTimeSlots) {
2030
- var _item$_productOrigin5, _item$_productOrigin6;
1846
+ var _item$_productOrigin2, _item$_productOrigin3;
2031
1847
  // 同一账号下,如果当前商品不是第一个,则需要根据上一个商品的 end_time 和 duration 计算出当前商品的 start_time 和 end_time
2032
1848
  // 前提:当前资源是单个预约才需要这么做
2033
- var currentResourceConfig = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.product_resource) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.resources) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.find(function (n) {
1849
+ var currentResourceConfig = (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.product_resource) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.resources) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.find(function (n) {
2034
1850
  return n.code === resources_code;
2035
1851
  });
2036
- // 只有 duration 类商品需要这个操作
2037
- if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single' && (_item$_productOrigin6 = item._productOrigin) !== null && _item$_productOrigin6 !== void 0 && _item$_productOrigin6.duration && !hasFlexibleProduct) {
2038
- var _item$_productOrigin7, _item$_productOrigin8;
2039
- var start_at = dayjs(recordTimeSlots.end_time).add(((_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.value) || 10, 'minutes');
2040
- var end_at = start_at.add(((_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.duration) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.value) || 10, 'minutes');
1852
+ // 只有 duration 类商品且不含有灵活时间的商品需要这个操作
1853
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single' && (_item$_productOrigin3 = item._productOrigin) !== null && _item$_productOrigin3 !== void 0 && _item$_productOrigin3.duration && !hasFlexibleProduct) {
1854
+ var _item$_productOrigin4, _item$_productOrigin5;
1855
+ var start_at = dayjs(recordTimeSlots.end_time).add(((_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) || 10, 'minutes');
1856
+ var end_at = start_at.add(((_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.value) || 10, 'minutes');
2041
1857
  recordTimeSlots = {
2042
1858
  start_time: start_at.format('HH:mm'),
2043
1859
  end_time: end_at.format('HH:mm'),
@@ -2046,7 +1862,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2046
1862
  };
2047
1863
  }
2048
1864
  // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
2049
- var res = _this10.autoSelectAccountResources({
1865
+ var res = _this11.autoSelectAccountResources({
2050
1866
  cartItem: item,
2051
1867
  holder_id: item.holder_id,
2052
1868
  resources_code: resources_code,
@@ -2054,10 +1870,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2054
1870
  countMap: selectResourcesWithTimeSlots,
2055
1871
  capacity: currentCapacity
2056
1872
  });
2057
- // // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
2058
- // if (item._origin.resources?.some((n: any) => n.form_id === res?.selectedResource?.form_id)) {
2059
- // return
2060
- // }
2061
1873
  if (res !== null && res !== void 0 && res.selectedResource) {
2062
1874
  if (!selectResourcesWithTimeSlots[res.selectedResource.id]) {
2063
1875
  selectResourcesWithTimeSlots[res.selectedResource.id] = [{
@@ -2072,7 +1884,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2072
1884
  }
2073
1885
  res.selectedResource.capacity = currentCapacity;
2074
1886
  checkSubResourcesCapacity(res.selectedResource);
2075
- _this10.store.cart.updateItem({
1887
+ _this11.store.cart.updateItem({
2076
1888
  _id: item._id,
2077
1889
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
2078
1890
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
@@ -2085,12 +1897,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2085
1897
  errorList.push(item._id);
2086
1898
  }
2087
1899
  } else {
2088
- var _item$_productOrigin9, _productResources$fin;
1900
+ var _item$_productOrigin6, _productResources$fin;
2089
1901
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
2090
- var allCartItems = cloneDeep(_this10.store.cart.getItems());
1902
+ // 能进到这种逻辑,说明是 duration 类商品或者灵活时长商品,且是第一种资源,还没有确定时间
1903
+ var allCartItems = cloneDeep(_this11.store.cart.getItems());
2091
1904
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
2092
1905
  var selectedResources = [];
2093
- var _resources = cloneDeep(((_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.product_resource) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.resources) || []);
1906
+ var _resources = cloneDeep(((_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.product_resource) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.resources) || []);
2094
1907
  var currentResourcesRenderList = [];
2095
1908
  _resources.forEach(function (n) {
2096
1909
  var _n$renderList;
@@ -2151,7 +1964,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2151
1964
  } else {
2152
1965
  selectResourcesMap[targetResource.id] += currentCapacity;
2153
1966
  }
2154
- _this10.store.cart.updateItem({
1967
+ _this11.store.cart.updateItem({
2155
1968
  _id: item._id,
2156
1969
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
2157
1970
  return existingRes.resourceType !== targetRenderList[0].resourceType;
@@ -2171,7 +1984,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2171
1984
  // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
2172
1985
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2173
1986
  accountList.forEach(function (account) {
2174
- var cartItems = _this10.store.cart.getCartByAccount(account.getId());
1987
+ var cartItems = _this11.store.cart.getCartByAccount(account.getId());
2175
1988
  selectForCartResources(cartItems);
2176
1989
  });
2177
1990
  } else {
@@ -2186,7 +1999,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2186
1999
  key: "getTimeSlotByAllResources",
2187
2000
  value: function getTimeSlotByAllResources(resources_code) {
2188
2001
  var _dateRange,
2189
- _this11 = this,
2002
+ _this12 = this,
2190
2003
  _cartItems$,
2191
2004
  _cartItems$2,
2192
2005
  _this$shopStore$get;
@@ -2205,8 +2018,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2205
2018
  var maxCutOffTime = undefined;
2206
2019
  var maxCutOffTimeValue = dayjs();
2207
2020
  cartItems.forEach(function (item) {
2208
- var _item$_productOrigin10, _item$_productOrigin11, _item$_productOrigin12, _item$_productOrigin13;
2209
- (_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.product_resource) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.resources) === null || _item$_productOrigin10 === void 0 || _item$_productOrigin10.forEach(function (n) {
2021
+ var _item$_productOrigin7, _item$_productOrigin8, _item$_productOrigin9, _item$_productOrigin10;
2022
+ (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.product_resource) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.resources) === null || _item$_productOrigin7 === void 0 || _item$_productOrigin7.forEach(function (n) {
2210
2023
  // TODO: 少了个 status 的判断
2211
2024
  if (n.code === resources_code) {
2212
2025
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
@@ -2219,10 +2032,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2219
2032
  if (item.resource_id) {
2220
2033
  resourceIds.push(item.resource_id);
2221
2034
  }
2222
- resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.product_resource) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.resources) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.find(function (n) {
2035
+ resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.resources) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.find(function (n) {
2223
2036
  return n.code === resources_code;
2224
- })) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.id;
2225
- if ((_item$_productOrigin12 = item._productOrigin) !== null && _item$_productOrigin12 !== void 0 && _item$_productOrigin12.cut_off_time && ((_item$_productOrigin13 = item._productOrigin) === null || _item$_productOrigin13 === void 0 ? void 0 : _item$_productOrigin13.cut_off_time.type) === 'advance') {
2037
+ })) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.id;
2038
+ if ((_item$_productOrigin9 = item._productOrigin) !== null && _item$_productOrigin9 !== void 0 && _item$_productOrigin9.cut_off_time && ((_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.cut_off_time.type) === 'advance') {
2226
2039
  var currentCutOffTime = dayjs().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
2227
2040
  if (currentCutOffTime.isAfter(maxCutOffTimeValue, 'minute')) {
2228
2041
  maxCutOffTimeValue = currentCutOffTime;
@@ -2250,13 +2063,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2250
2063
  cartItems.forEach(function (item) {
2251
2064
  // 单个预约累加账号 多个预约取最大值
2252
2065
  if (isSingleResource) {
2253
- var _item$_productOrigin14;
2254
- accountDuration += ((_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 || (_item$_productOrigin14 = _item$_productOrigin14.duration) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.value) || 10;
2066
+ var _item$_productOrigin11;
2067
+ accountDuration += ((_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.duration) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.value) || 10;
2255
2068
  } else {
2256
- var _item$_productOrigin15;
2257
- if (accountDuration < (((_item$_productOrigin15 = item._productOrigin) === null || _item$_productOrigin15 === void 0 || (_item$_productOrigin15 = _item$_productOrigin15.duration) === null || _item$_productOrigin15 === void 0 ? void 0 : _item$_productOrigin15.value) || 10)) {
2258
- var _item$_productOrigin16;
2259
- accountDuration = ((_item$_productOrigin16 = item._productOrigin) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.duration) === null || _item$_productOrigin16 === void 0 ? void 0 : _item$_productOrigin16.value) || 10;
2069
+ var _item$_productOrigin12;
2070
+ if (accountDuration < (((_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.duration) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.value) || 10)) {
2071
+ var _item$_productOrigin13;
2072
+ accountDuration = ((_item$_productOrigin13 = item._productOrigin) === null || _item$_productOrigin13 === void 0 || (_item$_productOrigin13 = _item$_productOrigin13.duration) === null || _item$_productOrigin13 === void 0 ? void 0 : _item$_productOrigin13.value) || 10;
2260
2073
  }
2261
2074
  }
2262
2075
  });
@@ -2266,7 +2079,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2266
2079
  };
2267
2080
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2268
2081
  accountList.forEach(function (account) {
2269
- var cartItems = _this11.store.cart.getCartByAccount(account.getId());
2082
+ var cartItems = _this12.store.cart.getCartByAccount(account.getId());
2270
2083
  checkDuration(cartItems);
2271
2084
  });
2272
2085
  } else {
@@ -2293,8 +2106,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2293
2106
  }
2294
2107
  var resourcesUseableMap = {};
2295
2108
  var hasFlexibleDuration = cartItems.some(function (item) {
2296
- var _item$_productOrigin17;
2297
- return ((_item$_productOrigin17 = item._productOrigin) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.duration) === null || _item$_productOrigin17 === void 0 ? void 0 : _item$_productOrigin17.type) === 'flexible';
2109
+ var _item$_productOrigin14;
2110
+ return ((_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 || (_item$_productOrigin14 = _item$_productOrigin14.duration) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.type) === 'flexible';
2298
2111
  });
2299
2112
  var operating_day_boundary = (_this$shopStore$get = this.shopStore.get('core')) === null || _this$shopStore$get === void 0 || (_this$shopStore$get = _this$shopStore$get.core) === null || _this$shopStore$get === void 0 ? void 0 : _this$shopStore$get.operating_day_boundary;
2300
2113
  var timeSlots = getTimeSlicesByResources({
@@ -2316,7 +2129,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2316
2129
  key: "submitTimeSlot",
2317
2130
  value: function submitTimeSlot(timeSlots) {
2318
2131
  var _this$shopStore$get2,
2319
- _this12 = this;
2132
+ _this13 = this;
2320
2133
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
2321
2134
  var cartItems = this.store.cart.getItems().filter(function (n) {
2322
2135
  return !isNormalProduct(n._productOrigin);
@@ -2345,9 +2158,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2345
2158
  var _newResources$;
2346
2159
  var newResources = cloneDeep(item._origin.resources);
2347
2160
  newResources.forEach(function (resource) {
2348
- var _item$_productOrigin18;
2161
+ var _item$_productOrigin15;
2349
2162
  // 如果商品配置的是灵活时长,开始时间设置为提交的时间,结束时间从资源的可用最晚时间和店铺营业结束时间里取一个最早的
2350
- if (((_item$_productOrigin18 = item._productOrigin) === null || _item$_productOrigin18 === void 0 || (_item$_productOrigin18 = _item$_productOrigin18.duration) === null || _item$_productOrigin18 === void 0 ? void 0 : _item$_productOrigin18.type) === 'flexible') {
2163
+ if (((_item$_productOrigin15 = item._productOrigin) === null || _item$_productOrigin15 === void 0 || (_item$_productOrigin15 = _item$_productOrigin15.duration) === null || _item$_productOrigin15 === void 0 ? void 0 : _item$_productOrigin15.type) === 'flexible') {
2351
2164
  var _allResources$find;
2352
2165
  item.duration = {
2353
2166
  type: 'minutes',
@@ -2364,7 +2177,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2364
2177
 
2365
2178
  // 将 operating_day_boundary 转换为与 resourcesEndTime.end_at 相同日期的完整日期时间
2366
2179
  var resourceDate = dayjs(resourcesEndTime.end_at).format('YYYY-MM-DD');
2367
- var operatingBoundaryDateTime = "".concat(resourceDate, " ").concat(operating_day_boundary.type === 'start_time' ? "23:59" : operating_day_boundary.time);
2180
+ var operatingBoundaryDateTime = "".concat(resourceDate, " ").concat(operating_day_boundary.type === 'start_time' ? '23:59' : operating_day_boundary.time);
2368
2181
  var endTime = dayjs(resourcesEndTime.end_at).isBefore(dayjs(operatingBoundaryDateTime)) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
2369
2182
  // 修复:如果 endTime 只是时间格式(如 "17:00"),需要加上日期
2370
2183
  var formattedEndTime;
@@ -2377,13 +2190,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2377
2190
  }
2378
2191
  resource.endTime = formattedEndTime.format('YYYY-MM-DD HH:mm');
2379
2192
  } else {
2380
- var _item$_productOrigin19;
2193
+ var _item$_productOrigin16;
2381
2194
  resource.startTime = currentStartTime;
2382
- resource.endTime = dayjs(currentStartTime).add(((_item$_productOrigin19 = item._productOrigin) === null || _item$_productOrigin19 === void 0 || (_item$_productOrigin19 = _item$_productOrigin19.duration) === null || _item$_productOrigin19 === void 0 ? void 0 : _item$_productOrigin19.value) || 10, 'minutes').format('YYYY-MM-DD HH:mm');
2195
+ resource.endTime = dayjs(currentStartTime).add(((_item$_productOrigin16 = item._productOrigin) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.duration) === null || _item$_productOrigin16 === void 0 ? void 0 : _item$_productOrigin16.value) || 10, 'minutes').format('YYYY-MM-DD HH:mm');
2383
2196
  }
2384
2197
  // delete resource.times;
2385
2198
  });
2386
- _this12.store.cart.updateItem({
2199
+ _this13.store.cart.updateItem({
2387
2200
  _id: item._id,
2388
2201
  resources: newResources
2389
2202
  });
@@ -2431,26 +2244,59 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2431
2244
  }, {
2432
2245
  key: "openProductDetail",
2433
2246
  value: function () {
2434
- var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(productId) {
2435
- var targetProduct, targetProductData, newScheduleArr;
2436
- return _regeneratorRuntime().wrap(function _callee26$(_context27) {
2437
- while (1) switch (_context27.prev = _context27.next) {
2247
+ var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(productId) {
2248
+ var targetProduct, targetProductData, newScheduleArr, dateRange;
2249
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2250
+ while (1) switch (_context25.prev = _context25.next) {
2438
2251
  case 0:
2439
- _context27.next = 2;
2252
+ _context25.next = 2;
2440
2253
  return this.store.products.getProduct(productId);
2441
2254
  case 2:
2442
- targetProduct = _context27.sent;
2443
- if (targetProduct) {
2444
- targetProductData = targetProduct.getData();
2445
- this.store.currentProduct = targetProduct;
2446
- newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
2447
- targetProduct.setOtherParams('schedule', newScheduleArr);
2255
+ targetProduct = _context25.sent;
2256
+ if (!targetProduct) {
2257
+ _context25.next = 16;
2258
+ break;
2448
2259
  }
2449
- case 4:
2260
+ targetProductData = targetProduct.getData();
2261
+ this.store.currentProduct = targetProduct;
2262
+ // 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
2263
+ if (!targetProductData['schedule.ids']) {
2264
+ _context25.next = 11;
2265
+ break;
2266
+ }
2267
+ newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
2268
+ targetProduct.setOtherParams('schedule', newScheduleArr);
2269
+ _context25.next = 16;
2270
+ break;
2271
+ case 11:
2272
+ if (!targetProductData.duration) {
2273
+ _context25.next = 16;
2274
+ break;
2275
+ }
2276
+ dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
2277
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
2278
+ _context25.next = 15;
2279
+ break;
2280
+ }
2281
+ return _context25.abrupt("return");
2282
+ case 15:
2283
+ // this.store.date.getResourceDates({
2284
+ // query: {
2285
+ // start_date: dateRange[0].date,
2286
+ // end_date: dateRange[dateRange.length - 1].date,
2287
+ // resource_ids: targetProductData.product_resource?.resources?.map((n: any) => n.id),
2288
+ // },
2289
+ // });
2290
+ this.getAvailableDate({
2291
+ startDate: dateRange[0].date,
2292
+ endDate: dateRange[dateRange.length - 1].date,
2293
+ products: [targetProductData]
2294
+ });
2295
+ case 16:
2450
2296
  case "end":
2451
- return _context27.stop();
2297
+ return _context25.stop();
2452
2298
  }
2453
- }, _callee26, this);
2299
+ }, _callee25, this);
2454
2300
  }));
2455
2301
  function openProductDetail(_x19) {
2456
2302
  return _openProductDetail.apply(this, arguments);
@@ -2466,12 +2312,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2466
2312
  }
2467
2313
  }, {
2468
2314
  key: "getTimeslotBySchedule",
2469
- value: function getTimeslotBySchedule(_ref9) {
2315
+ value: function getTimeslotBySchedule(_ref10) {
2470
2316
  var _this$store$currentPr2, _targetProductData$pr;
2471
- var date = _ref9.date,
2472
- scheduleIds = _ref9.scheduleIds,
2473
- resources = _ref9.resources,
2474
- product = _ref9.product;
2317
+ var date = _ref10.date,
2318
+ scheduleIds = _ref10.scheduleIds,
2319
+ resources = _ref10.resources,
2320
+ product = _ref10.product;
2475
2321
  var targetProduct = this.store.currentProduct;
2476
2322
  // 如果外面传递了product 优先用外面的
2477
2323
  var targetProductData = product || (targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
@@ -2498,9 +2344,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2498
2344
  });
2499
2345
  // 资源排下序,把单个资源靠前,组合资源排在后面
2500
2346
  allProductResources.sort(function (a, b) {
2501
- var _a$metadata4, _b$metadata4;
2502
- var aIsCombined = ((_a$metadata4 = a.metadata) === null || _a$metadata4 === void 0 || (_a$metadata4 = _a$metadata4.combined_resource) === null || _a$metadata4 === void 0 ? void 0 : _a$metadata4.status) === 1;
2503
- var bIsCombined = ((_b$metadata4 = b.metadata) === null || _b$metadata4 === void 0 || (_b$metadata4 = _b$metadata4.combined_resource) === null || _b$metadata4 === void 0 ? void 0 : _b$metadata4.status) === 1;
2347
+ var _a$metadata2, _b$metadata2;
2348
+ var aIsCombined = ((_a$metadata2 = a.metadata) === null || _a$metadata2 === void 0 || (_a$metadata2 = _a$metadata2.combined_resource) === null || _a$metadata2 === void 0 ? void 0 : _a$metadata2.status) === 1;
2349
+ var bIsCombined = ((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 || (_b$metadata2 = _b$metadata2.combined_resource) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.status) === 1;
2504
2350
  if (aIsCombined && !bIsCombined) return 1;
2505
2351
  if (!aIsCombined && bIsCombined) return -1;
2506
2352
  return 0;
@@ -2563,9 +2409,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2563
2409
  // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2564
2410
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2565
2411
  return n === false;
2566
- })
2412
+ }) &&
2567
2413
  // 只统计第一种资源的容量和 left
2568
- && m.form_id === firstEnabledResourceId) {
2414
+ m.form_id === firstEnabledResourceId) {
2569
2415
  if (currentResourcesCount >= count) {
2570
2416
  count = currentResourcesCount;
2571
2417
  }
@@ -2587,69 +2433,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2587
2433
  });
2588
2434
  return formatScheduleTimeSlots;
2589
2435
  }
2590
- }, {
2591
- key: "addProductToCart",
2592
- value: function addProductToCart(_ref10) {
2593
- var _this13 = this;
2594
- var product = _ref10.product,
2595
- date = _ref10.date,
2596
- account = _ref10.account;
2597
- var _ref11 = product || {},
2598
- bundle = _ref11.bundle,
2599
- options = _ref11.options,
2600
- origin = _ref11.origin,
2601
- product_variant_id = _ref11.product_variant_id,
2602
- rowKey = _ref11.rowKey,
2603
- _ref11$quantity = _ref11.quantity,
2604
- quantity = _ref11$quantity === void 0 ? 1 : _ref11$quantity;
2605
- var productData = _objectSpread(_objectSpread({}, origin), {}, {
2606
- product_variant_id: product_variant_id
2607
- });
2608
- if (!account) {
2609
- var activeAccount = this.getActiveAccount();
2610
- if (activeAccount) {
2611
- account = activeAccount;
2612
- }
2613
- }
2614
- if (rowKey) {
2615
- var cartItems = this.store.cart.getItems();
2616
- var targetCartItem = cartItems.find(function (n) {
2617
- var _n$_productOrigin3;
2618
- return ((_n$_productOrigin3 = n._productOrigin) === null || _n$_productOrigin3 === void 0 ? void 0 : _n$_productOrigin3.rowKey) === rowKey;
2619
- });
2620
- if (targetCartItem && isNormalProduct(targetCartItem._productOrigin)) {
2621
- this.store.cart.updateItem({
2622
- _id: targetCartItem._id,
2623
- product: _objectSpread(_objectSpread({}, targetCartItem._productOrigin), {}, {
2624
- quantity: (targetCartItem.num || 1) + quantity
2625
- })
2626
- });
2627
- return;
2628
- }
2629
- }
2630
- this.store.cart.addItem({
2631
- product: productData,
2632
- date: date,
2633
- account: account,
2634
- bundle: bundle,
2635
- options: options,
2636
- quantity: quantity
2637
- });
2638
- // 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
2639
- if (date) {
2640
- var _cartItems = this.store.cart.getItems().filter(function (n) {
2641
- return !isNormalProduct(n._productOrigin);
2642
- });
2643
- var cartItemsByDate = _cartItems.filter(function (n) {
2644
- return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
2645
- });
2646
- if (cartItemsByDate.length) {
2647
- cartItemsByDate.forEach(function (n) {
2648
- _this13.store.cart.removeItem(n._id);
2649
- });
2650
- }
2651
- }
2652
- }
2653
2436
  }, {
2654
2437
  key: "setOtherData",
2655
2438
  value: function setOtherData(key, value) {
@@ -2671,27 +2454,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2671
2454
  }, {
2672
2455
  key: "getProductTypeById",
2673
2456
  value: function () {
2674
- var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(id) {
2457
+ var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(id) {
2675
2458
  var product;
2676
- return _regeneratorRuntime().wrap(function _callee27$(_context28) {
2677
- while (1) switch (_context28.prev = _context28.next) {
2459
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2460
+ while (1) switch (_context26.prev = _context26.next) {
2678
2461
  case 0:
2679
- _context28.next = 2;
2462
+ _context26.next = 2;
2680
2463
  return this.store.products.getProduct(id);
2681
2464
  case 2:
2682
- product = _context28.sent;
2465
+ product = _context26.sent;
2683
2466
  if (!product) {
2684
- _context28.next = 5;
2467
+ _context26.next = 5;
2685
2468
  break;
2686
2469
  }
2687
- return _context28.abrupt("return", product.getProductType());
2470
+ return _context26.abrupt("return", product.getProductType());
2688
2471
  case 5:
2689
- return _context28.abrupt("return", 'normal');
2472
+ return _context26.abrupt("return", 'normal');
2690
2473
  case 6:
2691
2474
  case "end":
2692
- return _context28.stop();
2475
+ return _context26.stop();
2693
2476
  }
2694
- }, _callee27, this);
2477
+ }, _callee26, this);
2695
2478
  }));
2696
2479
  function getProductTypeById(_x20) {
2697
2480
  return _getProductTypeById.apply(this, arguments);
@@ -2709,7 +2492,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2709
2492
  }, {
2710
2493
  key: "getResourcesByCartItemAndCode",
2711
2494
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
2712
- var _cartItem$_productOri13, _cartItem$_productOri14;
2495
+ var _cartItem$_productOri8;
2713
2496
  var dateRange = this.store.date.getDateRange();
2714
2497
  var resources = [];
2715
2498
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -2732,20 +2515,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2732
2515
  });
2733
2516
  if (!cartItem) return [];
2734
2517
  var selectedResources = [];
2735
- var formatCapacity = formatDefaultCapacitys({
2736
- capacity: (_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.capacity,
2737
- product_bundle: cartItem._origin.product.product_bundle
2738
- });
2518
+ var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
2519
+ currentCapacity = _getCapacityInfoByCar7.currentCapacity,
2520
+ formatCapacity = _getCapacityInfoByCar7.formatCapacity;
2739
2521
  cartItem._origin.metadata.capacity = formatCapacity;
2740
- var currentCapacity = getSumCapacity({
2741
- capacity: formatCapacity
2742
- });
2743
2522
  if (cartItem.holder_id) {
2744
2523
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
2745
2524
  } else {
2746
2525
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
2747
2526
  }
2748
- var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 || (_cartItem$_productOri14 = _cartItem$_productOri14.product_resource) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.resources) || [], selectedResources, currentCapacity);
2527
+ var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri8 = cartItem._productOrigin) === null || _cartItem$_productOri8 === void 0 || (_cartItem$_productOri8 = _cartItem$_productOri8.product_resource) === null || _cartItem$_productOri8 === void 0 ? void 0 : _cartItem$_productOri8.resources) || [], selectedResources, currentCapacity);
2749
2528
  var targetResource = productResources.find(function (resource) {
2750
2529
  return resource.code === resourceCode;
2751
2530
  });
@@ -2755,9 +2534,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2755
2534
  var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
2756
2535
  var resourcesUseableMap = {};
2757
2536
  targetResource.renderList = targetResource.renderList.sort(function (a, b) {
2758
- var _a$metadata5, _b$metadata5;
2759
- var aIsCombined = ((_a$metadata5 = a.metadata) === null || _a$metadata5 === void 0 || (_a$metadata5 = _a$metadata5.combined_resource) === null || _a$metadata5 === void 0 ? void 0 : _a$metadata5.status) === 1;
2760
- var bIsCombined = ((_b$metadata5 = b.metadata) === null || _b$metadata5 === void 0 || (_b$metadata5 = _b$metadata5.combined_resource) === null || _b$metadata5 === void 0 ? void 0 : _b$metadata5.status) === 1;
2537
+ var _a$metadata3, _b$metadata3;
2538
+ var aIsCombined = ((_a$metadata3 = a.metadata) === null || _a$metadata3 === void 0 || (_a$metadata3 = _a$metadata3.combined_resource) === null || _a$metadata3 === void 0 ? void 0 : _a$metadata3.status) === 1;
2539
+ var bIsCombined = ((_b$metadata3 = b.metadata) === null || _b$metadata3 === void 0 || (_b$metadata3 = _b$metadata3.combined_resource) === null || _b$metadata3 === void 0 ? void 0 : _b$metadata3.status) === 1;
2761
2540
  if (aIsCombined && !bIsCombined) return 1;
2762
2541
  if (!aIsCombined && bIsCombined) return -1;
2763
2542
  return 0;
@@ -2768,7 +2547,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2768
2547
  });
2769
2548
  if (mTimes.length === 0) return false;
2770
2549
  var canUseArr = mTimes.map(function (item) {
2771
- var _cartItem$_productOri15;
2550
+ var _cartItem$_productOri9;
2772
2551
  var res = getIsUsableByTimeItem({
2773
2552
  timeSlice: {
2774
2553
  start_time: startTime.format('HH:mm'),
@@ -2780,7 +2559,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2780
2559
  resource: m,
2781
2560
  currentCount: currentCapacity || 0,
2782
2561
  resourcesUseableMap: resourcesUseableMap,
2783
- cut_off_time: (_cartItem$_productOri15 = cartItem._productOrigin) === null || _cartItem$_productOri15 === void 0 ? void 0 : _cartItem$_productOri15.cut_off_time
2562
+ cut_off_time: (_cartItem$_productOri9 = cartItem._productOrigin) === null || _cartItem$_productOri9 === void 0 ? void 0 : _cartItem$_productOri9.cut_off_time
2784
2563
  });
2785
2564
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2786
2565
  resourcesUseableMap[m.id] = res.usable;
@@ -2794,12 +2573,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2794
2573
  });
2795
2574
  } else {
2796
2575
  targetResource.renderList = targetResource.renderList.filter(function (n) {
2797
- var _cartItem$_productOri16;
2576
+ var _cartItem$_productOri10;
2798
2577
  var recordCount = n.capacity || 0;
2799
2578
  if (n.onlyComputed) return false;
2800
2579
  var timeSlots = getTimeSlicesByResource({
2801
2580
  resource: n,
2802
- duration: ((_cartItem$_productOri16 = cartItem._productOrigin) === null || _cartItem$_productOri16 === void 0 || (_cartItem$_productOri16 = _cartItem$_productOri16.duration) === null || _cartItem$_productOri16 === void 0 ? void 0 : _cartItem$_productOri16.value) || 10,
2581
+ duration: ((_cartItem$_productOri10 = cartItem._productOrigin) === null || _cartItem$_productOri10 === void 0 || (_cartItem$_productOri10 = _cartItem$_productOri10.duration) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.value) || 10,
2803
2582
  split: 10,
2804
2583
  currentDate: dateRange[0].date
2805
2584
  });
@@ -2817,12 +2596,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2817
2596
  }, {
2818
2597
  key: "getTimeslotsScheduleByDateRange",
2819
2598
  value: (function () {
2820
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(_ref12) {
2599
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(_ref11) {
2821
2600
  var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i, _dates, date;
2822
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2823
- while (1) switch (_context29.prev = _context29.next) {
2601
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2602
+ while (1) switch (_context27.prev = _context27.next) {
2824
2603
  case 0:
2825
- startDate = _ref12.startDate, endDate = _ref12.endDate, scheduleIds = _ref12.scheduleIds, resources = _ref12.resources;
2604
+ startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
2826
2605
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
2827
2606
  startDate: startDate,
2828
2607
  endDate: endDate,
@@ -2847,137 +2626,46 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2847
2626
  resources: resources
2848
2627
  });
2849
2628
  }
2850
- return _context29.abrupt("return", results);
2629
+ return _context27.abrupt("return", results);
2851
2630
  case 9:
2852
2631
  case "end":
2853
- return _context29.stop();
2632
+ return _context27.stop();
2854
2633
  }
2855
- }, _callee28, this);
2634
+ }, _callee27, this);
2856
2635
  }));
2857
2636
  function getTimeslotsScheduleByDateRange(_x21) {
2858
2637
  return _getTimeslotsScheduleByDateRange.apply(this, arguments);
2859
2638
  }
2860
2639
  return getTimeslotsScheduleByDateRange;
2861
2640
  }())
2862
- }, {
2863
- key: "getAvailableDateForSession",
2864
- value: function () {
2865
- var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2866
- var params,
2867
- startDate,
2868
- endDate,
2869
- type,
2870
- tempProducts,
2871
- _ref13,
2872
- resourceIds,
2873
- rules,
2874
- resourcesMap,
2875
- res,
2876
- dateListWithTimeSlots,
2877
- firstAvailableDate,
2878
- _args30 = arguments;
2879
- return _regeneratorRuntime().wrap(function _callee29$(_context30) {
2880
- while (1) switch (_context30.prev = _context30.next) {
2881
- case 0:
2882
- params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
2883
- // 开始日期如果小于今天,直接以今天当做开始日期
2884
- startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2885
- if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
2886
- startDate = dayjs().format('YYYY-MM-DD');
2887
- }
2888
- // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2889
- endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2890
- tempProducts = []; // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2891
- if (this.store.currentProduct) {
2892
- tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
2893
- _schedule: this.store.currentProduct.getOtherParams()['schedule']
2894
- })];
2895
- }
2896
- // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
2897
- _ref13 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref13.resourceIds, rules = _ref13.rules, resourcesMap = _ref13.resourcesMap;
2898
- this.otherParams.currentResourcesMap = resourcesMap;
2899
- _context30.next = 10;
2900
- return this.store.date.getResourceDates({
2901
- query: {
2902
- start_date: startDate || '',
2903
- end_date: endDate || '',
2904
- resource_ids: resourceIds
2905
- },
2906
- rules: rules,
2907
- type: type
2908
- });
2909
- case 10:
2910
- res = _context30.sent;
2911
- if (!this.store.currentProduct) {
2912
- _context30.next = 16;
2913
- break;
2914
- }
2915
- _context30.next = 14;
2916
- return this.getTimeslotsScheduleByDateRange({
2917
- startDate: startDate || '',
2918
- endDate: endDate || ''
2919
- });
2920
- case 14:
2921
- dateListWithTimeSlots = _context30.sent;
2922
- res.forEach(function (n) {
2923
- if (!dateListWithTimeSlots[n.date]) {
2924
- n.status = 'unavailable';
2925
- } else {
2926
- var allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(function (d) {
2927
- return d.count;
2928
- });
2929
- if (!allTimeSlotsCanUse) {
2930
- n.status = 'unavailable';
2931
- }
2932
- }
2933
- });
2934
- case 16:
2935
- // 找到第一个可用的日期返回给 UI
2936
- firstAvailableDate = res.find(function (n) {
2937
- return n.status === 'available';
2938
- });
2939
- return _context30.abrupt("return", {
2940
- dateList: res,
2941
- firstAvailableDate: firstAvailableDate
2942
- });
2943
- case 18:
2944
- case "end":
2945
- return _context30.stop();
2946
- }
2947
- }, _callee29, this);
2948
- }));
2949
- function getAvailableDateForSession() {
2950
- return _getAvailableDateForSession.apply(this, arguments);
2951
- }
2952
- return getAvailableDateForSession;
2953
- }()
2954
2641
  }, {
2955
2642
  key: "getAvailableDateForSessionOptimize",
2956
2643
  value: function () {
2957
- var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2644
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2958
2645
  var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2959
2646
  var params,
2960
2647
  startDate,
2961
2648
  endDate,
2962
2649
  endDateAfterMonth,
2650
+ tempEndDate,
2651
+ cache,
2963
2652
  tempProducts,
2964
2653
  schedule,
2965
2654
  filteredSchedule,
2966
2655
  tempResourceIds,
2967
2656
  res,
2968
- cache,
2969
2657
  dates,
2970
2658
  currentDate,
2971
2659
  firstAvailableDate,
2972
2660
  openResources,
2973
2661
  allProductResources,
2974
2662
  targetSchedules,
2975
- _loop3,
2976
- _args32 = arguments;
2977
- return _regeneratorRuntime().wrap(function _callee30$(_context32) {
2978
- while (1) switch (_context32.prev = _context32.next) {
2663
+ _loop2,
2664
+ _args29 = arguments;
2665
+ return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2666
+ while (1) switch (_context29.prev = _context29.next) {
2979
2667
  case 0:
2980
- params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
2668
+ params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
2981
2669
  // 开始日期如果小于今天,直接以今天当做开始日期
2982
2670
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2983
2671
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -2987,43 +2675,49 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2987
2675
  // 优化策略:
2988
2676
  // 在 endDate 添加完一个月以后,如果 endDate 还小于 startDate + 7 天,则还需要 endDate+7 天
2989
2677
  endDateAfterMonth = dayjs().add(1, 'month').format('YYYY-MM-DD');
2678
+ tempEndDate = endDateAfterMonth;
2990
2679
  if (dayjs(startDate).add(7, 'day').isAfter(dayjs(endDateAfterMonth), 'day')) {
2991
- endDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2680
+ tempEndDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2992
2681
  } else {
2993
- endDate = endDateAfterMonth;
2682
+ tempEndDate = endDateAfterMonth;
2994
2683
  }
2995
- // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2996
- tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2997
- schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2998
- filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2999
- tempResourceIds = getResourcesIdsByProduct(tempProducts);
3000
- _context32.next = 11;
3001
- return this.store.date.fetchResourceDates({
3002
- query: {
3003
- start_date: startDate || '',
3004
- end_date: endDate || '',
3005
- resource_ids: tempResourceIds
3006
- }
3007
- });
3008
- case 11:
3009
- res = _context32.sent;
2684
+ // 如果这么算出来的 tempEndDate 还小于 endDate,则需要把 endDate 置为 tempEndDate
2685
+ if (dayjs(tempEndDate).isBefore(dayjs(endDate), 'day')) {
2686
+ tempEndDate = endDate || '';
2687
+ }
2688
+ endDate = tempEndDate;
2689
+
3010
2690
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
3011
- // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
3012
- cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2691
+ cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
3013
2692
  if (!cache) {
3014
- _context32.next = 17;
2693
+ _context29.next = 13;
3015
2694
  break;
3016
2695
  }
3017
2696
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
3018
- _context32.next = 17;
2697
+ _context29.next = 13;
3019
2698
  break;
3020
2699
  }
3021
2700
  this.store.date.setDateList(cache.dateList);
3022
- return _context32.abrupt("return", {
2701
+ return _context29.abrupt("return", {
3023
2702
  dateList: cache.dateList,
3024
2703
  firstAvailableDate: cache.firstAvailableDate
3025
2704
  });
3026
- case 17:
2705
+ case 13:
2706
+ // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2707
+ tempProducts = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getData();
2708
+ schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
2709
+ filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2710
+ tempResourceIds = getResourcesIdsByProduct(tempProducts);
2711
+ _context29.next = 19;
2712
+ return this.store.date.fetchResourceDates({
2713
+ query: {
2714
+ start_date: startDate || '',
2715
+ end_date: endDate || '',
2716
+ resource_ids: tempResourceIds
2717
+ }
2718
+ });
2719
+ case 19:
2720
+ res = _context29.sent;
3027
2721
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
3028
2722
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
3029
2723
  dates = [];
@@ -3043,10 +2737,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3043
2737
  }
3044
2738
  });
3045
2739
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3046
- _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
2740
+ _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
3047
2741
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
3048
- return _regeneratorRuntime().wrap(function _loop3$(_context31) {
3049
- while (1) switch (_context31.prev = _context31.next) {
2742
+ return _regeneratorRuntime().wrap(function _loop2$(_context28) {
2743
+ while (1) switch (_context28.prev = _context28.next) {
3050
2744
  case 0:
3051
2745
  currentDateStr = currentDate.format('YYYY-MM-DD');
3052
2746
  status = 'available'; // 1. 检查商品的提前量等情况是否满足
@@ -3137,35 +2831,35 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3137
2831
  });
3138
2832
 
3139
2833
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
3140
- if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 14)) {
3141
- _context31.next = 9;
2834
+ if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
2835
+ _context28.next = 9;
3142
2836
  break;
3143
2837
  }
3144
- return _context31.abrupt("return", 1);
2838
+ return _context28.abrupt("return", 1);
3145
2839
  case 9:
3146
2840
  currentDate = dayjs(currentDate).add(1, 'day');
3147
2841
  case 10:
3148
2842
  case "end":
3149
- return _context31.stop();
2843
+ return _context28.stop();
3150
2844
  }
3151
- }, _loop3);
2845
+ }, _loop2);
3152
2846
  });
3153
- case 25:
2847
+ case 28:
3154
2848
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3155
- _context32.next = 31;
2849
+ _context29.next = 34;
3156
2850
  break;
3157
2851
  }
3158
- return _context32.delegateYield(_loop3(), "t0", 27);
3159
- case 27:
3160
- if (!_context32.t0) {
3161
- _context32.next = 29;
2852
+ return _context29.delegateYield(_loop2(), "t0", 30);
2853
+ case 30:
2854
+ if (!_context29.t0) {
2855
+ _context29.next = 32;
3162
2856
  break;
3163
2857
  }
3164
- return _context32.abrupt("break", 31);
3165
- case 29:
3166
- _context32.next = 25;
2858
+ return _context29.abrupt("break", 34);
2859
+ case 32:
2860
+ _context29.next = 28;
3167
2861
  break;
3168
- case 31:
2862
+ case 34:
3169
2863
  // 最终把资源数据也加到日期内
3170
2864
  dates = handleAvailableDateByResource(res.data, dates);
3171
2865
  this.store.date.setDateList(dates);
@@ -3177,15 +2871,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3177
2871
  startDate: startDate,
3178
2872
  endDate: dayjs(currentDate).format('YYYY-MM-DD')
3179
2873
  });
3180
- return _context32.abrupt("return", {
2874
+ return _context29.abrupt("return", {
3181
2875
  dateList: dates,
3182
2876
  firstAvailableDate: firstAvailableDate
3183
2877
  });
3184
- case 35:
2878
+ case 38:
3185
2879
  case "end":
3186
- return _context32.stop();
2880
+ return _context29.stop();
3187
2881
  }
3188
- }, _callee30, this);
2882
+ }, _callee28, this);
3189
2883
  }));
3190
2884
  function getAvailableDateForSessionOptimize() {
3191
2885
  return _getAvailableDateForSessionOptimize.apply(this, arguments);
@@ -3207,13 +2901,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3207
2901
  return !isNormalProduct(n._productOrigin);
3208
2902
  });
3209
2903
  return cartItems.some(function (n) {
3210
- var _n$_productOrigin4;
3211
- return (_n$_productOrigin4 = n._productOrigin) === null || _n$_productOrigin4 === void 0 ? void 0 : _n$_productOrigin4.duration;
2904
+ var _n$_productOrigin2;
2905
+ return (_n$_productOrigin2 = n._productOrigin) === null || _n$_productOrigin2 === void 0 ? void 0 : _n$_productOrigin2.duration;
3212
2906
  });
3213
2907
  }
3214
2908
  }, {
3215
2909
  key: "isTargetNormalProduct",
3216
2910
  value: function isTargetNormalProduct(product) {
2911
+ if (!product) return false;
3217
2912
  return isNormalProduct(product);
3218
2913
  }
3219
2914
  }, {