@pisell/pisellos 0.0.81 → 0.0.82

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.
@@ -457,4 +457,6 @@ export interface ProductResourceItem {
457
457
  updated_at: string;
458
458
  /** 可用资源列表 */
459
459
  renderList?: any[];
460
+ /** 资源类型 */
461
+ type: 'single' | 'multiple' | 'capacity';
460
462
  }
@@ -1092,6 +1092,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1092
1092
  if (currentResourcesCapacityMap[targetRes.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1093
1093
  return true;
1094
1094
  }
1095
+ currentResourcesCapacityMap[targetRes.id] += _currentCapacity;
1095
1096
  return false;
1096
1097
  }
1097
1098
  if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
@@ -1111,10 +1112,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1111
1112
  return false;
1112
1113
  });
1113
1114
  });
1114
- _this5.store.cart.updateItem({
1115
- _id: item._id,
1116
- resources: resources
1117
- });
1115
+ // session 类商品应该只调用清空 resource 的方法
1116
+ if (item.start_time) {
1117
+ var start_time = item.start_time;
1118
+ var end_time = item.end_time;
1119
+ var start_date = item.start_date;
1120
+ var end_date = item.end_date;
1121
+ _this5.store.cart.updateItem({
1122
+ _id: item._id,
1123
+ resources: resources,
1124
+ date: {
1125
+ startTime: dayjs("".concat(start_date, " ").concat(start_time)).format('YYYY-MM-DD HH:mm'),
1126
+ endTime: dayjs("".concat(end_date, " ").concat(end_time)).format('YYYY-MM-DD HH:mm')
1127
+ }
1128
+ });
1129
+ } else {
1130
+ _this5.store.cart.updateItem({
1131
+ _id: item._id,
1132
+ resources: resources
1133
+ });
1134
+ }
1118
1135
  });
1119
1136
  }
1120
1137
 
@@ -1222,7 +1239,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1222
1239
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1223
1240
  var cartItems = this.store.cart.getItems();
1224
1241
  var arr = [];
1225
- var capacityMap = {};
1226
1242
  cartItems.forEach(function (cartItem) {
1227
1243
  var _cartItem$_productOri, _cartItem$_productOri2;
1228
1244
  var selectedResources = [];
@@ -1235,9 +1251,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1235
1251
  capacity: formatCapacity
1236
1252
  });
1237
1253
  if (cartItem.holder_id) {
1238
- selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap, currentCapacity);
1254
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1239
1255
  } else {
1240
- selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap, currentCapacity);
1256
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1241
1257
  }
1242
1258
  var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri2 = cartItem._productOrigin) === null || _cartItem$_productOri2 === void 0 || (_cartItem$_productOri2 = _cartItem$_productOri2.product_resource) === null || _cartItem$_productOri2 === void 0 ? void 0 : _cartItem$_productOri2.resources) || [], selectedResources, currentCapacity);
1243
1259
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
@@ -1256,7 +1272,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1256
1272
  return 0;
1257
1273
  });
1258
1274
  n.renderList = n.renderList.filter(function (m) {
1259
- var recordCount = capacityMap[m.id] || 0;
1260
1275
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1261
1276
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1262
1277
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
@@ -1277,7 +1292,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1277
1292
  },
1278
1293
  time: item,
1279
1294
  resource: m,
1280
- currentCount: recordCount + (currentCapacity || 0),
1295
+ currentCount: currentCapacity || 0,
1281
1296
  resourcesUseableMap: resourcesUseableMap
1282
1297
  });
1283
1298
  // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
@@ -1347,7 +1362,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1347
1362
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1348
1363
  var cartItems = this.store.cart.getItems();
1349
1364
  var arr = [];
1350
- var capacityMap = {};
1351
1365
  cartItems.forEach(function (cartItem) {
1352
1366
  var _cartItem$_productOri4, _cartItem$_productOri5;
1353
1367
  var selectedResources = [];
@@ -1360,9 +1374,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1360
1374
  capacity: formatCapacity
1361
1375
  });
