@pisell/pisellos 0.0.79 → 0.0.81

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 = [];
@@ -641,7 +649,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
641
649
  key: "getAvailableDate",
642
650
  value: function () {
643
651
  var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
644
- var _this3 = this;
652
+ var _this3 = this,
653
+ _dateRange$,
654
+ _dateRange$2,
655
+ _dateRange$3;
645
656
  var params,
646
657
  products,
647
658
  startDate,
@@ -684,8 +695,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
684
695
  })];
685
696
  }
686
697
  dateRange = this.store.date.getDateRange();
687
- tempStartDate = startDate || (dateRange === null || dateRange === void 0 ? void 0 : dateRange[0].date);
688
- tempEndDate = endDate || (dateRange === null || dateRange === void 0 ? void 0 : dateRange[1].date);
698
+ tempStartDate = startDate || (dateRange === null || dateRange === void 0 || (_dateRange$ = dateRange[0]) === null || _dateRange$ === void 0 ? void 0 : _dateRange$.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);
689
700
  if (tempProducts.length) {
690
701
  _context13.next = 11;
691
702
  break;
@@ -1026,6 +1037,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1026
1037
  if (!targetCartItem) {
1027
1038
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(params._id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1028
1039
  }
1040
+ var currentResourcesCapacityMap = {};
1029
1041
  if (params.resources) {
1030
1042
  var _targetCartItem$_prod;
1031
1043
  var formatCapacity = formatDefaultCapacitys({
@@ -1037,19 +1049,52 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1037
1049
  });
1038
1050
  params.resources = params.resources.map(function (n) {
1039
1051
  n.capacity = currentCapacity || 1;
1052
+ currentResourcesCapacityMap[n.id] = currentCapacity;
1040
1053
  checkSubResourcesCapacity(n);
1041
1054
  return n;
1042
1055
  });
1043
1056
  }
1044
1057
  this.store.cart.updateItem(params);
1045
- // 更新购物车后,需要判定购物车里是否存在多个账号选择了相同资源的情况,如果是,则要把选择了相同资源的 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 给去除
1046
1073
  var cartItems = this.store.cart.getItems();
1047
1074
  cartItems.forEach(function (item) {
1048
- if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1049
- var _item$_origin$resourc;
1050
- var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1051
- // 检查当前资源是否与目标资源的任何资源匹配
1052
- 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
+ return false;
1096
+ }
1097
+ if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1053
1098
  var _targetRes$metadata$c, _m$metadata$combined_;
1054
1099
  // 检查主资源ID是否匹配
1055
1100
  if (targetRes.id === m.id) return true;
@@ -1058,19 +1103,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1058
1103
  // 如果现在选择的是组合资源,需要判断
1059
1104
  // 1、当前其他购物车里是否选了当前组合资源的子资源
1060
1105
  // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
1061
-
1062
1106
  targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some(function (n) {
1063
1107
  return m.metadata.combined_resource.resource_ids.includes(n);
1064
1108
  }))) return true;
1065
1109
  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;
1066
- return false;
1067
- });
1068
- });
1069
- _this5.store.cart.updateItem({
1070
- _id: item._id,
1071
- resources: resources
1110
+ }
1111
+ return false;
1072
1112
  });
1073
- }
1113
+ });
1114
+ _this5.store.cart.updateItem({
1115
+ _id: item._id,
1116
+ resources: resources
1117
+ });
1074
1118
  });
1075
1119
  }
1076
1120
 
