@pisell/pisellos 0.0.80 → 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.
@@ -430,7 +430,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
430
430
  break;
431
431
  }
432
432
  _context7.next = 3;
433
- return this.store.accountList.addHolderAccounts([account], extra.customerId);
433
+ return this.store.accountList.addHolderAccounts({
434
+ holders: [account],
435
+ customerId: extra.customerId,
436
+ type: 'unshift'
437
+ });
434
438
  case 3:
435
439
  accountModules = _context7.sent;
436
440
  return _context7.abrupt("return", accountModules[0].getAccount());
@@ -463,7 +467,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
463
467
  _context8.next = 3;
464
468
  break;
465
469
  }
466
- this.store.accountList.addHolderAccounts(accounts, extra.customerId);
470
+ this.store.accountList.addHolderAccounts({
471
+ holders: accounts,
472
+ customerId: extra.customerId,
473
+ type: 'unshift'
474
+ });
467
475
  return _context8.abrupt("return");
468
476
  case 3:
469
477
  res = [];
@@ -643,7 +651,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
643
651
  var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
644
652
  var _this3 = this,
645
653
  _dateRange$,
646
- _dateRange$2;
654
+ _dateRange$2,
655
+ _dateRange$3;
647
656
  var params,
648
657
  products,
649
658
  startDate,
@@ -687,7 +696,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
687
696
  }
688
697
  dateRange = this.store.date.getDateRange();
689
698
  tempStartDate = startDate || (dateRange === null || dateRange === void 0 || (_dateRange$ = dateRange[0]) === null || _dateRange$ === void 0 ? void 0 : _dateRange$.date);
690
- tempEndDate = endDate || (dateRange === null || dateRange === void 0 || (_dateRange$2 = dateRange[1]) === null || _dateRange$2 === void 0 ? void 0 : _dateRange$2.date);
699
+ tempEndDate = endDate || (dateRange === null || dateRange === void 0 || (_dateRange$2 = dateRange[1]) === null || _dateRange$2 === void 0 ? void 0 : _dateRange$2.date) || (dateRange === null || dateRange === void 0 || (_dateRange$3 = dateRange[0]) === null || _dateRange$3 === void 0 ? void 0 : _dateRange$3.date);
691
700
  if (tempProducts.length) {
692
701
  _context13.next = 11;
693
702
  break;
@@ -1028,6 +1037,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1028
1037
  if (!targetCartItem) {
1029
1038
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(params._id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1030
1039
  }
1040
+ var currentResourcesCapacityMap = {};
1031
1041
  if (params.resources) {
1032
1042
  var _targetCartItem$_prod;
1033
1043
  var formatCapacity = formatDefaultCapacitys({
@@ -1039,19 +1049,53 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1039
1049
  });
1040
1050
  params.resources = params.resources.map(function (n) {
1041
1051
  n.capacity = currentCapacity || 1;
1052
+ currentResourcesCapacityMap[n.id] = currentCapacity;
1042
1053
  checkSubResourcesCapacity(n);
1043
1054
  return n;
1044
1055
  });
1045
1056
  }
1046
1057
  this.store.cart.updateItem(params);
1047
- // 更新购物车后,需要判定购物车里是否存在多个账号选择了相同资源的情况,如果是,则要把选择了相同资源的 product._origin.resources 给去除
1058
+ var allOriginResources = [];
1059
+ var dateRange = this.store.date.getDateRange();
1060
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
1061
+ dateRange.forEach(function (n) {
1062
+ if (n.resource) allOriginResources.push.apply(allOriginResources, _toConsumableArray(n.resource));
1063
+ });
1064
+ }
1065
+ // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1066
+ if (!allOriginResources.length) {
1067
+ var dateList = this.store.date.getDateList();
1068
+ dateList.forEach(function (n) {
1069
+ if (n.resource) allOriginResources.push.apply(allOriginResources, _toConsumableArray(n.resource));
1070
+ });
1071
+ }
1072
+ // 更新购物车后,需要判定购物车里是否存在多个账号选择了相同资源的情况,如果是,且资源是单个预约,则要把选择了相同资源的 product._origin.resources 给去除
1048
1073
  var cartItems = this.store.cart.getItems();
1049
1074
  cartItems.forEach(function (item) {
1050
- if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1051
- var _item$_origin$resourc;
1052
- var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1053
- // 检查当前资源是否与目标资源的任何资源匹配
1054
- return !targetCartItem._origin.resources.some(function (targetRes) {
1075
+ var _item$_origin$resourc;
1076
+ var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1077
+ // 检查当前资源是否与目标资源的任何资源匹配
1078
+ return !targetCartItem._origin.resources.some(function (targetRes) {
1079
+ // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1080
+ if (targetRes.resourceType !== 'single') {
1081
+ var _item$_productOrigin2;
1082
+ var _formatCapacity = formatDefaultCapacitys({
1083
+ capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1084
+ product_bundle: item._origin.product.product_bundle
1085
+ });
1086
+ var _currentCapacity = getSumCapacity({
1087
+ capacity: _formatCapacity
1088
+ });
1089
+ var originResource = allOriginResources.find(function (n) {
1090
+ return n.id === targetRes.id;
1091
+ });
1092
+ if (currentResourcesCapacityMap[targetRes.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1093
+ return true;
1094
+ }
1095
+ currentResourcesCapacityMap[targetRes.id] += _currentCapacity;
1096
+ return false;
1097
+ }
1098
+ if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1055
1099
  var _targetRes$metadata$c, _m$metadata$combined_;
1056
1100
  // 检查主资源ID是否匹配
1057
1101
  if (targetRes.id === m.id) return true;
@@ -1064,9 +1108,25 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1064
1108
  return m.metadata.combined_resource.resource_ids.includes(n);
1065
1109
  }))) return true;
1066
1110
  if (((_m$metadata$combined_ = m.metadata.combined_resource) === null || _m$metadata$combined_ === void 0 ? void 0 : _m$metadata$combined_.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id)) return true;
1067
- return false;
1068
- });
1111
+ }
1112
+ return false;
1113
+ });
1114
+ });
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
+ }
1069
1128
  });
