@pisell/pisellos 3.0.56 → 3.0.58

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.
@@ -1,3 +1,3 @@
1
- import { Product } from "../../Product";
1
+ import { ProductData } from "../../Product";
2
2
  import { CartItem, IUpdateItemParams } from "../types";
3
- export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void, updateItemInitInfo: (item: IUpdateItemParams) => void): Promise<void>;
3
+ export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<ProductData | undefined>, updateCart: (item: IUpdateItemParams) => void, updateItemInitInfo: (item: IUpdateItemParams) => void): Promise<void>;
@@ -36,7 +36,7 @@ function _updateAllCartItemPrice() {
36
36
  return getProduct(item.id);
37
37
  case 4:
38
38
  cartProduct = _context.sent;
39
- productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
39
+ productInfo = cartProduct;
40
40
  if (!productInfo) {
41
41
  productInfo = item._productOrigin;
42
42
  }
@@ -1,6 +1,5 @@
1
1
  import { Module, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Product } from '../Product';
4
3
  import { ProductData } from '../Product/types';
5
4
  export * from './types';
6
5
  export declare class ProductList extends BaseModule implements Module {
@@ -26,7 +25,7 @@ export declare class ProductList extends BaseModule implements Module {
26
25
  channel?: string;
27
26
  }): Promise<any>;
28
27
  getProducts(): Promise<ProductData[]>;
29
- getProduct(id: number): Promise<Product | undefined>;
28
+ getProduct(id: number): Promise<ProductData | undefined>;
30
29
  addProduct(products: ProductData[]): Promise<void>;
31
30
  selectProducts(products: ProductData[]): Promise<void>;
32
31
  }
@@ -16,7 +16,6 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
16
16
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
17
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
18
  import { BaseModule } from "../BaseModule";
19
- import { Product } from "../Product";
20
19
  import { ProductListHooks } from "./types";
21
20
  import { cloneDeep } from 'lodash-es';
22
21
  export * from "./types";
@@ -46,12 +45,12 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
46
45
  this.store = options.store;
47
46
  this.otherParams = options.otherParams || {};
48
47
  if (Array.isArray((_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
49
- this.store.list = options.initialState.list;
48
+ this.store.list = options.initialState.list.slice().sort(function (a, b) {
49
+ return Number(b.sort) - Number(a.sort);
50
+ });
50
51
  this.core.effects.emit("".concat(this.name, ":changed"), this.store.list);
51
- this.storeChange();
52
52
  } else {
53
53
  this.store.list = [];
54
- this.store.productMap = new Map();
55
54
  this.store.selectProducts = [];
56
55
  }
57
56
  this.request = core.getPlugin('request');
@@ -70,28 +69,13 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
70
69
  key: "storeChange",
71
70
  value: function () {
72
71
  var _storeChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(path, value) {
73
- var _this$store$list,
74
- _this2 = this;
75
72
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
76
73
  while (1) switch (_context2.prev = _context2.next) {
77
74
  case 0:
78
- (_this$store$list = this.store.list) === null || _this$store$list === void 0 || _this$store$list.forEach(function (product) {
79
- var productModule = _this2.store.productMap.get("product-".concat(product.id));
80
- if (!productModule) {
81
- var newProductModule = new Product("product_".concat(product.id.toString()));
82
- _this2.core.registerModule(newProductModule, {
83
- initialState: product
84
- });
85
- _this2.store.productMap.set(product.id.toString(), newProductModule);
86
- } else {
87
- productModule.updateData(product);
88
- }
89
- });
90
- case 1:
91
75
  case "end":
92
76
  return _context2.stop();
93
77
  }
94
- }, _callee2, this);
78
+ }, _callee2);
95
79
  }));
