@pisell/pisellos 0.0.37 → 2.0.1

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 (47) hide show
  1. package/dist/modules/Cart/types.d.ts +0 -4
  2. package/dist/modules/Cart/utils.d.ts +0 -1
  3. package/dist/modules/Cart/utils.js +12 -23
  4. package/dist/modules/Product/index.d.ts +0 -10
  5. package/dist/modules/Product/index.js +0 -13
  6. package/dist/modules/Product/types.d.ts +0 -4
  7. package/dist/modules/Resource/types.d.ts +0 -1
  8. package/dist/modules/index.d.ts +0 -9
  9. package/dist/modules/index.js +1 -10
  10. package/dist/solution/BookingByStep/index.d.ts +5 -14
  11. package/dist/solution/BookingByStep/index.js +163 -284
  12. package/dist/solution/BookingByStep/types.d.ts +10 -2
  13. package/dist/solution/BookingByStep/types.js +7 -1
  14. package/dist/solution/BookingByStep/utils/resources.d.ts +4 -45
  15. package/dist/solution/BookingByStep/utils/resources.js +32 -153
  16. package/lib/modules/Cart/types.d.ts +0 -4
  17. package/lib/modules/Cart/utils.d.ts +0 -1
  18. package/lib/modules/Cart/utils.js +12 -24
  19. package/lib/modules/Product/index.d.ts +0 -10
  20. package/lib/modules/Product/index.js +0 -3
  21. package/lib/modules/Product/types.d.ts +0 -4
  22. package/lib/modules/Resource/types.d.ts +0 -1
  23. package/lib/modules/index.d.ts +0 -9
  24. package/lib/modules/index.js +1 -19
  25. package/lib/solution/BookingByStep/index.d.ts +5 -14
  26. package/lib/solution/BookingByStep/index.js +35 -84
  27. package/lib/solution/BookingByStep/types.d.ts +10 -2
  28. package/lib/solution/BookingByStep/types.js +12 -6
  29. package/lib/solution/BookingByStep/utils/resources.d.ts +4 -45
  30. package/lib/solution/BookingByStep/utils/resources.js +24 -101
  31. package/package.json +2 -2
  32. package/dist/modules/Schedule/index.d.ts +0 -10
  33. package/dist/modules/Schedule/index.js +0 -56
  34. package/dist/modules/Schedule/type.d.ts +0 -157
  35. package/dist/modules/Schedule/type.js +0 -1
  36. package/dist/modules/Schedule/types.d.ts +0 -177
  37. package/dist/modules/Schedule/types.js +0 -1
  38. package/dist/modules/Schedule/utils.d.ts +0 -61
  39. package/dist/modules/Schedule/utils.js +0 -700
  40. package/lib/modules/Schedule/index.d.ts +0 -10
  41. package/lib/modules/Schedule/index.js +0 -41
  42. package/lib/modules/Schedule/type.d.ts +0 -157
  43. package/lib/modules/Schedule/type.js +0 -17
  44. package/lib/modules/Schedule/types.d.ts +0 -177
  45. package/lib/modules/Schedule/types.js +0 -17
  46. package/lib/modules/Schedule/utils.d.ts +0 -61
  47. package/lib/modules/Schedule/utils.js +0 -572
@@ -88,7 +88,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
88
88
  }
89
89
  });
90
90
  this.core.effects.emit(import_types.BookingByStepHooks.onInited, {});
91
- this.loadAllSchedule();
92
91
  }
93
92
  // 初始化step
