@pisell/pisellos 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/modules/Cart/index.d.ts +0 -14
  2. package/dist/modules/Cart/index.js +0 -36
  3. package/dist/modules/Cart/utils/cartProduct.js +1 -10
  4. package/dist/modules/Date/index.js +6 -57
  5. package/dist/modules/Discount/index.d.ts +0 -1
  6. package/dist/modules/Discount/index.js +7 -15
  7. package/dist/modules/Discount/types.d.ts +0 -10
  8. package/dist/modules/ProductList/index.d.ts +0 -7
  9. package/dist/modules/ProductList/index.js +39 -102
  10. package/dist/modules/Rules/index.js +71 -196
  11. package/dist/modules/Rules/types.d.ts +0 -6
  12. package/dist/modules/Schedule/index.d.ts +1 -9
  13. package/dist/modules/Schedule/index.js +2 -122
  14. package/dist/modules/Schedule/types.d.ts +0 -13
  15. package/dist/solution/BookingByStep/index.d.ts +30 -120
  16. package/dist/solution/BookingByStep/index.js +1065 -750
  17. package/dist/solution/BookingByStep/utils/resources.d.ts +31 -29
  18. package/dist/solution/BookingByStep/utils/resources.js +94 -39
  19. package/dist/solution/BookingByStep/utils/timeslots.d.ts +0 -11
  20. package/dist/solution/BookingByStep/utils/timeslots.js +0 -15
  21. package/dist/solution/ShopDiscount/index.d.ts +0 -2
  22. package/dist/solution/ShopDiscount/index.js +32 -93
  23. package/lib/modules/Cart/index.d.ts +0 -14
  24. package/lib/modules/Cart/index.js +0 -32
  25. package/lib/modules/Cart/utils/cartProduct.js +1 -1
  26. package/lib/modules/Date/index.js +10 -62
  27. package/lib/modules/Discount/index.d.ts +0 -1
  28. package/lib/modules/Discount/index.js +6 -18
  29. package/lib/modules/Discount/types.d.ts +0 -10
  30. package/lib/modules/ProductList/index.d.ts +0 -7
  31. package/lib/modules/ProductList/index.js +0 -45
  32. package/lib/modules/Rules/index.js +56 -147
  33. package/lib/modules/Rules/types.d.ts +0 -6
  34. package/lib/modules/Schedule/index.d.ts +1 -9
  35. package/lib/modules/Schedule/index.js +1 -79
  36. package/lib/modules/Schedule/types.d.ts +0 -13
  37. package/lib/solution/BookingByStep/index.d.ts +30 -120
  38. package/lib/solution/BookingByStep/index.js +581 -392
  39. package/lib/solution/BookingByStep/utils/resources.d.ts +31 -29
  40. package/lib/solution/BookingByStep/utils/resources.js +59 -23
  41. package/lib/solution/BookingByStep/utils/timeslots.d.ts +0 -11
  42. package/lib/solution/BookingByStep/utils/timeslots.js +0 -7
  43. package/lib/solution/ShopDiscount/index.d.ts +0 -2
  44. package/lib/solution/ShopDiscount/index.js +18 -85
  45. package/package.json +1 -1
  46. package/dist/modules/Cart/utils/changePrice.d.ts +0 -3
  47. package/dist/modules/Cart/utils/changePrice.js +0 -104
  48. package/dist/solution/BookingByStep/utils/capacity.d.ts +0 -47
  49. package/dist/solution/BookingByStep/utils/capacity.js +0 -132
  50. package/lib/modules/Cart/utils/changePrice.d.ts +0 -3
  51. package/lib/modules/Cart/utils/changePrice.js +0 -78
  52. package/lib/solution/BookingByStep/utils/capacity.d.ts +0 -47
  53. package/lib/solution/BookingByStep/utils/capacity.js +0 -106
@@ -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, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, getResourcesIdsByProduct, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection } from "./utils/resources";
30
+ import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, formatDefaultCapacitys, getSumCapacity, checkSubResourcesCapacity, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, getResourcesIdsByProduct, sortCombinedResources } 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,11 +36,9 @@ 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 { handleAvailableDateByResource } from "../../modules/Date/utils";
39
+ import { disableAllDates, disableDatesBeforeOneDay, generateMonthDates, handleAvailableDateByResource } from "../../modules/Date/utils";
40
40
  import { areAllNormalProducts, isNormalProduct } from "../../modules/Product/utils";
41
- import { calculateResourceAvailableTime, filterConditionTimeSlots, findFastestAvailableResource } from "./utils/timeslots";
42
- import { updateAllCartItemPrice } from "../../modules/Cart/utils/changePrice";
43
- import { getCapacityInfoByCartItem, checkSubResourcesCapacity, checkResourceCanUseByCapacity } from "./utils/capacity";
41
+ import { calculateResourceAvailableTime, findFastestAvailableResource } from "./utils/timeslots";
44
42
  export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
45
43
  _inherits(BookingByStepImpl, _BaseModule);
46
44
  var _super = _createSuper(BookingByStepImpl);
@@ -126,7 +124,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
126
124
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
127
125
  }
128
126
  });
129
- this.store.schedule.loadAllSchedule();
127
+ this.loadAllSchedule();
130
128
  this.core.effects.emit(BookingByStepHooks.onInited, {});
131
129
  case 18:
132
130
  case "end":
@@ -207,40 +205,65 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
207
205
  this.store.step.updateStep(key, step);
208
206
  }
209
207
 
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
- */
208
+ // 获取购物车里 temp.xxx的方法
209
+ // async getStoreCart(key?: string) {
210
+ // return this.store.cart.getTemp(key);
211
+ // }
212
+
213
+ // 加载商品,然后导到商品列表里去
227
214
  }, {
228
215
  key: "loadProducts",
229
- value: (function () {
216
+ value: function () {
230
217
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
231
- var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date;
218
+ var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date, userPlugin, customer_id, _userPlugin$get, productsData;
232
219
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
233
220
  while (1) switch (_context2.prev = _context2.next) {
234
221
  case 0:
235
222
  _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;
236
- return _context2.abrupt("return", this.store.products.loadProducts({
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,
237
253
  category_ids: category_ids,
238
- product_ids: product_ids,
254
+ ids: product_ids,
239
255
  collection: collection,
240
- schedule_date: schedule_date,
241
- cacheId: this.cacheId
242
- }));
243
- case 2:
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:
244
267
  case "end":
245
268
  return _context2.stop();
246
269
  }
@@ -251,25 +274,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
251
274
  }
252
275
  return loadProducts;
253
276
  }()
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
- )
270
277
  }, {
271
278
  key: "loadProductByScheduleDate",
272
- value: (function () {
279
+ value: function () {
273
280
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
274
281
  var _schedule$product_ids;
275
282
  var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, schedule, otherProductsIds, allProductIds;
@@ -289,6 +296,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
289
296
  week: '',
290
297
  weekNum: 0
291
298
  }]);
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
+ // }
292
311
  // V2接口修改后,只能从schedule 接口里拿数据,不可以从外面拿,外面给的是装修数据
293
312
  schedule = scheduleList.find(function (n) {
294
313
  return n.date === date;
@@ -303,6 +322,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
303
322
  });
304
323
  _context3.next = 9;
305
324
  return this.loadProducts({
325
+ // schedule_ids: scheduleIds,
306
326
  product_ids: allProductIds,
307
327
  category_ids: category_ids,
308
328
  schedule_date: date
@@ -320,35 +340,29 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
320
340
  }
321
341
  return loadProductByScheduleDate;
322
342
  }()
323
- /**
324
- * 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
325
- *
326
- * @param {string} date
327
- * @memberof BookingByStepImpl
328
- */
329
- )
330
343
  }, {
331
344
  key: "updateQuotationPriceAndCart",
332
- value: (function () {
345
+ value: function () {
333
346
  var _updateQuotationPriceAndCart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(date) {
334
347
  var _this3 = this;
335
- var cartItems, userPlugin, customer_id, _userPlugin$get, res;
336
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
337
- while (1) switch (_context4.prev = _context4.next) {
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) {
338
351
  case 0:
352
+ // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
339
353
  cartItems = this.store.cart.getItems();
340
354
  if (!cartItems.length) {
341
- _context4.next = 11;
355
+ _context5.next = 25;
342
356
  break;
343
357
  }
344
358
  userPlugin = this.core.getPlugin('user');
345
359
  customer_id = undefined;
346
360
  try {
347
- customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get = userPlugin.get()) === null || _userPlugin$get === void 0 ? void 0 : _userPlugin$get.id;
361
+ customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get2 = userPlugin.get()) === null || _userPlugin$get2 === void 0 ? void 0 : _userPlugin$get2.id;
348
362
  } catch (error) {
349
363
  console.error(error);
350
364
  }
351
- _context4.next = 7;
365
+ _context5.next = 7;
352
366
  return this.store.products.loadProductsPrice({
353
367
  ids: cartItems.map(function (n) {
354
368
  return n.id;
@@ -357,104 +371,280 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
357
371
  customer_id: customer_id
358
372
  });
359
373
  case 7:
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);
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);
366
424
  });
367
- case 10:
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:
368
447
  this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
369
- case 11:
448
+ case 25:
370
449
  case "end":
371
- return _context4.stop();
450
+ return _context5.stop();
372
451
  }
373
- }, _callee4, this);
452
+ }, _callee4, this, [[9, 18, 21, 24]]);
374
453
  }));
375
454
  function updateQuotationPriceAndCart(_x5) {
376
455
  return _updateQuotationPriceAndCart.apply(this, arguments);
377
456
  }
378
457
  return updateQuotationPriceAndCart;
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
- )
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 层提供日期的起始范围,返回一个起始范围内日期的可用情况
394
488
  }, {
395
489
  key: "loadScheduleAvailableDate",
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) {
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) {
401
496
  case 0:
402
497
  startDate = _ref3.startDate, endDate = _ref3.endDate, custom_page_id = _ref3.custom_page_id, channel = _ref3.channel;
403
- _context5.next = 3;
404
- return this.store.schedule.loadScheduleAvailableDate({
405
- startDate: startDate,
406
- endDate: endDate,
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,
407
516
  custom_page_id: custom_page_id,
408
517
  channel: channel
409
518
  });
410
- case 3:
411
- return _context5.abrupt("return", _context5.sent);
412
- case 4:
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:
413
548
  case "end":
414
- return _context5.stop();
549
+ return _context7.stop();
415
550
  }
416
- }, _callee5, this);
551
+ }, _callee6, this);
417
552
  }));
418
553
  function loadScheduleAvailableDate(_x6) {
419
554
  return _loadScheduleAvailableDate.apply(this, arguments);
420
555
  }
421
556
  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;
422
613
  }() // 添加单个账户或者 guest
