@pisell/pisellos 2.0.34 → 2.0.35

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.
@@ -69,8 +69,10 @@ export interface CartItem {
69
69
  name?: string;
70
70
  /** 商品价格 */
71
71
  price?: number | string;
72
- /** 商品总价 */
72
+ /** 单个商品包括商品本身价格+套餐价格+规格等价格得出来的 */
73
73
  total?: number | string;
74
+ /** 基于 total 乘以 商品数量的价格 */
75
+ summaryTotal?: number | string;
74
76
  /** 商品原价总价,排除原始价格为0的场景 */
75
77
  origin_total?: number | string;
76
78
  /** 商品数量 */
@@ -61,6 +61,7 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
61
61
  options: options,
62
62
  num: num
63
63
  });
64
+ cartItem.summaryTotal = cartItem.total * (num || 1);
64
65
  cartItem.origin_total = getProductOriginTotalPrice({
65
66
  product: product,
66
67
  bundle: bundle,
@@ -161,7 +162,7 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
161
162
  var product = params.product,
162
163
  bundle = params.bundle,
163
164
  options = params.options;
164
- var num = params.num || 1;
165
+ // const num = params.num || 1;
165
166
  var price = Number(product.price);
166
167
  if (bundle !== null && bundle !== void 0 && bundle.length) {
167
168
  price = bundle.reduce(function (accumulator, currentValue) {
@@ -175,7 +176,7 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
175
176
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
176
177
  }, price);
177
178
  }
178
- return price * num;
179
+ return price;
179
180
  };
180
181
 
181
182
  /**
@@ -28,7 +28,7 @@ export var calculateSubtotal = function calculateSubtotal(items) {
28
28
  return '0.00';
29
29
  }
30
30
  var subtotal = items.reduce(function (sum, item) {
31
- var cartItemTotalPrice = new Decimal(item.total || 0);
31
+ var cartItemTotalPrice = new Decimal(item.summaryTotal || 0);
32
32
  return sum.plus(cartItemTotalPrice);
33
33
  }, new Decimal(0));
34
34
  return subtotal.toFixed(2);
@@ -50,7 +50,7 @@ export var calculateTaxFee = function calculateTaxFee(shopInfo, items) {
50
50
  is_price_include_tax = _ref.is_price_include_tax,
51
51
  tax_rate = _ref.tax_rate;
52
52
  var totalTaxFee = items.reduce(function (sum, item) {
53
- var cartItemTotalPrice = new Decimal(item.total || 0);
53
+ var cartItemTotalPrice = new Decimal(item.summaryTotal || 0);
54
54
  var taxRate = new Decimal(tax_rate || 0).div(100);
55
55
  var productTaxRate = cartItemTotalPrice.times(taxRate).times((item === null || item === void 0 ? void 0 : item.is_charge_tax) || 0).div(taxRate.times(is_price_include_tax || 0).plus(1));
56
56
  return sum.plus(productTaxRate);
@@ -272,8 +272,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
272
272
  key: "loadProductByScheduleDate",
273
273
  value: function () {
274
274
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
275
- var _product_ids;
276
- var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, _schedule$product_ids, schedule, otherProductsIds, allProductIds;
275
+ var _schedule$product_ids;
276
+ var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, schedule, otherProductsIds, allProductIds;
277
277
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
278
278
  while (1) switch (_context3.prev = _context3.next) {
279
279
  case 0:
@@ -296,29 +296,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
296
296
  // .filter((n) => n !== null && n !== undefined);
297
297
 
298
298
  // 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
299
- if (!((_product_ids = product_ids) !== null && _product_ids !== void 0 && _product_ids.length)) {
300
- schedule = scheduleList.find(function (n) {
301
- return n.date === date;
302
- });
303
- if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
304
- product_ids = schedule.product_ids;
305
- }
299
+ // if (!product_ids?.length) {
300
+ // const schedule = scheduleList.find((n) => n.date === date);
301
+ // if (schedule && schedule.product_ids?.length) {
302
+ // product_ids = schedule.product_ids;
303
+ // }
304
+ // }
305
+ // V2接口修改后,只能从schedule 接口里拿数据,不可以从外面拿,外面给的是装修数据
306
+ schedule = scheduleList.find(function (n) {
307
+ return n.date === date;
308
+ });
309
+ if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
310
+ product_ids = schedule.product_ids;
306
311
  }
307
312
  // 尝试去拿schedule 里的 other_product_ids 和 product_ids 拼在一起去重
308
313
  otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
309
314
  allProductIds = [].concat(_toConsumableArray(product_ids), _toConsumableArray(otherProductsIds)).filter(function (n, index, self) {
310
315
  return self.indexOf(n) === index;
311
316
  });
312
- _context3.next = 8;
317
+ _context3.next = 9;
313
318
  return this.loadProducts({
314
319
  // schedule_ids: scheduleIds,
315
320
  product_ids: allProductIds,
316
321
  category_ids: category_ids
317
322
  // schedule_date: date,
318
323
  });
319
- case 8:
320
- return _context3.abrupt("return", _context3.sent);
321
324
  case 9:
325
+ return _context3.abrupt("return", _context3.sent);
326
+ case 10:
322
327
  case "end":
323
328
  return _context3.stop();
324
329
  }
@@ -341,7 +346,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
341
346
  // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
342
347
  cartItems = this.store.cart.getItems();
343
348
  if (!cartItems.length) {
344
- _context5.next = 24;
349
+ _context5.next = 25;
345
350
  break;
346
351
  }
347
352
  userPlugin = this.core.getPlugin('user');
@@ -433,6 +438,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
433
438
  _iterator.f();
434
439
  return _context5.finish(21);
435
440
  case 24:
441
+ this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
442
+ case 25:
436
443
  case "end":
437
444
  return _context5.stop();
438
445
  }
@@ -2460,8 +2467,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2460
2467
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
2461
2468
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2462
2469
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
2470
+
2471
+ // n.start_at 是 2025-06-30 15:00 end_at 2025-06-30 17:00
2472
+ // item.start 是 2025-06-30 16:00 item.end 是 2025-06-30 19:00
2473
+ // 需要判断 n.start_at 和 n.end_at 是否在 item.start 和 item.end 之间
2474
+ // 如果 n.start_at 和 n.end_at 在 item.start 和 item.end 有交集,则此时间需要计算
2463
2475
  var mTimes = m.times.filter(function (n) {
2464
- return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
2476
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
2465
2477
  });
2466
2478
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2467
2479
  if (mTimes.length === 0) {
@@ -2889,6 +2901,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2889
2901
  var params,
2890
2902
  startDate,
2891
2903
  endDate,
2904
+ endDateAfterMonth,
2892
2905
  tempProducts,
2893
2906
  schedule,
2894
2907
  filteredSchedule,
@@ -2913,13 +2926,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2913
2926
  startDate = dayjs().format('YYYY-MM-DD');
2914
2927
  }
2915
2928
  // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2916
- endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2929
+ // 优化策略:
2930
+ // 在 endDate 添加完一个月以后,如果 endDate 还小于 startDate + 7 天,则还需要 endDate+7 天
2931
+ endDateAfterMonth = dayjs().add(1, 'month').format('YYYY-MM-DD');
2932
+ if (dayjs(startDate).add(7, 'day').isAfter(dayjs(endDateAfterMonth), 'day')) {
2933
+ endDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2934
+ } else {
2935
+ endDate = endDateAfterMonth;
2936
+ }
2917
2937
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2918
2938
  tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2919
2939
  schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2920
2940
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2921
2941
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2922
- _context32.next = 10;
2942
+ _context32.next = 11;
2923
2943
  return this.store.date.fetchResourceDates({
2924
2944
  query: {
2925
2945
  start_date: startDate || '',
@@ -2927,17 +2947,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2927
2947
  resource_ids: tempResourceIds
2928
2948
  }
2929
2949
  });
2930
- case 10:
2950
+ case 11:
2931
2951
  res = _context32.sent;
2932
2952
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2933
2953
  // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
2934
2954
  cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2935
2955
  if (!cache) {
2936
- _context32.next = 16;
2956
+ _context32.next = 17;
2937
2957
  break;
2938
2958
  }
2939
2959
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2940
- _context32.next = 16;
2960
+ _context32.next = 17;
2941
2961
  break;
2942
2962
  }
2943
2963
  this.store.date.setDateList(cache.dateList);
@@ -2945,7 +2965,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2945
2965
  dateList: cache.dateList,
2946
2966
  firstAvailableDate: cache.firstAvailableDate
2947
2967
  });
2948
- case 16:
2968
+ case 17:
2949
2969
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2950
2970
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2951
2971
  dates = [];
@@ -3072,22 +3092,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3072
3092
  }
3073
3093
  }, _loop3);
3074
3094
  });
3075
- case 24:
3095
+ case 25:
3076
3096
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3077
- _context32.next = 30;
3097
+ _context32.next = 31;
3078
3098
  break;
3079
3099
  }
3080
- return _context32.delegateYield(_loop3(), "t0", 26);
3081
- case 26:
3100
+ return _context32.delegateYield(_loop3(), "t0", 27);
3101
+ case 27:
3082
3102
  if (!_context32.t0) {
3083
- _context32.next = 28;
3103
+ _context32.next = 29;
3084
3104
  break;
3085
3105
  }
3086
- return _context32.abrupt("break", 30);
3087
- case 28:
3088
- _context32.next = 24;
3106
+ return _context32.abrupt("break", 31);
3107
+ case 29:
3108
+ _context32.next = 25;
3089
3109
  break;
3090
- case 30:
3110
+ case 31:
3091
3111
  // 最终把资源数据也加到日期内
3092
3112
  dates = handleAvailableDateByResource(res.data, dates);
3093
3113
  this.store.date.setDateList(dates);
@@ -3097,13 +3117,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3097
3117
  dateList: dates,
3098
3118
  firstAvailableDate: firstAvailableDate,
3099
3119
  startDate: startDate,
3100
- endDate: endDate
3120
+ endDate: dayjs(currentDate).format('YYYY-MM-DD')
3101
3121
  });
3102
3122
  return _context32.abrupt("return", {
3103
3123
  dateList: dates,
3104
3124
  firstAvailableDate: firstAvailableDate
3105
3125
  });
3106
- case 34:
3126
+ case 35:
3107
3127
  case "end":
3108
3128
  return _context32.stop();
3109
3129
  }
@@ -69,8 +69,10 @@ export interface CartItem {
69
69
  name?: string;
70
70
  /** 商品价格 */
71
71
  price?: number | string;
72
- /** 商品总价 */
72
+ /** 单个商品包括商品本身价格+套餐价格+规格等价格得出来的 */
73
73
  total?: number | string;
74
+ /** 基于 total 乘以 商品数量的价格 */
75
+ summaryTotal?: number | string;
74
76
  /** 商品原价总价,排除原始价格为0的场景 */
75
77
  origin_total?: number | string;
76
78
  /** 商品数量 */
@@ -74,6 +74,7 @@ var formatProductToCartItem = (params) => {
74
74
  cartItem.price = product == null ? void 0 : product.price;
75
75
  cartItem.num = num;
76
76
  cartItem.total = getProductTotalPrice({ product, bundle, options, num });
77
+ cartItem.summaryTotal = cartItem.total * (num || 1);
77
78
  cartItem.origin_total = getProductOriginTotalPrice({
78
79
  product,
79
80
  bundle,
@@ -163,7 +164,6 @@ var formatProductToCartItemOrigin = (params) => {
163
164
  };
164
165
  var getProductTotalPrice = (params) => {
165
166
  const { product, bundle, options } = params;
166
- const num = params.num || 1;
167
167
  let price = Number(product.price);
168
168
  if (bundle == null ? void 0 : bundle.length) {
169
169
  price = bundle.reduce((accumulator, currentValue) => {
@@ -175,7 +175,7 @@ var getProductTotalPrice = (params) => {
175
175
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
176
176
  }, price);
177
177
  }
178
- return price * num;
178
+ return price;
179
179
  };
180
180
  var getProductOriginTotalPrice = (params) => {
181
181
  const { product, bundle, options } = params;
@@ -55,7 +55,7 @@ var calculateSubtotal = (items) => {
55
55
  return "0.00";
56
56
  }
57
57
  const subtotal = items.reduce((sum, item) => {
58
- const cartItemTotalPrice = new import_decimal.default(item.total || 0);
58
+ const cartItemTotalPrice = new import_decimal.default(item.summaryTotal || 0);
59
59
  return sum.plus(cartItemTotalPrice);
60
60
  }, new import_decimal.default(0));
61
61
  return subtotal.toFixed(2);
@@ -66,7 +66,7 @@ var calculateTaxFee = (shopInfo, items) => {
66
66
  }
67
67
  const { is_price_include_tax, tax_rate } = shopInfo || {};
68
68
  const totalTaxFee = items.reduce((sum, item) => {
69
- const cartItemTotalPrice = new import_decimal.default(item.total || 0);
69
+ const cartItemTotalPrice = new import_decimal.default(item.summaryTotal || 0);
70
70
  const taxRate = new import_decimal.default(tax_rate || 0).div(100);
71
71
  const productTaxRate = cartItemTotalPrice.times(taxRate).times((item == null ? void 0 : item.is_charge_tax) || 0).div(taxRate.times(is_price_include_tax || 0).plus(1));
72
72
  return sum.plus(productTaxRate);
@@ -216,11 +216,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
216
216
  { date, status: "available", week: "", weekNum: 0 },
217
217
  { date, status: "available", week: "", weekNum: 0 }
218
218
  ]);
219
- if (!(product_ids == null ? void 0 : product_ids.length)) {
220
- const schedule = scheduleList.find((n) => n.date === date);
221
- if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
222
- product_ids = schedule.product_ids;
223
- }
219
+ const schedule = scheduleList.find((n) => n.date === date);
220
+ if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
221
+ product_ids = schedule.product_ids;
224
222
  }
225
223
  const otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
226
224
  const allProductIds = [...product_ids, ...otherProductsIds].filter(
@@ -283,6 +281,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
283
281
  bundle
284
282
  });
285
283
  }
284
+ this.core.effects.emit(`${this.store.cart.name}:onUpdateQuotationPrice`, {});
286
285
  }
287
286
  }
288
287
  // 加载当前店铺下所有 schedule
@@ -1703,7 +1702,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1703
1702
  let currentResourcesCount = 0;
1704
1703
  const currentResourcesTimeSlotCanUsedArr = [];
1705
1704
  const mTimes = m.times.filter((n) => {
1706
- return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute");
1705
+ return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
1707
1706
  });
1708
1707
  if (mTimes.length === 0) {
1709
1708
  return;
@@ -2037,7 +2036,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2037
2036
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
2038
2037
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2039
2038
  }
2040
- endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2039
+ const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2040
+ if ((0, import_dayjs.default)(startDate).add(7, "day").isAfter((0, import_dayjs.default)(endDateAfterMonth), "day")) {
2041
+ endDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
2042
+ } else {
2043
+ endDate = endDateAfterMonth;
2044
+ }
2041
2045
  let tempProducts;
2042
2046
  tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
2043
2047
  const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
@@ -2170,7 +2174,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2170
2174
  dateList: dates,
2171
2175
  firstAvailableDate,
2172
2176
  startDate,
2173
- endDate
2177
+ endDate: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD")
2174
2178
  });
2175
2179
  return {
2176
2180
  dateList: dates,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.34",
4
+ "version": "2.0.35",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "docs": "typedoc --out docs src/index.ts",
23
23
  "sync": "node sync.js",
24
24
  "prepublishOnly": "npm run build",
25
- "deploy": "yarn run build && yarn run changeset && yarn run version && npm run release"
25
+ "deploy": "npm run build && npm run changeset && npm run version && npm run release"
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
@@ -67,4 +67,4 @@
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  }
70
- }
70
+ }