@pisell/pisellos 2.0.14 → 2.0.15
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/Product/types.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +262 -64
- 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/Product/types.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +262 -66
- 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,32 +506,82 @@ 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
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
533
|
+
const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
|
|
534
|
+
return !targetCartItem._origin.resources.some((targetRes) => {
|
|
535
|
+
var _a3, _b, _c;
|
|
536
|
+
if (targetRes.resourceType !== "single") {
|
|
537
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
538
|
+
capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
|
|
539
|
+
product_bundle: item._origin.product.product_bundle
|
|
540
|
+
});
|
|
541
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
542
|
+
const originResource = allOriginResources.find((n) => n.id === targetRes.id);
|
|
543
|
+
if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
currentResourcesCapacityMap[targetRes.id] += currentCapacity;
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
|
|
512
550
|
if (targetRes.id === m.id)
|
|
513
551
|
return true;
|
|
514
|
-
if (((
|
|
552
|
+
if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
|
|
515
553
|
// 1、当前其他购物车里是否选了当前组合资源的子资源
|
|
516
554
|
// 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
|
|
517
|
-
(targetRes.metadata.combined_resource.resource_ids.includes(
|
|
518
|
-
|
|
519
|
-
|
|
555
|
+
(targetRes.metadata.combined_resource.resource_ids.includes(
|
|
556
|
+
m.id
|
|
557
|
+
) || targetRes.metadata.combined_resource.resource_ids.some(
|
|
558
|
+
(n) => {
|
|
559
|
+
return m.metadata.combined_resource.resource_ids.includes(
|
|
560
|
+
n
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
)))
|
|
520
564
|
return true;
|
|
521
|
-
if (((
|
|
565
|
+
if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
|
|
522
566
|
return true;
|
|
523
|
-
|
|
524
|
-
|
|
567
|
+
}
|
|
568
|
+
return false;
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
if (item.start_time) {
|
|
572
|
+
const start_time = item.start_time;
|
|
573
|
+
const end_time = item.end_time;
|
|
574
|
+
const start_date = item.start_date;
|
|
575
|
+
const end_date = item.end_date;
|
|
576
|
+
this.store.cart.updateItem({
|
|
577
|
+
_id: item._id,
|
|
578
|
+
resources,
|
|
579
|
+
date: {
|
|
580
|
+
startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format("YYYY-MM-DD HH:mm"),
|
|
581
|
+
endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format("YYYY-MM-DD HH:mm")
|
|
582
|
+
}
|
|
525
583
|
});
|
|
584
|
+
} else {
|
|
526
585
|
this.store.cart.updateItem({
|
|
527
586
|
_id: item._id,
|
|
528
587
|
resources
|
|
@@ -609,10 +668,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
609
668
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
610
669
|
const cartItems = this.store.cart.getItems();
|
|
611
670
|
const arr = [];
|
|
612
|
-
const capacityMap = {};
|
|
613
671
|
cartItems.forEach((cartItem) => {
|
|
614
672
|
var _a, _b, _c;
|
|
615
673
|
let selectedResources = [];
|
|
674
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
675
|
+
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
676
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
677
|
+
});
|
|
678
|
+
cartItem._origin.metadata.capacity = formatCapacity;
|
|
679
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
616
680
|
if (cartItem.holder_id) {
|
|
617
681
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
618
682
|
cartItems,
|
|
@@ -626,12 +690,133 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
626
690
|
resourcesMap
|
|
627
691
|
);
|
|
628
692
|
}
|
|
693
|
+
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
694
|
+
resourcesMap,
|
|
695
|
+
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
696
|
+
selectedResources,
|
|
697
|
+
currentCapacity
|
|
698
|
+
);
|
|
699
|
+
if (cartItem._origin.start_time) {
|
|
700
|
+
const startTime = (0, import_dayjs.default)(
|
|
701
|
+
`${cartItem._origin.start_date} ${cartItem._origin.start_time}`
|
|
702
|
+
);
|
|
703
|
+
const endTime = (0, import_dayjs.default)(
|
|
704
|
+
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
705
|
+
);
|
|
706
|
+
const resourcesUseableMap = {};
|
|
707
|
+
productResources.forEach((n) => {
|
|
708
|
+
n.renderList = n.renderList.sort((a, b) => {
|
|
709
|
+
var _a2, _b2, _c2, _d;
|
|
710
|
+
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
711
|
+
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
712
|
+
if (aIsCombined && !bIsCombined)
|
|
713
|
+
return 1;
|
|
714
|
+
if (!aIsCombined && bIsCombined)
|
|
715
|
+
return -1;
|
|
716
|
+
return 0;
|
|
717
|
+
});
|
|
718
|
+
n.renderList = n.renderList.filter((m) => {
|
|
719
|
+
const mTimes = m.times.filter((n2) => {
|
|
720
|
+
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));
|
|
721
|
+
});
|
|
722
|
+
if (mTimes.length === 0) {
|
|
723
|
+
return false;
|
|
724
|
+
}
|
|
725
|
+
const canUseArr = mTimes.map((item) => {
|
|
726
|
+
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
727
|
+
timeSlice: {
|
|
728
|
+
start_time: startTime.format("HH:mm"),
|
|
729
|
+
end_time: endTime.format("HH:mm"),
|
|
730
|
+
start_at: startTime,
|
|
731
|
+
end_at: endTime
|
|
732
|
+
},
|
|
733
|
+
time: item,
|
|
734
|
+
resource: m,
|
|
735
|
+
currentCount: currentCapacity || 0,
|
|
736
|
+
resourcesUseableMap
|
|
737
|
+
});
|
|
738
|
+
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
|
|
739
|
+
resourcesUseableMap[m.id] = res.usable;
|
|
740
|
+
}
|
|
741
|
+
return res.usable;
|
|
742
|
+
});
|
|
743
|
+
if (m.onlyComputed)
|
|
744
|
+
return false;
|
|
745
|
+
return !canUseArr.some((n2) => n2 === false);
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
} else {
|
|
749
|
+
productResources.forEach((item) => {
|
|
750
|
+
item.renderList = item.renderList.filter((n) => {
|
|
751
|
+
var _a2, _b2;
|
|
752
|
+
const recordCount = n.capacity || 0;
|
|
753
|
+
if (n.onlyComputed)
|
|
754
|
+
return false;
|
|
755
|
+
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
756
|
+
resource: n,
|
|
757
|
+
duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 0,
|
|
758
|
+
split: 10,
|
|
759
|
+
currentDate: dateRange[0].date
|
|
760
|
+
});
|
|
761
|
+
return recordCount >= currentCapacity && timeSlots.length > 0;
|
|
762
|
+
});
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
arr.push({
|
|
766
|
+
id: cartItem.id,
|
|
767
|
+
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
768
|
+
_id: cartItem._id,
|
|
769
|
+
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
770
|
+
product: cartItem._productOrigin,
|
|
771
|
+
resources: productResources,
|
|
772
|
+
holder_id: cartItem.holder_id,
|
|
773
|
+
holder_name: cartItem.holder_title
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
return arr;
|
|
777
|
+
}
|
|
778
|
+
// 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
|
|
779
|
+
checkResourceListForDate() {
|
|
780
|
+
const dateRange = this.store.date.getDateRange();
|
|
781
|
+
const resources = [];
|
|
782
|
+
if (dateRange == null ? void 0 : dateRange.length) {
|
|
783
|
+
dateRange.forEach((n) => {
|
|
784
|
+
if (n.resource)
|
|
785
|
+
resources.push(...n.resource);
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
if (!resources.length) {
|
|
789
|
+
const dateList = this.store.date.getDateList();
|
|
790
|
+
dateList.forEach((n) => {
|
|
791
|
+
if (n.resource)
|
|
792
|
+
resources.push(...n.resource);
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
796
|
+
const cartItems = this.store.cart.getItems();
|
|
797
|
+
const arr = [];
|
|
798
|
+
cartItems.forEach((cartItem) => {
|
|
799
|
+
var _a, _b, _c;
|
|
800
|
+
let selectedResources = [];
|
|
629
801
|
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
630
802
|
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
631
803
|
product_bundle: cartItem._origin.product.product_bundle
|
|
632
804
|
});
|
|
633
805
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
634
806
|
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
807
|
+
if (cartItem.holder_id) {
|
|
808
|
+
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
809
|
+
cartItems,
|
|
810
|
+
cartItem.holder_id,
|
|
811
|
+
resourcesMap
|
|
812
|
+
);
|
|
813
|
+
} else {
|
|
814
|
+
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
815
|
+
cartItems,
|
|
816
|
+
cartItem._id,
|
|
817
|
+
resourcesMap
|
|
818
|
+
);
|
|
819
|
+
}
|
|
635
820
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
636
821
|
resourcesMap,
|
|
637
822
|
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
@@ -658,7 +843,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
658
843
|
return 0;
|
|
659
844
|
});
|
|
660
845
|
n.renderList = n.renderList.filter((m) => {
|
|
661
|
-
const recordCount = capacityMap[m.id] || 0;
|
|
662
846
|
const mTimes = m.times.filter((n2) => {
|
|
663
847
|
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
848
|
});
|
|
@@ -675,7 +859,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
675
859
|
},
|
|
676
860
|
time: item,
|
|
677
861
|
resource: m,
|
|
678
|
-
currentCount:
|
|
862
|
+
currentCount: currentCapacity || 0,
|
|
679
863
|
resourcesUseableMap
|
|
680
864
|
});
|
|
681
865
|
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
|
|
@@ -710,13 +894,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
710
894
|
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
711
895
|
_id: cartItem._id,
|
|
712
896
|
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
713
|
-
|
|
714
|
-
resources: productResources,
|
|
715
|
-
holder_id: cartItem.holder_id,
|
|
716
|
-
holder_name: cartItem.holder_title
|
|
897
|
+
productResources
|
|
717
898
|
});
|
|
718
899
|
});
|
|
719
|
-
|
|
900
|
+
const hasResource = arr.every(
|
|
901
|
+
(n) => n.productResources.every((m) => m.renderList.length > 0)
|
|
902
|
+
);
|
|
903
|
+
return hasResource;
|
|
720
904
|
}
|
|
721
905
|
// 给单个购物车里的商品获取资源列表
|
|
722
906
|
getResourcesListByCartItem(id) {
|
|
@@ -728,12 +912,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
728
912
|
if (n.resource)
|
|
729
913
|
resources.push(...n.resource);
|
|
730
914
|
});
|
|
731
|
-
const resourcesMap = (0, import_utils.getResourcesMap)(
|
|
915
|
+
const resourcesMap = (0, import_utils.getResourcesMap)(resources);
|
|
732
916
|
const targetCartItem = cartItems.find((n) => n._id === id);
|
|
733
917
|
if (!targetCartItem) {
|
|
734
918
|
throw new Error(`没有找到${id}购物车商品`);
|
|
735
919
|
}
|
|
736
920
|
let selectedResources = [];
|
|
921
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
922
|
+
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
923
|
+
product_bundle: targetCartItem._origin.product.product_bundle
|
|
924
|
+
});
|
|
925
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
737
926
|
if (targetCartItem.holder_id) {
|
|
738
927
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
739
928
|
cartItems,
|
|
@@ -747,11 +936,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
747
936
|
resourcesMap
|
|
748
937
|
);
|
|
749
938
|
}
|
|
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
939
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
756
940
|
resourcesMap,
|
|
757
941
|
((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
@@ -852,8 +1036,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
852
1036
|
return -1;
|
|
853
1037
|
return 0;
|
|
854
1038
|
});
|
|
855
|
-
const resourcesUseableMap = [
|
|
856
|
-
|
|
1039
|
+
const resourcesUseableMap = [
|
|
1040
|
+
...selectedResources
|
|
1041
|
+
].reduce((acc, n) => {
|
|
1042
|
+
var _a2;
|
|
1043
|
+
acc[n] = ((_a2 = resourcesMap[n]) == null ? void 0 : _a2.resourceType) === "single" ? false : true;
|
|
857
1044
|
return acc;
|
|
858
1045
|
}, {});
|
|
859
1046
|
if (timeSlots) {
|
|
@@ -919,14 +1106,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
919
1106
|
resources.push(...n.resource);
|
|
920
1107
|
});
|
|
921
1108
|
}
|
|
922
|
-
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
923
1109
|
const errorList = [];
|
|
924
1110
|
const selectResourcesMap = {};
|
|
925
1111
|
const accountList = this.store.accountList.getAccounts();
|
|
926
1112
|
const selectForCartResources = (cartItems2) => {
|
|
927
1113
|
let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
|
|
928
1114
|
cartItems2.forEach((item, index) => {
|
|
929
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1115
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
930
1116
|
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
931
1117
|
capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
|
|
932
1118
|
product_bundle: item._origin.product.product_bundle
|
|
@@ -941,14 +1127,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
941
1127
|
};
|
|
942
1128
|
}
|
|
943
1129
|
if (recordTimeSlots) {
|
|
944
|
-
|
|
1130
|
+
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);
|
|
1131
|
+
if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single") {
|
|
945
1132
|
let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
|
|
946
|
-
((
|
|
947
|
-
((
|
|
1133
|
+
((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) ?? 0,
|
|
1134
|
+
((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.type) ?? "minutes"
|
|
948
1135
|
);
|
|
949
1136
|
let end_at = start_at.add(
|
|
950
|
-
((
|
|
951
|
-
((
|
|
1137
|
+
((_j = (_i = item._productOrigin) == null ? void 0 : _i.duration) == null ? void 0 : _j.value) ?? 0,
|
|
1138
|
+
((_l = (_k = item._productOrigin) == null ? void 0 : _k.duration) == null ? void 0 : _l.type) ?? "minutes"
|
|
952
1139
|
);
|
|
953
1140
|
recordTimeSlots = {
|
|
954
1141
|
start_time: start_at.format("HH:mm"),
|
|
@@ -993,7 +1180,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
993
1180
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
994
1181
|
let selectedResources = [];
|
|
995
1182
|
const resources2 = (0, import_lodash_es.cloneDeep)(
|
|
996
|
-
((
|
|
1183
|
+
((_n = (_m = item._productOrigin) == null ? void 0 : _m.product_resource) == null ? void 0 : _n.resources) || []
|
|
997
1184
|
);
|
|
998
1185
|
const currentResourcesRenderList = [];
|
|
999
1186
|
resources2.forEach((n) => {
|
|
@@ -1001,7 +1188,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1001
1188
|
if ((_a3 = n.renderList) == null ? void 0 : _a3.length) {
|
|
1002
1189
|
n.renderList = n.renderList.filter((m) => {
|
|
1003
1190
|
var _a4;
|
|
1004
|
-
const recordCount = m.capacity || 0;
|
|
1191
|
+
const recordCount = (m.capacity || 0) - (selectResourcesMap[m.id] || 0);
|
|
1005
1192
|
const timeSlots2 = (0, import_resources.getTimeSlicesByResource)({
|
|
1006
1193
|
resource: m,
|
|
1007
1194
|
duration: ((_a4 = item == null ? void 0 : item.duration) == null ? void 0 : _a4.value) || 0,
|
|
@@ -1013,39 +1200,39 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1013
1200
|
currentResourcesRenderList.push(...n.renderList || []);
|
|
1014
1201
|
}
|
|
1015
1202
|
});
|
|
1016
|
-
const
|
|
1203
|
+
const resourcesMap = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
|
|
1017
1204
|
if (item.holder_id) {
|
|
1018
1205
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1019
1206
|
allCartItems,
|
|
1020
1207
|
item.holder_id,
|
|
1021
|
-
|
|
1208
|
+
resourcesMap
|
|
1022
1209
|
);
|
|
1023
1210
|
} else {
|
|
1024
1211
|
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
1025
1212
|
allCartItems,
|
|
1026
1213
|
item._id,
|
|
1027
|
-
|
|
1214
|
+
resourcesMap
|
|
1028
1215
|
);
|
|
1029
1216
|
}
|
|
1030
1217
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1031
|
-
|
|
1218
|
+
resourcesMap,
|
|
1032
1219
|
(0, import_lodash_es.cloneDeep)(resources2),
|
|
1033
1220
|
selectedResources,
|
|
1034
1221
|
currentCapacity
|
|
1035
1222
|
);
|
|
1036
1223
|
productResources.forEach((item2) => {
|
|
1037
1224
|
item2.renderList = item2.renderList.filter((n) => {
|
|
1038
|
-
const recordCount = n.capacity || 0;
|
|
1225
|
+
const recordCount = (n.capacity || 0) - (selectResourcesMap[n.id] || 0);
|
|
1039
1226
|
if (n.onlyComputed)
|
|
1040
1227
|
return false;
|
|
1041
1228
|
return recordCount >= currentCapacity;
|
|
1042
1229
|
});
|
|
1043
1230
|
});
|
|
1044
|
-
const targetRenderList = (
|
|
1231
|
+
const targetRenderList = (_o = productResources.find(
|
|
1045
1232
|
(n) => n.code === resources_code
|
|
1046
|
-
)) == null ? void 0 :
|
|
1233
|
+
)) == null ? void 0 : _o.renderList;
|
|
1047
1234
|
if (targetRenderList && targetRenderList.length > 0) {
|
|
1048
|
-
if ((
|
|
1235
|
+
if ((_p = item._origin.resources) == null ? void 0 : _p.some(
|
|
1049
1236
|
(n) => n.form_id === targetRenderList[0].form_id
|
|
1050
1237
|
)) {
|
|
1051
1238
|
return;
|
|
@@ -1053,6 +1240,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1053
1240
|
const targetResource = targetRenderList[0];
|
|
1054
1241
|
targetResource.capacity = currentCapacity;
|
|
1055
1242
|
(0, import_resources.checkSubResourcesCapacity)(targetResource);
|
|
1243
|
+
if (!selectResourcesMap[targetResource.id]) {
|
|
1244
|
+
selectResourcesMap[targetResource.id] = currentCapacity;
|
|
1245
|
+
} else {
|
|
1246
|
+
selectResourcesMap[targetResource.id] += currentCapacity;
|
|
1247
|
+
}
|
|
1056
1248
|
this.store.cart.updateItem({
|
|
1057
1249
|
_id: item._id,
|
|
1058
1250
|
resources: [
|
|
@@ -1162,23 +1354,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1162
1354
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车
|
|
1163
1355
|
submitTimeSlot(timeSlots) {
|
|
1164
1356
|
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
|
-
|
|
1357
|
+
const itemsByAccount = cartItems.reduce(
|
|
1358
|
+
(acc, item) => {
|
|
1359
|
+
const holderId = item.holder_id;
|
|
1360
|
+
if (!acc[holderId]) {
|
|
1361
|
+
acc[holderId] = [];
|
|
1362
|
+
}
|
|
1363
|
+
acc[holderId].push(item);
|
|
1364
|
+
return acc;
|
|
1365
|
+
},
|
|
1366
|
+
{}
|
|
1367
|
+
);
|
|
1173
1368
|
Object.values(itemsByAccount).forEach((accountItems) => {
|
|
1174
1369
|
let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
1175
1370
|
accountItems.forEach((item, index) => {
|
|
1371
|
+
var _a;
|
|
1176
1372
|
const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
|
|
1177
1373
|
newResources.forEach((resource) => {
|
|
1178
|
-
var
|
|
1374
|
+
var _a2, _b, _c, _d;
|
|
1179
1375
|
resource.startTime = currentStartTime;
|
|
1180
1376
|
resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
|
|
1181
|
-
((_b = (
|
|
1377
|
+
((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.value) ?? 0,
|
|
1182
1378
|
((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
|
|
1183
1379
|
).format("YYYY-MM-DD HH:mm");
|
|
1184
1380
|
delete resource.times;
|
|
@@ -1187,7 +1383,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1187
1383
|
_id: item._id,
|
|
1188
1384
|
resources: newResources
|
|
1189
1385
|
});
|
|
1190
|
-
if (index < accountItems.length - 1) {
|
|
1386
|
+
if (index < accountItems.length - 1 && ((_a = newResources == null ? void 0 : newResources[0]) == null ? void 0 : _a.resourceType) === "single") {
|
|
1191
1387
|
currentStartTime = newResources[0].endTime;
|
|
1192
1388
|
}
|
|
1193
1389
|
});
|
|
@@ -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
|
}
|