96
80
  function storeChange(_x3, _x4) {
97
81
  return _storeChange.apply(this, arguments);
@@ -103,7 +87,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
103
87
  value: function () {
104
88
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
105
89
  var _this$otherParams;
106
- var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date, cacheId, userPlugin, customer_id, _userPlugin$get, productsData;
90
+ var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date, cacheId, userPlugin, customer_id, _userPlugin$get, productsData, sortedList;
107
91
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
108
92
  while (1) switch (_context3.prev = _context3.next) {
109
93
  case 0:
@@ -150,9 +134,12 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
150
134
  });
151
135
  case 6:
152
136
  productsData = _context3.sent;
153
- this.addProduct(productsData.data.list);
154
- return _context3.abrupt("return", productsData.data.list);
155
- case 9:
137
+ sortedList = (productsData.data.list || []).slice().sort(function (a, b) {
138
+ return Number(b.sort) - Number(a.sort);
139
+ });
140
+ this.addProduct(sortedList);
141
+ return _context3.abrupt("return", sortedList);
142
+ case 10:
156
143
  case "end":
157
144
  return _context3.stop();
158
145
  }
@@ -228,15 +215,11 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
228
215
  _context6.next = 2;
229
216
  return this.core.effects.emit(ProductListHooks.onGetProduct, this.store.list);
230
217
  case 2:
231
- product = this.store.productMap.get("".concat(id));
232
- if (!product) {
233
- _context6.next = 5;
234
- break;
235
- }
236
- return _context6.abrupt("return", product);
237
- case 5:
238
- return _context6.abrupt("return", undefined);
239
- case 6:
218
+ product = this.store.list.find(function (product) {
219
+ return product.id === id;
220
+ });
221
+ return _context6.abrupt("return", product ? cloneDeep(product) : undefined);
222
+ case 4:
240
223
  case "end":
241
224
  return _context6.stop();
242
225
  }
@@ -251,27 +234,30 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
251
234
  key: "addProduct",