94
93
  initStep(stepList) {
@@ -124,15 +123,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
124
123
  async loadProducts({
125
124
  category_ids = [],
126
125
  product_ids = [],
127
- collection = [],
128
- schedule_ids = []
126
+ collection = []
129
127
  }) {
130
128
  const productsData = await this.request.post(
131
129
  `/product/query`,
132
130
  {
133
131
  open_quotation: 1,
134
132
  open_bundle: 1,
135
- extension_type: ["product_appointment", "appointment_ticket", "session_product"],
133
+ extension_type: ["product_appointment", "appointment_ticket"],
136
134
  with: ["category", "collection"],
137
135
  status: "published",
138
136
  num: 500,
@@ -140,27 +138,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
140
138
  category_ids,
141
139
  ids: product_ids,
142
140
  collection,
143
- front_end_cache_id: this.cacheId,
144
- schedule_ids
141
+ front_end_cache_id: this.cacheId
145
142
  },
146
143
  { useCache: true }
147
144
  );
148
145
  this.store.products.addProduct(productsData.data.list);
149
146
  return productsData.data.list;
150
147
  }
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
- }
164
148
  async storeProduct(productData) {
165
149
  const activeAccount = this.getActiveAccount();
166
150
  if (!activeAccount) {
@@ -320,18 +304,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
320
304
  cartItems.forEach((item) => {
321
305
  var _a;
322
306
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
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
- });
307
+ const resources = (_a = item._origin.resources) == null ? void 0 : _a.filter(
308
+ (m) => !targetCartItem._origin.resources.some((targetRes) => targetRes.id === m.id)
309
+ );
335
310
  this.store.cart.updateItem({
336
311
  _id: item._id,
337
312
  resources
@@ -391,13 +366,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
391
366
  const cartItems = this.store.cart.getItems();
392
367
  const arr = [];
393
368
  cartItems.forEach((cartItem) => {
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);
369
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, cartItem, cartItems);
401
370
  arr.push({
402
371
  id: cartItem.id,
403
372
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
@@ -413,7 +382,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
413
382
  }
414
383
  // 给单个购物车里的商品获取资源列表
415
384
  getResourcesListByCartItem(id) {
416
- var _a, _b, _c;
417
385
  const cartItems = this.store.cart.getItems();
418
386
  const dateRange = this.store.date.getDateRange();
419
387
  const resources = [];
@@ -422,16 +390,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
422
390
  resources.push(...n.resource);
423
391
  });
424
392
  const resourcesMap = (0, import_utils.getResourcesMap)(resources);
393
+ const arr = [];
425
394
  const targetCartItem = cartItems.find((n) => n._id === id);
426
395
  if (!targetCartItem) {
427
396
  throw new Error(`没有找到${id}购物车商品`);
428
397
  }
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);
398
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, targetCartItem, cartItems);
435
399
  if (productResources) {
436
400
  return {
437
401
  id: targetCartItem.id,
@@ -460,7 +424,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
460
424
  });
461
425
  return timeSlots;
462
426
  }
463
- // 自动分派可用的资源-单种资源类型——此方法目前未使用,未经验证
427
+ // 自动分派可用的资源-单种资源类型
464
428
  autoSelectResource({
465
429
  resourceProductData,
466
430
  resources,
@@ -512,9 +476,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
512
476
  holder_id,
513
477
  resources_code,
514
478
  timeSlots,
515
- countMap,
516
- capacity
479
+ countMap
517
480
  }) {
481
+ var _a, _b, _c;
518
482
  const dateRange = this.store.date.getDateRange();
519
483
  const cartItems = this.store.cart.getItems();
520
484
  const accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
@@ -524,13 +488,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
524
488
  };
525
489
  }
