@pisell/pisellos 3.0.16 → 3.0.19

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.
@@ -102,6 +102,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
102
102
  throw new Error(`模块 ${step} 不存在`);
103
103
  }
104
104
  });
105
+ this.loadAllSchedule();
105
106
  this.core.effects.emit(import_types.BookingByStepHooks.onInited, {});
106
107
  }
107
108
  // 初始化step
@@ -204,12 +205,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
204
205
  { date, status: "available", week: "", weekNum: 0 }
205
206
  ]);
206
207
  const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
207
- return await this.loadProducts({ schedule_ids: scheduleIds, product_ids, category_ids, schedule_date: date });
208
+ return await this.loadProducts({
209
+ schedule_ids: scheduleIds,
210
+ product_ids,
211
+ category_ids,
212
+ schedule_date: date
213
+ });
208
214
  }
209
215
  // 加载当前店铺下所有 schedule
210
216
  async loadAllSchedule() {
211
217
  var _a;
212
- const scheduleList = await this.request.get(`/schedule?num=999`);
218
+ const scheduleList = await this.request.get(`/schedule`, { num: 999 }, { useCache: true });
213
219
  this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
214
220
  }
215
221
  // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
@@ -267,10 +273,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
267
273
  // 添加单个账户或者 guest
268
274
  async addAccount(account, extra) {
269
275
  if ((extra == null ? void 0 : extra.type) === "holder") {
270
- const accountModules = await this.store.accountList.addHolderAccounts(
271
- [account],
272
- extra.customerId
273
- );
276
+ const accountModules = await this.store.accountList.addHolderAccounts({
277
+ holders: [account],
278
+ customerId: extra.customerId,
279
+ type: "unshift"
280
+ });
274
281
  return accountModules[0].getAccount();
275
282
  }
276
283
  const newAccount = await this.store.accountList.addAccount(
@@ -281,10 +288,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
281
288
  // 添加账户或者 guest
282
289
  async addAccounts(accounts, extra) {
283
290
  if ((extra == null ? void 0 : extra.type) === "holder") {
284
- this.store.accountList.addHolderAccounts(
285
- accounts,
286
- extra.customerId
287
- );
291
+ this.store.accountList.addHolderAccounts({
292
+ holders: accounts,
293
+ customerId: extra.customerId,
294
+ type: "unshift"
295
+ });
288
296
  return;
289
297
  }
290
298
  const res = [];
@@ -342,6 +350,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
342
350
  }
343
351
  // 获取商品/服务的可用日期
344
352
  async getAvailableDate(params = {}) {
353
+ var _a, _b, _c;
345
354
  let { products, startDate, endDate, type } = params;
346
355
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
347
356
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
@@ -364,8 +373,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
364
373
  ];
365
374
  }
366
375
  let dateRange = this.store.date.getDateRange();
367
- const tempStartDate = startDate || (dateRange == null ? void 0 : dateRange[0].date);
368
- const tempEndDate = endDate || (dateRange == null ? void 0 : dateRange[1].date);
376
+ const tempStartDate = startDate || ((_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.date);
377
+ const tempEndDate = endDate || ((_b = dateRange == null ? void 0 : dateRange[1]) == null ? void 0 : _b.date) || ((_c = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _c.date);
369
378
  if (!tempProducts.length) {
370
379
  return [];
371
380
  }
@@ -489,6 +498,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
489
498
  if (!targetCartItem) {
490
499
  throw new Error(`没有找到${params._id}购物车商品`);
491
500
  }
501
+ let currentResourcesCapacityMap = {};
492
502
  if (params.resources) {
493
503
  const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
494
504
  capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
@@ -497,38 +507,92 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
497
507
  const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
498
508
  params.resources = params.resources.map((n) => {
499
509
  n.capacity = currentCapacity || 1;
510
+ currentResourcesCapacityMap[n.id] = currentCapacity;
500
511
  (0, import_resources.checkSubResourcesCapacity)(n);
501
512
  return n;
502
513
  });
503
514
  }
504
515
  this.store.cart.updateItem(params);
505
- const cartItems = this.store.cart.getItems();
506
- cartItems.forEach((item) => {
507
- var _a2;
508
- if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
509
- const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
510
- return !targetCartItem._origin.resources.some((targetRes) => {
511
- var _a3, _b;
512
- if (targetRes.id === m.id)
513
- return true;
514
- if (((_a3 = targetRes.metadata.combined_resource) == null ? void 0 : _a3.status) === 1 && // 如果现在选择的是组合资源,需要判断
515
- // 1、当前其他购物车里是否选了当前组合资源的子资源
516
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
517
- (targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some((n) => {
518
- return m.metadata.combined_resource.resource_ids.includes(n);
519
- })))
520
- return true;
521
- if (((_b = m.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
522
- return true;
523
- return false;
516
+ const allOriginResources = [];
517
+ const dateRange = this.store.date.getDateRange();
518
+ if (dateRange == null ? void 0 : dateRange.length) {
519
+ dateRange.forEach((n) => {
520
+ if (n.resource)
521
+ allOriginResources.push(...n.resource);
522
+ });
523
+ }
524
+ if (!allOriginResources.length) {
525
+ const dateList = this.store.date.getDateList();
526
+ dateList.forEach((n) => {
527
+ if (n.resource)
528
+ allOriginResources.push(...n.resource);
529
+ });
530
+ }
531
+ if (params.resources) {
532
+ const cartItems = this.store.cart.getItems();
533
+ cartItems.forEach((item) => {
534
+ var _a2;
535
+ if (item._id !== targetCartItem._id) {
536
+ const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
537
+ return !targetCartItem._origin.resources.some((targetRes) => {
538
+ var _a3, _b, _c;
539
+ if (targetRes.resourceType !== "single") {
540
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
541
+ capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
542
+ product_bundle: item._origin.product.product_bundle
543
+ });
544
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
545
+ const originResource = allOriginResources.find((n) => n.id === targetRes.id);
546
+ if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
547
+ return true;
548
+ }
549
+ currentResourcesCapacityMap[targetRes.id] += currentCapacity;
550
+ return false;
551
+ }
552
+ if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
553
+ if (targetRes.id === m.id)
554
+ return true;
555
+ if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
556
+ // 1、当前其他购物车里是否选了当前组合资源的子资源
557
+ // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
558
+ (targetRes.metadata.combined_resource.resource_ids.includes(
559
+ m.id
560
+ ) || targetRes.metadata.combined_resource.resource_ids.some(
561
+ (n) => {
562
+ return m.metadata.combined_resource.resource_ids.includes(
563
+ n
564
+ );
565
+ }
566
+ )))
567
+ return true;
568
+ if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
569
+ return true;
570
+ }
571
+ return false;
572
+ });
524
573
  });
525
- });
526
- this.store.cart.updateItem({
527
- _id: item._id,
528
- resources
529
- });
530
- }
531
- });
574
+ if (item.start_time) {
575
+ const start_time = item.start_time;
576
+ const end_time = item.end_time;
577
+ const start_date = item.start_date;
578
+ const end_date = item.end_date;
579
+ this.store.cart.updateItem({
580
+ _id: item._id,
581
+ resources,
582
+ date: {
583
+ startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format("YYYY-MM-DD HH:mm"),
584
+ endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format("YYYY-MM-DD HH:mm")
585
+ }
586
+ });
587
+ } else {
588
+ this.store.cart.updateItem({
589
+ _id: item._id,
590
+ resources
591
+ });
592
+ }
593
+ }
594
+ });
595
+ }
532
596
  }
