@pisell/pisellos 0.0.57 → 0.0.58

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.
@@ -146,17 +146,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
146
146
  resources: any[];
147
147
  currentResourceId: number;
148
148
  }): TimeSliceItem[];
149
- autoSelectResource({ resourceProductData, resources, timeSlots, }: {
150
- resourceProductData: any;
151
- resources: any[];
152
- timeSlots?: TimeSliceItem;
153
- }): {
154
- selectedResource: any;
155
- timeSlots?: undefined;
156
- } | {
157
- timeSlots: any[];
158
- selectedResource: any;
159
- } | undefined;
160
149
  autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap, capacity, }: {
161
150
  holder_id: string;
162
151
  resources_code: string | number;
@@ -1139,6 +1139,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1139
1139
  if (cartItem._origin.start_time) {
1140
1140
  var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
1141
1141
  var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
1142
+ // 资源排下序,把单个资源靠前,组合资源排在后面
1143
+ productResources.sort(function (a, b) {
1144
+ var _a$metadata, _b$metadata;
1145
+ var aIsCombined = ((_a$metadata = a.metadata) === null || _a$metadata === void 0 || (_a$metadata = _a$metadata.combined_resource) === null || _a$metadata === void 0 ? void 0 : _a$metadata.status) === 1;
1146
+ var bIsCombined = ((_b$metadata = b.metadata) === null || _b$metadata === void 0 || (_b$metadata = _b$metadata.combined_resource) === null || _b$metadata === void 0 ? void 0 : _b$metadata.status) === 1;
1147
+ if (aIsCombined && !bIsCombined) return 1;
1148
+ if (!aIsCombined && bIsCombined) return -1;
1149
+ return 0;
1150
+ });
1151
+ var resourcesUseableMap = {};
1142
1152
  productResources.forEach(function (n) {
1143
1153
  n.renderList = n.renderList.filter(function (m) {
1144
1154
  var recordCount = capacityMap[m.id] || 0;
@@ -1152,8 +1162,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1152
1162
  },
1153
1163
  time: item,
1154
1164
  resource: m,
1155
- currentCount: recordCount + (currentCapacity || 0)
1165
+ currentCount: recordCount + (currentCapacity || 0),
1166
+ resourcesUseableMap: resourcesUseableMap
1156
1167
  });
1168
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false) {
1169
+ resourcesUseableMap[m.id] = res.usable;
1170
+ }
1157
1171
  return res.usable;
1158
1172
  });
1159
1173
  return canUseTime;
@@ -1241,87 +1255,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1241
1255
  return timeSlots;
1242
1256
  }
1243
1257
 
