@pisell/pisellos 2.0.14 → 2.0.15

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,53 @@ 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
+ currentResourcesCapacityMap[targetRes.id] += _currentCapacity;
1096
+ return false;
1097
+ }
1098
+ if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1053
1099
  var _targetRes$metadata$c, _m$metadata$combined_;
1054
1100
  // 检查主资源ID是否匹配
1055
1101
  if (targetRes.id === m.id) return true;
@@ -1058,14 +1104,29 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1058
1104
  // 如果现在选择的是组合资源,需要判断
1059
1105
  // 1、当前其他购物车里是否选了当前组合资源的子资源
1060
1106
  // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
1061
-
1062
1107
  targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some(function (n) {
1063
1108
  return m.metadata.combined_resource.resource_ids.includes(n);
1064
1109
  }))) return true;
1065
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;
1066
- return false;
1067
- });
1111
+ }
1112
+ return false;
1068
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
+ }
1128
+ });
1129
+ } else {
1069
1130
  _this5.store.cart.updateItem({
1070
1131
  _id: item._id,
1071
1132
  resources: resources
@@ -1178,15 +1239,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1178
1239
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1179
1240
  var cartItems = this.store.cart.getItems();
1180
1241
  var arr = [];
1181
- var capacityMap = {};
1182
1242
  cartItems.forEach(function (cartItem) {
1183
1243
  var _cartItem$_productOri, _cartItem$_productOri2;
1184
1244
  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
1245
  var formatCapacity = formatDefaultCapacitys({
1191
1246
  capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
1192
1247
  product_bundle: cartItem._origin.product.product_bundle
@@ -1195,6 +1250,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1195
1250
  var currentCapacity = getSumCapacity({
1196
1251
  capacity: formatCapacity
1197
1252
  });
1253
+ if (cartItem.holder_id) {
1254
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1255
+ } else {
1256
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1257
+ }
1198
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);
1199
1259
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1200
1260
  if (cartItem._origin.start_time) {
@@ -1212,7 +1272,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1212
1272
  return 0;
1213
1273
  });
1214
1274
  n.renderList = n.renderList.filter(function (m) {
1215
- var recordCount = capacityMap[m.id] || 0;
1216
1275
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1217
1276
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1218
1277
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
@@ -1233,7 +1292,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1233
1292
  },
1234
1293
  time: item,
1235
1294
  resource: m,
1236
- currentCount: recordCount + (currentCapacity || 0),
1295
+ currentCount: currentCapacity || 0,
1237
1296
  resourcesUseableMap: resourcesUseableMap
1238
1297
  });
1239
1298
  // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
@@ -1282,6 +1341,132 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1282
1341
  return arr;
1283
1342
  }
1284
1343
 
1344
+ // 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
1345
+ }, {
1346
+ key: "checkResourceListForDate",
1347
+ value: function checkResourceListForDate() {
1348
+ var dateRange = this.store.date.getDateRange();
1349
+ var resources = [];
1350
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
1351
+ dateRange.forEach(function (n) {
1352
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1353
+ });
1354
+ }
1355
+ // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1356
+ if (!resources.length) {
1357
+ var dateList = this.store.date.getDateList();
1358
+ dateList.forEach(function (n) {
1359
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1360
+ });
1361
+ }
1362
+ var resourcesMap = getResourcesMap(cloneDeep(resources));
1363
+ var cartItems = this.store.cart.getItems();
1364
+ var arr = [];
1365
+ cartItems.forEach(function (cartItem) {
1366
+ var _cartItem$_productOri4, _cartItem$_productOri5;
1367
+ var selectedResources = [];
1368
+ var formatCapacity = formatDefaultCapacitys({
1369
+ capacity: (_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.capacity,
1370
+ product_bundle: cartItem._origin.product.product_bundle
1371
+ });
1372
+ cartItem._origin.metadata.capacity = formatCapacity;
1373
+ var currentCapacity = getSumCapacity({
1374
+ capacity: formatCapacity
1375
+ });
1376
+ if (cartItem.holder_id) {
1377
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1378
+ } else {
1379
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1380
+ }
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);
1382
+ // 如果购物车里已经有了时间片,则需要按照时间片过滤
1383
+ if (cartItem._origin.start_time) {
1384
+ var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
1385
+ var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
1386
+ var resourcesUseableMap = {};
1387
+ productResources.forEach(function (n) {
1388
+ // 资源排下序,把单个资源靠前,组合资源排在后面
1389
+ n.renderList = n.renderList.sort(function (a, b) {
1390
+ var _a$metadata2, _b$metadata2;
1391
+ 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;
1392
+ 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;
1393
+ if (aIsCombined && !bIsCombined) return 1;
1394
+ if (!aIsCombined && bIsCombined) return -1;
1395
+ return 0;
1396
+ });
1397
+ n.renderList = n.renderList.filter(function (m) {
1398
+ // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1399
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1400
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1401
+ var mTimes = m.times.filter(function (n) {
1402
+ return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
1403
+ });
1404
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1405
+ if (mTimes.length === 0) {
1406
+ return false;
1407
+ }
1408
+ var canUseArr = mTimes.map(function (item) {
1409
+ var res = getIsUsableByTimeItem({
1410
+ timeSlice: {
1411
+ start_time: startTime.format('HH:mm'),
1412
+ end_time: endTime.format('HH:mm'),
1413
+ start_at: startTime,
1414
+ end_at: endTime
1415
+ },
1416
+ time: item,
1417
+ resource: m,
1418
+ currentCount: currentCapacity || 0,
1419
+ resourcesUseableMap: resourcesUseableMap
1420
+ });
1421
+ // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况
1422
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
1423
+ resourcesUseableMap[m.id] = res.usable;
1424
+ }
1425
+ return res.usable;
1426
+ });
1427
+ if (m.onlyComputed) return false;
1428
+ // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1429
+ return !canUseArr.some(function (n) {
1430
+ return n === false;
1431
+ });
1432
+ });
1433
+ });
1434
+ } else {
1435
+ productResources.forEach(function (item) {
1436
+ // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1437
+ // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1438
+ item.renderList = item.renderList.filter(function (n) {
1439
+ var _cartItem$_productOri6;
1440
+ var recordCount = n.capacity || 0;
1441
+ if (n.onlyComputed) return false;
1442
+ // 查一下这个资源基于商品的可用时间片
1443
+ var timeSlots = getTimeSlicesByResource({
1444
+ resource: n,
1445
+ 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,
1446
+ split: 10,
1447
+ currentDate: dateRange[0].date
1448
+ });
1449
+ return recordCount >= currentCapacity && timeSlots.length > 0;
1450
+ });
1451
+ });
1452
+ }
1453
+ arr.push({
1454
+ id: cartItem.id,
1455
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1456
+ _id: cartItem._id,
1457
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
1458
+ productResources: productResources
1459
+ });
1460
+ });
1461
+ // 检查 productResources里是不是每一项资源的 renderList 里都有数据
1462
+ var hasResource = arr.every(function (n) {
1463
+ return n.productResources.every(function (m) {
1464
+ return m.renderList.length > 0;
1465
+ });
1466
+ });
1467
+ return hasResource;
1468
+ }
1469
+
1285
1470
  // 给单个购物车里的商品获取资源列表
1286
1471
  }, {
1287
1472
  key: "getResourcesListByCartItem",
@@ -1293,9 +1478,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1293
1478
  dateRange.forEach(function (n) {
1294
1479
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1295
1480
  });
1296
- // 这里为什么要 cloneDeep:因为 getOthersSelectedResources 和 getOthersCartSelectedResources 会修改 resourcesMap 的 capacity
1297
1481
  // 用于确保后续分配的容量不会超出
1298
- var resourcesMap = getResourcesMap(cloneDeep(resources));
1482
+ var resourcesMap = getResourcesMap(resources);
1299
1483
  var targetCartItem = cartItems.find(function (n) {
1300
1484
  return n._id === id;
1301
1485
  });
@@ -1303,11 +1487,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1303
1487
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1304
1488
  }
