@pisell/pisellos 2.0.5 → 2.0.6

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,7 +1502,7 @@ 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 = [];
1487
1508
  if (item.holder_id) {
@@ -1506,7 +1527,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1506
1527
  targetResource.capacity = currentCapacity;
1507
1528
  // 在这里处理 children 的数据
1508
1529
  checkSubResourcesCapacity(targetResource);
1509
- _this7.store.cart.updateItem({
1530
+ _this8.store.cart.updateItem({
1510
1531
  _id: item._id,
1511
1532
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
1512
1533
  return existingRes.resourceType !== targetRenderList[0].resourceType;
@@ -1524,7 +1545,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1524
1545
  // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
1525
1546
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
1526
1547
  accountList.forEach(function (account) {
1527
- var cartItems = _this7.store.cart.getCartByAccount(account.getId());
1548
+ var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1528
1549
  selectForCartResources(cartItems);
1529
1550
  });
1530
1551
  } else {
@@ -1538,7 +1559,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1538
1559
  }, {
1539
1560
  key: "getTimeSlotByAllResources",
1540
1561
  value: function getTimeSlotByAllResources(resources_code) {
1541
- var _this8 = this,
1562
+ var _this9 = this,
1542
1563
  _cartItems$,
1543
1564
  _cartItems$2;
1544
1565
  var dateRange = this.store.date.getDateRange();
@@ -1577,7 +1598,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1577
1598
  };
1578
1599
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
1579
1600
  accountList.forEach(function (account) {
1580
- var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1601
+ var cartItems = _this9.store.cart.getCartByAccount(account.getId());
1581
1602
  checkDuration(cartItems);
1582
1603
  });
1583
1604
  } else {
@@ -1618,7 +1639,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1618
1639
  }, {
1619
1640
  key: "submitTimeSlot",
1620
1641
  value: function submitTimeSlot(timeSlots) {
1621
- var _this9 = this;
1642
+ var _this10 = this;
1622
1643
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
1623
1644
  var cartItems = cloneDeep(this.store.cart.getItems());
1624
1645
 
@@ -1643,7 +1664,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1643
1664
  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
1665
  delete resource.times;
1645
1666
  });
1646
- _this9.store.cart.updateItem({
1667
+ _this10.store.cart.updateItem({
1647
1668
  _id: item._id,
1648
1669
  resources: newResources
1649
1670
  });
@@ -1805,7 +1826,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1805
1826
  }, {
1806
1827
  key: "addProductToCart",
1807
1828
  value: function addProductToCart(_ref13) {
1808
- var _this10 = this;
1829
+ var _this11 = this;
1809
1830
  var product = _ref13.product,
1810
1831
  date = _ref13.date,
1811
1832
  account = _ref13.account;
@@ -1838,7 +1859,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1838
1859
  });
1839
1860
  if (cartItemsByDate.length) {
1840
1861
  cartItemsByDate.forEach(function (n) {
1841
- _this10.store.cart.removeItem(n._id);
1862
+ _this11.store.cart.removeItem(n._id);
1842
1863
  });
1843
1864
  }
1844
1865
  }
@@ -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();
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.6",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",