1362
1376
  if (cartItem.holder_id) {
1363
- selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap, currentCapacity);
1377
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1364
1378
  } else {
1365
- selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap, currentCapacity);
1379
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1366
1380
  }
1367
1381
  var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri5 = cartItem._productOrigin) === null || _cartItem$_productOri5 === void 0 || (_cartItem$_productOri5 = _cartItem$_productOri5.product_resource) === null || _cartItem$_productOri5 === void 0 ? void 0 : _cartItem$_productOri5.resources) || [], selectedResources, currentCapacity);
1368
1382
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
@@ -1381,7 +1395,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1381
1395
  return 0;
1382
1396
  });
1383
1397
  n.renderList = n.renderList.filter(function (m) {
1384
- var recordCount = capacityMap[m.id] || 0;
1385
1398
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1386
1399
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1387
1400
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
@@ -1402,7 +1415,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1402
1415
  },
1403
1416
  time: item,
1404
1417
  resource: m,
1405
- currentCount: recordCount + (currentCapacity || 0),
1418
+ currentCount: currentCapacity || 0,
1406
1419
  resourcesUseableMap: resourcesUseableMap
1407
1420
  });
1408
1421
  // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
@@ -1465,9 +1478,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1465
1478
  dateRange.forEach(function (n) {
1466
1479
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1467
1480
  });
1468
- // 这里为什么要 cloneDeep:因为 getOthersSelectedResources 和 getOthersCartSelectedResources 会修改 resourcesMap 的 capacity
1469
1481
  // 用于确保后续分配的容量不会超出
1470
- var resourcesMap = getResourcesMap(cloneDeep(resources));
1482
+ var resourcesMap = getResourcesMap(resources);
1471
1483
  var targetCartItem = cartItems.find(function (n) {
1472
1484
  return n._id === id;
1473
1485
  });
@@ -1483,9 +1495,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1483
1495
  capacity: formatCapacity
1484
1496
  });
1485
1497
  if (targetCartItem.holder_id) {
1486
- selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap, currentCapacity);
1498
+ selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1487
1499
  } else {
1488
- selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap, currentCapacity);
1500
+ selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1489
1501
  }
1490
1502
  var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod3 = targetCartItem._productOrigin) === null || _targetCartItem$_prod3 === void 0 || (_targetCartItem$_prod3 = _targetCartItem$_prod3.product_resource) === null || _targetCartItem$_prod3 === void 0 ? void 0 : _targetCartItem$_prod3.resources) || [], selectedResources, currentCapacity);
1491
1503
  productResources.forEach(function (item) {
@@ -1580,7 +1592,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1580
1592
  }
1581
1593
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1582
1594
  var allCartItems = cloneDeep(this.store.cart.getItems());
1583
- var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap, capacity || 0);
1595
+ var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1584
1596
  var allProductResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri7 = cartItem._productOrigin) === null || _cartItem$_productOri7 === void 0 || (_cartItem$_productOri7 = _cartItem$_productOri7.product_resource) === null || _cartItem$_productOri7 === void 0 ? void 0 : _cartItem$_productOri7.resources) || [], selectedResources, 1);
1585
1597
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1586
1598
  return n.code === resources_code;
@@ -1595,7 +1607,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1595
1607
  return 0;
1596
1608
  });
1597
1609
  var resourcesUseableMap = _toConsumableArray(selectedResources).reduce(function (acc, n) {
1598
- acc[n] = false;
1610
+ var _resourcesMap$n;
1611
+ acc[n] = ((_resourcesMap$n = resourcesMap[n]) === null || _resourcesMap$n === void 0 ? void 0 : _resourcesMap$n.resourceType) === 'single' ? false : true;
1599
1612
  return acc;
1600
1613
  }, {});
1601
1614
 
@@ -1730,10 +1743,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1730
1743
  };
1731
1744
  }
