@pisell/pisellos 3.0.49 → 3.0.51

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.
@@ -28,6 +28,7 @@ export declare class CartModule extends BaseModule implements Module, CartModule
28
28
  * 更新购物车信息
29
29
  */
30
30
  updateItem(params: IUpdateItemParams): Promise<void>;
31
+ updateItemInitInfo(params: IUpdateItemParams): Promise<void>;
31
32
  /**
32
33
  * 格式化数据到购物车
33
34
  */
@@ -211,11 +211,39 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
211
211
  return _updateItem.apply(this, arguments);
212
212
  }
213
213
  return updateItem;
214
+ }() // 更新购物车中商品的初始信息
215
+ // 为什么会有这个操作,主要服务于报价单和商品券
216
+ // 商品券那边会使用 init 的 price 做计算,而报价单那边就需要修改 init 的 price 来辅助商品计算
217
+ )
218
+ }, {
219
+ key: "updateItemInitInfo",
220
+ value: function () {
221
+ var _updateItemInitInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
222
+ var _id, product, cartItem;
223
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
224
+ while (1) switch (_context4.prev = _context4.next) {
225
+ case 0:
226
+ _id = params._id, product = params.product;
227
+ cartItem = this.store.list.find(function (i) {
228
+ return i._id === _id;
229
+ });
230
+ if (cartItem) {
231
+ cartItem._productInit = cloneDeep(product);
232
+ }
233
+ case 3:
234
+ case "end":
235
+ return _context4.stop();
236
+ }
237
+ }, _callee4, this);
238
+ }));
239
+ function updateItemInitInfo(_x5) {
240
+ return _updateItemInitInfo.apply(this, arguments);
241
+ }
242
+ return updateItemInitInfo;
214
243
  }()
215
244
  /**
216
245
  * 格式化数据到购物车
217
246
  */
218
- )
219
247
  }, {
220
248
  key: "formatCartItem",
221
249
  value: function formatCartItem(params) {
@@ -305,18 +333,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
305
333
  }, {
306
334
  key: "batchSetItems",
307
335
  value: (function () {
308
- var _batchSetItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(items) {
309
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
310
- while (1) switch (_context4.prev = _context4.next) {
336
+ var _batchSetItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(items) {
337
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
338
+ while (1) switch (_context5.prev = _context5.next) {
311
339
  case 0:
312
340
  this.store.list = _toConsumableArray(items || []);
313
341
  case 1:
314
342
  case "end":
315
- return _context4.stop();
343
+ return _context5.stop();
316
344
  }
317
- }, _callee4, this);
345
+ }, _callee5, this);
318
346
  }));
319
- function batchSetItems(_x5) {
347
+ function batchSetItems(_x6) {
320
348
  return _batchSetItems.apply(this, arguments);
321
349
  }
322
350
  return batchSetItems;
@@ -359,24 +387,24 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
359
387
  }, {
360
388
  key: "removeItem",
361
389
  value: (function () {
362
- var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id) {
390
+ var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
363
391
  var items;
364
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
365
- while (1) switch (_context5.prev = _context5.next) {
392
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
393
+ while (1) switch (_context6.prev = _context6.next) {
366
394
  case 0:
367
395
  items = this.store.list.filter(function (i) {
368
396
  return i._id !== id;
369
397
  });
370
398
  this.store.list = items;
371
- _context5.next = 4;
399
+ _context6.next = 4;
372
400
  return this.core.effects.emit("".concat(this.name, ":onRemoveItem"), items);
373
401
  case 4:
374
402
  case "end":
375
- return _context5.stop();
403
+ return _context6.stop();
376
404
  }
377
- }, _callee5, this);
405
+ }, _callee6, this);
378
406
  }));
379
- function removeItem(_x6) {
407
+ function removeItem(_x7) {
380
408
  return _removeItem.apply(this, arguments);
381
409
  }
382
410
  return removeItem;
@@ -1,3 +1,3 @@
1
1
  import { Product } 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): Promise<void>;
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>;
@@ -11,11 +11,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
11
11
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
12
12
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
13
  import Decimal from "decimal.js";
