@pisell/pisellos 2.1.19 → 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,
@@ -245,17 +245,28 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
245
245
  var _getCapacityInfoByCar2 = getCapacityInfoByCartItem(cartItem),
246
246
  currentCapacity = _getCapacityInfoByCar2.currentCapacity;
247
247
  Object.keys(resourceTypeMap).forEach(function (formId) {
248
+ var _cartItem$_productOri;
248
249
  var resourcesInType = resourceTypeMap[formId];
249
250
  var resourceIdsInType = resourcesInType.map(function (r) {
250
251
  return r.id;
251
252
  });
253
+ var selectType = (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.product_resource) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.resources) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.find(function (r) {
254
+ var _r$id;
255
+ return ((_r$id = r.id) === null || _r$id === void 0 ? void 0 : _r$id.toString()) === formId;
256
+ })) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.type;
252
257
 
253
258
  // 检查该商品是否需要这种类型的资源
254
259
  var needsThisResourceType = productResourceIds.some(function (id) {
255
260
  return resourceIdsInType.includes(id);
256
261
  });
257
262
  if (needsThisResourceType) {
258
- requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
263
+ // 需要判断是单个预约还是多个预约,如果是单个预约,不用加 capacity,只用+1
264
+ if (selectType === 'single') {
265
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + 1;
266
+ } else {
267
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
268
+ }
269
+ // requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
259
270
  }
260
271
  });
261
272
  });
@@ -275,12 +286,12 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
275
286
  _step2;
276
287
  try {
277
288
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
278
- var _cartItem$_productOri;
289
+ var _cartItem$_productOri2;
279
290
  var cartItem = _step2.value;
280
- if ((_cartItem$_productOri = cartItem._productOrigin) !== null && _cartItem$_productOri !== void 0 && (_cartItem$_productOri = _cartItem$_productOri.product_resource) !== null && _cartItem$_productOri !== void 0 && _cartItem$_productOri.resources) {
291
+ if ((_cartItem$_productOri2 = cartItem._productOrigin) !== null && _cartItem$_productOri2 !== void 0 && (_cartItem$_productOri2 = _cartItem$_productOri2.product_resource) !== null && _cartItem$_productOri2 !== void 0 && _cartItem$_productOri2.resources) {
281
292
  resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
282
- var _r$id;
283
- return ((_r$id = r.id) === null || _r$id === void 0 ? void 0 : _r$id.toString()) === formId && r.status === 1;
293
+ var _r$id2;
294
+ return ((_r$id2 = r.id) === null || _r$id2 === void 0 ? void 0 : _r$id2.toString()) === formId && r.status === 1;
284
295
  });
285
296
  if (resourceTypeConfig) break;
286
297
  }
@@ -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,
@@ -182,13 +182,22 @@ function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResourc
182
182
  const productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
183
183
  const { currentCapacity } = getCapacityInfoByCartItem(cartItem);
184
184
  Object.keys(resourceTypeMap).forEach((formId) => {
185
+ var _a2, _b2, _c, _d;
185
186
  const resourcesInType = resourceTypeMap[formId];
186
187
  const resourceIdsInType = resourcesInType.map((r) => r.id);
188
+ const selectType = (_d = (_c = (_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c.find((r) => {
189
+ var _a3;
190
+ return ((_a3 = r.id) == null ? void 0 : _a3.toString()) === formId;
191
+ })) == null ? void 0 : _d.type;
187
192
  const needsThisResourceType = productResourceIds.some(
188
193
  (id) => resourceIdsInType.includes(id)
189
194
  );
190
195
  if (needsThisResourceType) {
191
- requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
196
+ if (selectType === "single") {
197
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + 1;
198
+ } else {
199
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
200
+ }
192
201
  }
193
202
  });
194
203
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.19",
4
+ "version": "2.1.21",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",