1732
1745
  if (recordTimeSlots) {
1733
- if (index !== 0 && recordTimeSlots) {
1734
- var _item$_productOrigin$, _item$_productOrigin4, _ref9, _item$_productOrigin5, _item$_productOrigin$2, _item$_productOrigin6, _ref10, _item$_productOrigin7;
1735
- var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref9 = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.type) !== null && _ref9 !== void 0 ? _ref9 : 'minutes');
1736
- var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref10 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
1746
+ var _item$_productOrigin4;
1747
+ // 同一账号下,如果当前商品不是第一个,则需要根据上一个商品的 end_time 和 duration 计算出当前商品的 start_time 和 end_time
1748
+ // 前提:当前资源是单个预约才需要这么做
1749
+ var currentResourceConfig = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.product_resource) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.resources) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.find(function (n) {
1750
+ return n.code === resources_code;
1751
+ });
1752
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single') {
1753
+ var _item$_productOrigin$, _item$_productOrigin5, _ref9, _item$_productOrigin6, _item$_productOrigin$2, _item$_productOrigin7, _ref10, _item$_productOrigin8;
1754
+ var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref9 = (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.type) !== null && _ref9 !== void 0 ? _ref9 : 'minutes');
1755
+ var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref10 = (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.duration) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
1737
1756
  recordTimeSlots = {
1738
1757
  start_time: start_at.format('HH:mm'),
1739
1758
  end_time: end_at.format('HH:mm'),
@@ -1775,12 +1794,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1775
1794
  errorList.push(item._id);
1776
1795
  }
1777
1796
  } else {
1778
- var _item$_productOrigin8, _productResources$fin;
1797
+ var _item$_productOrigin9, _productResources$fin;
1779
1798
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1780
1799
  var allCartItems = cloneDeep(_this8.store.cart.getItems());
1781
1800
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1782
1801
  var selectedResources = [];
1783
- var _resources = cloneDeep(((_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.resources) || []);
1802
+ var _resources = cloneDeep(((_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.product_resource) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.resources) || []);
1784
1803
  var currentResourcesRenderList = [];
1785
1804
  _resources.forEach(function (n) {
1786
1805
  var _n$renderList;
@@ -1803,9 +1822,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1803
1822
  });
1804
1823
  var resourcesMap = getResourcesMap(currentResourcesRenderList);
1805
1824
  if (item.holder_id) {
1806
- selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap, currentCapacity);
1825
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap);
1807
1826
  } else {
1808
- selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap, currentCapacity);
1827
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap);
1809
1828
  }
1810
1829
  var productResources = getResourcesByProduct(resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1811
1830
  productResources.forEach(function (item) {
@@ -1880,8 +1899,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1880
1899
  var resourceIds = [];
1881
1900
  var resourcesTypeId = undefined;
1882
1901
  cartItems.forEach(function (item) {
1883
- var _item$_productOrigin9, _item$_productOrigin10;
1884
- (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.product_resource) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.resources) === null || _item$_productOrigin9 === void 0 || _item$_productOrigin9.forEach(function (n) {
1902
+ var _item$_productOrigin10, _item$_productOrigin11;
1903
+ (_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.product_resource) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.resources) === null || _item$_productOrigin10 === void 0 || _item$_productOrigin10.forEach(function (n) {
1885
1904
  if (n.code === resources_code) {
1886
1905
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1887
1906
  }
@@ -1892,9 +1911,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1892
1911
  if (item.resource_id) {
1893
1912
  resourceIds.push(item.resource_id);
1894
1913
  }
1895
- resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.product_resource) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.resources) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.find(function (n) {
1914
+ resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.product_resource) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.resources) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.find(function (n) {
1896
1915
  return n.code === resources_code;
1897
- })) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.id;
1916
+ })) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.id;
1898
1917
  });
1899
1918
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
1900
1919
  if ((_dateRange = dateRange) !== null && _dateRange !== void 0 && (_dateRange = _dateRange[0]) !== null && _dateRange !== void 0 && (_dateRange = _dateRange.resource) !== null && _dateRange !== void 0 && _dateRange.length) {
@@ -1914,8 +1933,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1914
1933
  var checkDuration = function checkDuration(cartItems) {
1915
1934
  var accountDuration = 0;
1916
1935
  cartItems.forEach(function (item) {
1917
- var _item$_productOrigin$3, _item$_productOrigin11;
1918
- accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.duration) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1936
+ var _item$_productOrigin$3, _item$_productOrigin12;
1937
+ accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.duration) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1919
1938
  });
