@pisell/pisellos 0.0.10 → 0.0.13

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.
Files changed (130) hide show
  1. package/dist/modules/Account/index.d.ts +4 -2
  2. package/dist/modules/Account/index.js +23 -36
  3. package/dist/modules/Account/types.d.ts +1 -0
  4. package/dist/modules/AccountList/index.d.ts +2 -0
  5. package/dist/modules/AccountList/index.js +34 -11
  6. package/dist/modules/Cart/index.d.ts +17 -11
  7. package/dist/modules/Cart/index.js +179 -121
  8. package/dist/modules/Cart/types.d.ts +98 -9
  9. package/dist/modules/Cart/types.js +8 -0
  10. package/dist/modules/Cart/utils.d.ts +114 -0
  11. package/dist/modules/Cart/utils.js +345 -0
  12. package/dist/modules/Date/index.d.ts +11 -12
  13. package/dist/modules/Date/index.js +104 -60
  14. package/dist/modules/Date/types.d.ts +51 -20
  15. package/dist/modules/Date/types.js +2 -5
  16. package/dist/modules/Date/utils.d.ts +35 -0
  17. package/dist/modules/Date/utils.js +211 -0
  18. package/dist/modules/Discount/index.d.ts +26 -0
  19. package/dist/modules/Discount/index.js +234 -0
  20. package/dist/modules/Discount/types.d.ts +66 -0
  21. package/dist/modules/Discount/types.js +5 -0
  22. package/dist/modules/Order/index.d.ts +16 -12
  23. package/dist/modules/Order/index.js +38 -166
  24. package/dist/modules/Order/types.d.ts +18 -41
  25. package/dist/modules/Order/types.js +0 -14
  26. package/dist/modules/Payment/index.d.ts +0 -2
  27. package/dist/modules/Payment/index.js +45 -76
  28. package/dist/modules/Payment/types.d.ts +0 -2
  29. package/dist/modules/Payment/types.js +2 -0
  30. package/dist/modules/Product/types.d.ts +48 -1
  31. package/dist/modules/ProductList/index.d.ts +1 -0
  32. package/dist/modules/ProductList/index.js +21 -1
  33. package/dist/modules/ProductList/types.d.ts +1 -0
  34. package/dist/modules/Resource/types.d.ts +6 -2
  35. package/dist/modules/Rules/index.d.ts +32 -0
  36. package/dist/modules/Rules/index.js +423 -0
  37. package/dist/modules/Rules/types.d.ts +46 -0
  38. package/dist/modules/Rules/types.js +5 -0
  39. package/dist/modules/Summary/index.d.ts +13 -0
  40. package/dist/modules/Summary/index.js +80 -0
  41. package/dist/modules/Summary/types.d.ts +13 -0
  42. package/dist/modules/Summary/types.js +1 -0
  43. package/dist/modules/Summary/utils.d.ts +19 -0
  44. package/dist/modules/Summary/utils.js +56 -0
  45. package/dist/plugins/index.d.ts +3 -2
  46. package/dist/plugins/index.js +2 -1
  47. package/dist/plugins/request.d.ts +4 -3
  48. package/dist/plugins/request.js +30 -30
  49. package/dist/plugins/shopStore.d.ts +4 -0
  50. package/dist/plugins/shopStore.js +1 -0
  51. package/dist/solution/BookingByStep/index.d.ts +73 -12
  52. package/dist/solution/BookingByStep/index.js +635 -99
  53. package/dist/solution/BookingByStep/types.d.ts +2 -0
  54. package/dist/solution/BookingByStep/types.js +11 -8
  55. package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
  56. package/dist/solution/BookingByStep/utils/products.js +47 -0
  57. package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
  58. package/dist/solution/BookingByStep/utils/resources.js +144 -79
  59. package/dist/solution/ShopDiscount/index.d.ts +50 -0
  60. package/dist/solution/ShopDiscount/index.js +546 -0
  61. package/dist/solution/ShopDiscount/types.d.ts +24 -0
  62. package/dist/solution/ShopDiscount/types.js +10 -0
  63. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  64. package/dist/solution/ShopDiscount/utils.js +7 -0
  65. package/dist/solution/index.d.ts +1 -0
  66. package/dist/solution/index.js +2 -1
  67. package/lib/modules/Account/index.d.ts +4 -2
  68. package/lib/modules/Account/index.js +14 -3
  69. package/lib/modules/Account/types.d.ts +1 -0
  70. package/lib/modules/AccountList/index.d.ts +2 -0
  71. package/lib/modules/AccountList/index.js +17 -0
  72. package/lib/modules/Cart/index.d.ts +17 -11
  73. package/lib/modules/Cart/index.js +72 -21
  74. package/lib/modules/Cart/types.d.ts +98 -9
  75. package/lib/modules/Cart/utils.d.ts +114 -0
  76. package/lib/modules/Cart/utils.js +320 -0
  77. package/lib/modules/Date/index.d.ts +11 -12
  78. package/lib/modules/Date/index.js +50 -31
  79. package/lib/modules/Date/types.d.ts +51 -20
  80. package/lib/modules/Date/types.js +0 -4
  81. package/lib/modules/Date/utils.d.ts +35 -0
  82. package/lib/modules/Date/utils.js +167 -0
  83. package/lib/modules/Discount/index.d.ts +26 -0
  84. package/lib/modules/Discount/index.js +118 -0
  85. package/lib/modules/Discount/types.d.ts +66 -0
  86. package/lib/modules/Discount/types.js +33 -0
  87. package/lib/modules/Order/index.d.ts +16 -12
  88. package/lib/modules/Order/index.js +23 -51
  89. package/lib/modules/Order/types.d.ts +18 -41
  90. package/lib/modules/Payment/index.d.ts +0 -2
  91. package/lib/modules/Payment/index.js +6 -17
  92. package/lib/modules/Payment/types.d.ts +0 -2
  93. package/lib/modules/Product/types.d.ts +48 -1
  94. package/lib/modules/ProductList/index.d.ts +1 -0
  95. package/lib/modules/ProductList/index.js +4 -0
  96. package/lib/modules/ProductList/types.d.ts +1 -0
  97. package/lib/modules/Resource/types.d.ts +6 -2
  98. package/lib/modules/Rules/index.d.ts +32 -0
  99. package/lib/modules/Rules/index.js +283 -0
  100. package/lib/modules/Rules/types.d.ts +46 -0
  101. package/lib/modules/Rules/types.js +33 -0
  102. package/lib/modules/Summary/index.d.ts +13 -0
  103. package/lib/modules/Summary/index.js +49 -0
  104. package/lib/modules/Summary/types.d.ts +13 -0
  105. package/lib/modules/Summary/types.js +17 -0
  106. package/lib/modules/Summary/utils.d.ts +19 -0
  107. package/lib/modules/Summary/utils.js +79 -0
  108. package/lib/plugins/index.d.ts +3 -2
  109. package/lib/plugins/index.js +3 -1
  110. package/lib/plugins/request.d.ts +4 -3
  111. package/lib/plugins/request.js +4 -20
  112. package/lib/plugins/shopStore.d.ts +4 -0
  113. package/lib/plugins/shopStore.js +17 -0
  114. package/lib/solution/BookingByStep/index.d.ts +73 -12
  115. package/lib/solution/BookingByStep/index.js +451 -24
  116. package/lib/solution/BookingByStep/types.d.ts +2 -0
  117. package/lib/solution/BookingByStep/types.js +3 -0
  118. package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
  119. package/lib/solution/BookingByStep/utils/products.js +60 -0
  120. package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
  121. package/lib/solution/BookingByStep/utils/resources.js +106 -49
  122. package/lib/solution/ShopDiscount/index.d.ts +50 -0
  123. package/lib/solution/ShopDiscount/index.js +321 -0
  124. package/lib/solution/ShopDiscount/types.d.ts +24 -0
  125. package/lib/solution/ShopDiscount/types.js +38 -0
  126. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  127. package/lib/solution/ShopDiscount/utils.js +32 -0
  128. package/lib/solution/index.d.ts +1 -0
  129. package/lib/solution/index.js +3 -1
  130. package/package.json +4 -4