1244
- // 自动分派可用的资源-单种资源类型——此方法目前未使用,未经验证
1245
- }, {
1246
- key: "autoSelectResource",
1247
- value: function autoSelectResource(_ref8) {
1248
- var resourceProductData = _ref8.resourceProductData,
1249
- resources = _ref8.resources,
1250
- timeSlots = _ref8.timeSlots;
1251
- var dateRange = this.store.date.getDateRange();
1252
- if (timeSlots) {
1253
- // 如果 start_time 存在,则直接根据 start_time 算出商品总共需要的时长,然后根据时长去匹配资源
1254
- // const duration = resourceProductData.product.duration.value;
1255
- // const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1256
- // const end_time = dayjs(`${dateRange[0].date} ${start_time}`)
1257
- // .add(duration, resourceProductData.product.duration.type)
1258
- // .format("HH:mm");
1259
- // 根据 start_time 和 end_time 去匹配资源
1260
- var targetResource = null;
1261
- var _iterator2 = _createForOfIteratorHelper(resources),
1262
- _step2;
1263
- try {
1264
- var _loop = function _loop() {
1265
- var n = _step2.value;
1266
- var canUseTime = n.times.find(function (item) {
1267
- var res = getIsUsableByTimeItem({
1268
- timeSlice: timeSlots,
1269
- time: item,
1270
- resource: n,
1271
- currentCount: 1
1272
- });
1273
- return res.usable;
1274
- });
1275
- if (canUseTime) {
1276
- targetResource = n;
1277
- return 1; // break
1278
- }
1279
- };
1280
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1281
- if (_loop()) break;
1282
- }
1283
- } catch (err) {
1284
- _iterator2.e(err);
1285
- } finally {
1286
- _iterator2.f();
1287
- }
1288
- return {
1289
- selectedResource: targetResource
1290
- };
1291
- } else {
1292
- // 如果没有传递 timeSlots,证明是第一个资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1293
- var duration = resourceProductData.product.duration.value;
1294
- var resourcesMap = getResourcesMap(resources);
1295
- var resourceIds = resources.map(function (n) {
1296
- return n.id;
1297
- });
1298
- var _timeSlots = getTimeSlicesByResources({
1299
- resourceIds: resourceIds,
1300
- resourcesMap: resourcesMap,
1301
- duration: duration,
1302
- currentDate: dateRange[0].date,
1303
- split: 10
1304
- });
1305
- // 如果timeSlots返回了 空数组,代表没有可用的资源了
1306
- if (!_timeSlots) {
1307
- return; // 给一个提示?
1308
- }
1309
- return {
1310
- timeSlots: _timeSlots,
1311
- selectedResource: resources[0]
1312
- };
1313
- }
1314
- }
1315
-
1316
1258
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
1317
1259
  }, {
1318
1260
  key: "autoSelectAccountResources",
1319
- value: function autoSelectAccountResources(_ref9) {
1320
- var holder_id = _ref9.holder_id,
1321
- resources_code = _ref9.resources_code,
1322
- timeSlots = _ref9.timeSlots,
1323
- countMap = _ref9.countMap,
1324
- capacity = _ref9.capacity;
1261
+ value: function autoSelectAccountResources(_ref8) {
1262
+ var holder_id = _ref8.holder_id,
1263
+ resources_code = _ref8.resources_code,
1264
+ timeSlots = _ref8.timeSlots,
1265
+ countMap = _ref8.countMap,
1266
+ capacity = _ref8.capacity;
1325
1267
  var dateRange = this.store.date.getDateRange();
1326
1268
  var cartItems = this.store.cart.getItems();
1327
1269
  // 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
@@ -1349,6 +1291,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1349
1291
  }
1350
1292
  });
1351
1293
  });
1294
+ // 资源排下序,把单个资源靠前,组合资源排在后面
1295
+ resources.sort(function (a, b) {
1296
+ var _a$metadata2, _b$metadata2;
1297
+ var aIsCombined = ((_a$metadata2 = a.metadata) === null || _a$metadata2 === void 0 || (_a$metadata2 = _a$metadata2.combined_resource) === null || _a$metadata2 === void 0 ? void 0 : _a$metadata2.status) === 1;
1298
+ var bIsCombined = ((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 || (_b$metadata2 = _b$metadata2.combined_resource) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.status) === 1;
1299
+ if (aIsCombined && !bIsCombined) return 1;
1300
+ if (!aIsCombined && bIsCombined) return -1;
1301
+ return 0;
1302
+ });
1303
+ var resourcesUseableMap = {};
1352
1304
 
1353
1305
  // 如果有选择时间了,则代表不是第一种资源了,则需要根据开始时间去匹配
1354
1306
  // 每个商品
@@ -1359,19 +1311,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1359
1311
  // .format("HH:mm");
1360
1312
  // 根据 start_time 和 end_time 去匹配资源
1361
1313
  var targetResource = null;
1362
- var _iterator3 = _createForOfIteratorHelper(resources),
1363
- _step3;
1314
+ var _iterator2 = _createForOfIteratorHelper(resources),
1315
+ _step2;
1364
1316
  try {
1365
- var _loop2 = function _loop2() {
1366
- var n = _step3.value;
1317
+ var _loop = function _loop() {
1318
+ var n = _step2.value;
1367
1319
  var recordCount = countMap[n.id] || 0;
1368
1320
  var canUseTime = n.times.find(function (item) {
1369
1321
  var res = getIsUsableByTimeItem({
1370
1322
  timeSlice: timeSlots,
1371
1323
  time: item,
1372
1324
  resource: n,
1373
- currentCount: recordCount + (capacity || 0)
1325
+ currentCount: recordCount + (capacity || 0),
1326
+ resourcesUseableMap: {}
1374
1327
  });
1328
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false) {
1329
+ resourcesUseableMap[n.id] = res.usable;
1330
+ }
1375
1331
  return res.usable;
1376
1332
  });
1377
1333
  if (canUseTime) {
@@ -1379,13 +1335,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1379
1335
  return 1; // break
1380
1336
  }
1381
1337
  };
1382
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1383
- if (_loop2()) break;
1338
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1339
+ if (_loop()) break;
1384
1340
  }
1385
1341
  } catch (err) {
1386
- _iterator3.e(err);
1342
+ _iterator2.e(err);
1387
1343
  } finally {
1388
- _iterator3.f();
1344
+ _iterator2.f();
1389
1345
  }