1920
1939
  if (accountDuration > duration) {
1921
1940
  duration = accountDuration;
@@ -1985,9 +2004,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1985
2004
  var _newResources$;
1986
2005
  var newResources = cloneDeep(item._origin.resources);
1987
2006
  newResources.forEach(function (resource) {
1988
- var _item$_productOrigin$4, _item$_productOrigin12, _ref11, _item$_productOrigin13;
2007
+ var _item$_productOrigin$4, _item$_productOrigin13, _ref11, _item$_productOrigin14;
1989
2008
  resource.startTime = currentStartTime;
1990
- resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.duration) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref11 = (_item$_productOrigin13 = item._productOrigin) === null || _item$_productOrigin13 === void 0 || (_item$_productOrigin13 = _item$_productOrigin13.duration) === null || _item$_productOrigin13 === void 0 ? void 0 : _item$_productOrigin13.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes').format('YYYY-MM-DD HH:mm');
2009
+ resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_item$_productOrigin13 = item._productOrigin) === null || _item$_productOrigin13 === void 0 || (_item$_productOrigin13 = _item$_productOrigin13.duration) === null || _item$_productOrigin13 === void 0 ? void 0 : _item$_productOrigin13.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref11 = (_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 || (_item$_productOrigin14 = _item$_productOrigin14.duration) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes').format('YYYY-MM-DD HH:mm');
1991
2010
  delete resource.times;
1992
2011
  });
1993
2012
  _this10.store.cart.updateItem({
@@ -2093,7 +2112,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2093
2112
  });
2094
2113
  var cartItems = cloneDeep(this.store.cart.getItems());
2095
2114
  var resourcesMap = getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []);
2096
- var selectedResources = getOthersSelectedResources(cartItems, '', resourcesMap, 1);
2115
+ var selectedResources = getOthersSelectedResources(cartItems, '', resourcesMap);
2097
2116
  var productResources = getResourcesByProduct(resourcesMap, resources || ((_this$store$currentPr2 = this.store.currentProduct) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.getData()) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.product_resource) === null || _this$store$currentPr2 === void 0 ? void 0 : _this$store$currentPr2.resources) || [], selectedResources, 1);
2098
2117
  var minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, date);
2099
2118
  var scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime);
@@ -2111,9 +2130,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2111
2130
  if (!aIsCombined && bIsCombined) return -1;
2112
2131
  return 0;
2113
2132
  });
2114
- var resourcesUseableMap = {};
2133
+
2115
2134
  // 计算每个日程切片下日程可用的资源的容量总和
2116
2135
  var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
2136
+ // 用来计算资源的可使用情况,针对单个schedule 时间片
2137
+ var resourcesUseableMap = {};
2117
2138
  var count = 0;
2118
2139
  // 遍历所有资源
2119
2140
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
@@ -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>, currentCapacity: number) => number[];
138
+ export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem>) => 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>, currentCapacity: number) => number[];
147
+ export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
148
148
  interface CapacityItem {
149
149
  id: number;
150
150
  value: number;
@@ -580,7 +580,7 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
580
580
  * @return {*}
581
581
  * @Author: jinglin.tan
582
582
  */
583
- export var getOthersSelectedResources = function getOthersSelectedResources(cartItems, accountId, resourcesMap, currentCapacity) {
583
+ export var getOthersSelectedResources = function getOthersSelectedResources(cartItems, accountId, resourcesMap) {
584
584
  return cartItems.reduce(function (acc, d) {
585
585
  if (d.holder_id !== accountId) {
586
586
  var _d$_origin;
@@ -611,7 +611,7 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
611
611
  });
612
612
  }
613
613
  acc.push(n.id);
614
- if (resourcesMap[n.id]) resourcesMap[n.id].capacity -= currentCapacity || 0;
614
+ // if (resourcesMap[n.id]) resourcesMap[n.id].capacity -= currentCapacity || 0;
615
615
  });
616
616
  }
