@pisell/pisellos 2.1.20 → 2.1.21

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.
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  };
327
327
  setOtherData(key: string, value: any): void;
328
328
  getOtherData(key: string): any;
329
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
329
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
330
330
  /**
331
331
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
332
332
  *
@@ -2058,7 +2058,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2058
2058
  // item._origin.resources?.forEach((n: any) => {
2059
2059
  // resourceIds.push(n.relation_id);
2060
2060
  // });
2061
- if (item.resource_id) {
2061
+ if (item.resource_id && !resourceIds.includes(item.resource_id)) {
2062
2062
  resourceIds.push(item.resource_id);
2063
2063
  }
2064
2064
  resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.resources) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.find(function (n) {
@@ -2153,6 +2153,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2153
2153
  return 0;
2154
2154
  }, 0);
2155
2155
  }
2156
+ // 计算容量的辅助函数
2157
+ var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2158
+ return items.reduce(function (total, item) {
2159
+ return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2160
+ }, 0);
2161
+ };
2162
+
2163
+ // 如果是多个预约,去要求助几个 holder 下最大的需求容量capacity
2164
+ var maxCapacity = 1;
2165
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2166
+ accountList.forEach(function (account) {
2167
+ var accountCartItems = _this12.store.cart.getCartByAccount(account.getId());
2168
+ var currentCapacity = calculateCapacityFromCartItems(accountCartItems);
2169
+ if (currentCapacity > maxCapacity) {
2170
+ maxCapacity = currentCapacity;
2171
+ }
2172
+ });
2173
+ } else {
2174
+ maxCapacity = calculateCapacityFromCartItems(cartItems);
2175
+ }
2156
2176
  var timeSlots = getTimeSlicesByResources({
2157
2177
  resourceIds: resourceIds,
2158
2178
  resourcesMap: resourcesMap,
@@ -2160,6 +2180,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2160
2180
  currentDate: dateRange[0].date,
2161
2181
  split: 10,
2162
2182
  resourcesUseableMap: resourcesUseableMap,
2183
+ capacity: maxCapacity,
2163
2184
  cut_off_time: maxCutOffTime,
2164
2185
  hasFlexibleDuration: hasFlexibleDuration,
2165
2186
  operating_day_boundary: operating_day_boundary,
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  };
327
327
  setOtherData(key: string, value: any): void;
328
328
  getOtherData(key: string): any;
329
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
329
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
330
330
  /**
331
331
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
332
332
  *
@@ -1399,7 +1399,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1399
1399
  isSingleResource = n.type === "single";
1400
1400
  }
1401
1401
  });
1402
- if (item.resource_id) {
1402
+ if (item.resource_id && !resourceIds.includes(item.resource_id)) {
1403
1403
  resourceIds.push(item.resource_id);
1404
1404
  }
1405
1405
  resourcesTypeId = (_g2 = (_f2 = (_e2 = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f2.find(
@@ -1487,6 +1487,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1487
1487
  return 0;
1488
1488
  }, 0);
1489
1489
  }
1490
+ const calculateCapacityFromCartItems = (items) => {
1491
+ return items.reduce((total, item) => {
1492
+ return total + ((0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 0);
1493
+ }, 0);
1494
+ };
1495
+ let maxCapacity = 1;
1496
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1497
+ accountList.forEach((account) => {
1498
+ const accountCartItems = this.store.cart.getCartByAccount(account.getId());
1499
+ const currentCapacity = calculateCapacityFromCartItems(accountCartItems);
1500
+ if (currentCapacity > maxCapacity) {
1501
+ maxCapacity = currentCapacity;
1502
+ }
1503
+ });
1504
+ } else {
1505
+ maxCapacity = calculateCapacityFromCartItems(cartItems);
1506
+ }
1490
1507
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1491
1508
  resourceIds,
1492
1509
  resourcesMap,
@@ -1494,6 +1511,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1494
1511
  currentDate: dateRange[0].date,
1495
1512
  split: 10,
1496
1513
  resourcesUseableMap,
1514
+ capacity: maxCapacity,
1497
1515
  cut_off_time: maxCutOffTime,
1498
1516
  hasFlexibleDuration,
1499
1517
  operating_day_boundary,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.20",
4
+ "version": "2.1.21",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",