@@ -0,0 +1,423 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
+ 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."); }
6
+ 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); }
7
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
+ 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; }
10
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
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
+ 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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
17
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
18
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
19
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
20
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
21
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
22
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
23
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
+ 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); }
26
+ import { BaseModule } from "../BaseModule";
27
+ import { RulesHooks } from "./types";
28
+ import { uniqueById } from "../../solution/ShopDiscount/utils";
29
+ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
30
+ _inherits(RulesModule, _BaseModule);
31
+ var _super = _createSuper(RulesModule);
32
+ function RulesModule(name, version) {
33
+ var _this;
34
+ _classCallCheck(this, RulesModule);
35
+ _this = _super.call(this, name, version);
36
+ _defineProperty(_assertThisInitialized(_this), "defaultName", "rules");
37
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
38
+ _defineProperty(_assertThisInitialized(_this), "store", void 0);
39
+ _defineProperty(_assertThisInitialized(_this), "hooks", void 0);
40
+ _this.hooks = {};
41
+ return _this;
42
+ }
43
+ _createClass(RulesModule, [{
44
+ key: "initialize",
45
+ value: function () {
46
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
47
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
48
+ while (1) switch (_context.prev = _context.next) {
49
+ case 0:
50
+ this.core = core;
51
+ this.hooks = options === null || options === void 0 ? void 0 : options.hooks;
52
+ this.store = options === null || options === void 0 ? void 0 : options.store;
53
+ case 3:
54
+ case "end":
55
+ return _context.stop();
56
+ }
57
+ }, _callee, this);
58
+ }));
59
+ function initialize(_x, _x2) {
60
+ return _initialize.apply(this, arguments);
61
+ }
62
+ return initialize;
63
+ }()
64
+ }, {
65
+ key: "setRulesList",
66
+ value: function () {
67
+ var _setRulesList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(rulesList) {
68
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
69
+ while (1) switch (_context2.prev = _context2.next) {
70
+ case 0:
71
+ this.store.rulesList = rulesList;
72
+ _context2.next = 3;
73
+ return this.core.effects.emit(RulesHooks.OnRulesListChange, rulesList);
74
+ case 3:
75
+ case "end":
76
+ return _context2.stop();
77
+ }
78
+ }, _callee2, this);
79
+ }));
80
+ function setRulesList(_x3) {
81
+ return _setRulesList.apply(this, arguments);
82
+ }
83
+ return setRulesList;
84
+ }()
85
+ }, {
86
+ key: "getRulesList",
87
+ value: function getRulesList() {
88
+ return this.store.rulesList;
89
+ }
90
+
91
+ // 判断discountList 是否可以对当前productList生效
92
+ }, {
93
+ key: "isDiscountListAvailable",
94
+ value: function isDiscountListAvailable(_ref) {
95
+ var _this2 = this;
96
+ var oldDiscountList = _ref.oldDiscountList,
97
+ newDiscountList = _ref.newDiscountList,
98
+ productList = _ref.productList;
99
+ // 首先检查是否有新的优惠券可应用
100
+ if (!newDiscountList || newDiscountList.length === 0) {
101
+ return {
102
+ isAvailable: false,
103
+ discountList: oldDiscountList,
104
+ productList: productList
105
+ };
106
+ }
107
+
108
+ // 合并新旧折扣列表,并计算折扣结果
109
+ var mergedDiscountList = uniqueById([].concat(_toConsumableArray(oldDiscountList), _toConsumableArray(newDiscountList)));
110
+ var result = this.calcDiscount({
111
+ discountList: mergedDiscountList,
112
+ productList: _toConsumableArray(productList)
113
+ });
114
+
115
+ // 检查是否有产品使用了新折扣
116
+ var hasApplicableDiscount = false;
117
+ var newDiscountIds = newDiscountList.map(function (discount) {
118
+ return discount.id;
119
+ });
120
+
121
+ // 遍历处理后的产品列表,检查是否有产品使用了新折扣
122
+ result.productList.forEach(function (product) {
123
+ var _this2$hooks$getProdu = _this2.hooks.getProduct(product),
124
+ discount_list = _this2$hooks$getProdu.discount_list;
125
+ if (discount_list && discount_list.length > 0) {
126
+ // 检查是否有使用新折扣的情况
127
+ var usedNewDiscount = discount_list.some(function (discount) {
128
+ return newDiscountIds.includes(discount.resource_id);
129
+ });
130
+ if (usedNewDiscount) {
131
+ hasApplicableDiscount = true;
132
+ }
133
+ }
134
+ });
135
+ return {
136
+ isAvailable: hasApplicableDiscount,
137
+ discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
138
+ productList: hasApplicableDiscount ? result.productList : productList
139
+ };
140
+ }
141
+ }, {
142
+ key: "calcDiscount",
143
+ value: function calcDiscount(_ref2, options) {
144
+ var _this3 = this;
145
+ var discountList = _ref2.discountList,
146
+ productList = _ref2.productList;
147
+ var editModeDiscount = [];
148
+ var addModeDiscount = [];
149
+ discountList.forEach(function (discount) {
150
+ if (discount.isEditMode) {
151
+ editModeDiscount.push(discount);
152
+ } else {
153
+ addModeDiscount.push(discount);
154
+ }
155
+ });
156
+
157
+ // 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑
158
+ var filteredDiscountList = addModeDiscount.filter(function (discount) {
159
+ return !discount.isManualSelect;
160
+ });
161
+
162
+ // 优惠券按过期时间排序(即将过期优先)
163
+ var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
164
+ if (a.expire_time && b.expire_time) {
165
+ var timeA = new Date(a.expire_time).getTime();
166
+ var timeB = new Date(b.expire_time).getTime();
167
+ return timeA - timeB;
168
+ }
169
+ // 有过期时间的优先级高于永久的
170
+ return a.expire_time ? -1 : b.expire_time ? 1 : 0;
171
+ });
172
+
173
+ // 对productList按价格降序排序(用于应用优惠券时优先选择高价商品)
174
+ var sortedProductList = _toConsumableArray(productList).sort(function (a, b) {
175
+ var aProduct = _this3.hooks.getProduct(a);
176
+ var bProduct = _this3.hooks.getProduct(b);
177
+ var priceA = parseFloat(aProduct.price || "0");
178
+ var priceB = parseFloat(bProduct.price || "0");
179
+ return priceB - priceA;
180
+ });
181
+
182
+ // 标记已使用的优惠券
183
+ var usedDiscounts = new Map();
184
+
185
+ // 记录每个优惠券适用的商品ID
186
+ var discountApplicability = new Map();
187
+
188
+ // 记录每个优惠券适用的商品详细信息
189
+ var discountApplicableProducts = new Map();
190
+
191
+ // 初始化每个优惠券的适用性和可抵扣商品
192
+ addModeDiscount.forEach(function (discount) {
193
+ discountApplicability.set(discount.id, []);
194
+ discountApplicableProducts.set(discount.id, []);
195
+ });
196
+
197
+ // 处理后的商品列表(按排序后的顺序处理,记录优惠信息)
198
+ var processedProductsMap = new Map();
199
+
200
+ // 记录已应用优惠券的商品信息
201
+ var appliedDiscountProducts = new Map();
202
+
203
+ // 首先遍历所有商品和所有优惠券,确定每个优惠券的适用范围,包括isSelected为false的优惠券
204
+ sortedProductList.forEach(function (originProduct) {
205
+ var product = _this3.hooks.getProduct(originProduct);
206
+ addModeDiscount.forEach(function (discount) {
207
+ var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
208
+
209
+ // 判断优惠券是否适用于该商品
210
+ if (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
211
+ var _discountApplicabilit;
212
+ // 记录此优惠券适用的商品
213
+ (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
214
+
215
+ // 记录可抵扣的商品详情
216
+ var applicableProducts = discountApplicableProducts.get(discount.id) || [];
217
+ applicableProducts.push({
218
+ amount: product.price,
219
+ type: discount.tag,
220
+ resource_id: discount.id,
221
+ title: discount.format_title,
222
+ original_amount: product.origin_total
223
+ });
224
+ discountApplicableProducts.set(discount.id, applicableProducts);
225
+ }
226
+ });
227
+ });
228
+
229
+ // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
230
+ sortedProductList.forEach(function (originProduct) {
231
+ var _product$discount_lis;
232
+ var product = _this3.hooks.getProduct(originProduct);
233
+ if (product !== null && product !== void 0 && product.booking_id) {
234
+ processedProductsMap.set(product._id, originProduct);
235
+ return;
236
+ }
237
+
238
+ // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
239
+ var applicableDiscounts = sortedDiscountList.filter(function (discount) {
240
+ // 如果优惠券已被使用,则跳过
241
+ if (usedDiscounts.get(discount.id)) return false;
242
+ var limitedData = discount.limited_relation_product_data;
243
+
244
+ // 判断优惠券是否适用于该商品
245
+ if (limitedData.type === "product_all") {
246
+ return true;
247
+ } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
248
+ return true;
249
+ }
250
+ return false;
251
+ });
252
+
253
+ // 选择第一个适用的优惠券(已经按过期时间排序)
254
+ var selectedDiscount = applicableDiscounts[0];
255
+
256
+ // 如果是手动折扣,则不适用优惠券
257
+ var isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && !((_product$discount_lis = product.discount_list) !== null && _product$discount_lis !== void 0 && _product$discount_lis.length);
258
+
259
+ // 勾选时覆盖手动折扣
260
+ if (options !== null && options !== void 0 && options.discountId && (options === null || options === void 0 ? void 0 : options.discountId) === (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.id)) {
261
+ isManualDiscount = false;
262
+ }
263
+
264
+ // 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
265
+ if (applicableDiscounts.length === 0 || isManualDiscount) {
266
+ processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
267
+ total: product.origin_total || product.total,
268
+ price: product.price
269
+ }), {}, {
270
+ discount_list: []
271
+ })));
272
+ return;
273
+ }
274
+
275
+ // 标记优惠券为已使用
276
+ usedDiscounts.set(selectedDiscount.id, true);
277
+
278
+ // 记录实际应用了优惠券的商品信息
279
+ var appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
280
+ var discountDetail = {
281
+ amount: product.price,
282
+ type: selectedDiscount.tag,
283
+ resource_id: selectedDiscount.id,
284
+ title: selectedDiscount.format_title,
285
+ original_amount: product.origin_total,
286
+ product_id: selectedDiscount.product_id
287
+ };
288
+ appliedProducts.push(discountDetail);
289
+ appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
290
+
291
+ // 记录应用了优惠券的商品
292
+ // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
293
+ processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
294
+ discount_list: [discountDetail],
295
+ price: 0,
296
+ total: (product.origin_total || product.total) - product.price,
297
+ origin_total: product.origin_total || product.total
298
+ }));
299
+ });
300
+
301
+ // 按原始顺序构建处理后的商品列表
302
+ var processedProductList = productList.map(function (originProduct) {
303
+ var product = _this3.hooks.getProduct(originProduct);
304
+ return processedProductsMap.get(product._id) || _this3.hooks.setProduct(originProduct, {
305
+ discount_list: [],
306
+ total: product.total,
307
+ origin_total: product.origin_total,
308
+ price: product.price
309
+ });
310
+ });
311
+
312
+ // 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
313
+ var updatedDiscountList = addModeDiscount.map(function (discount) {
314
+ // 获取此优惠券适用的商品列表
315
+ var applicableProducts = discountApplicability.get(discount.id) || [];
316
+
317
+ // 获取此优惠券适用的商品详情
318
+ var applicableProductDetails = discountApplicableProducts.get(discount.id) || [];
319
+
320
+ // 获取此优惠券实际应用的商品详情
321
+ var appliedProductDetails = appliedDiscountProducts.get(discount.id) || [];
322
+
323
+ // 根据是否有适用商品决定isAvailable
324
+ var isAvailable = applicableProducts.length > 0;
325
+
326
+ // 如果此优惠券被明确设置为不选中,保持其状态,但正确设置isAvailable
327
+ if (typeof discount.isSelected === "boolean" && discount.isSelected === false && discount.isManualSelect) {
328
+ return _objectSpread(_objectSpread({}, discount), {}, {
329
+ isUsed: false,
330
+ isSelected: false,
331
+ isAvailable: isAvailable,
332
+ // 正确设置可用性
333
+ applicableProductIds: applicableProducts,
334
+ // 添加可抵扣的商品详情
335
+ applicableProductDetails: applicableProductDetails,
336
+ // 添加实际抵扣的商品详情(对于未选中的优惠券,为空数组)
337
+ appliedProductDetails: []
338
+ });
339
+ }
340
+ if (usedDiscounts.get(discount.id)) {
341
+ return _objectSpread(_objectSpread({}, discount), {}, {
342
+ isUsed: true,
343
+ isSelected: true,
344
+ // 标记为可用,因为它已被应用
345
+ isAvailable: true,
346
+ // 记录适用的商品IDs
347
+ applicableProductIds: applicableProducts,
348
+ // 添加可抵扣的商品详情
349
+ applicableProductDetails: applicableProductDetails,
350
+ // 添加实际抵扣的商品详情
351
+ appliedProductDetails: appliedProductDetails
352
+ });
353
+ }
354
+ var isSelected = typeof discount.isSelected === "boolean" ? discount.isSelected : undefined;
355
+
356
+ // 如果是可用的 并且没有手动标记 则设置为选中
357
+ if (isAvailable && !discount.isManualSelect) {
358
+ isSelected = true;
359
+ } else if (!appliedProductDetails.length) {
360
+ isSelected = false;
361
+ }
362
+ return _objectSpread(_objectSpread({}, discount), {}, {
363
+ // 如果有适用的商品,标记为可用
364
+ isAvailable: isAvailable,
365
+ isSelected: isSelected,
366
+ // 记录适用的商品IDs
367
+ applicableProductIds: applicableProducts,
368
+ // 添加可抵扣的商品详情
369
+ applicableProductDetails: applicableProductDetails,
370
+ // 添加实际抵扣的商品详情(对于未使用的优惠券,为空数组)
371
+ appliedProductDetails: []
372
+ });
373
+ });
374
+ return {
375
+ productList: processedProductList,
376
+ discountList: [].concat(editModeDiscount, _toConsumableArray(updatedDiscountList))
377
+ };
378
+ }
379
+ }, {
380
+ key: "destroy",
381
+ value: function () {
382
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
383
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
384
+ while (1) switch (_context3.prev = _context3.next) {
385
+ case 0:
386
+ this.core.effects.offByModuleDestroy(this.name);
387
+ _context3.next = 3;
388
+ return this.core.effects.emit(RulesHooks.OnDestroy, {});
389
+ case 3:
390
+ console.log("[Rules] 已销毁");
391
+ case 4:
392
+ case "end":
393
+ return _context3.stop();
394
+ }
395
+ }, _callee3, this);
396
+ }));
397
+ function destroy() {
398
+ return _destroy.apply(this, arguments);
399
+ }
400
+ return destroy;
401
+ }()
402
+ }, {
403
+ key: "clear",
404
+ value: function () {
405
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
406
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
407
+ while (1) switch (_context4.prev = _context4.next) {
408
+ case 0:
409
+ console.log("[Rules] clear");
410
+ case 1:
411
+ case "end":
412
+ return _context4.stop();
413
+ }
414
+ }, _callee4);
415
+ }));
416
+ function clear() {
417
+ return _clear.apply(this, arguments);
418
+ }
419
+ return clear;
420
+ }()
421
+ }]);
422
+ return RulesModule;
423
+ }(BaseModule);
@@ -0,0 +1,46 @@
1
+ import { Discount } from "../Discount/types";
2
+ export declare enum RulesHooks {
3
+ OnRulesListChange = "rules:onRulesListChange",
4
+ OnDestroy = "rules:onDestroy"
5
+ }
6
+ export interface Rules {
7
+ id: string;
8
+ name: string;
9
+ description: string;
10
+ discount: number;
11
+ }
12
+ export interface RulesState {
13
+ rulesList: Rules[];
14
+ }
15
+ export interface DiscountResult {
16
+ productList: any[];
17
+ discountList: any[];
18
+ }
19
+ export interface RulesModuleAPI {
20
+ setRulesList: (rulesList: Rules[]) => Promise<void>;
21
+ clear: () => Promise<void>;
22
+ calcDiscount: (params: {
23
+ discountList: any[];
24
+ productList: any[];
25
+ }) => DiscountResult;
26
+ }
27
+ type ProductDetail = {
28
+ isManualDiscount?: boolean;
29
+ booking_id: any;
30
+ id: number;
31
+ price: number | string;
32
+ total: number;
33
+ discount_list: Discount[];
34
+ origin_total: number;
35
+ _id: string;
36
+ };
37
+ export interface RulesParamsHooks {
38
+ getProduct: (product: Record<string, any>) => ProductDetail;
39
+ setProduct: (product: Record<string, any>, values: {
40
+ total?: number;
41
+ discount_list: any[];
42
+ origin_total?: number;
43
+ price?: number;
44
+ }) => Record<string, any>;
45
+ }
46
+ export {};
@@ -0,0 +1,5 @@
1
+ export var RulesHooks = /*#__PURE__*/function (RulesHooks) {
2
+ RulesHooks["OnRulesListChange"] = "rules:onRulesListChange";
3
+ RulesHooks["OnDestroy"] = "rules:onDestroy";
4
+ return RulesHooks;
5
+ }({});
@@ -0,0 +1,13 @@
1
+ import { Module, PisellCore, ModuleOptions } from "../../types";
2
+ import { BaseModule } from "../BaseModule";
3
+ import { CartItem } from "../Cart/types";
4
+ import { ISummaryState, ISummaryModuleAPI } from "./types";
5
+ export declare class SummaryModule extends BaseModule implements Module, ISummaryModuleAPI {
6
+ protected defaultName: string;
7
+ protected defaultVersion: string;
8
+ private shopStore;
9
+ private store;
10
+ constructor(name?: string, version?: string);
11
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
12
+ getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
13
+ }
@@ -0,0 +1,80 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ 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); } }
4
+ 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); }); }; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
9
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
10
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
12
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
13
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
14
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
+ 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); }
18
+ import { BaseModule } from "../BaseModule";
19
+ import { calculatePriceDetails } from "./utils";
20
+ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
21
+ _inherits(SummaryModule, _BaseModule);
22
+ var _super = _createSuper(SummaryModule);
23
+ function SummaryModule(name, version) {
24
+ var _this;
25
+ _classCallCheck(this, SummaryModule);
26
+ _this = _super.call(this, name, version);
27
+ _defineProperty(_assertThisInitialized(_this), "defaultName", "summary");
28
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
29
+ _defineProperty(_assertThisInitialized(_this), "shopStore", void 0);
30
+ _defineProperty(_assertThisInitialized(_this), "store", void 0);
31
+ return _this;
32
+ }
33
+ _createClass(SummaryModule, [{
34
+ key: "initialize",
35
+ value: function () {
36
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
37
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
38
+ while (1) switch (_context.prev = _context.next) {
39
+ case 0:
40
+ this.core = core;
41
+ this.store = options.store;
42
+ this.shopStore = this.core.getPlugin("shopStore");
43
+ case 3:
44
+ case "end":
45
+ return _context.stop();
46
+ }
47
+ }, _callee, this);
48
+ }));
49
+ function initialize(_x, _x2) {
50
+ return _initialize.apply(this, arguments);
51
+ }
52
+ return initialize;
53
+ }()
54
+ }, {
55
+ key: "getSummary",
56
+ value: function () {
57
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(cartItems) {
58
+ var _this$shopStore$get;
59
+ var shopInfo, summary;
60
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
61
+ while (1) switch (_context2.prev = _context2.next) {
62
+ case 0:
63
+ shopInfo = ((_this$shopStore$get = this.shopStore.get("core")) === null || _this$shopStore$get === void 0 || (_this$shopStore$get = _this$shopStore$get.core) === null || _this$shopStore$get === void 0 ? void 0 : _this$shopStore$get.shop) || {};
64
+ summary = calculatePriceDetails(shopInfo, cartItems);
65
+ this.store.summary = summary;
66
+ return _context2.abrupt("return", this.store.summary);
67
+ case 4:
68
+ case "end":
69
+ return _context2.stop();
70
+ }
71
+ }, _callee2, this);
72
+ }));
73
+ function getSummary(_x3) {
74
+ return _getSummary.apply(this, arguments);
75
+ }
76
+ return getSummary;
77
+ }()
78
+ }]);
79
+ return SummaryModule;
80
+ }(BaseModule);
@@ -0,0 +1,13 @@
1
+ import { CartItem } from "../Cart/types";
2
+ export interface ISummaryState {
3
+ summary: {
4
+ subtotal: string | number;
5
+ total: string | number;
6
+ taxTitle?: string;
7
+ totalTaxFee?: string | number;
8
+ isPriceIncludeTax?: 0 | 1;
9
+ };
10
+ }
11
+ export interface ISummaryModuleAPI {
12
+ getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import Decimal from "decimal.js";
2
+ import { CartItem } from "../Cart/types";
3
+ import { ISummaryState } from "./types";
4
+ export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[]) => ISummaryState["summary"];
5
+ /**
6
+ * 计算商品小计(不含其他费用)
7
+ * @param items - 购物车商品数组
8
+ * @returns 商品总价字符串,保留2位小数
9
+ */
10
+ export declare const calculateSubtotal: (items: CartItem[]) => string;
11
+ /**
12
+ * @title: 单个商品的税费
13
+ * @description:
14
+ * 单个商品的税费 = 商品销售单价(折扣后) * 税率 * is_charge_tax /( 1+ 税率 * is_price_include_tax)
15
+ * $taxFee = $price * $taxRate * $isChargeTax / (1 + $taxRate * $isPriceIncludeTax);
16
+ * @return {*}
17
+ * @Author: xiangfeng.xue
18
+ */
19
+ export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Decimal | "0.00";