14
- export function updateAllCartItemPrice(_x, _x2, _x3, _x4) {
14
+ export function updateAllCartItemPrice(_x, _x2, _x3, _x4, _x5) {
15
15
  return _updateAllCartItemPrice.apply(this, arguments);
16
16
  }
17
17
  function _updateAllCartItemPrice() {
18
- _updateAllCartItemPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cartItems, priceData, getProduct, updateCart) {
18
+ _updateAllCartItemPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cartItems, priceData, getProduct, updateCart, updateItemInitInfo) {
19
19
  var _iterator, _step, _loop;
20
20
  return _regeneratorRuntime().wrap(function _callee$(_context2) {
21
21
  while (1) switch (_context2.prev = _context2.next) {
@@ -37,6 +37,9 @@ function _updateAllCartItemPrice() {
37
37
  case 4:
38
38
  cartProduct = _context.sent;
39
39
  productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
40
+ if (!productInfo) {
41
+ productInfo = item._productOrigin;
42
+ }
40
43
  bundle = item._bundleOrigin;
41
44
  productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
42
45
  productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
@@ -79,13 +82,18 @@ function _updateAllCartItemPrice() {
79
82
  return n;
80
83
  });
81
84
  }
85
+ // 先把商品原始信息更新了
86
+ updateItemInitInfo({
87
+ _id: item._id,
88
+ product: productInfo
89
+ });
82
90
  updateCart({
83
91
  _id: item._id,
84
92
  product: productInfo,
85
93
  bundle: bundle,
86
94
  options: item._optionsOrigin
87
95
  });
88
- case 13:
96
+ case 15:
89
97
  case "end":
90
98
  return _context.stop();
91
99
  }
@@ -62,9 +62,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
62
62
  key: "createOrder",
63
63
  value: function createOrder(params) {
64
64
  var order = {
65
- type: params.type || 'appointment_booking',
65
+ type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
66
66
  // 要从外面拿,virtual
67
- platform: 'H5',
67
+ platform: (params === null || params === void 0 ? void 0 : params.platform) === 'pc' ? 'PC' : 'H5',
68
68
  sales_channel: 'my_pisel',
69
69
  order_sales_channel: 'online_store',
70
70
  bookings: [],
@@ -15,6 +15,7 @@ export interface CommitOrderParams {
15
15
  query: {
16
16
  cartItems: CartItem[];
17
17
  type: 'virtual' | 'appointment_booking';
18
+ platform?: 'pc' | 'h5';
18
19
  };
19
20
  }
20
21
  /**
@@ -165,8 +165,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
165
165
  var _this3 = this;
166
166
  var discountList = _ref2.discountList,
167
167
  productList = _ref2.productList;
168
- // debugger
169
-
170
168
  // 识别出来是不是在编辑的界面里又新增了商品
171
169
  // 这种情况下,如果有可用的优惠券,也会自动勾选上
172
170
  var isEditModeAddNewProduct = productList.find(function (n) {
@@ -21,6 +21,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
21
21
  private otherParams;
22
22
  private cacheId;
23
23
  private otherData;
24
+ private platform;
24
25
  initialize(core: PisellCore, options: any): Promise<void>;
25
26
  initStep(stepList: (keyof BookingByStepState)[]): void;
26
27
  getCurrentStep(): {
@@ -61,15 +61,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
61
61
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
62
62
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
63
63
  _defineProperty(_assertThisInitialized(_this), "otherData", {});
64
+ // 提供给 UI 层的临时数据存储,会进缓存
65
+ _defineProperty(_assertThisInitialized(_this), "platform", void 0);
64
66
  return _this;
65
67
  }
66
68
  _createClass(BookingByStepImpl, [{
67
69
  key: "initialize",
68
- value: // 提供给 UI 层的临时数据存储,会进缓存
70
+ value: // 平台类型,用于判断是 PC / H5
69
71
  function () {
70
72
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
71
73
  var _this$otherParams,
72
74
  _this$otherParams2,
75
+ _this$otherParams3,
73
76
  _this2 = this;
74
77
  var targetCacheData, sessionData, _data$this$otherParam, data, moduleArr;
75
78
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -99,7 +102,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
99
102
  // 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
100
103
  targetCacheData = {};
101
104
  this.cacheId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.cacheId;
102
- if ((_this$otherParams2 = this.otherParams) !== null && _this$otherParams2 !== void 0 && _this$otherParams2.cacheId) {
105
+ this.platform = (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.platform;
106
+ if ((_this$otherParams3 = this.otherParams) !== null && _this$otherParams3 !== void 0 && _this$otherParams3.cacheId) {
103
107
  sessionData = this.window.sessionStorage.getItem(this.name);
104
108
  if (sessionData) {
105
109
  data = JSON.parse(sessionData); // 匹配 cacheid,如果匹配不到,直接把 sessionData 清掉即可
@@ -128,7 +132,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
128
132
  });
129
133
  this.store.schedule.loadAllSchedule();
130
134
  this.core.effects.emit(BookingByStepHooks.onInited, {});
131
- case 18:
135
+ case 19:
132
136
  case "end":
133
137
  return _context.stop();
134
138
  }
@@ -374,6 +378,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
374
378
  return _this3.store.products.getProduct(id);
375
379
  }, function (params) {
376
380
  return _this3.store.cart.updateItem(params);
381
+ }, function (params) {
382
+ return _this3.store.cart.updateItemInitInfo(params);
377
383
  });
378
384
  case 10:
379
385
  this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
@@ -989,7 +995,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
989
995
  return _context19.abrupt("return", this.store.order.submitOrder({
990
996
  query: {
991
997
  cartItems: newCartItems,
992
- type: type
998
+ type: type,
999
+ platform: this.platform
993
1000
  }
994
1001
  }));
995
1002
  case 6:
@@ -28,6 +28,7 @@ export declare class CartModule extends BaseModule implements Module, CartModule
28
28
  * 更新购物车信息
29
29
  */
30
30
  updateItem(params: IUpdateItemParams): Promise<void>;
31
+ updateItemInitInfo(params: IUpdateItemParams): Promise<void>;
31
32
  /**
32
33
  * 格式化数据到购物车
33
34
  */
@@ -119,6 +119,16 @@ var CartModule = class extends import_BaseModule.BaseModule {
119
119
  console.error("[CartModule] 更新购物车商品失败", error);
120
120
  }
121
121
  }
122
+ // 更新购物车中商品的初始信息
123
+ // 为什么会有这个操作,主要服务于报价单和商品券
124
+ // 商品券那边会使用 init 的 price 做计算,而报价单那边就需要修改 init 的 price 来辅助商品计算
125
+ async updateItemInitInfo(params) {
126
+ const { _id, product } = params;
127
+ const cartItem = this.store.list.find((i) => i._id === _id);
128
+ if (cartItem) {
129
+ cartItem._productInit = (0, import_lodash_es.cloneDeep)(product);
130
+ }
131
+ }
122
132
  /**
123
133
  * 格式化数据到购物车
124
134
  */
@@ -1,3 +1,3 @@
1
1
  import { Product } 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): Promise<void>;
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>;
@@ -33,14 +33,17 @@ __export(changePrice_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(changePrice_exports);
35
35
  var import_decimal = __toESM(require("decimal.js"));
36
- async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart) {
36
+ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart, updateItemInitInfo) {
37
37
  var _a, _b;
38
38
  for (const item of cartItems) {
39
39
  const targetProduct = priceData.find((n) => n.id === item.id);
40
40
  const cartProduct = await getProduct(
41
41
  item.id
42
42
  );
43
- const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
43
+ let productInfo = cartProduct == null ? void 0 : cartProduct.getData();
44
+ if (!productInfo) {
45
+ productInfo = item._productOrigin;
46
+ }
44
47
  let bundle = item._bundleOrigin;
45
48
  productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
46
49
  productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
@@ -81,6 +84,10 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
81
84
  return n;
82
85
  });
83
86
  }
87
+ updateItemInitInfo({
88
+ _id: item._id,
89
+ product: productInfo
90
+ });
84
91
  updateCart({
85
92
  _id: item._id,
86
93
  product: productInfo,
@@ -39,9 +39,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
39
39
  createOrder(params) {
40
40
  var _a;
41
41
  const order = {
42
- type: params.type || "appointment_booking",
42
+ type: (params == null ? void 0 : params.type) || "appointment_booking",
43
43
  // 要从外面拿,virtual
44
- platform: "H5",
44
+ platform: (params == null ? void 0 : params.platform) === "pc" ? "PC" : "H5",
45
45
  sales_channel: "my_pisel",
46
46
  order_sales_channel: "online_store",
47
47
  bookings: [],
@@ -74,7 +74,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
74
74
  }
75
75
  });
76
76
  if (order.type === "appointment_booking") {
77
- const firstAppointmentCartItem = (_a = params.cartItems.filter((n) => !(0, import_utils2.isNormalProduct)(n._productOrigin))) == null ? void 0 : _a[0];
77
+ const firstAppointmentCartItem = (_a = params.cartItems.filter(
78
+ (n) => !(0, import_utils2.isNormalProduct)(n._productOrigin)
79
+ )) == null ? void 0 : _a[0];
78
80
  if (firstAppointmentCartItem) {
79
81
  order.schedule_date = firstAppointmentCartItem.start_date + " " + firstAppointmentCartItem.start_time + ":00";
80
82
  }
@@ -15,6 +15,7 @@ export interface CommitOrderParams {
15
15
  query: {
16
16
  cartItems: CartItem[];
17
17
  type: 'virtual' | 'appointment_booking';
18
+ platform?: 'pc' | 'h5';
18
19
  };
19
20
  }
20
21
  /**
@@ -21,6 +21,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
21
21
  private otherParams;
22
22
  private cacheId;
23
23
  private otherData;
24
+ private platform;
24
25
  initialize(core: PisellCore, options: any): Promise<void>;
25
26
  initStep(stepList: (keyof BookingByStepState)[]): void;
26
27
  getCurrentStep(): {
@@ -58,9 +58,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
58
58
  this.otherParams = {};
59
59
  this.otherData = {};
60
60
  }
61
- // 提供给 UI 层的临时数据存储,会进缓存
61
+ // 平台类型,用于判断是 PC / H5
62
62
  async initialize(core, options) {
63
- var _a, _b, _c, _d;
63
+ var _a, _b, _c, _d, _e;
64
64
  this.core = core;
65
65
  this.store = options.store || {};
66
66
  this.otherParams = options.otherParams || {};
@@ -76,12 +76,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
76
76
  }
77
77
  let targetCacheData = {};
78
78
  this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
79
- if ((_b = this.otherParams) == null ? void 0 : _b.cacheId) {
79
+ this.platform = (_b = this.otherParams) == null ? void 0 : _b.platform;
80
+ if ((_c = this.otherParams) == null ? void 0 : _c.cacheId) {
80
81
  const sessionData = this.window.sessionStorage.getItem(this.name);
81
82
  if (sessionData) {
82
83
  const data = JSON.parse(sessionData);
83
84
  targetCacheData = data[this.otherParams.cacheId];
84
- this.otherData = ((_d = (_c = data[this.otherParams.cacheId]) == null ? void 0 : _c[this.name]) == null ? void 0 : _d["otherData"]) || {};
85
+ this.otherData = ((_e = (_d = data[this.otherParams.cacheId]) == null ? void 0 : _d[this.name]) == null ? void 0 : _e["otherData"]) || {};
85
86
  }
86
87
  }
87
88
  const moduleArr = [
@@ -258,7 +259,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
258
259
  cartItems,
259
260
  res,
260
261
  (id) => this.store.products.getProduct(id),
261
- (params) => this.store.cart.updateItem(params)
262
+ (params) => this.store.cart.updateItem(params),
263
+ (params) => this.store.cart.updateItemInitInfo(params)
262
264
  );
263
265
  this.core.effects.emit(
264
266
  `${this.store.cart.name}:onUpdateQuotationPrice`,
@@ -529,7 +531,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
529
531
  type = "virtual";
530
532
  }
531
533
  return this.store.order.submitOrder({
532
- query: { cartItems: newCartItems, type }
534
+ query: {
535
+ cartItems: newCartItems,
536
+ type,
537
+ platform: this.platform
538
+ }
533
539
  });
534
540
  }
535
541
  // 拉起支付模块
@@ -827,7 +833,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
827
833
  if (!resources.length) {
828
834
  const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
829
835
  if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
830
- const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
836
+ const dateResources = this.store.date.getResourcesListByDate(
837
+ firstDateCartItem.start_date
838
+ );
831
839
  resources.push(...dateResources || []);
832
840
  } else {
833
841
  const dateList = this.store.date.getDateList();
@@ -1051,7 +1059,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1051
1059
  if (!AllResources.length) {
1052
1060
  const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
1053
1061
  if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
1054
- const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
1062
+ const dateResources = this.store.date.getResourcesListByDate(
1063
+ firstDateCartItem.start_date
1064
+ );
1055
1065
  AllResources.push(...dateResources || []);
1056
1066
  } else {
1057
1067
  const dateList = this.store.date.getDateList();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.49",
4
+ "version": "3.0.51",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",