@pisell/pisellos 0.0.79 → 0.0.81
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 +57 -37
- package/dist/modules/Cart/utils.js +12 -4
- package/dist/solution/BookingByStep/index.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +243 -64
- package/dist/solution/BookingByStep/utils/resources.d.ts +2 -2
- package/dist/solution/BookingByStep/utils/resources.js +20 -14
- package/lib/modules/AccountList/index.d.ts +6 -3
- package/lib/modules/AccountList/index.js +30 -9
- package/lib/modules/Cart/utils.js +7 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +254 -62
- package/lib/solution/BookingByStep/utils/resources.d.ts +2 -2
- package/lib/solution/BookingByStep/utils/resources.js +10 -14
- 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,37 +506,71 @@ 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
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
|
|
512
549
|
if (targetRes.id === m.id)
|
|
513
550
|
return true;
|
|
514
|
-
if (((
|
|
551
|
+
if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
|
|
515
552
|
// 1、当前其他购物车里是否选了当前组合资源的子资源
|
|
516
553
|
// 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
|
|
517
|
-
(targetRes.metadata.combined_resource.resource_ids.includes(
|
|
518
|
-
|
|
519
|
-
|
|
554
|
+
(targetRes.metadata.combined_resource.resource_ids.includes(
|
|
555
|
+
m.id
|
|
556
|
+
) || targetRes.metadata.combined_resource.resource_ids.some(
|
|
557
|
+
(n) => {
|
|
558
|
+
return m.metadata.combined_resource.resource_ids.includes(
|
|
559
|
+
n
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
)))
|
|
520
563
|
return true;
|
|
521
|
-
if (((
|
|
564
|
+
if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
|
|
522
565
|
return true;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
});
|
|
526
|
-
this.store.cart.updateItem({
|
|
527
|
-
_id: item._id,
|
|
528
|
-
resources
|
|
566
|
+
}
|
|
567
|
+
return false;
|
|
529
568
|
});
|
|
530
|
-
}
|
|
569
|
+
});
|
|
570
|
+
this.store.cart.updateItem({
|
|
571
|
+
_id: item._id,
|
|
572
|
+
resources
|
|
573
|
+
});
|
|
531
574
|
});
|
|
532
575
|
}
|
|
533
576
|
// 删除购物车里某个商品
|
|
@@ -613,25 +656,158 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
613
656
|
cartItems.forEach((cartItem) => {
|
|
614
657
|
var _a, _b, _c;
|
|
615
658
|
let selectedResources = [];
|
|
659
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
660
|
+
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
661
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
662
|
+
});
|
|
663
|
+
cartItem._origin.metadata.capacity = formatCapacity;
|
|
664
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
616
665
|
if (cartItem.holder_id) {
|
|
617
666
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
618
667
|
cartItems,
|
|
619
668
|
cartItem.holder_id,
|
|
620
|
-
resourcesMap
|
|
669
|
+
resourcesMap,
|
|
670
|
+
currentCapacity
|
|
621
671
|
);
|
|
622
672
|
} else {
|
|
623
673
|
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
624
674
|
cartItems,
|
|
625
675
|
cartItem._id,
|
|
626
|
-
resourcesMap
|
|
676
|
+
resourcesMap,
|
|
677
|
+
currentCapacity
|
|
627
678
|
);
|
|
628
679
|
}
|
|
680
|
+
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
681
|
+
resourcesMap,
|
|
682
|
+
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
683
|
+
selectedResources,
|
|
684
|
+
currentCapacity
|
|
685
|
+
);
|
|
686
|
+
if (cartItem._origin.start_time) {
|
|
687
|
+
const startTime = (0, import_dayjs.default)(
|
|
688
|
+
`${cartItem._origin.start_date} ${cartItem._origin.start_time}`
|
|
689
|
+
);
|
|
690
|
+
const endTime = (0, import_dayjs.default)(
|
|
691
|
+
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
692
|
+
);
|
|
693
|
+
const resourcesUseableMap = {};
|
|
694
|
+
productResources.forEach((n) => {
|
|
695
|
+
n.renderList = n.renderList.sort((a, b) => {
|
|
696
|
+
var _a2, _b2, _c2, _d;
|
|
697
|
+
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
698
|
+
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
699
|
+
if (aIsCombined && !bIsCombined)
|
|
700
|
+
return 1;
|
|
701
|
+
if (!aIsCombined && bIsCombined)
|
|
702
|
+
return -1;
|
|
703
|
+
return 0;
|
|
704
|
+
});
|
|
705
|
+
n.renderList = n.renderList.filter((m) => {
|
|
706
|
+
const recordCount = capacityMap[m.id] || 0;
|
|
707
|
+
const mTimes = m.times.filter((n2) => {
|
|
708
|
+
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));
|
|
709
|
+
});
|
|
710
|
+
if (mTimes.length === 0) {
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
const canUseArr = mTimes.map((item) => {
|
|
714
|
+
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
715
|
+
timeSlice: {
|
|
716
|
+
start_time: startTime.format("HH:mm"),
|
|
717
|
+
end_time: endTime.format("HH:mm"),
|
|
718
|
+
start_at: startTime,
|
|
719
|
+
end_at: endTime
|
|
720
|
+
},
|
|
721
|
+
time: item,
|
|
722
|
+
resource: m,
|
|
723
|
+
currentCount: recordCount + (currentCapacity || 0),
|
|
724
|
+
resourcesUseableMap
|
|
725
|
+
});
|
|
726
|
+
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
|
|
727
|
+
resourcesUseableMap[m.id] = res.usable;
|
|
728
|
+
}
|
|
729
|
+
return res.usable;
|
|
730
|
+
});
|
|
731
|
+
if (m.onlyComputed)
|
|
732
|
+
return false;
|
|
733
|
+
return !canUseArr.some((n2) => n2 === false);
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
} else {
|
|
737
|
+
productResources.forEach((item) => {
|
|
738
|
+
item.renderList = item.renderList.filter((n) => {
|
|
739
|
+
var _a2, _b2;
|
|
740
|
+
const recordCount = n.capacity || 0;
|
|
741
|
+
if (n.onlyComputed)
|
|
742
|
+
return false;
|
|
743
|
+
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
744
|
+
resource: n,
|
|
745
|
+
duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 0,
|
|
746
|
+
split: 10,
|
|
747
|
+
currentDate: dateRange[0].date
|
|
748
|
+
});
|
|
749
|
+
return recordCount >= currentCapacity && timeSlots.length > 0;
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
arr.push({
|
|
754
|
+
id: cartItem.id,
|
|
755
|
+
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
756
|
+
_id: cartItem._id,
|
|
757
|
+
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
758
|
+
product: cartItem._productOrigin,
|
|
759
|
+
resources: productResources,
|
|
760
|
+
holder_id: cartItem.holder_id,
|
|
761
|
+
holder_name: cartItem.holder_title
|
|
762
|
+
});
|
|
763
|
+
});
|
|
764
|
+
return arr;
|
|
765
|
+
}
|
|
766
|
+
// 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
|
|
767
|
+
checkResourceListForDate() {
|
|
768
|
+
const dateRange = this.store.date.getDateRange();
|
|
769
|
+
const resources = [];
|
|
770
|
+
if (dateRange == null ? void 0 : dateRange.length) {
|
|
771
|
+
dateRange.forEach((n) => {
|
|
772
|
+
if (n.resource)
|
|
773
|
+
resources.push(...n.resource);
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
if (!resources.length) {
|
|
777
|
+
const dateList = this.store.date.getDateList();
|
|
778
|
+
dateList.forEach((n) => {
|
|
779
|
+
if (n.resource)
|
|
780
|
+
resources.push(...n.resource);
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
784
|
+
const cartItems = this.store.cart.getItems();
|
|
785
|
+
const arr = [];
|
|
786
|
+
const capacityMap = {};
|
|
787
|
+
cartItems.forEach((cartItem) => {
|
|
788
|
+
var _a, _b, _c;
|
|
789
|
+
let selectedResources = [];
|
|
629
790
|
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
630
791
|
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
631
792
|
product_bundle: cartItem._origin.product.product_bundle
|
|
632
793
|
});
|
|
633
794
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
634
795
|
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
796
|
+
if (cartItem.holder_id) {
|
|
797
|
+
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
798
|
+
cartItems,
|
|
799
|
+
cartItem.holder_id,
|
|
800
|
+
resourcesMap,
|
|
801
|
+
currentCapacity
|
|
802
|
+
);
|
|
803
|
+
} else {
|
|
804
|
+
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
805
|
+
cartItems,
|
|
806
|
+
cartItem._id,
|
|
807
|
+
resourcesMap,
|
|
808
|
+
currentCapacity
|
|
809
|
+
);
|
|
810
|
+
}
|
|
635
811
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
636
812
|
resourcesMap,
|
|
637
813
|
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
@@ -710,13 +886,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
710
886
|
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
711
887
|
_id: cartItem._id,
|
|
712
888
|
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
713
|
-
|
|
714
|
-
resources: productResources,
|
|
715
|
-
holder_id: cartItem.holder_id,
|
|
716
|
-
holder_name: cartItem.holder_title
|
|
889
|
+
productResources
|
|
717
890
|
});
|
|
718
891
|
});
|
|
719
|
-
|
|
892
|
+
const hasResource = arr.every(
|
|
893
|
+
(n) => n.productResources.every((m) => m.renderList.length > 0)
|
|
894
|
+
);
|
|
895
|
+
return hasResource;
|
|
720
896
|
}
|
|
721
897
|
// 给单个购物车里的商品获取资源列表
|
|
722
898
|
getResourcesListByCartItem(id) {
|
|
@@ -734,24 +910,26 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
734
910
|
throw new Error(`没有找到${id}购物车商品`);
|
|
735
911
|
}
|
|
736
912
|
let selectedResources = [];
|
|
913
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
914
|
+
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
915
|
+
product_bundle: targetCartItem._origin.product.product_bundle
|
|
916
|
+
});
|
|
917
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
737
918
|
if (targetCartItem.holder_id) {
|
|
738
919
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
739
920
|
cartItems,
|
|
740
921
|
targetCartItem.holder_id,
|
|
741
|
-
resourcesMap
|
|
922
|
+
resourcesMap,
|
|
923
|
+
currentCapacity
|
|
742
924
|
);
|
|
743
925
|
} else {
|
|
744
926
|
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
745
927
|
cartItems,
|
|
746
928
|
targetCartItem._id,
|
|
747
|
-
resourcesMap
|
|
929
|
+
resourcesMap,
|
|
930
|
+
currentCapacity
|
|
748
931
|
);
|
|
749
932
|
}
|
|
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
933
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
756
934
|
resourcesMap,
|
|
757
935
|
((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
@@ -833,7 +1011,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
833
1011
|
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
834
1012
|
allCartItems,
|
|
835
1013
|
holder_id,
|
|
836
|
-
resourcesMap
|
|
1014
|
+
resourcesMap,
|
|
1015
|
+
capacity || 0
|
|
837
1016
|
);
|
|
838
1017
|
let allProductResources = (0, import_resources.getResourcesByProduct)(
|
|
839
1018
|
resourcesMap,
|
|
@@ -852,7 +1031,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
852
1031
|
return -1;
|
|
853
1032
|
return 0;
|
|
854
1033
|
});
|
|
855
|
-
const resourcesUseableMap = [
|
|
1034
|
+
const resourcesUseableMap = [
|
|
1035
|
+
...selectedResources
|
|
1036
|
+
].reduce((acc, n) => {
|
|
856
1037
|
acc[n] = false;
|
|
857
1038
|
return acc;
|
|
858
1039
|
}, {});
|
|
@@ -919,7 +1100,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
919
1100
|
resources.push(...n.resource);
|
|
920
1101
|
});
|
|
921
1102
|
}
|
|
922
|
-
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
923
1103
|
const errorList = [];
|
|
924
1104
|
const selectResourcesMap = {};
|
|
925
1105
|
const accountList = this.store.accountList.getAccounts();
|
|
@@ -1001,7 +1181,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1001
1181
|
if ((_a3 = n.renderList) == null ? void 0 : _a3.length) {
|
|
1002
1182
|
n.renderList = n.renderList.filter((m) => {
|
|
1003
1183
|
var _a4;
|
|
1004
|
-
const recordCount = m.capacity || 0;
|
|
1184
|
+
const recordCount = (m.capacity || 0) - (selectResourcesMap[m.id] || 0);
|
|
1005
1185
|
const timeSlots2 = (0, import_resources.getTimeSlicesByResource)({
|
|
1006
1186
|
resource: m,
|
|
1007
1187
|
duration: ((_a4 = item == null ? void 0 : item.duration) == null ? void 0 : _a4.value) || 0,
|
|
@@ -1013,29 +1193,31 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1013
1193
|
currentResourcesRenderList.push(...n.renderList || []);
|
|
1014
1194
|
}
|
|
1015
1195
|
});
|
|
1016
|
-
const
|
|
1196
|
+
const resourcesMap = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
|
|
1017
1197
|
if (item.holder_id) {
|
|
1018
1198
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1019
1199
|
allCartItems,
|
|
1020
1200
|
item.holder_id,
|
|
1021
|
-
|
|
1201
|
+
resourcesMap,
|
|
1202
|
+
currentCapacity
|
|
1022
1203
|
);
|
|
1023
1204
|
} else {
|
|
1024
1205
|
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
1025
1206
|
allCartItems,
|
|
1026
1207
|
item._id,
|
|
1027
|
-
|
|
1208
|
+
resourcesMap,
|
|
1209
|
+
currentCapacity
|
|
1028
1210
|
);
|
|
1029
1211
|
}
|
|
1030
1212
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1031
|
-
|
|
1213
|
+
resourcesMap,
|
|
1032
1214
|
(0, import_lodash_es.cloneDeep)(resources2),
|
|
1033
1215
|
selectedResources,
|
|
1034
1216
|
currentCapacity
|
|
1035
1217
|
);
|
|
1036
1218
|
productResources.forEach((item2) => {
|
|
1037
1219
|
item2.renderList = item2.renderList.filter((n) => {
|
|
1038
|
-
const recordCount = n.capacity || 0;
|
|
1220
|
+
const recordCount = (n.capacity || 0) - (selectResourcesMap[n.id] || 0);
|
|
1039
1221
|
if (n.onlyComputed)
|
|
1040
1222
|
return false;
|
|
1041
1223
|
return recordCount >= currentCapacity;
|
|
@@ -1053,6 +1235,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1053
1235
|
const targetResource = targetRenderList[0];
|
|
1054
1236
|
targetResource.capacity = currentCapacity;
|
|
1055
1237
|
(0, import_resources.checkSubResourcesCapacity)(targetResource);
|
|
1238
|
+
if (!selectResourcesMap[targetResource.id]) {
|
|
1239
|
+
selectResourcesMap[targetResource.id] = currentCapacity;
|
|
1240
|
+
} else {
|
|
1241
|
+
selectResourcesMap[targetResource.id] += currentCapacity;
|
|
1242
|
+
}
|
|
1056
1243
|
this.store.cart.updateItem({
|
|
1057
1244
|
_id: item._id,
|
|
1058
1245
|
resources: [
|
|
@@ -1162,23 +1349,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1162
1349
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车
|
|
1163
1350
|
submitTimeSlot(timeSlots) {
|
|
1164
1351
|
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
|
-
|
|
1352
|
+
const itemsByAccount = cartItems.reduce(
|
|
1353
|
+
(acc, item) => {
|
|
1354
|
+
const holderId = item.holder_id;
|
|
1355
|
+
if (!acc[holderId]) {
|
|
1356
|
+
acc[holderId] = [];
|
|
1357
|
+
}
|
|
1358
|
+
acc[holderId].push(item);
|
|
1359
|
+
return acc;
|
|
1360
|
+
},
|
|
1361
|
+
{}
|
|
1362
|
+
);
|
|
1173
1363
|
Object.values(itemsByAccount).forEach((accountItems) => {
|
|
1174
1364
|
let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
1175
1365
|
accountItems.forEach((item, index) => {
|
|
1366
|
+
var _a;
|
|
1176
1367
|
const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
|
|
1177
1368
|
newResources.forEach((resource) => {
|
|
1178
|
-
var
|
|
1369
|
+
var _a2, _b, _c, _d;
|
|
1179
1370
|
resource.startTime = currentStartTime;
|
|
1180
1371
|
resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
|
|
1181
|
-
((_b = (
|
|
1372
|
+
((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.value) ?? 0,
|
|
1182
1373
|
((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
|
|
1183
1374
|
).format("YYYY-MM-DD HH:mm");
|
|
1184
1375
|
delete resource.times;
|
|
@@ -1187,7 +1378,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1187
1378
|
_id: item._id,
|
|
1188
1379
|
resources: newResources
|
|
1189
1380
|
});
|
|
1190
|
-
if (index < accountItems.length - 1) {
|
|
1381
|
+
if (index < accountItems.length - 1 && ((_a = newResources == null ? void 0 : newResources[0]) == null ? void 0 : _a.resourceType) === "single") {
|
|
1191
1382
|
currentStartTime = newResources[0].endTime;
|
|
1192
1383
|
}
|
|
1193
1384
|
});
|
|
@@ -1260,7 +1451,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1260
1451
|
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1261
1452
|
cartItems,
|
|
1262
1453
|
"",
|
|
1263
|
-
resourcesMap
|
|
1454
|
+
resourcesMap,
|
|
1455
|
+
1
|
|
1264
1456
|
);
|
|
1265
1457
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1266
1458
|
resourcesMap,
|
|
@@ -135,7 +135,7 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
|
|
|
135
135
|
* @return {*}
|
|
136
136
|
* @Author: jinglin.tan
|
|
137
137
|
*/
|
|
138
|
-
export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem
|
|
138
|
+
export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem>, currentCapacity: number) => number[];
|
|
139
139
|
/**
|
|
140
140
|
* @title: 获取其他购物车内商品的已选资源
|
|
141
141
|
* @description:
|
|
@@ -144,7 +144,7 @@ export declare const getOthersSelectedResources: (cartItems: CartItem[], account
|
|
|
144
144
|
* @return {*}
|
|
145
145
|
* @Author: jinglin.tan
|
|
146
146
|
*/
|
|
147
|
-
export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem
|
|
147
|
+
export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>, currentCapacity: number) => number[];
|
|
148
148
|
interface CapacityItem {
|
|
149
149
|
id: number;
|
|
150
150
|
value: number;
|
|
@@ -180,7 +180,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
|
|
|
180
180
|
);
|
|
181
181
|
let optional_resource = item.optional_resource.reduce(
|
|
182
182
|
(childAcc, d) => {
|
|
183
|
-
|
|
183
|
+
var _a;
|
|
184
|
+
const isSelectSingleResources = ((_a = resourcesMap[d]) == null ? void 0 : _a.resourceType) === "single" && selectedResources.includes(resourcesMap[d].id);
|
|
185
|
+
if (resourcesMap[d] && !isSelectSingleResources) {
|
|
184
186
|
const combiningResources = [];
|
|
185
187
|
if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
|
|
186
188
|
resourcesMap[d].combined_resource.resource_ids.forEach(
|
|
@@ -222,7 +224,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
|
|
|
222
224
|
);
|
|
223
225
|
let default_resource = item.default_resource.reduce(
|
|
224
226
|
(childAcc, d) => {
|
|
225
|
-
|
|
227
|
+
var _a;
|
|
228
|
+
const isSelectSingleResources = ((_a = resourcesMap[d]) == null ? void 0 : _a.resourceType) === "single" && selectedResources.includes(resourcesMap[d].id);
|
|
229
|
+
if (resourcesMap[d] && !isSelectSingleResources) {
|
|
226
230
|
const combiningResources = [];
|
|
227
231
|
if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
|
|
228
232
|
resourcesMap[d].combined_resource.resource_ids.forEach(
|
|
@@ -429,7 +433,7 @@ var getTimeSlicesByResources = ({
|
|
|
429
433
|
let intersection = getTimesIntersection(timeSliceList, resources.length);
|
|
430
434
|
return intersection;
|
|
431
435
|
};
|
|
432
|
-
var getOthersSelectedResources = (cartItems, accountId, resourcesMap) => {
|
|
436
|
+
var getOthersSelectedResources = (cartItems, accountId, resourcesMap, currentCapacity) => {
|
|
433
437
|
return cartItems.reduce((acc, d) => {
|
|
434
438
|
var _a;
|
|
435
439
|
if (d.holder_id !== accountId) {
|
|
@@ -442,28 +446,25 @@ var getOthersSelectedResources = (cartItems, accountId, resourcesMap) => {
|
|
|
442
446
|
return acc;
|
|
443
447
|
}
|
|
444
448
|
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
449
|
} else {
|
|
449
450
|
Object.values(resourcesMap).forEach((m) => {
|
|
450
451
|
if (m.combined_resource && m.combined_resource.status === 1) {
|
|
451
452
|
if (m.combined_resource.resource_ids.includes(n.id)) {
|
|
452
453
|
acc.push(m.id);
|
|
453
|
-
resourcesMap[m.id].capacity -= n.num;
|
|
454
454
|
}
|
|
455
455
|
}
|
|
456
456
|
});
|
|
457
457
|
}
|
|
458
458
|
acc.push(n.id);
|
|
459
|
-
resourcesMap[n.id]
|
|
459
|
+
if (resourcesMap[n.id])
|
|
460
|
+
resourcesMap[n.id].capacity -= currentCapacity || 0;
|
|
460
461
|
});
|
|
461
462
|
}
|
|
462
463
|
}
|
|
463
464
|
return acc;
|
|
464
465
|
}, []);
|
|
465
466
|
};
|
|
466
|
-
var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
|
|
467
|
+
var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap, currentCapacity) => {
|
|
467
468
|
return cartItems.reduce((acc, d) => {
|
|
468
469
|
var _a;
|
|
469
470
|
if (d._id !== cartItemId) {
|
|
@@ -476,21 +477,16 @@ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
|
|
|
476
477
|
return acc;
|
|
477
478
|
}
|
|
478
479
|
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
480
|
} else {
|
|
483
481
|
Object.values(resourcesMap).forEach((m) => {
|
|
484
482
|
if (m.combined_resource && m.combined_resource.status === 1) {
|
|
485
483
|
if (m.combined_resource.resource_ids.includes(n.id)) {
|
|
486
484
|
acc.push(m.id);
|
|
487
|
-
resourcesMap[m.id].capacity -= n.num;
|
|
488
485
|
}
|
|
489
486
|
}
|
|
490
487
|
});
|
|
491
488
|
}
|
|
492
489
|
acc.push(n.id);
|
|
493
|
-
resourcesMap[n.id].capacity -= n.num;
|
|
494
490
|
});
|
|
495
491
|
}
|
|
496
492
|
}
|