@pisell/pisellos 0.0.77 → 0.0.79

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.
@@ -160,7 +160,8 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
160
160
  resources: any[];
161
161
  currentResourceId: number;
162
162
  }): TimeSliceItem[];
163
- autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap, capacity, }: {
163
+ autoSelectAccountResources({ cartItem, holder_id, resources_code, timeSlots, countMap, capacity, }: {
164
+ cartItem: CartItem;
164
165
  holder_id: string;
165
166
  resources_code: string | number;
166
167
  timeSlots?: TimeSliceItem;
@@ -1054,7 +1054,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1054
1054
  // 检查主资源ID是否匹配
1055
1055
  if (targetRes.id === m.id) return true;
1056
1056
  // 检查组合资源的情况
1057
- if (((_targetRes$metadata$c = targetRes.metadata.combined_resource) === null || _targetRes$metadata$c === void 0 ? void 0 : _targetRes$metadata$c.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id)) return true;
1057
+ if (((_targetRes$metadata$c = targetRes.metadata.combined_resource) === null || _targetRes$metadata$c === void 0 ? void 0 : _targetRes$metadata$c.status) === 1 && (
1058
+ // 如果现在选择的是组合资源,需要判断
1059
+ // 1、当前其他购物车里是否选了当前组合资源的子资源
1060
+ // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
1061
+
1062
+ targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some(function (n) {
1063
+ return m.metadata.combined_resource.resource_ids.includes(n);
1064
+ }))) return true;
1058
1065
  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;
1059
1066
  return false;
1060
1067
  });
@@ -1206,7 +1213,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1206
1213
  });
