@pisell/pisellos 0.0.80 → 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.
@@ -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
@@ -97,42 +97,56 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
97
97
  * 创建账号并添加到列表中
98
98
  * @param account 账号信息
99
99
  * @param needEmit 是否需要触发事件
100
+ * @param type 添加类型
100
101
  */
101
102
  }, {
102
103
  key: "createAccountAndAdd",
103
104
  value: (function () {
104
105
  var _createAccountAndAdd = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(account) {
105
106
  var needEmit,
107
+ type,
106
108
  tempAccountModule,
109
+ newAccountList,
107
110
  accountModule,
108
111
  _args2 = arguments;
109
112
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
110
113
  while (1) switch (_context2.prev = _context2.next) {
111
114
  case 0:
112
115
  needEmit = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : true;
116
+ type = _args2.length > 2 ? _args2[2] : undefined;
113
117
  tempAccountModule = this.store.accounts.find(function (a) {
114
118
  return a.getId() === account.id;
115
119
  }); // 如果账号已经存在,则直接返回
116
120
  if (!tempAccountModule) {
117
- _context2.next = 4;
121
+ _context2.next = 5;
118
122
  break;
119
123
  }
120
124
  return _context2.abrupt("return", tempAccountModule);
121
- case 4:
122
- this.store.accountList.push(account);
125
+ case 5:
126
+ newAccountList = _toConsumableArray(this.store.accountList || []);
127
+ if (type === 'unshift') {
128
+ newAccountList.unshift(account);
129
+ } else {
130
+ newAccountList.push(account);
131
+ }
132
+ this.store.accountList = newAccountList;
123
133
  accountModule = new AccountModule("account_".concat(account.id));
124
134
  this.core.registerModule(accountModule);
125
135
  accountModule.setAccountInfo(account);
126
- this.store.accounts = [].concat(_toConsumableArray(this.store.accounts || []), [accountModule]);
136
+ if (type === 'unshift') {
137
+ this.store.accounts = [accountModule].concat(_toConsumableArray(this.store.accounts || []));
138
+ } else {
139
+ this.store.accounts = [].concat(_toConsumableArray(this.store.accounts || []), [accountModule]);
140
+ }
127
141
  if (!needEmit) {
128
- _context2.next = 12;
142
+ _context2.next = 15;
129
143
  break;
130
144
  }
131
- _context2.next = 12;
145
+ _context2.next = 15;
132
146
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
133
- case 12:
147
+ case 15:
134
148
  return _context2.abrupt("return", accountModule);
135
- case 13:
149
+ case 16:
136
150
  case "end":
137
151
  return _context2.stop();
138
152
  }
@@ -425,59 +439,62 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
425
439
 
426
440
  /**
427
441
  * 批量添加holder类型账号
428
- * @param holders 账号信息列表
429
- * @param customerId 账户id
430
442
  */
431
443
  }, {
432
444
  key: "addHolderAccounts",
433
445
  value: (function () {
434
- var _addHolderAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(holders, customerId) {
435
- var accountModules, _iterator, _step, holder, account, accountModule;
446
+ var _addHolderAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
447
+ var holders, customerId, _params$type, type, accountModules, _iterator, _step, holder, account, accountModule;
436
448
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
437
449
  while (1) switch (_context8.prev = _context8.next) {
438
450
  case 0:
451
+ holders = params.holders, customerId = params.customerId, _params$type = params.type, type = _params$type === void 0 ? 'push' : _params$type;
439
452
  accountModules = [];
440
453
  _iterator = _createForOfIteratorHelper(holders);
441
- _context8.prev = 2;
454
+ _context8.prev = 3;
442
455
  _iterator.s();
443
- case 4:
456
+ case 5:
444
457
  if ((_step = _iterator.n()).done) {
445
- _context8.next = 13;
458
+ _context8.next = 14;
446
459
  break;
447
460
  }
448
461
  holder = _step.value;
449
462
  account = createHolderAccount(holder, customerId);
450
- _context8.next = 9;
451
- return this.createAccountAndAdd(account, false);
452
- case 9:
463
+ _context8.next = 10;
464
+ return this.createAccountAndAdd(account, false, type);
465
+ case 10:
453
466
  accountModule = _context8.sent;
454
- accountModules.push(accountModule);
455
- case 11:
456
- _context8.next = 4;
467
+ if (type === 'unshift') {
468
+ accountModules.unshift(accountModule);
469
+ } else {
470
+ accountModules.push(accountModule);
471
+ }
472
+ case 12:
473
+ _context8.next = 5;
457
474
  break;
458
- case 13:
459
- _context8.next = 18;
475
+ case 14:
476
+ _context8.next = 19;
460
477
  break;
461
- case 15:
462
- _context8.prev = 15;
463
- _context8.t0 = _context8["catch"](2);
478
+ case 16:
479
+ _context8.prev = 16;
480
+ _context8.t0 = _context8["catch"](3);
464
481
  _iterator.e(_context8.t0);
465
- case 18:
466
- _context8.prev = 18;
482
+ case 19:
483
+ _context8.prev = 19;
467
484
  _iterator.f();
468
- return _context8.finish(18);
469
- case 21:
470
- _context8.next = 23;
485
+ return _context8.finish(19);
486
+ case 22:
487
+ _context8.next = 24;
471
488
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
472
- case 23:
473
- return _context8.abrupt("return", accountModules);
474
489
  case 24:
490
+ return _context8.abrupt("return", accountModules);
491
+ case 25:
475
492
  case "end":
476
493
  return _context8.stop();
477
494
  }
478
- }, _callee8, this, [[2, 15, 18, 21]]);
495
+ }, _callee8, this, [[3, 16, 19, 22]]);
479
496
  }));
