@pisell/pisellos 1.0.42 → 1.0.46

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
  }
@@ -22,7 +22,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
22
22
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
23
23
  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); }
24
24
  import { BaseModule } from "../BaseModule";
25
- import { generateDuration } from "./utils";
25
+ import { generateDuration, mergeRelationForms } from "./utils";
26
26
  import { isNormalProduct } from "../Product/utils";
27
27
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
28
28
  _inherits(OrderModule, _BaseModule);
@@ -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: [],
@@ -92,6 +92,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
92
92
  (_order$relation_forms = order.relation_forms).push.apply(_order$relation_forms, _toConsumableArray(relationForms));
93
93
  delete item._origin.relation_forms;
94
94
  } else {
95
+ // 合并关联表单
96
+ var _relationForms = mergeRelationForms(item._origin.relation_forms || []);
97
+ item._origin.relation_forms = _relationForms;
95
98
  order.bookings.push(item._origin);
96
99
  }
97
100
  if (item !== null && item !== void 0 && item.deposit) {
@@ -8,3 +8,15 @@ export declare const generateDuration: (cartItem: CartItem) => {
8
8
  duration: number;
9
9
  durationType: string;
10
10
  };
11
+ /**
12
+ * 合并关联表单
13
+ * @param relationForms 关联表单
14
+ * @returns 合并后的关联表单
15
+ */
16
+ export declare const mergeRelationForms: (relationForms: {
17
+ form_id: number;
18
+ form_record_ids: number[];
19
+ }[]) => {
20
+ form_id: number;
21
+ form_record_ids: number[];
22
+ }[];
@@ -1,3 +1,9 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
1
7
  import dayjs from "dayjs";
2
8
  /**
3
9
  * 通过 session 类商品的开始时间结束时间生成商品的时长
@@ -12,4 +18,37 @@ export var generateDuration = function generateDuration(cartItem) {
12
18
  duration: duration,
13
19
  durationType: 'minutes'
14
20
  };
21
+ };
22
+
23
+ /**
24
+ * 合并关联表单
25
+ * @param relationForms 关联表单
26
+ * @returns 合并后的关联表单
27
+ */
28
+ export var mergeRelationForms = function mergeRelationForms(relationForms) {
29
+ return Object.values(relationForms.reduce(function (acc, cur) {
30
+ var _acc$form_id$form_rec;
31
+ var form_id = cur.form_id,
32
+ form_record_ids = cur.form_record_ids;
33
+ // 如果 acc 中没有 form_id,则初始化一个空数组
34
+ if (!acc[form_id]) {
35
+ acc[form_id] = {
36
+ form_id: form_id,
37
+ form_record_ids: []
38
+ };
39
+ }
40
+
41
+ // 兼容 form_record_id 可能是数组或单个数字
42
+ var ids = Array.isArray(form_record_ids) ? form_record_ids : [form_record_ids];
43
+ // 过滤掉空值(null、undefined等)
44
+ var validIds = ids.filter(function (id) {
45
+ return id != null;
46
+ });
47
+ (_acc$form_id$form_rec = acc[form_id].form_record_ids).push.apply(_acc$form_id$form_rec, _toConsumableArray(validIds));
48
+ // 去重
49
+ acc[form_id].form_record_ids = _toConsumableArray(new Set(acc[form_id].form_record_ids));
50
+ return acc;
51
+ }, {})).filter(function (item) {
52
+ return item.form_record_ids.length > 0;
53
+ }); // 过滤掉没有有效记录的表单
15
54
  };
@@ -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) {
@@ -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,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: 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: [],
@@ -65,6 +65,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
65
65
  order.relation_forms.push(...relationForms);
66
66
  delete item._origin.relation_forms;
67
67
  } else {
68
+ const relationForms = (0, import_utils.mergeRelationForms)(item._origin.relation_forms || []);
69
+ item._origin.relation_forms = relationForms;
68
70
  order.bookings.push(item._origin);
69
71
  }
70
72
  if (item == null ? void 0 : item.deposit) {
@@ -8,3 +8,15 @@ export declare const generateDuration: (cartItem: CartItem) => {
8
8
  duration: number;
9
9
  durationType: string;
10
10
  };
11
+ /**
12
+ * 合并关联表单
13
+ * @param relationForms 关联表单
14
+ * @returns 合并后的关联表单
15
+ */
16
+ export declare const mergeRelationForms: (relationForms: {
17
+ form_id: number;
18
+ form_record_ids: number[];
19
+ }[]) => {
20
+ form_id: number;
21
+ form_record_ids: number[];
22
+ }[];
@@ -29,7 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/modules/Order/utils.ts
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
- generateDuration: () => generateDuration
32
+ generateDuration: () => generateDuration,
33
+ mergeRelationForms: () => mergeRelationForms
33
34
  });
34
35
  module.exports = __toCommonJS(utils_exports);
35
36
  var import_dayjs = __toESM(require("dayjs"));
@@ -39,7 +40,23 @@ var generateDuration = (cartItem) => {
39
40
  const duration = endDate.diff(startDate, "minutes");
40
41
  return { duration, durationType: "minutes" };
41
42
  };
43
+ var mergeRelationForms = (relationForms) => {
44
+ return Object.values(
45
+ relationForms.reduce((acc, cur) => {
46
+ const { form_id, form_record_ids } = cur;
47
+ if (!acc[form_id]) {
48
+ acc[form_id] = { form_id, form_record_ids: [] };
49
+ }
50
+ const ids = Array.isArray(form_record_ids) ? form_record_ids : [form_record_ids];
51
+ const validIds = ids.filter((id) => id != null);
52
+ acc[form_id].form_record_ids.push(...validIds);
53
+ acc[form_id].form_record_ids = [...new Set(acc[form_id].form_record_ids)];
54
+ return acc;
55
+ }, {})
56
+ ).filter((item) => item.form_record_ids.length > 0);
57
+ };
42
58
  // Annotate the CommonJS export names for ESM import in node:
43
59
  0 && (module.exports = {
44
- generateDuration
60
+ generateDuration,
61
+ mergeRelationForms
45
62
  });
@@ -259,7 +259,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
259
259
  cartItems,
260
260
  res,
261
261
  (id) => this.store.products.getProduct(id),
262
- (params) => this.store.cart.updateItem(params)
262
+ (params) => this.store.cart.updateItem(params),
263
+ (params) => this.store.cart.updateItemInitInfo(params)
263
264
  );
264
265
  this.core.effects.emit(
265
266
  `${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": "1.0.42",
4
+ "version": "1.0.46",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -66,5 +66,8 @@
66
66
  },
67
67
  "publishConfig": {
68
68
  "access": "public"
69
+ },
70
+ "volta": {
71
+ "node": "18.20.8"
69
72
  }
70
73
  }