1129
+ } else {
1070
1130
  _this5.store.cart.updateItem({
1071
1131
  _id: item._id,
1072
1132
  resources: resources
@@ -1179,15 +1239,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1179
1239
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1180
1240
  var cartItems = this.store.cart.getItems();
1181
1241
  var arr = [];
1182
- var capacityMap = {};
1183
1242
  cartItems.forEach(function (cartItem) {
1184
1243
  var _cartItem$_productOri, _cartItem$_productOri2;
1185
1244
  var selectedResources = [];
1186
- if (cartItem.holder_id) {
1187
- selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1188
- } else {
1189
- selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1190
- }
1191
1245
  var formatCapacity = formatDefaultCapacitys({
1192
1246
  capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
1193
1247
  product_bundle: cartItem._origin.product.product_bundle
@@ -1196,6 +1250,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1196
1250
  var currentCapacity = getSumCapacity({
1197
1251
  capacity: formatCapacity
1198
1252
  });
1253
+ if (cartItem.holder_id) {
1254
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1255
+ } else {
1256
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1257
+ }
1199
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);
1200
1259
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1201
1260
  if (cartItem._origin.start_time) {
@@ -1213,7 +1272,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1213
1272
  return 0;
1214
1273
  });
1215
1274
  n.renderList = n.renderList.filter(function (m) {
1216
- var recordCount = capacityMap[m.id] || 0;
1217
1275
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1218
1276
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1219
1277
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
@@ -1234,7 +1292,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1234
1292
  },
1235
1293
  time: item,
1236
1294
  resource: m,
1237
- currentCount: recordCount + (currentCapacity || 0),
1295
+ currentCount: currentCapacity || 0,
1238
1296
  resourcesUseableMap: resourcesUseableMap
1239
1297
  });
1240
1298
  // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
@@ -1304,15 +1362,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1304
1362
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1305
1363
  var cartItems = this.store.cart.getItems();
1306
1364
  var arr = [];
1307
- var capacityMap = {};
1308
1365
  cartItems.forEach(function (cartItem) {
1309
1366
  var _cartItem$_productOri4, _cartItem$_productOri5;
1310
1367
  var selectedResources = [];
1311
- if (cartItem.holder_id) {
1312
- selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1313
- } else {
1314
- selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1315
- }
1316
1368
  var formatCapacity = formatDefaultCapacitys({
1317
1369
  capacity: (_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.capacity,
1318
1370
  product_bundle: cartItem._origin.product.product_bundle
@@ -1321,6 +1373,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1321
1373
  var currentCapacity = getSumCapacity({
1322
1374
  capacity: formatCapacity
1323
1375
  });
1376
+ if (cartItem.holder_id) {
1377
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1378
+ } else {
1379
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1380
+ }
1324
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);
1325
1382
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1326
1383
  if (cartItem._origin.start_time) {
@@ -1338,7 +1395,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1338
1395
  return 0;
1339
1396
  });
1340
1397
  n.renderList = n.renderList.filter(function (m) {
1341
- var recordCount = capacityMap[m.id] || 0;
1342
1398
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1343
1399
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1344
1400
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
@@ -1359,7 +1415,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1359
1415
  },
1360
1416
  time: item,
1361
1417
  resource: m,
1362
- currentCount: recordCount + (currentCapacity || 0),
1418
+ currentCount: currentCapacity || 0,
1363
1419
  resourcesUseableMap: resourcesUseableMap
1364
1420
  });
1365
1421
  // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
@@ -1422,9 +1478,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1422
1478
  dateRange.forEach(function (n) {
1423
1479
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1424
1480
  });
1425
- // 这里为什么要 cloneDeep:因为 getOthersSelectedResources 和 getOthersCartSelectedResources 会修改 resourcesMap 的 capacity
1426
1481
  // 用于确保后续分配的容量不会超出
1427
- var resourcesMap = getResourcesMap(cloneDeep(resources));
1482
+ var resourcesMap = getResourcesMap(resources);
1428
1483
  var targetCartItem = cartItems.find(function (n) {
1429
1484
  return n._id === id;
1430
1485
  });
@@ -1432,11 +1487,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1432
1487
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1433
1488
  }
1434
1489
  var selectedResources = [];
1435
- if (targetCartItem.holder_id) {
1436
- selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1437
- } else {
1438
- selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1439
- }
1440
1490
  var formatCapacity = formatDefaultCapacitys({
1441
1491
  capacity: (_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.capacity,
1442
1492
  product_bundle: targetCartItem._origin.product.product_bundle
@@ -1444,6 +1494,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1444
1494
  var currentCapacity = getSumCapacity({
1445
1495
  capacity: formatCapacity
1446
1496
  });
1497
+ if (targetCartItem.holder_id) {
1498
+ selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1499
+ } else {
1500
+ selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1501
+ }
1447
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);
1448
1503
  productResources.forEach(function (item) {
1449
1504
  item.renderList = item.renderList.filter(function (n) {
@@ -1552,7 +1607,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1552
1607
  return 0;
1553
1608
  });
1554
1609
  var resourcesUseableMap = _toConsumableArray(selectedResources).reduce(function (acc, n) {
1555
- 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;
1556
1612
  return acc;
1557
1613
  }, {});
1558
1614
 
@@ -1648,16 +1704,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1648
1704
  }, {
1649
1705
  key: "autoSelectAllProductResources",
1650
1706
  value: function autoSelectAllProductResources(resources_code, timeSlots) {
1651
- var _dateRange$3,
1707
+ var _dateRange$4,
1652
1708
  _this8 = this;
1653
1709
  var dateRange = this.store.date.getDateRange();
1654
1710
  var resources = [];
1655
- if (dateRange !== null && dateRange !== void 0 && (_dateRange$3 = dateRange[0]) !== null && _dateRange$3 !== void 0 && _dateRange$3.date) {
1711
+ if (dateRange !== null && dateRange !== void 0 && (_dateRange$4 = dateRange[0]) !== null && _dateRange$4 !== void 0 && _dateRange$4.date) {
1656
1712
  dateRange.forEach(function (n) {
1657
1713
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1658
1714
  });
1659
1715
  }
1660
- var resourcesMap = getResourcesMap(cloneDeep(resources));
1716
+ // const resourcesMap = getResourcesMap(cloneDeep(resources));
1661
1717
  // 一个账号一个账号处理
1662
1718
  var errorList = [];
1663
1719
  var selectResourcesMap = {};
@@ -1669,9 +1725,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1669
1725
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1670
1726
 
1671
1727
  cartItems.forEach(function (item, index) {
1672
- var _item$_productOrigin2;
1728
+ var _item$_productOrigin3;
1673
1729
  var formatCapacity = formatDefaultCapacitys({
1674
- capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1730
+ capacity: (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.capacity,
1675
1731
  product_bundle: item._origin.product.product_bundle
1676
1732
  });
1677
1733
  var currentCapacity = getSumCapacity({
@@ -1687,10 +1743,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1687
1743
  };
1688
1744
  }
1689
1745
  if (recordTimeSlots) {
1690
- if (index !== 0 && recordTimeSlots) {
1691
- var _item$_productOrigin$, _item$_productOrigin3, _ref9, _item$_productOrigin4, _item$_productOrigin$2, _item$_productOrigin5, _ref10, _item$_productOrigin6;
1692
- var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 || (_item$_productOrigin3 = _item$_productOrigin3.duration) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref9 = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.type) !== null && _ref9 !== void 0 ? _ref9 : 'minutes');
1693
- var end_at = start_at.add((_item$_productOrigin$2 = (_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$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref10 = (_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 && _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');
1694
1756
  recordTimeSlots = {
1695
1757
  start_time: start_at.format('HH:mm'),
1696
1758
  end_time: end_at.format('HH:mm'),
@@ -1732,12 +1794,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1732
1794
  errorList.push(item._id);
1733
1795
  }
1734
1796
  } else {
1735
- var _item$_productOrigin7, _productResources$fin;
1797
+ var _item$_productOrigin9, _productResources$fin;
1736
1798
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1737
1799
  var allCartItems = cloneDeep(_this8.store.cart.getItems());
1738
1800
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1739
1801
  var selectedResources = [];
1740
- var _resources = cloneDeep(((_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.product_resource) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.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) || []);
1741
1803
  var currentResourcesRenderList = [];
1742
1804
  _resources.forEach(function (n) {
1743
1805
  var _n$renderList;
@@ -1745,7 +1807,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1745
1807
  // 过滤掉 capacity 小于 currentCapacity 的资源
1746
1808
  n.renderList = n.renderList.filter(function (m) {
1747
1809
  var _item$duration;
1748
- var recordCount = m.capacity || 0;
1810
+ // 同时 还需要减去 selectResourcesMap 里已经选中的资源的数量
1811
+ var recordCount = (m.capacity || 0) - (selectResourcesMap[m.id] || 0);
1749
1812
  var timeSlots = getTimeSlicesByResource({
1750
1813
  resource: m,
1751
1814
  duration: (item === null || item === void 0 || (_item$duration = item.duration) === null || _item$duration === void 0 ? void 0 : _item$duration.value) || 0,
@@ -1757,16 +1820,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1757
1820
  currentResourcesRenderList.push.apply(currentResourcesRenderList, _toConsumableArray(n.renderList || []));
1758
1821
  }
1759
1822
  });
1760
- var _resourcesMap2 = getResourcesMap(currentResourcesRenderList);
1823
+ var resourcesMap = getResourcesMap(currentResourcesRenderList);
1761
1824
  if (item.holder_id) {
1762
- selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, _resourcesMap2);
1825
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap);
1763
1826
  } else {
1764
- selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap2);
1827
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap);
1765
1828
  }
1766
- var productResources = getResourcesByProduct(_resourcesMap2, cloneDeep(_resources), selectedResources, currentCapacity);
1829
+ var productResources = getResourcesByProduct(resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1767
1830
  productResources.forEach(function (item) {
1768
1831
  item.renderList = item.renderList.filter(function (n) {
1769
- var recordCount = n.capacity || 0;
1832
+ var recordCount = (n.capacity || 0) - (selectResourcesMap[n.id] || 0);
1770
1833
  if (n.onlyComputed) return false;
1771
1834
  return recordCount >= currentCapacity;
1772
1835
  });
@@ -1787,6 +1850,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1787
1850
  targetResource.capacity = currentCapacity;
1788
1851
  // 在这里处理 children 的数据
1789
1852
  checkSubResourcesCapacity(targetResource);
1853
+ if (!selectResourcesMap[targetResource.id]) {
1854
+ selectResourcesMap[targetResource.id] = currentCapacity;
1855
+ } else {
1856
+ selectResourcesMap[targetResource.id] += currentCapacity;
1857
+ }
1790
1858
  _this8.store.cart.updateItem({
1791
1859
  _id: item._id,
1792
1860
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
@@ -1831,8 +1899,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1831
1899
  var resourceIds = [];
1832
1900
  var resourcesTypeId = undefined;
1833
1901
  cartItems.forEach(function (item) {
1834
- var _item$_productOrigin8, _item$_productOrigin9;
1835
- (_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.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) {
1836
1904
  if (n.code === resources_code) {
1837
1905
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1838
1906
  }
@@ -1843,9 +1911,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1843
1911
  if (item.resource_id) {
1844
1912
  resourceIds.push(item.resource_id);
1845
1913
  }
1846
- resourcesTypeId = item === null || item === void 0 || (_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 = _item$_productOrigin9.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) {
1847
1915
  return n.code === resources_code;
1848
- })) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.id;
1916
+ })) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.id;
1849
1917
  });
1850
1918
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
1851
1919
  if ((_dateRange = dateRange) !== null && _dateRange !== void 0 && (_dateRange = _dateRange[0]) !== null && _dateRange !== void 0 && (_dateRange = _dateRange.resource) !== null && _dateRange !== void 0 && _dateRange.length) {
@@ -1865,8 +1933,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1865
1933
  var checkDuration = function checkDuration(cartItems) {
1866
1934
  var accountDuration = 0;
1867
1935
  cartItems.forEach(function (item) {
1868
- var _item$_productOrigin$3, _item$_productOrigin10;
1869
- accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.duration) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.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;
1870
1938
  });
1871
1939
  if (accountDuration > duration) {
1872
1940
  duration = accountDuration;
@@ -1933,11 +2001,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1933
2001
  Object.values(itemsByAccount).forEach(function (accountItems) {
1934
2002
  var currentStartTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
1935
2003
  accountItems.forEach(function (item, index) {
2004
+ var _newResources$;
1936
2005
  var newResources = cloneDeep(item._origin.resources);
1937
2006
  newResources.forEach(function (resource) {
1938
- var _item$_productOrigin$4, _item$_productOrigin11, _ref11, _item$_productOrigin12;
2007
+ var _item$_productOrigin$4, _item$_productOrigin13, _ref11, _item$_productOrigin14;
1939
2008
  resource.startTime = currentStartTime;
1940
- resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_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$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref11 = (_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.duration) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.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');
1941
2010
  delete resource.times;
1942
2011
  });
1943
2012
  _this10.store.cart.updateItem({
@@ -1946,7 +2015,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1946
2015
  });
1947
2016
 
1948
2017
  // 更新下一个商品的开始时间为当前商品的结束时间
1949
- if (index < accountItems.length - 1) {
2018
+ if (index < accountItems.length - 1 && (newResources === null || newResources === void 0 || (_newResources$ = newResources[0]) === null || _newResources$ === void 0 ? void 0 : _newResources$.resourceType) === 'single') {
1950
2019
  currentStartTime = newResources[0].endTime;
1951
2020
  }
1952
2021
  });
@@ -2061,9 +2130,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2061
2130
  if (!aIsCombined && bIsCombined) return -1;
2062
2131
  return 0;
2063
2132
  });
2064
- var resourcesUseableMap = {};
2133
+
2065
2134
  // 计算每个日程切片下日程可用的资源的容量总和
2066
2135
  var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
2136
+ // 用来计算资源的可使用情况,针对单个schedule 时间片
2137
+ var resourcesUseableMap = {};
2067
2138
  var count = 0;
2068
2139
  // 遍历所有资源
2069
2140
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
@@ -242,7 +242,11 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
242
242
  return item.default_resource.indexOf(d) == -1;
243
243
  });
244
244
  var optional_resource = item.optional_resource.reduce(function (childAcc, d) {
245
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
245
+ var _resourcesMap$d;
246
+ // 如果其他资源选择过,并且这个资源是单个预约,则不可以选中此资源
247
+ // TODO: 如果容量超了这里怎么处理?
248
+ var isSelectSingleResources = ((_resourcesMap$d = resourcesMap[d]) === null || _resourcesMap$d === void 0 ? void 0 : _resourcesMap$d.resourceType) === 'single' && selectedResources.includes(resourcesMap[d].id);
249
+ if (resourcesMap[d] && !isSelectSingleResources) {
246
250
  // 拼装组合资源的数据
247
251
  var combiningResources = [];
248
252
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
@@ -274,7 +278,9 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
274
278
  return childAcc;
275
279
  }, []);
276
280
  var default_resource = item.default_resource.reduce(function (childAcc, d) {
277
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
281
+ var _resourcesMap$d2;
282
+ var isSelectSingleResources = ((_resourcesMap$d2 = resourcesMap[d]) === null || _resourcesMap$d2 === void 0 ? void 0 : _resourcesMap$d2.resourceType) === 'single' && selectedResources.includes(resourcesMap[d].id);
283
+ if (resourcesMap[d] && !isSelectSingleResources) {
278
284
  // 拼装组合资源的数据
279
285
  var combiningResources = [];
280
286
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
@@ -589,9 +595,9 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
589
595
  return acc;
590
596
  }
591
597
  acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
592
- n.metadata.combined_resource.resource_ids.forEach(function (m) {
593
- resourcesMap[m].capacity -= n.num;
594
- });
598
+ // n.metadata.combined_resource.resource_ids.forEach((m: number) => {
599
+ // if (resourcesMap[m]) resourcesMap[m].capacity -= d.num || 0;
600
+ // });
595
601
  } else {
596
602
  // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
597
603
  // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
@@ -599,13 +605,13 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
599
605
  if (m.combined_resource && m.combined_resource.status === 1) {
600
606
  if (m.combined_resource.resource_ids.includes(n.id)) {
601
607
  acc.push(m.id);
602
- resourcesMap[m.id].capacity -= n.num;
608
+ // if (resourcesMap[m.id]) resourcesMap[m.id].capacity -= d.num || 0;
603
609
  }
604
610
  }
605
611
  });
606
612
  }
607
613
  acc.push(n.id);
608
- resourcesMap[n.id].capacity -= n.num;
614
+ // if (resourcesMap[n.id]) resourcesMap[n.id].capacity -= currentCapacity || 0;
609
615
  });
610
616
  }
611
617
  }
@@ -636,9 +642,9 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
636
642
  return acc;
637
643
  }
638
644
  acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
639
- n.metadata.combined_resource.resource_ids.forEach(function (m) {
640
- resourcesMap[m].capacity -= n.num;
641
- });
645
+ // n.metadata.combined_resource.resource_ids.forEach((m: number) => {
646
+ // resourcesMap[m].capacity -= n.num;
647
+ // });
642
648
  } else {
643
649
  // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
644
650
  // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
@@ -646,14 +652,14 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
646
652
  if (m.combined_resource && m.combined_resource.status === 1) {
647
653
  if (m.combined_resource.resource_ids.includes(n.id)) {
648
654
  acc.push(m.id);
649
- resourcesMap[m.id].capacity -= n.num;
655
+ // resourcesMap[m.id].capacity -= n.num;
650
656
  }
651
657
  }
652
658
  });
653
659
  }
654
660
  acc.push(n.id);
655
661
  // push 完以后,把 resourceMap 的 capacity 减掉当前的商品数量
656
- resourcesMap[n.id].capacity -= n.num;
662
+ // resourcesMap[n.id].capacity -= currentCapacity || 0;
657
663
  });
658
664
  }
659
665
  }
@@ -16,6 +16,7 @@ export declare class AccountListModule extends BaseModule implements Module {
16
16
  * 创建账号并添加到列表中
17
17
  * @param account 账号信息
18
18
  * @param needEmit 是否需要触发事件
19
+ * @param type 添加类型
19
20
  */
20
21
  private createAccountAndAdd;
21
22
  addAccount(account: Account): Promise<AccountModule>;
@@ -30,10 +31,12 @@ export declare class AccountListModule extends BaseModule implements Module {
30
31
  storeChange(): void;
31
32
  /**
32
33
  * 批量添加holder类型账号
33
- * @param holders 账号信息列表
34
- * @param customerId 账户id
35
34
  */
36
- addHolderAccounts(holders: IHolder[], customerId: number): Promise<AccountModule[]>;
35
+ addHolderAccounts(params: {
36
+ holders: IHolder[];
37
+ customerId: number;
38
+ type?: 'unshift' | 'push';
39
+ }): Promise<AccountModule[]>;
37
40
  /**
38
41
  * 获取holder类型账户列表
39
42
  * @param params
@@ -69,19 +69,30 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
69
69
  * 创建账号并添加到列表中
70
70
  * @param account 账号信息
71
71
  * @param needEmit 是否需要触发事件
72
+ * @param type 添加类型
72
73
  */
73
- async createAccountAndAdd(account, needEmit = true) {
74
+ async createAccountAndAdd(account, needEmit = true, type) {
74
75
  const tempAccountModule = this.store.accounts.find(
75
76
  (a) => a.getId() === account.id
76
77
  );
77
78
  if (tempAccountModule) {
78
79
  return tempAccountModule;
79
80
  }
80
- this.store.accountList.push(account);
81
+ const newAccountList = [...this.store.accountList || []];
82
+ if (type === "unshift") {
83
+ newAccountList.unshift(account);
84
+ } else {
85
+ newAccountList.push(account);
86
+ }
87
+ this.store.accountList = newAccountList;
81
88
  const accountModule = new import_Account.AccountModule(`account_${account.id}`);
82
89
  this.core.registerModule(accountModule);
83
90
  accountModule.setAccountInfo(account);
84
- this.store.accounts = [...this.store.accounts || [], accountModule];
91
+ if (type === "unshift") {
92
+ this.store.accounts = [accountModule, ...this.store.accounts || []];
93
+ } else {
94
+ this.store.accounts = [...this.store.accounts || [], accountModule];
95
+ }
85
96
  if (needEmit) {
86
97
  await this.core.effects.emit(
87
98
  import_types.AccountListHooks.OnAccountListUpdate,
@@ -250,15 +261,22 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
250
261
  }
251
262
  /**
252
263
  * 批量添加holder类型账号
253
- * @param holders 账号信息列表
254
- * @param customerId 账户id
255
264
  */
256
- async addHolderAccounts(holders, customerId) {
265
+ async addHolderAccounts(params) {
266
+ const { holders, customerId, type = "push" } = params;
257
267
  const accountModules = [];
258
268
  for (const holder of holders) {
259
269
  const account = (0, import_utils.createHolderAccount)(holder, customerId);
260
- const accountModule = await this.createAccountAndAdd(account, false);
261
- accountModules.push(accountModule);
270
+ const accountModule = await this.createAccountAndAdd(
271
+ account,
272
+ false,
273
+ type
274
+ );
275
+ if (type === "unshift") {
276
+ accountModules.unshift(accountModule);
277
+ } else {
278
+ accountModules.push(accountModule);
279
+ }
262
280
  }
263
281
  await this.core.effects.emit(
264
282
  import_types.AccountListHooks.OnAccountListUpdate,
@@ -283,7 +301,10 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
283
301
  skip: skip || 1
284
302
  });
285
303
  if ((_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) == null ? void 0 : _b.length) {
286
- await this.addHolderAccounts(res.data.list, customer_id);
304
+ await this.addHolderAccounts({
305
+ holders: res.data.list,
306
+ customerId: customer_id
307
+ });
287
308
  }
288
309
  } catch (error) {
289
310
  console.error(error);