@pisell/pisellos 0.0.123 → 0.0.125

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.
@@ -216,6 +216,7 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
216
216
  }, {
217
217
  key: "formatCartItem",
218
218
  value: function formatCartItem(params) {
219
+ var _tempCartItem;
219
220
  var _id = params._id,
220
221
  cartItem = params.cartItem,
221
222
  account = params.account,
@@ -226,11 +227,15 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
226
227
  resources = params.resources,
227
228
  note = params.note,
228
229
  date = params.date,
229
- relationForms = params.relationForms,
230
- quantity = params.quantity;
230
+ relationForms = params.relationForms;
231
+ var quantity = params.quantity;
231
232
  var tempCartItem = this.store.list.find(function (i) {
232
233
  return i._id === _id;
233
234
  });
235
+ if (!quantity && (_tempCartItem = tempCartItem) !== null && _tempCartItem !== void 0 && _tempCartItem.num) {
236
+ var _tempCartItem2;
237
+ quantity = ((_tempCartItem2 = tempCartItem) === null || _tempCartItem2 === void 0 ? void 0 : _tempCartItem2.num) || 1;
238
+ }
234
239
  if (!tempCartItem) {
235
240
  throw new Error('[CartModule] 格式化数据到购物车失败,商品不存在');
236
241
  }
@@ -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
  }
@@ -2890,6 +2897,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2890
2897
  var params,
2891
2898
  startDate,
2892
2899
  endDate,
2900
+ endDateAfterMonth,
2893
2901
  tempProducts,
2894
2902
  schedule,
2895
2903
  filteredSchedule,
@@ -2914,13 +2922,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2914
2922
  startDate = dayjs().format('YYYY-MM-DD');
2915
2923
  }
2916
2924
  // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2917
- endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2925
+ // 优化策略:
2926
+ // 在 endDate 添加完一个月以后,如果 endDate 还小于 startDate + 7 天,则还需要 endDate+7 天
2927
+ endDateAfterMonth = dayjs().add(1, 'month').format('YYYY-MM-DD');
2928
+ if (dayjs(startDate).add(7, 'day').isAfter(dayjs(endDateAfterMonth), 'day')) {
2929
+ endDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2930
+ } else {
2931
+ endDate = endDateAfterMonth;
2932
+ }
2918
2933
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2919
2934
  tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2920
2935
  schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2921
2936
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2922
2937
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2923
- _context32.next = 10;
2938
+ _context32.next = 11;
2924
2939
  return this.store.date.fetchResourceDates({
2925
2940
  query: {
2926
2941
  start_date: startDate || '',
@@ -2928,17 +2943,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2928
2943
  resource_ids: tempResourceIds
2929
2944
  }
2930
2945
  });
2931
- case 10:
2946
+ case 11:
2932
2947
  res = _context32.sent;
2933
2948
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2934
2949
  // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
2935
2950
  cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2936
2951
  if (!cache) {
2937
- _context32.next = 16;
2952
+ _context32.next = 17;
2938
2953
  break;
2939
2954
  }
2940
2955
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2941
- _context32.next = 16;
2956
+ _context32.next = 17;
2942
2957
  break;
2943
2958
  }
2944
2959
  this.store.date.setDateList(cache.dateList);
@@ -2946,7 +2961,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2946
2961
  dateList: cache.dateList,
2947
2962
  firstAvailableDate: cache.firstAvailableDate
2948
2963
  });
2949
- case 16:
2964
+ case 17:
2950
2965
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2951
2966
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2952
2967
  dates = [];
@@ -3073,22 +3088,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3073
3088
  }
3074
3089
  }, _loop3);
3075
3090
  });
3076
- case 24:
3091
+ case 25:
3077
3092
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3078
- _context32.next = 30;
3093
+ _context32.next = 31;
3079
3094
  break;
3080
3095
  }
3081
- return _context32.delegateYield(_loop3(), "t0", 26);
3082
- case 26:
3096
+ return _context32.delegateYield(_loop3(), "t0", 27);
3097
+ case 27:
3083
3098
  if (!_context32.t0) {
3084
- _context32.next = 28;
3099
+ _context32.next = 29;
3085
3100
  break;
3086
3101
  }
3087
- return _context32.abrupt("break", 30);
3088
- case 28:
3089
- _context32.next = 24;
3102
+ return _context32.abrupt("break", 31);
3103
+ case 29:
3104
+ _context32.next = 25;
3090
3105
  break;
3091
- case 30:
3106
+ case 31:
3092
3107
  // 最终把资源数据也加到日期内
3093
3108
  dates = handleAvailableDateByResource(res.data, dates);
3094
3109
  this.store.date.setDateList(dates);
@@ -3098,13 +3113,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3098
3113
  dateList: dates,
3099
3114
  firstAvailableDate: firstAvailableDate,
3100
3115
  startDate: startDate,
3101
- endDate: endDate
3116
+ endDate: dayjs(currentDate).format('YYYY-MM-DD')
3102
3117
  });
3103
3118
  return _context32.abrupt("return", {
3104
3119
  dateList: dates,
3105
3120
  firstAvailableDate: firstAvailableDate
3106
3121
  });
3107
- case 34:
3122
+ case 35:
3108
3123
  case "end":
3109
3124
  return _context32.stop();
3110
3125
  }
@@ -133,10 +133,13 @@ var CartModule = class extends import_BaseModule.BaseModule {
133
133
  resources,
134
134
  note,
135
135
  date,
136
- relationForms,
137
- quantity
136
+ relationForms
138
137
  } = params;
138
+ let quantity = params.quantity;
139
139
  let tempCartItem = this.store.list.find((i) => i._id === _id);
140
+ if (!quantity && (tempCartItem == null ? void 0 : tempCartItem.num)) {
141
+ quantity = (tempCartItem == null ? void 0 : tempCartItem.num) || 1;
142
+ }
140
143
  if (!tempCartItem) {
141
144
  throw new Error("[CartModule] 格式化数据到购物车失败,商品不存在");
142
145
  }
@@ -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
@@ -2038,7 +2037,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2038
2037
  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"))) {
2039
2038
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2040
2039
  }
2041
- endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2040
+ const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2041
+ if ((0, import_dayjs.default)(startDate).add(7, "day").isAfter((0, import_dayjs.default)(endDateAfterMonth), "day")) {
2042
+ endDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
2043
+ } else {
2044
+ endDate = endDateAfterMonth;
2045
+ }
2042
2046
  let tempProducts;
2043
2047
  tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
2044
2048
  const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
@@ -2171,7 +2175,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2171
2175
  dateList: dates,
2172
2176
  firstAvailableDate,
2173
2177
  startDate,
2174
- endDate
2178
+ endDate: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD")
2175
2179
  });
2176
2180
  return {
2177
2181
  dateList: dates,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.123",
4
+ "version": "0.0.125",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",