1207
1214
  n.renderList = n.renderList.filter(function (m) {
1208
1215
  var recordCount = capacityMap[m.id] || 0;
1209
- var canUseArr = m.times.map(function (item) {
1216
+ // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1217
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1218
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1219
+ var mTimes = m.times.filter(function (n) {
1220
+ return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
1221
+ });
1222
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1223
+ if (mTimes.length === 0) {
1224
+ return false;
1225
+ }
1226
+ var canUseArr = mTimes.map(function (item) {
1210
1227
  var res = getIsUsableByTimeItem({
1211
1228
  timeSlice: {
1212
1229
  start_time: startTime.format('HH:mm'),
@@ -1235,10 +1252,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1235
1252
  } else {
1236
1253
  productResources.forEach(function (item) {
1237
1254
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1255
+ // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1238
1256
  item.renderList = item.renderList.filter(function (n) {
1257
+ var _cartItem$_productOri3;
1239
1258
  var recordCount = n.capacity || 0;
1240
1259
  if (n.onlyComputed) return false;
1241
- return recordCount >= currentCapacity;
1260
+ // 查一下这个资源基于商品的可用时间片
1261
+ var timeSlots = getTimeSlicesByResource({
1262
+ resource: n,
1263
+ duration: ((_cartItem$_productOri3 = cartItem._productOrigin) === null || _cartItem$_productOri3 === void 0 || (_cartItem$_productOri3 = _cartItem$_productOri3.duration) === null || _cartItem$_productOri3 === void 0 ? void 0 : _cartItem$_productOri3.value) || 0,
1264
+ split: 10,
1265
+ currentDate: dateRange[0].date
1266
+ });
1267
+ return recordCount >= currentCapacity && timeSlots.length > 0;
1242
1268
  });
1243
1269
  });
1244
1270
  }
@@ -1334,7 +1360,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1334
1360
  }, {
1335
1361
  key: "autoSelectAccountResources",
1336
1362
  value: function autoSelectAccountResources(_ref8) {
1337
- var holder_id = _ref8.holder_id,
1363
+ var _cartItem$_productOri4, _allProductResources$;
1364
+ var cartItem = _ref8.cartItem,
1365
+ holder_id = _ref8.holder_id,
1338
1366
  resources_code = _ref8.resources_code,
1339
1367
  timeSlots = _ref8.timeSlots,
1340
1368
  countMap = _ref8.countMap,
@@ -1357,15 +1385,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1357
1385
  // 正常来说,能进这个业务的所有商品的 duration 类型都是一样的,所以这里取第一个商品的 duration 类型
1358
1386
  // let durationType = accountCartItems[0]?._productOrigin?.duration?.type ?? "minutes";
1359
1387
  // 取出账号下所对应类型的所有的可用资源
1360
- var resources = [];
1361
- accountCartItems.forEach(function (item) {
1362
- var _item$_productOrigin2;
1363
- (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.product_resource) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.resources) === null || _item$_productOrigin2 === void 0 || _item$_productOrigin2.forEach(function (n) {
1364
- if (n.code === resources_code) {
1365
- resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1366
- }
1388
+ // let resourcesCartItems: any[] = [];
1389
+ // accountCartItems.forEach((item) => {
1390
+ // item._productOrigin?.product_resource?.resources?.forEach((n) => {
1391
+ // if (n.code === resources_code) {
1392
+ // resourcesCartItems.push(...(n.renderList || []));
1393
+ // }
1394
+ // });
1395
+ // });
1396
+ var AllResources = [];
1397
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
1398
+ dateRange.forEach(function (n) {
1399
+ if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
1367
1400
  });
1368
- });
1401
+ }
1402
+ // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1403
+ if (!AllResources.length) {
1404
+ var dateList = this.store.date.getDateList();
1405
+ dateList.forEach(function (n) {
1406
+ if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
1407
+ });
1408
+ }
1409
+ var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1410
+ var allCartItems = cloneDeep(this.store.cart.getItems());
1411
+ var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1412
+ var allProductResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri4 = cartItem._productOrigin) === null || _cartItem$_productOri4 === void 0 || (_cartItem$_productOri4 = _cartItem$_productOri4.product_resource) === null || _cartItem$_productOri4 === void 0 ? void 0 : _cartItem$_productOri4.resources) || [], selectedResources, 1);
1413
+ var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1414
+ return n.code === resources_code;
1415
+ })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
1369
1416
  // 资源排下序,把单个资源靠前,组合资源排在后面
1370
1417
  resources.sort(function (a, b) {
1371
1418
  var _a$metadata2, _b$metadata2;
@@ -1375,7 +1422,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1375
1422
  if (!aIsCombined && bIsCombined) return -1;
1376
1423
  return 0;
1377
1424
  });
1378
- var resourcesUseableMap = {};
1425
+ var resourcesUseableMap = _toConsumableArray(selectedResources).reduce(function (acc, n) {
1426
+ acc[n] = false;
1427
+ return acc;
1428
+ }, {});
1379
1429
 
1380
1430
  // 如果有选择时间了,则代表不是第一种资源了,则需要根据开始时间去匹配
1381
1431
  // 每个商品
@@ -1390,29 +1440,47 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1390
1440
  _step2;
1391
1441
  try {
1392
1442
  var _loop = function _loop() {
1393
- var n = _step2.value;
1394
- var recordCount = countMap[n.id] || 0;
1395
- var canUseTime = n.times.find(function (item) {
1396
- var res = getIsUsableByTimeItem({
1397
- timeSlice: timeSlots,
1398
- time: item,
1399
- resource: n,
1400
- currentCount: recordCount + (capacity || 0),
1401
- resourcesUseableMap: resourcesUseableMap
1443
+ var n = _step2.value;
1444
+ // 如果资源是独占的,并且 countMap 里选择过这个资源,则直接跳过
1445
+ // if (n.resourceType === 'single' && countMap[n.id]) {
1446
+ // resourcesUseableMap[n.id] = false;
1447
+ // continue
1448
+ // }
1449
+ var recordCount = countMap[n.id] || 0;
1450
+ // n.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1451
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1452
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1453
+ var mTimes = n.times.filter(function (n) {
1454
+ return !dayjs(n.start_at).isAfter(dayjs(timeSlots.start_at)) && !dayjs(n.end_at).isBefore(dayjs(timeSlots.end_at));
1402
1455
  });
1403
- // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1404
- if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
1405
- resourcesUseableMap[n.id] = res.usable;
1456
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1457
+ if (mTimes.length === 0) {
1458
+ return 0; // continue
1406
1459
  }
1407
- return res.usable;
1408
- });
1409
- if (canUseTime) {
1410
- targetResource = n;
1411
- return 1; // break
1412
- }
1413
- };
1460
+ var canUseTime = mTimes.find(function (item) {
1461
+ var res = getIsUsableByTimeItem({
1462
+ timeSlice: timeSlots,
1463
+ time: item,
1464
+ resource: n,
1465
+ currentCount: recordCount + (capacity || 0),
1466
+ resourcesUseableMap: resourcesUseableMap
1467
+ });
1468
+ // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1469
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
1470
+ resourcesUseableMap[n.id] = res.usable;
1471
+ }
1472
+ return res.usable;
1473
+ });
1474
+ if (canUseTime && !n.onlyComputed) {
1475
+ targetResource = n;
1476
+ return 1; // break
1477
+ }
1478
+ },
1479
+ _ret;
1414
1480
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1415
- if (_loop()) break;
1481
+ _ret = _loop();
1482
+ if (_ret === 0) continue;
1483
+ if (_ret === 1) break;
1416
1484
  }
1417
1485
  } catch (err) {
1418
1486
  _iterator2.e(err);
@@ -1423,13 +1491,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1423
1491
  selectedResource: targetResource
1424
1492
  };
1425
1493
  } else {
1426
- var resourcesMap = getResourcesMap(resources);
1494
+ var _resourcesMap = getResourcesMap(resources);
1427
1495
  var resourceIds = resources.map(function (n) {
1428
1496
  return n.id;
1429
1497
  });
1430
1498
  var _timeSlots = getTimeSlicesByResources({
1431
1499
  resourceIds: resourceIds,
1432
- resourcesMap: resourcesMap,
1500
+ resourcesMap: _resourcesMap,
1433
1501
  duration: duration,
1434
1502
  currentDate: dateRange[0].date,
1435
1503
  split: 10,
@@ -1472,9 +1540,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1472
1540
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1473
1541
 
1474
1542
  cartItems.forEach(function (item, index) {
1475
- var _item$_productOrigin3;
1543
+ var _item$_productOrigin2;
1476
1544
  var formatCapacity = formatDefaultCapacitys({
1477
- capacity: (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.capacity,
1545
+ capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1478
1546
  product_bundle: item._origin.product.product_bundle
1479
1547
  });
1480
1548
  var currentCapacity = getSumCapacity({
@@ -1491,9 +1559,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1491
1559
  }
1492
1560
  if (recordTimeSlots) {
1493
1561
  if (index !== 0 && recordTimeSlots) {
1494
- var _item$_productOrigin$, _item$_productOrigin4, _ref9, _item$_productOrigin5, _item$_productOrigin$2, _item$_productOrigin6, _ref10, _item$_productOrigin7;
1495
- 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');
1496
- 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');
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');
1497
1565
  recordTimeSlots = {
1498
1566
  start_time: start_at.format('HH:mm'),
1499
1567
  end_time: end_at.format('HH:mm'),
@@ -1503,6 +1571,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1503
1571
  }
1504
1572
  // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
1505
1573
  var res = _this8.autoSelectAccountResources({
1574
+ cartItem: item,
1506
1575
  holder_id: item.holder_id,
1507
1576
  resources_code: resources_code,
1508
1577
  timeSlots: recordTimeSlots,
@@ -1525,7 +1594,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1525
1594
  _id: item._id,
1526
1595
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
1527
1596
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
1528
- return existingRes.form_id !== res.selectedResource.form_id;
1597
+ var _res$selectedResource;
1598
+ return existingRes.form_id !== ((_res$selectedResource = res.selectedResource) === null || _res$selectedResource === void 0 ? void 0 : _res$selectedResource.form_id);
1529
1599
  })), [res.selectedResource])
1530
1600
  });
1531
1601
  } else {
@@ -1533,31 +1603,38 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1533
1603
  errorList.push(item._id);
1534
1604
  }
1535
1605
  } else {
1536
- var _item$_productOrigin8, _productResources$fin;
1606
+ var _item$_productOrigin7, _productResources$fin;
1537
1607
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1538
1608
  var allCartItems = cloneDeep(_this8.store.cart.getItems());
1539
1609
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1540
1610
  var selectedResources = [];
1541
- 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) || []);
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) || []);
1542
1612
  var currentResourcesRenderList = [];
1543
1613
  _resources.forEach(function (n) {
1544
1614
  var _n$renderList;
1545
1615
  if ((_n$renderList = n.renderList) !== null && _n$renderList !== void 0 && _n$renderList.length) {
1546
1616
  // 过滤掉 capacity 小于 currentCapacity 的资源
1547
1617
  n.renderList = n.renderList.filter(function (m) {
1618
+ var _item$duration;
1548
1619
  var recordCount = m.capacity || 0;
1549
- return recordCount >= currentCapacity;
1620
+ var timeSlots = getTimeSlicesByResource({
1621
+ resource: m,
1622
+ duration: (item === null || item === void 0 || (_item$duration = item.duration) === null || _item$duration === void 0 ? void 0 : _item$duration.value) || 0,
1623
+ split: 10,
1624
+ currentDate: dateRange[0].date
1625
+ });
1626
+ return recordCount >= currentCapacity && timeSlots.length > 0;
1550
1627
  });
1551
1628
  currentResourcesRenderList.push.apply(currentResourcesRenderList, _toConsumableArray(n.renderList || []));
1552
1629
  }
1553
1630
  });
1554
- var _resourcesMap = getResourcesMap(currentResourcesRenderList);
1631
+ var _resourcesMap2 = getResourcesMap(currentResourcesRenderList);
1555
1632
  if (item.holder_id) {
1556
- selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, _resourcesMap);
1633
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, _resourcesMap2);
1557
1634
  } else {
1558
- selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap);
1635
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap2);
1559
1636
  }