252
235
  value: function () {
253
236
  var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(products) {
254
- var _this3 = this;
237
+ var _this2 = this;
255
238
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
256
239
  while (1) switch (_context7.prev = _context7.next) {
257
240
  case 0:
258
- // 加到 list 以后上面的storeChange 会自动初始化商品详情的 module 实例
259
241
  // list 需要根据 id 去重
260
242
  if (!this.store.list) {
261
243
  this.store.list = [];
262
244
  }
263
245
  products.forEach(function (n) {
264
- var index = _this3.store.list.findIndex(function (m) {
246
+ var index = _this2.store.list.findIndex(function (m) {
265
247
  return m.id === n.id;
266
248
  });
267
249
  if (index === -1) {
268
- _this3.store.list.push(n);
250
+ _this2.store.list.push(n);
269
251
  } else {
270
- _this3.store.list[index] = n;
252
+ _this2.store.list[index] = n;
271
253
  }
272
254
  });
273
- this.storeChange();
274
- case 3:
255
+ // 根据 sort 值做降序排序(数字越大越靠前)
256
+ this.store.list.sort(function (a, b) {
257
+ return Number(b.sort) - Number(a.sort);
258
+ });
259
+ this.core.effects.emit("".concat(this.name, ":changed"), this.store.list);
260
+ case 4:
275
261
  case "end":
276
262
  return _context7.stop();
277
263
  }
@@ -1,7 +1,6 @@
1
1
  import { ProductData } from '../Product/types';
2
2
  export interface ProductListData {
3
3
  list: ProductData[];
4
- productMap: Map<string, any>;
5
4
  selectProducts: ProductData[];
6
5
  }
7
6
  export declare enum ProductListHooks {
@@ -701,6 +701,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
701
701
  _params$useCache,
702
702
  useCache,
703
703
  tempProducts,
704
+ _this$store$currentPr,
704
705
  dateRange,
705
706
  tempStartDate,
706
707
  tempEndDate,
@@ -732,8 +733,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
732
733
  }
733
734
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
734
735
  if (this.store.currentProduct) {
735
- tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
736
- _schedule: this.store.currentProduct.getOtherParams()['schedule']
736
+ tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct), {}, {
737
+ _schedule: (_this$store$currentPr = this.store.currentProductMeta) === null || _this$store$currentPr === void 0 ? void 0 : _this$store$currentPr['schedule']
737
738
  })];
738
739
  }
739
740
  dateRange = this.store.date.getDateRange();
@@ -2278,41 +2279,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2278
2279
  key: "openProductDetail",
2279
2280
  value: function () {
2280
2281
  var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(productId) {
2281
- var targetProduct, targetProductData, newScheduleArr, dateRange;
2282
+ var targetProductData, newScheduleArr, dateRange;
2282
2283
  return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2283
2284
  while (1) switch (_context25.prev = _context25.next) {
2284
2285
  case 0:
2285
2286
  _context25.next = 2;
2286
2287
  return this.store.products.getProduct(productId);
2287
2288
  case 2:
2288
- targetProduct = _context25.sent;
2289
- if (!targetProduct) {
2290
- _context25.next = 16;
2289
+ targetProductData = _context25.sent;
2290
+ if (!targetProductData) {
2291
+ _context25.next = 17;
2291
2292
  break;
2292
2293
  }
2293
- targetProductData = targetProduct.getData();
2294
- this.store.currentProduct = targetProduct;
2294
+ this.store.currentProduct = targetProductData;
2295
+ this.store.currentProductMeta = {};
2295
2296
  // 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
2296
2297
  if (!targetProductData['schedule.ids']) {
2297
- _context25.next = 11;
2298
+ _context25.next = 12;
2298
2299
  break;
2299
2300
  }
2300
2301
  newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
2301
- targetProduct.setOtherParams('schedule', newScheduleArr);
2302
- _context25.next = 16;
2302
+ if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
2303
+ this.store.currentProductMeta.schedule = newScheduleArr;
2304
+ _context25.next = 17;
2303
2305
  break;
2304
- case 11:
2306
+ case 12:
2305
2307
  if (!targetProductData.duration) {
2306
- _context25.next = 16;
2308
+ _context25.next = 17;
2307
2309
  break;
2308
2310
  }
2309
2311
  dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
2310
2312
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
2311
- _context25.next = 15;
2313
+ _context25.next = 16;
2312
2314
  break;
2313
2315
  }
2314
2316
  return _context25.abrupt("return");
2315
- case 15:
2317
+ case 16:
2316
2318
  // this.store.date.getResourceDates({
2317
2319
  // query: {
2318
2320
  // start_date: dateRange[0].date,
@@ -2325,7 +2327,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2325
2327
  endDate: dateRange[dateRange.length - 1].date,
2326
2328
  products: [targetProductData]
2327
2329
  });
2328
- case 16:
2330
+ case 17:
2329
2331
  case "end":
2330
2332
  return _context25.stop();
2331
2333
  }
@@ -2339,8 +2341,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2339
2341
  }, {
2340
2342
  key: "closeProductDetail",
2341
2343
  value: function closeProductDetail() {
2342
- var _this$store$currentPr;
2343
- (_this$store$currentPr = this.store.currentProduct) === null || _this$store$currentPr === void 0 || _this$store$currentPr.setOtherParams('schedule', []);
2344
+ if (this.store.currentProductMeta) {
2345
+ this.store.currentProductMeta.schedule = [];
2346
+ }
2344
2347
  this.store.currentProduct = undefined;
2345
2348
  }
2346
2349
  }, {
@@ -2353,7 +2356,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2353
2356
  product = _ref10.product;
2354
2357
  var targetProduct = this.store.currentProduct;
2355
2358
  // 如果外面传递了product 优先用外面的
2356
- var targetProductData = product || (targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
2359
+ var targetProductData = product || targetProduct;
2357
2360
  var targetSchedules = [];
2358
2361
  // 如果外面传递了 scheduleIds,优先取入参
2359
2362
  if (scheduleIds !== null && scheduleIds !== void 0 && scheduleIds.length) {
@@ -2368,7 +2371,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2368
2371
  var cartItems = cloneDeep(this.store.cart.getItems());
2369
2372
  var resourcesMap = getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []);
2370
2373
  var selectedResources = getOthersSelectedResources(cartItems, '', resourcesMap);
2371
- var productResources = getResourcesByProduct(resourcesMap, resources || ((_this$store$currentPr2 = this.store.currentProduct) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.getData()) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.product_resource) === null || _this$store$currentPr2 === void 0 ? void 0 : _this$store$currentPr2.resources) || [], selectedResources, 1);
2374
+ var productResources = getResourcesByProduct(resourcesMap, resources || ((_this$store$currentPr2 = this.store.currentProduct) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.product_resource) === null || _this$store$currentPr2 === void 0 ? void 0 : _this$store$currentPr2.resources) || [], selectedResources, 1);
2372
2375
  var minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, date);
2373
2376
  var scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime);
2374
2377
  // 当前所有待选择资源的集合,先提出来,提升性能