526
490
  let duration = accountCartItems.reduce((acc, n) => {
527
- var _a, _b;
528
- return acc + (((_b = (_a = n._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0);
491
+ var _a2, _b2;
492
+ return acc + (((_b2 = (_a2 = n._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0);
529
493
  }, 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";
530
495
  const resources = [];
531
496
  accountCartItems.forEach((item) => {
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) => {
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) => {
534
499
  if (n.code === resources_code) {
535
500
  resources.push(...n.renderList || []);
536
501
  }
@@ -545,7 +510,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
545
510
  timeSlice: timeSlots,
546
511
  time: item,
547
512
  resource: n,
548
- currentCount: recordCount + (capacity || 0)
513
+ currentCount: recordCount + 1
549
514
  });
550
515
  return res.usable;
551
516
  });
@@ -565,8 +530,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
565
530
  resourcesMap,
566
531
  duration,
567
532
  currentDate: dateRange[0].date,
568
- split: 10,
569
- capacity
533
+ split: 10
570
534
  });
571
535
  if (!timeSlots2) {
572
536
  return;
@@ -590,20 +554,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
590
554
  const selectResourcesMap = {};
591
555
  this.store.accountList.getAccounts().forEach((account) => {
592
556
  const cartItems = this.store.cart.getCartByAccount(account.getId());
557
+ const allCartItems = this.store.cart.getItems();
593
558
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
594
559
  cartItems.forEach((item, index) => {
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 });
560
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
598
561
  if (timeSlots) {
599
562
  if (index !== 0 && recordTimeSlots) {
600
563
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
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"
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"
603
566
  );
604
567
  let end_at = start_at.add(
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"
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"
607
570
  );
608
571
  recordTimeSlots = {
609
572
  start_time: start_at.format("HH:mm"),
@@ -616,17 +579,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
616
579
  holder_id: item.holder_id,
617
580
  resources_code,
618
581
  timeSlots: recordTimeSlots,
619
- countMap: selectResourcesMap,
620
- capacity: currentCapacity
582
+ countMap: selectResourcesMap
621
583
  });
622
584
  if (res == null ? void 0 : res.selectedResource) {
623
585
  if (!selectResourcesMap[res.selectedResource.id]) {
624
- selectResourcesMap[res.selectedResource.id] = currentCapacity;
586
+ selectResourcesMap[res.selectedResource.id] = 1;
625
587
  } else {
626
- selectResourcesMap[res.selectedResource.id] += currentCapacity;
588
+ selectResourcesMap[res.selectedResource.id]++;
627
589
  }
628
- res.selectedResource.capacity = currentCapacity;
629
- (0, import_resources.checkSubResourcesCapacity)(res.selectedResource);
590
+ console.log(this.store.cart.getItems());
591
+ res.selectedResource.capacity = 1;
630
592
  this.store.cart.updateItem({
631
593
  _id: item._id,
632
594
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
@@ -637,23 +599,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
637
599
  res.selectedResource
638
600
  ]
639
601
  });
602
+ console.log(this.store.cart.getItems());
640
603
  } else {
641
604
  errorList.push(item._id);
642
605
  }
643
606
  } else {
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;
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;
650
609
  if (targetRenderList && targetRenderList.length > 0) {
651
- if ((_m = item._origin.resources) == null ? void 0 : _m.some((n) => n.form_id === targetRenderList[0].form_id)) {
610
+ if ((_j = item._origin.resources) == null ? void 0 : _j.some((n) => n.form_id === targetRenderList[0].form_id)) {
652
611
  return;
653
612
  }
654
613
  const targetResource = targetRenderList[0];
655
- targetResource.capacity = currentCapacity;
656
- (0, import_resources.checkSubResourcesCapacity)(targetResource);
614
+ targetResource.capacity = 1;
657
615
  this.store.cart.updateItem({
658
616
  _id: item._id,
659
617
  resources: [
@@ -663,7 +621,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
663
621
  targetResource
664
622
  ]
665
623
  });
666
- console.log(account, "已分配");
667
624
  } else {
668
625
  errorList.push(item._id);
669
626
  }
@@ -749,12 +706,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
749
706
  }
750
707
  clearCacheByModule(module2) {
751
708
  }
752
- async openProductDetail(productId) {
753
- const targetProduct = await this.store.products.getProduct(productId);
754
- if (targetProduct) {
755
- this.store.currentProduct = targetProduct;
756
- }
757
- }
758
709
  };
759
710
  // Annotate the CommonJS export names for ESM import in node:
760
711
  0 && (module.exports = {
@@ -1,4 +1,13 @@
1
- import { ProductList, CartModule, Product, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule } from "../../modules";
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";
2
11
  export interface BookingByStepState {
3
12
  cart: CartModule;
4
13
  summary: SummaryModule;
@@ -11,7 +20,6 @@ export interface BookingByStepState {
11
20
  accountList: AccountListModule;
12
21
  order: OrderModule;
13
22
  payment: PaymentModule;
14
- currentProduct: Product;
15
23
  }
16
24
  export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
17
25
  export declare enum BookingByStepHooks {
@@ -24,24 +24,30 @@ __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");
27
33
  function createModule(moduleName, solutionName, name, version) {
28
34
  switch (moduleName) {
29
35
  case "cart":
30
36
  return new import_modules.CartModule(`${solutionName}_${name || moduleName}`, version);
31
37
  case "summary":
32
- return new import_modules.SummaryModule(`${solutionName}_${name || moduleName}`, version);
38
+ return new import_Summary.SummaryModule(`${solutionName}_${name || moduleName}`, version);
33
39
  case "step":
34
- return new import_modules.StepModule(`${solutionName}_${name || moduleName}`, version);
40
+ return new import_Step.StepModule(`${solutionName}_${name || moduleName}`, version);
35
41
  case "products":
36
42
  return new import_modules.ProductList(`${solutionName}_${name || moduleName}`, version);
37
43
  case "date":
38
- return new import_modules.DateModule(`${solutionName}_${name || moduleName}`, version);
44
+ return new import_Date.DateModule(`${solutionName}_${name || moduleName}`, version);
39
45
  case "accountList":
40
- return new import_modules.AccountListModule(`${solutionName}_${name || moduleName}`, version);
46
+ return new import_AccountList.AccountListModule(`${solutionName}_${name || moduleName}`, version);
41
47
  case "order":
42
- return new import_modules.OrderModule(`${solutionName}_${name || moduleName}`, version);
48
+ return new import_Order.OrderModule(`${solutionName}_${name || moduleName}`, version);
43
49
  case "payment":
44
- return new import_modules.PaymentModule(`${solutionName}_${name || moduleName}`, version);
50
+ return new import_Payment.PaymentModule(`${solutionName}_${name || moduleName}`, version);
45
51
  default:
46
52
  throw new Error(`Unknown module type: ${moduleName}`);
47
53
  }
@@ -45,7 +45,8 @@ 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>, resources: ResourceItem[], selectedResources: number[], capacity?: number) => ResourceItem[];
48
+ export declare const getResourcesByProduct: (resourcesMap: Record<string, ResourceItem>, cartItem: CartItem, cartList: CartItem[]) => ResourceItem[];
49
+ export declare const getSumCapacity: () => number;
49
50
  /**
50
51
  * @title: 获取资源列表
51
52
  * @description:
@@ -66,12 +67,11 @@ export declare const formatResources: ({ booking, resources }: {
66
67
  * @return {*}
67
68
  * @Author: zhiwei.Wang
68
69
  */
69
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity }: {
70
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate }: {
70
71
  resource: ResourceItem;
71
72
  duration: number;
72
73
  split: number;
73
74
  currentDate: DateType | string;
74
- capacity?: number | undefined;
75
75
  }) => TimeSliceItem[];
76
76
  /**
77
77
  * @title: 获取时间切片列表的交集
@@ -100,52 +100,11 @@ 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, capacity }: {
103
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split }: {
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;
110
109
  }) => 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;
151
110
  export {};
@@ -29,11 +29,8 @@ 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,
34
32
  formatResources: () => formatResources,
35
33
  getIsUsableByTimeItem: () => getIsUsableByTimeItem,
36
- getOthersSelectedResources: () => getOthersSelectedResources,
37
34
  getResourcesByIds: () => getResourcesByIds,
38
35
  getResourcesByProduct: () => getResourcesByProduct,
39
36
  getSumCapacity: () => getSumCapacity,
@@ -114,37 +111,37 @@ var getIsUsableByTimeItem = ({ timeSlice, time, resource, currentCount = 1 }) =>
114
111
  status.usable = true;
115
112
  return status;
116
113
  };
117
- var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacity = 1) => {
118
- return (resources || []).reduce((acc, item) => {
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) => {
119
118
  if ((item == null ? void 0 : item.status) == 1) {
120
119
  const form_id = item.id;
121
120
  item.optional_resource = (item.optional_resource || []).filter(
122
121
  (d) => item.default_resource.indexOf(d) == -1
123
122
  );
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
- }
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);
132
129
  });
133
130
  }
131
+ }
132
+ return acc2;
133
+ }, []);
134
+ let optional_resource = item.optional_resource.reduce((childAcc, d) => {
135
+ if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
134
136
  childAcc.push(Object.assign({}, resourcesMap[d], {
135
137
  form_id,
136
- resourceType: item.type,
137
- children: combiningResources,
138
- metadata: {
139
- ...resourcesMap[d].metadata,
140
- combined_resource: resourcesMap[d].combined_resource
141
- }
138
+ resourceType: item.type
142
139
  }));
143
140
  }
144
141
  return childAcc;
145
142
  }, []);
146
143
  let default_resource = item.default_resource.reduce((childAcc, d) => {
147
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id) && capacity <= resourcesMap[d].capacity) {
144
+ if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
148
145
  childAcc.push(Object.assign({}, resourcesMap[d], {
149
146
  form_id,
150
147
  resourceType: item.type,
@@ -166,6 +163,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
166
163
  return acc;
167
164
  }, []);
168
165
  };
166
+ var getSumCapacity = () => {
167
+ return 1;
168
+ };
169
169
  var formatResources = ({ booking, resources }) => {
170
170
  try {
171
171
  let _list = [...resources];
@@ -195,8 +195,7 @@ var getTimeSlicesByResource = ({
195
195
  resource,
196
196
  duration,
197
197
  split = 10,
198
- currentDate = (0, import_dayjs.default)(),
199
- capacity
198
+ currentDate = (0, import_dayjs.default)()
200
199
  }) => {
201
200
  const { times } = resource;
202
201
  const timeSlices = [];
@@ -220,7 +219,7 @@ var getTimeSlicesByResource = ({
220
219
  timeSlice,
221
220
  time,
222
221
  resource,
223
- currentCount: capacity || 1
222
+ currentCount: getSumCapacity()
224
223
  });
225
224
  if (_status.usable) {
226
225
  timeSlices.push({
@@ -257,95 +256,19 @@ var getTimeSlicesByResources = ({
257
256
  resourcesMap,
258
257
  duration,
259
258
  currentDate,
260
- split,
261
- capacity
259
+ split
262
260
  }) => {
263
261
  let resources = getResourcesByIds(resourcesMap, resourceIds);
264
262
  let timeSliceList = resources.reduce((acc, item) => {
265
- return acc.concat(getTimeSlicesByResource({ resource: item, duration, split, currentDate, capacity }));
263
+ return acc.concat(getTimeSlicesByResource({ resource: item, duration, split, currentDate }));
266
264
  }, []);
267
265
  let intersection = getTimesIntersection(timeSliceList, resources.length);
268
266
  return intersection;
269
267
  };
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
- };
342
268
  // Annotate the CommonJS export names for ESM import in node:
343
269
  0 && (module.exports = {
344
- checkSubResourcesCapacity,
345
- formatDefaultCapacitys,
346
270
  formatResources,
347
271
  getIsUsableByTimeItem,
348
- getOthersSelectedResources,
349
272
  getResourcesByIds,
350
273
  getResourcesByProduct,
351
274
  getSumCapacity,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.37",
4
+ "version": "2.0.1",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "docs": "typedoc --out docs src/index.ts",
22
22
  "sync": "node sync.js",
23
23
  "prepublishOnly": "npm run build",
24
- "deploy": "yarn run build && yarn run changeset && yarn run version && npm run release"
24
+ "deploy": "yarn run build && yarn run changeset && yarn run version && yarn run release"
25
25
  },
26
26
  "repository": {
27
27
  "type": "git",
@@ -1,10 +0,0 @@
1
- import { Module, PisellCore, ModuleOptions } from '../../types';
2
- import { BaseModule } from '../BaseModule';
3
- import { ScheduleModuleAPI } from './types';
4
- export declare class ScheduleModule extends BaseModule implements Module, ScheduleModuleAPI {
5
- protected defaultName: string;
6
- protected defaultVersion: string;
7
- private store;
8
- constructor(name?: string, version?: string);
9
- initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
10
- }