1560
- var productResources = getResourcesByProduct(_resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1637
+ var productResources = getResourcesByProduct(_resourcesMap2, cloneDeep(_resources), selectedResources, currentCapacity);
1561
1638
  productResources.forEach(function (item) {
1562
1639
  item.renderList = item.renderList.filter(function (n) {
1563
1640
  var recordCount = n.capacity || 0;
@@ -1625,8 +1702,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1625
1702
  var resourceIds = [];
1626
1703
  var resourcesTypeId = undefined;
1627
1704
  cartItems.forEach(function (item) {
1628
- var _item$_productOrigin9, _item$_productOrigin10;
1629
- (_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) {
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) {
1630
1707
  if (n.code === resources_code) {
1631
1708
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1632
1709
  }
@@ -1637,9 +1714,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1637
1714
  if (item.resource_id) {
1638
1715
  resourceIds.push(item.resource_id);
1639
1716
  }
1640
- 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) {
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) {
1641
1718
  return n.code === resources_code;
1642
- })) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.id;
1719
+ })) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.id;
1643
1720
  });
1644
1721
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
1645
1722
  if ((_dateRange = dateRange) !== null && _dateRange !== void 0 && (_dateRange = _dateRange[0]) !== null && _dateRange !== void 0 && (_dateRange = _dateRange.resource) !== null && _dateRange !== void 0 && _dateRange.length) {
@@ -1659,8 +1736,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1659
1736
  var checkDuration = function checkDuration(cartItems) {
1660
1737
  var accountDuration = 0;
1661
1738
  cartItems.forEach(function (item) {
1662
- var _item$_productOrigin$3, _item$_productOrigin11;
1663
- 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;
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;
1664
1741
  });
1665
1742
  if (accountDuration > duration) {
1666
1743
  duration = accountDuration;
@@ -1729,9 +1806,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1729
1806
  accountItems.forEach(function (item, index) {
1730
1807
  var newResources = cloneDeep(item._origin.resources);
1731
1808
  newResources.forEach(function (resource) {
1732
- var _item$_productOrigin$4, _item$_productOrigin12, _ref11, _item$_productOrigin13;
1809
+ var _item$_productOrigin$4, _item$_productOrigin11, _ref11, _item$_productOrigin12;
1733
1810
  resource.startTime = currentStartTime;
1734
- 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');
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');
1735
1812
  delete resource.times;
1736
1813
  });
1737
1814
  _this10.store.cart.updateItem({
@@ -1861,11 +1938,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1861
1938
  var count = 0;
1862
1939
  // 遍历所有资源
1863
1940
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
1864
- debugger;
1865
1941
  // 遍历所有资源的上工时间片
1866
1942
  var currentResourcesCount = 0;
1867
1943
  var currentResourcesTimeSlotCanUsedArr = [];
1868
- m.times.forEach(function (childTiem) {
1944
+ // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1945
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1946
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1947
+ var mTimes = m.times.filter(function (n) {
1948
+ return !dayjs(n.start_at).isAfter(dayjs(item.start)) && !dayjs(n.end_at).isBefore(dayjs(item.end));
1949
+ });
1950
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1951
+ if (mTimes.length === 0) {
1952
+ return;
1953
+ }
1954
+ mTimes.forEach(function (childTiem) {
1869
1955
  // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
1870
1956
  var res = getIsUsableByTimeItem({
1871
1957
  timeSlice: {
@@ -1888,7 +1974,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1888
1974
  }
1889
1975
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1890
1976
  });
1891
- // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1977
+ // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
1892
1978
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
1893
1979
  return n === false;
1894
1980
  })) {
@@ -160,7 +160,8 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
160
160
  resources: any[];
161
161
  currentResourceId: number;
162
162
  }): TimeSliceItem[];
163
- autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap, capacity, }: {
163
+ autoSelectAccountResources({ cartItem, holder_id, resources_code, timeSlots, countMap, capacity, }: {
164
+ cartItem: CartItem;
164
165
  holder_id: string;
165
166
  resources_code: string | number;
166
167
  timeSlots?: TimeSliceItem;
@@ -511,7 +511,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
511
511
  var _a3, _b;
512
512
  if (targetRes.id === m.id)
513
513
  return true;
514
- if (((_a3 = targetRes.metadata.combined_resource) == null ? void 0 : _a3.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id))
514
+ if (((_a3 = targetRes.metadata.combined_resource) == null ? void 0 : _a3.status) === 1 && // 如果现在选择的是组合资源,需要判断
515
+ // 1、当前其他购物车里是否选了当前组合资源的子资源
516
+ // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
517
+ (targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some((n) => {
518
+ return m.metadata.combined_resource.resource_ids.includes(n);
519
+ })))
515
520
  return true;
516
521
  if (((_b = m.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
517
522
  return true;
@@ -654,7 +659,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
654
659
  });
655
660
  n.renderList = n.renderList.filter((m) => {
656
661
  const recordCount = capacityMap[m.id] || 0;
657
- const canUseArr = m.times.map((item) => {
662
+ const mTimes = m.times.filter((n2) => {
663
+ return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(endTime));
664
+ });
665
+ if (mTimes.length === 0) {
666
+ return false;
667
+ }
668
+ const canUseArr = mTimes.map((item) => {
658
669
  const res = (0, import_resources.getIsUsableByTimeItem)({
659
670
  timeSlice: {
660
671
  start_time: startTime.format("HH:mm"),
@@ -680,10 +691,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
680
691
  } else {
681
692
  productResources.forEach((item) => {
682
693
  item.renderList = item.renderList.filter((n) => {
694
+ var _a2, _b2;
683
695
  const recordCount = n.capacity || 0;
684
696
  if (n.onlyComputed)
685
697
  return false;
686
- return recordCount >= currentCapacity;
698
+ const timeSlots = (0, import_resources.getTimeSlicesByResource)({
699
+ resource: n,
700
+ duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 0,
701
+ split: 10,
702
+ currentDate: dateRange[0].date
703
+ });
704
+ return recordCount >= currentCapacity && timeSlots.length > 0;
687
705
  });
688
706
  });
689
707
  }
@@ -778,12 +796,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
778
796
  }
779
797
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
780
798
  autoSelectAccountResources({
799
+ cartItem,
781
800
  holder_id,
782
801
  resources_code,
783
802
  timeSlots,
784
803
  countMap,
785
804
  capacity
786
805
  }) {
806
+ var _a, _b, _c;
787
807
  const dateRange = this.store.date.getDateRange();
788
808
  const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
789
809
  let accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
@@ -791,34 +811,62 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
791
811
  accountCartItems = cartItems;
792
812
  }
793
813
  let duration = accountCartItems.reduce((acc, n) => {
794
- var _a, _b;
795
- return acc + (((_b = (_a = n._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0);
814
+ var _a2, _b2;
815
+ return acc + (((_b2 = (_a2 = n._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0);
796
816
  }, 0);
797
- let resources = [];
798
- accountCartItems.forEach((item) => {
799
- var _a, _b, _c;
800
- (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
801
- if (n.code === resources_code) {
802
- resources.push(...n.renderList || []);
803
- }
817
+ let AllResources = [];
818
+ if (dateRange == null ? void 0 : dateRange.length) {
819
+ dateRange.forEach((n) => {
820
+ if (n.resource)
821
+ AllResources.push(...n.resource);
804
822
  });
805
- });
823
+ }
824
+ if (!AllResources.length) {
825
+ const dateList = this.store.date.getDateList();
826
+ dateList.forEach((n) => {
827
+ if (n.resource)
828
+ AllResources.push(...n.resource);
829
+ });
830
+ }
831
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
832
+ const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
833
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(
834
+ allCartItems,
835
+ holder_id,
836
+ resourcesMap
837
+ );
838
+ let allProductResources = (0, import_resources.getResourcesByProduct)(
839
+ resourcesMap,
840
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
841
+ selectedResources,
842
+ 1
843
+ );
844
+ const resources = ((_c = allProductResources.find((n) => n.code === resources_code)) == null ? void 0 : _c.renderList) || [];
806
845
  resources.sort((a, b) => {
807
- var _a, _b, _c, _d;
808
- const aIsCombined = ((_b = (_a = a.metadata) == null ? void 0 : _a.combined_resource) == null ? void 0 : _b.status) === 1;
809
- const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
846
+ var _a2, _b2, _c2, _d;
847
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
848
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
810
849
  if (aIsCombined && !bIsCombined)
811
850
  return 1;
812
851
  if (!aIsCombined && bIsCombined)
813
852
  return -1;
814
853
  return 0;
815
854
  });
816
- const resourcesUseableMap = {};
855
+ const resourcesUseableMap = [...selectedResources].reduce((acc, n) => {
856
+ acc[n] = false;
857
+ return acc;
858
+ }, {});
817
859
  if (timeSlots) {
818
860
  let targetResource = null;
819
861
  for (const n of resources) {
820
862
  const recordCount = countMap[n.id] || 0;
821
- const canUseTime = n.times.find((item) => {
863
+ const mTimes = n.times.filter((n2) => {
864
+ return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
865
+ });
866
+ if (mTimes.length === 0) {
867
+ continue;
868
+ }
869
+ const canUseTime = mTimes.find((item) => {
822
870
  const res = (0, import_resources.getIsUsableByTimeItem)({
823
871
  timeSlice: timeSlots,
824
872
  time: item,
@@ -831,7 +879,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
831
879
  }
832
880
  return res.usable;
833
881
  });
834
- if (canUseTime) {
882
+ if (canUseTime && !n.onlyComputed) {
835
883
  targetResource = n;
836
884
  break;
837
885
  }
@@ -840,11 +888,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
840
888
  selectedResource: targetResource
841
889
  };
842
890
  } else {
843
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
891
+ const resourcesMap2 = (0, import_utils.getResourcesMap)(resources);
844
892
  const resourceIds = resources.map((n) => n.id);
845
893
  const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
846
894
  resourceIds,
847
- resourcesMap,
895
+ resourcesMap: resourcesMap2,
848
896
  duration,
849
897
  currentDate: dateRange[0].date,
850
898
  split: 10,
@@ -910,6 +958,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
910
958
  };
911
959
  }
912
960
  const res = this.autoSelectAccountResources({
961
+ cartItem: item,
913
962
  holder_id: item.holder_id,
914
963
  resources_code,
915
964
  timeSlots: recordTimeSlots,
@@ -929,7 +978,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
929
978
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
930
979
  resources: [
931
980
  ...(item._origin.resources || []).filter(
932
- (existingRes) => existingRes.form_id !== res.selectedResource.form_id
981
+ (existingRes) => {
982
+ var _a3;
983
+ return existingRes.form_id !== ((_a3 = res.selectedResource) == null ? void 0 : _a3.form_id);
984
+ }
933
985
  ),
934
986
  res.selectedResource
935
987
  ]
@@ -948,8 +1000,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
948
1000
  var _a3;
949
1001
  if ((_a3 = n.renderList) == null ? void 0 : _a3.length) {
950
1002
  n.renderList = n.renderList.filter((m) => {
1003
+ var _a4;
951
1004
  const recordCount = m.capacity || 0;
952
- return recordCount >= currentCapacity;
1005
+ const timeSlots2 = (0, import_resources.getTimeSlicesByResource)({
1006
+ resource: m,
1007
+ duration: ((_a4 = item == null ? void 0 : item.duration) == null ? void 0 : _a4.value) || 0,
1008
+ split: 10,
1009
+ currentDate: dateRange[0].date
1010
+ });
1011
+ return recordCount >= currentCapacity && timeSlots2.length > 0;
953
1012
  });
954
1013
  currentResourcesRenderList.push(...n.renderList || []);
955
1014
  }
@@ -1231,10 +1290,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1231
1290
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1232
1291
  let count = 0;
1233
1292
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1234
- debugger;
1235
1293
  let currentResourcesCount = 0;
1236
1294
  const currentResourcesTimeSlotCanUsedArr = [];
1237
- m.times.forEach((childTiem) => {
1295
+ const mTimes = m.times.filter((n) => {
1296
+ return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start)) && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end));
1297
+ });
1298
+ if (mTimes.length === 0) {
1299
+ return;
1300
+ }
1301
+ mTimes.forEach((childTiem) => {
1238
1302
  const res = (0, import_resources.getIsUsableByTimeItem)({
1239
1303
  timeSlice: {
1240
1304
  start_time: item.start,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.77",
4
+ "version": "0.0.79",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",