@pisell/pisellos 3.0.15 → 3.0.18

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