423
- )
424
614
  }, {
425
615
  key: "addAccount",
426
616
  value: function () {
427
- var _addAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(account, extra) {
617
+ var _addAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(account, extra) {
428
618
  var accountModules, newAccount;
429
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
430
- while (1) switch (_context6.prev = _context6.next) {
619
+ return _regeneratorRuntime().wrap(function _callee8$(_context9) {
620
+ while (1) switch (_context9.prev = _context9.next) {
431
621
  case 0:
432
622
  if (!((extra === null || extra === void 0 ? void 0 : extra.type) === 'holder')) {
433
- _context6.next = 5;
623
+ _context9.next = 5;
434
624
  break;
435
625
  }
436
- _context6.next = 3;
626
+ _context9.next = 3;
437
627
  return this.store.accountList.addHolderAccounts({
438
628
  holders: [account],
439
629
  customerId: extra.customerId,
440
630
  type: 'unshift'
441
631
  });
442
632
  case 3:
443
- accountModules = _context6.sent;
444
- return _context6.abrupt("return", accountModules[0].getAccount());
633
+ accountModules = _context9.sent;
634
+ return _context9.abrupt("return", accountModules[0].getAccount());
445
635
  case 5:
446
- _context6.next = 7;
636
+ _context9.next = 7;
447
637
  return this.store.accountList.addAccount(account);
448
638
  case 7:
449
- newAccount = _context6.sent;
450
- return _context6.abrupt("return", newAccount.getAccount());
639
+ newAccount = _context9.sent;
640
+ return _context9.abrupt("return", newAccount.getAccount());
451
641
  case 9:
452
642
  case "end":
453
- return _context6.stop();
643
+ return _context9.stop();
454
644
  }
455
- }, _callee6, this);
645
+ }, _callee8, this);
456
646
  }));
457
- function addAccount(_x7, _x8) {
647
+ function addAccount(_x8, _x9) {
458
648
  return _addAccount.apply(this, arguments);
459
649
  }
460
650
  return addAccount;
@@ -462,13 +652,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
462
652
  }, {
463
653
  key: "addAccounts",
464
654
  value: function () {
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) {
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) {
469
659
  case 0:
470
660
  if (!((extra === null || extra === void 0 ? void 0 : extra.type) === 'holder')) {
471
- _context7.next = 3;
661
+ _context10.next = 3;
472
662
  break;
473
663
  }
474
664
  this.store.accountList.addHolderAccounts({
@@ -476,49 +666,49 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
476
666
  customerId: extra.customerId,
477
667
  type: 'unshift'
478
668
  });
479
- return _context7.abrupt("return");
669
+ return _context10.abrupt("return");
480
670
  case 3:
481
671
  res = [];
482
- _iterator = _createForOfIteratorHelper(accounts);
483
- _context7.prev = 5;
484
- _iterator.s();
672
+ _iterator2 = _createForOfIteratorHelper(accounts);
673
+ _context10.prev = 5;
674
+ _iterator2.s();
485
675
  case 7:
486
- if ((_step = _iterator.n()).done) {
487
- _context7.next = 16;
676
+ if ((_step2 = _iterator2.n()).done) {
677
+ _context10.next = 16;
488
678
  break;
489
679
  }
490
- account = _step.value;
491
- _context7.next = 11;
680
+ account = _step2.value;
681
+ _context10.next = 11;
492
682
  return this.store.accountList.addAccount(account);
493
683
  case 11:
494
- accountModule = _context7.sent;
684
+ accountModule = _context10.sent;
495
685
  accountData = accountModule.getAccount();
496
686
  if (accountData) {
497
687
  res.push(accountData);
498
688
  }
499
689
  case 14:
500
- _context7.next = 7;
690
+ _context10.next = 7;
501
691
  break;
502
692
  case 16:
503
- _context7.next = 21;
693
+ _context10.next = 21;
504
694
  break;
505
695
  case 18:
506
- _context7.prev = 18;
507
- _context7.t0 = _context7["catch"](5);
508
- _iterator.e(_context7.t0);
696
+ _context10.prev = 18;
697
+ _context10.t0 = _context10["catch"](5);
698
+ _iterator2.e(_context10.t0);
509
699
  case 21:
510
- _context7.prev = 21;
511
- _iterator.f();
512
- return _context7.finish(21);
700
+ _context10.prev = 21;
701
+ _iterator2.f();
702
+ return _context10.finish(21);
513
703
  case 24:
514
- return _context7.abrupt("return", res);
704
+ return _context10.abrupt("return", res);
515
705
  case 25:
516
706
  case "end":
517
- return _context7.stop();
707
+ return _context10.stop();
518
708
  }
519
- }, _callee7, this, [[5, 18, 21, 24]]);
709
+ }, _callee9, this, [[5, 18, 21, 24]]);
520
710
  }));
521
- function addAccounts(_x9, _x10) {
711
+ function addAccounts(_x10, _x11) {
522
712
  return _addAccounts.apply(this, arguments);
523
713
  }
524
714
  return addAccounts;
@@ -526,20 +716,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
526
716
  }, {
527
717
  key: "getAccounts",
528
718
  value: function () {
529
- var _getAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
719
+ var _getAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
530
720
  var accounts;
531
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
532
- while (1) switch (_context8.prev = _context8.next) {
721
+ return _regeneratorRuntime().wrap(function _callee10$(_context11) {
722
+ while (1) switch (_context11.prev = _context11.next) {
533
723
  case 0:
534
724
  accounts = this.store.accountList.getAccounts();
535
- return _context8.abrupt("return", accounts.map(function (account) {
725
+ return _context11.abrupt("return", accounts.map(function (account) {
536
726
  return account.getAccount();
537
727
  }));
538
728
  case 2:
539
729
  case "end":
540
- return _context8.stop();
730
+ return _context11.stop();
541
731
  }
542
- }, _callee8, this);
732
+ }, _callee10, this);
543
733
  }));
544
734
  function getAccounts() {
545
735
  return _getAccounts.apply(this, arguments);
@@ -563,8 +753,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
563
753
  key: "getActiveAccount",
564
754
  value: function getActiveAccount() {
565
755
  var activeAccount = this.store.accountList.getActiveAccount();
566
- var account = activeAccount === null || activeAccount === void 0 ? void 0 : activeAccount.getAccount();
567
- return account === null ? undefined : account;
756
+ return activeAccount ? activeAccount.getAccount() : null;
568
757
  }
569
758
  }, {
570
759
  key: "removeAccount",
@@ -581,10 +770,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
581
770
  }, {
582
771
  key: "fetchHolderAccountsAsync",
583
772
  value: (function () {
584
- var _fetchHolderAccountsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
773
+ var _fetchHolderAccountsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
585
774
  var cartItems, _this$store$date$getD, date, normalProductCartItem;
586
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
587
- while (1) switch (_context9.prev = _context9.next) {
775
+ return _regeneratorRuntime().wrap(function _callee11$(_context12) {
776
+ while (1) switch (_context12.prev = _context12.next) {
588
777
  case 0:
589
778
  cartItems = this.store.cart.getItems();
590
779
  if (cartItems.length) {
@@ -599,14 +788,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
599
788
  }
600
789
  this.updateQuotationPriceAndCart(date);
601
790
  }
602
- return _context9.abrupt("return", this.store.accountList.fetchHolderAccounts(params));
791
+ return _context12.abrupt("return", this.store.accountList.fetchHolderAccounts(params));
603
792
  case 3:
604
793
  case "end":
605
- return _context9.stop();
794
+ return _context12.stop();
606
795
  }
607
- }, _callee9, this);
796
+ }, _callee11, this);
608
797
  }));
609
- function fetchHolderAccountsAsync(_x11) {
798
+ function fetchHolderAccountsAsync(_x12) {
610
799
  return _fetchHolderAccountsAsync.apply(this, arguments);
611
800
  }
612
801
  return fetchHolderAccountsAsync;
@@ -615,9 +804,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
615
804
  }, {
616
805
  key: "setDateRange",
617
806
  value: function () {
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) {
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) {
621
810
  case 0:
622
811
  this.store.date.setDateRange(dateRange);
623
812
  // 日期数据变更后,如果购物车里有数据,需要更新购物车里的报价单的价格
@@ -626,11 +815,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
626
815
  }
627
816
  case 2:
628
817
  case "end":
629
- return _context10.stop();
818
+ return _context13.stop();
630
819
  }
631
- }, _callee10, this);
820
+ }, _callee12, this);
632
821
  }));
633
- function setDateRange(_x12) {
822
+ function setDateRange(_x13) {
634
823
  return _setDateRange.apply(this, arguments);
635
824
  }
636
825
  return setDateRange;
@@ -645,16 +834,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
645
834
  }, {
646
835
  key: "getDateRange",
647
836
  value: function () {
648
- var _getDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
649
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
650
- while (1) switch (_context11.prev = _context11.next) {
837
+ var _getDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
838
+ return _regeneratorRuntime().wrap(function _callee13$(_context14) {
839
+ while (1) switch (_context14.prev = _context14.next) {
651
840
  case 0:
652
- return _context11.abrupt("return", this.store.date.getDateRange());
841
+ return _context14.abrupt("return", this.store.date.getDateRange());
653
842
  case 1:
654
843
  case "end":
655
- return _context11.stop();
844
+ return _context14.stop();
656
845
  }
657
- }, _callee11, this);
846
+ }, _callee13, this);
658
847
  }));
659
848
  function getDateRange() {
660
849
  return _getDateRange.apply(this, arguments);
@@ -671,7 +860,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
671
860
  }, {
672
861
  key: "getAvailableDate",
673
862
  value: function () {
674
- var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
863
+ var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
675
864
  var _this4 = this,
676
865
  _dateRange$,
677
866
  _dateRange$2,
@@ -685,16 +874,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
685
874
  dateRange,
686
875
  tempStartDate,
687
876
  tempEndDate,
688
- _ref4,
877
+ _ref5,
689
878
  resourceIds,
690
879
  rules,
691
880
  resourcesMap,
692
881
  res,
693
- _args12 = arguments;
694
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
695
- while (1) switch (_context12.prev = _context12.next) {
882
+ _args15 = arguments;
883
+ return _regeneratorRuntime().wrap(function _callee14$(_context15) {
884
+ while (1) switch (_context15.prev = _context15.next) {
696
885
  case 0:
697
- params = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
886
+ params = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
698
887
  // 开始日期如果小于今天,直接以今天当做开始日期
699
888
  products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
700
889
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -721,15 +910,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
721
910
  tempStartDate = startDate || (dateRange === null || dateRange === void 0 || (_dateRange$ = dateRange[0]) === null || _dateRange$ === void 0 ? void 0 : _dateRange$.date);
722
911
  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);
723
912
  if (tempProducts.length) {
724
- _context12.next = 11;
913
+ _context15.next = 11;
725
914
  break;
726
915
  }
727
- return _context12.abrupt("return", []);
916
+ return _context15.abrupt("return", []);
728
917
  case 11:
729
918
  // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
730
- _ref4 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref4.resourceIds, rules = _ref4.rules, resourcesMap = _ref4.resourcesMap;
919
+ _ref5 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref5.resourceIds, rules = _ref5.rules, resourcesMap = _ref5.resourcesMap;
731
920
  this.otherParams.currentResourcesMap = resourcesMap;
732
- _context12.next = 15;
921
+ _context15.next = 15;
733
922
  return this.store.date.getResourceDates({
734
923
  url: params.url,
735
924
  query: {
@@ -741,13 +930,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
741
930
  type: type
742
931
  });
743
932
  case 15:
744
- res = _context12.sent;
745
- return _context12.abrupt("return", res);
933
+ res = _context15.sent;
934
+ return _context15.abrupt("return", res);
746
935
  case 17:
747
936
  case "end":
748
- return _context12.stop();
937
+ return _context15.stop();
749
938
  }
750
- }, _callee12, this);
939
+ }, _callee14, this);
751
940
  }));
