@pisell/pisellos 0.0.35 → 0.0.37

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.
Files changed (45) hide show
  1. package/dist/modules/Cart/types.d.ts +4 -0
  2. package/dist/modules/Cart/utils.js +21 -11
  3. package/dist/modules/Product/index.d.ts +10 -0
  4. package/dist/modules/Product/index.js +13 -0
  5. package/dist/modules/Product/types.d.ts +4 -0
  6. package/dist/modules/Resource/types.d.ts +1 -0
  7. package/dist/modules/Schedule/index.d.ts +10 -0
  8. package/dist/modules/Schedule/index.js +56 -0
  9. package/dist/modules/Schedule/type.d.ts +157 -0
  10. package/dist/modules/Schedule/type.js +1 -0
  11. package/dist/modules/Schedule/types.d.ts +177 -0
  12. package/dist/modules/Schedule/types.js +1 -0
  13. package/dist/modules/Schedule/utils.d.ts +61 -0
  14. package/dist/modules/Schedule/utils.js +700 -0
  15. package/dist/modules/index.d.ts +9 -0
  16. package/dist/modules/index.js +10 -1
  17. package/dist/solution/BookingByStep/index.d.ts +14 -5
  18. package/dist/solution/BookingByStep/index.js +284 -163
  19. package/dist/solution/BookingByStep/types.d.ts +2 -10
  20. package/dist/solution/BookingByStep/types.js +1 -7
  21. package/dist/solution/BookingByStep/utils/resources.d.ts +45 -4
  22. package/dist/solution/BookingByStep/utils/resources.js +153 -32
  23. package/lib/modules/Cart/types.d.ts +4 -0
  24. package/lib/modules/Cart/utils.js +22 -11
  25. package/lib/modules/Product/index.d.ts +10 -0
  26. package/lib/modules/Product/index.js +3 -0
  27. package/lib/modules/Product/types.d.ts +4 -0
  28. package/lib/modules/Resource/types.d.ts +1 -0
  29. package/lib/modules/Schedule/index.d.ts +10 -0
  30. package/lib/modules/Schedule/index.js +41 -0
  31. package/lib/modules/Schedule/type.d.ts +157 -0
  32. package/lib/modules/Schedule/type.js +17 -0
  33. package/lib/modules/Schedule/types.d.ts +177 -0
  34. package/lib/modules/Schedule/types.js +17 -0
  35. package/lib/modules/Schedule/utils.d.ts +61 -0
  36. package/lib/modules/Schedule/utils.js +572 -0
  37. package/lib/modules/index.d.ts +9 -0
  38. package/lib/modules/index.js +19 -1
  39. package/lib/solution/BookingByStep/index.d.ts +14 -5
  40. package/lib/solution/BookingByStep/index.js +84 -35
  41. package/lib/solution/BookingByStep/types.d.ts +2 -10
  42. package/lib/solution/BookingByStep/types.js +6 -12
  43. package/lib/solution/BookingByStep/utils/resources.d.ts +45 -4
  44. package/lib/solution/BookingByStep/utils/resources.js +101 -24
  45. package/package.json +1 -1
@@ -88,6 +88,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
88
88
  }
89
89
  });
90
90
  this.core.effects.emit(import_types.BookingByStepHooks.onInited, {});
91
+ this.loadAllSchedule();
91
92
  }
92
93
  // 初始化step