1390
1346
  return {
1391
1347
  selectedResource: targetResource
@@ -1395,20 +1351,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1395
1351
  var resourceIds = resources.map(function (n) {
1396
1352
  return n.id;
1397
1353
  });
1398
- var _timeSlots2 = getTimeSlicesByResources({
1354
+ var _timeSlots = getTimeSlicesByResources({
1399
1355
  resourceIds: resourceIds,
1400
1356
  resourcesMap: resourcesMap,
1401
1357
  duration: duration,
1402
1358
  currentDate: dateRange[0].date,
1403
1359
  split: 10,
1404
- capacity: capacity
1360
+ capacity: capacity,
1361
+ resourcesUseableMap: resourcesUseableMap
1405
1362
  });
1406
1363
  // 如果timeSlots返回了 空数组,代表没有可用的资源了
1407
- if (!_timeSlots2) {
1364
+ if (!_timeSlots) {
1408
1365
  return; // 给一个提示?
1409
1366
  }
1410
1367
  return {
1411
- timeSlots: _timeSlots2,
1368
+ timeSlots: _timeSlots,
1412
1369
  selectedResource: resources[0]
1413
1370
  };
1414
1371
  }
@@ -1458,9 +1415,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1458
1415
  }
1459
1416
  if (recordTimeSlots) {
1460
1417
  if (index !== 0 && recordTimeSlots) {
1461
- var _item$_productOrigin$, _item$_productOrigin4, _ref10, _item$_productOrigin5, _item$_productOrigin$2, _item$_productOrigin6, _ref11, _item$_productOrigin7;
1462
- 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, (_ref10 = (_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 && _ref10 !== void 0 ? _ref10 : 'minutes');
1463
- 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, (_ref11 = (_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 && _ref11 !== void 0 ? _ref11 : 'minutes');
1418
+ var _item$_productOrigin$, _item$_productOrigin4, _ref9, _item$_productOrigin5, _item$_productOrigin$2, _item$_productOrigin6, _ref10, _item$_productOrigin7;
1419
+ 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');
1420
+ 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');
1464
1421
  recordTimeSlots = {
1465
1422
  start_time: start_at.format('HH:mm'),
1466
1423
  end_time: end_at.format('HH:mm'),
@@ -1616,12 +1573,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1616
1573
  weekNum: 0
1617
1574
  }];
1618
1575
  }
1576
+ var resourcesUseableMap = {};
1619
1577
  var timeSlots = getTimeSlicesByResources({
1620
1578
  resourceIds: resourceIds,
1621
1579
  resourcesMap: resourcesMap,
1622
1580
  duration: duration,
1623
1581
  currentDate: dateRange[0].date,
1624
- split: 10
1582
+ split: 10,
1583
+ resourcesUseableMap: resourcesUseableMap
1625
1584
  });
1626
1585
  return timeSlots;
1627
1586
  }
@@ -1650,9 +1609,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1650
1609
  accountItems.forEach(function (item, index) {
1651
1610
  var newResources = cloneDeep(item._origin.resources);
1652
1611
  newResources.forEach(function (resource) {
1653
- var _item$_productOrigin$4, _item$_productOrigin11, _ref12, _item$_productOrigin12;
1612
+ var _item$_productOrigin$4, _item$_productOrigin11, _ref11, _item$_productOrigin12;
1654
1613
  resource.startTime = currentStartTime;
1655
- 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, (_ref12 = (_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 && _ref12 !== void 0 ? _ref12 : 'minutes').format('YYYY-MM-DD HH:mm');
1614
+ 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');
1656
1615
  delete resource.times;
1657
1616
  });
1658
1617
  _this9.store.cart.updateItem({
@@ -1734,11 +1693,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1734
1693
  }
1735
1694
  }, {
1736
1695
  key: "getTimeslotBySchedule",
1737
- value: function getTimeslotBySchedule(_ref13) {
1696
+ value: function getTimeslotBySchedule(_ref12) {
1738
1697
  var _this$store$currentPr2;
1739
- var date = _ref13.date,
1740
- scheduleIds = _ref13.scheduleIds,
1741
- resources = _ref13.resources;
1698
+ var date = _ref12.date,
1699
+ scheduleIds = _ref12.scheduleIds,
1700
+ resources = _ref12.resources;
1742
1701
  var targetProduct = this.store.currentProduct;
1743
1702
  var targetProductData = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData();
1744
1703
  var targetSchedules = [];
@@ -1763,6 +1722,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1763
1722
  var allProductResources = productResources.flatMap(function (n) {
1764
1723
  return n.renderList;
1765
1724
  });
1725
+ // 资源排下序,把单个资源靠前,组合资源排在后面
1726
+ allProductResources.sort(function (a, b) {
1727
+ var _a$metadata3, _b$metadata3;
1728
+ var aIsCombined = ((_a$metadata3 = a.metadata) === null || _a$metadata3 === void 0 || (_a$metadata3 = _a$metadata3.combined_resource) === null || _a$metadata3 === void 0 ? void 0 : _a$metadata3.status) === 1;
1729
+ var bIsCombined = ((_b$metadata3 = b.metadata) === null || _b$metadata3 === void 0 || (_b$metadata3 = _b$metadata3.combined_resource) === null || _b$metadata3 === void 0 ? void 0 : _b$metadata3.status) === 1;
1730
+ if (aIsCombined && !bIsCombined) return 1;
1731
+ if (!aIsCombined && bIsCombined) return -1;
1732
+ return 0;
1733
+ });
1734
+ var resourcesUseableMap = {};
1766
1735
  // 计算每个日程切片下日程可用的资源的容量总和
1767
1736
  var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
1768
1737
  var count = 0;
@@ -1780,8 +1749,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1780
1749
  },
1781
1750
  time: childTiem,
1782
1751
  resource: m,
1783
- currentCount: 1
1752
+ currentCount: 1,
1753
+ resourcesUseableMap: resourcesUseableMap
1784
1754
  });
1755
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false) {
1756
+ resourcesUseableMap[m.id] = res.usable;
1757
+ }
1785
1758
  // 如果资源可用,且是独占资源,remainingCapacity 始终为 1
1786
1759
  if (res.usable && res.remainingCapacity >= count) {
1787
1760
  count = res.remainingCapacity;
@@ -1802,16 +1775,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1802
1775
  }
1803
1776
  }, {
1804
1777
  key: "addProductToCart",
1805
- value: function addProductToCart(_ref14) {
1778
+ value: function addProductToCart(_ref13) {
1806
1779
  var _this10 = this;
1807
- var product = _ref14.product,
1808
- date = _ref14.date,
1809
- account = _ref14.account;
1810
- var _ref15 = product || {},
1811
- bundle = _ref15.bundle,
1812
- options = _ref15.options,
1813
- origin = _ref15.origin,
1814
- product_variant_id = _ref15.product_variant_id;
1780
+ var product = _ref13.product,
1781
+ date = _ref13.date,
1782
+ account = _ref13.account;
1783
+ var _ref14 = product || {},
1784
+ bundle = _ref14.bundle,
1785
+ options = _ref14.options,
1786
+ origin = _ref14.origin,
1787
+ product_variant_id = _ref14.product_variant_id;
1815
1788
  var productData = _objectSpread(_objectSpread({}, origin), {}, {
1816
1789
  product_variant_id: product_variant_id
1817
1790
  });
@@ -27,11 +27,12 @@ interface BookingItem {
27
27
  * @return {*}
28
28
  * @Author: zhiwei.Wang
29
29
  */
30
- export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount, }: {
30
+ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount, resourcesUseableMap }: {
31
31
  timeSlice: TimeSliceItem;
32
32
  time: any;
33
33
  resource: ResourceItem;
34
34
  currentCount: number;
35
+ resourcesUseableMap: Record<string, boolean>;
35
36
  }) => {
36
37
  afterToDay: boolean;
37
38
  capacity: boolean;
@@ -67,12 +68,13 @@ export declare const formatResources: ({ booking, resources, }: {
67
68
  * @return {*}
68
69
  * @Author: zhiwei.Wang
69
70
  */
70
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, }: {
71
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, }: {
71
72
  resource: ResourceItem;
72
73
  duration: number;
73
74
  split: number;
74
75
  currentDate: DateType | string;
75
76
  capacity?: number | undefined;
77
+ resourcesUseableMap?: Record<string, boolean> | undefined;
76
78
  }) => TimeSliceItem[];
77
79
  /**
78
80
  * @title: 获取时间切片列表的交集
@@ -101,13 +103,14 @@ export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceIt
101
103
  * @return {*}
102
104
  * @Author: zhiwei.Wang
103
105
  */
104
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, }: {
106
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, }: {
105
107
  resourceIds: number[];
106
108
  resourcesMap: any;
107
109
  duration: number;
108
110
  currentDate: DateType | string;
109
111
  split: number;
110
112
  capacity?: number | undefined;
113
+ resourcesUseableMap: Record<string, boolean>;
111
114
  }) => any[];
112
115
  /**
113
116
  * @title: 获取其他人的已选资源
@@ -167,11 +167,14 @@ var checkCapacity = function checkCapacity(_ref) {
167
167
  * @Author: zhiwei.Wang
168
168
  */
169
169
  export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
170
+ var _resource$combined_re;
170
171
  var timeSlice = _ref2.timeSlice,
171
172
  time = _ref2.time,
172
173
  resource = _ref2.resource,
173
174
  _ref2$currentCount = _ref2.currentCount,
174
- currentCount = _ref2$currentCount === void 0 ? 1 : _ref2$currentCount;
175
+ currentCount = _ref2$currentCount === void 0 ? 1 : _ref2$currentCount,
176
+ _ref2$resourcesUseabl = _ref2.resourcesUseableMap,
177
+ resourcesUseableMap = _ref2$resourcesUseabl === void 0 ? {} : _ref2$resourcesUseabl;
175
178
  var status = {
176
179
  afterToDay: false,
177
180
  capacity: false,
@@ -180,7 +183,6 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
180
183
  };
181
184
  // 最早可预约时间为 当前日期之后并且提前量之后
182
185
  var earliest = dayjs();
183
-
184
186
  // 不可预约提前量时间之前的
185
187
  if (!checkAfterToDay(timeSlice.start_at, earliest)) {
186
188
  return status;
@@ -192,6 +194,16 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
192
194
  resource: resource,
193
195
  currentCount: currentCount
194
196
  });
197
+ if ((_resource$combined_re = resource.combined_resource) !== null && _resource$combined_re !== void 0 && _resource$combined_re.status) {
198
+ // 组合资源中子资源是否可用
199
+ var resourceIds = resource.combined_resource.resource_ids;
200
+ resourceIds.forEach(function (id) {
201
+ // 只要有一个子资源不可用,整个组合资源都不可用
202
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[id]) === false) {
203
+ checkCapacityResult.status = false;
204
+ }
205
+ });
206
+ }
195
207
  if (!checkCapacityResult.status) {
196
208
  return status;
197
209
  }
@@ -341,7 +353,9 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref4) {
341
353
  split = _ref4$split === void 0 ? 10 : _ref4$split,
342
354
  _ref4$currentDate = _ref4.currentDate,
343
355
  currentDate = _ref4$currentDate === void 0 ? dayjs() : _ref4$currentDate,
344
- capacity = _ref4.capacity;
356
+ capacity = _ref4.capacity,
357
+ _ref4$resourcesUseabl = _ref4.resourcesUseableMap,
358
+ resourcesUseableMap = _ref4$resourcesUseabl === void 0 ? {} : _ref4$resourcesUseabl;
345
359
  var times = resource.times;
346
360
 
347
361
  // 存储所有时间切片
@@ -378,8 +392,12 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref4) {
378
392
  timeSlice: timeSlice,
379
393
  time: time,
380
394
  resource: resource,
381
- currentCount: capacity || 1
395
+ currentCount: capacity || 1,
396
+ resourcesUseableMap: resourcesUseableMap
382
397
  });