752
941
  function getAvailableDate() {
753
942
  return _getAvailableDate.apply(this, arguments);
@@ -760,22 +949,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
760
949
  }, {
761
950
  key: "getSummary",
762
951
  value: (function () {
763
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
952
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
764
953
  var cartItems, summary;
765
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
766
- while (1) switch (_context13.prev = _context13.next) {
954
+ return _regeneratorRuntime().wrap(function _callee15$(_context16) {
955
+ while (1) switch (_context16.prev = _context16.next) {
767
956
  case 0:
768
957
  cartItems = this.store.cart.getItems();
769
- _context13.next = 3;
958
+ _context16.next = 3;
770
959
  return this.store.summary.getSummary(cartItems);
771
960
  case 3:
772
- summary = _context13.sent;
773
- return _context13.abrupt("return", summary);
961
+ summary = _context16.sent;
962
+ return _context16.abrupt("return", summary);
774
963
  case 5:
775
964
  case "end":
776
- return _context13.stop();
965
+ return _context16.stop();
777
966
  }
778
- }, _callee13, this);
967
+ }, _callee15, this);
779
968
  }));
780
969
  function getSummary() {
781
970
  return _getSummary.apply(this, arguments);
@@ -789,18 +978,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
789
978
  }, {
790
979
  key: "getProtocol",
791
980
  value: (function () {
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) {
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) {
795
984
  case 0:
796
- return _context14.abrupt("return", this.store.summary.getProtocol(protocolId));
985
+ return _context17.abrupt("return", this.store.summary.getProtocol(protocolId));
797
986
  case 1:
798
987
  case "end":
799
- return _context14.stop();
988
+ return _context17.stop();
800
989
  }
801
- }, _callee14, this);
990
+ }, _callee16, this);
802
991
  }));
803
- function getProtocol(_x13) {
992
+ function getProtocol(_x14) {
804
993
  return _getProtocol.apply(this, arguments);
805
994
  }
806
995
  return getProtocol;
@@ -809,16 +998,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
809
998
  }, {
810
999
  key: "getProducts",
811
1000
  value: function () {
812
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
813
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
814
- while (1) switch (_context15.prev = _context15.next) {
1001
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1002
+ return _regeneratorRuntime().wrap(function _callee17$(_context18) {
1003
+ while (1) switch (_context18.prev = _context18.next) {
815
1004
  case 0:
816
- return _context15.abrupt("return", this.store.products.getProducts());
1005
+ return _context18.abrupt("return", this.store.products.getProducts());
817
1006
  case 1:
818
1007
  case "end":
819
- return _context15.stop();
1008
+ return _context18.stop();
820
1009
  }
821
- }, _callee15, this);
1010
+ }, _callee17, this);
822
1011
  }));
823
1012
  function getProducts() {
824
1013
  return _getProducts.apply(this, arguments);
@@ -828,15 +1017,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
828
1017
  }, {
829
1018
  key: "setLoginAccount",
830
1019
  value: function () {
831
- var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(accountId, accountInfo) {
1020
+ var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(accountId, accountInfo) {
832
1021
  var _this5 = this;
833
1022
  var account, stateAccountId, cartItems, _this$store$date$getD2, date, normalProductCartItem;
834
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
835
- while (1) switch (_context16.prev = _context16.next) {
1023
+ return _regeneratorRuntime().wrap(function _callee18$(_context19) {
1024
+ while (1) switch (_context19.prev = _context19.next) {
836
1025
  case 0:
837
1026
  account = this.store.accountList.getAccount(accountId);
838
1027
  if (!account) {
839
- _context16.next = 11;
1028
+ _context19.next = 11;
840
1029
  break;
841
1030
  }
842
1031
  stateAccountId = account.getId();
@@ -865,17 +1054,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
865
1054
  }
866
1055
  this.updateQuotationPriceAndCart(date);
867
1056
  }
868
- _context16.next = 12;
1057
+ _context19.next = 12;
869
1058
  break;
870
1059
  case 11:
871
1060
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
872
1061
  case 12:
873
1062
  case "end":
874
- return _context16.stop();
1063
+ return _context19.stop();
875
1064
  }
876
- }, _callee16, this);
1065
+ }, _callee18, this);
877
1066
  }));
878
- function setLoginAccount(_x14, _x15) {
1067
+ function setLoginAccount(_x15, _x16) {
879
1068
  return _setLoginAccount.apply(this, arguments);
880
1069
  }
881
1070
  return setLoginAccount;
@@ -883,14 +1072,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
883
1072
  }, {
884
1073
  key: "generateCartData",
885
1074
  value: function () {
886
- var _generateCartData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
887
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
888
- while (1) switch (_context17.prev = _context17.next) {
1075
+ var _generateCartData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1076
+ return _regeneratorRuntime().wrap(function _callee19$(_context20) {
1077
+ while (1) switch (_context20.prev = _context20.next) {
889
1078
  case 0:
890
1079
  case "end":
891
- return _context17.stop();
1080
+ return _context20.stop();
892
1081
  }
893
- }, _callee17);
1082
+ }, _callee19);
894
1083
  }));
895
1084
  function generateCartData() {
896
1085
  return _generateCartData.apply(this, arguments);
@@ -900,23 +1089,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
900
1089
  }, {
901
1090
  key: "getFreeProduct",
902
1091
  value: function () {
903
- var _getFreeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(id) {
1092
+ var _getFreeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(id) {
904
1093
  var res;
905
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
906
- while (1) switch (_context18.prev = _context18.next) {
1094
+ return _regeneratorRuntime().wrap(function _callee20$(_context21) {
1095
+ while (1) switch (_context21.prev = _context21.next) {
907
1096
  case 0:
908
- _context18.next = 2;
1097
+ _context21.next = 2;
909
1098
  return this.request.post("/pay/order/free-pay/".concat(id));
910
1099
  case 2:
911
- res = _context18.sent;
912
- return _context18.abrupt("return", res);
1100
+ res = _context21.sent;
1101
+ return _context21.abrupt("return", res);
913
1102
  case 4:
914
1103
  case "end":
915
- return _context18.stop();
1104
+ return _context21.stop();
916
1105
  }
917
- }, _callee18, this);
1106
+ }, _callee20, this);
918
1107
  }));
919
- function getFreeProduct(_x16) {
1108
+ function getFreeProduct(_x17) {
920
1109
  return _getFreeProduct.apply(this, arguments);
921
1110
  }
922
1111
  return getFreeProduct;
@@ -939,16 +1128,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
939
1128
  }, {
940
1129
  key: "submitOrder",
941
1130
  value: function () {
942
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1131
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
943
1132
  var cartItems, newCartItems, type;
944
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
945
- while (1) switch (_context19.prev = _context19.next) {
1133
+ return _regeneratorRuntime().wrap(function _callee21$(_context22) {
1134
+ while (1) switch (_context22.prev = _context22.next) {
946
1135
  case 0:
947
1136
  cartItems = this.store.cart.getItems();
948
1137
  newCartItems = cloneDeep(cartItems); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
949
1138
  newCartItems.forEach(function (item) {
950
1139
  if (item._origin.resources && item._origin.resources.length) {
951
- var _item$_origin;
1140
+ var _item$_productOrigin, _item$_origin;
952
1141
  item._origin.resources = item._origin.resources.map(function (n) {
953
1142
  var newResourcesItem = cloneDeep(n);
954
1143
  delete newResourcesItem.id;
@@ -956,9 +1145,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
956
1145
  delete newResourcesItem.resourceType;
957
1146
  return _objectSpread({}, newResourcesItem);
958
1147
  });
959
- var _getCapacityInfoByCar = getCapacityInfoByCartItem(item),
960
- currentCapacity = _getCapacityInfoByCar.currentCapacity,
961
- formatCapacity = _getCapacityInfoByCar.formatCapacity;
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
+ });
962
1155
  if (!((_item$_origin = item._origin) !== null && _item$_origin !== void 0 && _item$_origin.metadata)) {
963
1156
  item._origin.metadata = {};
964
1157
  }
@@ -972,7 +1165,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
972
1165
  }))) {
973
1166
  type = 'virtual';
974
1167
  }
975
- return _context19.abrupt("return", this.store.order.submitOrder({
1168
+ return _context22.abrupt("return", this.store.order.submitOrder({
976
1169
  query: {
977
1170
  cartItems: newCartItems,
978
1171
  type: type
@@ -980,9 +1173,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
980
1173
  }));
981
1174
  case 6:
982
1175
  case "end":
983
- return _context19.stop();
1176
+ return _context22.stop();
984
1177
  }
985
- }, _callee19, this);
1178
+ }, _callee21, this);
986
1179
  }));
987
1180
  function submitOrder() {
988
1181
  return _submitOrder.apply(this, arguments);
@@ -992,14 +1185,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
992
1185
  }, {
993
1186
  key: "pay",
994
1187
  value: function () {
995
- var _pay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
996
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
997
- while (1) switch (_context20.prev = _context20.next) {
1188
+ var _pay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1189
+ return _regeneratorRuntime().wrap(function _callee22$(_context23) {
1190
+ while (1) switch (_context23.prev = _context23.next) {
998
1191
  case 0:
999
1192
  case "end":
1000
- return _context20.stop();
1193
+ return _context23.stop();
1001
1194
  }
1002
- }, _callee20);
1195
+ }, _callee22);
1003
1196
  }));
1004
1197
  function pay() {
1005
1198
  return _pay.apply(this, arguments);
@@ -1009,14 +1202,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1009
1202
  }, {
1010
1203
  key: "getPayInfo",
1011
1204
  value: function () {
1012
- var _getPayInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1013
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1014
- while (1) switch (_context21.prev = _context21.next) {
1205
+ var _getPayInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1206
+ return _regeneratorRuntime().wrap(function _callee23$(_context24) {
1207
+ while (1) switch (_context24.prev = _context24.next) {
1015
1208
  case 0:
1016
1209
  case "end":
1017
- return _context21.stop();
1210
+ return _context24.stop();
1018
1211
  }
1019
- }, _callee21);
1212
+ }, _callee23);
1020
1213
  }));
1021
1214
  function getPayInfo() {
1022
1215
  return _getPayInfo.apply(this, arguments);
@@ -1026,15 +1219,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1026
1219
  }, {
1027
1220
  key: "setOtherParams",
1028
1221
  value: function () {
1029
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
1030
- var _ref5,
1031
- _ref5$cover,
1222
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
1223
+ var _ref6,
1224
+ _ref6$cover,
1032
1225
  cover,
1033
- _args22 = arguments;
1034
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1035
- while (1) switch (_context22.prev = _context22.next) {
1226
+ _args25 = arguments;
1227
+ return _regeneratorRuntime().wrap(function _callee24$(_context25) {
1228
+ while (1) switch (_context25.prev = _context25.next) {
1036
1229
  case 0:
1037
- _ref5 = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
1230
+ _ref6 = _args25.length > 1 && _args25[1] !== undefined ? _args25[1] : {}, _ref6$cover = _ref6.cover, cover = _ref6$cover === void 0 ? false : _ref6$cover;
1038
1231
  if (cover) {
1039
1232
  this.otherParams = params;
1040
1233
  } else {
@@ -1042,11 +1235,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1042
1235
  }
1043
1236
  case 2:
1044
1237
  case "end":
1045
- return _context22.stop();
1238
+ return _context25.stop();
1046
1239
  }
1047
- }, _callee22, this);
1240
+ }, _callee24, this);
1048
1241
  }));
