@pisell/pisellos 1.0.14 → 1.0.16

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.
@@ -303,7 +303,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
303
303
  key: "removeAccount",
304
304
  value: function () {
305
305
  var _removeAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
306
- var index;
306
+ var _this$getActiveAccoun, index;
307
307
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
308
308
  while (1) switch (_context6.prev = _context6.next) {
309
309
  case 0:
@@ -324,26 +324,31 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
324
324
  this.store.accountList = this.store.accountList.filter(function (account) {
325
325
  return account.id !== id;
326
326
  });
327
- _context6.next = 11;
327
+
328
+ // 检测 如果被删除的是活跃账号,则默认把第一个账号设置为 activeAccount
329
+ if (((_this$getActiveAccoun = this.getActiveAccount()) === null || _this$getActiveAccoun === void 0 ? void 0 : _this$getActiveAccoun.getId()) === id) {
330
+ this.setActiveAccount(this.store.accounts[0].getId());
331
+ }
332
+ _context6.next = 12;
328
333
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
329
- case 11:
330
- _context6.next = 18;
334
+ case 12:
335
+ _context6.next = 19;
331
336
  break;
332
- case 13:
333
- _context6.prev = 13;
337
+ case 14:
338
+ _context6.prev = 14;
334
339
  _context6.t0 = _context6["catch"](0);
335
340
  this.store.error = _context6.t0 instanceof Error ? _context6.t0.message : 'Failed to remove account';
336
- _context6.next = 18;
341
+ _context6.next = 19;
337
342
  return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
338
- case 18:
339
- _context6.prev = 18;
343
+ case 19:
344
+ _context6.prev = 19;
340
345
  this.store.isLoading = false;
341
- return _context6.finish(18);
342
- case 21:
346
+ return _context6.finish(19);
347
+ case 22:
343
348
  case "end":
344
349
  return _context6.stop();
345
350
  }
346
- }, _callee6, this, [[0, 13, 18, 21]]);
351
+ }, _callee6, this, [[0, 14, 19, 22]]);
347
352
  }));
348
353
  function removeAccount(_x9) {
349
354
  return _removeAccount.apply(this, arguments);
@@ -401,7 +401,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
401
401
  var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
402
402
 
403
403
  // 需要拆分出来的数量
404
- var splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter(function (item) {
404
+ var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, applicableDiscounts.filter(function (item) {
405
405
  return (item.tag || item.type) === 'good_pass';
406
406
  }).length) : 1;
407
407
  var arr = [];
@@ -1410,17 +1410,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1410
1410
  resources.push.apply(resources, _toConsumableArray(_this10.store.date.getResourcesListByDate(n.date) || []));
1411
1411
  });
1412
1412
  }
1413
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1414
+ return !isNormalProduct(n._productOrigin);
1415
+ });
1416
+
1413
1417
  // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1414
1418
  if (!resources.length) {
1415
- var dateList = this.store.date.getDateList();
1416
- dateList.forEach(function (n) {
1417
- if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1419
+ // 如果此时购物车里已经有了开始时间,则直接取那天的数据即可
1420
+ var firstDateCartItem = cartItems === null || cartItems === void 0 ? void 0 : cartItems.find(function (n) {
1421
+ return n.start_date;
1418
1422
  });
1423
+ if (firstDateCartItem !== null && firstDateCartItem !== void 0 && firstDateCartItem.start_date) {
1424
+ var dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
1425
+ resources.push.apply(resources, _toConsumableArray(dateResources || []));
1426
+ } else {
1427
+ var dateList = this.store.date.getDateList();
1428
+ dateList.forEach(function (n) {
1429
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1430
+ });
1431
+ }
1419
1432
  }
1420
1433
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1421
- var cartItems = this.store.cart.getItems().filter(function (n) {
1422
- return !isNormalProduct(n._productOrigin);
1423
- });
1424
1434
  var arr = [];
1425
1435
  cartItems.forEach(function (cartItem) {
1426
1436
  var _cartItem$_productOri;
@@ -179,6 +179,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
179
179
  });
180
180
  }
181
181
  async removeAccount(id) {
182
+ var _a;
182
183
  try {
183
184
  this.store.isLoading = true;
184
185
  this.store.error = null;
@@ -194,6 +195,9 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
194
195
  this.store.accountList = this.store.accountList.filter(
195
196
  (account) => account.id !== id
196
197
  );
198
+ if (((_a = this.getActiveAccount()) == null ? void 0 : _a.getId()) === id) {
199
+ this.setActiveAccount(this.store.accounts[0].getId());
200
+ }
197
201
  await this.core.effects.emit(
198
202
  import_types.AccountListHooks.OnAccountListUpdate,
199
203
  this.store
@@ -279,7 +279,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
279
279
  return;
280
280
  }
281
281
  const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
282
- const splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
282
+ const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
283
283
  const arr = [];
284
284
  if (splitCount < product.quantity && isNeedSplit) {
285
285
  arr.push(this.hooks.setProduct(originProduct, {
@@ -820,15 +820,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
820
820
  resources.push(...this.store.date.getResourcesListByDate(n.date) || []);
821
821
  });
822
822
  }
823
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
823
824
  if (!resources.length) {
824
- const dateList = this.store.date.getDateList();
825
- dateList.forEach((n) => {
826
- if (n.resource)
827
- resources.push(...n.resource);
828
- });
825
+ const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
826
+ if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
827
+ const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
828
+ resources.push(...dateResources || []);
829
+ } else {
830
+ const dateList = this.store.date.getDateList();
831
+ dateList.forEach((n) => {
832
+ if (n.resource)
833
+ resources.push(...n.resource);
834
+ });
835
+ }
829
836
  }
830
837
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
831
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
832
838
  const arr = [];
833
839
  cartItems.forEach((cartItem) => {
834
840
  var _a, _b, _c, _d, _e, _f;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.14",
4
+ "version": "1.0.16",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",