@pisell/pisellos 0.0.76 → 0.0.78

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
  });
@@ -1189,6 +1196,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1189
1196
  capacity: formatCapacity
1190
1197
  });
1191
1198
  var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri2 = cartItem._productOrigin) === null || _cartItem$_productOri2 === void 0 || (_cartItem$_productOri2 = _cartItem$_productOri2.product_resource) === null || _cartItem$_productOri2 === void 0 ? void 0 : _cartItem$_productOri2.resources) || [], selectedResources, currentCapacity);
1199
+ debugger;
1192
1200
  // 如果购物车里已经有了时间片,则需要按照时间片过滤
1193
1201
  if (cartItem._origin.start_time) {
1194
1202
  var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
@@ -1206,7 +1214,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1206
1214
  });
1207
1215
  n.renderList = n.renderList.filter(function (m) {
1208
1216
  var recordCount = capacityMap[m.id] || 0;
1209
- var canUseArr = m.times.map(function (item) {
1217
+ // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1218
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1219
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1220
+ var mTimes = m.times.filter(function (n) {
1221
+ return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
1222
+ });
1223
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1224
+ if (mTimes.length === 0) {
1225
+ return false;
1226
+ }
1227
+ var canUseArr = mTimes.map(function (item) {
1210
1228
  var res = getIsUsableByTimeItem({
1211
1229
  timeSlice: {
1212
1230
  start_time: startTime.format('HH:mm'),
@@ -1334,7 +1352,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1334
1352
  }, {
1335
1353
  key: "autoSelectAccountResources",
1336
1354
  value: function autoSelectAccountResources(_ref8) {
1337
- var holder_id = _ref8.holder_id,
1355
+ var _cartItem$_productOri3, _allProductResources$;
1356
+ var cartItem = _ref8.cartItem,
1357
+ holder_id = _ref8.holder_id,
1338
1358
  resources_code = _ref8.resources_code,
1339
1359
  timeSlots = _ref8.timeSlots,
1340
1360
  countMap = _ref8.countMap,
@@ -1357,15 +1377,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1357
1377
  // 正常来说,能进这个业务的所有商品的 duration 类型都是一样的,所以这里取第一个商品的 duration 类型
1358
1378
  // let durationType = accountCartItems[0]?._productOrigin?.duration?.type ?? "minutes";
1359
1379
  // 取出账号下所对应类型的所有的可用资源
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
- }
1380
+ // let resourcesCartItems: any[] = [];
1381
+ // accountCartItems.forEach((item) => {
1382
+ // item._productOrigin?.product_resource?.resources?.forEach((n) => {
1383
+ // if (n.code === resources_code) {
1384
+ // resourcesCartItems.push(...(n.renderList || []));
1385
+ // }
1386
+ // });
1387
+ // });
1388
+ var AllResources = [];
1389
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
1390
+ dateRange.forEach(function (n) {
1391
+ if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
1367
1392
  });
1368
- });
1393
+ }
1394
+ // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1395
+ if (!AllResources.length) {
1396
+ var dateList = this.store.date.getDateList();
1397
+ dateList.forEach(function (n) {
1398
+ if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
1399
+ });
1400
+ }
1401
+ var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1402
+ var allCartItems = cloneDeep(this.store.cart.getItems());
1403
+ var selectedResources = getOthersSelectedResources(allCartItems, holder_id, resourcesMap);
1404
+ var allProductResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri3 = cartItem._productOrigin) === null || _cartItem$_productOri3 === void 0 || (_cartItem$_productOri3 = _cartItem$_productOri3.product_resource) === null || _cartItem$_productOri3 === void 0 ? void 0 : _cartItem$_productOri3.resources) || [], selectedResources, 1);
1405
+ var resources = ((_allProductResources$ = allProductResources.find(function (n) {
1406
+ return n.code === resources_code;
1407
+ })) === null || _allProductResources$ === void 0 ? void 0 : _allProductResources$.renderList) || [];
1369
1408
  // 资源排下序,把单个资源靠前,组合资源排在后面
1370
1409
  resources.sort(function (a, b) {
1371
1410
  var _a$metadata2, _b$metadata2;
@@ -1375,7 +1414,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1375
1414
  if (!aIsCombined && bIsCombined) return -1;
1376
1415
  return 0;
1377
1416
  });
1378
- var resourcesUseableMap = {};
1417
+ var resourcesUseableMap = _toConsumableArray(selectedResources).reduce(function (acc, n) {
1418
+ acc[n] = false;
1419
+ return acc;
1420
+ }, {});
1379
1421
 
1380
1422
  // 如果有选择时间了,则代表不是第一种资源了,则需要根据开始时间去匹配
1381
1423
  // 每个商品
@@ -1390,29 +1432,47 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1390
1432
  _step2;
1391
1433
  try {
1392
1434
  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
1435
+ var n = _step2.value;
1436
+ // 如果资源是独占的,并且 countMap 里选择过这个资源,则直接跳过
1437
+ // if (n.resourceType === 'single' && countMap[n.id]) {
1438
+ // resourcesUseableMap[n.id] = false;
1439
+ // continue
1440
+ // }
1441
+ var recordCount = countMap[n.id] || 0;
1442
+ // n.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1443
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1444
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1445
+ var mTimes = n.times.filter(function (n) {
1446
+ return !dayjs(n.start_at).isAfter(dayjs(timeSlots.start_at)) && !dayjs(n.end_at).isBefore(dayjs(timeSlots.end_at));
1402
1447
  });
1403
- // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1404
- if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
1405
- resourcesUseableMap[n.id] = res.usable;
1448
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1449
+ if (mTimes.length === 0) {
1450
+ return 0; // continue
1406
1451
  }
1407
- return res.usable;
1408
- });
1409
- if (canUseTime) {
1410
- targetResource = n;
1411
- return 1; // break
1412
- }
1413
- };
1452
+ var canUseTime = mTimes.find(function (item) {
1453
+ var res = getIsUsableByTimeItem({
1454
+ timeSlice: timeSlots,
1455
+ time: item,
1456
+ resource: n,
1457
+ currentCount: recordCount + (capacity || 0),
1458
+ resourcesUseableMap: resourcesUseableMap
1459
+ });
1460
+ // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1461
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== 'capacityOnly') {
1462
+ resourcesUseableMap[n.id] = res.usable;
1463
+ }
1464
+ return res.usable;
1465
+ });
1466
+ if (canUseTime && !n.onlyComputed) {
1467
+ targetResource = n;
1468
+ return 1; // break
1469
+ }
1470
+ },
1471
+ _ret;
1414
1472
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1415
- if (_loop()) break;
1473
+ _ret = _loop();
1474
+ if (_ret === 0) continue;
1475
+ if (_ret === 1) break;
1416
1476
  }
