@pisell/pisellos 3.0.16 → 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.
- package/dist/modules/AccountList/index.d.ts +6 -3
- package/dist/modules/AccountList/index.js +67 -45
- package/dist/modules/Cart/utils.js +12 -4
- package/dist/modules/Product/types.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +274 -74
- package/dist/solution/BookingByStep/utils/resources.js +18 -12
- package/lib/modules/AccountList/index.d.ts +6 -3
- package/lib/modules/AccountList/index.js +32 -9
- package/lib/modules/Cart/utils.js +7 -1
- package/lib/modules/Product/types.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +270 -72
- package/lib/solution/BookingByStep/utils/resources.js +6 -12
- package/package.json +1 -1
|
@@ -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({
|
|
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.
|
|
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.
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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:
|
|
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
|
-
|
|
714
|
-
resources: productResources,
|
|
715
|
-
holder_id: cartItem.holder_id,
|
|
716
|
-
holder_name: cartItem.holder_title
|
|
899
|
+
productResources
|
|
717
900
|
});
|
|
718
901
|
});
|
|
719
|
-
|
|
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)(
|
|
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 = [
|
|
856
|
-
|
|
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
|
-
|
|
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
|
-
((
|
|
947
|
-
((
|
|
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
|
-
((
|
|
951
|
-
((
|
|
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
|
-
((
|
|
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
|
|
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
|
-
|
|
1210
|
+
resourcesMap
|
|
1022
1211
|
);
|
|
1023
1212
|
} else {
|
|
1024
1213
|
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
1025
1214
|
allCartItems,
|
|
1026
1215
|
item._id,
|
|
1027
|
-
|
|
1216
|
+
resourcesMap
|
|
1028
1217
|
);
|
|
1029
1218
|
}
|
|
1030
1219
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1031
|
-
|
|
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 = (
|
|
1233
|
+
const targetRenderList = (_o = productResources.find(
|
|
1045
1234
|
(n) => n.code === resources_code
|
|
1046
|
-
)) == null ? void 0 :
|
|
1235
|
+
)) == null ? void 0 : _o.renderList;
|
|
1047
1236
|
if (targetRenderList && targetRenderList.length > 0) {
|
|
1048
|
-
if ((
|
|
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(
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
acc[holderId]
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
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
|
|
1376
|
+
var _a2, _b, _c, _d;
|
|
1179
1377
|
resource.startTime = currentStartTime;
|
|
1180
1378
|
resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
|
|
1181
|
-
((_b = (
|
|
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
|
});
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
}
|