617
617
  }
@@ -627,7 +627,7 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
627
627
  * @return {*}
628
628
  * @Author: jinglin.tan
629
629
  */
630
- export var getOthersCartSelectedResources = function getOthersCartSelectedResources(cartItems, cartItemId, resourcesMap, currentCapacity) {
630
+ export var getOthersCartSelectedResources = function getOthersCartSelectedResources(cartItems, cartItemId, resourcesMap) {
631
631
  return cartItems.reduce(function (acc, d) {
632
632
  if (d._id !== cartItemId) {
633
633
  var _d$_origin2;
@@ -457,4 +457,6 @@ export interface ProductResourceItem {
457
457
  updated_at: string;
458
458
  /** 可用资源列表 */
459
459
  renderList?: any[];
460
+ /** 资源类型 */
461
+ type: 'single' | 'multiple' | 'capacity';
460
462
  }
@@ -543,6 +543,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
543
543
  if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
544
544
  return true;
545
545
  }
546
+ currentResourcesCapacityMap[targetRes.id] += currentCapacity;
546
547
  return false;
547
548
  }
548
549
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
@@ -567,10 +568,25 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
567
568
  return false;
568
569
  });
569
570
  });
570
- this.store.cart.updateItem({
571
- _id: item._id,
572
- resources
573
- });
571
+ if (item.start_time) {
572
+ const start_time = item.start_time;
573
+ const end_time = item.end_time;
574
+ const start_date = item.start_date;
575
+ const end_date = item.end_date;
576
+ this.store.cart.updateItem({
577
+ _id: item._id,
578
+ resources,
579
+ date: {
580
+ startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format("YYYY-MM-DD HH:mm"),
581
+ endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format("YYYY-MM-DD HH:mm")
582
+ }
583
+ });
584
+ } else {
585
+ this.store.cart.updateItem({
586
+ _id: item._id,
587
+ resources
588
+ });
589
+ }
574
590
  });
575
591
  }
576
592
  // 删除购物车里某个商品
@@ -652,7 +668,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
652
668
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
653
669
  const cartItems = this.store.cart.getItems();
654
670
  const arr = [];
655
- const capacityMap = {};
656
671
  cartItems.forEach((cartItem) => {
657
672
  var _a, _b, _c;
658
673
  let selectedResources = [];
@@ -666,15 +681,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
666
681
  selectedResources = (0, import_resources.getOthersSelectedResources)(
667
682
  cartItems,
668
683
  cartItem.holder_id,
669
- resourcesMap,
670
- currentCapacity
684
+ resourcesMap
671
685
  );
672
686
  } else {
673
687
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
674
688
  cartItems,
675
689
  cartItem._id,
676
- resourcesMap,
677
- currentCapacity
690
+ resourcesMap
678
691
  );
679
692
  }
680
693
  const productResources = (0, import_resources.getResourcesByProduct)(
@@ -703,7 +716,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
703
716
  return 0;
704
717
  });
705
718
  n.renderList = n.renderList.filter((m) => {
706
- const recordCount = capacityMap[m.id] || 0;
707
719
  const mTimes = m.times.filter((n2) => {
708
720
  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
721
  });
@@ -720,7 +732,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
720
732
  },
721
733
  time: item,
722
734
  resource: m,
723
- currentCount: recordCount + (currentCapacity || 0),
735
+ currentCount: currentCapacity || 0,
724
736
  resourcesUseableMap
725
737
  });
726
738
  if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
@@ -783,7 +795,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
783
795
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
784
796
  const cartItems = this.store.cart.getItems();
785
797
  const arr = [];
786
- const capacityMap = {};
787
798
  cartItems.forEach((cartItem) => {
788
799
  var _a, _b, _c;
789
800
  let selectedResources = [];
@@ -797,15 +808,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
797
808
  selectedResources = (0, import_resources.getOthersSelectedResources)(
798
809
  cartItems,
799
810
  cartItem.holder_id,
800
- resourcesMap,
801
- currentCapacity
811
+ resourcesMap
802
812
  );
803
813
  } else {
804
814
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
805
815
  cartItems,
806
816
  cartItem._id,
807
- resourcesMap,
808
- currentCapacity
817
+ resourcesMap
809
818
  );
810
819
  }
