@pisell/pisellos 3.0.42 → 3.0.44

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 (53) 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/Date/index.js +70 -6
  7. package/dist/modules/Discount/index.d.ts +1 -0
  8. package/dist/modules/Discount/index.js +13 -6
  9. package/dist/modules/Discount/types.d.ts +10 -0
  10. package/dist/modules/ProductList/index.d.ts +7 -0
  11. package/dist/modules/ProductList/index.js +102 -39
  12. package/dist/modules/Rules/index.js +218 -80
  13. package/dist/modules/Rules/types.d.ts +7 -1
  14. package/dist/modules/Schedule/index.d.ts +9 -1
  15. package/dist/modules/Schedule/index.js +122 -2
  16. package/dist/modules/Schedule/types.d.ts +13 -0
  17. package/dist/solution/BookingByStep/index.d.ts +120 -30
  18. package/dist/solution/BookingByStep/index.js +755 -1078
  19. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  20. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  21. package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
  22. package/dist/solution/BookingByStep/utils/resources.js +39 -95
  23. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  24. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  25. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  26. package/dist/solution/ShopDiscount/index.js +119 -44
  27. package/lib/modules/AccountList/index.js +4 -0
  28. package/lib/modules/Cart/index.d.ts +14 -0
  29. package/lib/modules/Cart/index.js +34 -1
  30. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -0
  31. package/lib/modules/Cart/utils/cartProduct.js +20 -8
  32. package/lib/modules/Date/index.js +59 -2
  33. package/lib/modules/Discount/index.d.ts +1 -0
  34. package/lib/modules/Discount/index.js +17 -6
  35. package/lib/modules/Discount/types.d.ts +10 -0
  36. package/lib/modules/ProductList/index.d.ts +7 -0
  37. package/lib/modules/ProductList/index.js +45 -0
  38. package/lib/modules/Rules/index.js +154 -63
  39. package/lib/modules/Rules/types.d.ts +7 -1
  40. package/lib/modules/Schedule/index.d.ts +9 -1
  41. package/lib/modules/Schedule/index.js +79 -1
  42. package/lib/modules/Schedule/types.d.ts +13 -0
  43. package/lib/solution/BookingByStep/index.d.ts +120 -30
  44. package/lib/solution/BookingByStep/index.js +391 -589
  45. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  46. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  47. package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
  48. package/lib/solution/BookingByStep/utils/resources.js +21 -58
  49. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  50. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  51. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  52. package/lib/solution/ShopDiscount/index.js +91 -19
  53. 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,
@@ -875,16 +698,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
875
698
  dateRange,
876
699
  tempStartDate,
877
700
  tempEndDate,
878
- _ref5,
701
+ _ref4,
879
702
  resourceIds,
880
703
  rules,
881
704
  resourcesMap,
882
705
  res,
883
- _args15 = arguments;
884
- return _regeneratorRuntime().wrap(function _callee14$(_context15) {
885
- 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) {
886
709
  case 0:
887
- params = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
710
+ params = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
888
711
  // 开始日期如果小于今天,直接以今天当做开始日期
889
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 置为今天
890
713
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -911,15 +734,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
911
734
  tempStartDate = startDate || (dateRange === null || dateRange === void 0 || (_dateRange$ = dateRange[0]) === null || _dateRange$ === void 0 ? void 0 : _dateRange$.date);
912
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);
913
736
  if (tempProducts.length) {
914
- _context15.next = 11;
737
+ _context12.next = 11;
915
738
  break;
916
739
  }
917
- return _context15.abrupt("return", []);
740
+ return _context12.abrupt("return", []);
918
741
  case 11:
919
742
  // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
920
- _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;
921
744
  this.otherParams.currentResourcesMap = resourcesMap;
922
- _context15.next = 15;
745
+ _context12.next = 15;
923
746
  return this.store.date.getResourceDates({
924
747
  url: params.url,
925
748
  query: {
@@ -932,13 +755,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
932
755
  useCache: useCache
933
756
  });
934
757
  case 15:
935
- res = _context15.sent;
936
- return _context15.abrupt("return", res);
758
+ res = _context12.sent;
759
+ return _context12.abrupt("return", res);
937
760
  case 17:
938
761
  case "end":
939
- return _context15.stop();
762
+ return _context12.stop();
940
763
  }
941
- }, _callee14, this);
764
+ }, _callee12, this);
942
765
  }));
943
766
  function getAvailableDate() {
944
767
  return _getAvailableDate.apply(this, arguments);
@@ -951,22 +774,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
951
774
  }, {
952
775
  key: "getSummary",
953
776
  value: (function () {
954
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
777
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
955
778
  var cartItems, summary;
956
- return _regeneratorRuntime().wrap(function _callee15$(_context16) {
957
- while (1) switch (_context16.prev = _context16.next) {
779
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
780
+ while (1) switch (_context13.prev = _context13.next) {
958
781
  case 0:
959
782
  cartItems = this.store.cart.getItems();
960
- _context16.next = 3;
783
+ _context13.next = 3;
961
784
  return this.store.summary.getSummary(cartItems);
962
785
  case 3:
963
- summary = _context16.sent;
964
- return _context16.abrupt("return", summary);
786
+ summary = _context13.sent;
787
+ return _context13.abrupt("return", summary);
965
788
  case 5:
966
789
  case "end":
967
- return _context16.stop();
790
+ return _context13.stop();
968
791
  }
969
- }, _callee15, this);
792
+ }, _callee13, this);
970
793
  }));
971
794
  function getSummary() {
972
795
  return _getSummary.apply(this, arguments);
@@ -980,18 +803,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
980
803
  }, {
981
804
  key: "getProtocol",
982
805
  value: (function () {
983
- var _getProtocol = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(protocolId) {
984
- return _regeneratorRuntime().wrap(function _callee16$(_context17) {
985
- 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) {
986
809
  case 0:
987
- return _context17.abrupt("return", this.store.summary.getProtocol(protocolId));
810
+ return _context14.abrupt("return", this.store.summary.getProtocol(protocolId));
988
811
  case 1:
989
812
  case "end":
990
- return _context17.stop();
813
+ return _context14.stop();
991
814
  }
992
- }, _callee16, this);
815
+ }, _callee14, this);
993
816
  }));
994
- function getProtocol(_x14) {
817
+ function getProtocol(_x13) {
995
818
  return _getProtocol.apply(this, arguments);
996
819
  }
997
820
  return getProtocol;
@@ -1000,16 +823,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1000
823
  }, {
1001
824
  key: "getProducts",
1002
825
  value: function () {
1003
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1004
- return _regeneratorRuntime().wrap(function _callee17$(_context18) {
1005
- 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) {
1006
829
  case 0:
1007
- return _context18.abrupt("return", this.store.products.getProducts());
830
+ return _context15.abrupt("return", this.store.products.getProducts());
1008
831
  case 1:
1009
832
  case "end":
1010
- return _context18.stop();
833
+ return _context15.stop();
1011
834
  }
1012
- }, _callee17, this);
835
+ }, _callee15, this);
1013
836
  }));
1014
837
  function getProducts() {
1015
838
  return _getProducts.apply(this, arguments);
@@ -1019,15 +842,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1019
842
  }, {
1020
843
  key: "setLoginAccount",
1021
844
  value: function () {
1022
- var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(accountId, accountInfo) {
845
+ var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(accountId, accountInfo) {
1023
846
  var _this5 = this;
1024
847
  var account, stateAccountId, cartItems, _this$store$date$getD2, date, normalProductCartItem;
1025
- return _regeneratorRuntime().wrap(function _callee18$(_context19) {
1026
- while (1) switch (_context19.prev = _context19.next) {
848
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
849
+ while (1) switch (_context16.prev = _context16.next) {
1027
850
  case 0:
1028
851
  account = this.store.accountList.getAccount(accountId);
1029
852
  if (!account) {
1030
- _context19.next = 11;
853
+ _context16.next = 11;
1031
854
  break;
1032
855
  }
1033
856
  stateAccountId = account.getId();
@@ -1056,17 +879,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1056
879
  }
1057
880
  this.updateQuotationPriceAndCart(date);
1058
881
  }
1059
- _context19.next = 12;
882
+ _context16.next = 12;
1060
883
  break;
1061
884
  case 11:
1062
885
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
1063
886
  case 12:
1064
887
  case "end":
1065
- return _context19.stop();
888
+ return _context16.stop();
1066
889
  }
1067
- }, _callee18, this);
890
+ }, _callee16, this);
1068
891
  }));
1069
- function setLoginAccount(_x15, _x16) {
892
+ function setLoginAccount(_x14, _x15) {
1070
893
  return _setLoginAccount.apply(this, arguments);
1071
894
  }
1072
895
  return setLoginAccount;
@@ -1074,14 +897,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1074
897
  }, {
1075
898
  key: "generateCartData",
1076
899
  value: function () {
1077
- var _generateCartData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1078
- return _regeneratorRuntime().wrap(function _callee19$(_context20) {
1079
- 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) {
1080
903
  case 0:
1081
904
  case "end":
1082
- return _context20.stop();
905
+ return _context17.stop();
1083
906
  }
1084
- }, _callee19);
907
+ }, _callee17);
1085
908
  }));
