@pisell/pisellos 0.0.208 → 0.0.209

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) {
@@ -79,13 +79,18 @@ function _updateAllCartItemPrice() {
79
79
  return n;
80
80
  });
81
81
  }
82
+ // 先把商品原始信息更新了
83
+ updateItemInitInfo({
84
+ _id: item._id,
85
+ product: productInfo
86
+ });
82
87
  updateCart({
83
88
  _id: item._id,
84
89
  product: productInfo,
85
90
  bundle: bundle,
86
91
  options: item._optionsOrigin
87
92
  });
88
- case 13:
93
+ case 14:
89
94
  case "end":
90
95
  return _context.stop();
91
96
  }
@@ -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: params.platform === 'pc' ? 'PC' : '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: [],
@@ -427,7 +427,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
427
427
  }));
428
428
  }
429
429
  for (var _i = 0; _i < splitCount; _i++) {
430
- var _originProduct$_produ, _product$discount_lis11;
430
+ var _product$discount_lis11, _originProduct$_produ;
431
431
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
432
432
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[_i];
433
433
  // 标记优惠券为已使用
@@ -438,14 +438,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
438
438
 
439
439
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
440
440
  var productOriginTotal = product.origin_total || product.total || 0;
441
+ // 如果当前 product 有 discount_list,则先从 origin_total 拿
442
+ if ((_product$discount_lis11 = product.discount_list) !== null && _product$discount_lis11 !== void 0 && _product$discount_lis11.length && product.origin_total) {
443
+ productOriginTotal = product.origin_total;
444
+ }
441
445
  // 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
442
446
  if (Number((originProduct === null || originProduct === void 0 || (_originProduct$_produ = originProduct._productInit) === null || _originProduct$_produ === void 0 ? void 0 : _originProduct$_produ.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
443
447
  productOriginTotal = product.total;
444
448
  }
445
- // 如果当前 product 有 discount_list,则必须从 origin_total 拿
446
- if ((_product$discount_lis11 = product.discount_list) !== null && _product$discount_lis11 !== void 0 && _product$discount_lis11.length && product.origin_total) {
447
- productOriginTotal = product.origin_total;
448
- }
449
449
 
450
450
  // 计算使用折扣卡/商品券以后,单个商品的总 total
451
451
  var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(productOriginTotal).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(productOriginTotal)).toNumber();
@@ -378,6 +378,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
378
378
  return _this3.store.products.getProduct(id);
379
379
  }, function (params) {
380
380
  return _this3.store.cart.updateItem(params);
381
+ }, function (params) {
382
+ return _this3.store.cart.updateItemInitInfo(params);
381
383
  });
382
384
  case 10:
383
385
  this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
@@ -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,7 +33,7 @@ __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);
@@ -81,6 +81,10 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
81
81
  return n;
82
82
  });
83
83
  }
84
+ updateItemInitInfo({
85
+ _id: item._id,
86
+ product: productInfo
87
+ });
84
88
  updateCart({
85
89
  _id: item._id,
86
90
  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: params.platform === "pc" ? "PC" : "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: [],
@@ -302,12 +302,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
302
302
  usedDiscounts.set(selectedDiscount2.id, true);
303
303
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
304
304
  let productOriginTotal = product.origin_total || product.total || 0;
305
- if (Number(((_g = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _g.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
306
- productOriginTotal = product.total;
307
- }
308
- if (((_h = product.discount_list) == null ? void 0 : _h.length) && product.origin_total) {
305
+ if (((_g = product.discount_list) == null ? void 0 : _g.length) && product.origin_total) {
309
306
  productOriginTotal = product.origin_total;
310
307
  }
308
+ if (Number(((_h = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _h.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
309
+ productOriginTotal = product.total;
310
+ }
311
311
  const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(productOriginTotal).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(productOriginTotal)).toNumber();
312
312
  const discountDetail = {
313
313
  amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
@@ -258,7 +258,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
258
258
  cartItems,
259
259
  res,
260
260
  (id) => this.store.products.getProduct(id),
261
- (params) => this.store.cart.updateItem(params)
261
+ (params) => this.store.cart.updateItem(params),
262
+ (params) => this.store.cart.updateItemInitInfo(params)
262
263
  );
263
264
  this.core.effects.emit(
264
265
  `${this.store.cart.name}:onUpdateQuotationPrice`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.208",
4
+ "version": "0.0.209",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",