480
- function addHolderAccounts(_x10, _x11) {
497
+ function addHolderAccounts(_x10) {
481
498
  return _addHolderAccounts.apply(this, arguments);
482
499
  }
483
500
  return addHolderAccounts;
@@ -513,7 +530,10 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
513
530
  break;
514
531
  }
515
532
  _context9.next = 9;
516
- return this.addHolderAccounts(res.data.list, customer_id);
533
+ return this.addHolderAccounts({
534
+ holders: res.data.list,
535
+ customerId: customer_id
536
+ });
517
537
  case 9:
518
538
  _context9.next = 14;
519
539
  break;
@@ -527,7 +547,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
527
547
  }
528
548
  }, _callee9, this, [[2, 11]]);
529
549
  }));
530
- function fetchHolderAccounts(_x12) {
550
+ function fetchHolderAccounts(_x11) {
531
551
  return _fetchHolderAccounts.apply(this, arguments);
532
552
  }
533
553
  return fetchHolderAccounts;
@@ -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,52 @@ 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
+ return false;
1096
+ }
1097
+ if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1055
1098
  var _targetRes$metadata$c, _m$metadata$combined_;
1056
1099
  // 检查主资源ID是否匹配
1057
1100
  if (targetRes.id === m.id) return true;
@@ -1064,14 +1107,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1064
1107
  return m.metadata.combined_resource.resource_ids.includes(n);
1065
1108
  }))) return true;
1066
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;
1067
- return false;
1068
- });
1069
- });
1070
- _this5.store.cart.updateItem({
1071
- _id: item._id,
1072
- resources: resources
1110
+ }
1111
+ return false;
1073
1112
  });
1074
- }
1113
+ });
1114
+ _this5.store.cart.updateItem({
1115
+ _id: item._id,
1116
+ resources: resources
1117
+ });
1075
1118
  });
1076
1119
  }
1077
1120
 