1417
1477
  } catch (err) {
1418
1478
  _iterator2.e(err);
@@ -1423,13 +1483,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1423
1483
  selectedResource: targetResource
1424
1484
  };
1425
1485
  } else {
1426
- var resourcesMap = getResourcesMap(resources);
1486
+ var _resourcesMap = getResourcesMap(resources);
1427
1487
  var resourceIds = resources.map(function (n) {
1428
1488
  return n.id;
1429
1489
  });
1430
1490
  var _timeSlots = getTimeSlicesByResources({
1431
1491
  resourceIds: resourceIds,
1432
- resourcesMap: resourcesMap,
1492
+ resourcesMap: _resourcesMap,
1433
1493
  duration: duration,
1434
1494
  currentDate: dateRange[0].date,
1435
1495
  split: 10,
@@ -1472,9 +1532,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1472
1532
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1473
1533
 
1474
1534
  cartItems.forEach(function (item, index) {
1475
- var _item$_productOrigin3;
1535
+ var _item$_productOrigin2;
1476
1536
  var formatCapacity = formatDefaultCapacitys({
1477
- capacity: (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.capacity,
1537
+ capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1478
1538
  product_bundle: item._origin.product.product_bundle
1479
1539
  });
1480
1540
  var currentCapacity = getSumCapacity({
@@ -1491,9 +1551,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1491
1551
  }
1492
1552
  if (recordTimeSlots) {
1493
1553
  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');
1554
+ var _item$_productOrigin$, _item$_productOrigin3, _ref9, _item$_productOrigin4, _item$_productOrigin$2, _item$_productOrigin5, _ref10, _item$_productOrigin6;
1555
+ 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');
1556
+ 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
1557
  recordTimeSlots = {
1498
1558
  start_time: start_at.format('HH:mm'),
1499
1559
  end_time: end_at.format('HH:mm'),
@@ -1503,6 +1563,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1503
1563
  }
1504
1564
  // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
1505
1565
  var res = _this8.autoSelectAccountResources({
1566
+ cartItem: item,
1506
1567
  holder_id: item.holder_id,
1507
1568
  resources_code: resources_code,
1508
1569
  timeSlots: recordTimeSlots,
@@ -1525,7 +1586,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1525
1586
  _id: item._id,
1526
1587
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
1527
1588
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
1528
- return existingRes.form_id !== res.selectedResource.form_id;
1589
+ var _res$selectedResource;
1590
+ return existingRes.form_id !== ((_res$selectedResource = res.selectedResource) === null || _res$selectedResource === void 0 ? void 0 : _res$selectedResource.form_id);
1529
1591
  })), [res.selectedResource])
1530
1592
  });
1531
1593
  } else {
@@ -1533,12 +1595,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1533
1595
  errorList.push(item._id);
1534
1596
  }
1535
1597
  } else {
1536
- var _item$_productOrigin8, _productResources$fin;
1598
+ var _item$_productOrigin7, _productResources$fin;
1537
1599
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1538
1600
  var allCartItems = cloneDeep(_this8.store.cart.getItems());
1539
1601
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1540
1602
  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) || []);
1603
+ 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
1604
  var currentResourcesRenderList = [];
1543
1605
  _resources.forEach(function (n) {
1544
1606
  var _n$renderList;
@@ -1551,13 +1613,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1551
1613
  currentResourcesRenderList.push.apply(currentResourcesRenderList, _toConsumableArray(n.renderList || []));
1552
1614
  }
1553
1615
  });
