@pisell/pisellos 1.0.76 → 1.0.78

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.
@@ -50,8 +50,9 @@ export interface RulesParamsHooks {
50
50
  origin_total?: number;
51
51
  price?: string | number;
52
52
  variant?: any[];
53
- original_price?: number;
53
+ original_price?: number | string;
54
54
  quantity?: number;
55
+ bundle?: any[];
55
56
  }) => Record<string, any>;
56
57
  }
57
58
  export {};
@@ -2186,7 +2186,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2186
2186
  account
2187
2187
  }) {
2188
2188
  var _a, _b;
2189
- const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
2189
+ const cartItems = this.store.cart.getItems().filter((item) => !(0, import_utils5.isNormalProduct)(item._productOrigin));
2190
2190
  const currentCartItem = this.convertProductToCartItem({ product, date, account });
2191
2191
  cartItems.push(currentCartItem);
2192
2192
  if (cartItems.length === 0)
@@ -122,12 +122,6 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
122
122
  throw error;
123
123
  }
124
124
  }
125
- /**
126
- * 初始化外设扫码结果监听
127
- */
128
- initPeripheralsListener() {
129
- this.scan.initPeripheralsListener();
130
- }
131
125
  /**
132
126
  * 获取商品列表(不加载到模块中)
133
127
  * @returns 商品列表
@@ -314,7 +314,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
314
314
  if (item.booking_id) {
315
315
  const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
316
316
  (item.discount_list || []).forEach((discount) => {
317
- var _a3, _b, _c;
317
+ var _a3, _b, _c, _d, _e;
318
318
  if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
319
319
  const index = editModeDiscountList.findIndex((n) => {
320
320
  var _a4;
@@ -324,7 +324,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
324
324
  editModeDiscountList[index] = {
325
325
  ...editModeDiscountList[index],
326
326
  amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
327
- savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
327
+ savedAmount: new import_decimal.default(discount.amount || 0).times(((_a3 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a3.num) || (product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
328
328
  };
329
329
  } else {
330
330
  if (discount.type && !discount.tag) {
@@ -335,13 +335,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
335
335
  name: discount.name || discount.discount.title.auto,
336
336
  isEditMode: true,
337
337
  limited_relation_product_data: {},
338
- savedAmount: discount.amount * ((product == null ? void 0 : product.num) || 1),
338
+ savedAmount: discount.amount * (((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.num) || (product == null ? void 0 : product.num) || 1),
339
339
  isAvailable: true,
340
- id: ((_a3 = discount.discount) == null ? void 0 : _a3.resource_id) || discount.id,
341
- format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
340
+ id: ((_c = discount.discount) == null ? void 0 : _c.resource_id) || discount.id,
341
+ format_title: ((_d = discount.discount) == null ? void 0 : _d.title) || discount.format_title,
342
342
  isDisabled: true,
343
343
  isSelected: true,
344
- product_id: ((_c = discount.discount) == null ? void 0 : _c.product_id) || discount.product_id
344
+ product_id: ((_e = discount.discount) == null ? void 0 : _e.product_id) || discount.product_id
345
345
  });
346
346
  }
347
347
  }
@@ -355,15 +355,17 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
355
355
  const isProductFree = (id) => {
356
356
  var _a2;
357
357
  const targetProduct = productList.find((n) => n.id === id);
358
+ if (!targetProduct)
359
+ return false;
358
360
  const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
359
361
  return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
360
362
  };
361
363
  const allUsedProductIds = newDiscountList.map((n) => {
362
364
  var _a2;
363
- return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
365
+ return n.isSelected ? ((_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
364
366
  var _a3;
365
367
  return (_a3 = n2.discount) == null ? void 0 : _a3.product_id;
366
- }) : [];
368
+ })) || n.product_id : [];
367
369
  }).flat();
368
370
  newDiscountList.forEach((item) => {
369
371
  var _a2;
@@ -10,3 +10,10 @@ export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
10
10
  * @returns
11
11
  */
12
12
  export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
13
+ export declare const getDiscountListAmountTotal: (discount: Discount[]) => any;
14
+ /**
15
+ * 获取折扣金额 计算每个折扣的金额
16
+ * @param discount
17
+ * @returns
18
+ */
19
+ export declare const getDiscountListAmount: (discount: Discount[]) => any;
@@ -30,6 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
32
  getDiscountAmount: () => getDiscountAmount,
33
+ getDiscountListAmount: () => getDiscountListAmount,
34
+ getDiscountListAmountTotal: () => getDiscountListAmountTotal,
33
35
  uniqueById: () => uniqueById
34
36
  });
35
37
  module.exports = __toCommonJS(utils_exports);
@@ -41,16 +43,28 @@ var uniqueById = (arr, key = "id") => {
41
43
  var getDiscountAmount = (discount, total, price) => {
42
44
  var _a;
43
45
  if (discount.tag === "good_pass") {
44
- return new import_decimal.default(total).minus(new import_decimal.default(price || 0)).toNumber();
46
+ return new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
45
47
  }
46
48
  const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
47
49
  if (isFixedAmount) {
48
- return Math.max(new import_decimal.default(total).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
50
+ return Math.max(new import_decimal.default(price).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
49
51
  }
50
- return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(total)).toNumber();
52
+ return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
53
+ };
54
+ var getDiscountListAmountTotal = (discount) => {
55
+ return discount.reduce((acc, cur) => {
56
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.num || 1).mul(new import_decimal.default(cur.amount || 0))).toNumber();
57
+ }, new import_decimal.default(0));
58
+ };
59
+ var getDiscountListAmount = (discount) => {
60
+ return discount.reduce((acc, cur) => {
61
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.amount || 0)).toNumber();
62
+ }, new import_decimal.default(0));
51
63
  };
52
64
  // Annotate the CommonJS export names for ESM import in node:
53
65
  0 && (module.exports = {
54
66
  getDiscountAmount,
67
+ getDiscountListAmount,
68
+ getDiscountListAmountTotal,
55
69
  uniqueById
56
70
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.76",
4
+ "version": "1.0.78",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",