@pisell/pisellos 0.0.134 → 0.0.136

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.
@@ -206,7 +206,7 @@ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(para
206
206
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
207
207
  }, price);
208
208
  }
209
- return price * num;
209
+ return price;
210
210
  };
211
211
 
212
212
  /**
@@ -206,7 +206,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
206
206
  }
207
207
  if (discount.appliedProductDetails) {
208
208
  return discount.appliedProductDetails.reduce(function (total, product) {
209
- var price = new Decimal((product === null || product === void 0 ? void 0 : product.amount) || 0);
209
+ var price = new Decimal((product === null || product === void 0 ? void 0 : product.amount) || 0).mul((product === null || product === void 0 ? void 0 : product.num) || 1);
210
210
  return new Decimal(total).plus(price).toNumber();
211
211
  }, 0);
212
212
  }
@@ -27,6 +27,7 @@ interface ApplicableProductDetails {
27
27
  resource_id: number;
28
28
  title: string;
29
29
  original_amount: string;
30
+ num: number;
30
31
  }
31
32
  export interface Discount {
32
33
  id: number;
@@ -242,7 +242,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
242
242
 
243
243
  // 编辑的商品 使用了优惠券不可用
244
244
  var isAvailableProduct = !(product !== null && product !== void 0 && product.booking_id && product !== null && product !== void 0 && (_product$discount_lis = product.discount_list) !== null && _product$discount_lis !== void 0 && _product$discount_lis.length && product !== null && product !== void 0 && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.every(function (discount) {
245
- return discount.id && discount.type === 'good_pass';
245
+ return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.type);
246
246
  }));
247
247
 
248
248
  // 判断优惠券是否适用于该商品
@@ -261,7 +261,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
261
261
  title: discount.format_title,
262
262
  original_amount: product.origin_total,
263
263
  pre_value: discount.par_value
264
- }
264
+ },
265
+ num: product.num || 1
265
266
  });
266
267
  discountApplicableProducts.set(discount.id, applicableProducts);
267
268
  }
@@ -273,7 +274,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
273
274
  var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
274
275
  var product = _this3.hooks.getProduct(originProduct);
275
276
  if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length && product !== null && product !== void 0 && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.every(function (discount) {
276
- return discount.id && discount.type === 'good_pass';
277
+ return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.type);
277
278
  })) {
278
279
  processedProductsMap.set(product._id, originProduct);
279
280
  return;
@@ -358,7 +359,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
358
359
  original_amount: product.price,
359
360
  product_id: selectedDiscount.product_id,
360
361
  percent: selectedDiscount.par_value
361
- }
362
+ },
363
+ num: product.num || 1
362
364
  };
363
365
  appliedProducts.push(discountDetail);
364
366
  appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
@@ -388,7 +390,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
388
390
  processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
389
391
  discount_list: [discountDetail],
390
392
  price: new Decimal(targetProductPrice).toNumber(),
391
- total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0)).toNumber(),
393
+ total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
392
394
  origin_total: product.origin_total || product.total
393
395
  }));
394
396
  }
@@ -37,6 +37,7 @@ type ProductDetail = {
37
37
  options?: any[];
38
38
  bundle?: any[];
39
39
  original_price?: number | string;
40
+ num?: number;
40
41
  };
41
42
  export interface RulesParamsHooks {
42
43
  getProduct: (product: Record<string, any>) => ProductDetail;
@@ -568,7 +568,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
568
568
  _ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id, _ref4$quantity = _ref4.quantity, quantity = _ref4$quantity === void 0 ? 1 : _ref4$quantity, rowKey = _ref4.rowKey; // 检查购物车里是否已经存在 rowKey相同的数据,如果是则更新数量
569
569
  cartItems = this.store.cart.getItems();
570
570
  if (!rowKey) {
571
- _context8.next = 8;
571
+ _context8.next = 9;
572
572
  break;
573
573
  }
574
574
  targetCartItem = cartItems.find(function (n) {
@@ -576,7 +576,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
576
576
  return ((_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.rowKey) === rowKey;
577
577
  });
578
578
  if (!(targetCartItem && isNormalProduct(targetCartItem._productOrigin))) {
579
- _context8.next = 8;
579
+ _context8.next = 9;
580
580
  break;
581
581
  }
582
582
  this.store.cart.updateItem({
@@ -584,8 +584,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
584
584
  product: _objectSpread({}, targetCartItem._productOrigin),
585
585
  quantity: (targetCartItem.num || 1) + quantity
586
586
  });
587
+ // 这里需要单独触发一个,购物车商品数量发生改变的 hook
588
+ this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateCartItemNums"), {});
587
589
  return _context8.abrupt("return");
588
- case 8:
590
+ case 9:
589
591
  product = _objectSpread(_objectSpread({}, origin), {}, {
590
592
  product_variant_id: product_variant_id,
591
593
  rowKey: rowKey
@@ -600,7 +602,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
600
602
  addCartItem.account = activeAccount;
601
603
  }
602
604
  this.store.cart.addItem(addCartItem);
603
- case 12:
605
+ case 13:
604
606
  case "end":
605
607
  return _context8.stop();
606
608
  }
@@ -2630,6 +2632,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2630
2632
  options: targetCartItem._optionsOrigin,
2631
2633
  quantity: (targetCartItem.num || 1) + quantity
2632
2634
  });
2635
+ // 这里需要单独触发一个,购物车商品数量发生改变的 hook
2636
+ this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateCartItemNums"), {});
2633
2637
  return;
2634
2638
  }
2635
2639
  }
@@ -434,7 +434,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
434
434
  productList.forEach(function (item) {
435
435
  if (item.booking_id) {
436
436
  (item.discount_list || []).forEach(function (discount) {
437
- if (discount.id && discount.type === 'good_pass') {
437
+ if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
438
438
  var _discount$discount, _discount$discount2, _discount$discount3;
439
439
  editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
440
440
  isEditMode: true,
@@ -194,7 +194,7 @@ var getProductOriginTotalPrice = (params) => {
194
194
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
195
195
  }, price);
196
196
  }
197
- return price * num;
197
+ return price;
198
198
  };
199
199
  var formatOptions = (options) => {
200
200
  if (!(options == null ? void 0 : options.length))
@@ -122,7 +122,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
122
122
  }
123
123
  if (discount.appliedProductDetails) {
124
124
  return discount.appliedProductDetails.reduce((total, product) => {
125
- const price = new import_decimal.default((product == null ? void 0 : product.amount) || 0);
125
+ const price = new import_decimal.default((product == null ? void 0 : product.amount) || 0).mul((product == null ? void 0 : product.num) || 1);
126
126
  return new import_decimal.default(total).plus(price).toNumber();
127
127
  }, 0);
128
128
  }
@@ -27,6 +27,7 @@ interface ApplicableProductDetails {
27
27
  resource_id: number;
28
28
  title: string;
29
29
  original_amount: string;
30
+ num: number;
30
31
  }
31
32
  export interface Discount {
32
33
  id: number;
@@ -164,7 +164,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
164
164
  var _a, _b, _c;
165
165
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
166
166
  const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
167
- const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && discount2.type === "good_pass")));
167
+ const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.type))));
168
168
  if (isAvailableProduct && isLimitedProduct) {
169
169
  (_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
170
170
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
@@ -176,7 +176,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
176
176
  title: discount.format_title,
177
177
  original_amount: product.origin_total,
178
178
  pre_value: discount.par_value
179
- }
179
+ },
180
+ num: product.num || 1
180
181
  });
181
182
  discountApplicableProducts.set(discount.id, applicableProducts);
182
183
  }
@@ -185,7 +186,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
185
186
  sortedProductList.forEach((originProduct) => {
186
187
  var _a, _b, _c, _d, _e;
187
188
  const product = this.hooks.getProduct(originProduct);
188
- if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && discount.type === "good_pass"))) {
189
+ if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.type)))) {
189
190
  processedProductsMap.set(product._id, originProduct);
190
191
  return;
191
192
  }
@@ -259,7 +260,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
259
260
  original_amount: product.price,
260
261
  product_id: selectedDiscount.product_id,
261
262
  percent: selectedDiscount.par_value
262
- }
263
+ },
264
+ num: product.num || 1
263
265
  };
264
266
  appliedProducts.push(discountDetail);
265
267
  appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
@@ -291,7 +293,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
291
293
  this.hooks.setProduct(originProduct, {
292
294
  discount_list: [discountDetail],
293
295
  price: new import_decimal.default(targetProductPrice).toNumber(),
294
- total: new import_decimal.default(product.origin_total || product.total || 0).minus(new import_decimal.default(product.price || 0)).toNumber(),
296
+ total: new import_decimal.default(product.origin_total || product.total || 0).minus(new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice))).toNumber(),
295
297
  origin_total: product.origin_total || product.total
296
298
  })
297
299
  );
@@ -37,6 +37,7 @@ type ProductDetail = {
37
37
  options?: any[];
38
38
  bundle?: any[];
39
39
  original_price?: number | string;
40
+ num?: number;
40
41
  };
41
42
  export interface RulesParamsHooks {
42
43
  getProduct: (product: Record<string, any>) => ProductDetail;
@@ -359,6 +359,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
359
359
  },
360
360
  quantity: (targetCartItem.num || 1) + quantity
361
361
  });
362
+ this.core.effects.emit(`${this.store.cart.name}:onUpdateCartItemNums`, {});
362
363
  return;
363
364
  }
364
365
  }
@@ -1829,6 +1830,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1829
1830
  options: targetCartItem._optionsOrigin,
1830
1831
  quantity: (targetCartItem.num || 1) + quantity
1831
1832
  });
1833
+ this.core.effects.emit(`${this.store.cart.name}:onUpdateCartItemNums`, {});
1832
1834
  return;
1833
1835
  }
1834
1836
  }
@@ -271,7 +271,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
271
271
  if (item.booking_id) {
272
272
  (item.discount_list || []).forEach((discount) => {
273
273
  var _a2, _b, _c;
274
- if (discount.id && discount.type === "good_pass") {
274
+ if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
275
275
  editModeDiscountList.push({
276
276
  ...discount,
277
277
  isEditMode: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.134",
4
+ "version": "0.0.136",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",