398
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[resource.id]) !== false) {
399
+ resourcesUseableMap[resource.id] = _status.usable;
400
+ }
383
401
  if (_status.usable) {
384
402
  // 添加时间切片 09:00 ~ 10:00 09:20 ~ 10:20 09:00 ~ 10:00 09:20 ~ 10:20 11:00 ~ 12:00 11:20 ~ 12:20
385
403
  timeSlices.push(_objectSpread(_objectSpread({}, timeSlice), {}, {
@@ -453,7 +471,8 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref5) {
453
471
  duration = _ref5.duration,
454
472
  currentDate = _ref5.currentDate,
455
473
  split = _ref5.split,
456
- capacity = _ref5.capacity;
474
+ capacity = _ref5.capacity,
475
+ resourcesUseableMap = _ref5.resourcesUseableMap;
457
476
  // 获取资源列表
458
477
  var resources = getResourcesByIds(resourcesMap, resourceIds);
459
478
 
@@ -464,7 +483,8 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref5) {
464
483
  duration: duration,
465
484
  split: split,
466
485
  currentDate: currentDate,
467
- capacity: capacity
486
+ capacity: capacity,
487
+ resourcesUseableMap: resourcesUseableMap
468
488
  }));
469
489
  }, []);
470
490
 
@@ -146,17 +146,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
146
146
  resources: any[];
