@pisell/pisellos 0.0.54 → 0.0.56

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.
@@ -176,6 +176,8 @@ export interface IUpdateItemParams {
176
176
  quantity?: number;
177
177
  /** 资源 */
178
178
  resources?: Resource[];
179
+ /** 元数据 */
180
+ metadata?: any;
179
181
  /** 备注 */
180
182
  note?: string;
181
183
  /** 日期 */
@@ -132,7 +132,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
132
132
  case 5:
133
133
  // 1.生成当前月份的所有日期,默认都是可用的
134
134
  dates = generateMonthDates(start_date, end_date, type); // 如果没有资源或者结束日期在今天之前,则所有日期均不可用
135
- if (!(!(resource_ids !== null && resource_ids !== void 0 && resource_ids.length) || dayjs(end_date).isBefore(dayjs()))) {
135
+ if (!(!(resource_ids !== null && resource_ids !== void 0 && resource_ids.length) || dayjs(end_date).isBefore(dayjs().startOf('day')))) {
136
136
  _context3.next = 8;
137
137
  break;
138
138
  }
@@ -145,8 +145,6 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
145
145
  end_date: end_date,
146
146
  resource_ids: resource_ids,
147
147
  front_end_cache_id: this.cacheId
148
- }, {
149
- useCache: true
150
148
  });
151
149
  case 11:
152
150
  res = _context3.sent;
@@ -244,6 +244,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
244
244
  status: 'available',
245
245
  week: '',
246
246
  weekNum: 0
247
+ }, {
248
+ date: date,
249
+ status: 'available',
250
+ week: '',
251
+ weekNum: 0
247
252
  }]);
248
253
  scheduleIds = scheduleList.filter(function (n) {
249
254
  return n.date === date;
@@ -656,22 +661,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
656
661
  _schedule: this.store.currentProduct.getOtherParams()['schedule']
657
662
  })];
658
663
  }
659
- _context13.next = 8;
660
- return this.getDateRange();
661
- case 8:
662
- dateRange = _context13.sent;
664
+ dateRange = this.store.date.getDateRange();
663
665
  tempStartDate = startDate || (dateRange === null || dateRange === void 0 ? void 0 : dateRange[0].date);
664
- tempEndDate = endDate || (dateRange === null || dateRange === void 0 ? void 0 : dateRange[0].date);
666
+ tempEndDate = endDate || (dateRange === null || dateRange === void 0 ? void 0 : dateRange[1].date);
665
667
  if (tempProducts.length) {
666
- _context13.next = 13;
668
+ _context13.next = 11;
667
669
  break;
668
670
  }
669
671
  return _context13.abrupt("return", []);
670
- case 13:
672
+ case 11:
671
673
  // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
672
674
  _ref5 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref5.resourceIds, rules = _ref5.rules, resourcesMap = _ref5.resourcesMap;
673
675
  this.otherParams.currentResourcesMap = resourcesMap;
674
- _context13.next = 17;
676
+ _context13.next = 15;
675
677
  return this.store.date.getResourceDates({
676
678
  url: params.url,
677
679
  query: {
@@ -682,10 +684,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
682
684
  rules: rules,
683
685
  type: type
684
686
  });
685
- case 17:
687
+ case 15:
686
688
  res = _context13.sent;
687
689
  return _context13.abrupt("return", res);
688
- case 19:
690
+ case 17:
689
691
  case "end":
690
692
  return _context13.stop();
691
693
  }
@@ -876,6 +878,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
876
878
  cartItems = this.store.cart.getItems();
877
879
  newCartItems = cloneDeep(cartItems); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