1049
- function setOtherParams(_x17) {
1242
+ function setOtherParams(_x18) {
1050
1243
  return _setOtherParams.apply(this, arguments);
1051
1244
  }
1052
1245
  return setOtherParams;
@@ -1054,193 +1247,51 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1054
1247
  }, {
1055
1248
  key: "getOtherParams",
1056
1249
  value: function () {
1057
- var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1058
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1059
- while (1) switch (_context23.prev = _context23.next) {
1250
+ var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1251
+ return _regeneratorRuntime().wrap(function _callee25$(_context26) {
1252
+ while (1) switch (_context26.prev = _context26.next) {
1060
1253
  case 0:
1061
- return _context23.abrupt("return", this.otherParams);
1254
+ return _context26.abrupt("return", this.otherParams);
1062
1255
  case 1:
1063
1256
  case "end":
1064
- return _context23.stop();
1257
+ return _context26.stop();
1065
1258
  }
1066
- }, _callee23, this);
1259
+ }, _callee25, this);
1067
1260
  }));
1068
1261
  function getOtherParams() {
1069
1262
  return _getOtherParams.apply(this, arguments);
1070
1263
  }
1071
1264
  return getOtherParams;
1072
- }()
1073
- /**
1074
- * 往购物车加商品数据(duration 类、普通商品)
1075
- * 老接口,先不删,怕 UI 有问题,直接桥接到新接口addProductToCart上
1076
- *
1077
- * @param {ProductData} productData
1078
- * @memberof BookingByStepImpl
1079
- */
1080
- }, {
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);
1102
- }
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
- */
1265
+ }() // 更新购物车
1176
1266
  }, {
1177
- key: "addProductCheck",
1178
- value: function addProductCheck(_ref8) {
1267
+ key: "updateCart",
1268
+ value: function updateCart(params) {
1179
1269
  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);
1185
- });
1186
- var cartItemsByDate = cartItems.filter(function (n) {
1187
- return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
1188
- });
1189
- if (cartItemsByDate.length) {
1190
- cartItemsByDate.forEach(function (n) {
1191
- _this6.store.cart.removeItem(n._id);
1192
- });
1193
- }
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"));
1194
1273
  }
1195
- }
1196
- }, {
1197
- key: "beforeUpdateCart",
1198
- value: function beforeUpdateCart(params, targetCartItem) {
1274
+ var currentResourcesCapacityMap = {};
1199
1275
  if (params.resources) {
1200
- var _getCapacityInfoByCar2 = getCapacityInfoByCartItem(targetCartItem),
1201
- currentCapacity = _getCapacityInfoByCar2.currentCapacity;
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
1280
+ });
1281
+ var currentCapacity = getSumCapacity({
1282
+ capacity: formatCapacity
1283
+ });
1202
1284
  params.resources = params.resources.map(function (n) {
1203
1285
  n.capacity = currentCapacity || 1;
1286
+ currentResourcesCapacityMap[n.id] = currentCapacity;
1204
1287
  checkSubResourcesCapacity(n);
1205
1288
  return n;
1206
1289
  });
1207
1290
  }
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);
1219
1291
  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
- // 零售模板不需要检测
1237
1292
  if (this.otherParams.isRetailTemplate) {
1238
1293
  return;
1239
1294
  }
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
- });
1244
1295
  var allOriginResources = [];
1245
1296
  var dateRange = this.store.date.getDateRange();
1246
1297
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -1262,27 +1313,48 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1262
1313
  cartItems.forEach(function (item) {
1263
1314
  if (item._id !== targetCartItem._id) {
1264
1315
  var _item$_origin$resourc;
1265
- var _getCapacityInfoByCar3 = getCapacityInfoByCartItem(item),
1266
- currentCapacity = _getCapacityInfoByCar3.currentCapacity;
1267
1316
  var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1268
1317
  // 检查当前资源是否与目标资源的任何资源匹配
1269
1318
  // 目标资源,应该只取跟当前 m.form_id 相同的资源
1270
- var sameFormIdResources = filterResourcesByFormItem(targetCartItem._origin.resources, m.form_id);
1319
+ var sameFormIdResources = targetCartItem._origin.resources.filter(function (n) {
1320
+ return n.form_id === m.form_id;
1321
+ });
1271
1322
  if (!(sameFormIdResources !== null && sameFormIdResources !== void 0 && sameFormIdResources.length)) {
1272
1323
  return true;
1273
1324
  }
1274
1325
  return !sameFormIdResources.some(function (targetRes) {
1275
1326
  // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1276
1327
  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
+ });
1277
1336
  var originResource = allOriginResources.find(function (n) {
1278
1337
  return n.id === targetRes.id;
1279
1338
  });
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;
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;
1283
1344
  }
1284
1345
  if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1285
- return checkTwoResourcesIntersection(targetRes, m);
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;
1286
1358
  }
1287
1359
  return false;
1288
1360
  });
@@ -1293,7 +1365,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1293
1365
  var end_time = item.end_time;
1294
1366
  var start_date = item.start_date;
1295
1367
  var end_date = item.end_date;
1296
- _this7.store.cart.updateItem({
1368
+ _this6.store.cart.updateItem({
1297
1369
  _id: item._id,
1298
1370
  resources: resources,
1299
1371
  date: {
@@ -1302,7 +1374,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1302
1374
  }
1303
1375
  });
1304
1376
  } else {
1305
- _this7.store.cart.updateItem({
1377
+ _this6.store.cart.updateItem({
1306
1378
  _id: item._id,
1307
1379
  resources: resources
1308
1380
  });
@@ -1339,10 +1411,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1339
1411
  }, {
1340
1412
  key: "batchUpdateCart",
1341
1413
  value: function batchUpdateCart(paramsList) {
1342
- var _this8 = this;
1414
+ var _this7 = this;
1343
1415
  var cartItems = [];
1344
1416
  paramsList.forEach(function (params) {
1345
- var cartItem = _this8.store.cart.formatCartItem(params);
1417
+ var cartItem = _this7.store.cart.formatCartItem(params);
1346
1418
  cartItems.push(cartItem);
1347
1419
  });
1348
1420
  this.store.cart.batchSetItems(cartItems);
@@ -1370,82 +1442,208 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1370
1442
  }, {
1371
1443
  key: "checkCartItems",
1372
1444
  value: function checkCartItems(type) {
1373
- var _this9 = this;
1445
+ var _this8 = this;
1374
1446
  // 预约流程中普通商品无需检测这些东西
1375
1447
  var cartItems = this.store.cart.getItems().filter(function (n) {
1376
1448
  return !isNormalProduct(n._productOrigin);
1377
1449
  });
1378
1450
  var errorCartItemIds = [];
1379
1451
  cartItems.forEach(function (cartItem) {
1380
- var result = _this9.store.cart.checkCartItemByType(cartItem, type);
1452
+ var result = _this8.store.cart.checkCartItemByType(cartItem, type);
1381
1453
  if (!result) {
1382
1454
  errorCartItemIds.push(cartItem._id);
1383
1455
  }
1384
1456
  });
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);
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 || (_this9$shopStore$get = _this9$shopStore$get.operating_day_boundary) === null || _this9$shopStore$get === void 0 ? void 0 : _this9$shopStore$get.time;
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
+ });
1592
+ }
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
+ });
1604
+ return arr;
1399
1605
  }
1400
1606
 
1401
- // 获取当前购物车内所有关联的资源列表,拼装数据格式
1607
+ // 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
1402
1608
  }, {
1403
- key: "getResourcesList",
1404
- value: function getResourcesList() {
1405
- var _this10 = this;
1609
+ key: "checkResourceListForDate",
1610
+ value: function checkResourceListForDate() {
1406
1611
  var dateRange = this.store.date.getDateRange();
1407
1612
  var resources = [];
1408
1613
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
1409
1614
  dateRange.forEach(function (n) {
1410
- resources.push.apply(resources, _toConsumableArray(_this10.store.date.getResourcesListByDate(n.date) || []));
1615
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1411
1616
  });
1412
1617
  }
1413
- var cartItems = this.store.cart.getItems().filter(function (n) {
1414
- return !isNormalProduct(n._productOrigin);
1415
- });
1416
-
1417
1618
  // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1418
1619
  if (!resources.length) {
1419
- // 如果此时购物车里已经有了开始时间,则直接取那天的数据即可
1420
- var firstDateCartItem = cartItems === null || cartItems === void 0 ? void 0 : cartItems.find(function (n) {
1421
- return n.start_date;
1620
+ var dateList = this.store.date.getDateList();
1621
+ dateList.forEach(function (n) {
1622
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1422
1623
  });
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
- }
1432
1624
  }
1433
1625
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1626
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1627
+ return !isNormalProduct(n._productOrigin);
1628
+ });
1434
1629
  var arr = [];
1435
1630
  cartItems.forEach(function (cartItem) {
1436
- var _cartItem$_productOri;
1631
+ var _cartItem$_productOri7, _cartItem$_productOri8;
1437
1632
  var selectedResources = [];
1438
- var _getCapacityInfoByCar4 = getCapacityInfoByCartItem(cartItem),
1439
- currentCapacity = _getCapacityInfoByCar4.currentCapacity,
1440
- formatCapacity = _getCapacityInfoByCar4.formatCapacity;
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
+ });
1441
1637
  cartItem._origin.metadata.capacity = formatCapacity;
1638
+ var currentCapacity = getSumCapacity({
1639
+ capacity: formatCapacity
1640
+ });
1442
1641
  if (cartItem.holder_id) {
1443
1642
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1444
1643
  } else {
1445
1644
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1446
1645
  }
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);
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);
1449
1647
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1450
1648
  if (cartItem._origin.start_time) {
1451
1649
  var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
@@ -1453,18 +1651,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1453
1651
  var resourcesUseableMap = {};
1454
1652
  productResources.forEach(function (n) {
1455
1653
  // 资源排下序,把单个资源靠前,组合资源排在后面
1456
- n.renderList = sortCombinedResources(n.renderList);
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
+ });
1457
1662
  n.renderList = n.renderList.filter(function (m) {
1458
1663
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1459
1664
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1460
1665
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1461
- var mTimes = filterConditionTimeSlots(m.times, startTime, endTime);
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
+ });
1462
1669
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1463
1670
  if (mTimes.length === 0) {
1464
1671
  return false;
1465
1672
  }
1466
1673
  var canUseArr = mTimes.map(function (item) {
1467
- var _cartItem$_productOri2;
1674
+ var _cartItem$_productOri9;
1468
1675
  var res = getIsUsableByTimeItem({
1469
1676
  timeSlice: {
1470
1677
  start_time: startTime.format('HH:mm'),
@@ -1476,9 +1683,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1476
1683
  resource: m,
1477
1684
  currentCount: currentCapacity || 0,
1478
1685
  resourcesUseableMap: resourcesUseableMap,
1479
- cut_off_time: (_cartItem$_productOri2 = cartItem._productOrigin) === null || _cartItem$_productOri2 === void 0 ? void 0 : _cartItem$_productOri2.cut_off_time
1686
+ cut_off_time: (_cartItem$_productOri9 = cartItem._productOrigin) === null || _cartItem$_productOri9 === void 0 ? void 0 : _cartItem$_productOri9.cut_off_time
1480
1687
  });
1481
- // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况(因为组合资源还需要判断子资源够不够)
1688
+ // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1482
1689
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1483
1690
  resourcesUseableMap[m.id] = res.usable;
1484
1691
  }
@@ -1492,25 +1699,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1492
1699
  });
1493
1700
  });