1305
1489
  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
1490
  var formatCapacity = formatDefaultCapacitys({
1312
1491
  capacity: (_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.capacity,
1313
1492
  product_bundle: targetCartItem._origin.product.product_bundle
@@ -1315,6 +1494,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1315
1494
  var currentCapacity = getSumCapacity({
1316
1495
  capacity: formatCapacity
1317
1496
  });
1497
+ if (targetCartItem.holder_id) {
1498
+ selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1499
+ } else {
1500
+ selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1501
+ }
1318
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);
1319
1503
  productResources.forEach(function (item) {
1320
1504
  item.renderList = item.renderList.filter(function (n) {
@@ -1360,7 +1544,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1360
1544
  }, {
1361
1545
  key: "autoSelectAccountResources",
1362
1546
  value: function autoSelectAccountResources(_ref8) {
1363
- var _cartItem$_productOri4, _allProductResources$;
1547
+ var _cartItem$_productOri7, _allProductResources$;
1364
1548
  var cartItem = _ref8.cartItem,
1365
1549
  holder_id = _ref8.holder_id,
1366
1550
  resources_code = _ref8.resources_code,
@@ -1409,21 +1593,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1409
1593
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1410
1594
  var allCartItems = cloneDeep(this.store.cart.getItems());
1411
1595
  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);
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);
1413
1597
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1414
1598
  return n.code === resources_code;
1415
1599
  })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
1416
1600
  // 资源排下序,把单个资源靠前,组合资源排在后面
1417
1601
  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;
1602
+ var _a$metadata3, _b$metadata3;
1603
+ 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;
1604
+ 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
1605
  if (aIsCombined && !bIsCombined) return 1;
1422
1606
  if (!aIsCombined && bIsCombined) return -1;
1423
1607
  return 0;
1424
1608
  });
1425
1609
  var resourcesUseableMap = _toConsumableArray(selectedResources).reduce(function (acc, n) {
1426
- 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;
1427
1612
  return acc;
1428
1613
  }, {});
1429
1614
 
@@ -1519,16 +1704,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1519
1704
  }, {
1520
1705
  key: "autoSelectAllProductResources",
1521
1706
  value: function autoSelectAllProductResources(resources_code, timeSlots) {
1522
- var _dateRange$,
1707
+ var _dateRange$4,
1523
1708
  _this8 = this;
1524
1709
  var dateRange = this.store.date.getDateRange();
1525
1710
  var resources = [];
1526
- if (dateRange !== null && dateRange !== void 0 && (_dateRange$ = dateRange[0]) !== null && _dateRange$ !== void 0 && _dateRange$.date) {
1711
+ if (dateRange !== null && dateRange !== void 0 && (_dateRange$4 = dateRange[0]) !== null && _dateRange$4 !== void 0 && _dateRange$4.date) {
1527
1712
  dateRange.forEach(function (n) {
1528
1713
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1529
1714
  });
1530
1715
  }
1531
- var resourcesMap = getResourcesMap(cloneDeep(resources));
1716
+ // const resourcesMap = getResourcesMap(cloneDeep(resources));
1532
1717
  // 一个账号一个账号处理
1533
1718
  var errorList = [];
1534
1719
  var selectResourcesMap = {};
@@ -1540,9 +1725,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1540
1725
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1541
1726
 
1542
1727
  cartItems.forEach(function (item, index) {
1543
- var _item$_productOrigin2;
1728
+ var _item$_productOrigin3;
1544
1729
  var formatCapacity = formatDefaultCapacitys({
1545
- 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,
1546
1731
  product_bundle: item._origin.product.product_bundle
1547
1732
  });
1548
1733
  var currentCapacity = getSumCapacity({
@@ -1558,10 +1743,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1558
1743
  };
1559
1744
  }
1560
1745
  if (recordTimeSlots) {
1561
- 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');
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');
1565
1756
  recordTimeSlots = {
1566
1757
  start_time: start_at.format('HH:mm'),
1567
1758
  end_time: end_at.format('HH:mm'),
@@ -1603,12 +1794,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1603
1794
  errorList.push(item._id);
1604
1795
  }
1605
1796
  } else {
1606
- var _item$_productOrigin7, _productResources$fin;
1797
+ var _item$_productOrigin9, _productResources$fin;
1607
1798
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1608
1799
  var allCartItems = cloneDeep(_this8.store.cart.getItems());
1609
1800
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1610
1801
  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) || []);
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) || []);
1612
1803
  var currentResourcesRenderList = [];
1613
1804
  _resources.forEach(function (n) {
1614
1805
  var _n$renderList;
@@ -1616,7 +1807,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1616
1807
  // 过滤掉 capacity 小于 currentCapacity 的资源
1617
1808
  n.renderList = n.renderList.filter(function (m) {
1618
1809
  var _item$duration;
1619
- var recordCount = m.capacity || 0;
1810
+ // 同时 还需要减去 selectResourcesMap 里已经选中的资源的数量
1811
+ var recordCount = (m.capacity || 0) - (selectResourcesMap[m.id] || 0);
1620
1812
  var timeSlots = getTimeSlicesByResource({
1621
1813
  resource: m,
1622
1814
  duration: (item === null || item === void 0 || (_item$duration = item.duration) === null || _item$duration === void 0 ? void 0 : _item$duration.value) || 0,
@@ -1628,16 +1820,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1628
1820
  currentResourcesRenderList.push.apply(currentResourcesRenderList, _toConsumableArray(n.renderList || []));
1629
1821
  }
1630
1822
  });
1631
- var _resourcesMap2 = getResourcesMap(currentResourcesRenderList);
1823
+ var resourcesMap = getResourcesMap(currentResourcesRenderList);
1632
1824
  if (item.holder_id) {
1633
- selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, _resourcesMap2);
1825
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap);
1634
1826
  } else {
1635
- selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap2);
1827
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap);
1636
1828
  }
1637
- var productResources = getResourcesByProduct(_resourcesMap2, cloneDeep(_resources), selectedResources, currentCapacity);
1829
+ var productResources = getResourcesByProduct(resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1638
1830
  productResources.forEach(function (item) {
1639
1831
  item.renderList = item.renderList.filter(function (n) {
1640
- var recordCount = n.capacity || 0;
1832
+ var recordCount = (n.capacity || 0) - (selectResourcesMap[n.id] || 0);
1641
1833
  if (n.onlyComputed) return false;
1642
1834
  return recordCount >= currentCapacity;
1643
1835
  });
@@ -1658,6 +1850,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1658
1850
  targetResource.capacity = currentCapacity;
1659
1851
  // 在这里处理 children 的数据
1660
1852
  checkSubResourcesCapacity(targetResource);
1853
+ if (!selectResourcesMap[targetResource.id]) {
1854
+ selectResourcesMap[targetResource.id] = currentCapacity;
1855
+ } else {
1856
+ selectResourcesMap[targetResource.id] += currentCapacity;
1857
+ }
1661
1858
  _this8.store.cart.updateItem({
1662
1859
  _id: item._id,
1663
1860
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
@@ -1702,8 +1899,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1702
1899
  var resourceIds = [];
1703
1900
  var resourcesTypeId = undefined;
1704
1901
  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) {
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) {
1707
1904
  if (n.code === resources_code) {
1708
1905
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1709
1906
  }
@@ -1714,9 +1911,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1714
1911
  if (item.resource_id) {
1715
1912
  resourceIds.push(item.resource_id);
1716
1913
  }
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) {
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) {
1718
1915
  return n.code === resources_code;
1719
- })) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.id;
1916
+ })) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.id;
1720
1917
  });