@@ -1182,11 +1226,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1182
1226
  cartItems.forEach(function (cartItem) {
1183
1227
  var _cartItem$_productOri, _cartItem$_productOri2;
1184
1228
  var selectedResources = [];
1185
- if (cartItem.holder_id) {
1186
- selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1187
- } else {
1188
- selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1189
- }
1190
1229
  var formatCapacity = formatDefaultCapacitys({
1191
1230
  capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
1192
1231
  product_bundle: cartItem._origin.product.product_bundle
@@ -1195,6 +1234,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1195
1234
  var currentCapacity = getSumCapacity({
1196
1235
  capacity: formatCapacity
1197
1236
  });
1237
+ if (cartItem.holder_id) {
1238
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap, currentCapacity);
1239
+ } else {
1240
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap, currentCapacity);
1241
+ }
1198
1242
  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);
1199
1243
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1200
1244
  if (cartItem._origin.start_time) {
@@ -1282,6 +1326,134 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1282
1326
  return arr;
1283
1327
  }
1284
1328
 
1329
+ // 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
1330
+ }, {
1331
+ key: "checkResourceListForDate",
1332
+ value: function checkResourceListForDate() {
1333
+ var dateRange = this.store.date.getDateRange();
1334
+ var resources = [];
1335
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
1336
+ dateRange.forEach(function (n) {
1337
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1338
+ });
1339
+ }
1340
+ // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1341
+ if (!resources.length) {
1342
+ var dateList = this.store.date.getDateList();
1343
+ dateList.forEach(function (n) {
1344
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1345
+ });
1346
+ }
1347
+ var resourcesMap = getResourcesMap(cloneDeep(resources));
1348
+ var cartItems = this.store.cart.getItems();
1349
+ var arr = [];
1350
+ var capacityMap = {};
1351
+ cartItems.forEach(function (cartItem) {
1352
+ var _cartItem$_productOri4, _cartItem$_productOri5;
1353
+ var selectedResources = [];
1354
+ var formatCapacity = formatDefaultCapacitys({
1355
+ capacity: (_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.capacity,
1356
+ product_bundle: cartItem._origin.product.product_bundle
1357
+ });
1358
+ cartItem._origin.metadata.capacity = formatCapacity;
1359
+ var currentCapacity = getSumCapacity({
1360
+ capacity: formatCapacity
1361
+ });
1362
+ if (cartItem.holder_id) {
1363
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap, currentCapacity);
1364
+ } else {
1365
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap, currentCapacity);
1366
+ }
1367
+ 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
+ // 如果购物车里已经有了时间片,则需要按照时间片过滤
1369
+ if (cartItem._origin.start_time) {
1370
+ var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
1371
+ var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
1372
+ var resourcesUseableMap = {};
1373
+ productResources.forEach(function (n) {
1374
+ // 资源排下序,把单个资源靠前,组合资源排在后面
1375
+ n.renderList = n.renderList.sort(function (a, b) {
1376
+ var _a$metadata2, _b$metadata2;
1377
+ var aIsCombined = ((_a$metadata2 = a.metadata) === null || _a$metadata2 === void 0 || (_a$metadata2 = _a$metadata2.combined_resource) === null || _a$metadata2 === void 0 ? void 0 : _a$metadata2.status) === 1;
1378
+ var bIsCombined = ((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 || (_b$metadata2 = _b$metadata2.combined_resource) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.status) === 1;
1379
+ if (aIsCombined && !bIsCombined) return 1;
1380
+ if (!aIsCombined && bIsCombined) return -1;
1381
+ return 0;
1382
+ });
1383
+ n.renderList = n.renderList.filter(function (m) {
1384
+ var recordCount = capacityMap[m.id] || 0;
1385
+ // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1386
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1387
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1388
+ var mTimes = m.times.filter(function (n) {
1389
+ return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
1390
+ });
1391
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1392
+ if (mTimes.length === 0) {
1393
+ return false;
1394
+ }
1395
+ var canUseArr = mTimes.map(function (item) {
1396
+ var res = getIsUsableByTimeItem({
1397
+ timeSlice: {
1398
+ start_time: startTime.format('HH:mm'),
1399
+ end_time: endTime.format('HH:mm'),
1400
+ start_at: startTime,
1401
+ end_at: endTime
1402
+ },
1403
+ time: item,
1404
+ resource: m,
1405
+ currentCount: recordCount + (currentCapacity || 0),
1406
+ resourcesUseableMap: resourcesUseableMap
1407
+ });
1408
+ // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1409
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1410
+ resourcesUseableMap[m.id] = res.usable;
1411
+ }
1412
+ return res.usable;
1413
+ });
1414
+ if (m.onlyComputed) return false;
1415
+ // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1416
+ return !canUseArr.some(function (n) {
1417
+ return n === false;
1418
+ });
1419
+ });
1420
+ });
1421
+ } else {
1422
+ productResources.forEach(function (item) {
1423
+ // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1424
+ // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1425
+ item.renderList = item.renderList.filter(function (n) {
1426
+ var _cartItem$_productOri6;
1427
+ var recordCount = n.capacity || 0;
1428
+ if (n.onlyComputed) return false;
1429
+ // 查一下这个资源基于商品的可用时间片
1430
+ var timeSlots = getTimeSlicesByResource({
1431
+ resource: n,
1432
+ duration: ((_cartItem$_productOri6 = cartItem._productOrigin) === null || _cartItem$_productOri6 === void 0 || (_cartItem$_productOri6 = _cartItem$_productOri6.duration) === null || _cartItem$_productOri6 === void 0 ? void 0 : _cartItem$_productOri6.value) || 0,
1433
+ split: 10,
1434
+ currentDate: dateRange[0].date
1435
+ });
1436
+ return recordCount >= currentCapacity && timeSlots.length > 0;
1437
+ });
1438
+ });
1439
+ }
1440
+ arr.push({
1441
+ id: cartItem.id,
1442
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1443
+ _id: cartItem._id,
1444
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1445
+ productResources: productResources
1446
+ });
1447
+ });
1448
+ // 检查 productResources里是不是每一项资源的 renderList 里都有数据
1449
+ var hasResource = arr.every(function (n) {
1450
+ return n.productResources.every(function (m) {
1451
+ return m.renderList.length > 0;
1452
+ });
1453
+ });
1454
+ return hasResource;
1455
+ }
1456
+
1285
1457
  // 给单个购物车里的商品获取资源列表