1494
1701
  } 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;
1498
1702
  productResources.forEach(function (item) {
1499
1703
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1500
1704
  // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1501
1705
  item.renderList = item.renderList.filter(function (n) {
1502
- var _cartItem$_productOri4, _cartItem$_productOri5;
1706
+ var _cartItem$_productOri10;
1503
1707
  var recordCount = n.capacity || 0;
1504
1708
  if (n.onlyComputed) return false;
1505
1709
  // 查一下这个资源基于商品的可用时间片
1506
1710
  var timeSlots = getTimeSlicesByResource({
1507
1711
  resource: n,
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,
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,
1509
1713
  split: 10,
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
1714
+ currentDate: dateRange[0].date
1514
1715
  });
1515
1716
  return recordCount >= currentCapacity && timeSlots.length > 0;
1516
1717
  });
@@ -1521,46 +1722,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1521
1722
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1522
1723
  _id: cartItem._id,
1523
1724
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1524
- product: cartItem._productOrigin,
1525
- resources: productResources,
1526
- holder_id: cartItem.holder_id,
1527
- holder_name: cartItem.holder_title
1725
+ productResources: productResources
1528
1726
  });
1529
1727
  });
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;
1728
+ // 检查 productResources里是不是每一项资源的 renderList 里都有数据
1729
+ var hasResource = arr.every(function (n) {
1730
+ return n.productResources.every(function (m) {
1731
+ return m.renderList.length > 0;
1548
1732
  });
1549
1733
  });
1550
1734
  return hasResource;
1551
1735
  }
1552
1736
 
1553
- /**
1554
- * 给单个购物车里的商品获取资源列表,给 UI 用的
1555
- *
1556
- * @param {(string | number)} id
1557
- * @return {*}
1558
- * @memberof BookingByStepImpl
1559
- */
1737
+ // 给单个购物车里的商品获取资源列表
1560
1738
  }, {
1561
1739
  key: "getResourcesListByCartItem",
1562
1740
  value: function getResourcesListByCartItem(id) {
1563
- var _targetCartItem$_prod;
1741
+ var _targetCartItem$_prod2, _targetCartItem$_prod3;
1564
1742
  var cartItems = this.store.cart.getItems().filter(function (n) {
1565
1743
  return !isNormalProduct(n._productOrigin);
1566
1744
  });
@@ -1578,14 +1756,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1578
1756
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1579
1757
  }
1580
1758
  var selectedResources = [];
1581
- var _getCapacityInfoByCar5 = getCapacityInfoByCartItem(targetCartItem),
1582
- currentCapacity = _getCapacityInfoByCar5.currentCapacity;
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
+ });
1583
1766
  if (targetCartItem.holder_id) {
1584
1767
  selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1585
1768
  } else {
1586
1769
  selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1587
1770
  }
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);
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);
1589
1772
  productResources.forEach(function (item) {
1590
1773
  item.renderList = item.renderList.filter(function (n) {
1591
1774
  var recordCount = n.capacity || 0;
@@ -1607,17 +1790,36 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1607
1790
  }
1608
1791
  }
1609
1792
 
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
+
1610
1812
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
1611
1813
  }, {
1612
1814
  key: "autoSelectAccountResources",
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;
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;
1621
1823
  if (isNormalProduct(cartItem._productOrigin)) {
1622
1824
  return {};
1623
1825
  }
@@ -1631,10 +1833,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1631
1833
  if (!accountCartItems.length) {
1632
1834
  accountCartItems = cartItems;
1633
1835
  }
1634
- // duration=所有商品时间的集合,如果是灵活时长,当做占用 10 分钟处理
1836
+ // duration=所有商品时间的集合
1635
1837
  var duration = accountCartItems.reduce(function (acc, n) {
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);
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);
1638
1840
  }, 0);
1639
1841
  var AllResources = [];
1640
1842
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -1652,15 +1854,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1652
1854
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1653
1855
  var allCartItems = cloneDeep(this.store.cart.getItems());
1654
1856
  var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
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);
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);
1656
1858
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1657
1859
  return n.code === resources_code;
1658
1860
  })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
1659
1861
  // 资源排下序,把单个资源靠前,组合资源排在后面