@@ -1183,11 +1226,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1183
1226
  cartItems.forEach(function (cartItem) {
1184
1227
  var _cartItem$_productOri, _cartItem$_productOri2;
1185
1228
  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
1229
  var formatCapacity = formatDefaultCapacitys({
1192
1230
  capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
1193
1231
  product_bundle: cartItem._origin.product.product_bundle
@@ -1196,6 +1234,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1196
1234
  var currentCapacity = getSumCapacity({
1197
1235
  capacity: formatCapacity
1198
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
+ }
1199
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);
1200
1243
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1201
1244
  if (cartItem._origin.start_time) {
@@ -1308,11 +1351,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1308
1351
  cartItems.forEach(function (cartItem) {
1309
1352
  var _cartItem$_productOri4, _cartItem$_productOri5;
1310
1353
  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
1354
  var formatCapacity = formatDefaultCapacitys({
1317
1355
  capacity: (_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.capacity,
1318
1356
  product_bundle: cartItem._origin.product.product_bundle
@@ -1321,6 +1359,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1321
1359
  var currentCapacity = getSumCapacity({
1322
1360
  capacity: formatCapacity
1323
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
+ }
1324
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);
1325
1368
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1326
1369
  if (cartItem._origin.start_time) {
@@ -1432,11 +1475,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1432
1475
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1433
1476
  }
1434
1477
  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
1478
  var formatCapacity = formatDefaultCapacitys({
1441
1479
  capacity: (_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.capacity,
1442
1480
  product_bundle: targetCartItem._origin.product.product_bundle
@@ -1444,6 +1482,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1444
1482
  var currentCapacity = getSumCapacity({
1445
1483
  capacity: formatCapacity
1446
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
+ }
1447
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);
1448
1491
  productResources.forEach(function (item) {
1449
1492
  item.renderList = item.renderList.filter(function (n) {
@@ -1537,7 +1580,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1537
1580
  }
1538
1581
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1539
1582
  var allCartItems = cloneDeep(this.store.cart.getItems());
1540
- var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1583
+ var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap, capacity || 0);
1541
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);
1542
1585
  var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1543
1586
  return n.code === resources_code;
@@ -1648,16 +1691,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1648
1691
  }, {
1649
1692
  key: "autoSelectAllProductResources",
1650
1693
  value: function autoSelectAllProductResources(resources_code, timeSlots) {
1651
- var _dateRange$3,
1694
+ var _dateRange$4,
1652
1695
  _this8 = this;
1653
1696
  var dateRange = this.store.date.getDateRange();
1654
1697
  var resources = [];
1655
- if (dateRange !== null && dateRange !== void 0 && (_dateRange$3 = dateRange[0]) !== null && _dateRange$3 !== void 0 && _dateRange$3.date) {
1698
+ if (dateRange !== null && dateRange !== void 0 && (_dateRange$4 = dateRange[0]) !== null && _dateRange$4 !== void 0 && _dateRange$4.date) {
1656
1699
  dateRange.forEach(function (n) {
1657
1700
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1658
1701
  });
1659
1702
  }
1660
- var resourcesMap = getResourcesMap(cloneDeep(resources));
1703
+ // const resourcesMap = getResourcesMap(cloneDeep(resources));
1661
1704
  // 一个账号一个账号处理
1662
1705
  var errorList = [];
1663
1706
  var selectResourcesMap = {};
@@ -1669,9 +1712,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1669
1712
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1670
1713
 
1671
1714
  cartItems.forEach(function (item, index) {
1672
- var _item$_productOrigin2;
1715
+ var _item$_productOrigin3;
1673
1716
  var formatCapacity = formatDefaultCapacitys({
1674
- 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,
1675
1718
  product_bundle: item._origin.product.product_bundle
1676
1719
  });
1677
1720
  var currentCapacity = getSumCapacity({
@@ -1688,9 +1731,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1688
1731
  }
1689
1732
  if (recordTimeSlots) {
1690
1733
  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');
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');
1694
1737
  recordTimeSlots = {
1695
1738
  start_time: start_at.format('HH:mm'),
1696
1739
  end_time: end_at.format('HH:mm'),
@@ -1732,12 +1775,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1732
1775
  errorList.push(item._id);
1733
1776
  }
1734
1777
  } else {
1735
- var _item$_productOrigin7, _productResources$fin;
1778
+ var _item$_productOrigin8, _productResources$fin;
1736
1779
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1737
1780
  var allCartItems = cloneDeep(_this8.store.cart.getItems());
1738
1781
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1739
1782
  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) || []);
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) || []);
1741
1784
  var currentResourcesRenderList = [];
1742
1785
  _resources.forEach(function (n) {
1743
1786
  var _n$renderList;
@@ -1745,7 +1788,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1745
1788
  // 过滤掉 capacity 小于 currentCapacity 的资源
1746
1789
  n.renderList = n.renderList.filter(function (m) {
1747
1790
  var _item$duration;
1748
- var recordCount = m.capacity || 0;
1791
+ // 同时 还需要减去 selectResourcesMap 里已经选中的资源的数量
1792
+ var recordCount = (m.capacity || 0) - (selectResourcesMap[m.id] || 0);
1749
1793
  var timeSlots = getTimeSlicesByResource({
1750
1794
  resource: m,
1751
1795
  duration: (item === null || item === void 0 || (_item$duration = item.duration) === null || _item$duration === void 0 ? void 0 : _item$duration.value) || 0,
@@ -1757,16 +1801,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1757
1801
  currentResourcesRenderList.push.apply(currentResourcesRenderList, _toConsumableArray(n.renderList || []));
1758
1802
  }
1759
1803
  });
1760
- var _resourcesMap2 = getResourcesMap(currentResourcesRenderList);
1804
+ var resourcesMap = getResourcesMap(currentResourcesRenderList);
1761
1805
  if (item.holder_id) {
1762
- selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, _resourcesMap2);
1806
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap, currentCapacity);
1763
1807
  } else {
1764
- selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap2);
1808
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap, currentCapacity);
1765
1809
  }
1766
- var productResources = getResourcesByProduct(_resourcesMap2, cloneDeep(_resources), selectedResources, currentCapacity);
1810
+ var productResources = getResourcesByProduct(resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1767
1811
  productResources.forEach(function (item) {
1768
1812
  item.renderList = item.renderList.filter(function (n) {
1769
- var recordCount = n.capacity || 0;
1813
+ var recordCount = (n.capacity || 0) - (selectResourcesMap[n.id] || 0);
1770
1814
  if (n.onlyComputed) return false;
1771
1815
  return recordCount >= currentCapacity;
1772
1816
  });
@@ -1787,6 +1831,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1787
1831
  targetResource.capacity = currentCapacity;
1788
1832
  // 在这里处理 children 的数据
1789
1833
  checkSubResourcesCapacity(targetResource);
1834
+ if (!selectResourcesMap[targetResource.id]) {
1835
+ selectResourcesMap[targetResource.id] = currentCapacity;
1836
+ } else {
1837
+ selectResourcesMap[targetResource.id] += currentCapacity;
1838
+ }
1790
1839
  _this8.store.cart.updateItem({
1791
1840
  _id: item._id,
1792
1841
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
@@ -1831,8 +1880,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1831
1880
  var resourceIds = [];
1832
1881
  var resourcesTypeId = undefined;
1833
1882
  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) {
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) {
1836
1885
  if (n.code === resources_code) {
1837
1886
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1838
1887
  }
@@ -1843,9 +1892,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1843
1892
  if (item.resource_id) {
1844
1893
  resourceIds.push(item.resource_id);
1845
1894
  }
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) {
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) {
1847
1896
  return n.code === resources_code;
1848
- })) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.id;
1897
+ })) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.id;
1849
1898
  });
1850
1899
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
1851
1900
  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 +1914,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1865
1914
  var checkDuration = function checkDuration(cartItems) {
1866
1915
  var accountDuration = 0;
1867
1916
  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;
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;
1870
1919
  });
1871
1920
  if (accountDuration > duration) {
1872
1921
  duration = accountDuration;
@@ -1933,11 +1982,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1933
1982
  Object.values(itemsByAccount).forEach(function (accountItems) {
1934
1983
  var currentStartTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
1935
1984
  accountItems.forEach(function (item, index) {
1985
+ var _newResources$;
1936
1986
  var newResources = cloneDeep(item._origin.resources);
1937
1987
  newResources.forEach(function (resource) {
1938
- var _item$_productOrigin$4, _item$_productOrigin11, _ref11, _item$_productOrigin12;
1988
+ var _item$_productOrigin$4, _item$_productOrigin12, _ref11, _item$_productOrigin13;
1939
1989
  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');
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');
1941
1991
  delete resource.times;
1942
1992
  });
1943
1993
  _this10.store.cart.updateItem({
@@ -1946,7 +1996,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1946
1996
  });
1947
1997
 
1948
1998
  // 更新下一个商品的开始时间为当前商品的结束时间
1949
- 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') {
1950
2000
  currentStartTime = newResources[0].endTime;
1951
2001
  }
1952
2002
  });
@@ -2043,7 +2093,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2043
2093
  });
2044
2094
  var cartItems = cloneDeep(this.store.cart.getItems());
2045
2095
  var resourcesMap = getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []);
2046
- var selectedResources = getOthersSelectedResources(cartItems, '', resourcesMap);
2096
+ var selectedResources = getOthersSelectedResources(cartItems, '', resourcesMap, 1);
2047
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);
2048
2098
  var minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, date);
2049
2099
  var scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime);
@@ -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;
@@ -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) {
@@ -574,7 +580,7 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
574
580
  * @return {*}
575
581
  * @Author: jinglin.tan
576
582
  */
577
- export var getOthersSelectedResources = function getOthersSelectedResources(cartItems, accountId, resourcesMap) {
583
+ export var getOthersSelectedResources = function getOthersSelectedResources(cartItems, accountId, resourcesMap, currentCapacity) {
578
584
  return cartItems.reduce(function (acc, d) {
579
585
  if (d.holder_id !== accountId) {
580
586
  var _d$_origin;
@@ -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
  }
@@ -621,7 +627,7 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
621
627
  * @return {*}
622
628
  * @Author: jinglin.tan
623
629
  */
624
- export var getOthersCartSelectedResources = function getOthersCartSelectedResources(cartItems, cartItemId, resourcesMap) {
630
+ export var getOthersCartSelectedResources = function getOthersCartSelectedResources(cartItems, cartItemId, resourcesMap, currentCapacity) {
625
631
  return cartItems.reduce(function (acc, d) {
626
632
  if (d._id !== cartItemId) {
627
633
  var _d$_origin2;
@@ -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);
@@ -272,10 +272,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
272
272
  // 添加单个账户或者 guest
273
273
  async addAccount(account, extra) {
274
274
  if ((extra == null ? void 0 : extra.type) === "holder") {
275
- const accountModules = await this.store.accountList.addHolderAccounts(
276
- [account],
277
- extra.customerId
278
- );
275
+ const accountModules = await this.store.accountList.addHolderAccounts({
276
+ holders: [account],
277
+ customerId: extra.customerId,
278
+ type: "unshift"
279
+ });
279
280
  return accountModules[0].getAccount();
280
281
  }
281
282
  const newAccount = await this.store.accountList.addAccount(
@@ -286,10 +287,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
286
287
  // 添加账户或者 guest
287
288
  async addAccounts(accounts, extra) {
288
289
  if ((extra == null ? void 0 : extra.type) === "holder") {
289
- this.store.accountList.addHolderAccounts(
290
- accounts,
291
- extra.customerId
292
- );
290
+ this.store.accountList.addHolderAccounts({
291
+ holders: accounts,
292
+ customerId: extra.customerId,
293
+ type: "unshift"
294
+ });
293
295
  return;
294
296
  }
295
297
  const res = [];
@@ -347,7 +349,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
347
349
  }
348
350
  // 获取商品/服务的可用日期
349
351
  async getAvailableDate(params = {}) {
350
- var _a, _b;
352
+ var _a, _b, _c;
351
353
  let { products, startDate, endDate, type } = params;
352
354
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
353
355
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
@@ -371,7 +373,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
371
373
  }
372
374
  let dateRange = this.store.date.getDateRange();
373
375
  const tempStartDate = startDate || ((_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.date);
374
- const tempEndDate = endDate || ((_b = dateRange == null ? void 0 : dateRange[1]) == null ? void 0 : _b.date);
376
+ const tempEndDate = endDate || ((_b = dateRange == null ? void 0 : dateRange[1]) == null ? void 0 : _b.date) || ((_c = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _c.date);
375
377
  if (!tempProducts.length) {
376
378
  return [];
377
379
  }
@@ -495,6 +497,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
495
497
  if (!targetCartItem) {
496
498
  throw new Error(`没有找到${params._id}购物车商品`);
497
499
  }
500
+ let currentResourcesCapacityMap = {};
498
501
  if (params.resources) {
499
502
  const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
500
503
  capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
@@ -503,21 +506,49 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
503
506
  const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
504
507
  params.resources = params.resources.map((n) => {
505
508
  n.capacity = currentCapacity || 1;
509
+ currentResourcesCapacityMap[n.id] = currentCapacity;
506
510
  (0, import_resources.checkSubResourcesCapacity)(n);
507
511
  return n;
508
512
  });
509
513
  }
510
514
  this.store.cart.updateItem(params);
515
+ const allOriginResources = [];
516
+ const dateRange = this.store.date.getDateRange();
517
+ if (dateRange == null ? void 0 : dateRange.length) {
518
+ dateRange.forEach((n) => {
519
+ if (n.resource)
520
+ allOriginResources.push(...n.resource);
521
+ });
522
+ }
523
+ if (!allOriginResources.length) {
524
+ const dateList = this.store.date.getDateList();
525
+ dateList.forEach((n) => {
526
+ if (n.resource)
527
+ allOriginResources.push(...n.resource);
528
+ });
529
+ }
511
530
  const cartItems = this.store.cart.getItems();
512
531
  cartItems.forEach((item) => {
513
532
  var _a2;
514
- if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
515
- const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
516
- return !targetCartItem._origin.resources.some((targetRes) => {
517
- var _a3, _b;
533
+ const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
534
+ return !targetCartItem._origin.resources.some((targetRes) => {
535
+ var _a3, _b, _c;
536
+ if (targetRes.resourceType !== "single") {
537
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
538
+ capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
539
+ product_bundle: item._origin.product.product_bundle
540
+ });
541
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
542
+ const originResource = allOriginResources.find((n) => n.id === targetRes.id);
543
+ if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
544
+ return true;
545
+ }
546
+ return false;
547
+ }
548
+ if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
518
549
  if (targetRes.id === m.id)
519
550
  return true;
520
- if (((_a3 = targetRes.metadata.combined_resource) == null ? void 0 : _a3.status) === 1 && // 如果现在选择的是组合资源,需要判断
551
+ if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
521
552
  // 1、当前其他购物车里是否选了当前组合资源的子资源
522
553
  // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
523
554
  (targetRes.metadata.combined_resource.resource_ids.includes(
@@ -530,16 +561,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
530
561
  }
531
562
  )))
532
563
  return true;
533
- if (((_b = m.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
564
+ if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
534
565
  return true;
535
- return false;
536
- });
537
- });
538
- this.store.cart.updateItem({
539
- _id: item._id,
540
- resources
566
+ }
567
+ return false;
541
568
  });
542
- }
569
+ });
570
+ this.store.cart.updateItem({
571
+ _id: item._id,
572
+ resources
573
+ });
543
574
  });
544
575
  }
545
576
  // 删除购物车里某个商品
@@ -625,25 +656,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
625
656
  cartItems.forEach((cartItem) => {
626
657
  var _a, _b, _c;
627
658
  let selectedResources = [];
659
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
660
+ capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
661
+ product_bundle: cartItem._origin.product.product_bundle
662
+ });
663
+ cartItem._origin.metadata.capacity = formatCapacity;
664
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
628
665
  if (cartItem.holder_id) {
629
666
  selectedResources = (0, import_resources.getOthersSelectedResources)(
630
667
  cartItems,
631
668
  cartItem.holder_id,
632
- resourcesMap
669
+ resourcesMap,
670
+ currentCapacity
633
671
  );
634
672
  } else {
635
673
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
636
674
  cartItems,
637
675
  cartItem._id,
638
- resourcesMap
676
+ resourcesMap,
677
+ currentCapacity
639
678
  );
640
679
  }
641
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
642
- capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
643
- product_bundle: cartItem._origin.product.product_bundle
644
- });
645
- cartItem._origin.metadata.capacity = formatCapacity;
646
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
647
680
  const productResources = (0, import_resources.getResourcesByProduct)(
648
681
  resourcesMap,
649
682
  ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
@@ -754,25 +787,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
754
787
  cartItems.forEach((cartItem) => {
755
788
  var _a, _b, _c;
756
789
  let selectedResources = [];
790
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
791
+ capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
792
+ product_bundle: cartItem._origin.product.product_bundle
793
+ });
794
+ cartItem._origin.metadata.capacity = formatCapacity;
795
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
757
796
  if (cartItem.holder_id) {
758
797
  selectedResources = (0, import_resources.getOthersSelectedResources)(
759
798
  cartItems,
760
799
  cartItem.holder_id,
761
- resourcesMap
800
+ resourcesMap,
801
+ currentCapacity
762
802
  );
763
803
  } else {
764
804
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
765
805
  cartItems,
766
806
  cartItem._id,
767
- resourcesMap
807
+ resourcesMap,
808
+ currentCapacity
768
809
  );
769
810
  }
770
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
771
- capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
772
- product_bundle: cartItem._origin.product.product_bundle
773
- });
774
- cartItem._origin.metadata.capacity = formatCapacity;
775
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
776
811
  const productResources = (0, import_resources.getResourcesByProduct)(
777
812
  resourcesMap,
778
813
  ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
@@ -875,24 +910,26 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
875
910
  throw new Error(`没有找到${id}购物车商品`);
876
911
  }
877
912
  let selectedResources = [];
913
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
914
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
915
+ product_bundle: targetCartItem._origin.product.product_bundle
916
+ });
917
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
878
918
  if (targetCartItem.holder_id) {
879
919
  selectedResources = (0, import_resources.getOthersSelectedResources)(
880
920
  cartItems,
881
921
  targetCartItem.holder_id,
882
- resourcesMap
922
+ resourcesMap,
923
+ currentCapacity
883
924
  );
884
925
  } else {
885
926
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
886
927
  cartItems,
887
928
  targetCartItem._id,
888
- resourcesMap
929
+ resourcesMap,
930
+ currentCapacity
889
931
  );
890
932
  }
891
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
892
- capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
893
- product_bundle: targetCartItem._origin.product.product_bundle
894
- });
895
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
896
933
  const productResources = (0, import_resources.getResourcesByProduct)(
897
934
  resourcesMap,
898
935
  ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
@@ -974,7 +1011,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
974
1011
  const selectedResources = (0, import_resources.getOthersSelectedResources)(
975
1012
  allCartItems,
976
1013
  holder_id,
977
- resourcesMap
1014
+ resourcesMap,
1015
+ capacity || 0
978
1016
  );
979
1017
  let allProductResources = (0, import_resources.getResourcesByProduct)(
980
1018
  resourcesMap,
@@ -1062,7 +1100,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1062
1100
  resources.push(...n.resource);
1063
1101
  });
1064
1102
  }
1065
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
1066
1103
  const errorList = [];
1067
1104
  const selectResourcesMap = {};
1068
1105
  const accountList = this.store.accountList.getAccounts();
@@ -1144,7 +1181,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1144
1181
  if ((_a3 = n.renderList) == null ? void 0 : _a3.length) {
1145
1182
  n.renderList = n.renderList.filter((m) => {
1146
1183
  var _a4;
1147
- const recordCount = m.capacity || 0;
1184
+ const recordCount = (m.capacity || 0) - (selectResourcesMap[m.id] || 0);
1148
1185
  const timeSlots2 = (0, import_resources.getTimeSlicesByResource)({
1149
1186
  resource: m,
1150
1187
  duration: ((_a4 = item == null ? void 0 : item.duration) == null ? void 0 : _a4.value) || 0,
@@ -1156,29 +1193,31 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1156
1193
  currentResourcesRenderList.push(...n.renderList || []);
1157
1194
  }
1158
1195
  });
1159
- const resourcesMap2 = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
1196
+ const resourcesMap = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
1160
1197
  if (item.holder_id) {
1161
1198
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1162
1199
  allCartItems,
1163
1200
  item.holder_id,
1164
- resourcesMap2
1201
+ resourcesMap,
1202
+ currentCapacity
1165
1203
  );
1166
1204
  } else {
1167
1205
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
1168
1206
  allCartItems,
1169
1207
  item._id,
1170
- resourcesMap2
1208
+ resourcesMap,
1209
+ currentCapacity
1171
1210
  );
1172
1211
  }
1173
1212
  const productResources = (0, import_resources.getResourcesByProduct)(
1174
- resourcesMap2,
1213
+ resourcesMap,
1175
1214
  (0, import_lodash_es.cloneDeep)(resources2),
1176
1215
  selectedResources,
1177
1216
  currentCapacity
1178
1217
  );
1179
1218
  productResources.forEach((item2) => {
1180
1219
  item2.renderList = item2.renderList.filter((n) => {
1181
- const recordCount = n.capacity || 0;
1220
+ const recordCount = (n.capacity || 0) - (selectResourcesMap[n.id] || 0);
1182
1221
  if (n.onlyComputed)
1183
1222
  return false;
1184
1223
  return recordCount >= currentCapacity;
@@ -1196,6 +1235,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1196
1235
  const targetResource = targetRenderList[0];
1197
1236
  targetResource.capacity = currentCapacity;
1198
1237
  (0, import_resources.checkSubResourcesCapacity)(targetResource);
1238
+ if (!selectResourcesMap[targetResource.id]) {
1239
+ selectResourcesMap[targetResource.id] = currentCapacity;
1240
+ } else {
1241
+ selectResourcesMap[targetResource.id] += currentCapacity;
1242
+ }
1199
1243
  this.store.cart.updateItem({
1200
1244
  _id: item._id,
1201
1245
  resources: [
@@ -1319,12 +1363,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1319
1363
  Object.values(itemsByAccount).forEach((accountItems) => {
1320
1364
  let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1321
1365
  accountItems.forEach((item, index) => {
1366
+ var _a;
1322
1367
  const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
1323
1368
  newResources.forEach((resource) => {
1324
- var _a, _b, _c, _d;
1369
+ var _a2, _b, _c, _d;
1325
1370
  resource.startTime = currentStartTime;
1326
1371
  resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
1327
- ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
1372
+ ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.value) ?? 0,
1328
1373
  ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
1329
1374
  ).format("YYYY-MM-DD HH:mm");
1330
1375
  delete resource.times;
@@ -1333,7 +1378,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1333
1378
  _id: item._id,
1334
1379
  resources: newResources
1335
1380
  });
1336
- if (index < accountItems.length - 1) {
1381
+ if (index < accountItems.length - 1 && ((_a = newResources == null ? void 0 : newResources[0]) == null ? void 0 : _a.resourceType) === "single") {
1337
1382
  currentStartTime = newResources[0].endTime;
1338
1383
  }
1339
1384
  });
@@ -1406,7 +1451,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1406
1451
  const selectedResources = (0, import_resources.getOthersSelectedResources)(
1407
1452
  cartItems,
1408
1453
  "",
1409
- resourcesMap
1454
+ resourcesMap,
1455
+ 1
1410
1456
  );
1411
1457
  const productResources = (0, import_resources.getResourcesByProduct)(
1412
1458
  resourcesMap,
@@ -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;
@@ -180,7 +180,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
180
180
  );
181
181
  let optional_resource = item.optional_resource.reduce(
182
182
  (childAcc, d) => {
183
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
183
+ var _a;
184
+ const isSelectSingleResources = ((_a = resourcesMap[d]) == null ? void 0 : _a.resourceType) === "single" && selectedResources.includes(resourcesMap[d].id);
185
+ if (resourcesMap[d] && !isSelectSingleResources) {
184
186
  const combiningResources = [];
185
187
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
186
188
  resourcesMap[d].combined_resource.resource_ids.forEach(
@@ -222,7 +224,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
222
224
  );
223
225
  let default_resource = item.default_resource.reduce(
224
226
  (childAcc, d) => {
225
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
227
+ var _a;
228
+ const isSelectSingleResources = ((_a = resourcesMap[d]) == null ? void 0 : _a.resourceType) === "single" && selectedResources.includes(resourcesMap[d].id);
229
+ if (resourcesMap[d] && !isSelectSingleResources) {
226
230
  const combiningResources = [];
227
231
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
228
232
  resourcesMap[d].combined_resource.resource_ids.forEach(
@@ -429,7 +433,7 @@ var getTimeSlicesByResources = ({
429
433
  let intersection = getTimesIntersection(timeSliceList, resources.length);
430
434
  return intersection;
431
435
  };
432
- var getOthersSelectedResources = (cartItems, accountId, resourcesMap) => {
436
+ var getOthersSelectedResources = (cartItems, accountId, resourcesMap, currentCapacity) => {
433
437
  return cartItems.reduce((acc, d) => {
434
438
  var _a;
435
439
  if (d.holder_id !== accountId) {
@@ -442,28 +446,25 @@ var getOthersSelectedResources = (cartItems, accountId, resourcesMap) => {
442
446
  return acc;
443
447
  }
444
448
  acc.push(...n.metadata.combined_resource.resource_ids);
445
- n.metadata.combined_resource.resource_ids.forEach((m) => {
446
- resourcesMap[m].capacity -= n.num;
447
- });
448
449
  } else {
449
450
  Object.values(resourcesMap).forEach((m) => {
450
451
  if (m.combined_resource && m.combined_resource.status === 1) {
451
452
  if (m.combined_resource.resource_ids.includes(n.id)) {
452
453
  acc.push(m.id);
453
- resourcesMap[m.id].capacity -= n.num;
454
454
  }
455
455
  }
456
456
  });
457
457
  }
458
458
  acc.push(n.id);
459
- resourcesMap[n.id].capacity -= n.num;
459
+ if (resourcesMap[n.id])
460
+ resourcesMap[n.id].capacity -= currentCapacity || 0;
460
461
  });
461
462
  }
462
463
  }
463
464
  return acc;
464
465
  }, []);
465
466
  };
466
- var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
467
+ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap, currentCapacity) => {
467
468
  return cartItems.reduce((acc, d) => {
468
469
  var _a;
469
470
  if (d._id !== cartItemId) {
@@ -476,21 +477,16 @@ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
476
477
  return acc;
477
478
  }
478
479
  acc.push(...n.metadata.combined_resource.resource_ids);
479
- n.metadata.combined_resource.resource_ids.forEach((m) => {
480
- resourcesMap[m].capacity -= n.num;
481
- });
482
480
  } else {
483
481
  Object.values(resourcesMap).forEach((m) => {
484
482
  if (m.combined_resource && m.combined_resource.status === 1) {
485
483
  if (m.combined_resource.resource_ids.includes(n.id)) {
486
484
  acc.push(m.id);
487
- resourcesMap[m.id].capacity -= n.num;
488
485
  }
489
486
  }
490
487
  });
491
488
  }
492
489
  acc.push(n.id);
493
- resourcesMap[n.id].capacity -= n.num;
494
490
  });
495
491
  }
496
492
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.80",
4
+ "version": "0.0.81",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",