1286
1458
  }, {
1287
1459
  key: "getResourcesListByCartItem",
@@ -1303,11 +1475,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1303
1475
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1304
1476
  }
1305
1477
  var selectedResources = [];
1306
- if (targetCartItem.holder_id) {
1307
- selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1308
- } else {
1309
- selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1310
- }
1311
1478
  var formatCapacity = formatDefaultCapacitys({
1312
1479
  capacity: (_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.capacity,
1313
1480
  product_bundle: targetCartItem._origin.product.product_bundle
@@ -1315,6 +1482,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1315
1482
  var currentCapacity = getSumCapacity({
1316
1483
  capacity: formatCapacity
1317
1484
  });
1485
+ if (targetCartItem.holder_id) {
1486
+ selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap, currentCapacity);
1487
+ } else {
1488
+ selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap, currentCapacity);
1489
+ }
1318
1490
  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);
1319
1491
  productResources.forEach(function (item) {
1320
1492
  item.renderList = item.renderList.filter(function (n) {
@@ -1360,7 +1532,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1360
1532
  }, {
1361
1533
  key: "autoSelectAccountResources",
1362
1534
  value: function autoSelectAccountResources(_ref8) {
1363
- var _cartItem$_productOri4, _allProductResources$;
1535
+ var _cartItem$_productOri7, _allProductResources$;
1364
1536
  var cartItem = _ref8.cartItem,
1365
1537
  holder_id = _ref8.holder_id,
1366
1538
  resources_code = _ref8.resources_code,
@@ -1408,16 +1580,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1408
1580
  }
1409
1581
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1410
1582
  var allCartItems = cloneDeep(this.store.cart.getItems());
1411
- var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1412
- var allProductResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 || (_cartItem$_productOri4 = _cartItem$_productOri4.product_resource) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.resources) || [], selectedResources, 1);
1583
+ var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap, capacity || 0);
1584
+ 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);
1413
1585
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1414
1586
  return n.code === resources_code;