1554
- var _resourcesMap = getResourcesMap(currentResourcesRenderList);
1616
+ var _resourcesMap2 = getResourcesMap(currentResourcesRenderList);
1555
1617
  if (item.holder_id) {
1556
- selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, _resourcesMap);
1618
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, _resourcesMap2);
1557
1619
  } else {
1558
- selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap);
1620
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap2);
1559
1621
  }
1560
- var productResources = getResourcesByProduct(_resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1622
+ var productResources = getResourcesByProduct(_resourcesMap2, cloneDeep(_resources), selectedResources, currentCapacity);
1561
1623
  productResources.forEach(function (item) {
1562
1624
  item.renderList = item.renderList.filter(function (n) {
1563
1625
  var recordCount = n.capacity || 0;
@@ -1625,8 +1687,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1625
1687
  var resourceIds = [];
1626
1688
  var resourcesTypeId = undefined;
1627
1689
  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) {
1690
+ var _item$_productOrigin8, _item$_productOrigin9;
1691
+ (_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
1692
  if (n.code === resources_code) {
1631
1693
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1632
1694
  }
@@ -1637,9 +1699,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1637
1699
  if (item.resource_id) {
1638
1700
  resourceIds.push(item.resource_id);
1639
1701
  }
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) {
1702
+ 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
1703
  return n.code === resources_code;
1642
- })) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.id;
1704
+ })) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.id;
1643
1705
  });
1644
1706
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
1645
1707
  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 +1721,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1659
1721
  var checkDuration = function checkDuration(cartItems) {
1660
1722
  var accountDuration = 0;
1661
1723
  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;
1724
+ var _item$_productOrigin$3, _item$_productOrigin10;
1725
+ 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
1726
  });
1665
1727
  if (accountDuration > duration) {
1666
1728
  duration = accountDuration;
@@ -1729,9 +1791,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1729
1791
  accountItems.forEach(function (item, index) {
1730
1792
  var newResources = cloneDeep(item._origin.resources);
1731
1793
  newResources.forEach(function (resource) {
1732
- var _item$_productOrigin$4, _item$_productOrigin12, _ref11, _item$_productOrigin13;
1794
+ var _item$_productOrigin$4, _item$_productOrigin11, _ref11, _item$_productOrigin12;
1733
1795
  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');
1796
+ 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
1797
  delete resource.times;
1736
1798
  });
1737
1799
  _this10.store.cart.updateItem({
@@ -1772,6 +1834,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1772
1834
  });
1773
1835
  });
1774
1836
  var newScheduleArr = Object.values(newSchedule);
1837
+ // newScheduleArr 需要做个排序,按日期从小到大
1838
+ newScheduleArr.sort(function (a, b) {
1839
+ return dayjs(a.date).diff(dayjs(b.date));
1840
+ });
1775
1841
  return newScheduleArr;
1776
1842
  }
