@pisell/pisellos 1.0.5 → 1.0.7

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