@@ -2488,22 +2491,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2488
2491
  key: "getProductTypeById",
2489
2492
  value: function () {
2490
2493
  var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(id) {
2491
- var product;
2494
+ var productData, _productData$schedule;
2492
2495
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2493
2496
  while (1) switch (_context26.prev = _context26.next) {
2494
2497
  case 0:
2495
2498
  _context26.next = 2;
2496
2499
  return this.store.products.getProduct(id);
2497
2500
  case 2:
2498
- product = _context26.sent;
2499
- if (!product) {
2500
- _context26.next = 5;
2501
+ productData = _context26.sent;
2502
+ if (!productData) {
2503
+ _context26.next = 9;
2501
2504
  break;
2502
2505
  }
2503
- return _context26.abrupt("return", product.getProductType());
2504
- case 5:
2505
- return _context26.abrupt("return", 'normal');
2506
+ if (!productData.duration) {
2507
+ _context26.next = 6;
2508
+ break;
2509
+ }
2510
+ return _context26.abrupt("return", 'duration');
2506
2511
  case 6:
2512
+ if (!((_productData$schedule = productData['schedule.ids']) !== null && _productData$schedule !== void 0 && _productData$schedule.length)) {
2513
+ _context26.next = 8;
2514
+ break;
2515
+ }
2516
+ return _context26.abrupt("return", 'session');
2517
+ case 8:
2518
+ return _context26.abrupt("return", 'normal');
2519
+ case 9:
2520
+ return _context26.abrupt("return", 'normal');
2521
+ case 10:
2507
2522
  case "end":
2508
2523
  return _context26.stop();
2509
2524
  }
@@ -2675,7 +2690,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2675
2690
  key: "getAvailableDateForSessionOptimize",
2676
2691
  value: function () {
2677
2692
  var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2678
- var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2693
+ var _this$store$currentPr3, _this$store$currentPr4, _tempProducts;
2679
2694
  var params,
2680
2695
  startDate,
2681
2696
  endDate,
@@ -2721,7 +2736,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2721
2736
  endDate = tempEndDate;
2722
2737
 
2723
2738
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2724
- cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
2739
+ cache = (_this$store$currentPr3 = this.store.currentProductMeta) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3['timeSlotBySchedule'];
2725
2740
  if (!cache) {
2726
2741
  _context29.next = 13;
2727
2742
  break;
@@ -2737,8 +2752,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2737
2752
  });
2738
2753
  case 13:
2739
2754
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2740
- tempProducts = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getData();
2741
- schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
2755
+ tempProducts = this.store.currentProduct;
2756
+ schedule = (_this$store$currentPr4 = this.store.currentProductMeta) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4['schedule'];
2742
2757
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2743
2758
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2744
2759
  _context29.next = 19;
@@ -2898,17 +2913,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2898
2913
  this.store.date.setDateList(dates);
2899
2914
 
2900
2915
  // 缓存这次结果,以防后面他小幅度范围内去修改天数
2901
- (_this$store$currentPr6 = this.store.currentProduct) === null || _this$store$currentPr6 === void 0 || _this$store$currentPr6.setOtherParams('timeSlotBySchedule', {
2916
+ if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
2917
+ this.store.currentProductMeta.timeSlotBySchedule = {
2902
2918
  dateList: dates,
2903
2919
  firstAvailableDate: firstAvailableDate,
2904
2920
  startDate: startDate,
2905
2921
  endDate: dayjs(currentDate).format('YYYY-MM-DD')
2906
- });
2922
+ };
2907
2923
  return _context29.abrupt("return", {
2908
2924
  dateList: dates,
2909
2925
  firstAvailableDate: firstAvailableDate
2910
2926
  });
2911
- case 38:
2927
+ case 39:
2912
2928
  case "end":
2913
2929
  return _context29.stop();
2914
2930
  }
@@ -1,4 +1,4 @@
1
- import { ProductList, CartModule, Product, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from '../../modules';
1
+ import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from '../../modules';
2
2
  export interface BookingByStepState {
3
3
  cart: CartModule;
4
4
  summary: SummaryModule;
@@ -11,7 +11,8 @@ export interface BookingByStepState {
11
11
  accountList: AccountListModule;
12
12
  order: OrderModule;
13
13
  payment: PaymentModule;
14
- currentProduct?: Product;
14
+ currentProduct?: ProductData;
15
+ currentProductMeta?: Record<string, any>;
15
16
  schedule: ScheduleModule;
16
17
  }
17
18
  export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
@@ -1,5 +1,5 @@
1
1
  import { Module, PisellCore } from '../../types';
2
- import { Product, ProductData } from '../../modules/';
2
+ import { ProductData } from '../../modules/';
3
3
  import { BaseModule } from '../../modules/BaseModule';
4
4
  export * from './types';
5
5
  export declare class BuyTicketsImpl extends BaseModule implements Module {
@@ -16,7 +16,7 @@ export declare class BuyTicketsImpl extends BaseModule implements Module {
16
16
  loadProductsByCategory(categoryId: number): Promise<void>;
17
17
  destroy(): Promise<void>;
18
18
  getProducts(): Promise<ProductData[]>;
19
- getProduct(id: number): Promise<Product>;
19
+ getProduct(id: number): Promise<ProductData>;
20
20
  listSubmit(data: Record<string, any>): Promise<{
21
21
  status: boolean;
22
22
  data: any;
@@ -238,7 +238,7 @@ export var BuyTicketsImpl = /*#__PURE__*/function (_BaseModule) {
238
238
  }
239
239
  return _context6.abrupt("return", otherProduct);
240
240
  case 10:
241
- return _context6.abrupt("return", Promise.reject('Not fund product for id: ' + id));
241
+ throw new Error("Product not found: ".concat(id));
242
242
  case 11:
243
243
  case "end":
244
244
  return _context6.stop();
@@ -1,3 +1,3 @@
1
- import { Product } from "../../Product";
1
+ import { ProductData } from "../../Product";
2
2
  import { CartItem, IUpdateItemParams } from "../types";
3
- export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void, updateItemInitInfo: (item: IUpdateItemParams) => void): Promise<void>;
3
+ export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<ProductData | undefined>, updateCart: (item: IUpdateItemParams) => void, updateItemInitInfo: (item: IUpdateItemParams) => void): Promise<void>;
@@ -40,7 +40,7 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
40
40
  const cartProduct = await getProduct(
41
41
  item.id
42
42
  );
43
- let productInfo = cartProduct == null ? void 0 : cartProduct.getData();
43
+ let productInfo = cartProduct;
44
44
  if (!productInfo) {
45
45
  productInfo = item._productOrigin;
46
46
  }
@@ -1,6 +1,5 @@
1
1
  import { Module, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Product } from '../Product';
4
3
  import { ProductData } from '../Product/types';
5
4
  export * from './types';
6
5
  export declare class ProductList extends BaseModule implements Module {
@@ -26,7 +25,7 @@ export declare class ProductList extends BaseModule implements Module {
26
25
  channel?: string;
27
26
  }): Promise<any>;
28
27
  getProducts(): Promise<ProductData[]>;
29
- getProduct(id: number): Promise<Product | undefined>;
28
+ getProduct(id: number): Promise<ProductData | undefined>;
30
29
  addProduct(products: ProductData[]): Promise<void>;
31
30
  selectProducts(products: ProductData[]): Promise<void>;
32
31
  }
@@ -24,7 +24,6 @@ __export(ProductList_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(ProductList_exports);
26
26
  var import_BaseModule = require("../BaseModule");
27
- var import_Product = require("../Product");
28
27
  var import_types = require("./types");
29
28
  var import_lodash_es = require("lodash-es");
30
29
  __reExport(ProductList_exports, require("./types"), module.exports);
@@ -41,30 +40,15 @@ var ProductList = class extends import_BaseModule.BaseModule {
41
40
  this.store = options.store;
42
41
  this.otherParams = options.otherParams || {};
43
42
  if (Array.isArray((_a = options.initialState) == null ? void 0 : _a.list)) {
44
- this.store.list = options.initialState.list;
43
+ this.store.list = options.initialState.list.slice().sort((a, b) => Number(b.sort) - Number(a.sort));
45
44
  this.core.effects.emit(`${this.name}:changed`, this.store.list);
46
- this.storeChange();
47
45
  } else {
48
46
  this.store.list = [];
49
- this.store.productMap = /* @__PURE__ */ new Map();
50
47
  this.store.selectProducts = [];
51
48
  }
52
49
  this.request = core.getPlugin("request");
53
50
  }
54
51
  async storeChange(path, value) {
55
- var _a;
56
- (_a = this.store.list) == null ? void 0 : _a.forEach((product) => {
57
- const productModule = this.store.productMap.get(`product-${product.id}`);
58
- if (!productModule) {
59
- const newProductModule = new import_Product.Product(
60
- `product_${product.id.toString()}`
61
- );
62
- this.core.registerModule(newProductModule, { initialState: product });
63
- this.store.productMap.set(product.id.toString(), newProductModule);
64
- } else {
65
- productModule.updateData(product);
66
- }
67
- });
68
52
  }
69
53
  async loadProducts({
70
54
  category_ids = [],
@@ -109,8 +93,9 @@ var ProductList = class extends import_BaseModule.BaseModule {
109
93
  },
110
94
  { useCache: true }
111
95
  );
112
- this.addProduct(productsData.data.list);
113
- return productsData.data.list;
96
+ const sortedList = (productsData.data.list || []).slice().sort((a, b) => Number(b.sort) - Number(a.sort));
97
+ this.addProduct(sortedList);
98
+ return sortedList;
114
99
  }
115
100
  async loadProductsPrice({
116
101
  ids = [],
@@ -142,10 +127,8 @@ var ProductList = class extends import_BaseModule.BaseModule {
142
127
  import_types.ProductListHooks.onGetProduct,
143
128
  this.store.list
144
129
  );
145
- const product = this.store.productMap.get(`${id}`);
146
- if (product)
147
- return product;
148
- return void 0;
130
+ const product = this.store.list.find((product2) => product2.id === id);
131
+ return product ? (0, import_lodash_es.cloneDeep)(product) : void 0;
149
132
  }
150
133
  async addProduct(products) {
151
134
  if (!this.store.list) {
@@ -159,7 +142,8 @@ var ProductList = class extends import_BaseModule.BaseModule {
159
142
  this.store.list[index] = n;
160
143
  }
161
144
  });
162
- this.storeChange();
145
+ this.store.list.sort((a, b) => Number(b.sort) - Number(a.sort));
146
+ this.core.effects.emit(`${this.name}:changed`, this.store.list);
163
147
  }
164
148
  async selectProducts(products) {
165
149
  this.store.selectProducts = products;
@@ -1,7 +1,6 @@
1
1
  import { ProductData } from '../Product/types';
2
2
  export interface ProductListData {
3
3
  list: ProductData[];
4
- productMap: Map<string, any>;
5
4
  selectProducts: ProductData[];
6
5
  }
7
6
  export declare enum ProductListHooks {
@@ -390,7 +390,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
390
390
  }
391
391
  // 获取商品/服务的可用日期
392
392
  async getAvailableDate(params = {}) {
393
- var _a, _b, _c;
393
+ var _a, _b, _c, _d;
394
394
  let { products, startDate, endDate, type, useCache = true } = params;
395
395
  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"))) {
396
396
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
@@ -407,14 +407,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
407
407
  if (this.store.currentProduct) {
408
408
  tempProducts = [
409
409
  {
410
- ...this.store.currentProduct.getData(),
411
- _schedule: this.store.currentProduct.getOtherParams()["schedule"]
410
+ ...this.store.currentProduct,
411
+ _schedule: (_a = this.store.currentProductMeta) == null ? void 0 : _a["schedule"]
412
412
  }
413
413
  ];
414
414
  }
415
415
  let dateRange = this.store.date.getDateRange();
416
- const tempStartDate = startDate || ((_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.date);
417
- const tempEndDate = endDate || ((_b = dateRange == null ? void 0 : dateRange[1]) == null ? void 0 : _b.date) || ((_c = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _c.date);
416
+ const tempStartDate = startDate || ((_b = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _b.date);
417
+ const tempEndDate = endDate || ((_c = dateRange == null ? void 0 : dateRange[1]) == null ? void 0 : _c.date) || ((_d = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _d.date);
418
418
  if (!tempProducts.length) {
419
419
  return [];
420
420
  }
@@ -1596,15 +1596,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1596
1596
  }
1597
1597
  // 打开某个商品详情的弹窗,OS 层这边会记录当前选中的商品,适用于 session 类商品预约
1598
1598
  async openProductDetail(productId) {
1599
- const targetProduct = await this.store.products.getProduct(productId);
1600
- if (targetProduct) {
1601
- const targetProductData = targetProduct.getData();
1602
- this.store.currentProduct = targetProduct;
1599
+ const targetProductData = await this.store.products.getProduct(productId);
1600
+ if (targetProductData) {
1601
+ this.store.currentProduct = targetProductData;
1602
+ this.store.currentProductMeta = {};
1603
1603
  if (targetProductData["schedule.ids"]) {
1604
1604
  const newScheduleArr = this.getScheduleDataByIds(
1605
1605
  targetProductData["schedule.ids"]
1606
1606
  );
1607
- targetProduct.setOtherParams("schedule", newScheduleArr);
1607
+ if (!this.store.currentProductMeta)
1608
+ this.store.currentProductMeta = {};
1609
+ this.store.currentProductMeta.schedule = newScheduleArr;
1608
1610
  } else if (targetProductData.duration) {
1609
1611
  const dateRange = this.store.date.getDateRange();
1610
1612
  if (!(dateRange == null ? void 0 : dateRange.length))
@@ -1618,8 +1620,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1618
1620
  }
1619
1621
  }
1620
1622
  closeProductDetail() {
1621
- var _a;
1622
- (_a = this.store.currentProduct) == null ? void 0 : _a.setOtherParams("schedule", []);
1623
+ if (this.store.currentProductMeta) {
1624
+ this.store.currentProductMeta.schedule = [];
1625
+ }
1623
1626
  this.store.currentProduct = void 0;
1624
1627
  }
1625
1628
  getTimeslotBySchedule({
@@ -1628,9 +1631,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1628
1631
  resources,
1629
1632
  product
1630
1633
  }) {
1631
- var _a, _b, _c, _d, _e, _f;
1634
+ var _a, _b, _c, _d, _e;
1632
1635
  const targetProduct = this.store.currentProduct;
1633
- const targetProductData = product || (targetProduct == null ? void 0 : targetProduct.getData());
1636
+ const targetProductData = product || targetProduct;
1634
1637
  let targetSchedules = [];
1635
1638
  if (scheduleIds == null ? void 0 : scheduleIds.length) {
1636
1639
  targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
@@ -1650,7 +1653,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1650
1653
  );
1651
1654
  const productResources = (0, import_resources.getResourcesByProduct)(
1652
1655
  resourcesMap,
1653
- resources || ((_c = (_b = (_a = this.store.currentProduct) == null ? void 0 : _a.getData()) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
1656
+ resources || ((_b = (_a = this.store.currentProduct) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1654
1657
  selectedResources,
1655
1658
  1
1656
1659
  );
@@ -1671,9 +1674,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1671
1674
  return -1;
1672
1675
  return 0;
1673
1676
  });
1674
- const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find(
1677
+ const firstEnabledResourceId = (_e = (_d = (_c = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
1675
1678
  (n) => n.status === 1
1676
- )) == null ? void 0 : _f.id;
1679
+ )) == null ? void 0 : _e.id;
1677
1680
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1678
1681
  const resourcesUseableMap = {};
1679
1682
  let count = 0;
@@ -1747,9 +1750,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1747
1750
  return this.otherData[key];
1748
1751
  }
1749
1752
  async getProductTypeById(id) {
1750
- const product = await this.store.products.getProduct(id);
1751
- if (product) {
1752
- return product.getProductType();
1753
+ var _a;
1754
+ const productData = await this.store.products.getProduct(id);
1755
+ if (productData) {
1756
+ if (productData.duration) {
1757
+ return "duration";
1758
+ }
1759
+ if ((_a = productData["schedule.ids"]) == null ? void 0 : _a.length) {
1760
+ return "session";
1761
+ }
1762
+ return "normal";
1753
1763
  }
1754
1764
  return "normal";
1755
1765
  }
@@ -1910,7 +1920,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1910
1920
  return results;
1911
1921
  }
1912
1922
  async getAvailableDateForSessionOptimize(params = {}) {
1913
- var _a, _b, _c, _d, _e, _f;
1923
+ var _a, _b, _c, _d;
1914
1924
  let { startDate, endDate } = params;
1915
1925
  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"))) {
1916
1926
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
@@ -1926,7 +1936,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1926
1936
  tempEndDate = endDate || "";
1927
1937
  }
1928
1938
  endDate = tempEndDate;
1929
- const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
1939
+ const cache = (_a = this.store.currentProductMeta) == null ? void 0 : _a["timeSlotBySchedule"];
1930
1940
  if (cache) {
1931
1941
  if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
1932
1942
  this.store.date.setDateList(cache.dateList);
@@ -1937,8 +1947,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1937
1947
  }
1938
1948
  }
1939
1949
  let tempProducts;
1940
- tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
1941
- const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
1950
+ tempProducts = this.store.currentProduct;
1951
+ const schedule = (_b = this.store.currentProductMeta) == null ? void 0 : _b["schedule"];
1942
1952
  const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
1943
1953
  schedule,
1944
1954
  startDate || "",
@@ -1955,7 +1965,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1955
1965
  let dates = [];
1956
1966
  let currentDate = (0, import_dayjs.default)(startDate);
1957
1967
  let firstAvailableDate = "";
1958
- const openResources = ((_e = (_d = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.filter(
1968
+ const openResources = ((_d = (_c = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.filter(
1959
1969
  (m) => m.status === 1
1960
1970
  )) || [];
1961
1971
  const allProductResources = (0, import_resources.sortCombinedResources)(res.data);
@@ -2056,12 +2066,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2056
2066
  }
2057
2067
  dates = (0, import_utils3.handleAvailableDateByResource)(res.data, dates);
2058
2068
  this.store.date.setDateList(dates);
2059
- (_f = this.store.currentProduct) == null ? void 0 : _f.setOtherParams("timeSlotBySchedule", {
2069
+ if (!this.store.currentProductMeta)
2070
+ this.store.currentProductMeta = {};
2071
+ this.store.currentProductMeta.timeSlotBySchedule = {
2060
2072
  dateList: dates,
2061
2073
  firstAvailableDate,
2062
2074
  startDate,
2063
2075
  endDate: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD")
2064
- });
2076
+ };
2065
2077
  return {
2066
2078
  dateList: dates,
2067
2079
  firstAvailableDate
@@ -1,4 +1,4 @@
1
- import { ProductList, CartModule, Product, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from '../../modules';
1
+ import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from '../../modules';
2
2
  export interface BookingByStepState {
3
3
  cart: CartModule;
4
4
  summary: SummaryModule;
@@ -11,7 +11,8 @@ export interface BookingByStepState {
11
11
  accountList: AccountListModule;
12
12
  order: OrderModule;
13
13
  payment: PaymentModule;
14
- currentProduct?: Product;
14
+ currentProduct?: ProductData;
15
+ currentProductMeta?: Record<string, any>;
15
16
  schedule: ScheduleModule;
16
17
  }
17
18
  export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
@@ -1,5 +1,5 @@
1
1
  import { Module, PisellCore } from '../../types';
2
- import { Product, ProductData } from '../../modules/';
2
+ import { ProductData } from '../../modules/';
3
3
  import { BaseModule } from '../../modules/BaseModule';
4
4
  export * from './types';
5
5
  export declare class BuyTicketsImpl extends BaseModule implements Module {
@@ -16,7 +16,7 @@ export declare class BuyTicketsImpl extends BaseModule implements Module {
16
16
  loadProductsByCategory(categoryId: number): Promise<void>;
17
17
  destroy(): Promise<void>;
18
18
  getProducts(): Promise<ProductData[]>;
19
- getProduct(id: number): Promise<Product>;
19
+ getProduct(id: number): Promise<ProductData>;
20
20
  listSubmit(data: Record<string, any>): Promise<{
21
21
  status: boolean;
22
22
  data: any;
@@ -98,7 +98,7 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
98
98
  return mainProduct;
99
99
  if (otherProduct)
100
100
  return otherProduct;
101
- return Promise.reject("Not fund product for id: " + id);
101
+ throw new Error(`Product not found: ${id}`);
102
102
  }
103
103
  // 商品列表页提交
104
104
  async listSubmit(data) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.56",
4
+ "version": "3.0.58",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",