@pisell/pisellos 0.0.144 → 0.0.146

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.
@@ -61,6 +61,7 @@ export interface Discount {
61
61
  applicableProductIds?: number[];
62
62
  applicableProductDetails: ApplicableProductDetails[];
63
63
  appliedProductDetails: ApplicableProductDetails[];
64
+ isDisabledForProductUsed?: boolean;
64
65
  }
65
66
  export interface DiscountState {
66
67
  discountList: Discount[];
@@ -179,8 +179,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
179
179
  } else if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
180
180
  // 都是折扣券,按照par_value排序(折扣越大越优先,即par_value越小越优先)
181
181
  if (a.par_value !== b.par_value) {
182
- var valueA = new Decimal(a.par_value || 0);
183
- var valueB = new Decimal(b.par_value || 0);
182
+ var valueA = new Decimal(100).minus(a.par_value || 0);
183
+ var valueB = new Decimal(100).minus(b.par_value || 0);
184
184
  return valueA.minus(valueB).toNumber();
185
185
  }
186
186
  // 相同折扣的情况下,按照过期时间排序
@@ -460,6 +460,20 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
460
460
  var newDiscountList = [].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
461
461
  return !item.isDisabled;
462
462
  })));
463
+ var allUsedProductIds = newDiscountList.map(function (n) {
464
+ return n.isSelected ? n.applicableProductIds : [];
465
+ }).flat();
466
+ newDiscountList.forEach(function (item) {
467
+ var _item$applicableProdu;
468
+ var isAllProductUsed = (_item$applicableProdu = item.applicableProductIds) === null || _item$applicableProdu === void 0 ? void 0 : _item$applicableProdu.every(function (id) {
469
+ return allUsedProductIds === null || allUsedProductIds === void 0 ? void 0 : allUsedProductIds.includes(id);
470
+ });
471
+ if (!item.isSelected && isAllProductUsed) {
472
+ item.isDisabledForProductUsed = true;
473
+ } else {
474
+ item.isDisabledForProductUsed = false;
475
+ }
476
+ });
463
477
  (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
464
478
  this.emitDiscountListChange(newDiscountList);
465
479
  return newDiscountList;
@@ -61,6 +61,7 @@ export interface Discount {
61
61
  applicableProductIds?: number[];
62
62
  applicableProductDetails: ApplicableProductDetails[];
63
63
  appliedProductDetails: ApplicableProductDetails[];
64
+ isDisabledForProductUsed?: boolean;
64
65
  }
65
66
  export interface DiscountState {
66
67
  discountList: Discount[];
@@ -126,8 +126,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
126
126
  return compareByExpireTime(a, b);
127
127
  } else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
128
128
  if (a.par_value !== b.par_value) {
129
- const valueA = new import_decimal.default(a.par_value || 0);
130
- const valueB = new import_decimal.default(b.par_value || 0);
129
+ const valueA = new import_decimal.default(100).minus(a.par_value || 0);
130
+ const valueB = new import_decimal.default(100).minus(b.par_value || 0);
131
131
  return valueA.minus(valueB).toNumber();
132
132
  }
133
133
  return compareByExpireTime(a, b);
@@ -296,6 +296,18 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
296
296
  ...editModeDiscountList,
297
297
  ...discountList.filter((item) => !item.isDisabled)
298
298
  ];
299
+ const allUsedProductIds = newDiscountList.map((n) => n.isSelected ? n.applicableProductIds : []).flat();
300
+ newDiscountList.forEach((item) => {
301
+ var _a2;
302
+ const isAllProductUsed = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
303
+ return allUsedProductIds == null ? void 0 : allUsedProductIds.includes(id);
304
+ });
305
+ if (!item.isSelected && isAllProductUsed) {
306
+ item.isDisabledForProductUsed = true;
307
+ } else {
308
+ item.isDisabledForProductUsed = false;
309
+ }
310
+ });
299
311
  (_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
300
312
  this.emitDiscountListChange(newDiscountList);
301
313
  return newDiscountList;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.144",
4
+ "version": "0.0.146",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",