147
147
  currentResourceId: number;
148
148
  }): TimeSliceItem[];
149
- autoSelectResource({ resourceProductData, resources, timeSlots, }: {
150
- resourceProductData: any;
151
- resources: any[];
152
- timeSlots?: TimeSliceItem;
153
- }): {
154
- selectedResource: any;
155
- timeSlots?: undefined;
156
- } | {
157
- timeSlots: any[];
158
- selectedResource: any;
159
- } | undefined;
160
149
  autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap, capacity, }: {
161
150
  holder_id: string;
162
151
  resources_code: string | number;
@@ -184,7 +184,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
184
184
  product_ids
185
185
  }) {
186
186
  const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
187
- this.setDateRange([{ date, status: "available", week: "", weekNum: 0 }, { date, status: "available", week: "", weekNum: 0 }]);
187
+ this.setDateRange([
188
+ { date, status: "available", week: "", weekNum: 0 },
189
+ { date, status: "available", week: "", weekNum: 0 }
190
+ ]);
188
191
  const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
189
192
  return await this.loadProducts({ schedule_ids: scheduleIds, product_ids });
190
193
  }
@@ -598,6 +601,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
598
601
  const endTime = (0, import_dayjs.default)(
599
602
  `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
600
603
  );
604
+ productResources.sort((a, b) => {
605
+ var _a2, _b2, _c2, _d;
606
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
607
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
608
+ if (aIsCombined && !bIsCombined)
609
+ return 1;
610
+ if (!aIsCombined && bIsCombined)
611
+ return -1;
612
+ return 0;
613
+ });
614
+ const resourcesUseableMap = {};
601
615
  productResources.forEach((n) => {
602
616
  n.renderList = n.renderList.filter((m) => {
603
617
  const recordCount = capacityMap[m.id] || 0;
@@ -611,8 +625,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
611
625
  },
612
626
  time: item,
613
627
  resource: m,
614
- currentCount: recordCount + (currentCapacity || 0)
628
+ currentCount: recordCount + (currentCapacity || 0),
629
+ resourcesUseableMap
615
630
  });
631
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
632
+ resourcesUseableMap[m.id] = res.usable;
633
+ }
616
634
  return res.usable;
617
635
  });
618
636
  return canUseTime;
@@ -700,53 +718,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
700
718
  });
701
719
  return timeSlots;
702
720
  }
703
- // 自动分派可用的资源-单种资源类型——此方法目前未使用,未经验证
704
- autoSelectResource({
705
- resourceProductData,
706
- resources,
707
- timeSlots
708
- }) {
709
- const dateRange = this.store.date.getDateRange();
710
- if (timeSlots) {
711
- let targetResource = null;
712
- for (const n of resources) {
713
- const canUseTime = n.times.find((item) => {
714
- const res = (0, import_resources.getIsUsableByTimeItem)({
715
- timeSlice: timeSlots,
716
- time: item,
717
- resource: n,
718
- currentCount: 1
719
- });
720
- return res.usable;
721
- });
722
- if (canUseTime) {
723
- targetResource = n;
724
- break;
725
- }
726
- }
727
- return {
728
- selectedResource: targetResource
729
- };
730
- } else {
731
- const duration = resourceProductData.product.duration.value;
732
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
733
- const resourceIds = resources.map((n) => n.id);
734
- const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
735
- resourceIds,
736
- resourcesMap,
737
- duration,
738
- currentDate: dateRange[0].date,
739
- split: 10
740
- });
741
- if (!timeSlots2) {
742
- return;
743
- }
744
- return {
745
- timeSlots: timeSlots2,
746
- selectedResource: resources[0]
747
- };
748
- }
749
- }
750
721
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
751
722
  autoSelectAccountResources({
752
723
  holder_id,
@@ -765,7 +736,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
765
736
  var _a, _b;
766
737
  return acc + (((_b = (_a = n._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0);
767
738
  }, 0);
768
- const resources = [];
739
+ let resources = [];
769
740
  accountCartItems.forEach((item) => {
770
741
  var _a, _b, _c;
771
742
  (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
@@ -774,6 +745,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
774
745
  }
775
746
  });
776
747
  });
748
+ resources.sort((a, b) => {
749
+ var _a, _b, _c, _d;
750
+ const aIsCombined = ((_b = (_a = a.metadata) == null ? void 0 : _a.combined_resource) == null ? void 0 : _b.status) === 1;
751
+ const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
752
+ if (aIsCombined && !bIsCombined)
753
+ return 1;
754
+ if (!aIsCombined && bIsCombined)
755
+ return -1;
756
+ return 0;
757
+ });
758
+ const resourcesUseableMap = {};
777
759
  if (timeSlots) {
778
760
  let targetResource = null;
779
761
  for (const n of resources) {
@@ -783,8 +765,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
783
765
  timeSlice: timeSlots,
784
766
  time: item,
785
767
  resource: n,
786
- currentCount: recordCount + (capacity || 0)
768
+ currentCount: recordCount + (capacity || 0),
769
+ resourcesUseableMap: {}
787
770
  });
771
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[n.id]) !== false) {
772
+ resourcesUseableMap[n.id] = res.usable;
773
+ }
788
774
  return res.usable;
789
775
  });
790
776
  if (canUseTime) {
@@ -804,7 +790,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
804
790
  duration,
805
791
  currentDate: dateRange[0].date,
806
792
  split: 10,
807
- capacity
793
+ capacity,
794
+ resourcesUseableMap
808
795
  });
809
796
  if (!timeSlots2) {
810
797
  return;
@@ -1007,26 +994,31 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1007
994
  }
1008
995
  ];
1009
996
  }
997
+ const resourcesUseableMap = {};
1010
998
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1011
999
  resourceIds,
1012
1000
  resourcesMap,
1013
1001
  duration,
1014
1002
  currentDate: dateRange[0].date,
1015
- split: 10
1003
+ split: 10,
1004
+ resourcesUseableMap
1016
1005
  });
1017
1006
  return timeSlots;
1018
1007
  }
1019
1008
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车
1020
1009
  submitTimeSlot(timeSlots) {
1021
1010
  const cartItems = this.store.cart.getItems();
1022
- const itemsByAccount = cartItems.reduce((acc, item) => {
1023
- const holderId = item.holder_id;
1024
- if (!acc[holderId]) {
1025
- acc[holderId] = [];
1026
- }
1027
- acc[holderId].push(item);
1028
- return acc;
1029
- }, {});
1011
+ const itemsByAccount = cartItems.reduce(
1012
+ (acc, item) => {
1013
+ const holderId = item.holder_id;
1014
+ if (!acc[holderId]) {
1015
+ acc[holderId] = [];
1016
+ }
1017
+ acc[holderId].push(item);
1018
+ return acc;
1019
+ },
1020
+ {}
1021
+ );
1030
1022
  Object.values(itemsByAccount).forEach((accountItems) => {
1031
1023
  let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1032
1024
  accountItems.forEach((item, index) => {
@@ -1129,7 +1121,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1129
1121
  );
1130
1122
  const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1131
1123
  console.log("scheduleTimeSlots:", scheduleTimeSlots, productResources);
1132
- const allProductResources = productResources.flatMap((n) => n.renderList);
1124
+ let allProductResources = productResources.flatMap((n) => n.renderList);
1125
+ allProductResources.sort((a, b) => {
1126
+ var _a2, _b2, _c2, _d;
1127
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1128
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1129
+ if (aIsCombined && !bIsCombined)
1130
+ return 1;
1131
+ if (!aIsCombined && bIsCombined)
1132
+ return -1;
1133
+ return 0;
1134
+ });
1135
+ const resourcesUseableMap = {};
1133
1136
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1134
1137
  let count = 0;
1135
1138
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
@@ -1143,8 +1146,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1143
1146
  },
1144
1147
  time: childTiem,
1145
1148
  resource: m,
1146
- currentCount: 1
1149
+ currentCount: 1,
1150
+ resourcesUseableMap
1147
1151
  });
1152
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
1153
+ resourcesUseableMap[m.id] = res.usable;
1154
+ }
1148
1155
  if (res.usable && res.remainingCapacity >= count) {
1149
1156
  count = res.remainingCapacity;
1150
1157
  }
@@ -27,11 +27,12 @@ interface BookingItem {
27
27
  * @return {*}
28
28
  * @Author: zhiwei.Wang
29
29
  */
30
- export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount, }: {
30
+ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount, resourcesUseableMap }: {
31
31
  timeSlice: TimeSliceItem;
32
32
  time: any;
33
33
  resource: ResourceItem;
34
34
  currentCount: number;
35
+ resourcesUseableMap: Record<string, boolean>;
35
36
  }) => {
36
37
  afterToDay: boolean;
37
38
  capacity: boolean;
@@ -67,12 +68,13 @@ export declare const formatResources: ({ booking, resources, }: {
67
68
  * @return {*}
68
69
  * @Author: zhiwei.Wang
69
70
  */
70
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, }: {
71
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, }: {
71
72
  resource: ResourceItem;
72
73
  duration: number;
73
74
  split: number;
74
75
  currentDate: DateType | string;
75
76
  capacity?: number | undefined;
77
+ resourcesUseableMap?: Record<string, boolean> | undefined;
76
78
  }) => TimeSliceItem[];
77
79
  /**
78
80
  * @title: 获取时间切片列表的交集
@@ -101,13 +103,14 @@ export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceIt
101
103
  * @return {*}
102
104
  * @Author: zhiwei.Wang
103
105
  */
104
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, }: {
106
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, }: {
105
107
  resourceIds: number[];
106
108
  resourcesMap: any;
107
109
  duration: number;
108
110
  currentDate: DateType | string;
109
111
  split: number;
110
112
  capacity?: number | undefined;
113
+ resourcesUseableMap: Record<string, boolean>;
111
114
  }) => any[];
112
115
  /**
113
116
  * @title: 获取其他人的已选资源
@@ -124,8 +124,10 @@ var getIsUsableByTimeItem = ({
124
124
  timeSlice,
125
125
  time,
126
126
  resource,
127
- currentCount = 1
127
+ currentCount = 1,
128
+ resourcesUseableMap = {}
128
129
  }) => {
130
+ var _a;
129
131
  let status = {
130
132
  afterToDay: false,
131
133
  capacity: false,
@@ -144,6 +146,14 @@ var getIsUsableByTimeItem = ({
144
146
  resource,
145
147
  currentCount
146
148
  });
149
+ if ((_a = resource.combined_resource) == null ? void 0 : _a.status) {
150
+ const resourceIds = resource.combined_resource.resource_ids;
151
+ resourceIds.forEach((id) => {
152
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[id]) === false) {
153
+ checkCapacityResult.status = false;
154
+ }
155
+ });
156
+ }
147
157
  if (!checkCapacityResult.status) {
148
158
  return status;
149
159
  }
@@ -264,7 +274,8 @@ var getTimeSlicesByResource = ({
264
274
  duration,
265
275
  split = 10,
266
276
  currentDate = (0, import_dayjs.default)(),
267
- capacity
277
+ capacity,
278
+ resourcesUseableMap = {}
268
279
  }) => {
269
280
  const { times } = resource;
270
281
  const timeSlices = [];
@@ -288,8 +299,12 @@ var getTimeSlicesByResource = ({
288
299
  timeSlice,
289
300
  time,
290
301
  resource,
291
- currentCount: capacity || 1
302
+ currentCount: capacity || 1,
303
+ resourcesUseableMap
292
304
  });
305
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[resource.id]) !== false) {
306
+ resourcesUseableMap[resource.id] = _status.usable;
307
+ }
293
308
  if (_status.usable) {
294
309
  timeSlices.push({
295
310
  ...timeSlice,
@@ -326,7 +341,8 @@ var getTimeSlicesByResources = ({
326
341
  duration,
327
342
  currentDate,
328
343
  split,
329
- capacity
344
+ capacity,
345
+ resourcesUseableMap
330
346
  }) => {
331
347
  let resources = getResourcesByIds(resourcesMap, resourceIds);
332
348
  let timeSliceList = resources.reduce(
@@ -337,7 +353,8 @@ var getTimeSlicesByResources = ({
337
353
  duration,
338
354
  split,
339
355
  currentDate,
340
- capacity
356
+ capacity,
357
+ resourcesUseableMap
341
358
  })
342
359
  );
343
360
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.57",
4
+ "version": "0.0.58",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",