1086
909
  function generateCartData() {
1087
910
  return _generateCartData.apply(this, arguments);
@@ -1091,23 +914,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1091
914
  }, {
1092
915
  key: "getFreeProduct",
1093
916
  value: function () {
1094
- var _getFreeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(id) {
917
+ var _getFreeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(id) {
1095
918
  var res;
1096
- return _regeneratorRuntime().wrap(function _callee20$(_context21) {
1097
- while (1) switch (_context21.prev = _context21.next) {
919
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
920
+ while (1) switch (_context18.prev = _context18.next) {
1098
921
  case 0:
1099
- _context21.next = 2;
922
+ _context18.next = 2;
1100
923
  return this.request.post("/pay/order/free-pay/".concat(id));
1101
924
  case 2:
1102
- res = _context21.sent;
1103
- return _context21.abrupt("return", res);
925
+ res = _context18.sent;
926
+ return _context18.abrupt("return", res);
1104
927
  case 4:
1105
928
  case "end":
1106
- return _context21.stop();
929
+ return _context18.stop();
1107
930
  }
1108
- }, _callee20, this);
931
+ }, _callee18, this);
1109
932
  }));
1110
- function getFreeProduct(_x17) {
933
+ function getFreeProduct(_x16) {
1111
934
  return _getFreeProduct.apply(this, arguments);
1112
935
  }
1113
936
  return getFreeProduct;
@@ -1130,16 +953,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1130
953
  }, {
1131
954
  key: "submitOrder",
1132
955
  value: function () {
1133
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
956
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1134
957
  var cartItems, newCartItems, type;
1135
- return _regeneratorRuntime().wrap(function _callee21$(_context22) {
1136
- while (1) switch (_context22.prev = _context22.next) {
958
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
959
+ while (1) switch (_context19.prev = _context19.next) {
1137
960
  case 0:
1138
961
  cartItems = this.store.cart.getItems();
1139
962
  newCartItems = cloneDeep(cartItems); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
1140
963
  newCartItems.forEach(function (item) {
1141
964
  if (item._origin.resources && item._origin.resources.length) {
1142
- var _item$_productOrigin, _item$_origin;
965
+ var _item$_origin;
1143
966
  item._origin.resources = item._origin.resources.map(function (n) {
1144
967
  var newResourcesItem = cloneDeep(n);
1145
968
  delete newResourcesItem.id;
@@ -1147,13 +970,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1147
970
  delete newResourcesItem.resourceType;
1148
971
  return _objectSpread({}, newResourcesItem);
1149
972
  });
1150
- var formatCapacity = formatDefaultCapacitys({
1151
- capacity: (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.capacity,
1152
- product_bundle: item._origin.product.product_bundle
1153
- });
1154
- var currentCapacity = getSumCapacity({
1155
- capacity: formatCapacity
1156
- });
973
+ var _getCapacityInfoByCar = getCapacityInfoByCartItem(item),
974
+ currentCapacity = _getCapacityInfoByCar.currentCapacity,
975
+ formatCapacity = _getCapacityInfoByCar.formatCapacity;
1157
976
  if (!((_item$_origin = item._origin) !== null && _item$_origin !== void 0 && _item$_origin.metadata)) {
1158
977
  item._origin.metadata = {};
1159
978
  }
@@ -1167,7 +986,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1167
986
  }))) {
1168
987
  type = 'virtual';
1169
988
  }
1170
- return _context22.abrupt("return", this.store.order.submitOrder({
989
+ return _context19.abrupt("return", this.store.order.submitOrder({
1171
990
  query: {
1172
991
  cartItems: newCartItems,
1173
992
  type: type
@@ -1175,9 +994,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1175
994
  }));
1176
995
  case 6:
1177
996
  case "end":
1178
- return _context22.stop();
997
+ return _context19.stop();
1179
998
  }
1180
- }, _callee21, this);
999
+ }, _callee19, this);
1181
1000
  }));
1182
1001
  function submitOrder() {
1183
1002
  return _submitOrder.apply(this, arguments);
@@ -1187,14 +1006,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1187
1006
  }, {
1188
1007
  key: "pay",
1189
1008
  value: function () {
1190
- var _pay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1191
- return _regeneratorRuntime().wrap(function _callee22$(_context23) {
1192
- 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) {
1193
1012
  case 0:
1194
1013
  case "end":
1195
- return _context23.stop();
1014
+ return _context20.stop();
1196
1015
  }
1197
- }, _callee22);
1016
+ }, _callee20);
1198
1017
  }));
1199
1018
  function pay() {
1200
1019
  return _pay.apply(this, arguments);
@@ -1204,14 +1023,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1204
1023
  }, {
1205
1024
  key: "getPayInfo",
1206
1025
  value: function () {
1207
- var _getPayInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1208
- return _regeneratorRuntime().wrap(function _callee23$(_context24) {
1209
- 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) {
1210
1029
  case 0:
1211
1030
  case "end":
1212
- return _context24.stop();
1031
+ return _context21.stop();
1213
1032
  }
1214
- }, _callee23);
1033
+ }, _callee21);
1215
1034
  }));
1216
1035
  function getPayInfo() {
1217
1036
  return _getPayInfo.apply(this, arguments);
@@ -1221,15 +1040,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1221
1040
  }, {
1222
1041
  key: "setOtherParams",
1223
1042
  value: function () {
1224
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
1225
- var _ref6,
1226
- _ref6$cover,
1043
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
1044
+ var _ref5,
1045
+ _ref5$cover,
1227
1046
  cover,
1228
- _args25 = arguments;
1229
- return _regeneratorRuntime().wrap(function _callee24$(_context25) {
1230
- 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) {
1231
1050
  case 0:
1232
- _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;
1233
1052
  if (cover) {
1234
1053
  this.otherParams = params;
1235
1054
  } else {
@@ -1237,11 +1056,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1237
1056
  }
1238
1057
  case 2:
1239
1058
  case "end":
1240
- return _context25.stop();
1059
+ return _context22.stop();
1241
1060
  }
1242
- }, _callee24, this);
1061
+ }, _callee22, this);
1243
1062
  }));
1244
- function setOtherParams(_x18) {
1063
+ function setOtherParams(_x17) {
1245
1064
  return _setOtherParams.apply(this, arguments);
1246
1065
  }
1247
1066
  return setOtherParams;
@@ -1249,51 +1068,193 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1249
1068
  }, {
1250
1069
  key: "getOtherParams",
1251
1070
  value: function () {
1252
- var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1253
- return _regeneratorRuntime().wrap(function _callee25$(_context26) {
1254
- 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) {
1255
1074
  case 0:
1256
- return _context26.abrupt("return", this.otherParams);
1075
+ return _context23.abrupt("return", this.otherParams);
1257
1076
  case 1:
1258
1077
  case "end":
1259
- return _context26.stop();
1078
+ return _context23.stop();
1260
1079
  }
1261
- }, _callee25, this);
1080
+ }, _callee23, this);
1262
1081
  }));
1263
1082
  function getOtherParams() {
1264
1083
  return _getOtherParams.apply(this, arguments);
1265
1084
  }
1266
1085
  return getOtherParams;