1660
1862
  resources.sort(function (a, b) {
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;
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;
1664
1866
  if (aIsCombined && !bIsCombined) return 1;
1665
1867
  if (!aIsCombined && bIsCombined) return -1;
1666
1868
  return 0;
@@ -1681,11 +1883,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1681
1883
  // 根据 start_time 和 end_time 去匹配资源
1682
1884
  var targetResource = null;
1683
1885
  var targetResourceTime = 0;
1684
- var _iterator2 = _createForOfIteratorHelper(resources),
1685
- _step2;
1886
+ var _iterator3 = _createForOfIteratorHelper(resources),
1887
+ _step3;
1686
1888
  try {
1687
- var _loop = function _loop() {
1688
- var n = _step2.value;
1889
+ var _loop2 = function _loop2() {
1890
+ var n = _step3.value;
1689
1891
  // 如果资源是独占的,并且 countMap 里选择过这个资源,则直接跳过
1690
1892
  // if (n.resourceType === 'single' && countMap[n.id]) {
1691
1893
  // resourcesUseableMap[n.id] = false;
@@ -1707,20 +1909,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1707
1909
  var hasOverlap = !dayjs(item.time.start_at).isAfter(dayjs(timeSlots.start_at)) && !dayjs(item.time.end_at).isBefore(dayjs(timeSlots.end_at));
1708
1910
  return hasOverlap ? sum + item.pax : sum;
1709
1911
  }, 0);
1710
-
1711
- // 如果资源是单个预约,并且有 totalCapacity,则认为在当前 timeSlots 资源已经被选择过,就不可用了
1712
- if (n.resourceType === 'single' && totalCapacity > 0) {
1713
- return 0; // continue
1714
- }
1715
1912
  var canUseTime = mTimes.find(function (item) {
1716
- var _cartItem$_productOri7;
1913
+ var _cartItem$_productOri12;
1717
1914
  var res = getIsUsableByTimeItem({
1718
1915
  timeSlice: timeSlots,
1719
1916
  time: item,
1720
1917
  resource: n,
1721
1918
  currentCount: totalCapacity + (capacity || 0),
1722
1919
  resourcesUseableMap: resourcesUseableMap,
1723
- cut_off_time: (_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.cut_off_time
1920
+ cut_off_time: (_cartItem$_productOri12 = cartItem._productOrigin) === null || _cartItem$_productOri12 === void 0 ? void 0 : _cartItem$_productOri12.cut_off_time
1724
1921
  });
1725
1922
  // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1726
1923
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
@@ -1740,15 +1937,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1740
1937
  }
1741
1938
  },
1742
1939
  _ret;
1743
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1744
- _ret = _loop();
1940
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1941
+ _ret = _loop2();
1745
1942
  if (_ret === 0) continue;
1746
1943
  if (_ret === 1) break;
1747
1944
  }
1748
1945
  } catch (err) {
1749
- _iterator2.e(err);
1946
+ _iterator3.e(err);
1750
1947
  } finally {
1751
- _iterator2.f();
1948
+ _iterator3.f();
1752
1949
  }
1753
1950
  return {
1754
1951
  selectedResource: targetResource
@@ -1783,7 +1980,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1783
1980
  key: "autoSelectAllProductResources",
1784
1981
  value: function autoSelectAllProductResources(resources_code, timeSlots) {
1785
1982
  var _dateRange$4,
1786
- _this11 = this;
1983
+ _this10 = this;
1787
1984
  var dateRange = this.store.date.getDateRange();
1788
1985
  var resources = [];
1789
1986
  if (dateRange !== null && dateRange !== void 0 && (_dateRange$4 = dateRange[0]) !== null && _dateRange$4 !== void 0 && _dateRange$4.date) {
@@ -1791,11 +1988,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1791
1988
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1792
1989
  });
1793
1990
  }
1991
+ // const resourcesMap = getResourcesMap(cloneDeep(resources));
1794
1992
  // 一个账号一个账号处理
1795
1993
  var errorList = [];
1796
- // 资源使用情况-单个预约
1797
1994
  var selectResourcesMap = {};
1798
- // 资源使用情况-多个预约
1799
1995
  var selectResourcesWithTimeSlots = {};
1800
1996
  var accountList = this.store.accountList.getAccounts();
1801
1997
  var selectForCartResources = function selectForCartResources(cartItems) {
@@ -1803,14 +1999,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1803
1999
  // timeSlots 传进来的只是用户选中的时间片,但是实际上需要根据多个商品时间进行累加
1804
2000
  // 假设 timeSlots.start_time 是15:40 duration 是 30min
1805
2001
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1806
- // 判断购物车里是否有 flexible 类型的商品,如果有则不累加时间
1807
- var hasFlexibleProduct = cartItems.some(function (item) {
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';
1810
- });
2002
+
1811
2003
  cartItems.forEach(function (item, index) {
1812
- var _getCapacityInfoByCar6 = getCapacityInfoByCartItem(item),
1813
- currentCapacity = _getCapacityInfoByCar6.currentCapacity;
2004
+ var _item$_productOrigin3;
2005
+ var formatCapacity = formatDefaultCapacitys({
2006
+ capacity: (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.capacity,
2007
+ product_bundle: item._origin.product.product_bundle
2008
+ });
2009
+ var currentCapacity = getSumCapacity({
2010
+ capacity: formatCapacity
2011
+ });
1814
2012
  // 如果商品已经有时间数据了,意味着是通过先选日期再选商品流程进来的,相当于时间切片已经选中了
1815
2013
  if (item._origin.start_time && !(timeSlots !== null && timeSlots !== void 0 && timeSlots.start_time)) {
1816
2014
  recordTimeSlots = {
@@ -1821,17 +2019,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1821
2019
  };
1822
2020
  }
1823
2021
  if (recordTimeSlots) {
1824
- var _item$_productOrigin2, _item$_productOrigin3;
2022
+ var _item$_productOrigin4, _item$_productOrigin5, _item$_productOrigin6;
1825
2023
  // 同一账号下,如果当前商品不是第一个,则需要根据上一个商品的 end_time 和 duration 计算出当前商品的 start_time 和 end_time
1826
2024
  // 前提:当前资源是单个预约才需要这么做
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) {
2025
+ var currentResourceConfig = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.product_resource) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.resources) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.find(function (n) {
1828
2026
  return n.code === resources_code;
1829
2027
  });
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');
2028
+ // 只有 duration 类商品需要这个操作
2029
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single' && (_item$_productOrigin5 = item._productOrigin) !== null && _item$_productOrigin5 !== void 0 && _item$_productOrigin5.duration && ((_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.type) !== 'flexible') {
2030
+ var _item$_productOrigin7, _item$_productOrigin8;
2031
+ 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');
2032
+ 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');
1835
2033
  recordTimeSlots = {
1836
2034
  start_time: start_at.format('HH:mm'),
1837
2035
  end_time: end_at.format('HH:mm'),
@@ -1840,7 +2038,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1840
2038
  };
1841
2039
  }
1842
2040
  // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
1843
- var res = _this11.autoSelectAccountResources({
2041
+ var res = _this10.autoSelectAccountResources({
1844
2042
  cartItem: item,
1845
2043
  holder_id: item.holder_id,
1846
2044
  resources_code: resources_code,
@@ -1848,6 +2046,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1848
2046
  countMap: selectResourcesWithTimeSlots,
1849
2047
  capacity: currentCapacity
1850
2048
  });
2049
+ // // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
2050
+ // if (item._origin.resources?.some((n: any) => n.form_id === res?.selectedResource?.form_id)) {
2051
+ // return
2052
+ // }
1851
2053
  if (res !== null && res !== void 0 && res.selectedResource) {
1852
2054
  if (!selectResourcesWithTimeSlots[res.selectedResource.id]) {
1853
2055
  selectResourcesWithTimeSlots[res.selectedResource.id] = [{
@@ -1862,7 +2064,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1862
2064
  }
1863
2065
  res.selectedResource.capacity = currentCapacity;
1864
2066
  checkSubResourcesCapacity(res.selectedResource);
1865
- _this11.store.cart.updateItem({
2067
+ _this10.store.cart.updateItem({
1866
2068
  _id: item._id,
1867
2069
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
1868
2070
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
@@ -1875,13 +2077,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1875
2077
  errorList.push(item._id);
1876
2078
  }
1877
2079
  } else {
1878
- var _item$_productOrigin6, _productResources$fin;
2080
+ var _item$_productOrigin9, _productResources$fin;
1879
2081
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1880
- // 能进到这种逻辑,说明是 duration 类商品或者灵活时长商品,且是第一种资源,还没有确定时间
1881
- var allCartItems = cloneDeep(_this11.store.cart.getItems());
2082
+ var allCartItems = cloneDeep(_this10.store.cart.getItems());
1882
2083
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1883
2084
  var selectedResources = [];
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) || []);
2085
+ 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) || []);
1885
2086
  var currentResourcesRenderList = [];
1886
2087
  _resources.forEach(function (n) {
1887
2088
  var _n$renderList;
@@ -1942,7 +2143,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1942
2143
  } else {
1943
2144
  selectResourcesMap[targetResource.id] += currentCapacity;
1944
2145
  }
1945
- _this11.store.cart.updateItem({
2146
+ _this10.store.cart.updateItem({
1946
2147
  _id: item._id,
1947
2148
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
1948
2149
  return existingRes.resourceType !== targetRenderList[0].resourceType;
@@ -1962,7 +2163,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1962
2163
  // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
1963
2164
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
1964
2165
  accountList.forEach(function (account) {
1965
- var cartItems = _this11.store.cart.getCartByAccount(account.getId());
2166
+ var cartItems = _this10.store.cart.getCartByAccount(account.getId());
1966
2167
  selectForCartResources(cartItems);
1967
2168
  });
1968
2169
  } else {
@@ -1977,7 +2178,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1977
2178
  key: "getTimeSlotByAllResources",
1978
2179
  value: function getTimeSlotByAllResources(resources_code) {
1979
2180
  var _dateRange,
1980
- _this12 = this,
2181
+ _this11 = this,
1981
2182
  _cartItems$,
1982
2183
  _cartItems$2,
1983
2184
  _this$shopStore$get;
@@ -1996,8 +2197,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1996
2197
  var maxCutOffTime = undefined;
1997
2198
  var maxCutOffTimeValue = dayjs();
1998
2199
  cartItems.forEach(function (item) {
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) {
2200
+ var _item$_productOrigin10, _item$_productOrigin11, _item$_productOrigin12, _item$_productOrigin13;
2201
+ (_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) {
2001
2202
  // TODO: 少了个 status 的判断
2002
2203
  if (n.code === resources_code) {
2003
2204
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
@@ -2010,10 +2211,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2010
2211
  if (item.resource_id) {
2011
2212
  resourceIds.push(item.resource_id);
2012
2213
  }
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) {
2214
+ 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) {
2014
2215
  return n.code === resources_code;
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') {
2216
+ })) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.id;
2217
+ 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') {
2017
2218
  var currentCutOffTime = dayjs().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
2018
2219
  if (currentCutOffTime.isAfter(maxCutOffTimeValue, 'minute')) {
2019
2220
  maxCutOffTimeValue = currentCutOffTime;
@@ -2041,13 +2242,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2041
2242
  cartItems.forEach(function (item) {
2042
2243
  // 单个预约累加账号 多个预约取最大值
2043
2244
  if (isSingleResource) {
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;
2245
+ var _item$_productOrigin14;
2246
+ 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;
2046
2247
  } else {
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;
2248
+ var _item$_productOrigin15;
2249
+ 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)) {
2250
+ var _item$_productOrigin16;
2251
+ 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;
2051
2252
  }
2052
2253
  }
2053
2254
  });
@@ -2057,7 +2258,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2057
2258
  };
2058
2259
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2059
2260
  accountList.forEach(function (account) {
2060
- var cartItems = _this12.store.cart.getCartByAccount(account.getId());
2261
+ var cartItems = _this11.store.cart.getCartByAccount(account.getId());
2061
2262
  checkDuration(cartItems);
2062
2263
  });
2063
2264
  } else {
@@ -2084,10 +2285,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2084
2285
  }
2085
2286
  var resourcesUseableMap = {};
2086
2287
  var hasFlexibleDuration = cartItems.some(function (item) {
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';
2288
+ var _item$_productOrigin17;
2289
+ 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';
2089
2290
  });
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;
2291
+ 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 || (_this$shopStore$get = _this$shopStore$get.operating_day_boundary) === null || _this$shopStore$get === void 0 ? void 0 : _this$shopStore$get.time;
2091
2292
  var timeSlots = getTimeSlicesByResources({
2092
2293
  resourceIds: resourceIds,
2093
2294
  resourcesMap: resourcesMap,
@@ -2107,7 +2308,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2107
2308
  key: "submitTimeSlot",
2108
2309
  value: function submitTimeSlot(timeSlots) {
2109
2310
  var _this$shopStore$get2,
2110
- _this13 = this;
2311
+ _this12 = this;
2111
2312
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
2112
2313
  var cartItems = this.store.cart.getItems().filter(function (n) {
2113
2314
  return !isNormalProduct(n._productOrigin);
@@ -2127,7 +2328,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2127
2328
  }, {});
2128
2329
 
2129
2330
  // 店铺营业结束时间
2130
- var operating_day_boundary = (_this$shopStore$get2 = this.shopStore.get('core')) === null || _this$shopStore$get2 === void 0 || (_this$shopStore$get2 = _this$shopStore$get2.core) === null || _this$shopStore$get2 === void 0 ? void 0 : _this$shopStore$get2.operating_day_boundary;
2331
+ var operating_day_boundary = (_this$shopStore$get2 = this.shopStore.get('core')) === null || _this$shopStore$get2 === void 0 || (_this$shopStore$get2 = _this$shopStore$get2.core) === null || _this$shopStore$get2 === void 0 || (_this$shopStore$get2 = _this$shopStore$get2.operating_day_boundary) === null || _this$shopStore$get2 === void 0 ? void 0 : _this$shopStore$get2.time;
2131
2332
 
2132
2333
  // 处理每个账号的商品
2133
2334
  Object.values(itemsByAccount).forEach(function (accountItems) {
@@ -2136,9 +2337,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2136
2337
  var _newResources$;
2137
2338
  var newResources = cloneDeep(item._origin.resources);
2138
2339
  newResources.forEach(function (resource) {
2139
- var _item$_productOrigin15;
2340
+ var _item$_productOrigin18;
2140
2341
  // 如果商品配置的是灵活时长,开始时间设置为提交的时间,结束时间从资源的可用最晚时间和店铺营业结束时间里取一个最早的
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') {
2342
+ 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') {
2142
2343
  var _allResources$find;
2143
2344
  item.duration = {
2144
2345
  type: 'minutes',
@@ -2152,11 +2353,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2152
2353
  var resourcesEndTime = targetResourceTimes.reduce(function (acc, curr) {
2153
2354
  return dayjs(curr.end_at).isBefore(dayjs(acc.end_at)) ? curr : acc;
2154
2355
  }, targetResourceTimes[0]);
2155
-
2156
- // 将 operating_day_boundary 转换为与 resourcesEndTime.end_at 相同日期的完整日期时间
2157
- var resourceDate = dayjs(resourcesEndTime.end_at).format('YYYY-MM-DD');
2158
- var operatingBoundaryDateTime = "".concat(resourceDate, " ").concat(operating_day_boundary.type === 'start_time' ? '23:59' : operating_day_boundary.time);
2159
- var endTime = dayjs(resourcesEndTime.end_at).isBefore(dayjs(operatingBoundaryDateTime)) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
2356
+ var endTime = dayjs(resourcesEndTime.end_at).isBefore(dayjs(operating_day_boundary)) ? resourcesEndTime.end_at : operating_day_boundary;
2160
2357
  // 修复:如果 endTime 只是时间格式(如 "17:00"),需要加上日期
2161
2358
  var formattedEndTime;
2162
2359
  if (typeof endTime === 'string' && endTime.includes(':') && !endTime.includes(' ') && !endTime.includes('T')) {
@@ -2168,13 +2365,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2168
2365
  }
2169
2366
  resource.endTime = formattedEndTime.format('YYYY-MM-DD HH:mm');
2170
2367
  } else {
2171
- var _item$_productOrigin16;
2368
+ var _item$_productOrigin19;
2172
2369
  resource.startTime = currentStartTime;
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');
2370
+ 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');
2174
2371
  }
2175
2372
  // delete resource.times;
2176
2373
  });
2177
- _this13.store.cart.updateItem({
2374
+ _this12.store.cart.updateItem({
2178
2375
  _id: item._id,
2179
2376
  resources: newResources
2180
2377
  });
@@ -2222,59 +2419,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2222
2419
  }, {
2223
2420
  key: "openProductDetail",
2224
2421
  value: function () {
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) {
2422
+ var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(productId) {
2423
+ var targetProduct, targetProductData, newScheduleArr;
2424
+ return _regeneratorRuntime().wrap(function _callee26$(_context27) {
2425
+ while (1) switch (_context27.prev = _context27.next) {
2229
2426
  case 0:
2230
- _context25.next = 2;
2427
+ _context27.next = 2;
2231
2428
  return this.store.products.getProduct(productId);
2232
2429
  case 2:
2233
- targetProduct = _context25.sent;
2234
- if (!targetProduct) {
2235
- _context25.next = 16;
2236
- break;
2237
- }
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;
2430
+ targetProduct = _context27.sent;
2431
+ if (targetProduct) {
2432
+ targetProductData = targetProduct.getData();
2433
+ this.store.currentProduct = targetProduct;
2434
+ newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
2435
+ targetProduct.setOtherParams('schedule', newScheduleArr);
2253
2436
  }
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:
2437
+ case 4:
2274
2438
  case "end":
2275
- return _context25.stop();
2439
+ return _context27.stop();
2276
2440
  }
2277
- }, _callee25, this);
2441
+ }, _callee26, this);
2278
2442
  }));
2279
2443
  function openProductDetail(_x19) {
2280
2444
  return _openProductDetail.apply(this, arguments);
@@ -2290,12 +2454,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2290
2454
  }
2291
2455
  }, {
2292
2456
  key: "getTimeslotBySchedule",
2293
- value: function getTimeslotBySchedule(_ref10) {
2457
+ value: function getTimeslotBySchedule(_ref9) {
2294
2458
  var _this$store$currentPr2, _targetProductData$pr;
2295
- var date = _ref10.date,
2296
- scheduleIds = _ref10.scheduleIds,
2297
- resources = _ref10.resources,
2298
- product = _ref10.product;
2459
+ var date = _ref9.date,
2460
+ scheduleIds = _ref9.scheduleIds,
2461
+ resources = _ref9.resources,
2462
+ product = _ref9.product;
2299
2463
  var targetProduct = this.store.currentProduct;
2300
2464
  // 如果外面传递了product 优先用外面的
2301
2465
  var targetProductData = product || (targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
@@ -2322,9 +2486,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2322
2486
  });
2323
2487
  // 资源排下序,把单个资源靠前,组合资源排在后面
2324
2488
  allProductResources.sort(function (a, b) {
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;
2489
+ var _a$metadata4, _b$metadata4;
2490
+ 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;
2491
+ 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;
2328
2492
  if (aIsCombined && !bIsCombined) return 1;
2329
2493
  if (!aIsCombined && bIsCombined) return -1;
2330
2494
  return 0;
@@ -2387,9 +2551,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2387
2551
  // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2388
2552
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2389
2553
  return n === false;
2390
- }) &&
2554
+ })
2391
2555
  // 只统计第一种资源的容量和 left
2392
- m.form_id === firstEnabledResourceId) {
2556
+ && m.form_id === firstEnabledResourceId) {
2393
2557
  if (currentResourcesCount >= count) {
2394
2558
  count = currentResourcesCount;
2395
2559
  }
@@ -2411,6 +2575,69 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2411
2575
  });
2412
2576
  return formatScheduleTimeSlots;
2413
2577
  }
2578
+ }, {
2579
+ key: "addProductToCart",
2580
+ value: function addProductToCart(_ref10) {
2581
+ var _this13 = this;
2582
+ var product = _ref10.product,
2583
+ date = _ref10.date,
2584
+ account = _ref10.account;
2585
+ var _ref11 = product || {},
2586
+ bundle = _ref11.bundle,
2587
+ options = _ref11.options,
2588
+ origin = _ref11.origin,
2589
+ product_variant_id = _ref11.product_variant_id,
2590
+ rowKey = _ref11.rowKey,
2591
+ _ref11$quantity = _ref11.quantity,
2592
+ quantity = _ref11$quantity === void 0 ? 1 : _ref11$quantity;
2593
+ var productData = _objectSpread(_objectSpread({}, origin), {}, {
2594
+ product_variant_id: product_variant_id
2595
+ });
2596
+ if (!account) {
2597
+ var activeAccount = this.getActiveAccount();
2598
+ if (activeAccount) {
2599
+ account = activeAccount;
2600
+ }
2601
+ }
2602
+ if (rowKey) {
2603
+ var cartItems = this.store.cart.getItems();
2604
+ var targetCartItem = cartItems.find(function (n) {
2605
+ var _n$_productOrigin3;
2606
+ return ((_n$_productOrigin3 = n._productOrigin) === null || _n$_productOrigin3 === void 0 ? void 0 : _n$_productOrigin3.rowKey) === rowKey;
2607
+ });
2608
+ if (targetCartItem && isNormalProduct(targetCartItem._productOrigin)) {
2609
+ this.store.cart.updateItem({
2610
+ _id: targetCartItem._id,
2611
+ product: _objectSpread(_objectSpread({}, targetCartItem._productOrigin), {}, {
2612
+ quantity: (targetCartItem.num || 1) + quantity
2613
+ })
2614
+ });
2615
+ return;
2616
+ }
2617
+ }
2618
+ this.store.cart.addItem({
2619
+ product: productData,
2620
+ date: date,
2621
+ account: account,
2622
+ bundle: bundle,
2623
+ options: options,
2624
+ quantity: quantity
2625
+ });
2626
+ // 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
2627
+ if (date) {
2628
+ var _cartItems = this.store.cart.getItems().filter(function (n) {
2629
+ return !isNormalProduct(n._productOrigin);
2630
+ });
2631
+ var cartItemsByDate = _cartItems.filter(function (n) {
2632
+ return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
2633
+ });
2634
+ if (cartItemsByDate.length) {
2635
+ cartItemsByDate.forEach(function (n) {
2636
+ _this13.store.cart.removeItem(n._id);
2637
+ });
2638
+ }
2639
+ }
2640
+ }
2414
2641
  }, {
2415
2642
  key: "setOtherData",
2416
2643
  value: function setOtherData(key, value) {
@@ -2432,27 +2659,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2432
2659
  }, {
2433
2660
  key: "getProductTypeById",
2434
2661
  value: function () {
2435
- var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(id) {
2662
+ var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(id) {
2436
2663
  var product;
2437
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2438
- while (1) switch (_context26.prev = _context26.next) {
2664
+ return _regeneratorRuntime().wrap(function _callee27$(_context28) {
2665
+ while (1) switch (_context28.prev = _context28.next) {
2439
2666
  case 0:
2440
- _context26.next = 2;
2667
+ _context28.next = 2;
2441
2668
  return this.store.products.getProduct(id);
2442
2669
  case 2:
2443
- product = _context26.sent;
2670
+ product = _context28.sent;
2444
2671
  if (!product) {
2445
- _context26.next = 5;
2672
+ _context28.next = 5;
2446
2673
  break;
2447
2674
  }
2448
- return _context26.abrupt("return", product.getProductType());
2675
+ return _context28.abrupt("return", product.getProductType());
2449
2676
  case 5:
2450
- return _context26.abrupt("return", 'normal');
2677
+ return _context28.abrupt("return", 'normal');
2451
2678
  case 6:
2452
2679
  case "end":
2453
- return _context26.stop();
2680
+ return _context28.stop();
2454
2681
  }
2455
- }, _callee26, this);
2682
+ }, _callee27, this);
2456
2683
  }));
2457
2684
  function getProductTypeById(_x20) {
2458
2685
  return _getProductTypeById.apply(this, arguments);
@@ -2470,7 +2697,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2470
2697
  }, {
2471
2698
  key: "getResourcesByCartItemAndCode",
2472
2699
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
2473
- var _cartItem$_productOri8;
2700
+ var _cartItem$_productOri13, _cartItem$_productOri14;
2474
2701
  var dateRange = this.store.date.getDateRange();
2475
2702
  var resources = [];
2476
2703
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -2493,16 +2720,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2493
2720
  });
2494
2721
  if (!cartItem) return [];
2495
2722
  var selectedResources = [];
2496
- var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
2497
- currentCapacity = _getCapacityInfoByCar7.currentCapacity,
2498
- formatCapacity = _getCapacityInfoByCar7.formatCapacity;
2723
+ var formatCapacity = formatDefaultCapacitys({
2724
+ capacity: (_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.capacity,
2725
+ product_bundle: cartItem._origin.product.product_bundle
2726
+ });
2499
2727
  cartItem._origin.metadata.capacity = formatCapacity;
2728
+ var currentCapacity = getSumCapacity({
2729
+ capacity: formatCapacity
2730
+ });
2500
2731
  if (cartItem.holder_id) {
2501
2732
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
2502
2733
  } else {
2503
2734
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
2504
2735
  }
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);
2736
+ 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);
2506
2737
  var targetResource = productResources.find(function (resource) {
2507
2738
  return resource.code === resourceCode;
2508
2739
  });
@@ -2512,9 +2743,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2512
2743
  var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
2513
2744
  var resourcesUseableMap = {};
2514
2745
  targetResource.renderList = targetResource.renderList.sort(function (a, b) {
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;
2746
+ var _a$metadata5, _b$metadata5;
2747
+ 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;
2748
+ 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;
2518
2749
  if (aIsCombined && !bIsCombined) return 1;
2519
2750
  if (!aIsCombined && bIsCombined) return -1;
2520
2751
  return 0;
@@ -2525,7 +2756,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2525
2756
  });
2526
2757
  if (mTimes.length === 0) return false;
2527
2758
  var canUseArr = mTimes.map(function (item) {
2528
- var _cartItem$_productOri9;
2759
+ var _cartItem$_productOri15;
2529
2760
  var res = getIsUsableByTimeItem({
2530
2761
  timeSlice: {
2531
2762
  start_time: startTime.format('HH:mm'),
@@ -2537,7 +2768,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2537
2768
  resource: m,
2538
2769
  currentCount: currentCapacity || 0,
2539
2770
  resourcesUseableMap: resourcesUseableMap,
2540
- cut_off_time: (_cartItem$_productOri9 = cartItem._productOrigin) === null || _cartItem$_productOri9 === void 0 ? void 0 : _cartItem$_productOri9.cut_off_time
2771
+ cut_off_time: (_cartItem$_productOri15 = cartItem._productOrigin) === null || _cartItem$_productOri15 === void 0 ? void 0 : _cartItem$_productOri15.cut_off_time
2541
2772
  });
2542
2773
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2543
2774
  resourcesUseableMap[m.id] = res.usable;
@@ -2551,12 +2782,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2551
2782
  });
2552
2783
  } else {
2553
2784
  targetResource.renderList = targetResource.renderList.filter(function (n) {
2554
- var _cartItem$_productOri10;
2785
+ var _cartItem$_productOri16;
2555
2786
  var recordCount = n.capacity || 0;
2556
2787
  if (n.onlyComputed) return false;
2557
2788
  var timeSlots = getTimeSlicesByResource({
2558
2789
  resource: n,
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,
2790
+ 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,
2560
2791
  split: 10,
2561
2792
  currentDate: dateRange[0].date
2562
2793
  });
@@ -2574,12 +2805,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2574
2805
  }, {
2575
2806
  key: "getTimeslotsScheduleByDateRange",
2576
2807
  value: (function () {
2577
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(_ref11) {
2808
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(_ref12) {
2578
2809
  var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i, _dates, date;
2579
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2580
- while (1) switch (_context27.prev = _context27.next) {
2810
+ return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2811
+ while (1) switch (_context29.prev = _context29.next) {
2581
2812
  case 0:
2582
- startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
2813
+ startDate = _ref12.startDate, endDate = _ref12.endDate, scheduleIds = _ref12.scheduleIds, resources = _ref12.resources;
2583
2814
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
2584
2815
  startDate: startDate,
2585
2816
  endDate: endDate,
@@ -2604,46 +2835,137 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2604
2835
  resources: resources
2605
2836
  });
2606
2837
  }
2607
- return _context27.abrupt("return", results);
2838
+ return _context29.abrupt("return", results);
2608
2839
  case 9:
2609
2840
  case "end":
2610
- return _context27.stop();
2841
+ return _context29.stop();
2611
2842
  }
2612
- }, _callee27, this);
2843
+ }, _callee28, this);
2613
2844
  }));
2614
2845
  function getTimeslotsScheduleByDateRange(_x21) {
2615
2846
  return _getTimeslotsScheduleByDateRange.apply(this, arguments);
2616
2847
  }
2617
2848
  return getTimeslotsScheduleByDateRange;
2618
2849
  }())
2850
+ }, {
2851
+ key: "getAvailableDateForSession",
2852
+ value: function () {
2853
+ var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2854
+ var params,
2855
+ startDate,
2856
+ endDate,
2857
+ type,
2858
+ tempProducts,
2859
+ _ref13,
2860
+ resourceIds,
2861
+ rules,
2862
+ resourcesMap,
2863
+ res,
2864
+ dateListWithTimeSlots,
2865
+ firstAvailableDate,
2866
+ _args30 = arguments;
2867
+ return _regeneratorRuntime().wrap(function _callee29$(_context30) {
2868
+ while (1) switch (_context30.prev = _context30.next) {
2869
+ case 0:
2870
+ params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
2871
+ // 开始日期如果小于今天,直接以今天当做开始日期
2872
+ startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2873
+ if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
2874
+ startDate = dayjs().format('YYYY-MM-DD');
2875
+ }
2876
+ // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2877
+ endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2878
+ tempProducts = []; // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2879
+ if (this.store.currentProduct) {
2880
+ tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
2881
+ _schedule: this.store.currentProduct.getOtherParams()['schedule']
2882
+ })];
2883
+ }
2884
+ // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
2885
+ _ref13 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref13.resourceIds, rules = _ref13.rules, resourcesMap = _ref13.resourcesMap;
2886
+ this.otherParams.currentResourcesMap = resourcesMap;
2887
+ _context30.next = 10;
2888
+ return this.store.date.getResourceDates({
2889
+ query: {
2890
+ start_date: startDate || '',
2891
+ end_date: endDate || '',
2892
+ resource_ids: resourceIds
2893
+ },
2894
+ rules: rules,
2895
+ type: type
2896
+ });
2897
+ case 10:
2898
+ res = _context30.sent;
2899
+ if (!this.store.currentProduct) {
2900
+ _context30.next = 16;
2901
+ break;
2902
+ }
2903
+ _context30.next = 14;
2904
+ return this.getTimeslotsScheduleByDateRange({
2905
+ startDate: startDate || '',
2906
+ endDate: endDate || ''
2907
+ });
2908
+ case 14:
2909
+ dateListWithTimeSlots = _context30.sent;
2910
+ res.forEach(function (n) {
2911
+ if (!dateListWithTimeSlots[n.date]) {
2912
+ n.status = 'unavailable';
2913
+ } else {
2914
+ var allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(function (d) {
2915
+ return d.count;
2916
+ });
2917
+ if (!allTimeSlotsCanUse) {
2918
+ n.status = 'unavailable';
2919
+ }
2920
+ }
2921
+ });
2922
+ case 16:
2923
+ // 找到第一个可用的日期返回给 UI
2924
+ firstAvailableDate = res.find(function (n) {
2925
+ return n.status === 'available';
2926
+ });
2927
+ return _context30.abrupt("return", {
2928
+ dateList: res,
2929
+ firstAvailableDate: firstAvailableDate
2930
+ });
2931
+ case 18:
2932
+ case "end":
2933
+ return _context30.stop();
2934
+ }
2935
+ }, _callee29, this);
2936
+ }));
2937
+ function getAvailableDateForSession() {
2938
+ return _getAvailableDateForSession.apply(this, arguments);
2939
+ }
2940
+ return getAvailableDateForSession;
2941
+ }()
2619
2942
  }, {
2620
2943
  key: "getAvailableDateForSessionOptimize",
2621
2944
  value: function () {
2622
- var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2945
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2623
2946
  var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2624
2947
  var params,
2625
2948
  startDate,
2626
2949
  endDate,
2627
2950
  endDateAfterMonth,
2628
- tempEndDate,
2629
- cache,
2630
2951
  tempProducts,
2631
2952
  schedule,
2632
2953
  filteredSchedule,
2633
2954
  tempResourceIds,
2634
2955
  res,
2956
+ cache,
2635
2957
  dates,
2636
2958
  currentDate,
2637
2959
  firstAvailableDate,
2638
2960
  openResources,
2639
2961
  allProductResources,
2640
2962
  targetSchedules,
2641
- _loop2,
2642
- _args29 = arguments;
2643
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
2644
- while (1) switch (_context29.prev = _context29.next) {
2963
+ _loop3,
2964
+ _args32 = arguments;
2965
+ return _regeneratorRuntime().wrap(function _callee30$(_context32) {
2966
+ while (1) switch (_context32.prev = _context32.next) {
2645
2967
  case 0:
2646
- params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
2968
+ params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
2647
2969
  // 开始日期如果小于今天,直接以今天当做开始日期
2648
2970
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2649
2971
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -2653,49 +2975,43 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2653
2975
  // 优化策略:
2654
2976
  // 在 endDate 添加完一个月以后,如果 endDate 还小于 startDate + 7 天,则还需要 endDate+7 天
2655
2977
  endDateAfterMonth = dayjs().add(1, 'month').format('YYYY-MM-DD');
2656
- tempEndDate = endDateAfterMonth;
2657
2978
  if (dayjs(startDate).add(7, 'day').isAfter(dayjs(endDateAfterMonth), 'day')) {
2658
- tempEndDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2979
+ endDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2659
2980
  } else {
2660
- tempEndDate = endDateAfterMonth;
2661
- }
2662
- // 如果这么算出来的 tempEndDate 还小于 endDate,则需要把 endDate 置为 tempEndDate
2663
- if (dayjs(tempEndDate).isBefore(dayjs(endDate), 'day')) {
2664
- tempEndDate = endDate || '';
2981
+ endDate = endDateAfterMonth;
2665
2982
  }
2666
- endDate = tempEndDate;
2667
-
2983
+ // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2984
+ tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2985
+ schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2986
+ filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2987
+ tempResourceIds = getResourcesIdsByProduct(tempProducts);
2988
+ _context32.next = 11;
2989
+ return this.store.date.fetchResourceDates({
2990
+ query: {
2991
+ start_date: startDate || '',
2992
+ end_date: endDate || '',
2993
+ resource_ids: tempResourceIds
2994
+ }
2995
+ });
2996
+ case 11:
2997
+ res = _context32.sent;
2668
2998
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2669
- cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
2999
+ // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
3000
+ cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2670
3001
  if (!cache) {
2671
- _context29.next = 13;
3002
+ _context32.next = 17;
2672
3003
  break;
2673
3004
  }
2674
3005
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2675
- _context29.next = 13;
3006
+ _context32.next = 17;
2676
3007
  break;
2677
3008
  }
2678
3009
  this.store.date.setDateList(cache.dateList);
2679
- return _context29.abrupt("return", {
3010
+ return _context32.abrupt("return", {
2680
3011
  dateList: cache.dateList,
2681
3012
  firstAvailableDate: cache.firstAvailableDate
2682
3013
  });
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;
3014
+ case 17:
2699
3015
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2700
3016
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2701
3017
  dates = [];
@@ -2715,10 +3031,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2715
3031
  }
2716
3032
  });
2717
3033
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
2718
- _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
3034
+ _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
2719
3035
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
2720
- return _regeneratorRuntime().wrap(function _loop2$(_context28) {
2721
- while (1) switch (_context28.prev = _context28.next) {
3036
+ return _regeneratorRuntime().wrap(function _loop3$(_context31) {
3037
+ while (1) switch (_context31.prev = _context31.next) {
2722
3038
  case 0:
2723
3039
  currentDateStr = currentDate.format('YYYY-MM-DD');
2724
3040
  status = 'available'; // 1. 检查商品的提前量等情况是否满足
@@ -2810,34 +3126,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2810
3126
 
2811
3127
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
2812
3128
  if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 14)) {
2813
- _context28.next = 9;
3129
+ _context31.next = 9;
2814
3130
  break;
2815
3131
  }
2816
- return _context28.abrupt("return", 1);
3132
+ return _context31.abrupt("return", 1);
2817
3133
  case 9:
2818
3134
  currentDate = dayjs(currentDate).add(1, 'day');
2819
3135
  case 10:
2820
3136
  case "end":
2821
- return _context28.stop();
3137
+ return _context31.stop();
2822
3138
  }
2823
- }, _loop2);
3139
+ }, _loop3);
2824
3140
  });
2825
- case 28:
3141
+ case 25:
2826
3142
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
2827
- _context29.next = 34;
3143
+ _context32.next = 31;
2828
3144
  break;
2829
3145
  }