1777
1843
  // 打开某个商品详情的弹窗,OS 层这边会记录当前选中的商品,适用于 session 类商品预约
@@ -1857,11 +1923,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1857
1923
  var count = 0;
1858
1924
  // 遍历所有资源
1859
1925
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
1860
- debugger;
1861
1926
  // 遍历所有资源的上工时间片
1862
1927
  var currentResourcesCount = 0;
1863
1928
  var currentResourcesTimeSlotCanUsedArr = [];
1864
- m.times.forEach(function (childTiem) {
1929
+ // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1930
+ // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1931
+ // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1932
+ var mTimes = m.times.filter(function (n) {
1933
+ return !dayjs(n.start_at).isAfter(dayjs(item.start)) && !dayjs(n.end_at).isBefore(dayjs(item.end));
1934
+ });
1935
+ // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1936
+ if (mTimes.length === 0) {
1937
+ return;
1938
+ }
1939
+ mTimes.forEach(function (childTiem) {
1865
1940
  // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
1866
1941
  var res = getIsUsableByTimeItem({
1867
1942
  timeSlice: {
@@ -1884,7 +1959,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1884
1959
  }
1885
1960
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1886
1961
  });
1887
- // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1962
+ // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
1888
1963
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
1889
1964
  return n === false;
1890
1965
  })) {
@@ -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;
@@ -633,6 +638,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
633
638
  selectedResources,
634
639
  currentCapacity
635
640
  );
641
+ debugger;
636
642
  if (cartItem._origin.start_time) {
637
643
  const startTime = (0, import_dayjs.default)(
638
644
  `${cartItem._origin.start_date} ${cartItem._origin.start_time}`
@@ -654,7 +660,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
654
660
  });
655
661
  n.renderList = n.renderList.filter((m) => {
656
662
  const recordCount = capacityMap[m.id] || 0;
657
- const canUseArr = m.times.map((item) => {
663
+ const mTimes = m.times.filter((n2) => {
664
+ 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));
665
+ });
666
+ if (mTimes.length === 0) {
667
+ return false;
668
+ }
669
+ const canUseArr = mTimes.map((item) => {
658
670
  const res = (0, import_resources.getIsUsableByTimeItem)({
659
671
  timeSlice: {
660
672
  start_time: startTime.format("HH:mm"),
@@ -778,12 +790,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
778
790
  }
779
791
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
780
792
  autoSelectAccountResources({
793
+ cartItem,
781
794
  holder_id,
782
795
  resources_code,
783
796
  timeSlots,
784
797
  countMap,
785
798
  capacity
786
799
  }) {
800
+ var _a, _b, _c;
787
801
  const dateRange = this.store.date.getDateRange();
788
802
  const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
789
803
  let accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
@@ -791,34 +805,62 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
791
805
  accountCartItems = cartItems;
792
806
  }
793
807
  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);
808
+ var _a2, _b2;
809
+ return acc + (((_b2 = (_a2 = n._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0);
796
810
  }, 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
- }
811
+ let AllResources = [];
812
+ if (dateRange == null ? void 0 : dateRange.length) {
813
+ dateRange.forEach((n) => {
814
+ if (n.resource)
815
+ AllResources.push(...n.resource);
804
816
  });
805
- });
817
+ }
818
+ if (!AllResources.length) {
819
+ const dateList = this.store.date.getDateList();
820
+ dateList.forEach((n) => {
821
+ if (n.resource)
822
+ AllResources.push(...n.resource);
823
+ });
824
+ }
825
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
826
+ const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
827
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(
828
+ allCartItems,
829
+ holder_id,
830
+ resourcesMap
831
+ );
832
+ let allProductResources = (0, import_resources.getResourcesByProduct)(
833
+ resourcesMap,
834
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
835
+ selectedResources,
836
+ 1
837
+ );
838
+ const resources = ((_c = allProductResources.find((n) => n.code === resources_code)) == null ? void 0 : _c.renderList) || [];
806
839
  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;
840
+ var _a2, _b2, _c2, _d;
841
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
842
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
810
843
  if (aIsCombined && !bIsCombined)
811
844
  return 1;
812
845
  if (!aIsCombined && bIsCombined)
813
846
  return -1;
814
847
  return 0;
815
848
  });
816
- const resourcesUseableMap = {};
849
+ const resourcesUseableMap = [...selectedResources].reduce((acc, n) => {
850
+ acc[n] = false;
851
+ return acc;
852
+ }, {});
817
853
  if (timeSlots) {
818
854
  let targetResource = null;
819
855
  for (const n of resources) {
820
856
  const recordCount = countMap[n.id] || 0;
821
- const canUseTime = n.times.find((item) => {
857
+ const mTimes = n.times.filter((n2) => {
858
+ 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));
859
+ });
860
+ if (mTimes.length === 0) {
861
+ continue;
862
+ }
863
+ const canUseTime = mTimes.find((item) => {
822
864
  const res = (0, import_resources.getIsUsableByTimeItem)({
823
865
  timeSlice: timeSlots,
824
866
  time: item,
@@ -831,7 +873,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
831
873
  }
832
874
  return res.usable;
833
875
  });
834
- if (canUseTime) {
876
+ if (canUseTime && !n.onlyComputed) {
835
877
  targetResource = n;
836
878
  break;
837
879
  }
@@ -840,11 +882,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
840
882
  selectedResource: targetResource
841
883
  };
842
884
  } else {
843
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
885
+ const resourcesMap2 = (0, import_utils.getResourcesMap)(resources);
844
886
  const resourceIds = resources.map((n) => n.id);
845
887
  const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
846
888
  resourceIds,
847
- resourcesMap,
889
+ resourcesMap: resourcesMap2,
848
890
  duration,
849
891
  currentDate: dateRange[0].date,
850
892
  split: 10,
@@ -910,6 +952,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
910
952
  };
911
953
  }
912
954
  const res = this.autoSelectAccountResources({
955
+ cartItem: item,
913
956
  holder_id: item.holder_id,
914
957
  resources_code,
915
958
  timeSlots: recordTimeSlots,
@@ -929,7 +972,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
929
972
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
930
973
  resources: [
931
974
  ...(item._origin.resources || []).filter(
932
- (existingRes) => existingRes.form_id !== res.selectedResource.form_id
975
+ (existingRes) => {
976
+ var _a3;
977
+ return existingRes.form_id !== ((_a3 = res.selectedResource) == null ? void 0 : _a3.form_id);
978
+ }
933
979
  ),
934
980
  res.selectedResource
935
981
  ]
@@ -1156,6 +1202,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1156
1202
  });
1157
1203
  });
1158
1204
  const newScheduleArr = Object.values(newSchedule);
1205
+ newScheduleArr.sort((a, b) => {
1206
+ return (0, import_dayjs.default)(a.date).diff((0, import_dayjs.default)(b.date));
1207
+ });
1159
1208
  return newScheduleArr;
1160
1209
  }
1161
1210
  // 打开某个商品详情的弹窗,OS 层这边会记录当前选中的商品,适用于 session 类商品预约
@@ -1228,10 +1277,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1228
1277
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1229
1278
  let count = 0;
1230
1279
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1231
- debugger;
1232
1280
  let currentResourcesCount = 0;
1233
1281
  const currentResourcesTimeSlotCanUsedArr = [];
1234
- m.times.forEach((childTiem) => {
1282
+ const mTimes = m.times.filter((n) => {
1283
+ 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));
1284
+ });
1285
+ if (mTimes.length === 0) {
1286
+ return;
1287
+ }
1288
+ mTimes.forEach((childTiem) => {
1235
1289
  const res = (0, import_resources.getIsUsableByTimeItem)({
1236
1290
  timeSlice: {
1237
1291
  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.76",
4
+ "version": "0.0.78",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",