@pisell/pisellos 2.0.40 → 2.0.42

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.
@@ -326,7 +326,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
326
326
  });
327
327
 
328
328
  // 检测 如果被删除的是活跃账号,则默认把第一个账号设置为 activeAccount
329
- if (((_this$getActiveAccoun = this.getActiveAccount()) === null || _this$getActiveAccoun === void 0 ? void 0 : _this$getActiveAccoun.getId()) === id) {
329
+ if (!this.getActiveAccount() || ((_this$getActiveAccoun = this.getActiveAccount()) === null || _this$getActiveAccoun === void 0 ? void 0 : _this$getActiveAccoun.getId()) === id || this.store.accounts.length === 1) {
330
330
  this.setActiveAccount(this.store.accounts[0].getId());
331
331
  }
332
332
  _context6.next = 12;
@@ -423,15 +423,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
423
423
  // 记录实际应用了优惠券的商品信息
424
424
  var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
425
425
 
426
+ // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
427
+ var productOriginTotal = product.origin_total || product.total || 0;
428
+
426
429
  // 计算使用折扣卡/商品券以后,单个商品的总 total
427
- var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(product.origin_total || 0).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(product.origin_total || 0)).toNumber();
430
+ var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(productOriginTotal).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(productOriginTotal)).toNumber();
428
431
  var discountDetail = {
429
- amount: new Decimal(product.origin_total || 0).minus(new Decimal(targetProductTotal)).toNumber(),
432
+ amount: new Decimal(productOriginTotal).minus(new Decimal(targetProductTotal)).toNumber(),
430
433
  type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
431
434
  discount: {
432
435
  resource_id: _selectedDiscount.id,
433
436
  title: _selectedDiscount.format_title,
434
- original_amount: product.origin_total,
437
+ original_amount: productOriginTotal,
435
438
  product_id: originProduct.id,
436
439
  percent: _selectedDiscount.par_value
437
440
  },
@@ -465,7 +468,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
465
468
  price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
466
469
  quantity: isNeedSplit ? 1 : product.quantity,
467
470
  total: targetProductTotal,
468
- origin_total: product.origin_total || product.total
471
+ origin_total: productOriginTotal
469
472
  }));
470
473
  }
471
474
  }
@@ -1191,6 +1191,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1191
1191
  _this6.store.cart.removeItem(n._id);
1192
1192
  });
1193
1193
  }
1194
+ // 如果 date.startTime 和 dateRange 里的 startTime 不一样,需要修正 dateRange
1195
+ var dateRange = this.store.date.getDateRange();
1196
+ if (dateRange !== null && dateRange !== void 0 && dateRange[0] && !dayjs(dateRange[0].date).isSame(dayjs(date.startTime), 'day')) {
1197
+ this.setDateRange([{
1198
+ date: dayjs(date.startTime).format('YYYY-MM-DD'),
1199
+ status: 'available',
1200
+ week: '',
1201
+ weekNum: 0
1202
+ }, {
1203
+ date: dayjs(date.endTime).format('YYYY-MM-DD'),
1204
+ status: 'available',
1205
+ week: '',
1206
+ weekNum: 0
1207
+ }]);
1208
+ }
1194
1209
  }
1195
1210
  }
1196
1211
  }, {
@@ -2809,7 +2824,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2809
2824
  });
2810
2825
 
2811
2826
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
2812
- if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 14)) {
2827
+ if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
2813
2828
  _context28.next = 9;
2814
2829
  break;
2815
2830
  }
@@ -195,7 +195,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
195
195
  this.store.accountList = this.store.accountList.filter(
196
196
  (account) => account.id !== id
197
197
  );
198
- if (((_a = this.getActiveAccount()) == null ? void 0 : _a.getId()) === id) {
198
+ if (!this.getActiveAccount() || ((_a = this.getActiveAccount()) == null ? void 0 : _a.getId()) === id || this.store.accounts.length === 1) {
199
199
  this.setActiveAccount(this.store.accounts[0].getId());
200
200
  }
201
201
  await this.core.effects.emit(
@@ -293,14 +293,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
293
293
  const selectedDiscount2 = applicableDiscounts[i2];
294
294
  usedDiscounts.set(selectedDiscount2.id, true);
295
295
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
296
- const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(product.origin_total || 0).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(product.origin_total || 0)).toNumber();
296
+ const productOriginTotal = product.origin_total || product.total || 0;
297
+ const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(productOriginTotal).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(productOriginTotal)).toNumber();
297
298
  const discountDetail = {
298
- amount: new import_decimal.default(product.origin_total || 0).minus(new import_decimal.default(targetProductTotal)).toNumber(),
299
+ amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
299
300
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
300
301
  discount: {
301
302
  resource_id: selectedDiscount2.id,
302
303
  title: selectedDiscount2.format_title,
303
- original_amount: product.origin_total,
304
+ original_amount: productOriginTotal,
304
305
  product_id: originProduct.id,
305
306
  percent: selectedDiscount2.par_value
306
307
  },
@@ -331,7 +332,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
331
332
  price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
332
333
  quantity: isNeedSplit ? 1 : product.quantity,
333
334
  total: targetProductTotal,
334
- origin_total: product.origin_total || product.total
335
+ origin_total: productOriginTotal
335
336
  }));
336
337
  }
337
338
  }
@@ -637,6 +637,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
637
637
  this.store.cart.removeItem(n._id);
638
638
  });
639
639
  }
640
+ const dateRange = this.store.date.getDateRange();
641
+ if ((dateRange == null ? void 0 : dateRange[0]) && !(0, import_dayjs.default)(dateRange[0].date).isSame((0, import_dayjs.default)(date.startTime), "day")) {
642
+ this.setDateRange([
643
+ { date: (0, import_dayjs.default)(date.startTime).format("YYYY-MM-DD"), status: "available", week: "", weekNum: 0 },
644
+ { date: (0, import_dayjs.default)(date.endTime).format("YYYY-MM-DD"), status: "available", week: "", weekNum: 0 }
645
+ ]);
646
+ }
640
647
  }
641
648
  }
642
649
  beforeUpdateCart(params, targetCartItem) {
@@ -2010,7 +2017,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2010
2017
  weekNum: (0, import_dayjs.default)(currentDate).day(),
2011
2018
  status
2012
2019
  });
2013
- if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 14) {
2020
+ if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 31) {
2014
2021
  break;
2015
2022
  }
2016
2023
  currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.40",
4
+ "version": "2.0.42",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",