@pisell/pisellos 2.0.39 → 2.0.41

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