1267
- }() // 更新购物车
1086
+ }()
1087
+ /**
1088
+ * 往购物车加商品数据(duration 类、普通商品)
1089
+ * 老接口,先不删,怕 UI 有问题,直接桥接到新接口addProductToCart上
1090
+ *
1091
+ * @param {ProductData} productData
1092
+ * @memberof BookingByStepImpl
1093
+ */
1268
1094
  }, {
1269
- key: "updateCart",
1270
- value: function updateCart(params) {
1271
- var _this6 = this;
1272
- var targetCartItem = this.store.cart.getItem(params._id);
1273
- if (!targetCartItem) {
1274
- 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);
1275
1116
  }
1276
- var currentResourcesCapacityMap = {};
1277
- if (params.resources) {
1278
- var _targetCartItem$_prod;
1279
- var formatCapacity = formatDefaultCapacitys({
1280
- capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
1281
- 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);
1282
1199
  });
1283
- var currentCapacity = getSumCapacity({
1284
- capacity: formatCapacity
1200
+ var cartItemsByDate = cartItems.filter(function (n) {
1201
+ return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
1285
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;
1286
1216
  params.resources = params.resources.map(function (n) {
1287
1217
  n.capacity = currentCapacity || 1;
1288
- currentResourcesCapacityMap[n.id] = currentCapacity;
1289
1218
  checkSubResourcesCapacity(n);
1290
1219
  return n;
1291
1220
  });
1292
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);
1293
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
+ // 零售模板不需要检测
1294
1251
  if (this.otherParams.isRetailTemplate) {
1295
1252
  return;
1296
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
+ });
1297
1258
  var allOriginResources = [];
1298
1259
  var dateRange = this.store.date.getDateRange();
1299
1260
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -1315,48 +1276,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1315
1276
  cartItems.forEach(function (item) {
1316
1277
  if (item._id !== targetCartItem._id) {
1317
1278
  var _item$_origin$resourc;
1279
+ var _getCapacityInfoByCar3 = getCapacityInfoByCartItem(item),
1280
+ currentCapacity = _getCapacityInfoByCar3.currentCapacity;
1318
1281
  var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1319
1282
  // 检查当前资源是否与目标资源的任何资源匹配
1320
1283
  // 目标资源,应该只取跟当前 m.form_id 相同的资源
1321
- var sameFormIdResources = targetCartItem._origin.resources.filter(function (n) {
1322
- return n.form_id === m.form_id;
1323
- });
1284
+ var sameFormIdResources = filterResourcesByFormItem(targetCartItem._origin.resources, m.form_id);
1324
1285
  if (!(sameFormIdResources !== null && sameFormIdResources !== void 0 && sameFormIdResources.length)) {
1325
1286
  return true;
1326
1287
  }
1327
1288
  return !sameFormIdResources.some(function (targetRes) {
1328
1289
  // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1329
1290
  if (targetRes.resourceType !== 'single') {
1330
- var _item$_productOrigin2;
1331
- var _formatCapacity = formatDefaultCapacitys({
1332
- capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1333
- product_bundle: item._origin.product.product_bundle
1334
- });
1335
- var _currentCapacity = getSumCapacity({
1336
- capacity: _formatCapacity
1337
- });
1338
1291
  var originResource = allOriginResources.find(function (n) {
1339
1292
  return n.id === targetRes.id;
1340
1293
  });
1341
- if (currentResourcesCapacityMap[m.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1342
- return true;
1343
- }
1344
- currentResourcesCapacityMap[m.id] += _currentCapacity;
1345
- 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;
1346
1297
  }
1347
1298
  if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1348
- var _targetRes$metadata$c, _m$metadata$combined_;
1349
- // 检查主资源ID是否匹配
1350
- if (targetRes.id === m.id) return true;
1351
- // 检查组合资源的情况
1352
- if (((_targetRes$metadata$c = targetRes.metadata.combined_resource) === null || _targetRes$metadata$c === void 0 ? void 0 : _targetRes$metadata$c.status) === 1 && (
1353
- // 如果现在选择的是组合资源,需要判断
1354
- // 1、当前其他购物车里是否选了当前组合资源的子资源
1355
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
1356
- targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some(function (n) {
1357
- return m.metadata.combined_resource.resource_ids.includes(n);
1358
- }))) return true;
1359
- 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);
1360
1300
  }
1361
1301
  return false;
1362
1302
  });
@@ -1367,7 +1307,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1367
1307
  var end_time = item.end_time;
1368
1308
  var start_date = item.start_date;
1369
1309
  var end_date = item.end_date;
1370
- _this6.store.cart.updateItem({
1310
+ _this7.store.cart.updateItem({
1371
1311
  _id: item._id,
1372
1312
  resources: resources,
1373
1313
  date: {
@@ -1376,7 +1316,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1376
1316
  }
1377
1317
  });
1378
1318
  } else {
1379
- _this6.store.cart.updateItem({
1319
+ _this7.store.cart.updateItem({
1380
1320
  _id: item._id,
1381
1321
  resources: resources
1382
1322
  });
@@ -1413,10 +1353,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1413
1353
  }, {
1414
1354
  key: "batchUpdateCart",
1415
1355
  value: function batchUpdateCart(paramsList) {
1416
- var _this7 = this;
1356
+ var _this8 = this;
1417
1357
  var cartItems = [];
1418
1358
  paramsList.forEach(function (params) {
1419
- var cartItem = _this7.store.cart.formatCartItem(params);
1359
+ var cartItem = _this8.store.cart.formatCartItem(params);
1420
1360
  cartItems.push(cartItem);
1421
1361
  });
1422
1362
  this.store.cart.batchSetItems(cartItems);
@@ -1444,172 +1384,39 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1444
1384
  }, {
1445
1385
  key: "checkCartItems",
1446
1386
  value: function checkCartItems(type) {
1447
- var _this8 = this;
1448
- // 预约流程中普通商品无需检测这些东西
1449
- var cartItems = this.store.cart.getItems().filter(function (n) {
1450
- return !isNormalProduct(n._productOrigin);
1451
- });
1452
- var errorCartItemIds = [];
1453
- cartItems.forEach(function (cartItem) {
1454
- var result = _this8.store.cart.checkCartItemByType(cartItem, type);
1455
- if (!result) {
1456
- errorCartItemIds.push(cartItem._id);
1457
- }
1458
- });
1459
- return errorCartItemIds;
1460
- }
1461
- }, {
1462
- key: "destroy",
1463
- value: function destroy() {
1464
- var _this$store$cart, _this$store$step, _this$store$products, _this$store$guests, _this$store$date, _this$store$accountLi;
1465
- (_this$store$cart = this.store.cart) === null || _this$store$cart === void 0 || _this$store$cart.destroy();
1466
- (_this$store$step = this.store.step) === null || _this$store$step === void 0 || _this$store$step.destroy();
1467
- (_this$store$products = this.store.products) === null || _this$store$products === void 0 || _this$store$products.destroy();
1468
- (_this$store$guests = this.store.guests) === null || _this$store$guests === void 0 || _this$store$guests.destroy();
1469
- (_this$store$date = this.store.date) === null || _this$store$date === void 0 || _this$store$date.destroy();
1470
- (_this$store$accountLi = this.store.accountList) === null || _this$store$accountLi === void 0 || _this$store$accountLi.destroy();
1471
- this.core.effects.offByModuleDestroy(this.name);
1472
- this.core.unregisterModule(this);
1473
- }
1474
-
1475
- // 获取当前购物车内所有关联的资源列表,拼装数据格式
1476
- }, {
1477
- key: "getResourcesList",
1478
- value: function getResourcesList() {
1479
1387
  var _this9 = this;
1480
- var dateRange = this.store.date.getDateRange();
1481
- var resources = [];
1482
- if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
1483
- dateRange.forEach(function (n) {
1484
- if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1485
- });
1486
- }
1487
- // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1488
- if (!resources.length) {
1489
- var dateList = this.store.date.getDateList();
1490
- dateList.forEach(function (n) {
1491
- if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1492
- });
1493
- }
1494
- var resourcesMap = getResourcesMap(cloneDeep(resources));
1495
- var cartItems = this.store.cart.getItems().filter(function (n) {
1496
- return !isNormalProduct(n._productOrigin);
1497
- });
1498
- var arr = [];
1499
- cartItems.forEach(function (cartItem) {
1500
- var _cartItem$_productOri, _cartItem$_productOri2;
1501
- var selectedResources = [];
1502
- var formatCapacity = formatDefaultCapacitys({
1503
- capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
1504
- product_bundle: cartItem._origin.product.product_bundle
1505
- });
1506
- cartItem._origin.metadata.capacity = formatCapacity;
1507
- var currentCapacity = getSumCapacity({
1508
- capacity: formatCapacity
1509
- });
1510
- if (cartItem.holder_id) {
1511
- selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1512
- } else {
1513
- selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1514
- }
1515
- 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);
1516
- // 如果购物车里已经有了时间片,则需要按照时间片过滤
1517
- if (cartItem._origin.start_time) {
1518
- var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
1519
- var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
1520
- var resourcesUseableMap = {};
1521
- productResources.forEach(function (n) {
1522
- // 资源排下序,把单个资源靠前,组合资源排在后面
1523
- n.renderList = n.renderList.sort(function (a, b) {
1524
- var _a$metadata, _b$metadata;
1525
- 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;
1526
- 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;
1527
- if (aIsCombined && !bIsCombined) return 1;
1528
- if (!aIsCombined && bIsCombined) return -1;
1529
- return 0;
1530
- });
1531
- n.renderList = n.renderList.filter(function (m) {
1532
- // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1533
- // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1534
- // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1535
- var mTimes = m.times.filter(function (n) {
1536
- return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
1537
- });
1538
- // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1539
- if (mTimes.length === 0) {
1540
- return false;
1541
- }
1542
- var canUseArr = mTimes.map(function (item) {
1543
- var _cartItem$_productOri3;
1544
- var res = getIsUsableByTimeItem({
1545
- timeSlice: {
1546
- start_time: startTime.format('HH:mm'),
1547
- end_time: endTime.format('HH:mm'),
1548
- start_at: startTime,
1549
- end_at: endTime
1550
- },
1551
- time: item,
1552
- resource: m,
1553
- currentCount: currentCapacity || 0,
1554
- resourcesUseableMap: resourcesUseableMap,
1555
- cut_off_time: (_cartItem$_productOri3 = cartItem._productOrigin) === null || _cartItem$_productOri3 === void 0 ? void 0 : _cartItem$_productOri3.cut_off_time
1556
- });
1557
- // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1558
- if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1559
- resourcesUseableMap[m.id] = res.usable;
1560
- }
1561
- return res.usable;
1562
- });
1563
- if (m.onlyComputed) return false;
1564
- // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1565
- return !canUseArr.some(function (n) {
1566
- return n === false;
1567
- });
1568
- });
1569
- });
1570
- } else {
1571
- var _cartItem$_productOri4, _this9$shopStore$get;
1572
- 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';
1573
- 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;
1574
- productResources.forEach(function (item) {
1575
- // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1576
- // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1577
- item.renderList = item.renderList.filter(function (n) {
1578
- var _cartItem$_productOri5, _cartItem$_productOri6;
1579
- var recordCount = n.capacity || 0;
1580
- if (n.onlyComputed) return false;
1581
- // 查一下这个资源基于商品的可用时间片
1582
- var timeSlots = getTimeSlicesByResource({
1583
- resource: n,
1584
- 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,
1585
- split: 10,
1586
- currentDate: dateRange[0].date,
1587
- hasFlexibleDuration: hasFlexibleDuration,
1588
- cut_off_time: (_cartItem$_productOri6 = cartItem._productOrigin) === null || _cartItem$_productOri6 === void 0 ? void 0 : _cartItem$_productOri6.cut_off_time,
1589
- operating_day_boundary: operating_day_boundary
1590
- });
1591
- return recordCount >= currentCapacity && timeSlots.length > 0;
1592
- });
1593
- });
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);
1594
1397
  }
1595
- arr.push({
1596
- id: cartItem.id,
1597
- // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1598
- _id: cartItem._id,
1599
- // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1600
- product: cartItem._productOrigin,
1601
- resources: productResources,
1602
- holder_id: cartItem.holder_id,
1603
- holder_name: cartItem.holder_title
1604
- });
1605
1398
  });
1606
- 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);
1607
1413
  }
1608
1414
 
1609
- // 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
1415
+ // 获取当前购物车内所有关联的资源列表,拼装数据格式
1610
1416
  }, {
1611
- key: "checkResourceListForDate",
1612
- value: function checkResourceListForDate() {
1417
+ key: "getResourcesList",
1418
+ value: function getResourcesList() {
1419
+ var _this10 = this;
1613
1420
  var dateRange = this.store.date.getDateRange();
1614
1421
  var resources = [];
1615
1422
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -1617,35 +1424,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1617
1424
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1618
1425
  });
1619
1426
  }
1427
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1428
+ return !isNormalProduct(n._productOrigin);
1429
+ });
1430
+
1620
1431
  // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1621
1432
  if (!resources.length) {
1622
- var dateList = this.store.date.getDateList();
1623
- dateList.forEach(function (n) {
1624
- 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;
1625
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
+ }
1626
1446
  }
1627
1447
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1628
- var cartItems = this.store.cart.getItems().filter(function (n) {
1629
- return !isNormalProduct(n._productOrigin);
1630
- });
1631
1448
  var arr = [];
1632
1449
  cartItems.forEach(function (cartItem) {
1633
- var _cartItem$_productOri7, _cartItem$_productOri8;
1450
+ var _cartItem$_productOri;
1634
1451
  var selectedResources = [];
1635
- var formatCapacity = formatDefaultCapacitys({
1636
- capacity: (_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.capacity,
1637
- product_bundle: cartItem._origin.product.product_bundle
1638
- });
1452
+ var _getCapacityInfoByCar4 = getCapacityInfoByCartItem(cartItem),
1453
+ currentCapacity = _getCapacityInfoByCar4.currentCapacity,
1454
+ formatCapacity = _getCapacityInfoByCar4.formatCapacity;
1639
1455
  cartItem._origin.metadata.capacity = formatCapacity;
1640
- var currentCapacity = getSumCapacity({
1641
- capacity: formatCapacity
1642
- });
1643
1456
  if (cartItem.holder_id) {
1644
1457
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1645
1458
  } else {
1646
1459
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1647
1460
  }
1648
- 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);
1649
1463
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1650
1464
  if (cartItem._origin.start_time) {
1651
1465
  var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
@@ -1653,27 +1467,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1653
1467
  var resourcesUseableMap = {};
1654
1468
  productResources.forEach(function (n) {
1655
1469
  // 资源排下序,把单个资源靠前,组合资源排在后面
1656
- n.renderList = n.renderList.sort(function (a, b) {
1657
- var _a$metadata2, _b$metadata2;
1658
- 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;
1659
- 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;
1660
- if (aIsCombined && !bIsCombined) return 1;
1661
- if (!aIsCombined && bIsCombined) return -1;
1662
- return 0;
1663
- });
1470
+ n.renderList = sortCombinedResources(n.renderList);
1664
1471
  n.renderList = n.renderList.filter(function (m) {
1665
1472
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1666
1473
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1667
1474
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1668
- var mTimes = m.times.filter(function (n) {
1669
- return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
1670
- });
1475
+ var mTimes = filterConditionTimeSlots(m.times, startTime, endTime);
1671
1476
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1672
1477
  if (mTimes.length === 0) {
1673
1478
  return false;
1674
1479
  }
1675
1480
  var canUseArr = mTimes.map(function (item) {
1676
- var _cartItem$_productOri9;
1481
+ var _cartItem$_productOri2;
1677
1482
  var res = getIsUsableByTimeItem({
1678
1483
  timeSlice: {
1679
1484
  start_time: startTime.format('HH:mm'),
@@ -1685,9 +1490,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1685
1490
  resource: m,
1686
1491
  currentCount: currentCapacity || 0,
1687
1492
  resourcesUseableMap: resourcesUseableMap,
1688
- 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
1689
1494
  });
1690
- // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1495
+ // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况(因为组合资源还需要判断子资源够不够)
1691
1496
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1692
1497
  resourcesUseableMap[m.id] = res.usable;
1693
1498
  }
@@ -1701,19 +1506,25 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1701
1506
  });
1702
1507
  });
1703
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;
1704
1512
  productResources.forEach(function (item) {
1705
1513
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1706
1514
  // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1707
1515
  item.renderList = item.renderList.filter(function (n) {
1708
- var _cartItem$_productOri10;
1516
+ var _cartItem$_productOri4, _cartItem$_productOri5;
1709
1517
  var recordCount = n.capacity || 0;
1710
1518
  if (n.onlyComputed) return false;
1711
1519
  // 查一下这个资源基于商品的可用时间片
1712
1520
  var timeSlots = getTimeSlicesByResource({
1713
1521
  resource: n,
1714
- 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,
1715
1523
  split: 10,
1716
- 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
1717
1528
  });
1718
1529
  return recordCount >= currentCapacity && timeSlots.length > 0;
1719
1530
  });
@@ -1724,23 +1535,46 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1724
1535
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1725
1536
  _id: cartItem._id,
1726
1537
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1727
- productResources: productResources
1538
+ product: cartItem._productOrigin,
1539
+ resources: productResources,
1540
+ holder_id: cartItem.holder_id,
1541
+ holder_name: cartItem.holder_title
1728
1542
  });
1729
1543
  });
1730
- // 检查 productResources里是不是每一项资源的 renderList 里都有数据
1731
- var hasResource = arr.every(function (n) {
1732
- return n.productResources.every(function (m) {
1733
- 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;
1734
1562
  });
1735
1563
  });
1736
1564
  return hasResource;
1737
1565
  }
1738
1566
 
1739
- // 给单个购物车里的商品获取资源列表
1567
+ /**
1568
+ * 给单个购物车里的商品获取资源列表,给 UI 用的
1569
+ *
1570
+ * @param {(string | number)} id
1571
+ * @return {*}
1572
+ * @memberof BookingByStepImpl
1573
+ */
1740
1574
  }, {
1741
1575
  key: "getResourcesListByCartItem",
1742
1576
  value: function getResourcesListByCartItem(id) {
1743
- var _targetCartItem$_prod2, _targetCartItem$_prod3;
1577
+ var _targetCartItem$_prod;
1744
1578
  var cartItems = this.store.cart.getItems().filter(function (n) {
1745
1579
  return !isNormalProduct(n._productOrigin);
1746
1580
  });
@@ -1758,19 +1592,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1758
1592
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1759
1593
  }
1760
1594
  var selectedResources = [];
1761
- var formatCapacity = formatDefaultCapacitys({
1762
- capacity: (_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.capacity,
1763
- product_bundle: targetCartItem._origin.product.product_bundle
1764
- });
1765
- var currentCapacity = getSumCapacity({
1766
- capacity: formatCapacity
1767
- });
1595
+ var _getCapacityInfoByCar5 = getCapacityInfoByCartItem(targetCartItem),
1596
+ currentCapacity = _getCapacityInfoByCar5.currentCapacity;
1768
1597
  if (targetCartItem.holder_id) {
1769
1598
  selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1770
1599
  } else {
1771
1600
  selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1772
1601
  }
1773
- 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);
1774
1603
  productResources.forEach(function (item) {
1775
1604
  item.renderList = item.renderList.filter(function (n) {
1776
1605
  var recordCount = n.capacity || 0;
@@ -1792,36 +1621,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1792
1621
  }
1793
1622
  }
1794
1623
 
1795
- // 通过资源列表和指定的资源 id,获取指定资源的时间切片
1796
- }, {
1797
- key: "getResourceTimeSlot",
1798
- value: function getResourceTimeSlot(_ref7) {
1799
- var product = _ref7.product,
1800
- resources = _ref7.resources,
1801
- currentResourceId = _ref7.currentResourceId;
1802
- var dateRange = this.store.date.getDateRange();
1803
- var timeSlots = getTimeSlicesByResource({
1804
- resource: resources.find(function (n) {
1805
- return n.id === currentResourceId;
1806
- }),
1807
- duration: product.duration.value,
1808
- split: 10,
1809
- currentDate: dateRange[0].date
1810
- });
1811
- return timeSlots;
1812
- }
1813
-
1814
1624
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
1815
1625
  }, {
1816
1626
  key: "autoSelectAccountResources",
1817
- value: function autoSelectAccountResources(_ref8) {
1818
- var _cartItem$_productOri11, _allProductResources$;
1819
- var cartItem = _ref8.cartItem,
1820
- holder_id = _ref8.holder_id,
1821
- resources_code = _ref8.resources_code,
1822
- timeSlots = _ref8.timeSlots,
1823
- countMap = _ref8.countMap,
1824
- 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;
1825
1635
  if (isNormalProduct(cartItem._productOrigin)) {
1826
1636
  return {};
1827
1637
  }
@@ -1835,10 +1645,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1835
1645
  if (!accountCartItems.length) {
1836
1646
  accountCartItems = cartItems;
1837
1647
  }
1838
- // duration=所有商品时间的集合
1648
+ // duration=所有商品时间的集合,如果是灵活时长,当做占用 10 分钟处理
1839
1649
  var duration = accountCartItems.reduce(function (acc, n) {
1840
- var _n$_productOrigin2;
1841
- 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);
1842
1652
  }, 0);
1843
1653
  var AllResources = [];
1844
1654
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -1848,23 +1658,31 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1848
1658
  }
1849
1659
  // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1850
1660
  if (!AllResources.length) {
1851
- var dateList = this.store.date.getDateList();
1852
- dateList.forEach(function (n) {
1853
- 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;
1854
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
+ }
1855
1673
  }
1856
1674
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1857
1675
  var allCartItems = cloneDeep(this.store.cart.getItems());
1858
1676
  var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1859
- 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);
1860
1678
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1861
1679
  return n.code === resources_code;
1862
1680
  })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
1863
1681
  // 资源排下序,把单个资源靠前,组合资源排在后面
1864
1682
  resources.sort(function (a, b) {
1865
- var _a$metadata3, _b$metadata3;
1866
- 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;
1867
- 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;
1868
1686
  if (aIsCombined && !bIsCombined) return 1;
1869
1687
  if (!aIsCombined && bIsCombined) return -1;
1870
1688
  return 0;
@@ -1885,11 +1703,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1885
1703
  // 根据 start_time 和 end_time 去匹配资源
1886
1704
  var targetResource = null;
1887
1705
  var targetResourceTime = 0;
1888
- var _iterator3 = _createForOfIteratorHelper(resources),
1889
- _step3;
1706
+ var _iterator2 = _createForOfIteratorHelper(resources),
1707
+ _step2;
1890
1708
  try {
1891
- var _loop2 = function _loop2() {
1892
- var n = _step3.value;
1709
+ var _loop = function _loop() {
1710
+ var n = _step2.value;
1893
1711
  // 如果资源是独占的,并且 countMap 里选择过这个资源,则直接跳过
1894
1712
  // if (n.resourceType === 'single' && countMap[n.id]) {
1895
1713
  // resourcesUseableMap[n.id] = false;
@@ -1917,14 +1735,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1917
1735
  return 0; // continue
1918
1736
  }
1919
1737
  var canUseTime = mTimes.find(function (item) {
1920
- var _cartItem$_productOri12;
1738
+ var _cartItem$_productOri7;
1921
1739
  var res = getIsUsableByTimeItem({
1922
1740
  timeSlice: timeSlots,
1923
1741
  time: item,
1924
1742
  resource: n,
1925
1743
  currentCount: totalCapacity + (capacity || 0),
1926
1744
  resourcesUseableMap: resourcesUseableMap,
1927
- 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
1928
1746
  });
1929
1747
  // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1930
1748
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
@@ -1944,15 +1762,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1944
1762
  }
1945
1763
  },
1946
1764
  _ret;
1947
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1948
- _ret = _loop2();
1765
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1766
+ _ret = _loop();
1949
1767
  if (_ret === 0) continue;
1950
1768
  if (_ret === 1) break;
1951
1769
  }
1952
1770
  } catch (err) {
1953
- _iterator3.e(err);
1771
+ _iterator2.e(err);
1954
1772
  } finally {
1955
- _iterator3.f();
1773
+ _iterator2.f();
1956
1774
  }
1957
1775
  return {
1958
1776
  selectedResource: targetResource
@@ -1987,7 +1805,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1987
1805
  key: "autoSelectAllProductResources",
1988
1806
  value: function autoSelectAllProductResources(resources_code, timeSlots) {
1989
1807
  var _dateRange$4,
1990
- _this10 = this;
1808
+ _this11 = this;
1991
1809
  var dateRange = this.store.date.getDateRange();
1992
1810
  var resources = [];
1993
1811
  if (dateRange !== null && dateRange !== void 0 && (_dateRange$4 = dateRange[0]) !== null && _dateRange$4 !== void 0 && _dateRange$4.date) {
@@ -1995,10 +1813,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1995
1813
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1996
1814
  });
1997
1815
  }
1998
- // const resourcesMap = getResourcesMap(cloneDeep(resources));
1999
1816
  // 一个账号一个账号处理
2000
1817
  var errorList = [];
1818
+ // 资源使用情况-单个预约
2001
1819
  var selectResourcesMap = {};
1820
+ // 资源使用情况-多个预约
2002
1821
  var selectResourcesWithTimeSlots = {};
2003
1822
  var accountList = this.store.accountList.getAccounts();
2004
1823
  var selectForCartResources = function selectForCartResources(cartItems) {
@@ -2008,18 +1827,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2008
1827
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
2009
1828
  // 判断购物车里是否有 flexible 类型的商品,如果有则不累加时间
2010
1829
  var hasFlexibleProduct = cartItems.some(function (item) {
2011
- var _item$_productOrigin3;
2012
- 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';
2013
1832
  });
2014
1833
  cartItems.forEach(function (item, index) {
2015
- var _item$_productOrigin4;
2016
- var formatCapacity = formatDefaultCapacitys({
2017
- capacity: (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.capacity,
2018
- product_bundle: item._origin.product.product_bundle
2019
- });
2020
- var currentCapacity = getSumCapacity({
2021
- capacity: formatCapacity
2022
- });
1834
+ var _getCapacityInfoByCar6 = getCapacityInfoByCartItem(item),
1835
+ currentCapacity = _getCapacityInfoByCar6.currentCapacity;
2023
1836
  // 如果商品已经有时间数据了,意味着是通过先选日期再选商品流程进来的,相当于时间切片已经选中了
2024
1837
  if (item._origin.start_time && !(timeSlots !== null && timeSlots !== void 0 && timeSlots.start_time)) {
2025
1838
  recordTimeSlots = {
@@ -2030,17 +1843,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2030
1843
  };
2031
1844
  }
2032
1845
  if (recordTimeSlots) {
2033
- var _item$_productOrigin5, _item$_productOrigin6;
1846
+ var _item$_productOrigin2, _item$_productOrigin3;
2034
1847
  // 同一账号下,如果当前商品不是第一个,则需要根据上一个商品的 end_time 和 duration 计算出当前商品的 start_time 和 end_time
2035
1848
  // 前提:当前资源是单个预约才需要这么做
2036
- 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) {
2037
1850
  return n.code === resources_code;
2038
1851
  });
2039
- // 只有 duration 类商品需要这个操作
2040
- 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) {
2041
- var _item$_productOrigin7, _item$_productOrigin8;
2042
- 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');
2043
- 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');
2044
1857
  recordTimeSlots = {
2045
1858
  start_time: start_at.format('HH:mm'),
2046
1859
  end_time: end_at.format('HH:mm'),
@@ -2049,7 +1862,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2049
1862
  };
2050
1863
  }
2051
1864
  // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
2052
- var res = _this10.autoSelectAccountResources({
1865
+ var res = _this11.autoSelectAccountResources({
2053
1866
  cartItem: item,
2054
1867
  holder_id: item.holder_id,
2055
1868
  resources_code: resources_code,
@@ -2057,10 +1870,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2057
1870
  countMap: selectResourcesWithTimeSlots,
2058
1871
  capacity: currentCapacity
2059
1872
  });
2060
- // // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
2061
- // if (item._origin.resources?.some((n: any) => n.form_id === res?.selectedResource?.form_id)) {
2062
- // return
2063
- // }
2064
1873
  if (res !== null && res !== void 0 && res.selectedResource) {
2065
1874
  if (!selectResourcesWithTimeSlots[res.selectedResource.id]) {
2066
1875
  selectResourcesWithTimeSlots[res.selectedResource.id] = [{
@@ -2075,7 +1884,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2075
1884
  }
2076
1885
  res.selectedResource.capacity = currentCapacity;
2077
1886
  checkSubResourcesCapacity(res.selectedResource);
2078
- _this10.store.cart.updateItem({
1887
+ _this11.store.cart.updateItem({
2079
1888
  _id: item._id,
2080
1889
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
2081
1890
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
@@ -2088,12 +1897,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2088
1897
  errorList.push(item._id);
2089
1898
  }
2090
1899
  } else {
2091
- var _item$_productOrigin9, _productResources$fin;
1900
+ var _item$_productOrigin6, _productResources$fin;
2092
1901
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
2093
- var allCartItems = cloneDeep(_this10.store.cart.getItems());
1902
+ // 能进到这种逻辑,说明是 duration 类商品或者灵活时长商品,且是第一种资源,还没有确定时间
1903
+ var allCartItems = cloneDeep(_this11.store.cart.getItems());
2094
1904
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
2095
1905
  var selectedResources = [];
2096
- 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) || []);
2097
1907
  var currentResourcesRenderList = [];
2098
1908
  _resources.forEach(function (n) {
2099
1909
  var _n$renderList;
@@ -2154,7 +1964,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2154
1964
  } else {
2155
1965
  selectResourcesMap[targetResource.id] += currentCapacity;
2156
1966
  }
2157
- _this10.store.cart.updateItem({
1967
+ _this11.store.cart.updateItem({
2158
1968
  _id: item._id,
2159
1969
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
2160
1970
  return existingRes.resourceType !== targetRenderList[0].resourceType;
@@ -2174,7 +1984,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2174
1984
  // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
2175
1985
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2176
1986
  accountList.forEach(function (account) {
2177
- var cartItems = _this10.store.cart.getCartByAccount(account.getId());
1987
+ var cartItems = _this11.store.cart.getCartByAccount(account.getId());
2178
1988
  selectForCartResources(cartItems);
2179
1989
  });
2180
1990
  } else {
@@ -2189,7 +1999,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2189
1999
  key: "getTimeSlotByAllResources",
2190
2000
  value: function getTimeSlotByAllResources(resources_code) {
2191
2001
  var _dateRange,
2192
- _this11 = this,
2002
+ _this12 = this,
2193
2003
  _cartItems$,
2194
2004
  _cartItems$2,
2195
2005
  _this$shopStore$get;
@@ -2208,8 +2018,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2208
2018
  var maxCutOffTime = undefined;
2209
2019
  var maxCutOffTimeValue = dayjs();
2210
2020
  cartItems.forEach(function (item) {
2211
- var _item$_productOrigin10, _item$_productOrigin11, _item$_productOrigin12, _item$_productOrigin13;
2212
- (_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) {
2213
2023
  // TODO: 少了个 status 的判断
2214
2024
  if (n.code === resources_code) {
2215
2025
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
@@ -2222,10 +2032,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2222
2032
  if (item.resource_id) {
2223
2033
  resourceIds.push(item.resource_id);
2224
2034
  }
2225
- 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) {
2226
2036
  return n.code === resources_code;
2227
- })) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.id;
2228
- 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') {
2229
2039
  var currentCutOffTime = dayjs().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
2230
2040
  if (currentCutOffTime.isAfter(maxCutOffTimeValue, 'minute')) {
2231
2041
  maxCutOffTimeValue = currentCutOffTime;
@@ -2253,13 +2063,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2253
2063
  cartItems.forEach(function (item) {
2254
2064
  // 单个预约累加账号 多个预约取最大值
2255
2065
  if (isSingleResource) {
2256
- var _item$_productOrigin14;
2257
- 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;
2258
2068
  } else {
2259
- var _item$_productOrigin15;
2260
- 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)) {
2261
- var _item$_productOrigin16;
2262
- 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;
2263
2073
  }
2264
2074
  }
2265
2075
  });
@@ -2269,7 +2079,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2269
2079
  };
2270
2080
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2271
2081
  accountList.forEach(function (account) {
2272
- var cartItems = _this11.store.cart.getCartByAccount(account.getId());
2082
+ var cartItems = _this12.store.cart.getCartByAccount(account.getId());
2273
2083
  checkDuration(cartItems);
2274
2084
  });
2275
2085
  } else {
@@ -2296,8 +2106,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2296
2106
  }
2297
2107
  var resourcesUseableMap = {};
2298
2108
  var hasFlexibleDuration = cartItems.some(function (item) {
2299
- var _item$_productOrigin17;
2300
- 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';
2301
2111
  });
2302
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;
2303
2113
  var timeSlots = getTimeSlicesByResources({
@@ -2319,7 +2129,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2319
2129
  key: "submitTimeSlot",
2320
2130
  value: function submitTimeSlot(timeSlots) {
2321
2131
  var _this$shopStore$get2,
2322
- _this12 = this;
2132
+ _this13 = this;
2323
2133
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
2324
2134
  var cartItems = this.store.cart.getItems().filter(function (n) {
2325
2135
  return !isNormalProduct(n._productOrigin);
@@ -2348,26 +2158,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2348
2158
  var _newResources$;
2349
2159
  var newResources = cloneDeep(item._origin.resources);
2350
2160
  newResources.forEach(function (resource) {
2351
- var _item$_productOrigin18;
2161
+ var _item$_productOrigin15;
2352
2162
  // 如果商品配置的是灵活时长,开始时间设置为提交的时间,结束时间从资源的可用最晚时间和店铺营业结束时间里取一个最早的
2353
- 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') {
2354
2164
  var _allResources$find;
2355
2165
  item.duration = {
2356
2166
  type: 'minutes',
2357
2167
  value: 10
2358
2168
  };
2359
2169
  resource.startTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
2360
- // 找到resource.times里最早的end_at
2170
+ // 找到resource.times里最晚的end_at
2361
2171
  var targetResourceTimes = allResources === null || allResources === void 0 || (_allResources$find = allResources.find(function (n) {
2362
2172
  return n.id === resource.id;
2363
2173
  })) === null || _allResources$find === void 0 ? void 0 : _allResources$find.times;
2364
2174
  var resourcesEndTime = targetResourceTimes.reduce(function (acc, curr) {
2365
- return dayjs(curr.end_at).isBefore(dayjs(acc.end_at)) ? curr : acc;
2175
+ return dayjs(curr.end_at).isAfter(dayjs(acc.end_at)) ? curr : acc;
2366
2176
  }, targetResourceTimes[0]);
2367
2177
 
2368
2178
  // 将 operating_day_boundary 转换为与 resourcesEndTime.end_at 相同日期的完整日期时间
2369
2179
  var resourceDate = dayjs(resourcesEndTime.end_at).format('YYYY-MM-DD');
2370
- 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);
2371
2181
  var endTime = dayjs(resourcesEndTime.end_at).isBefore(dayjs(operatingBoundaryDateTime)) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
2372
2182
  // 修复:如果 endTime 只是时间格式(如 "17:00"),需要加上日期
2373
2183
  var formattedEndTime;
@@ -2380,13 +2190,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2380
2190
  }
2381
2191
  resource.endTime = formattedEndTime.format('YYYY-MM-DD HH:mm');
2382
2192
  } else {
2383
- var _item$_productOrigin19;
2193
+ var _item$_productOrigin16;
2384
2194
  resource.startTime = currentStartTime;
2385
- 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');
2386
2196
  }
2387
2197
  // delete resource.times;
2388
2198
  });
2389
- _this12.store.cart.updateItem({
2199
+ _this13.store.cart.updateItem({
2390
2200
  _id: item._id,
2391
2201
  resources: newResources
2392
2202
  });
@@ -2434,26 +2244,59 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2434
2244
  }, {
2435
2245
  key: "openProductDetail",
2436
2246
  value: function () {
2437
- var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(productId) {
2438
- var targetProduct, targetProductData, newScheduleArr;
2439
- return _regeneratorRuntime().wrap(function _callee26$(_context27) {
2440
- 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) {
2441
2251
  case 0:
2442
- _context27.next = 2;
2252
+ _context25.next = 2;
2443
2253
  return this.store.products.getProduct(productId);
2444
2254
  case 2:
2445
- targetProduct = _context27.sent;
2446
- if (targetProduct) {
2447
- targetProductData = targetProduct.getData();
2448
- this.store.currentProduct = targetProduct;
2449
- newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
2450
- targetProduct.setOtherParams('schedule', newScheduleArr);
2255
+ targetProduct = _context25.sent;
2256
+ if (!targetProduct) {
2257
+ _context25.next = 16;
2258
+ break;
2451
2259
  }
2452
- 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:
2453
2296
  case "end":
2454
- return _context27.stop();
2297
+ return _context25.stop();
2455
2298
  }
2456
- }, _callee26, this);
2299
+ }, _callee25, this);
2457
2300
  }));
2458
2301
  function openProductDetail(_x19) {
2459
2302
  return _openProductDetail.apply(this, arguments);
@@ -2469,12 +2312,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2469
2312
  }
2470
2313
  }, {
2471
2314
  key: "getTimeslotBySchedule",
2472
- value: function getTimeslotBySchedule(_ref9) {
2315
+ value: function getTimeslotBySchedule(_ref10) {
2473
2316
  var _this$store$currentPr2, _targetProductData$pr;
2474
- var date = _ref9.date,
2475
- scheduleIds = _ref9.scheduleIds,
2476
- resources = _ref9.resources,
2477
- product = _ref9.product;
2317
+ var date = _ref10.date,
2318
+ scheduleIds = _ref10.scheduleIds,
2319
+ resources = _ref10.resources,
2320
+ product = _ref10.product;
2478
2321
  var targetProduct = this.store.currentProduct;
2479
2322
  // 如果外面传递了product 优先用外面的
2480
2323
  var targetProductData = product || (targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
@@ -2501,9 +2344,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2501
2344
  });
2502
2345
  // 资源排下序,把单个资源靠前,组合资源排在后面
2503
2346
  allProductResources.sort(function (a, b) {
2504
- var _a$metadata4, _b$metadata4;
2505
- 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;
2506
- 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;
2507
2350
  if (aIsCombined && !bIsCombined) return 1;
2508
2351
  if (!aIsCombined && bIsCombined) return -1;
2509
2352
  return 0;
@@ -2566,9 +2409,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2566
2409
  // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2567
2410
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2568
2411
  return n === false;
2569
- })
2412
+ }) &&
2570
2413
  // 只统计第一种资源的容量和 left
2571
- && m.form_id === firstEnabledResourceId) {
2414
+ m.form_id === firstEnabledResourceId) {
2572
2415
  if (currentResourcesCount >= count) {
2573
2416
  count = currentResourcesCount;
2574
2417
  }
@@ -2590,84 +2433,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2590
2433
  });
2591
2434
  return formatScheduleTimeSlots;
2592
2435
  }
2593
- }, {
2594
- key: "addProductToCart",
2595
- value: function addProductToCart(_ref10) {
2596
- var _this13 = this;
2597
- var product = _ref10.product,
2598
- date = _ref10.date,
2599
- account = _ref10.account;
2600
- var _ref11 = product || {},
2601
- bundle = _ref11.bundle,
2602
- options = _ref11.options,
2603
- origin = _ref11.origin,
2604
- product_variant_id = _ref11.product_variant_id,
2605
- rowKey = _ref11.rowKey,
2606
- _ref11$quantity = _ref11.quantity,
2607
- quantity = _ref11$quantity === void 0 ? 1 : _ref11$quantity;
2608
- var productData = _objectSpread(_objectSpread({}, origin), {}, {
2609
- product_variant_id: product_variant_id
2610
- });
2611
- if (!account) {
2612
- var activeAccount = this.getActiveAccount();
2613
- if (activeAccount) {
2614
- account = activeAccount;
2615
- }
2616
- }
2617
- if (rowKey) {
2618
- var cartItems = this.store.cart.getItems();
2619
- var targetCartItem = cartItems.find(function (n) {
2620
- var _n$_productOrigin3;
2621
- return ((_n$_productOrigin3 = n._productOrigin) === null || _n$_productOrigin3 === void 0 ? void 0 : _n$_productOrigin3.rowKey) === rowKey;
2622
- });
2623
- if (targetCartItem && isNormalProduct(targetCartItem._productOrigin)) {
2624
- this.store.cart.updateItem({
2625
- _id: targetCartItem._id,
2626
- product: _objectSpread(_objectSpread({}, targetCartItem._productOrigin), {}, {
2627
- quantity: (targetCartItem.num || 1) + quantity
2628
- })
2629
- });
2630
- return;
2631
- }
2632
- }
2633
- this.store.cart.addItem({
2634
- product: productData,
2635
- date: date,
2636
- account: account,
2637
- bundle: bundle,
2638
- options: options,
2639
- quantity: quantity
2640
- });
2641
- // 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
2642
- if (date) {
2643
- var _cartItems = this.store.cart.getItems().filter(function (n) {
2644
- return !isNormalProduct(n._productOrigin);
2645
- });
2646
- var cartItemsByDate = _cartItems.filter(function (n) {
2647
- return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
2648
- });
2649
- if (cartItemsByDate.length) {
2650
- cartItemsByDate.forEach(function (n) {
2651
- _this13.store.cart.removeItem(n._id);
2652
- });
2653
- }
2654
- // 如果 date.startTime 和 dateRange 里的 startTime 不一样,需要修正 dateRange
2655
- var dateRange = this.store.date.getDateRange();
2656
- if (dateRange !== null && dateRange !== void 0 && dateRange[0] && !dayjs(dateRange[0].date).isSame(dayjs(date.startTime), 'day')) {
2657
- this.setDateRange([{
2658
- date: dayjs(date.startTime).format('YYYY-MM-DD'),
2659
- status: 'available',
2660
- week: '',
2661
- weekNum: 0
2662
- }, {
2663
- date: dayjs(date.endTime).format('YYYY-MM-DD'),
2664
- status: 'available',
2665
- week: '',
2666
- weekNum: 0
2667
- }]);
2668
- }
2669
- }
2670
- }
2671
2436
  }, {
2672
2437
  key: "setOtherData",
2673
2438
  value: function setOtherData(key, value) {
@@ -2689,27 +2454,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2689
2454
  }, {
2690
2455
  key: "getProductTypeById",
2691
2456
  value: function () {
2692
- var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(id) {
2457
+ var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(id) {
2693
2458
  var product;
2694
- return _regeneratorRuntime().wrap(function _callee27$(_context28) {
2695
- while (1) switch (_context28.prev = _context28.next) {
2459
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2460
+ while (1) switch (_context26.prev = _context26.next) {
2696
2461
  case 0:
2697
- _context28.next = 2;
2462
+ _context26.next = 2;
2698
2463
  return this.store.products.getProduct(id);
2699
2464
  case 2:
2700
- product = _context28.sent;
2465
+ product = _context26.sent;
2701
2466
  if (!product) {
2702
- _context28.next = 5;
2467
+ _context26.next = 5;
2703
2468
  break;
2704
2469
  }
2705
- return _context28.abrupt("return", product.getProductType());
2470
+ return _context26.abrupt("return", product.getProductType());
2706
2471
  case 5:
2707
- return _context28.abrupt("return", 'normal');
2472
+ return _context26.abrupt("return", 'normal');
2708
2473
  case 6:
2709
2474
  case "end":
2710
- return _context28.stop();
2475
+ return _context26.stop();
2711
2476
  }
2712
- }, _callee27, this);
2477
+ }, _callee26, this);
2713
2478
  }));
2714
2479
  function getProductTypeById(_x20) {
2715
2480
  return _getProductTypeById.apply(this, arguments);
@@ -2727,7 +2492,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2727
2492
  }, {
2728
2493
  key: "getResourcesByCartItemAndCode",
2729
2494
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
2730
- var _cartItem$_productOri13, _cartItem$_productOri14;
2495
+ var _cartItem$_productOri8;
2731
2496
  var dateRange = this.store.date.getDateRange();
2732
2497
  var resources = [];
2733
2498
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -2750,20 +2515,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2750
2515
  });
2751
2516
  if (!cartItem) return [];
2752
2517
  var selectedResources = [];
2753
- var formatCapacity = formatDefaultCapacitys({
2754
- capacity: (_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.capacity,
2755
- product_bundle: cartItem._origin.product.product_bundle
2756
- });
2518
+ var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
2519
+ currentCapacity = _getCapacityInfoByCar7.currentCapacity,
2520
+ formatCapacity = _getCapacityInfoByCar7.formatCapacity;
2757
2521
  cartItem._origin.metadata.capacity = formatCapacity;
2758
- var currentCapacity = getSumCapacity({
2759
- capacity: formatCapacity
2760
- });
2761
2522
  if (cartItem.holder_id) {
2762
2523
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
2763
2524
  } else {
2764
2525
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
2765
2526
  }
2766
- 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);
2767
2528
  var targetResource = productResources.find(function (resource) {
2768
2529
  return resource.code === resourceCode;
2769
2530
  });
@@ -2773,9 +2534,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2773
2534
  var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
2774
2535
  var resourcesUseableMap = {};
2775
2536
  targetResource.renderList = targetResource.renderList.sort(function (a, b) {
2776
- var _a$metadata5, _b$metadata5;
2777
- 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;
2778
- 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;
2779
2540
  if (aIsCombined && !bIsCombined) return 1;
2780
2541
  if (!aIsCombined && bIsCombined) return -1;
2781
2542
  return 0;
@@ -2786,7 +2547,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2786
2547
  });
2787
2548
  if (mTimes.length === 0) return false;
2788
2549
  var canUseArr = mTimes.map(function (item) {
2789
- var _cartItem$_productOri15;
2550
+ var _cartItem$_productOri9;
2790
2551
  var res = getIsUsableByTimeItem({
2791
2552
  timeSlice: {
2792
2553
  start_time: startTime.format('HH:mm'),
@@ -2798,7 +2559,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2798
2559
  resource: m,
2799
2560
  currentCount: currentCapacity || 0,
2800
2561
  resourcesUseableMap: resourcesUseableMap,
2801
- 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
2802
2563
  });
2803
2564
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2804
2565
  resourcesUseableMap[m.id] = res.usable;
@@ -2812,12 +2573,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2812
2573
  });
2813
2574
  } else {
2814
2575
  targetResource.renderList = targetResource.renderList.filter(function (n) {
2815
- var _cartItem$_productOri16;
2576
+ var _cartItem$_productOri10;
2816
2577
  var recordCount = n.capacity || 0;
2817
2578
  if (n.onlyComputed) return false;
2818
2579
  var timeSlots = getTimeSlicesByResource({
2819
2580
  resource: n,
2820
- 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,
2821
2582
  split: 10,
2822
2583
  currentDate: dateRange[0].date
2823
2584
  });
@@ -2835,12 +2596,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2835
2596
  }, {
2836
2597
  key: "getTimeslotsScheduleByDateRange",
2837
2598
  value: (function () {
2838
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(_ref12) {
2599
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(_ref11) {
2839
2600
  var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i, _dates, date;
2840
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2841
- while (1) switch (_context29.prev = _context29.next) {
2601
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2602
+ while (1) switch (_context27.prev = _context27.next) {
2842
2603
  case 0:
2843
- 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;
2844
2605
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
2845
2606
  startDate: startDate,
2846
2607
  endDate: endDate,
@@ -2865,137 +2626,46 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2865
2626
  resources: resources
2866
2627
  });
2867
2628
  }
2868
- return _context29.abrupt("return", results);
2629
+ return _context27.abrupt("return", results);
2869
2630
  case 9:
2870
2631
  case "end":
2871
- return _context29.stop();
2632
+ return _context27.stop();
2872
2633
  }
2873
- }, _callee28, this);
2634
+ }, _callee27, this);
2874
2635
  }));
2875
2636
  function getTimeslotsScheduleByDateRange(_x21) {
2876
2637
  return _getTimeslotsScheduleByDateRange.apply(this, arguments);
2877
2638
  }
2878
2639
  return getTimeslotsScheduleByDateRange;
2879
2640
  }())
2880
- }, {
2881
- key: "getAvailableDateForSession",
2882
- value: function () {
2883
- var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2884
- var params,
2885
- startDate,
2886
- endDate,
2887
- type,
2888
- tempProducts,
2889
- _ref13,
2890
- resourceIds,
2891
- rules,
2892
- resourcesMap,
2893
- res,
2894
- dateListWithTimeSlots,
2895
- firstAvailableDate,
2896
- _args30 = arguments;
2897
- return _regeneratorRuntime().wrap(function _callee29$(_context30) {
2898
- while (1) switch (_context30.prev = _context30.next) {
2899
- case 0:
2900
- params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
2901
- // 开始日期如果小于今天,直接以今天当做开始日期
2902
- startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2903
- if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
2904
- startDate = dayjs().format('YYYY-MM-DD');
2905
- }
2906
- // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2907
- endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2908
- tempProducts = []; // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2909
- if (this.store.currentProduct) {
2910
- tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
2911
- _schedule: this.store.currentProduct.getOtherParams()['schedule']
2912
- })];
2913
- }
2914
- // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
2915
- _ref13 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref13.resourceIds, rules = _ref13.rules, resourcesMap = _ref13.resourcesMap;
2916
- this.otherParams.currentResourcesMap = resourcesMap;
2917
- _context30.next = 10;
2918
- return this.store.date.getResourceDates({
2919
- query: {
2920
- start_date: startDate || '',
2921
- end_date: endDate || '',
2922
- resource_ids: resourceIds
2923
- },
2924
- rules: rules,
2925
- type: type
2926
- });
2927
- case 10:
2928
- res = _context30.sent;
2929
- if (!this.store.currentProduct) {
2930
- _context30.next = 16;
2931
- break;
2932
- }
2933
- _context30.next = 14;
2934
- return this.getTimeslotsScheduleByDateRange({
2935
- startDate: startDate || '',
2936
- endDate: endDate || ''
2937
- });
2938
- case 14:
2939
- dateListWithTimeSlots = _context30.sent;
2940
- res.forEach(function (n) {
2941
- if (!dateListWithTimeSlots[n.date]) {
2942
- n.status = 'unavailable';
2943
- } else {
2944
- var allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(function (d) {
2945
- return d.count;
2946
- });
2947
- if (!allTimeSlotsCanUse) {
2948
- n.status = 'unavailable';
2949
- }
2950
- }
2951
- });
2952
- case 16:
2953
- // 找到第一个可用的日期返回给 UI
2954
- firstAvailableDate = res.find(function (n) {
2955
- return n.status === 'available';
2956
- });
2957
- return _context30.abrupt("return", {
2958
- dateList: res,
2959
- firstAvailableDate: firstAvailableDate
2960
- });
2961
- case 18:
2962
- case "end":
2963
- return _context30.stop();
2964
- }
2965
- }, _callee29, this);
2966
- }));
2967
- function getAvailableDateForSession() {
2968
- return _getAvailableDateForSession.apply(this, arguments);
2969
- }
2970
- return getAvailableDateForSession;
2971
- }()
2972
2641
  }, {
2973
2642
  key: "getAvailableDateForSessionOptimize",
2974
2643
  value: function () {
2975
- var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2644
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2976
2645
  var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2977
2646
  var params,
2978
2647
  startDate,
2979
2648
  endDate,
2980
2649
  endDateAfterMonth,
2650
+ tempEndDate,
2651
+ cache,
2981
2652
  tempProducts,
2982
2653
  schedule,
2983
2654
  filteredSchedule,
2984
2655
  tempResourceIds,
2985
2656
  res,
2986
- cache,
2987
2657
  dates,
2988
2658
  currentDate,
2989
2659
  firstAvailableDate,
2990
2660
  openResources,
2991
2661
  allProductResources,
2992
2662
  targetSchedules,
2993
- _loop3,
2994
- _args32 = arguments;
2995
- return _regeneratorRuntime().wrap(function _callee30$(_context32) {
2996
- 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) {
2997
2667
  case 0:
2998
- params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
2668
+ params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
2999
2669
  // 开始日期如果小于今天,直接以今天当做开始日期
3000
2670
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
3001
2671
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -3005,43 +2675,49 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3005
2675
  // 优化策略:
3006
2676
  // 在 endDate 添加完一个月以后,如果 endDate 还小于 startDate + 7 天,则还需要 endDate+7 天
3007
2677
  endDateAfterMonth = dayjs().add(1, 'month').format('YYYY-MM-DD');
2678
+ tempEndDate = endDateAfterMonth;
3008
2679
  if (dayjs(startDate).add(7, 'day').isAfter(dayjs(endDateAfterMonth), 'day')) {
3009
- endDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2680
+ tempEndDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
3010
2681
  } else {
3011
- endDate = endDateAfterMonth;
2682
+ tempEndDate = endDateAfterMonth;
3012
2683
  }
3013
- // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
3014
- tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
3015
- schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
3016
- filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
3017
- tempResourceIds = getResourcesIdsByProduct(tempProducts);
3018
- _context32.next = 11;
3019
- return this.store.date.fetchResourceDates({
3020
- query: {
3021
- start_date: startDate || '',
3022
- end_date: endDate || '',
3023
- resource_ids: tempResourceIds
3024
- }
3025
- });
3026
- case 11:
3027
- res = _context32.sent;
2684
+ // 如果这么算出来的 tempEndDate 还小于 endDate,则需要把 endDate 置为 tempEndDate
2685
+ if (dayjs(tempEndDate).isBefore(dayjs(endDate), 'day')) {
2686
+ tempEndDate = endDate || '';
2687
+ }
2688
+ endDate = tempEndDate;
2689
+
3028
2690
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
3029
- // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
3030
- 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'];
3031
2692
  if (!cache) {
3032
- _context32.next = 17;
2693
+ _context29.next = 13;
3033
2694
  break;
3034
2695
  }
3035
2696
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
3036
- _context32.next = 17;
2697
+ _context29.next = 13;
3037
2698
  break;
3038
2699
  }
3039
2700
  this.store.date.setDateList(cache.dateList);
3040
- return _context32.abrupt("return", {
2701
+ return _context29.abrupt("return", {
3041
2702
  dateList: cache.dateList,
3042
2703
  firstAvailableDate: cache.firstAvailableDate
3043
2704
  });
3044
- 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;
3045
2721
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
3046
2722
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
3047
2723
  dates = [];
@@ -3061,10 +2737,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3061
2737
  }
3062
2738
  });
3063
2739
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3064
- _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
2740
+ _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
3065
2741
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
3066
- return _regeneratorRuntime().wrap(function _loop3$(_context31) {
3067
- while (1) switch (_context31.prev = _context31.next) {
2742
+ return _regeneratorRuntime().wrap(function _loop2$(_context28) {
2743
+ while (1) switch (_context28.prev = _context28.next) {
3068
2744
  case 0:
3069
2745
  currentDateStr = currentDate.format('YYYY-MM-DD');
3070
2746
  status = 'available'; // 1. 检查商品的提前量等情况是否满足
@@ -3156,34 +2832,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3156
2832
 
3157
2833
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
3158
2834
  if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
3159
- _context31.next = 9;
2835
+ _context28.next = 9;
3160
2836
  break;
3161
2837
  }
3162
- return _context31.abrupt("return", 1);
2838
+ return _context28.abrupt("return", 1);
3163
2839
  case 9:
3164
2840
  currentDate = dayjs(currentDate).add(1, 'day');
3165
2841
  case 10:
3166
2842
  case "end":
3167
- return _context31.stop();
2843
+ return _context28.stop();
3168
2844
  }
3169
- }, _loop3);
2845
+ }, _loop2);
3170
2846
  });
3171
- case 25:
2847
+ case 28:
3172
2848
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3173
- _context32.next = 31;
2849
+ _context29.next = 34;
3174
2850
  break;
3175
2851
  }
3176
- return _context32.delegateYield(_loop3(), "t0", 27);
3177
- case 27:
3178
- if (!_context32.t0) {
3179
- _context32.next = 29;
2852
+ return _context29.delegateYield(_loop2(), "t0", 30);
2853
+ case 30:
2854
+ if (!_context29.t0) {
2855
+ _context29.next = 32;
3180
2856
  break;
3181
2857
  }
3182
- return _context32.abrupt("break", 31);
3183
- case 29:
3184
- _context32.next = 25;
2858
+ return _context29.abrupt("break", 34);
2859
+ case 32:
2860
+ _context29.next = 28;
3185
2861
  break;
3186
- case 31:
2862
+ case 34:
3187
2863
  // 最终把资源数据也加到日期内
3188
2864
  dates = handleAvailableDateByResource(res.data, dates);
3189
2865
  this.store.date.setDateList(dates);
@@ -3195,15 +2871,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3195
2871
  startDate: startDate,
3196
2872
  endDate: dayjs(currentDate).format('YYYY-MM-DD')
3197
2873
  });
3198
- return _context32.abrupt("return", {
2874
+ return _context29.abrupt("return", {
3199
2875
  dateList: dates,
3200
2876
  firstAvailableDate: firstAvailableDate
3201
2877
  });
3202
- case 35:
2878
+ case 38:
3203
2879
  case "end":
3204
- return _context32.stop();
2880
+ return _context29.stop();
3205
2881
  }
3206
- }, _callee30, this);
2882
+ }, _callee28, this);
3207
2883
  }));
3208
2884
  function getAvailableDateForSessionOptimize() {
3209
2885
  return _getAvailableDateForSessionOptimize.apply(this, arguments);
@@ -3225,13 +2901,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3225
2901
  return !isNormalProduct(n._productOrigin);
3226
2902
  });
3227
2903
  return cartItems.some(function (n) {
3228
- var _n$_productOrigin4;
3229
- 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;
3230
2906
  });
3231
2907
  }
3232
2908
  }, {
3233
2909
  key: "isTargetNormalProduct",
3234
2910
  value: function isTargetNormalProduct(product) {
2911
+ if (!product) return false;
3235
2912
  return isNormalProduct(product);
3236
2913
  }
3237
2914
  }, {