2830
- return _context29.delegateYield(_loop2(), "t0", 30);
2831
- case 30:
2832
- if (!_context29.t0) {
2833
- _context29.next = 32;
3146
+ return _context32.delegateYield(_loop3(), "t0", 27);
3147
+ case 27:
3148
+ if (!_context32.t0) {
3149
+ _context32.next = 29;
2834
3150
  break;
2835
3151
  }
2836
- return _context29.abrupt("break", 34);
2837
- case 32:
2838
- _context29.next = 28;
3152
+ return _context32.abrupt("break", 31);
3153
+ case 29:
3154
+ _context32.next = 25;
2839
3155
  break;
2840
- case 34:
3156
+ case 31:
2841
3157
  // 最终把资源数据也加到日期内
2842
3158
  dates = handleAvailableDateByResource(res.data, dates);
2843
3159
  this.store.date.setDateList(dates);
@@ -2849,15 +3165,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2849
3165
  startDate: startDate,
2850
3166
  endDate: dayjs(currentDate).format('YYYY-MM-DD')
2851
3167
  });
2852
- return _context29.abrupt("return", {
3168
+ return _context32.abrupt("return", {
2853
3169
  dateList: dates,
2854
3170
  firstAvailableDate: firstAvailableDate
2855
3171
  });
2856
- case 38:
3172
+ case 35:
2857
3173
  case "end":
2858
- return _context29.stop();
3174
+ return _context32.stop();
2859
3175
  }
2860
- }, _callee28, this);
3176
+ }, _callee30, this);
2861
3177
  }));
2862
3178
  function getAvailableDateForSessionOptimize() {
2863
3179
  return _getAvailableDateForSessionOptimize.apply(this, arguments);
@@ -2879,14 +3195,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2879
3195
  return !isNormalProduct(n._productOrigin);
2880
3196
  });
2881
3197
  return cartItems.some(function (n) {
2882
- var _n$_productOrigin2;
2883
- return (_n$_productOrigin2 = n._productOrigin) === null || _n$_productOrigin2 === void 0 ? void 0 : _n$_productOrigin2.duration;
3198
+ var _n$_productOrigin4;
3199
+ return (_n$_productOrigin4 = n._productOrigin) === null || _n$_productOrigin4 === void 0 ? void 0 : _n$_productOrigin4.duration;
2884
3200
  });
2885
3201
  }
2886
3202
  }, {
2887
3203
  key: "isTargetNormalProduct",
2888
3204
  value: function isTargetNormalProduct(product) {
2889
- if (!product) return false;
2890
3205
  return isNormalProduct(product);
2891
3206
  }
2892
3207
  }, {