811
820
  const productResources = (0, import_resources.getResourcesByProduct)(
@@ -834,7 +843,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
834
843
  return 0;
835
844
  });
836
845
  n.renderList = n.renderList.filter((m) => {
837
- const recordCount = capacityMap[m.id] || 0;
838
846
  const mTimes = m.times.filter((n2) => {
839
847
  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));
840
848
  });
@@ -851,7 +859,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
851
859
  },
852
860
  time: item,
853
861
  resource: m,
854
- currentCount: recordCount + (currentCapacity || 0),
862
+ currentCount: currentCapacity || 0,
855
863
  resourcesUseableMap
856
864
  });
857
865
  if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
@@ -904,7 +912,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
904
912
  if (n.resource)
905
913
  resources.push(...n.resource);
906
914
  });
907
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
915
+ const resourcesMap = (0, import_utils.getResourcesMap)(resources);
908
916
  const targetCartItem = cartItems.find((n) => n._id === id);
909
917
  if (!targetCartItem) {
910
918
  throw new Error(`没有找到${id}购物车商品`);
@@ -919,15 +927,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
919
927
  selectedResources = (0, import_resources.getOthersSelectedResources)(
920
928
  cartItems,
921
929
  targetCartItem.holder_id,
922
- resourcesMap,
923
- currentCapacity
930
+ resourcesMap
924
931
  );
925
932
  } else {
926
933
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
927
934
  cartItems,
928
935
  targetCartItem._id,
929
- resourcesMap,
930
- currentCapacity
936
+ resourcesMap
931
937
  );
932
938
  }