1415
1587
  })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
1416
1588
  // 资源排下序,把单个资源靠前,组合资源排在后面
1417
1589
  resources.sort(function (a, b) {
1418
- var _a$metadata2, _b$metadata2;
1419
- var aIsCombined = ((_a$metadata2 = a.metadata) === null || _a$metadata2 === void 0 || (_a$metadata2 = _a$metadata2.combined_resource) === null || _a$metadata2 === void 0 ? void 0 : _a$metadata2.status) === 1;
1420
- var bIsCombined = ((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 || (_b$metadata2 = _b$metadata2.combined_resource) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.status) === 1;
1590
+ var _a$metadata3, _b$metadata3;
1591
+ var aIsCombined = ((_a$metadata3 = a.metadata) === null || _a$metadata3 === void 0 || (_a$metadata3 = _a$metadata3.combined_resource) === null || _a$metadata3 === void 0 ? void 0 : _a$metadata3.status) === 1;
1592
+ var bIsCombined = ((_b$metadata3 = b.metadata) === null || _b$metadata3 === void 0 || (_b$metadata3 = _b$metadata3.combined_resource) === null || _b$metadata3 === void 0 ? void 0 : _b$metadata3.status) === 1;
1421
1593
  if (aIsCombined && !bIsCombined) return 1;
1422
1594
  if (!aIsCombined && bIsCombined) return -1;
1423
1595
  return 0;
@@ -1519,16 +1691,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1519
1691
  }, {
1520
1692
  key: "autoSelectAllProductResources",
1521
1693
  value: function autoSelectAllProductResources(resources_code, timeSlots) {
1522
- var _dateRange$,
1694
+ var _dateRange$4,
1523
1695
  _this8 = this;
1524
1696
  var dateRange = this.store.date.getDateRange();
1525
1697
  var resources = [];
1526
- if (dateRange !== null && dateRange !== void 0 && (_dateRange$ = dateRange[0]) !== null && _dateRange$ !== void 0 && _dateRange$.date) {
1698
+ if (dateRange !== null && dateRange !== void 0 && (_dateRange$4 = dateRange[0]) !== null && _dateRange$4 !== void 0 && _dateRange$4.date) {
1527
1699
  dateRange.forEach(function (n) {
1528
1700
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1529
1701
  });
1530
1702
  }
1531
- var resourcesMap = getResourcesMap(cloneDeep(resources));
1703
+ // const resourcesMap = getResourcesMap(cloneDeep(resources));
1532
1704
  // 一个账号一个账号处理
1533
1705
  var errorList = [];
1534
1706
  var selectResourcesMap = {};
@@ -1540,9 +1712,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1540
1712
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1541
1713
 
1542
1714
  cartItems.forEach(function (item, index) {
1543
- var _item$_productOrigin2;
1715
+ var _item$_productOrigin3;
1544
1716
  var formatCapacity = formatDefaultCapacitys({
1545
- capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1717
+ capacity: (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.capacity,
1546
1718
  product_bundle: item._origin.product.product_bundle
1547
1719
  });
1548
1720
  var currentCapacity = getSumCapacity({
@@ -1559,9 +1731,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1559
1731
  }
1560
1732
  if (recordTimeSlots) {
1561
1733
  if (index !== 0 && recordTimeSlots) {
1562
- var _item$_productOrigin$, _item$_productOrigin3, _ref9, _item$_productOrigin4, _item$_productOrigin$2, _item$_productOrigin5, _ref10, _item$_productOrigin6;
1563
- 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');
1564
- 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');
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');
1565
1737
  recordTimeSlots = {
1566
1738
  start_time: start_at.format('HH:mm'),
1567
1739
  end_time: end_at.format('HH:mm'),
@@ -1603,12 +1775,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1603
1775
  errorList.push(item._id);
1604
1776
  }
1605
1777
  } else {
1606
- var _item$_productOrigin7, _productResources$fin;
1778
+ var _item$_productOrigin8, _productResources$fin;
1607
1779
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1608
1780
  var allCartItems = cloneDeep(_this8.store.cart.getItems());
1609
1781
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1610
1782
  var selectedResources = [];
1611
- 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) || []);
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) || []);
1612
1784
  var currentResourcesRenderList = [];
1613
1785
  _resources.forEach(function (n) {
1614
1786
  var _n$renderList;
@@ -1616,7 +1788,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1616
1788
  // 过滤掉 capacity 小于 currentCapacity 的资源
1617
1789
  n.renderList = n.renderList.filter(function (m) {
1618
1790
  var _item$duration;
1619
- var recordCount = m.capacity || 0;
1791
+ // 同时 还需要减去 selectResourcesMap 里已经选中的资源的数量
1792
+ var recordCount = (m.capacity || 0) - (selectResourcesMap[m.id] || 0);
1620
1793
  var timeSlots = getTimeSlicesByResource({
1621
1794
  resource: m,
1622
1795
  duration: (item === null || item === void 0 || (_item$duration = item.duration) === null || _item$duration === void 0 ? void 0 : _item$duration.value) || 0,
@@ -1628,16 +1801,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1628
1801
  currentResourcesRenderList.push.apply(currentResourcesRenderList, _toConsumableArray(n.renderList || []));
1629
1802
  }
1630
1803
  });
1631
- var _resourcesMap2 = getResourcesMap(currentResourcesRenderList);
1804
+ var resourcesMap = getResourcesMap(currentResourcesRenderList);
1632
1805
  if (item.holder_id) {
1633
- selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, _resourcesMap2);
1806
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap, currentCapacity);
1634
1807
  } else {
1635
- selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap2);
1808
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap, currentCapacity);
1636
1809
  }
1637
- var productResources = getResourcesByProduct(_resourcesMap2, cloneDeep(_resources), selectedResources, currentCapacity);
1810
+ var productResources = getResourcesByProduct(resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1638
1811
  productResources.forEach(function (item) {
1639
1812
  item.renderList = item.renderList.filter(function (n) {
1640
- var recordCount = n.capacity || 0;
1813
+ var recordCount = (n.capacity || 0) - (selectResourcesMap[n.id] || 0);
1641
1814
  if (n.onlyComputed) return false;
1642
1815
  return recordCount >= currentCapacity;
1643
1816
  });
@@ -1658,6 +1831,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1658
1831
  targetResource.capacity = currentCapacity;
1659
1832
  // 在这里处理 children 的数据
1660
1833
  checkSubResourcesCapacity(targetResource);
1834
+ if (!selectResourcesMap[targetResource.id]) {
1835
+ selectResourcesMap[targetResource.id] = currentCapacity;
1836
+ } else {
1837
+ selectResourcesMap[targetResource.id] += currentCapacity;
1838
+ }
1661
1839
  _this8.store.cart.updateItem({
1662
1840
  _id: item._id,
1663
1841
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
@@ -1702,8 +1880,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1702
1880
  var resourceIds = [];
1703
1881
  var resourcesTypeId = undefined;
1704
1882
  cartItems.forEach(function (item) {
1705
- var _item$_productOrigin8, _item$_productOrigin9;
1706
- (_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) {
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) {
1707
1885
  if (n.code === resources_code) {
1708
1886
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1709
1887
  }
@@ -1714,9 +1892,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1714
1892
  if (item.resource_id) {
1715
1893
  resourceIds.push(item.resource_id);
1716
1894
  }
1717
- 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) {
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) {
1718
1896
  return n.code === resources_code;
1719
- })) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.id;
1897
+ })) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.id;
1720
1898
  });
1721
1899
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
1722
1900
  if ((_dateRange = dateRange) !== null && _dateRange !== void 0 && (_dateRange = _dateRange[0]) !== null && _dateRange !== void 0 && (_dateRange = _dateRange.resource) !== null && _dateRange !== void 0 && _dateRange.length) {
@@ -1736,8 +1914,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1736
1914
  var checkDuration = function checkDuration(cartItems) {
1737
1915
  var accountDuration = 0;
1738
1916
  cartItems.forEach(function (item) {
1739
- var _item$_productOrigin$3, _item$_productOrigin10;
1740
- 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;
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;
1741
1919
  });
1742
1920
  if (accountDuration > duration) {
1743
1921
  duration = accountDuration;
@@ -1804,11 +1982,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1804
1982
  Object.values(itemsByAccount).forEach(function (accountItems) {
1805
1983
  var currentStartTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
1806
1984
  accountItems.forEach(function (item, index) {
1985
+ var _newResources$;
1807
1986
  var newResources = cloneDeep(item._origin.resources);
1808
1987
  newResources.forEach(function (resource) {
1809
- var _item$_productOrigin$4, _item$_productOrigin11, _ref11, _item$_productOrigin12;
1988
+ var _item$_productOrigin$4, _item$_productOrigin12, _ref11, _item$_productOrigin13;
1810
1989
  resource.startTime = currentStartTime;
1811
- 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');
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');
1812
1991
  delete resource.times;
1813
1992
  });
1814
1993
  _this10.store.cart.updateItem({
@@ -1817,7 +1996,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1817
1996
  });
1818
1997
 
1819
1998
  // 更新下一个商品的开始时间为当前商品的结束时间
1820
- if (index < accountItems.length - 1) {
1999
+ if (index < accountItems.length - 1 && (newResources === null || newResources === void 0 || (_newResources$ = newResources[0]) === null || _newResources$ === void 0 ? void 0 : _newResources$.resourceType) === 'single') {
1821
2000
  currentStartTime = newResources[0].endTime;
1822
2001
  }
1823
2002
  });
@@ -1914,7 +2093,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1914
2093
  });
1915
2094
  var cartItems = cloneDeep(this.store.cart.getItems());
1916
2095
  var resourcesMap = getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []);
1917
- var selectedResources = getOthersSelectedResources(cartItems, '', resourcesMap);
2096
+ var selectedResources = getOthersSelectedResources(cartItems, '', resourcesMap, 1);
1918
2097
  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);
1919
2098
  var minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, date);
1920
2099
  var scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime);
@@ -1925,9 +2104,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1925
2104
  });
1926
2105
  // 资源排下序,把单个资源靠前,组合资源排在后面
1927
2106
  allProductResources.sort(function (a, b) {
1928
- var _a$metadata3, _b$metadata3;
1929
- var aIsCombined = ((_a$metadata3 = a.metadata) === null || _a$metadata3 === void 0 || (_a$metadata3 = _a$metadata3.combined_resource) === null || _a$metadata3 === void 0 ? void 0 : _a$metadata3.status) === 1;
1930
- var bIsCombined = ((_b$metadata3 = b.metadata) === null || _b$metadata3 === void 0 || (_b$metadata3 = _b$metadata3.combined_resource) === null || _b$metadata3 === void 0 ? void 0 : _b$metadata3.status) === 1;
2107
+ var _a$metadata4, _b$metadata4;
2108
+ var aIsCombined = ((_a$metadata4 = a.metadata) === null || _a$metadata4 === void 0 || (_a$metadata4 = _a$metadata4.combined_resource) === null || _a$metadata4 === void 0 ? void 0 : _a$metadata4.status) === 1;
2109
+ var bIsCombined = ((_b$metadata4 = b.metadata) === null || _b$metadata4 === void 0 || (_b$metadata4 = _b$metadata4.combined_resource) === null || _b$metadata4 === void 0 ? void 0 : _b$metadata4.status) === 1;
1931
2110
  if (aIsCombined && !bIsCombined) return 1;
1932
2111
  if (!aIsCombined && bIsCombined) return -1;
1933
2112
  return 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>) => number[];
138
+ export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem>, currentCapacity: number) => 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>) => number[];
147
+ export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>, currentCapacity: number) => number[];
148
148
  interface CapacityItem {
149
149
  id: number;
150
150
  value: number;