533
597
  // 删除购物车里某个商品
534
598
  deleteCart(cartItemId) {
@@ -609,10 +673,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
609
673
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
610
674
  const cartItems = this.store.cart.getItems();
611
675
  const arr = [];
612
- const capacityMap = {};
613
676
  cartItems.forEach((cartItem) => {
614
677
  var _a, _b, _c;
615
678
  let selectedResources = [];
679
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
680
+ capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
681
+ product_bundle: cartItem._origin.product.product_bundle
682
+ });
683
+ cartItem._origin.metadata.capacity = formatCapacity;
684
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
616
685
  if (cartItem.holder_id) {
617
686
  selectedResources = (0, import_resources.getOthersSelectedResources)(
618
687
  cartItems,
@@ -626,12 +695,133 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
626
695
  resourcesMap
627
696
  );
628
697
  }
698
+ const productResources = (0, import_resources.getResourcesByProduct)(
699
+ resourcesMap,
700
+ ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
701
+ selectedResources,
702
+ currentCapacity
703
+ );
704
+ if (cartItem._origin.start_time) {
705
+ const startTime = (0, import_dayjs.default)(
706
+ `${cartItem._origin.start_date} ${cartItem._origin.start_time}`
707
+ );
708
+ const endTime = (0, import_dayjs.default)(
709
+ `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
710
+ );
711
+ const resourcesUseableMap = {};
712
+ productResources.forEach((n) => {
713
+ n.renderList = n.renderList.sort((a, b) => {
714
+ var _a2, _b2, _c2, _d;
715
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
716
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
717
+ if (aIsCombined && !bIsCombined)
718
+ return 1;
719
+ if (!aIsCombined && bIsCombined)
720
+ return -1;
721
+ return 0;
722
+ });
723
+ n.renderList = n.renderList.filter((m) => {
724
+ const mTimes = m.times.filter((n2) => {
725
+ return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(endTime));
726
+ });
727
+ if (mTimes.length === 0) {
728
+ return false;
729
+ }
730
+ const canUseArr = mTimes.map((item) => {
731
+ const res = (0, import_resources.getIsUsableByTimeItem)({
732
+ timeSlice: {
733
+ start_time: startTime.format("HH:mm"),
734
+ end_time: endTime.format("HH:mm"),
735
+ start_at: startTime,
736
+ end_at: endTime
737
+ },
738
+ time: item,
739
+ resource: m,
740
+ currentCount: currentCapacity || 0,
741
+ resourcesUseableMap
742
+ });
743
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
744
+ resourcesUseableMap[m.id] = res.usable;
745
+ }
746
+ return res.usable;
747
+ });
748
+ if (m.onlyComputed)
749
+ return false;
750
+ return !canUseArr.some((n2) => n2 === false);
751
+ });
752
+ });
753
+ } else {
754
+ productResources.forEach((item) => {
755
+ item.renderList = item.renderList.filter((n) => {
756
+ var _a2, _b2;
757
+ const recordCount = n.capacity || 0;
758
+ if (n.onlyComputed)
759
+ return false;
760
+ const timeSlots = (0, import_resources.getTimeSlicesByResource)({
761
+ resource: n,
762
+ duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 0,
763
+ split: 10,
764
+ currentDate: dateRange[0].date
765
+ });
766
+ return recordCount >= currentCapacity && timeSlots.length > 0;
767
+ });
768
+ });
769
+ }
770
+ arr.push({
771
+ id: cartItem.id,
772
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
773
+ _id: cartItem._id,
774
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
775
+ product: cartItem._productOrigin,
776
+ resources: productResources,
777
+ holder_id: cartItem.holder_id,
778
+ holder_name: cartItem.holder_title
779
+ });
780
+ });
781
+ return arr;
782
+ }
783
+ // 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
784
+ checkResourceListForDate() {
785
+ const dateRange = this.store.date.getDateRange();
786
+ const resources = [];
787
+ if (dateRange == null ? void 0 : dateRange.length) {
788
+ dateRange.forEach((n) => {
789
+ if (n.resource)
790
+ resources.push(...n.resource);
791
+ });
792
+ }
793
+ if (!resources.length) {
794
+ const dateList = this.store.date.getDateList();
795
+ dateList.forEach((n) => {
796
+ if (n.resource)
797
+ resources.push(...n.resource);
798
+ });
799
+ }
800
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
801
+ const cartItems = this.store.cart.getItems();
802
+ const arr = [];
803
+ cartItems.forEach((cartItem) => {
804
+ var _a, _b, _c;
805
+ let selectedResources = [];
629
806
  const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
630
807
  capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
631
808
  product_bundle: cartItem._origin.product.product_bundle
632
809
  });
633
810
  cartItem._origin.metadata.capacity = formatCapacity;
634
811
  const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
812
+ if (cartItem.holder_id) {
813
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
814
+ cartItems,
815
+ cartItem.holder_id,
816
+ resourcesMap
817
+ );
818
+ } else {
819
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
820
+ cartItems,
821
+ cartItem._id,
822
+ resourcesMap
823
+ );
824
+ }
635
825
  const productResources = (0, import_resources.getResourcesByProduct)(
636
826
  resourcesMap,
637
827
  ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
@@ -658,7 +848,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
658
848
  return 0;
659
849
  });
660
850
  n.renderList = n.renderList.filter((m) => {
661
- const recordCount = capacityMap[m.id] || 0;
662
851
  const mTimes = m.times.filter((n2) => {
663
852
  return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(endTime));
664
853
  });
@@ -675,7 +864,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
675
864
  },
676
865
  time: item,
677
866
  resource: m,
678
- currentCount: recordCount + (currentCapacity || 0),
867
+ currentCount: currentCapacity || 0,
679
868
  resourcesUseableMap
680
869
  });
681
870
  if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
@@ -710,13 +899,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
710
899
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
711
900
  _id: cartItem._id,
712
901
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
713
- product: cartItem._productOrigin,
714
- resources: productResources,
715
- holder_id: cartItem.holder_id,
716
- holder_name: cartItem.holder_title
902
+ productResources
717
903
  });
718
904
  });
719
- return arr;
905
+ const hasResource = arr.every(
906
+ (n) => n.productResources.every((m) => m.renderList.length > 0)
907
+ );
908
+ return hasResource;
720
909
  }
721
910
  // 给单个购物车里的商品获取资源列表
722
911
  getResourcesListByCartItem(id) {
@@ -728,12 +917,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
728
917
  if (n.resource)
729
918
  resources.push(...n.resource);
730
919
  });
731
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
920
+ const resourcesMap = (0, import_utils.getResourcesMap)(resources);
732
921
  const targetCartItem = cartItems.find((n) => n._id === id);
733
922
  if (!targetCartItem) {
734
923
  throw new Error(`没有找到${id}购物车商品`);
735
924
  }
736
925
  let selectedResources = [];
926
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
927
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
928
+ product_bundle: targetCartItem._origin.product.product_bundle
929
+ });
930
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
737
931
  if (targetCartItem.holder_id) {
738
932
  selectedResources = (0, import_resources.getOthersSelectedResources)(
739
933
  cartItems,
@@ -747,11 +941,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
747
941
  resourcesMap
748
942
  );
749
943
  }
750
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
751
- capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
752
- product_bundle: targetCartItem._origin.product.product_bundle
753
- });
754
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
755
944
  const productResources = (0, import_resources.getResourcesByProduct)(
756
945
  resourcesMap,
757
946
  ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
@@ -852,8 +1041,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
852
1041
  return -1;
853
1042
  return 0;
854
1043
  });
855
- const resourcesUseableMap = [...selectedResources].reduce((acc, n) => {
856
- acc[n] = false;
1044
+ const resourcesUseableMap = [
1045
+ ...selectedResources
1046
+ ].reduce((acc, n) => {
1047
+ var _a2;
1048
+ acc[n] = ((_a2 = resourcesMap[n]) == null ? void 0 : _a2.resourceType) === "single" ? false : true;
857
1049
  return acc;
858
1050
  }, {});
859
1051
  if (timeSlots) {
@@ -919,14 +1111,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
919
1111
  resources.push(...n.resource);
920
1112
  });
921
1113
  }
922
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
923
1114
  const errorList = [];
924
1115
  const selectResourcesMap = {};
925
1116
  const accountList = this.store.accountList.getAccounts();
926
1117
  const selectForCartResources = (cartItems2) => {
927
1118
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
928
1119
  cartItems2.forEach((item, index) => {
929
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1120
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
930
1121
  const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
931
1122
  capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
932
1123
  product_bundle: item._origin.product.product_bundle
@@ -941,15 +1132,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
941
1132
  };
942
1133
  }
943
1134
  if (recordTimeSlots) {
944
- if (index !== 0 && recordTimeSlots) {
1135
+ const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find((n) => n.code === resources_code);
1136
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
945
1137
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
946
- ((_c = (_b = item._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.value) ?? 0,
947
- ((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.type) ?? "minutes"
948
- );
949
- let end_at = start_at.add(
950
1138
  ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) ?? 0,
951
1139
  ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.type) ?? "minutes"
952
1140
  );
1141
+ let end_at = start_at.add(
1142
+ ((_k = (_j = item._productOrigin) == null ? void 0 : _j.duration) == null ? void 0 : _k.value) ?? 0,
1143
+ ((_m = (_l = item._productOrigin) == null ? void 0 : _l.duration) == null ? void 0 : _m.type) ?? "minutes"
1144
+ );
953
1145
  recordTimeSlots = {
954
1146
  start_time: start_at.format("HH:mm"),
955
1147
  end_time: end_at.format("HH:mm"),
@@ -993,7 +1185,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
993
1185
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
994
1186
  let selectedResources = [];
995
1187
  const resources2 = (0, import_lodash_es.cloneDeep)(
996
- ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || []
1188
+ ((_o = (_n = item._productOrigin) == null ? void 0 : _n.product_resource) == null ? void 0 : _o.resources) || []
997
1189
  );
998
1190
  const currentResourcesRenderList = [];
999
1191
  resources2.forEach((n) => {
@@ -1001,7 +1193,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1001
1193
  if ((_a3 = n.renderList) == null ? void 0 : _a3.length) {
1002
1194
  n.renderList = n.renderList.filter((m) => {
1003
1195
  var _a4;
1004
- const recordCount = m.capacity || 0;
1196
+ const recordCount = (m.capacity || 0) - (selectResourcesMap[m.id] || 0);
1005
1197
  const timeSlots2 = (0, import_resources.getTimeSlicesByResource)({
1006
1198
  resource: m,
1007
1199
  duration: ((_a4 = item == null ? void 0 : item.duration) == null ? void 0 : _a4.value) || 0,
@@ -1013,39 +1205,39 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1013
1205
  currentResourcesRenderList.push(...n.renderList || []);
1014
1206
  }
1015
1207
  });
1016
- const resourcesMap2 = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
1208
+ const resourcesMap = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
1017
1209
  if (item.holder_id) {
1018
1210
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1019
1211
  allCartItems,
1020
1212
  item.holder_id,
1021
- resourcesMap2
1213
+ resourcesMap
1022
1214
  );
1023
1215
  } else {
1024
1216
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
1025
1217
  allCartItems,
1026
1218
  item._id,
1027
- resourcesMap2
1219
+ resourcesMap
1028
1220
  );
1029
1221
  }
1030
1222
  const productResources = (0, import_resources.getResourcesByProduct)(
1031
- resourcesMap2,
1223
+ resourcesMap,
1032
1224
  (0, import_lodash_es.cloneDeep)(resources2),
1033
1225
  selectedResources,
1034
1226
  currentCapacity
1035
1227
  );
1036
1228
  productResources.forEach((item2) => {
1037
1229
  item2.renderList = item2.renderList.filter((n) => {
1038
- const recordCount = n.capacity || 0;
1230
+ const recordCount = (n.capacity || 0) - (selectResourcesMap[n.id] || 0);
1039
1231
  if (n.onlyComputed)
1040
1232
  return false;
1041
1233
  return recordCount >= currentCapacity;
1042
1234
  });
1043
1235
  });
1044
- const targetRenderList = (_l = productResources.find(
1236
+ const targetRenderList = (_p = productResources.find(
1045
1237
  (n) => n.code === resources_code
1046
- )) == null ? void 0 : _l.renderList;
1238
+ )) == null ? void 0 : _p.renderList;
1047
1239
  if (targetRenderList && targetRenderList.length > 0) {
1048
- if ((_m = item._origin.resources) == null ? void 0 : _m.some(
1240
+ if ((_q = item._origin.resources) == null ? void 0 : _q.some(
1049
1241
  (n) => n.form_id === targetRenderList[0].form_id
1050
1242
  )) {
1051
1243
  return;
@@ -1053,6 +1245,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1053
1245
  const targetResource = targetRenderList[0];
1054
1246
  targetResource.capacity = currentCapacity;
1055
1247
  (0, import_resources.checkSubResourcesCapacity)(targetResource);
1248
+ if (!selectResourcesMap[targetResource.id]) {
1249
+ selectResourcesMap[targetResource.id] = currentCapacity;
1250
+ } else {
1251
+ selectResourcesMap[targetResource.id] += currentCapacity;
1252
+ }
1056
1253
  this.store.cart.updateItem({
1057
1254
  _id: item._id,
1058
1255
  resources: [
@@ -1162,23 +1359,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1162
1359
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车
1163
1360
  submitTimeSlot(timeSlots) {
1164
1361
  const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1165
- const itemsByAccount = cartItems.reduce((acc, item) => {
1166
- const holderId = item.holder_id;
1167
- if (!acc[holderId]) {
1168
- acc[holderId] = [];
1169
- }
1170
- acc[holderId].push(item);
1171
- return acc;
1172
- }, {});
1362
+ const itemsByAccount = cartItems.reduce(
1363
+ (acc, item) => {
1364
+ const holderId = item.holder_id;
1365
+ if (!acc[holderId]) {
1366
+ acc[holderId] = [];
1367
+ }
1368
+ acc[holderId].push(item);
1369
+ return acc;
1370
+ },
1371
+ {}
1372
+ );
1173
1373
  Object.values(itemsByAccount).forEach((accountItems) => {
1174
1374
  let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1175
1375
  accountItems.forEach((item, index) => {
1376
+ var _a;
1176
1377
  const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
1177
1378
  newResources.forEach((resource) => {
1178
- var _a, _b, _c, _d;
1379
+ var _a2, _b, _c, _d;
1179
1380
  resource.startTime = currentStartTime;
1180
1381
  resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
1181
- ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
1382
+ ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.value) ?? 0,
1182
1383
  ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
1183
1384
  ).format("YYYY-MM-DD HH:mm");
1184
1385
  delete resource.times;
@@ -1187,7 +1388,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1187
1388
  _id: item._id,
1188
1389
  resources: newResources
1189
1390
  });
1190
- if (index < accountItems.length - 1) {
1391
+ if (index < accountItems.length - 1 && ((_a = newResources == null ? void 0 : newResources[0]) == null ? void 0 : _a.resourceType) === "single") {
1191
1392
  currentStartTime = newResources[0].endTime;
1192
1393
  }
1193
1394
  });
@@ -181,7 +181,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
181
181
  );
182
182
  let optional_resource = item.optional_resource.reduce(
183
183
  (childAcc, d) => {
184
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
184
+ var _a;
185
+ const isSelectSingleResources = ((_a = resourcesMap[d]) == null ? void 0 : _a.resourceType) === "single" && selectedResources.includes(resourcesMap[d].id);
186
+ if (resourcesMap[d] && !isSelectSingleResources) {
185
187
  const combiningResources = [];
186
188
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
187
189
  resourcesMap[d].combined_resource.resource_ids.forEach(
@@ -223,7 +225,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
223
225
  );
224
226
  let default_resource = item.default_resource.reduce(
225
227
  (childAcc, d) => {
226
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
228
+ var _a;
229
+ const isSelectSingleResources = ((_a = resourcesMap[d]) == null ? void 0 : _a.resourceType) === "single" && selectedResources.includes(resourcesMap[d].id);
230
+ if (resourcesMap[d] && !isSelectSingleResources) {
227
231
  const combiningResources = [];
228
232
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
229
233
  resourcesMap[d].combined_resource.resource_ids.forEach(
@@ -443,21 +447,16 @@ var getOthersSelectedResources = (cartItems, accountId, resourcesMap) => {
443
447
  return acc;
444
448
  }
445
449
  acc.push(...n.metadata.combined_resource.resource_ids);
446
- n.metadata.combined_resource.resource_ids.forEach((m) => {
447
- resourcesMap[m].capacity -= n.num;
448
- });
449
450
  } else {
450
451
  Object.values(resourcesMap).forEach((m) => {
451
452
  if (m.combined_resource && m.combined_resource.status === 1) {
452
453
  if (m.combined_resource.resource_ids.includes(n.id)) {
453
454
  acc.push(m.id);
454
- resourcesMap[m.id].capacity -= n.num;
455
455
  }
456
456
  }
457
457
  });
458
458
  }
459
459
  acc.push(n.id);
460
- resourcesMap[n.id].capacity -= n.num;
461
460
  });
462
461
  }
463
462
  }
@@ -477,21 +476,16 @@ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
477
476
  return acc;
478
477
  }
479
478
  acc.push(...n.metadata.combined_resource.resource_ids);
480
- n.metadata.combined_resource.resource_ids.forEach((m) => {
481
- resourcesMap[m].capacity -= n.num;
482
- });
483
479
  } else {
484
480
  Object.values(resourcesMap).forEach((m) => {
485
481
  if (m.combined_resource && m.combined_resource.status === 1) {
486
482
  if (m.combined_resource.resource_ids.includes(n.id)) {
487
483
  acc.push(m.id);
488
- resourcesMap[m.id].capacity -= n.num;
489
484
  }
490
485
  }
491
486
  });
492
487
  }
493
488
  acc.push(n.id);
494
- resourcesMap[n.id].capacity -= n.num;
495
489
  });
496
490
  }
497
491
  }
@@ -271,7 +271,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
271
271
  if (item.booking_id) {
272
272
  (item.discount_list || []).forEach((discount) => {
273
273
  var _a2, _b, _c;
274
- if (discount.id) {
274
+ if (discount.id && discount.type === "good_pass") {
275
275
  editModeDiscountList.push({
276
276
  ...discount,
277
277
  isEditMode: true,