@pisell/pisellos 2.0.5 → 2.0.7

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.
@@ -44,9 +44,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
44
44
  collection?: number | string[];
45
45
  schedule_ids?: number[];
46
46
  }): Promise<any>;
47
- loadProductByScheduleDate({ date, product_ids, }: {
47
+ loadProductByScheduleDate({ date, product_ids, category_ids, }: {
48
48
  date: string;
49
49
  product_ids?: number[];
50
+ category_ids?: number[];
50
51
  }): Promise<any>;
51
52
  loadAllSchedule(): Promise<void>;
52
53
  loadScheduleAvailableDate({ startDate, endDate, custom_page_id, }: {
@@ -132,6 +133,12 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
132
133
  */
133
134
  deleteCartItemInfo(type: ECartItemInfoType, _id?: string): void;
134
135
  checkCartItemByType(cartItem: CartItem, type: ECartItemCheckType): boolean;
136
+ /**
137
+ * 检查购物车商品是否符合条件
138
+ * @param type 类型
139
+ * @returns 不符合条件的购物车商品ID列表
140
+ */
141
+ checkCartItems(type: ECartItemCheckType): string[];
135
142
  destroy(): void;
136
143
  getResourcesList(): any[];
137
144
  getResourcesListByCartItem(id: string | number): {
@@ -243,11 +243,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
243
243
  key: "loadProductByScheduleDate",
244
244
  value: function () {
245
245
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
246
- var date, product_ids, scheduleList, scheduleIds;
246
+ var date, product_ids, _ref2$category_ids, category_ids, scheduleList, scheduleIds;
247
247
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
248
248
  while (1) switch (_context3.prev = _context3.next) {
249
249
  case 0:
250
- date = _ref2.date, product_ids = _ref2.product_ids;
250
+ date = _ref2.date, product_ids = _ref2.product_ids, _ref2$category_ids = _ref2.category_ids, category_ids = _ref2$category_ids === void 0 ? [] : _ref2$category_ids;
251
251
  scheduleList = this.store.schedule.getAvailabilityScheduleDateList(); // 缓存下这次选择的结果,如果是先选日期再选 duration 类商品,后面用得到
252
252
  this.setDateRange([{
253
253
  date: date,
@@ -268,7 +268,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
268
268
  _context3.next = 6;
269
269
  return this.loadProducts({
270
270
  schedule_ids: scheduleIds,
271
- product_ids: product_ids
271
+ product_ids: product_ids,
272
+ category_ids: category_ids
272
273
  });
273
274
  case 6:
274
275
  return _context3.abrupt("return", _context3.sent);
@@ -1104,6 +1105,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1104
1105
  value: function checkCartItemByType(cartItem, type) {
1105
1106
  return this.store.cart.checkCartItemByType(cartItem, type);
1106
1107
  }
1108
+
1109
+ /**
1110
+ * 检查购物车商品是否符合条件
1111
+ * @param type 类型
1112
+ * @returns 不符合条件的购物车商品ID列表
1113
+ */
1114
+ }, {
1115
+ key: "checkCartItems",
1116
+ value: function checkCartItems(type) {
1117
+ var _this7 = this;
1118
+ var cartItems = this.store.cart.getItems();
1119
+ var errorCartItemIds = [];
1120
+ cartItems.forEach(function (cartItem) {
1121
+ var result = _this7.store.cart.checkCartItemByType(cartItem, type);
1122
+ if (!result) {
1123
+ errorCartItemIds.push(cartItem._id);
1124
+ }
1125
+ });
1126
+ return errorCartItemIds;
1127
+ }
1107
1128
  }, {
1108
1129
  key: "destroy",
1109
1130
  value: function destroy() {
@@ -1398,7 +1419,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1398
1419
  key: "autoSelectAllProductResources",
1399
1420
  value: function autoSelectAllProductResources(resources_code, timeSlots) {
1400
1421
  var _dateRange$,
1401
- _this7 = this;
1422
+ _this8 = this;
1402
1423
  var dateRange = this.store.date.getDateRange();
1403
1424
  var resources = [];
1404
1425
  if (dateRange !== null && dateRange !== void 0 && (_dateRange$ = dateRange[0]) !== null && _dateRange$ !== void 0 && _dateRange$.date) {
@@ -1448,7 +1469,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1448
1469
  };
1449
1470
  }
1450
1471
  // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
1451
- var res = _this7.autoSelectAccountResources({
1472
+ var res = _this8.autoSelectAccountResources({
1452
1473
  holder_id: item.holder_id,
1453
1474
  resources_code: resources_code,
1454
1475
  timeSlots: recordTimeSlots,
@@ -1467,7 +1488,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1467
1488
  }
1468
1489
  res.selectedResource.capacity = currentCapacity;
1469
1490
  checkSubResourcesCapacity(res.selectedResource);
1470
- _this7.store.cart.updateItem({
1491
+ _this8.store.cart.updateItem({
1471
1492
  _id: item._id,
1472
1493
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
1473
1494
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
@@ -1481,15 +1502,24 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1481
1502
  } else {
1482
1503
  var _item$_productOrigin8, _productResources$fin;
1483
1504
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1484
- var allCartItems = cloneDeep(_this7.store.cart.getItems());
1505
+ var allCartItems = cloneDeep(_this8.store.cart.getItems());
1485
1506
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1486
1507
  var selectedResources = [];
1508
+ 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) || []);
1509
+ var currentResourcesRenderList = [];
1510
+ _resources.forEach(function (n) {
1511
+ var _n$renderList;
1512
+ if ((_n$renderList = n.renderList) !== null && _n$renderList !== void 0 && _n$renderList.length) {
1513
+ currentResourcesRenderList.push.apply(currentResourcesRenderList, _toConsumableArray(n.renderList || []));
1514
+ }
1515
+ });
1516
+ var _resourcesMap = getResourcesMap(currentResourcesRenderList);
1487
1517
  if (item.holder_id) {
1488
- selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap);
1518
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, _resourcesMap);
1489
1519
  } else {
1490
- selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap);
1520
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap);
1491
1521
  }
1492
- 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);
1522
+ var productResources = getResourcesByProduct(_resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1493
1523
  // 自动选择 productResources 中对应 resources_code 的资源
1494
1524
  var targetRenderList = (_productResources$fin = productResources.find(function (n) {
1495
1525
  return n.code === resources_code;
@@ -1506,7 +1536,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1506
1536
  targetResource.capacity = currentCapacity;
1507
1537
  // 在这里处理 children 的数据
1508
1538
  checkSubResourcesCapacity(targetResource);
1509
- _this7.store.cart.updateItem({
1539
+ _this8.store.cart.updateItem({
1510
1540
  _id: item._id,
1511
1541
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
1512
1542
  return existingRes.resourceType !== targetRenderList[0].resourceType;
@@ -1524,7 +1554,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1524
1554
  // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
1525
1555
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
1526
1556
  accountList.forEach(function (account) {
1527
- var cartItems = _this7.store.cart.getCartByAccount(account.getId());
1557
+ var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1528
1558
  selectForCartResources(cartItems);
1529
1559
  });
1530
1560
  } else {
@@ -1538,7 +1568,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1538
1568
  }, {
1539
1569
  key: "getTimeSlotByAllResources",
1540
1570
  value: function getTimeSlotByAllResources(resources_code) {
1541
- var _this8 = this,
1571
+ var _this9 = this,
1542
1572
  _cartItems$,
1543
1573
  _cartItems$2;
1544
1574
  var dateRange = this.store.date.getDateRange();
@@ -1577,7 +1607,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1577
1607
  };
1578
1608
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
1579
1609
  accountList.forEach(function (account) {
1580
- var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1610
+ var cartItems = _this9.store.cart.getCartByAccount(account.getId());
1581
1611
  checkDuration(cartItems);
1582
1612
  });
1583
1613
  } else {
@@ -1618,7 +1648,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1618
1648
  }, {
1619
1649
  key: "submitTimeSlot",
1620
1650
  value: function submitTimeSlot(timeSlots) {
1621
- var _this9 = this;
1651
+ var _this10 = this;
1622
1652
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
1623
1653
  var cartItems = cloneDeep(this.store.cart.getItems());
1624
1654
 
@@ -1643,7 +1673,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1643
1673
  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');
1644
1674
  delete resource.times;
1645
1675
  });
1646
- _this9.store.cart.updateItem({
1676
+ _this10.store.cart.updateItem({
1647
1677
  _id: item._id,
1648
1678
  resources: newResources
1649
1679
  });
@@ -1805,7 +1835,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1805
1835
  }, {
1806
1836
  key: "addProductToCart",
1807
1837
  value: function addProductToCart(_ref13) {
1808
- var _this10 = this;
1838
+ var _this11 = this;
1809
1839
  var product = _ref13.product,
1810
1840
  date = _ref13.date,
1811
1841
  account = _ref13.account;
@@ -1838,7 +1868,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1838
1868
  });
1839
1869
  if (cartItemsByDate.length) {
1840
1870
  cartItemsByDate.forEach(function (n) {
1841
- _this10.store.cart.removeItem(n._id);
1871
+ _this11.store.cart.removeItem(n._id);
1842
1872
  });
1843
1873
  }
1844
1874
  }
@@ -44,9 +44,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
44
44
  collection?: number | string[];
45
45
  schedule_ids?: number[];
46
46
  }): Promise<any>;
47
- loadProductByScheduleDate({ date, product_ids, }: {
47
+ loadProductByScheduleDate({ date, product_ids, category_ids, }: {
48
48
  date: string;
49
49
  product_ids?: number[];
50
+ category_ids?: number[];
50
51
  }): Promise<any>;
51
52
  loadAllSchedule(): Promise<void>;
52
53
  loadScheduleAvailableDate({ startDate, endDate, custom_page_id, }: {
@@ -132,6 +133,12 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
132
133
  */
133
134
  deleteCartItemInfo(type: ECartItemInfoType, _id?: string): void;
134
135
  checkCartItemByType(cartItem: CartItem, type: ECartItemCheckType): boolean;
136
+ /**
137
+ * 检查购物车商品是否符合条件
138
+ * @param type 类型
139
+ * @returns 不符合条件的购物车商品ID列表
140
+ */
141
+ checkCartItems(type: ECartItemCheckType): string[];
135
142
  destroy(): void;
136
143
  getResourcesList(): any[];
137
144
  getResourcesListByCartItem(id: string | number): {
@@ -187,7 +187,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
187
187
  }
188
188
  async loadProductByScheduleDate({
189
189
  date,
190
- product_ids
190
+ product_ids,
191
+ category_ids = []
191
192
  }) {
192
193
  const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
193
194
  this.setDateRange([
@@ -195,7 +196,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
195
196
  { date, status: "available", week: "", weekNum: 0 }
196
197
  ]);
197
198
  const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
198
- return await this.loadProducts({ schedule_ids: scheduleIds, product_ids });
199
+ return await this.loadProducts({ schedule_ids: scheduleIds, product_ids, category_ids });
199
200
  }
200
201
  // 加载当前店铺下所有 schedule
201
202
  async loadAllSchedule() {
@@ -548,6 +549,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
548
549
  checkCartItemByType(cartItem, type) {
549
550
  return this.store.cart.checkCartItemByType(cartItem, type);
550
551
  }
552
+ /**
553
+ * 检查购物车商品是否符合条件
554
+ * @param type 类型
555
+ * @returns 不符合条件的购物车商品ID列表
556
+ */
557
+ checkCartItems(type) {
558
+ const cartItems = this.store.cart.getItems();
559
+ const errorCartItemIds = [];
560
+ cartItems.forEach((cartItem) => {
561
+ const result = this.store.cart.checkCartItemByType(cartItem, type);
562
+ if (!result) {
563
+ errorCartItemIds.push(cartItem._id);
564
+ }
565
+ });
566
+ return errorCartItemIds;
567
+ }
551
568
  destroy() {
552
569
  var _a, _b, _c, _d, _e, _f;
553
570
  (_a = this.store.cart) == null ? void 0 : _a.destroy();
@@ -896,22 +913,31 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
896
913
  } else {
897
914
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
898
915
  let selectedResources = [];
916
+ const resources2 = (0, import_lodash_es.cloneDeep)(((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || []);
917
+ const currentResourcesRenderList = [];
918
+ resources2.forEach((n) => {
919
+ var _a3;
920
+ if ((_a3 = n.renderList) == null ? void 0 : _a3.length) {
921
+ currentResourcesRenderList.push(...n.renderList || []);
922
+ }
923
+ });
924
+ const resourcesMap2 = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
899
925
  if (item.holder_id) {
900
926
  selectedResources = (0, import_resources.getOthersSelectedResources)(
901
927
  allCartItems,
902
928
  item.holder_id,
903
- resourcesMap
929
+ resourcesMap2
904
930
  );
905
931
  } else {
906
932
  selectedResources = (0, import_resources.getOthersCartSelectedResources)(
907
933
  allCartItems,
908
934
  item._id,
909
- resourcesMap
935
+ resourcesMap2
910
936
  );
911
937
  }
912
938
  const productResources = (0, import_resources.getResourcesByProduct)(
913
- resourcesMap,
914
- ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || [],
939
+ resourcesMap2,
940
+ (0, import_lodash_es.cloneDeep)(resources2),
915
941
  selectedResources,
916
942
  currentCapacity
917
943
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.5",
4
+ "version": "2.0.7",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",