1721
1918
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
1722
1919
  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 +1933,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1736
1933
  var checkDuration = function checkDuration(cartItems) {
1737
1934
  var accountDuration = 0;
1738
1935
  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;
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;
1741
1938
  });
1742
1939
  if (accountDuration > duration) {
1743
1940
  duration = accountDuration;
@@ -1804,11 +2001,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1804
2001
  Object.values(itemsByAccount).forEach(function (accountItems) {
1805
2002
  var currentStartTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
1806
2003
  accountItems.forEach(function (item, index) {
2004
+ var _newResources$;
1807
2005
  var newResources = cloneDeep(item._origin.resources);
1808
2006
  newResources.forEach(function (resource) {
1809
- var _item$_productOrigin$4, _item$_productOrigin11, _ref11, _item$_productOrigin12;
2007
+ var _item$_productOrigin$4, _item$_productOrigin13, _ref11, _item$_productOrigin14;
1810
2008
  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');
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');
1812
2010
  delete resource.times;
1813
2011
  });
1814
2012
  _this10.store.cart.updateItem({
@@ -1817,7 +2015,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1817
2015
  });
1818
2016
 
1819
2017
  // 更新下一个商品的开始时间为当前商品的结束时间
1820
- 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') {
1821
2019
  currentStartTime = newResources[0].endTime;
1822
2020
  }
1823
2021
  });
@@ -1925,9 +2123,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1925
2123
  });
1926
2124
  // 资源排下序,把单个资源靠前,组合资源排在后面
1927
2125
  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;
2126
+ var _a$metadata4, _b$metadata4;
2127
+ 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;
2128
+ 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
2129
  if (aIsCombined && !bIsCombined) return 1;
1932
2130
  if (!aIsCombined && bIsCombined) return -1;
1933
2131
  return 0;