933
939
  const productResources = (0, import_resources.getResourcesByProduct)(
@@ -1011,8 +1017,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1011
1017
  const selectedResources = (0, import_resources.getOthersSelectedResources)(
1012
1018
  allCartItems,
1013
1019
  holder_id,
1014
- resourcesMap,
1015
- capacity || 0
1020
+ resourcesMap
1016
1021
  );
1017
1022
  let allProductResources = (0, import_resources.getResourcesByProduct)(
1018
1023
  resourcesMap,
@@ -1034,7 +1039,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1034
1039
  const resourcesUseableMap = [
1035
1040
  ...selectedResources
1036
1041
  ].reduce((acc, n) => {
1037
- acc[n] = false;
1042
+ var _a2;
1043
+ acc[n] = ((_a2 = resourcesMap[n]) == null ? void 0 : _a2.resourceType) === "single" ? false : true;
1038
1044
  return acc;
1039
1045
  }, {});
1040
1046
  if (timeSlots) {
@@ -1106,7 +1112,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1106
1112
  const selectForCartResources = (cartItems2) => {
1107
1113
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
1108
1114
  cartItems2.forEach((item, index) => {
1109
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1115
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1110
1116
  const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
1111
1117
  capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
1112
1118
  product_bundle: item._origin.product.product_bundle
@@ -1121,14 +1127,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1121
1127
  };
1122
1128
  }
1123
1129
  if (recordTimeSlots) {
1124
- if (index !== 0 && recordTimeSlots) {
1130
+ const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find((n) => n.code === resources_code);
1131
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single") {
1125
1132
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
1126
- ((_c = (_b = item._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.value) ?? 0,
1127
- ((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.type) ?? "minutes"
1133
+ ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) ?? 0,
1134
+ ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.type) ?? "minutes"
1128
1135
  );
1129
1136
  let end_at = start_at.add(
1130
- ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) ?? 0,
1131
- ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.type) ?? "minutes"
1137
+ ((_j = (_i = item._productOrigin) == null ? void 0 : _i.duration) == null ? void 0 : _j.value) ?? 0,
1138
+ ((_l = (_k = item._productOrigin) == null ? void 0 : _k.duration) == null ? void 0 : _l.type) ?? "minutes"
1132
1139
  );
1133
1140
  recordTimeSlots = {
1134
1141
  start_time: start_at.format("HH:mm"),
@@ -1173,7 +1180,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1173
1180
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1174
1181
  let selectedResources = [];
1175
1182
  const resources2 = (0, import_lodash_es.cloneDeep)(
1176
- ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || []
1183
+ ((_n = (_m = item._productOrigin) == null ? void 0 : _m.product_resource) == null ? void 0 : _n.resources) || []
1177
1184
  );
1178
1185
  const currentResourcesRenderList = [];
1179
1186
  resources2.forEach((n) => {
@@ -1198,15 +1205,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1198
1205
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1199
1206
  allCartItems,
1200
1207
  item.holder_id,
1201
- resourcesMap,
1202
- currentCapacity
1208
+ resourcesMap
1203
1209
  );
1204
1210
  } else {
1205
1211
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
1206
1212
  allCartItems,
1207
1213
  item._id,
1208
- resourcesMap,
1209
- currentCapacity
1214
+ resourcesMap
1210
1215
  );
1211
1216
  }
1212
1217
  const productResources = (0, import_resources.getResourcesByProduct)(
@@ -1223,11 +1228,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1223
1228
  return recordCount >= currentCapacity;
1224
1229
  });
1225
1230
  });
1226
- const targetRenderList = (_l = productResources.find(
1231
+ const targetRenderList = (_o = productResources.find(
1227
1232
  (n) => n.code === resources_code
1228
- )) == null ? void 0 : _l.renderList;
1233
+ )) == null ? void 0 : _o.renderList;
1229
1234
  if (targetRenderList && targetRenderList.length > 0) {
1230
- if ((_m = item._origin.resources) == null ? void 0 : _m.some(
1235
+ if ((_p = item._origin.resources) == null ? void 0 : _p.some(
1231
1236
  (n) => n.form_id === targetRenderList[0].form_id
1232
1237
  )) {
1233
1238
  return;
@@ -1451,8 +1456,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1451
1456
  const selectedResources = (0, import_resources.getOthersSelectedResources)(
1452
1457
  cartItems,
1453
1458
  "",
1454
- resourcesMap,
1455
- 1
1459
+ resourcesMap
1456
1460
  );
1457
1461
  const productResources = (0, import_resources.getResourcesByProduct)(
1458
1462
  resourcesMap,
@@ -1478,8 +1482,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1478
1482
  return -1;
1479
1483
  return 0;
1480
1484
  });
1481
- const resourcesUseableMap = {};
1482
1485
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1486
+ const resourcesUseableMap = {};
1483
1487
  let count = 0;
1484
1488
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1485
1489
  let currentResourcesCount = 0;
@@ -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>, currentCapacity: number) => number[];
138
+ export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem>) => 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>, currentCapacity: number) => number[];
147
+ export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
148
148
  interface CapacityItem {
149
149
  id: number;
150
150
  value: number;
@@ -433,7 +433,7 @@ var getTimeSlicesByResources = ({
433
433
  let intersection = getTimesIntersection(timeSliceList, resources.length);
434
434
  return intersection;
435
435
  };
436
- var getOthersSelectedResources = (cartItems, accountId, resourcesMap, currentCapacity) => {
436
+ var getOthersSelectedResources = (cartItems, accountId, resourcesMap) => {
437
437
  return cartItems.reduce((acc, d) => {
438
438
  var _a;
439
439
  if (d.holder_id !== accountId) {
@@ -456,15 +456,13 @@ var getOthersSelectedResources = (cartItems, accountId, resourcesMap, currentCap
456
456
  });
457
457
  }
458
458
  acc.push(n.id);
459
- if (resourcesMap[n.id])
460
- resourcesMap[n.id].capacity -= currentCapacity || 0;
461
459
  });
462
460
  }
463
461
  }
464
462
  return acc;
465
463
  }, []);
466
464
  };
467
- var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap, currentCapacity) => {
465
+ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
468
466
  return cartItems.reduce((acc, d) => {
469
467
  var _a;
470
468
  if (d._id !== cartItemId) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.81",
4
+ "version": "0.0.82",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",