878
880
  newCartItems.forEach(function (item) {
881
+ var _item$_productOrigin;
879
882
  item._origin.resources = item._origin.resources.map(function (n) {
880
883
  var newResourcesItem = cloneDeep(n);
881
884
  delete newResourcesItem.id;
@@ -883,6 +886,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
883
886
  delete newResourcesItem.resourceType;
884
887
  return _objectSpread({}, newResourcesItem);
885
888
  });
889
+ var formatCapacity = formatDefaultCapacitys({
890
+ capacity: (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.capacity,
891
+ product_bundle: item._origin.product.product_bundle
892
+ });
893
+ item._origin.metadata.capacity = formatCapacity;
886
894
  });
887
895
  return _context20.abrupt("return", this.store.order.submitOrder({
888
896
  query: {
@@ -990,8 +998,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
990
998
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(params._id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
991
999
  }
992
1000
  if (params.resources) {
1001
+ var _targetCartItem$_prod;
1002
+ var formatCapacity = formatDefaultCapacitys({
1003
+ capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
1004
+ product_bundle: targetCartItem._origin.product.product_bundle
1005
+ });
1006
+ var currentCapacity = getSumCapacity({
1007
+ capacity: formatCapacity
1008
+ });
993
1009
  params.resources = params.resources.map(function (n) {
994
- n.capacity = targetCartItem.num || 1;
1010
+ n.capacity = currentCapacity || 1;
995
1011
  checkSubResourcesCapacity(n);
996
1012
  return n;
997
1013
  });
@@ -1114,6 +1130,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1114
1130
  capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
1115
1131
  product_bundle: cartItem._origin.product.product_bundle
1116
1132
  });
1133
+ cartItem._origin.metadata.capacity = formatCapacity;
1117
1134
  var currentCapacity = getSumCapacity({
1118
1135
  capacity: formatCapacity
1119
1136
  });
@@ -1161,7 +1178,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1161
1178
  }, {
1162
1179
  key: "getResourcesListByCartItem",
1163
1180
  value: function getResourcesListByCartItem(id) {
1164
- var _targetCartItem$_prod, _targetCartItem$_prod2;
1181
+ var _targetCartItem$_prod2, _targetCartItem$_prod3;
1165
1182
  var cartItems = this.store.cart.getItems();
1166
1183
  var dateRange = this.store.date.getDateRange();
1167
1184
  var resources = [];
@@ -1184,13 +1201,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1184
1201
  selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1185
1202
  }
1186
1203
  var formatCapacity = formatDefaultCapacitys({
1187
- capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
1204
+ capacity: (_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.capacity,
1188
1205
  product_bundle: targetCartItem._origin.product.product_bundle
1189
1206
  });
1190
1207
  var currentCapacity = getSumCapacity({
1191
1208
  capacity: formatCapacity
1192
1209
  });
1193
- var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 || (_targetCartItem$_prod2 = _targetCartItem$_prod2.product_resource) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.resources) || [], selectedResources, currentCapacity);
1210
+ var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod3 = targetCartItem._productOrigin) === null || _targetCartItem$_prod3 === void 0 || (_targetCartItem$_prod3 = _targetCartItem$_prod3.product_resource) === null || _targetCartItem$_prod3 === void 0 ? void 0 : _targetCartItem$_prod3.resources) || [], selectedResources, currentCapacity);
1194
1211
  if (productResources) {
1195
1212
  return {
1196
1213
  id: targetCartItem.id,
@@ -1325,8 +1342,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1325
1342
  // 取出账号下所对应类型的所有的可用资源
1326
1343
  var resources = [];
1327
1344
  accountCartItems.forEach(function (item) {
1328
- var _item$_productOrigin;
1329
- (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 || (_item$_productOrigin = _item$_productOrigin.product_resource) === null || _item$_productOrigin === void 0 || (_item$_productOrigin = _item$_productOrigin.resources) === null || _item$_productOrigin === void 0 || _item$_productOrigin.forEach(function (n) {
1345
+ var _item$_productOrigin2;
1346
+ (_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) {
1330
1347
  if (n.code === resources_code) {
1331
1348
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1332
1349
  }
@@ -1422,9 +1439,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1422
1439
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1423
1440
 
1424
1441
  cartItems.forEach(function (item, index) {
1425
- var _item$_productOrigin2;
1442
+ var _item$_productOrigin3;
1426
1443
  var formatCapacity = formatDefaultCapacitys({
1427
- capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1444
+ capacity: (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.capacity,
1428
1445
  product_bundle: item._origin.product.product_bundle
1429
1446
  });
1430
1447
  var currentCapacity = getSumCapacity({
@@ -1441,9 +1458,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1441
1458
  }
1442
1459
  if (recordTimeSlots) {
1443
1460
  if (index !== 0 && recordTimeSlots) {
1444
- var _item$_productOrigin$, _item$_productOrigin3, _ref10, _item$_productOrigin4, _item$_productOrigin$2, _item$_productOrigin5, _ref11, _item$_productOrigin6;
1445
- 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, (_ref10 = (_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 && _ref10 !== void 0 ? _ref10 : 'minutes');
1446
- 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, (_ref11 = (_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 && _ref11 !== void 0 ? _ref11 : 'minutes');
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');
1447
1464
  recordTimeSlots = {
1448
1465
  start_time: start_at.format('HH:mm'),
1449
1466
  end_time: end_at.format('HH:mm'),
@@ -1483,7 +1500,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1483
1500
  errorList.push(item._id);
1484
1501
  }
1485
1502
  } else {
1486
- var _item$_productOrigin7, _productResources$fin;
1503
+ var _item$_productOrigin8, _productResources$fin;
1487
1504
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1488
1505
  var allCartItems = _this7.store.cart.getItems();
1489
1506
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
@@ -1493,7 +1510,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1493
1510
  } else {
1494
1511
  selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap);
1495
1512
  }
1496
- var productResources = getResourcesByProduct(resourcesMap, ((_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) || [], selectedResources, currentCapacity);
1513
+ var productResources = getResourcesByProduct(resourcesMap, ((_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) || [], selectedResources, currentCapacity);
1497
1514
  // 自动选择 productResources 中对应 resources_code 的资源
1498
1515
  var targetRenderList = (_productResources$fin = productResources.find(function (n) {
1499
1516
  return n.code === resources_code;
@@ -1547,11 +1564,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1547
1564
  // 取出购物车中所有一已选择的第一步资源
1548
1565
  var resources = [];
1549
1566
  var cartItems = this.store.cart.getItems();
1550
- if (cartItems !== null && cartItems !== void 0 && cartItems[0].start_date) return [];
1567
+ // if (cartItems?.[0].start_date) return [];
1551
1568
  var resourceIds = [];
1552
1569
  cartItems.forEach(function (item) {
1553
- var _item$_productOrigin8;
1554
- (_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) {
1570
+ var _item$_productOrigin9;
1571
+ (_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) {
1555
1572
  if (n.code === resources_code) {
1556
1573
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1557
1574
  }
@@ -1566,17 +1583,39 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1566
1583
  var resourcesMap = getResourcesMap(resources);
1567
1584
  var duration = 0;
1568
1585
  // duration = 不同账号的最长时间
1569
- this.store.accountList.getAccounts().forEach(function (account) {
1586
+ var accountList = this.store.accountList.getAccounts();
1587
+ var checkDuration = function checkDuration(cartItems) {
1570
1588
  var accountDuration = 0;
1571
- var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1572
1589
  cartItems.forEach(function (item) {
1573
- var _item$_productOrigin$3, _item$_productOrigin9;
1574
- accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.duration) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1590
+ var _item$_productOrigin$3, _item$_productOrigin10;
1591
+ 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;
1575
1592
  });
1576
1593
  if (accountDuration > duration) {
1577
1594
  duration = accountDuration;
1578
1595
  }
1579
- });
1596
+ };
1597
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
1598
+ accountList.forEach(function (account) {
1599
+ var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1600
+ checkDuration(cartItems);
1601
+ });
1602
+ } else {
1603
+ checkDuration(cartItems);
1604
+ }
1605
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].start_date && !dateRange) {
1606
+ var _cartItems$, _cartItems$2;
1607
+ dateRange = [{
1608
+ date: cartItems === null || cartItems === void 0 ? void 0 : cartItems[0].start_date,
1609
+ status: 'available',
1610
+ week: '',
1611
+ weekNum: 0
1612
+ }, {
1613
+ date: (cartItems === null || cartItems === void 0 || (_cartItems$ = cartItems[0]) === null || _cartItems$ === void 0 ? void 0 : _cartItems$.end_date) || (cartItems === null || cartItems === void 0 || (_cartItems$2 = cartItems[0]) === null || _cartItems$2 === void 0 ? void 0 : _cartItems$2.start_date) || '',
1614
+ status: 'available',
1615
+ week: '',
1616
+ weekNum: 0
1617
+ }];
1618
+ }
1580
1619
  var timeSlots = getTimeSlicesByResources({
1581
1620
  resourceIds: resourceIds,
1582
1621
  resourcesMap: resourcesMap,
@@ -1611,9 +1650,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1611
1650
  accountItems.forEach(function (item, index) {
1612
1651
  var newResources = cloneDeep(item._origin.resources);
1613
1652
  newResources.forEach(function (resource) {
1614
- var _item$_productOrigin$4, _item$_productOrigin10, _ref12, _item$_productOrigin11;
1653
+ var _item$_productOrigin$4, _item$_productOrigin11, _ref12, _item$_productOrigin12;
1615
1654
  resource.startTime = currentStartTime;
1616
- resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_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$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref12 = (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.duration) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.type) !== null && _ref12 !== void 0 ? _ref12 : 'minutes').format('YYYY-MM-DD HH:mm');
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');
1617
1656
  delete resource.times;
1618
1657
  });
1619
1658
  _this9.store.cart.updateItem({
@@ -1776,6 +1815,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1776
1815
  var productData = _objectSpread(_objectSpread({}, origin), {}, {
1777
1816
  product_variant_id: product_variant_id
1778
1817
  });
1818
+ if (!account) {
1819
+ var activeAccount = this.getActiveAccount();
1820
+ if (activeAccount) {
1821
+ account = activeAccount;
1822
+ }
1823
+ }
1779
1824
  this.store.cart.addItem({
1780
1825
  product: productData,
1781
1826
  date: date,
@@ -176,6 +176,8 @@ export interface IUpdateItemParams {
176
176
  quantity?: number;
177
177
  /** 资源 */
178
178
  resources?: Resource[];
179
+ /** 元数据 */
180
+ metadata?: any;
179
181
  /** 备注 */
180
182
  note?: string;
181
183
  /** 日期 */
@@ -85,7 +85,7 @@ var DateModule = class extends import_BaseModule.BaseModule {
85
85
  return [];
86
86
  }
87
87
  let dates = (0, import_utils.generateMonthDates)(start_date, end_date, type);
88
- if (!(resource_ids == null ? void 0 : resource_ids.length) || (0, import_dayjs.default)(end_date).isBefore((0, import_dayjs.default)())) {
88
+ if (!(resource_ids == null ? void 0 : resource_ids.length) || (0, import_dayjs.default)(end_date).isBefore((0, import_dayjs.default)().startOf("day"))) {
89
89
  return (0, import_utils.disableAllDates)(dates);
90
90
  }
91
91
  try {
@@ -96,8 +96,7 @@ var DateModule = class extends import_BaseModule.BaseModule {
96
96
  end_date,
97
97
  resource_ids,
98
98
  front_end_cache_id: this.cacheId
99
- },
100
- { useCache: true }
99
+ }
101
100
  );
102
101
  if (!((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.length)) {
103
102
  return (0, import_utils.disableAllDates)(dates);
@@ -184,7 +184,7 @@ 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 }]);
187
+ this.setDateRange([{ date, status: "available", week: "", weekNum: 0 }, { date, status: "available", week: "", weekNum: 0 }]);
188
188
  const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
189
189
  return await this.loadProducts({ schedule_ids: scheduleIds, product_ids });
190
190
  }
@@ -345,9 +345,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
345
345
  }
346
346
  ];
347
347
  }
348
- const dateRange = await this.getDateRange();
348
+ let dateRange = this.store.date.getDateRange();
349
349
  const tempStartDate = startDate || (dateRange == null ? void 0 : dateRange[0].date);
350
- const tempEndDate = endDate || (dateRange == null ? void 0 : dateRange[0].date);
350
+ const tempEndDate = endDate || (dateRange == null ? void 0 : dateRange[1].date);
351
351
  if (!tempProducts.length) {
352
352
  return [];
353
353
  }
@@ -427,6 +427,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
427
427
  const cartItems = this.store.cart.getItems();
428
428
  const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
429
429
  newCartItems.forEach((item) => {
430
+ var _a;
430
431
  item._origin.resources = item._origin.resources.map((n) => {
431
432
  const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
432
433
  delete newResourcesItem.id;
@@ -434,6 +435,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
434
435
  delete newResourcesItem.resourceType;
435
436
  return { ...newResourcesItem };
436
437
  });
438
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
439
+ capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
440
+ product_bundle: item._origin.product.product_bundle
441
+ });
442
+ item._origin.metadata.capacity = formatCapacity;
437
443
  });
438
444
  return this.store.order.submitOrder({ query: { cartItems: newCartItems } });
439
445
  }
@@ -455,13 +461,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
455
461
  }
456
462
  // 更新购物车
457
463
  updateCart(params) {
464
+ var _a;
458
465
  const targetCartItem = this.store.cart.getItem(params._id);
459
466
  if (!targetCartItem) {
460
467
  throw new Error(`没有找到${params._id}购物车商品`);
461
468
  }
462
469
  if (params.resources) {
470
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
471
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
472
+ product_bundle: targetCartItem._origin.product.product_bundle
473
+ });
474
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
463
475
  params.resources = params.resources.map((n) => {
464
- n.capacity = targetCartItem.num || 1;
476
+ n.capacity = currentCapacity || 1;
465
477
  (0, import_resources.checkSubResourcesCapacity)(n);
466
478
  return n;
467
479
  });
@@ -469,14 +481,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
469
481
  this.store.cart.updateItem(params);
470
482
  const cartItems = this.store.cart.getItems();
471
483
  cartItems.forEach((item) => {
472
- var _a;
484
+ var _a2;
473
485
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
474
- const resources = (_a = item._origin.resources) == null ? void 0 : _a.filter((m) => {
486
+ const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
475
487
  return !targetCartItem._origin.resources.some((targetRes) => {
476
- var _a2, _b;
488
+ var _a3, _b;
477
489
  if (targetRes.id === m.id)
478
490
  return true;
479
- if (((_a2 = targetRes.metadata.combined_resource) == null ? void 0 : _a2.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id))
491
+ if (((_a3 = targetRes.metadata.combined_resource) == null ? void 0 : _a3.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id))
480
492
  return true;
481
493
  if (((_b = m.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
482
494
  return true;
@@ -571,6 +583,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
571
583
  capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
572
584
  product_bundle: cartItem._origin.product.product_bundle
573
585
  });
586
+ cartItem._origin.metadata.capacity = formatCapacity;
574
587
  const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
575
588
  const productResources = (0, import_resources.getResourcesByProduct)(
576
589
  resourcesMap,
@@ -941,15 +954,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
941
954
  }
942
955
  // 从购物车中获取已经分配好第一步资源的所有时间片
943
956
  getTimeSlotByAllResources(resources_code) {
944
- const dateRange = this.store.date.getDateRange();
957
+ var _a, _b;
958
+ let dateRange = this.store.date.getDateRange();
945
959
  const resources = [];
946
960
  const cartItems = this.store.cart.getItems();
947
- if (cartItems == null ? void 0 : cartItems[0].start_date)
948
- return [];
949
961
  const resourceIds = [];
950
962
  cartItems.forEach((item) => {
951
- var _a, _b, _c;
952
- (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
963
+ var _a2, _b2, _c;
964
+ (_c = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c.forEach((n) => {
953
965
  if (n.code === resources_code) {
954
966
  resources.push(...n.renderList || []);
955
967
  }
@@ -960,17 +972,41 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
960
972
  });
961
973
  const resourcesMap = (0, import_utils.getResourcesMap)(resources);
962
974
  let duration = 0;
963
- this.store.accountList.getAccounts().forEach((account) => {
975
+ const accountList = this.store.accountList.getAccounts();
976
+ const checkDuration = (cartItems2) => {
964
977
  let accountDuration = 0;
965
- const cartItems2 = this.store.cart.getCartByAccount(account.getId());
966
978
  cartItems2.forEach((item) => {
967
- var _a, _b;
968
- accountDuration += ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0;
979
+ var _a2, _b2;
980
+ accountDuration += ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0;
969
981
  });
970
982
  if (accountDuration > duration) {
971
983
  duration = accountDuration;
972
984
  }
973
- });
985
+ };
986
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
987
+ accountList.forEach((account) => {
988
+ const cartItems2 = this.store.cart.getCartByAccount(account.getId());
989
+ checkDuration(cartItems2);
990
+ });
991
+ } else {
992
+ checkDuration(cartItems);
993
+ }
994
+ if ((cartItems == null ? void 0 : cartItems[0].start_date) && !dateRange) {
995
+ dateRange = [
996
+ {
997
+ date: cartItems == null ? void 0 : cartItems[0].start_date,
998
+ status: "available",
999
+ week: "",
1000
+ weekNum: 0
1001
+ },
1002
+ {
1003
+ date: ((_a = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _a.end_date) || ((_b = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _b.start_date) || "",
1004
+ status: "available",
1005
+ week: "",
1006
+ weekNum: 0
1007
+ }
1008
+ ];
1009
+ }
974
1010
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
975
1011
  resourceIds,
976
1012
  resourcesMap,
@@ -1133,6 +1169,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1133
1169
  }) {
1134
1170
  const { bundle, options, origin, product_variant_id } = product || {};
1135
1171
  const productData = { ...origin, product_variant_id };
1172
+ if (!account) {
1173
+ const activeAccount = this.getActiveAccount();
1174
+ if (activeAccount) {
1175
+ account = activeAccount;
1176
+ }
1177
+ }
1136
1178
  this.store.cart.addItem({
1137
1179
  product: productData,
1138
1180
  date,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.54",
4
+ "version": "0.0.56",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",