93
94
  initStep(stepList) {
@@ -123,14 +124,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
123
124
  async loadProducts({
124
125
  category_ids = [],
125
126
  product_ids = [],
126
- collection = []
127
+ collection = [],
128
+ schedule_ids = []
127
129
  }) {
128
130
  const productsData = await this.request.post(
129
131
  `/product/query`,
130
132
  {
131
133
  open_quotation: 1,
132
134
  open_bundle: 1,
133
- extension_type: ["product_appointment", "appointment_ticket"],
135
+ extension_type: ["product_appointment", "appointment_ticket", "session_product"],
134
136
  with: ["category", "collection"],
135
137
  status: "published",
136
138
  num: 500,
@@ -138,13 +140,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
138
140
  category_ids,
139
141
  ids: product_ids,
140
142
  collection,
141
- front_end_cache_id: this.cacheId
143
+ front_end_cache_id: this.cacheId,
144
+ schedule_ids
142
145
  },
143
146
  { useCache: true }
144
147
  );
145
148
  this.store.products.addProduct(productsData.data.list);
146
149
  return productsData.data.list;
147
150
  }
151
+ // 加载当前店铺下所有 schedule
152
+ async loadAllSchedule() {
153
+ const scheduleList = await this.request.get(`/schedule`);
154
+ }
155
+ // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
156
+ async loadAvailableDate({ startDate, endDate, custom_page_id }) {
157
+ const res = await this.request.get(`/schedule/product/availability`, {
158
+ start_date: startDate,
159
+ end_date: endDate,
160
+ custom_page_id
161
+ });
162
+ return res.data.list;
163
+ }
148
164
  async storeProduct(productData) {
149
165
  const activeAccount = this.getActiveAccount();
150
166
  if (!activeAccount) {
@@ -304,9 +320,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
304
320
  cartItems.forEach((item) => {
305
321
  var _a;
306
322
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
307
- const resources = (_a = item._origin.resources) == null ? void 0 : _a.filter(
308
- (m) => !targetCartItem._origin.resources.some((targetRes) => targetRes.id === m.id)
309
- );
323
+ const resources = (_a = item._origin.resources) == null ? void 0 : _a.filter((m) => {
324
+ return !targetCartItem._origin.resources.some((targetRes) => {
325
+ var _a2, _b;
326
+ if (targetRes.id === m.id)
327
+ return true;
328
+ if (((_a2 = targetRes.metadata.combined_resource) == null ? void 0 : _a2.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id))
329
+ return true;
330
+ if (((_b = m.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
331
+ return true;
332
+ return false;
333
+ });
334
+ });
310
335
  this.store.cart.updateItem({
311
336
  _id: item._id,
312
337
  resources
@@ -366,7 +391,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
366
391
  const cartItems = this.store.cart.getItems();
367
392
  const arr = [];
368
393
  cartItems.forEach((cartItem) => {
369
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, cartItem, cartItems);
394
+ var _a, _b, _c;
395
+ if (!cartItem.holder_id)
396
+ return;
397
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(cartItems, cartItem.holder_id, resourcesMap);
398
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({ capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity, product_bundle: cartItem._origin.product.product_bundle });
399
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
400
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [], selectedResources, currentCapacity);
370
401
  arr.push({
371
402
  id: cartItem.id,
372
403
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
@@ -382,6 +413,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
382
413
  }
383
414
  // 给单个购物车里的商品获取资源列表
384
415
  getResourcesListByCartItem(id) {
416
+ var _a, _b, _c;
385
417
  const cartItems = this.store.cart.getItems();
386
418
  const dateRange = this.store.date.getDateRange();
387
419
  const resources = [];
@@ -390,12 +422,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
390
422
  resources.push(...n.resource);
391
423
  });
392
424
  const resourcesMap = (0, import_utils.getResourcesMap)(resources);
393
- const arr = [];
394
425
  const targetCartItem = cartItems.find((n) => n._id === id);
395
426
  if (!targetCartItem) {
396
427
  throw new Error(`没有找到${id}购物车商品`);
397
428
  }
398
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, targetCartItem, cartItems);
429
+ if (!targetCartItem.holder_id)
430
+ return;
431
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(cartItems, targetCartItem.holder_id, resourcesMap);
432
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity, product_bundle: targetCartItem._origin.product.product_bundle });
433
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
434
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [], selectedResources, currentCapacity);
399
435
  if (productResources) {
400
436
  return {
401
437
  id: targetCartItem.id,
@@ -424,7 +460,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
424
460
  });
425
461
  return timeSlots;
426
462
  }
427
- // 自动分派可用的资源-单种资源类型
463
+ // 自动分派可用的资源-单种资源类型——此方法目前未使用,未经验证
428
464
  autoSelectResource({
429
465
  resourceProductData,
430
466
  resources,
@@ -476,9 +512,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
476
512
  holder_id,
477
513
  resources_code,
478
514
  timeSlots,
479
- countMap
515
+ countMap,
516
+ capacity
480
517
  }) {
481
- var _a, _b, _c;
482
518
  const dateRange = this.store.date.getDateRange();
483
519
  const cartItems = this.store.cart.getItems();
484
520
  const accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
@@ -488,14 +524,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
488
524
  };
489
525
  }
490
526
  let duration = accountCartItems.reduce((acc, n) => {
491
- var _a2, _b2;
492
- return acc + (((_b2 = (_a2 = n._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0);
527
+ var _a, _b;
528
+ return acc + (((_b = (_a = n._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0);
493
529
  }, 0);
494
- let durationType = ((_c = (_b = (_a = accountCartItems[0]) == null ? void 0 : _a._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.type) ?? "minutes";
495
530
  const resources = [];
496
531
  accountCartItems.forEach((item) => {
497
- var _a2, _b2, _c2;
498
- (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
532
+ var _a, _b, _c;
533
+ (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
499
534
  if (n.code === resources_code) {
500
535
  resources.push(...n.renderList || []);
501
536
  }
@@ -510,7 +545,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
510
545
  timeSlice: timeSlots,
511
546
  time: item,
512
547
  resource: n,
513
- currentCount: recordCount + 1
548
+ currentCount: recordCount + (capacity || 0)
514
549
  });
515
550
  return res.usable;
516
551
  });
@@ -530,7 +565,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
530
565
  resourcesMap,
531
566
  duration,
532
567
  currentDate: dateRange[0].date,
533
- split: 10
568
+ split: 10,
569
+ capacity
534
570
  });
535
571
  if (!timeSlots2) {
536
572
  return;
@@ -554,19 +590,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
554
590
  const selectResourcesMap = {};
555
591
  this.store.accountList.getAccounts().forEach((account) => {
556
592
  const cartItems = this.store.cart.getCartByAccount(account.getId());
557
- const allCartItems = this.store.cart.getItems();
558
593
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
559
594
  cartItems.forEach((item, index) => {
560
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
595
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
596
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({ capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity, product_bundle: item._origin.product.product_bundle });
597
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
561
598
  if (timeSlots) {
562
599
  if (index !== 0 && recordTimeSlots) {
563
600
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
564
- ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
565
- ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
601
+ ((_c = (_b = item._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.value) ?? 0,
602
+ ((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.type) ?? "minutes"
566
603
  );
567
604
  let end_at = start_at.add(
568
- ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) ?? 0,
569
- ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.type) ?? "minutes"
605
+ ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) ?? 0,
606
+ ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.type) ?? "minutes"
570
607
  );
571
608
  recordTimeSlots = {
572
609
  start_time: start_at.format("HH:mm"),
@@ -579,16 +616,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
579
616
  holder_id: item.holder_id,
580
617
  resources_code,
581
618
  timeSlots: recordTimeSlots,
582
- countMap: selectResourcesMap
619
+ countMap: selectResourcesMap,
620
+ capacity: currentCapacity
583
621
  });
584
622
  if (res == null ? void 0 : res.selectedResource) {
585
623
  if (!selectResourcesMap[res.selectedResource.id]) {
586
- selectResourcesMap[res.selectedResource.id] = 1;
624
+ selectResourcesMap[res.selectedResource.id] = currentCapacity;
587
625
  } else {
588
- selectResourcesMap[res.selectedResource.id]++;
626
+ selectResourcesMap[res.selectedResource.id] += currentCapacity;
589
627
  }
590
- console.log(this.store.cart.getItems());
591
- res.selectedResource.capacity = 1;
628
+ res.selectedResource.capacity = currentCapacity;
629
+ (0, import_resources.checkSubResourcesCapacity)(res.selectedResource);
592
630
  this.store.cart.updateItem({
593
631
  _id: item._id,
594
632
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
@@ -599,19 +637,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
599
637
  res.selectedResource
600
638
  ]
601
639
  });
602
- console.log(this.store.cart.getItems());
603
640
  } else {
604
641
  errorList.push(item._id);
605
642
  }
606
643
  } else {
607
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, item, allCartItems);
608
- const targetRenderList = (_i = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _i.renderList;
644
+ const allCartItems = this.store.cart.getItems();
645
+ if (!item.holder_id)
646
+ return;
647
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(allCartItems, item.holder_id, resourcesMap);
648
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || [], selectedResources, currentCapacity);
649
+ const targetRenderList = (_l = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _l.renderList;
609
650
  if (targetRenderList && targetRenderList.length > 0) {
610
- if ((_j = item._origin.resources) == null ? void 0 : _j.some((n) => n.form_id === targetRenderList[0].form_id)) {
651
+ if ((_m = item._origin.resources) == null ? void 0 : _m.some((n) => n.form_id === targetRenderList[0].form_id)) {
611
652
  return;
612
653
  }
613
654
  const targetResource = targetRenderList[0];
614
- targetResource.capacity = 1;
655
+ targetResource.capacity = currentCapacity;
656
+ (0, import_resources.checkSubResourcesCapacity)(targetResource);
615
657
  this.store.cart.updateItem({
616
658
  _id: item._id,
617
659
  resources: [
@@ -621,6 +663,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
621
663
  targetResource
622
664
  ]
623
665
  });
666
+ console.log(account, "已分配");
624
667
  } else {
625
668
  errorList.push(item._id);
626
669
  }
@@ -706,6 +749,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
706
749
  }
707
750
  clearCacheByModule(module2) {
708
751
  }
752
+ async openProductDetail(productId) {
753
+ const targetProduct = await this.store.products.getProduct(productId);
754
+ if (targetProduct) {
755
+ this.store.currentProduct = targetProduct;
756
+ }
757
+ }
709
758
  };
710
759
  // Annotate the CommonJS export names for ESM import in node:
711
760
  0 && (module.exports = {
@@ -1,13 +1,4 @@
1
- import { ProductList, CartModule } from "../../modules";
2
- import { AccountModule } from "../../modules/Account";
3
- import { AccountListModule } from "../../modules/AccountList";
4
- import { DateModule } from "../../modules/Date";
5
- import { GuestListModule } from "../../modules/Guests";
6
- import { OrderModule } from "../../modules/Order";
7
- import { PaymentModule } from "../../modules/Payment";
8
- import { ResourceListModule } from "../../modules/Resource";
9
- import { StepModule } from "../../modules/Step";
10
- import { SummaryModule } from "../../modules/Summary";
1
+ import { ProductList, CartModule, Product, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule } from "../../modules";
11
2
  export interface BookingByStepState {
12
3
  cart: CartModule;
13
4
  summary: SummaryModule;
@@ -20,6 +11,7 @@ export interface BookingByStepState {
20
11
  accountList: AccountListModule;
21
12
  order: OrderModule;
22
13
  payment: PaymentModule;
14
+ currentProduct: Product;
23
15
  }
24
16
  export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
25
17
  export declare enum BookingByStepHooks {
@@ -24,30 +24,24 @@ __export(types_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(types_exports);
26
26
  var import_modules = require("../../modules");
27
- var import_AccountList = require("../../modules/AccountList");
28
- var import_Date = require("../../modules/Date");
29
- var import_Order = require("../../modules/Order");
30
- var import_Payment = require("../../modules/Payment");
31
- var import_Step = require("../../modules/Step");
32
- var import_Summary = require("../../modules/Summary");
33
27
  function createModule(moduleName, solutionName, name, version) {
34
28
  switch (moduleName) {
35
29
  case "cart":
36
30
  return new import_modules.CartModule(`${solutionName}_${name || moduleName}`, version);
37
31
  case "summary":
38
- return new import_Summary.SummaryModule(`${solutionName}_${name || moduleName}`, version);
32
+ return new import_modules.SummaryModule(`${solutionName}_${name || moduleName}`, version);
39
33
  case "step":
40
- return new import_Step.StepModule(`${solutionName}_${name || moduleName}`, version);
34
+ return new import_modules.StepModule(`${solutionName}_${name || moduleName}`, version);
41
35
  case "products":
42
36
  return new import_modules.ProductList(`${solutionName}_${name || moduleName}`, version);
43
37
  case "date":
44
- return new import_Date.DateModule(`${solutionName}_${name || moduleName}`, version);
38
+ return new import_modules.DateModule(`${solutionName}_${name || moduleName}`, version);
45
39
  case "accountList":
46
- return new import_AccountList.AccountListModule(`${solutionName}_${name || moduleName}`, version);
40
+ return new import_modules.AccountListModule(`${solutionName}_${name || moduleName}`, version);
47
41
  case "order":
48
- return new import_Order.OrderModule(`${solutionName}_${name || moduleName}`, version);
42
+ return new import_modules.OrderModule(`${solutionName}_${name || moduleName}`, version);
49
43
  case "payment":
50
- return new import_Payment.PaymentModule(`${solutionName}_${name || moduleName}`, version);
44
+ return new import_modules.PaymentModule(`${solutionName}_${name || moduleName}`, version);
51
45
  default:
52
46
  throw new Error(`Unknown module type: ${moduleName}`);
53
47
  }
@@ -45,8 +45,7 @@ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, curren
45
45
  * @return {*}
46
46
  * @Author: zhiwei.Wang
47
47
  */
48
- export declare const getResourcesByProduct: (resourcesMap: Record<string, ResourceItem>, cartItem: CartItem, cartList: CartItem[]) => ResourceItem[];
49
- export declare const getSumCapacity: () => number;
48
+ export declare const getResourcesByProduct: (resourcesMap: Record<string, ResourceItem>, resources: ResourceItem[], selectedResources: number[], capacity?: number) => ResourceItem[];
50
49
  /**
51
50
  * @title: 获取资源列表
52
51
  * @description:
@@ -67,11 +66,12 @@ export declare const formatResources: ({ booking, resources }: {
67
66
  * @return {*}
68
67
  * @Author: zhiwei.Wang
69
68
  */
70
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate }: {
69
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity }: {
71
70
  resource: ResourceItem;
72
71
  duration: number;
73
72
  split: number;
74
73
  currentDate: DateType | string;
74
+ capacity?: number | undefined;
75
75
  }) => TimeSliceItem[];
76
76
  /**
77
77
  * @title: 获取时间切片列表的交集
@@ -100,11 +100,52 @@ export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceIt
100
100
  * @return {*}
101
101
  * @Author: zhiwei.Wang
102
102
  */
103
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split }: {
103
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity }: {
104
104
  resourceIds: number[];
105
105
  resourcesMap: any;
106
106
  duration: number;
107
107
  currentDate: DateType | string;
108
108
  split: number;
109
+ capacity?: number | undefined;
109
110
  }) => any[];
111
+ /**
112
+ * @title: 获取其他人的已选资源
113
+ * @description:
114
+ * @param {CartItem[]} cartItems
115
+ * @param {number | string} accountId
116
+ * @return {*}
117
+ * @Author: jinglin.tan
118
+ */
119
+ export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
120
+ interface CapacityItem {
121
+ id: number;
122
+ value: number;
123
+ name: string;
124
+ }
125
+ /**
126
+ * @title: 基于选择的商品格式化容量
127
+ * @description:
128
+ * @param {any} param1
129
+ * @return {*}
130
+ * @Author: zhiwei.Wang
131
+ */
132
+ export declare const formatDefaultCapacitys: ({ capacity, product_bundle }: any) => CapacityItem[];
133
+ /**
134
+ * @title: 获取总容量
135
+ * @description:
136
+ * @param {object} capacity 为 formatDefaultCapacitys()的结果
137
+ * @return {*}
138
+ * @Author: zhiwei.Wang
139
+ */
140
+ export declare const getSumCapacity: ({ capacity }: {
141
+ capacity: CapacityItem[];
142
+ }) => number;
143
+ /**
144
+ * @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
145
+ * @description:
146
+ * @param {object} resource
147
+ * @return {*}
148
+ * @Author: jinglin.tan
149
+ */
150
+ export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
110
151
  export {};
@@ -29,8 +29,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/solution/BookingByStep/utils/resources.ts
30
30
  var resources_exports = {};
31
31
  __export(resources_exports, {
32
+ checkSubResourcesCapacity: () => checkSubResourcesCapacity,
33
+ formatDefaultCapacitys: () => formatDefaultCapacitys,
32
34
  formatResources: () => formatResources,
33
35
  getIsUsableByTimeItem: () => getIsUsableByTimeItem,
36
+ getOthersSelectedResources: () => getOthersSelectedResources,
34
37
  getResourcesByIds: () => getResourcesByIds,
35
38
  getResourcesByProduct: () => getResourcesByProduct,
36
39
  getSumCapacity: () => getSumCapacity,
@@ -111,37 +114,37 @@ var getIsUsableByTimeItem = ({ timeSlice, time, resource, currentCount = 1 }) =>
111
114
  status.usable = true;
112
115
  return status;
113
116
  };
114
- var getResourcesByProduct = (resourcesMap, cartItem, cartList) => {
115
- var _a;
116
- const product = cartItem._productOrigin;
117
- return (((_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources) || []).reduce((acc, item) => {
117
+ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacity = 1) => {
118
+ return (resources || []).reduce((acc, item) => {
118
119
  if ((item == null ? void 0 : item.status) == 1) {
119
120
  const form_id = item.id;
120
121
  item.optional_resource = (item.optional_resource || []).filter(
121
122
  (d) => item.default_resource.indexOf(d) == -1
122
123
  );
123
- const selectedResources = cartList.reduce((acc2, d) => {
124
- var _a2;
125
- if (d.holder_id !== cartItem.holder_id) {
126
- if ((_a2 = d._origin) == null ? void 0 : _a2.resources) {
127
- d._origin.resources.forEach((n) => {
128
- acc2.push(n.id);
124
+ let optional_resource = item.optional_resource.reduce((childAcc, d) => {
125
+ if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id) && capacity <= resourcesMap[d].capacity) {
126
+ const combiningResources = [];
127
+ if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
128
+ resourcesMap[d].combined_resource.resource_ids.forEach((id) => {
129
+ if (resourcesMap[id]) {
130
+ combiningResources.push(resourcesMap[id]);
131
+ }
129
132
  });
130
133
  }
131
- }
132
- return acc2;
133
- }, []);
134
- let optional_resource = item.optional_resource.reduce((childAcc, d) => {
135
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
136
134
  childAcc.push(Object.assign({}, resourcesMap[d], {
137
135
  form_id,
138
- resourceType: item.type
136
+ resourceType: item.type,
137
+ children: combiningResources,
138
+ metadata: {
139
+ ...resourcesMap[d].metadata,
140
+ combined_resource: resourcesMap[d].combined_resource
141
+ }
139
142
  }));
140
143
  }
141
144
  return childAcc;
142
145
  }, []);
143
146
  let default_resource = item.default_resource.reduce((childAcc, d) => {
144
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
147
+ if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id) && capacity <= resourcesMap[d].capacity) {
145
148
  childAcc.push(Object.assign({}, resourcesMap[d], {
146
149
  form_id,
147
150
  resourceType: item.type,
@@ -163,9 +166,6 @@ var getResourcesByProduct = (resourcesMap, cartItem, cartList) => {
163
166
  return acc;
164
167
  }, []);
165
168
  };
166
- var getSumCapacity = () => {
167
- return 1;
168
- };
169
169
  var formatResources = ({ booking, resources }) => {
170
170
  try {
171
171
  let _list = [...resources];
@@ -195,7 +195,8 @@ var getTimeSlicesByResource = ({
195
195
  resource,
196
196
  duration,
197
197
  split = 10,
198
- currentDate = (0, import_dayjs.default)()
198
+ currentDate = (0, import_dayjs.default)(),
199
+ capacity
199
200
  }) => {
200
201
  const { times } = resource;
201
202
  const timeSlices = [];
@@ -219,7 +220,7 @@ var getTimeSlicesByResource = ({
219
220
  timeSlice,
220
221
  time,
221
222
  resource,
222
- currentCount: getSumCapacity()
223
+ currentCount: capacity || 1
223
224
  });
224
225
  if (_status.usable) {
225
226
  timeSlices.push({
@@ -256,19 +257,95 @@ var getTimeSlicesByResources = ({
256
257
  resourcesMap,
257
258
  duration,
258
259
  currentDate,
259
- split
260
+ split,
261
+ capacity
260
262
  }) => {
261
263
  let resources = getResourcesByIds(resourcesMap, resourceIds);
262
264
  let timeSliceList = resources.reduce((acc, item) => {
263
- return acc.concat(getTimeSlicesByResource({ resource: item, duration, split, currentDate }));
265
+ return acc.concat(getTimeSlicesByResource({ resource: item, duration, split, currentDate, capacity }));
264
266
  }, []);
265
267
  let intersection = getTimesIntersection(timeSliceList, resources.length);
266
268
  return intersection;
267
269
  };
270
+ var getOthersSelectedResources = (cartItems, accountId, resourcesMap) => {
271
+ return cartItems.reduce((acc, d) => {
272
+ var _a;
273
+ if (d.holder_id !== accountId) {
274
+ if ((_a = d._origin) == null ? void 0 : _a.resources) {
275
+ d._origin.resources.forEach((n) => {
276
+ if (n.metadata.combined_resource && n.metadata.combined_resource.status === 1) {
277
+ if (n.metadata.combined_resource.resource_ids.some((m) => acc.includes(m))) {
278
+ return acc;
279
+ }
280
+ acc.push(...n.metadata.combined_resource.resource_ids);
281
+ } else {
282
+ Object.values(resourcesMap).forEach((m) => {
283
+ if (m.combined_resource && m.combined_resource.status === 1) {
284
+ if (m.combined_resource.resource_ids.includes(n.id)) {
285
+ acc.push(m.id);
286
+ }
287
+ }
288
+ });
289
+ }
290
+ acc.push(n.id);
291
+ });
292
+ }
293
+ }
294
+ return acc;
295
+ }, []);
296
+ };
297
+ var formatDefaultCapacitys = ({ capacity, product_bundle }) => {
298
+ if ((capacity == null ? void 0 : capacity.type) === "package") {
299
+ return (product_bundle || []).map((d) => {
300
+ const id = d.bundle_product_id;
301
+ const item = ((capacity == null ? void 0 : capacity.package) || []).find(
302
+ (item2) => item2.product_id === id
303
+ );
304
+ return {
305
+ id,
306
+ value: item ? d.num || 0 : 0,
307
+ name: (item == null ? void 0 : item.name) || (d == null ? void 0 : d.title)
308
+ };
309
+ });
310
+ }
311
+ if ((capacity == null ? void 0 : capacity.type) === "custom") {
312
+ return ((capacity == null ? void 0 : capacity.custom) || []).map((d) => {
313
+ return {
314
+ id: d.id,
315
+ value: d.min,
316
+ name: d.name
317
+ };
318
+ });
319
+ }
320
+ return [{ id: 0, value: 1, name: "" }];
321
+ };
322
+ var getSumCapacity = ({ capacity }) => {
323
+ let sum = 0;
324
+ for (let item of capacity || []) {
325
+ sum += item.value;
326
+ }
327
+ return sum;
328
+ };
329
+ var checkSubResourcesCapacity = (resource) => {
330
+ if (resource.children && resource.children.length) {
331
+ let countCapacity = resource.capacity;
332
+ resource.children.forEach((child) => {
333
+ if (child.capacity <= countCapacity) {
334
+ countCapacity -= child.capacity;
335
+ } else {
336
+ child.capacity = countCapacity;
337
+ countCapacity = 0;
338
+ }
339
+ });
340
+ }
341
+ };
268
342
  // Annotate the CommonJS export names for ESM import in node:
269
343
  0 && (module.exports = {
344
+ checkSubResourcesCapacity,
345
+ formatDefaultCapacitys,
270
346
  formatResources,
271
347
  getIsUsableByTimeItem,
348
+ getOthersSelectedResources,
272
349
  getResourcesByIds,
273
350
  getResourcesByProduct,
274
351
  getSumCapacity,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.35",
4
+ "version": "0.0.37",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",