@pisell/pisellos 2.2.175 → 2.2.176

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 (172) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +193 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.d.ts +6 -0
  32. package/dist/modules/Customer/index.js +129 -83
  33. package/dist/modules/Customer/types.d.ts +2 -0
  34. package/dist/modules/Discount/index.d.ts +2 -4
  35. package/dist/modules/Discount/index.js +8 -93
  36. package/dist/modules/Discount/types.d.ts +1 -7
  37. package/dist/modules/Order/index.d.ts +84 -17
  38. package/dist/modules/Order/index.js +1239 -495
  39. package/dist/modules/Order/types.d.ts +198 -18
  40. package/dist/modules/Order/types.js +31 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  42. package/dist/modules/Order/utils/manualProductDiscount.js +212 -0
  43. package/dist/modules/Order/utils.d.ts +50 -1
  44. package/dist/modules/Order/utils.js +261 -31
  45. package/dist/modules/Quotation/index.d.ts +0 -1
  46. package/dist/modules/Quotation/index.js +23 -21
  47. package/dist/modules/Rules/index.d.ts +4 -0
  48. package/dist/modules/Rules/index.js +26 -10
  49. package/dist/modules/SalesSummary/index.js +4 -2
  50. package/dist/modules/SalesSummary/utils.js +3 -3
  51. package/dist/modules/Schedule/index.js +6 -2
  52. package/dist/modules/index.d.ts +1 -0
  53. package/dist/modules/index.js +2 -1
  54. package/dist/server/index.js +87 -29
  55. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  56. package/dist/server/modules/products/index.d.ts +1 -1
  57. package/dist/server/modules/products/index.js +130 -113
  58. package/dist/server/modules/schedule/index.js +13 -6
  59. package/dist/solution/BaseSales/index.d.ts +89 -7
  60. package/dist/solution/BaseSales/index.js +1484 -365
  61. package/dist/solution/BaseSales/types.d.ts +67 -1
  62. package/dist/solution/BaseSales/types.js +3 -1
  63. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  64. package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
  65. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  66. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  67. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +68 -16
  68. package/dist/solution/BaseSales/utils.js +46 -8
  69. package/dist/solution/BookingByStep/index.d.ts +1 -1
  70. package/dist/solution/BookingTicket/index.d.ts +133 -1
  71. package/dist/solution/BookingTicket/index.js +780 -175
  72. package/dist/solution/BookingTicket/types.d.ts +2 -0
  73. package/dist/solution/BookingTicket/types.js +3 -0
  74. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  75. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  76. package/dist/solution/BookingTicket/utils/cartView.js +4 -2
  77. package/dist/solution/ScanOrder/index.d.ts +9 -3
  78. package/dist/solution/ScanOrder/index.js +231 -128
  79. package/dist/solution/ScanOrder/utils.js +46 -8
  80. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  81. package/dist/solution/ShopDiscount/index.js +18 -23
  82. package/dist/solution/VenueBooking/index.d.ts +5 -9
  83. package/dist/solution/VenueBooking/index.js +103 -55
  84. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  85. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  86. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  87. package/lib/modules/BookingContext/index.d.ts +37 -0
  88. package/lib/modules/BookingContext/index.js +297 -0
  89. package/lib/modules/BookingContext/types.d.ts +102 -0
  90. package/lib/modules/BookingContext/types.js +34 -0
  91. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  92. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
  93. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  94. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  95. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  96. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  97. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  98. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  99. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  100. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  101. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  102. package/lib/modules/BookingContext/utils/index.js +43 -0
  103. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  104. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  105. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  106. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  107. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  108. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  109. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  110. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  111. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  112. package/lib/modules/BookingContext/utils/resources.js +377 -0
  113. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  114. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  115. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  116. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  117. package/lib/modules/Customer/index.d.ts +6 -0
  118. package/lib/modules/Customer/index.js +26 -11
  119. package/lib/modules/Customer/types.d.ts +2 -0
  120. package/lib/modules/Discount/index.d.ts +2 -4
  121. package/lib/modules/Discount/index.js +8 -63
  122. package/lib/modules/Discount/types.d.ts +1 -7
  123. package/lib/modules/Order/index.d.ts +84 -17
  124. package/lib/modules/Order/index.js +588 -145
  125. package/lib/modules/Order/types.d.ts +198 -18
  126. package/lib/modules/Order/types.js +1 -0
  127. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  128. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  129. package/lib/modules/Order/utils.d.ts +50 -1
  130. package/lib/modules/Order/utils.js +229 -21
  131. package/lib/modules/Quotation/index.d.ts +0 -1
  132. package/lib/modules/Quotation/index.js +18 -15
  133. package/lib/modules/Rules/index.d.ts +4 -0
  134. package/lib/modules/Rules/index.js +22 -14
  135. package/lib/modules/SalesSummary/index.js +4 -2
  136. package/lib/modules/SalesSummary/utils.js +3 -3
  137. package/lib/modules/Schedule/index.js +3 -1
  138. package/lib/modules/index.d.ts +1 -0
  139. package/lib/modules/index.js +3 -1
  140. package/lib/server/index.js +41 -4
  141. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  142. package/lib/server/modules/products/index.d.ts +1 -1
  143. package/lib/server/modules/products/index.js +30 -20
  144. package/lib/server/modules/schedule/index.js +2 -1
  145. package/lib/solution/BaseSales/index.d.ts +89 -7
  146. package/lib/solution/BaseSales/index.js +736 -22
  147. package/lib/solution/BaseSales/types.d.ts +67 -1
  148. package/lib/solution/BaseSales/types.js +3 -1
  149. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  150. package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
  151. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  152. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  153. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +71 -12
  154. package/lib/solution/BaseSales/utils.js +46 -6
  155. package/lib/solution/BookingByStep/index.d.ts +1 -1
  156. package/lib/solution/BookingTicket/index.d.ts +133 -1
  157. package/lib/solution/BookingTicket/index.js +352 -8
  158. package/lib/solution/BookingTicket/types.d.ts +2 -0
  159. package/lib/solution/BookingTicket/types.js +6 -0
  160. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  161. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  162. package/lib/solution/BookingTicket/utils/cartView.js +4 -2
  163. package/lib/solution/ScanOrder/index.d.ts +9 -3
  164. package/lib/solution/ScanOrder/index.js +147 -66
  165. package/lib/solution/ScanOrder/utils.js +46 -6
  166. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  167. package/lib/solution/ShopDiscount/index.js +2 -4
  168. package/lib/solution/VenueBooking/index.d.ts +5 -9
  169. package/lib/solution/VenueBooking/index.js +50 -14
  170. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  171. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  172. package/package.json +2 -2
@@ -1,10 +1,14 @@
1
1
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ 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."); }
2
4
  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); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
3
7
  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; }
4
8
  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); }
5
- 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; }
6
9
  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; }
7
10
  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; }
11
+ 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; }
8
12
  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); } }
9
13
  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); }); }; }
10
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -23,13 +27,16 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
23
27
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
24
28
  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); }
25
29
  import { BaseModule } from "../../modules/BaseModule";
30
+ import { BaseSalesHookNames } from "./types";
26
31
  import { OrderModule } from "../../modules/Order";
27
32
  import Decimal from 'decimal.js';
28
33
  import { createModule } from "../BookingByStep/types";
29
- import { composeLinePrice, sumOptionUnitPrice } from "../../modules/Order/utils";
34
+ import { composeLinePrice, createUuidV4, sumOptionUnitPrice } from "../../modules/Order/utils";
30
35
  import dayjs from 'dayjs';
31
36
  export * from "./types";
37
+ import { QuotationModule } from "../../modules/Quotation";
32
38
  import { transformBaseProductToOrderProduct as _transformBaseProductToOrderProduct } from "./utils/transformBaseProductToOrderProduct";
39
+ import { calculateBaseSalesProductBookingPrice } from "./utils/quotationPrice";
33
40
  export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
34
41
  _inherits(BaseSalesImpl, _BaseModule);
35
42
  var _super = _createSuper(BaseSalesImpl);
@@ -43,6 +50,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
43
50
  _defineProperty(_assertThisInitialized(_this), "initializeOptions", {});
44
51
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
45
52
  // LoggerManager 实例
53
+ _defineProperty(_assertThisInitialized(_this), "appPlugin", void 0);
46
54
  _defineProperty(_assertThisInitialized(_this), "store", {
47
55
  order: undefined
48
56
  });
@@ -56,17 +64,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
56
64
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
57
65
  // 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
58
66
  _defineProperty(_assertThisInitialized(_this), "currentSalesDetail", null);
67
+ _defineProperty(_assertThisInitialized(_this), "discountConfigCacheKey", null);
68
+ _defineProperty(_assertThisInitialized(_this), "hasManualDiscountSelection", false);
59
69
  return _this;
60
70
  }
61
71
 
62
72
  /**
63
73
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
64
- * 默认包含通用销售模块:products / order / salesSummary / schedule / payment。
74
+ * 默认包含通用销售模块:products / order / salesSummary / schedule / payment / quotation
65
75
  */
66
76
  _createClass(BaseSalesImpl, [{
67
77
  key: "getRegisteredModuleNames",
68
78
  value: function getRegisteredModuleNames() {
69
- return ['products', 'order', 'salesSummary', 'schedule', 'payment'];
79
+ return ['products', 'order', 'salesSummary', 'schedule', 'payment', 'quotation'];
70
80
  }
71
81
 
72
82
  /**
@@ -121,6 +131,251 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
121
131
  get: function get() {
122
132
  return this.store.payment;
123
133
  }
134
+ }, {
135
+ key: "getCurrentOrderCustomerId",
136
+ value: function getCurrentOrderCustomerId() {
137
+ var _this$store$order, _this$store$order$get;
138
+ var tempOrder = (_this$store$order = this.store.order) === null || _this$store$order === void 0 || (_this$store$order$get = _this$store$order.getTempOrder) === null || _this$store$order$get === void 0 ? void 0 : _this$store$order$get.call(_this$store$order);
139
+ var customerId = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.customer_id;
140
+ if (customerId === null || customerId === undefined) return undefined;
141
+ return customerId;
142
+ }
143
+ }, {
144
+ key: "applyQuotationScheduleResolver",
145
+ value: function applyQuotationScheduleResolver(quotation) {
146
+ var scheduleModule = this.store.schedule;
147
+ if (!scheduleModule) return;
148
+ quotation.setScheduleResolver(function (id) {
149
+ var _scheduleModule$getSc;
150
+ var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || [];
151
+ return schedules[0];
152
+ });
153
+ }
154
+ }, {
155
+ key: "loadQuotationForPriceQuery",
156
+ value: function () {
157
+ var _loadQuotationForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
158
+ var _this$otherParams;
159
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
160
+ while (1) switch (_context.prev = _context.next) {
161
+ case 0:
162
+ if (params.quotation) {
163
+ _context.next = 2;
164
+ break;
165
+ }
166
+ return _context.abrupt("return");
167
+ case 2:
168
+ this.applyQuotationScheduleResolver(params.quotation);
169
+ _context.next = 5;
170
+ return params.quotation.loadQuotations({
171
+ channel: params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel),
172
+ customer_id: params.customer_id
173
+ });
174
+ case 5:
175
+ case "end":
176
+ return _context.stop();
177
+ }
178
+ }, _callee, this);
179
+ }));
180
+ function loadQuotationForPriceQuery(_x) {
181
+ return _loadQuotationForPriceQuery.apply(this, arguments);
182
+ }
183
+ return loadQuotationForPriceQuery;
184
+ }()
185
+ }, {
186
+ key: "getPriceQueryProductId",
187
+ value: function getPriceQueryProductId(product) {
188
+ var _product$product_id;
189
+ var productId = Number((_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : product === null || product === void 0 ? void 0 : product.id);
190
+ if (!Number.isFinite(productId)) return null;
191
+ return productId;
192
+ }
193
+ }, {
194
+ key: "getPriceQuerySchedule",
195
+ value: function getPriceQuerySchedule(params) {
196
+ var booking = params.booking || {};
197
+ if (typeof booking.start_date === 'string' && booking.start_date.trim()) {
198
+ var scheduleDate = booking.start_date.trim();
199
+ var startTime = typeof booking.start_time === 'string' && booking.start_time.trim() ? booking.start_time.trim() : '00:00:00';
200
+ var datetime = dayjs("".concat(scheduleDate, " ").concat(startTime));
201
+ return {
202
+ schedule_date: scheduleDate,
203
+ schedule_datetime: datetime.isValid() ? datetime.format('YYYY-MM-DD HH:mm:ss') : "".concat(scheduleDate, " ").concat(startTime)
204
+ };
205
+ }
206
+ if (typeof params.datetime === 'string' && params.datetime.trim()) {
207
+ var _datetime = dayjs(params.datetime.trim());
208
+ if (_datetime.isValid()) {
209
+ return {
210
+ schedule_date: _datetime.format('YYYY-MM-DD'),
211
+ schedule_datetime: _datetime.format('YYYY-MM-DD HH:mm:ss')
212
+ };
213
+ }
214
+ }
215
+ var now = dayjs();
216
+ return {
217
+ schedule_date: now.format('YYYY-MM-DD'),
218
+ schedule_datetime: now.format('YYYY-MM-DD HH:mm:ss')
219
+ };
220
+ }
221
+ }, {
222
+ key: "loadProductForPriceQuery",
223
+ value: function () {
224
+ var _loadProductForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params, customerId) {
225
+ var product, productId, schedule, _this$otherParams2, _response$data, response, list;
226
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
227
+ while (1) switch (_context2.prev = _context2.next) {
228
+ case 0:
229
+ product = params.product || {};
230
+ productId = this.getPriceQueryProductId(product);
231
+ if (!(productId === null || !this.request)) {
232
+ _context2.next = 4;
233
+ break;
234
+ }
235
+ return _context2.abrupt("return", null);
236
+ case 4:
237
+ schedule = this.getPriceQuerySchedule(params);
238
+ _context2.prev = 5;
239
+ _context2.next = 8;
240
+ return this.request.post('/product/query', {
241
+ ids: [productId],
242
+ open_quotation: 1,
243
+ open_bundle: 1,
244
+ status: 'published',
245
+ num: 1,
246
+ skip: 1,
247
+ customer_id: customerId,
248
+ schedule_date: schedule.schedule_date,
249
+ schedule_datetime: schedule.schedule_datetime,
250
+ application_code: params.channel || ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.channel)
251
+ }, {
252
+ osServer: true,
253
+ customToast: function customToast() {}
254
+ });
255
+ case 8:
256
+ response = _context2.sent;
257
+ list = (response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) || (response === null || response === void 0 ? void 0 : response.list) || [];
258
+ if (Array.isArray(list)) {
259
+ _context2.next = 12;
260
+ break;
261
+ }
262
+ return _context2.abrupt("return", null);
263
+ case 12:
264
+ return _context2.abrupt("return", list.find(function (item) {
265
+ var _item$id;
266
+ return Number((_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.product_id) === productId;
267
+ }) || null);
268
+ case 15:
269
+ _context2.prev = 15;
270
+ _context2.t0 = _context2["catch"](5);
271
+ this.logWarning('loadProductForPriceQuery: 商品重查失败,使用入参 fallback', {
272
+ productId: productId,
273
+ error: _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0)
274
+ });
275
+ return _context2.abrupt("return", null);
276
+ case 19:
277
+ case "end":
278
+ return _context2.stop();
279
+ }
280
+ }, _callee2, this, [[5, 15]]);
281
+ }));
282
+ function loadProductForPriceQuery(_x2, _x3) {
283
+ return _loadProductForPriceQuery.apply(this, arguments);
284
+ }
285
+ return loadProductForPriceQuery;
286
+ }()
287
+ }, {
288
+ key: "getAuthoritativeBundleItems",
289
+ value: function getAuthoritativeBundleItems(product) {
290
+ if (Array.isArray(product === null || product === void 0 ? void 0 : product.product_bundle)) return product.product_bundle;
291
+ var groups = Array.isArray(product === null || product === void 0 ? void 0 : product.bundle_group) ? product.bundle_group : Array.isArray(product === null || product === void 0 ? void 0 : product.bundleGroup) ? product.bundleGroup : [];
292
+ return groups.flatMap(function (group) {
293
+ var items = Array.isArray(group === null || group === void 0 ? void 0 : group.bundle_item) ? group.bundle_item : Array.isArray(group === null || group === void 0 ? void 0 : group.bundleItem) ? group.bundleItem : [];
294
+ return items.map(function (item) {
295
+ var _item$group_id, _ref, _item$bundle_group_id;
296
+ return _objectSpread(_objectSpread({}, item), {}, {
297
+ group_id: (_item$group_id = item === null || item === void 0 ? void 0 : item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : group === null || group === void 0 ? void 0 : group.id,
298
+ bundle_group_id: (_ref = (_item$bundle_group_id = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item === null || item === void 0 ? void 0 : item.group_id) !== null && _ref !== void 0 ? _ref : group === null || group === void 0 ? void 0 : group.id
299
+ });
300
+ });
301
+ });
302
+ }
303
+ }, {
304
+ key: "findAuthoritativeBundleItem",
305
+ value: function findAuthoritativeBundleItem(bundle, candidates) {
306
+ var _bundle$bundle_id, _bundle$bundle_produc, _bundle$bundle_group_;
307
+ var bundleId = (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id;
308
+ if (bundleId != null) {
309
+ var matchedById = candidates.find(function (item) {
310
+ var _item$bundle_id;
311
+ return String((_item$bundle_id = item === null || item === void 0 ? void 0 : item.bundle_id) !== null && _item$bundle_id !== void 0 ? _item$bundle_id : item === null || item === void 0 ? void 0 : item.id) === String(bundleId);
312
+ });
313
+ if (matchedById) return matchedById;
314
+ }
315
+ var productId = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id;
316
+ var groupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
317
+ return candidates.find(function (item) {
318
+ var _item$bundle_product_, _item$bundle_group_id2;
319
+ var itemProductId = (_item$bundle_product_ = item === null || item === void 0 ? void 0 : item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item === null || item === void 0 ? void 0 : item._bundle_product_id;
320
+ var itemGroupId = (_item$bundle_group_id2 = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id2 !== void 0 ? _item$bundle_group_id2 : item === null || item === void 0 ? void 0 : item.group_id;
321
+ if (productId == null || String(itemProductId) !== String(productId)) return false;
322
+ if (groupId == null) return true;
323
+ return String(itemGroupId) === String(groupId);
324
+ }) || null;
325
+ }
326
+ }, {
327
+ key: "getAuthoritativeBundleUnitPrice",
328
+ value: function getAuthoritativeBundleUnitPrice(bundle) {
329
+ var _ref2, _ref3, _ref4, _bundle$price;
330
+ return (_ref2 = (_ref3 = (_ref4 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref4 !== void 0 ? _ref4 : bundle.custom_price) !== null && _ref3 !== void 0 ? _ref3 : bundle.product_price) !== null && _ref2 !== void 0 ? _ref2 : bundle.base_price;
331
+ }
332
+ }, {
333
+ key: "mergeProductForPriceQuery",
334
+ value: function mergeProductForPriceQuery(product, authoritativeProduct) {
335
+ var _this2 = this,
336
+ _product$id,
337
+ _ref5,
338
+ _product$product_id2,
339
+ _ref6,
340
+ _product$product_vari,
341
+ _ref7,
342
+ _product$num,
343
+ _ref8,
344
+ _product$quantity,
345
+ _product$product_opti,
346
+ _product$metadata;
347
+ if (!authoritativeProduct) return product;
348
+ var selectedBundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
349
+ var authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
350
+ var productBundle = selectedBundles.map(function (bundle) {
351
+ var _authoritativeBundle$, _authoritativeBundle$2;
352
+ var authoritativeBundle = _this2.findAuthoritativeBundleItem(bundle, authoritativeBundles);
353
+ var unitPrice = authoritativeBundle ? _this2.getAuthoritativeBundleUnitPrice(authoritativeBundle) : undefined;
354
+ if (unitPrice === undefined || unitPrice === null || unitPrice === '') return bundle;
355
+ return _objectSpread(_objectSpread({}, bundle), {}, {
356
+ price: unitPrice,
357
+ bundle_selling_price: unitPrice,
358
+ base_price: (_authoritativeBundle$ = authoritativeBundle === null || authoritativeBundle === void 0 ? void 0 : authoritativeBundle.base_price) !== null && _authoritativeBundle$ !== void 0 ? _authoritativeBundle$ : bundle.base_price,
359
+ product_price: (_authoritativeBundle$2 = authoritativeBundle === null || authoritativeBundle === void 0 ? void 0 : authoritativeBundle.product_price) !== null && _authoritativeBundle$2 !== void 0 ? _authoritativeBundle$2 : bundle.product_price
360
+ });
361
+ });
362
+ return _objectSpread(_objectSpread(_objectSpread({}, product), authoritativeProduct), {}, {
363
+ id: (_product$id = product.id) !== null && _product$id !== void 0 ? _product$id : authoritativeProduct.id,
364
+ product_id: (_ref5 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref5 !== void 0 ? _ref5 : authoritativeProduct.id,
365
+ product_variant_id: (_ref6 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref6 !== void 0 ? _ref6 : 0,
366
+ num: (_ref7 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref7 !== void 0 ? _ref7 : authoritativeProduct.num,
367
+ quantity: (_ref8 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref8 !== void 0 ? _ref8 : authoritativeProduct.quantity,
368
+ product_option_item: (_product$product_opti = product.product_option_item) !== null && _product$product_opti !== void 0 ? _product$product_opti : authoritativeProduct.product_option_item,
369
+ product_bundle: productBundle,
370
+ metadata: (_product$metadata = product.metadata) !== null && _product$metadata !== void 0 ? _product$metadata : authoritativeProduct.metadata
371
+ });
372
+ }
373
+ }, {
374
+ key: "getSubmitOrderSalesChannel",
375
+ value: function getSubmitOrderSalesChannel() {
376
+ var _this$otherParams3;
377
+ return (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.channel;
378
+ }
124
379
 
125
380
  /**
126
381
  * 工厂入口:根据子模块名实例化对应模块。
@@ -130,6 +385,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
130
385
  }, {
131
386
  key: "createSubModule",
132
387
  value: function createSubModule(moduleName) {
388
+ if (moduleName === 'quotation') {
389
+ return new QuotationModule("".concat(this.name, "_quotation"));
390
+ }
133
391
  return createModule(moduleName, this.name);
134
392
  }
135
393
  }, {
@@ -163,77 +421,124 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
163
421
  return {};
164
422
  }
165
423
  }
424
+ }, {
425
+ key: "getAppData",
426
+ value: function getAppData(key) {
427
+ var _this$appPlugin$getDa, _this$appPlugin, _app$models, _app$models$getStore, _app$models$getStore$, _app$models$getStore$2;
428
+ var getData = (_this$appPlugin$getDa = (_this$appPlugin = this.appPlugin).getData) === null || _this$appPlugin$getDa === void 0 ? void 0 : _this$appPlugin$getDa.call(_this$appPlugin);
429
+ if (typeof getData === 'function') return getData(key);
430
+ var app = this.appPlugin.getApp();
431
+ var coreData = app === null || app === void 0 || (_app$models = app.models) === null || _app$models === void 0 || (_app$models$getStore = _app$models.getStore) === null || _app$models$getStore === void 0 || (_app$models$getStore$ = (_app$models$getStore$2 = _app$models$getStore.call(_app$models)).getDataByModel) === null || _app$models$getStore$ === void 0 ? void 0 : _app$models$getStore$.call(_app$models$getStore$2, 'core', 'core');
432
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
433
+ }
434
+ }, {
435
+ key: "syncAppDataToTempOrder",
436
+ value: function syncAppDataToTempOrder(tempOrder) {
437
+ var isPriceIncludeTax = this.getAppData('is_price_include_tax');
438
+ var taxCountryCode = this.getAppData('tax_country_code');
439
+ var currencyCode = this.getAppData('shop_currency_code');
440
+ var currencySymbol = this.getAppData('shop_symbol');
441
+ var isChanged = false;
442
+ if (isPriceIncludeTax !== undefined) {
443
+ var nextIsPriceIncludeTax = Number(isPriceIncludeTax);
444
+ if ((nextIsPriceIncludeTax === 0 || nextIsPriceIncludeTax === 1) && tempOrder.is_price_include_tax !== nextIsPriceIncludeTax) {
445
+ tempOrder.is_price_include_tax = nextIsPriceIncludeTax;
446
+ isChanged = true;
447
+ }
448
+ }
449
+ if (taxCountryCode !== undefined) {
450
+ var nextTaxCountryCode = String(taxCountryCode || '');
451
+ if (tempOrder.tax_country_code !== nextTaxCountryCode) {
452
+ tempOrder.tax_country_code = nextTaxCountryCode;
453
+ isChanged = true;
454
+ }
455
+ }
456
+ if (currencyCode !== undefined) {
457
+ var nextCurrencyCode = String(currencyCode || '');
458
+ if (tempOrder.currency_code !== nextCurrencyCode) {
459
+ tempOrder.currency_code = nextCurrencyCode;
460
+ isChanged = true;
461
+ }
462
+ }
463
+ if (currencySymbol !== undefined) {
464
+ var nextCurrencySymbol = String(currencySymbol || '');
465
+ if (tempOrder.currency_symbol !== nextCurrencySymbol) {
466
+ tempOrder.currency_symbol = nextCurrencySymbol;
467
+ isChanged = true;
468
+ }
469
+ }
470
+ return isChanged;
471
+ }
166
472
  }, {
167
473
  key: "initialize",
168
474
  value: function () {
169
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core) {
170
- var _this$otherParams,
171
- _this2 = this;
475
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(core) {
476
+ var _this$otherParams4,
477
+ _this3 = this;
172
478
  var options,
173
- appPlugin,
174
479
  app,
175
480
  targetCacheData,
176
481
  moduleNames,
177
- _args = arguments;
178
- return _regeneratorRuntime().wrap(function _callee$(_context) {
179
- while (1) switch (_context.prev = _context.next) {
482
+ _args3 = arguments;
483
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
484
+ while (1) switch (_context3.prev = _context3.next) {
180
485
  case 0:
181
- options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
486
+ options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
182
487
  this.core = core;
183
488
  this.initializeOptions = options || {};
184
489
  // this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
185
490
  this.otherParams = options.otherParams || {};
186
- this.cacheId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.cacheId;
491
+ this.cacheId = (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.cacheId;
187
492
  this.window = core.getPlugin('window');
188
493
  this.request = core.getPlugin('request');
189
494
 
190
495
  // 获取 logger 实例
191
- appPlugin = core.getPlugin('app');
192
- if (appPlugin) {
193
- _context.next = 10;
496
+ this.appPlugin = core.getPlugin('app');
497
+ if (this.appPlugin) {
498
+ _context3.next = 10;
194
499
  break;
195
500
  }
196
501
  throw new Error('Checkout 解决方案需要 app 插件支持');
197
502
  case 10:
198
- app = appPlugin.getApp();
503
+ app = this.appPlugin.getApp();
199
504
  this.logger = app.logger;
200
505
  targetCacheData = this.readSessionCacheData();
201
506
  moduleNames = this.getRegisteredModuleNames();
202
507
  moduleNames.forEach(function (step) {
203
- var targetModule = _this2.createSubModule(step);
508
+ var targetModule = _this3.createSubModule(step);
204
509
  if (!targetModule) {
205
510
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
206
511
  }
207
- var hooks = _this2.getSubModuleHooks(step);
208
- _this2.store[step] = targetModule;
209
- _this2.core.registerModule(targetModule, _objectSpread(_objectSpread({
512
+ var hooks = _this3.getSubModuleHooks(step);
513
+ _this3.store[step] = targetModule;
514
+ _this3.core.registerModule(targetModule, _objectSpread(_objectSpread({
210
515
  initialState: (targetCacheData === null || targetCacheData === void 0 ? void 0 : targetCacheData[targetModule.name]) || {}
211
516
  }, hooks ? {
212
517
  hooks: hooks
213
518
  } : {}), {}, {
214
- otherParams: _objectSpread(_objectSpread({}, _this2.otherParams), {}, {
215
- salesSummaryModuleName: "".concat(_this2.name, "_salesSummary"),
216
- fatherModule: _this2.name,
217
- openCache: _this2.cacheId ? true : false,
218
- cacheId: _this2.cacheId
519
+ otherParams: _objectSpread(_objectSpread({}, _this3.otherParams), {}, {
520
+ salesSummaryModuleName: "".concat(_this3.name, "_salesSummary"),
521
+ fatherModule: _this3.name,
522
+ openCache: _this3.cacheId ? true : false,
523
+ cacheId: _this3.cacheId
219
524
  })
220
525
  }));
221
526
  });
222
527
  if (!this.store.schedule) {
223
- _context.next = 18;
528
+ _context3.next = 18;
224
529
  break;
225
530
  }
226
- _context.next = 18;
531
+ _context3.next = 18;
227
532
  return this.store.schedule.loadAllSchedule();
228
533
  case 18:
229
534
  this.core.effects.emit("".concat(this.name, ":onInited"), {});
230
535
  case 19:
231
536
  case "end":
232
- return _context.stop();
537
+ return _context3.stop();
233
538
  }
234
- }, _callee, this);
539
+ }, _callee3, this);
235
540
  }));
236
- function initialize(_x) {
541
+ function initialize(_x4) {
237
542
  return _initialize.apply(this, arguments);
238
543
  }
239
544
  return initialize;
@@ -241,13 +546,13 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
241
546
  }, {
242
547
  key: "destroy",
243
548
  value: function () {
244
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
245
- var _this3 = this;
246
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
247
- while (1) switch (_context2.prev = _context2.next) {
549
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
550
+ var _this4 = this;
551
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
552
+ while (1) switch (_context4.prev = _context4.next) {
248
553
  case 0:
249
554
  Object.keys(this.store).forEach(function (key) {
250
- var sub = _this3.store[key];
555
+ var sub = _this4.store[key];
251
556
  if (sub && typeof sub.destroy === 'function') {
252
557
  try {
253
558
  sub.destroy();
@@ -257,15 +562,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
257
562
  }
258
563
  });
259
564
  this.currentSalesDetail = null;
260
- _context2.next = 4;
565
+ _context4.next = 4;
261
566
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
262
567
  case 4:
263
568
  _get(_getPrototypeOf(BaseSalesImpl.prototype), "destroy", this).call(this);
264
569
  case 5:
265
570
  case "end":
266
- return _context2.stop();
571
+ return _context4.stop();
267
572
  }
268
- }, _callee2, this);
573
+ }, _callee4, this);
269
574
  }));
270
575
  function destroy() {
271
576
  return _destroy.apply(this, arguments);
@@ -282,13 +587,13 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
282
587
  }, {
283
588
  key: "loadSalesDetail",
284
589
  value: (function () {
285
- var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(orderIdOrParams) {
590
+ var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(orderIdOrParams) {
286
591
  var params, externalSaleNumber, localRecord, _sales, res, message, sales;
287
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
288
- while (1) switch (_context3.prev = _context3.next) {
592
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
593
+ while (1) switch (_context5.prev = _context5.next) {
289
594
  case 0:
290
595
  if (this.store.order) {
291
- _context3.next = 2;
596
+ _context5.next = 2;
292
597
  break;
293
598
  }
294
599
  throw new Error('order 模块未初始化');
@@ -298,107 +603,107 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
298
603
  };
299
604
  externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
300
605
  if (params.forceRemote) {
301
- _context3.next = 35;
606
+ _context5.next = 35;
302
607
  break;
303
608
  }
304
609
  if (!(params.orderId !== undefined)) {
305
- _context3.next = 11;
610
+ _context5.next = 11;
306
611
  break;
307
612
  }
308
- _context3.next = 8;
613
+ _context5.next = 8;
309
614
  return this.store.order.getLocalOrderByOrderId(params.orderId);
310
615
  case 8:
311
- _context3.t0 = _context3.sent;
312
- _context3.next = 26;
616
+ _context5.t0 = _context5.sent;
617
+ _context5.next = 26;
313
618
  break;
314
619
  case 11:
315
620
  if (!externalSaleNumber) {
316
- _context3.next = 17;
621
+ _context5.next = 17;
317
622
  break;
318
623
  }
319
- _context3.next = 14;
624
+ _context5.next = 14;
320
625
  return this.store.order.getLocalOrderByExternalSaleNumber(externalSaleNumber);
321
626
  case 14:
322
- _context3.t1 = _context3.sent;
323
- _context3.next = 25;
627
+ _context5.t1 = _context5.sent;
628
+ _context5.next = 25;
324
629
  break;
325
630
  case 17:
326
631
  if (!params.orderNumber) {
327
- _context3.next = 23;
632
+ _context5.next = 23;
328
633
  break;
329
634
  }
330
- _context3.next = 20;
635
+ _context5.next = 20;
331
636
  return this.store.order.getLocalOrderByOrderNumber(params.orderNumber);
332
637
  case 20:
333
- _context3.t2 = _context3.sent;
334
- _context3.next = 24;
638
+ _context5.t2 = _context5.sent;
639
+ _context5.next = 24;
335
640
  break;
336
641
  case 23:
337
- _context3.t2 = null;
642
+ _context5.t2 = null;
338
643
  case 24:
339
- _context3.t1 = _context3.t2;
644
+ _context5.t1 = _context5.t2;
340
645
  case 25:
341
- _context3.t0 = _context3.t1;
646
+ _context5.t0 = _context5.t1;
342
647
  case 26:
343
- localRecord = _context3.t0;
648
+ localRecord = _context5.t0;
344
649
  if (!localRecord) {
345
- _context3.next = 35;
650
+ _context5.next = 35;
346
651
  break;
347
652
  }
348
- _context3.next = 30;
653
+ _context5.next = 30;
349
654
  return this.store.order.hydrateTempOrderFromRecord(localRecord, {
350
655
  recalcOnHydrate: false
351
656
  });
352
657
  case 30:
353
- _sales = _context3.sent;
658
+ _sales = _context5.sent;
354
659
  this.currentSalesDetail = _sales;
355
- _context3.next = 34;
660
+ _context5.next = 34;
356
661
  return this.core.effects.emit("".concat(this.name, ":onSalesOrderLoaded"), {
357
662
  sales: _sales
358
663
  });
359
664
  case 34:
360
- return _context3.abrupt("return", _sales);
665
+ return _context5.abrupt("return", _sales);
361
666
  case 35:
362
667
  if (!(params.orderId === undefined || params.orderId === null)) {
363
- _context3.next = 37;
668
+ _context5.next = 37;
364
669
  break;
365
670
  }
366
671
  throw new Error('加载销售详情需要 orderId,或本地库中存在对应 externalSaleNumber/orderNumber');
367
672
  case 37:
368
- _context3.next = 39;
673
+ _context5.next = 39;
369
674
  return this.store.order.getOrderInfoByRemote(Number(params.orderId));
370
675
  case 39:
371
- res = _context3.sent;
676
+ res = _context5.sent;
372
677
  if (!(!res || res.code !== 200)) {
373
- _context3.next = 43;
678
+ _context5.next = 43;
374
679
  break;
375
680
  }
376
681
  message = res && (res.message || res.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(params.orderId);
377
682
  throw new Error(message);
378
683
  case 43:
379
- _context3.next = 45;
684
+ _context5.next = 45;
380
685
  return this.store.order.hydrateTempOrderFromRecord(res.data, {
381
686
  recalcOnHydrate: false
382
687
  });
383
688
  case 45:
384
- sales = _context3.sent;
385
- _context3.next = 48;
689
+ sales = _context5.sent;
690
+ _context5.next = 48;
386
691
  return this.store.order.saveDraft();
387
692
  case 48:
388
693
  this.currentSalesDetail = sales;
389
- _context3.next = 51;
694
+ _context5.next = 51;
390
695
  return this.core.effects.emit("".concat(this.name, ":onSalesOrderLoaded"), {
391
696
  sales: sales
392
697
  });
393
698
  case 51:
394
- return _context3.abrupt("return", sales);
699
+ return _context5.abrupt("return", sales);
395
700
  case 52:
396
701
  case "end":
397
- return _context3.stop();
702
+ return _context5.stop();
398
703
  }
399
- }, _callee3, this);
704
+ }, _callee5, this);
400
705
  }));
401
- function loadSalesDetail(_x2) {
706
+ function loadSalesDetail(_x5) {
402
707
  return _loadSalesDetail.apply(this, arguments);
403
708
  }
404
709
  return loadSalesDetail;
@@ -471,10 +776,45 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
471
776
  }, {
472
777
  key: "getTempOrder",
473
778
  value: function getTempOrder() {
474
- var _this$store$order;
475
- var result = ((_this$store$order = this.store.order) === null || _this$store$order === void 0 ? void 0 : _this$store$order.getTempOrder()) || null;
779
+ var _this$store$order2;
780
+ var result = ((_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 ? void 0 : _this$store$order2.getTempOrder()) || null;
476
781
  return result;
477
782
  }
783
+ }, {
784
+ key: "replaceTempOrder",
785
+ value: function () {
786
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(tempOrder) {
787
+ var nextTempOrder;
788
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
789
+ while (1) switch (_context6.prev = _context6.next) {
790
+ case 0:
791
+ if (this.store.order) {
792
+ _context6.next = 2;
793
+ break;
794
+ }
795
+ throw new Error('order 模块未初始化');
796
+ case 2:
797
+ _context6.next = 4;
798
+ return this.store.order.replaceTempOrder(tempOrder);
799
+ case 4:
800
+ nextTempOrder = _context6.sent;
801
+ _context6.next = 7;
802
+ return this.effectsEmit('onTempOrderReplaced', {
803
+ tempOrder: nextTempOrder
804
+ });
805
+ case 7:
806
+ return _context6.abrupt("return", nextTempOrder);
807
+ case 8:
808
+ case "end":
809
+ return _context6.stop();
810
+ }
811
+ }, _callee6, this);
812
+ }));
813
+ function replaceTempOrder(_x6) {
814
+ return _replaceTempOrder.apply(this, arguments);
815
+ }
816
+ return replaceTempOrder;
817
+ }()
478
818
  }, {
479
819
  key: "getOrderIdentity",
480
820
  value: function getOrderIdentity() {
@@ -508,14 +848,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
508
848
  }, {
509
849
  key: "updateTempOrderNote",
510
850
  value: function updateTempOrderNote(note) {
851
+ var sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
511
852
  try {
512
853
  if (!this.store.order) throw new Error('order 模块未初始化');
513
- var result = this.store.order.updateTempOrderNote(note);
854
+ var result = this.store.order.updateTempOrderNote(note, sync);
514
855
  return result;
515
856
  } catch (error) {
516
857
  throw error;
517
858
  }
518
859
  }
860
+ }, {
861
+ key: "updateRemoteOrderNote",
862
+ value: function updateRemoteOrderNote(orderId, note) {
863
+ if (!this.store.order) throw new Error('order 模块未初始化');
864
+ this.store.order.syncTempOrderNoteToRemote(orderId, note);
865
+ }
519
866
  }, {
520
867
  key: "updateTempOrderShopDiscount",
521
868
  value: function updateTempOrderShopDiscount(amount) {
@@ -528,6 +875,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
528
875
  if (!this.store.order) throw new Error('order 模块未初始化');
529
876
  return this.store.order.updateTempOrderContactsInfo(contactsInfo);
530
877
  }
878
+
879
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
880
+ }, {
881
+ key: "setEnableTempOrderPersist",
882
+ value: function setEnableTempOrderPersist(enabled) {
883
+ if (!this.store.order) throw new Error('order 模块未初始化');
884
+ this.store.order.setEnableTempOrderPersist(enabled);
885
+ }
886
+
887
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
888
+ }, {
889
+ key: "isTempOrderPersistEnabled",
890
+ value: function isTempOrderPersistEnabled() {
891
+ if (!this.store.order) return false;
892
+ return this.store.order.isTempOrderPersistEnabled();
893
+ }
531
894
  }, {
532
895
  key: "ensureTempOrder",
533
896
  value: function ensureTempOrder() {
@@ -539,32 +902,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
539
902
  }, {
540
903
  key: "addNewOrder",
541
904
  value: function () {
542
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
905
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
543
906
  var tempOrder;
544
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
545
- while (1) switch (_context4.prev = _context4.next) {
907
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
908
+ while (1) switch (_context7.prev = _context7.next) {
546
909
  case 0:
547
- _context4.prev = 0;
910
+ _context7.prev = 0;
548
911
  if (this.store.order) {
549
- _context4.next = 3;
912
+ _context7.next = 3;
550
913
  break;
551
914
  }
552
915
  throw new Error('order 模块未初始化');
553
916
  case 3:
554
- _context4.next = 5;
917
+ _context7.next = 5;
555
918
  return this.store.order.addNewOrder();
556
919
  case 5:
557
- tempOrder = _context4.sent;
558
- return _context4.abrupt("return", tempOrder);
559
- case 9:
560
- _context4.prev = 9;
561
- _context4.t0 = _context4["catch"](0);
562
- throw _context4.t0;
563
- case 12:
920
+ tempOrder = _context7.sent;
921
+ if (!this.syncAppDataToTempOrder(tempOrder)) {
922
+ _context7.next = 10;
923
+ break;
924
+ }
925
+ this.store.order.persistTempOrder();
926
+ _context7.next = 10;
927
+ return this.store.order.saveDraft();
928
+ case 10:
929
+ return _context7.abrupt("return", tempOrder);
930
+ case 13:
931
+ _context7.prev = 13;
932
+ _context7.t0 = _context7["catch"](0);
933
+ throw _context7.t0;
934
+ case 16:
564
935
  case "end":
565
- return _context4.stop();
936
+ return _context7.stop();
566
937
  }
567
- }, _callee4, this, [[0, 9]]);
938
+ }, _callee7, this, [[0, 13]]);
568
939
  }));
569
940
  function addNewOrder() {
570
941
  return _addNewOrder.apply(this, arguments);
@@ -574,22 +945,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
574
945
  }, {
575
946
  key: "saveDraft",
576
947
  value: function () {
577
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
578
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
579
- while (1) switch (_context5.prev = _context5.next) {
948
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
949
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
950
+ while (1) switch (_context8.prev = _context8.next) {
580
951
  case 0:
581
952
  if (this.store.order) {
582
- _context5.next = 2;
953
+ _context8.next = 2;
583
954
  break;
584
955
  }
585
956
  throw new Error('order 模块未初始化');
586
957
  case 2:
587
- return _context5.abrupt("return", this.store.order.saveDraft());
958
+ return _context8.abrupt("return", this.store.order.saveDraft());
588
959
  case 3:
589
960
  case "end":
590
- return _context5.stop();
961
+ return _context8.stop();
591
962
  }
592
- }, _callee5, this);
963
+ }, _callee8, this);
593
964
  }));
594
965
  function saveDraft() {
595
966
  return _saveDraft.apply(this, arguments);
@@ -600,36 +971,113 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
600
971
  }, {
601
972
  key: "restoreOrder",
602
973
  value: function () {
603
- var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
974
+ var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
604
975
  var tempOrder;
605
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
606
- while (1) switch (_context6.prev = _context6.next) {
976
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
977
+ while (1) switch (_context9.prev = _context9.next) {
607
978
  case 0:
608
- _context6.prev = 0;
979
+ _context9.prev = 0;
609
980
  if (this.store.order) {
610
- _context6.next = 3;
981
+ _context9.next = 3;
611
982
  break;
612
983
  }
613
984
  throw new Error('scanOrder 解决方案需要 order 模块支持');
614
985
  case 3:
615
986
  // this.store.resource = null;
616
987
  tempOrder = this.store.order.restoreOrder();
617
- return _context6.abrupt("return", tempOrder);
618
- case 7:
619
- _context6.prev = 7;
620
- _context6.t0 = _context6["catch"](0);
621
- throw _context6.t0;
622
- case 10:
988
+ this.currentSalesDetail = null;
989
+ this.discountConfigCacheKey = null;
990
+ this.hasManualDiscountSelection = false;
991
+ _context9.next = 9;
992
+ return this.effectsEmit('onTempOrderReplaced', {
993
+ tempOrder: tempOrder
994
+ });
995
+ case 9:
996
+ if (!this.syncAppDataToTempOrder(tempOrder)) {
997
+ _context9.next = 13;
998
+ break;
999
+ }
1000
+ this.store.order.persistTempOrder();
1001
+ _context9.next = 13;
1002
+ return this.store.order.saveDraft();
1003
+ case 13:
1004
+ return _context9.abrupt("return", tempOrder);
1005
+ case 16:
1006
+ _context9.prev = 16;
1007
+ _context9.t0 = _context9["catch"](0);
1008
+ throw _context9.t0;
1009
+ case 19:
623
1010
  case "end":
624
- return _context6.stop();
1011
+ return _context9.stop();
625
1012
  }
626
- }, _callee6, this, [[0, 7]]);
1013
+ }, _callee9, this, [[0, 16]]);
627
1014
  }));
628
1015
  function restoreOrder() {
629
1016
  return _restoreOrder.apply(this, arguments);
630
1017
  }
631
1018
  return restoreOrder;
632
1019
  }()
1020
+ /**
1021
+ * 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
1022
+ * 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
1023
+ */
1024
+ }, {
1025
+ key: "clearOrderCartLines",
1026
+ value: (function () {
1027
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1028
+ var tempOrder;
1029
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1030
+ while (1) switch (_context10.prev = _context10.next) {
1031
+ case 0:
1032
+ _context10.prev = 0;
1033
+ if (this.store.order) {
1034
+ _context10.next = 3;
1035
+ break;
1036
+ }
1037
+ throw new Error('order 模块未初始化');
1038
+ case 3:
1039
+ _context10.next = 5;
1040
+ return this.store.order.clearOrderCartLines();
1041
+ case 5:
1042
+ tempOrder = _context10.sent;
1043
+ if (this.currentSalesDetail) {
1044
+ this.currentSalesDetail = _objectSpread(_objectSpread({}, this.currentSalesDetail), {}, {
1045
+ products: [],
1046
+ bookings: [],
1047
+ rootBooking: null,
1048
+ bookingsByProductUid: {},
1049
+ discount_list: []
1050
+ });
1051
+ }
1052
+ _context10.next = 9;
1053
+ return this.effectsEmit('onTempOrderReplaced', {
1054
+ tempOrder: tempOrder
1055
+ });
1056
+ case 9:
1057
+ if (!this.syncAppDataToTempOrder(tempOrder)) {
1058
+ _context10.next = 13;
1059
+ break;
1060
+ }
1061
+ this.store.order.persistTempOrder();
1062
+ _context10.next = 13;
1063
+ return this.store.order.saveDraft();
1064
+ case 13:
1065
+ return _context10.abrupt("return", tempOrder);
1066
+ case 16:
1067
+ _context10.prev = 16;
1068
+ _context10.t0 = _context10["catch"](0);
1069
+ throw _context10.t0;
1070
+ case 19:
1071
+ case "end":
1072
+ return _context10.stop();
1073
+ }
1074
+ }, _callee10, this, [[0, 16]]);
1075
+ }));
1076
+ function clearOrderCartLines() {
1077
+ return _clearOrderCartLines.apply(this, arguments);
1078
+ }
1079
+ return clearOrderCartLines;
1080
+ }())
633
1081
  }, {
634
1082
  key: "getOrderProducts",
635
1083
  value: function getOrderProducts() {
@@ -640,37 +1088,384 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
640
1088
  }, {
641
1089
  key: "getSummary",
642
1090
  value: function () {
643
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1091
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
644
1092
  var summary;
645
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
646
- while (1) switch (_context7.prev = _context7.next) {
1093
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1094
+ while (1) switch (_context11.prev = _context11.next) {
647
1095
  case 0:
648
- _context7.prev = 0;
1096
+ _context11.prev = 0;
649
1097
  if (this.store.order) {
650
- _context7.next = 3;
1098
+ _context11.next = 3;
651
1099
  break;
652
1100
  }
653
1101
  throw new Error('order 模块未初始化');
654
1102
  case 3:
655
- _context7.next = 5;
1103
+ _context11.next = 5;
656
1104
  return this.store.order.getOrderSummary();
657
1105
  case 5:
658
- summary = _context7.sent;
659
- return _context7.abrupt("return", summary);
1106
+ summary = _context11.sent;
1107
+ return _context11.abrupt("return", summary);
660
1108
  case 9:
661
- _context7.prev = 9;
662
- _context7.t0 = _context7["catch"](0);
663
- throw _context7.t0;
1109
+ _context11.prev = 9;
1110
+ _context11.t0 = _context11["catch"](0);
1111
+ throw _context11.t0;
664
1112
  case 12:
665
1113
  case "end":
666
- return _context7.stop();
1114
+ return _context11.stop();
1115
+ }
1116
+ }, _callee11, this, [[0, 9]]);
1117
+ }));
1118
+ function getSummary() {
1119
+ return _getSummary.apply(this, arguments);
1120
+ }
1121
+ return getSummary;
1122
+ }()
1123
+ }, {
1124
+ key: "getHistoricalProductDiscountList",
1125
+ value: function getHistoricalProductDiscountList(products) {
1126
+ var _this5 = this;
1127
+ var historyDiscountList = [];
1128
+ products.forEach(function (item) {
1129
+ if (!_this5.isPersistedOrderProduct(item)) return;
1130
+ (item.discount_list || []).forEach(function (discount) {
1131
+ var _discount$discount, _discount$metadata, _discount$discount2, _discount$discount3, _discount$discount4;
1132
+ var discountId = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
1133
+ if (!discountId || !['good_pass', 'discount_card'].includes(discount.type)) return;
1134
+ var quantity = item.quantity || item.num || item.product_quantity || 1;
1135
+ var savedAmount = new Decimal(discount.amount || 0).times(quantity).plus((discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
1136
+ var index = historyDiscountList.findIndex(function (n) {
1137
+ return n.id === discountId;
1138
+ });
1139
+ if (index !== -1) {
1140
+ historyDiscountList[index] = _objectSpread(_objectSpread({}, historyDiscountList[index]), {}, {
1141
+ amount: new Decimal(historyDiscountList[index].amount || 0).plus(discount.amount || 0).toNumber(),
1142
+ savedAmount: savedAmount.plus(historyDiscountList[index].savedAmount || 0).toNumber()
1143
+ });
1144
+ return;
1145
+ }
1146
+ historyDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
1147
+ id: discountId,
1148
+ tag: discount.tag || discount.type,
1149
+ name: discount.name || ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 || (_discount$discount2 = _discount$discount2.title) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.auto),
1150
+ format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
1151
+ isEditMode: true,
1152
+ limited_relation_product_data: {},
1153
+ savedAmount: savedAmount.toNumber(),
1154
+ isAvailable: true,
1155
+ isDisabled: true,
1156
+ isSelected: true,
1157
+ product_id: ((_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.product_id) || discount.product_id
1158
+ }));
1159
+ });
1160
+ });
1161
+ return historyDiscountList;
1162
+ }
1163
+ }, {
1164
+ key: "isPersistedOrderProduct",
1165
+ value: function isPersistedOrderProduct(product) {
1166
+ var _product$order_detail, _product$booking_id;
1167
+ var orderDetailId = (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : product.orderDetailId;
1168
+ if (orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '') {
1169
+ return true;
1170
+ }
1171
+ var bookingId = (_product$booking_id = product.booking_id) !== null && _product$booking_id !== void 0 ? _product$booking_id : product.bookingId;
1172
+ return bookingId !== undefined && bookingId !== null && bookingId !== '';
1173
+ }
1174
+ }, {
1175
+ key: "mergeHistoricalDiscountList",
1176
+ value: function mergeHistoricalDiscountList(discountList, products) {
1177
+ var historyDiscountList = this.getHistoricalProductDiscountList(products);
1178
+ var historyIds = new Set(historyDiscountList.map(function (discount) {
1179
+ return discount.id;
1180
+ }));
1181
+ return [].concat(_toConsumableArray(historyDiscountList), _toConsumableArray((discountList || []).filter(function (discount) {
1182
+ return !historyIds.has(discount.id);
1183
+ })));
1184
+ }
1185
+ }, {
1186
+ key: "mergeCurrentDiscountSelectionState",
1187
+ value: function mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
1188
+ if (!currentDiscountList.length) return discountList;
1189
+ var currentDiscountMap = new Map(currentDiscountList.map(function (discount) {
1190
+ return [discount.id, discount];
1191
+ }));
1192
+ return discountList.map(function (discount) {
1193
+ var currentDiscount = currentDiscountMap.get(discount.id);
1194
+ if (!currentDiscount) return discount;
1195
+ if (currentDiscount.isManualSelect) {
1196
+ return _objectSpread(_objectSpread({}, discount), {}, {
1197
+ isSelected: false,
1198
+ isManualSelect: true
1199
+ });
1200
+ }
1201
+ if (currentDiscount.isSelected) {
1202
+ return _objectSpread(_objectSpread({}, discount), {}, {
1203
+ isSelected: true,
1204
+ isManualSelect: false
1205
+ });
1206
+ }
1207
+ return discount;
1208
+ });
1209
+ }
1210
+ }, {
1211
+ key: "loadDiscountConfig",
1212
+ value: function () {
1213
+ var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1214
+ var _this$getOrderIdentit, _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _discountModule$getDi, _discountModule$getOr, _discountModule$getDi2;
1215
+ var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, _tempOrder$holder, _tempOrder$holder2, _orderStore$summary, holders, result, _iterator, _step, _product$metadata2, _tempOrder$_extend3, _product$metadata3, _product$metadata$sou, _product$metadata4, _product$metadata5, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
1216
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1217
+ while (1) switch (_context12.prev = _context12.next) {
1218
+ case 0:
1219
+ if (this.store.order) {
1220
+ _context12.next = 2;
1221
+ break;
1222
+ }
1223
+ throw new Error('order 模块未初始化');
1224
+ case 2:
1225
+ tempOrder = this.store.order.ensureTempOrder();
1226
+ orderStore = this.store.order.store || {};
1227
+ discountModule = orderStore.discount;
1228
+ rulesModule = orderStore.rules;
1229
+ orderId = tempOrder.order_id || ((_this$getOrderIdentit = this.getOrderIdentity) === null || _this$getOrderIdentit === void 0 || (_this$getOrderIdentit = _this$getOrderIdentit.call(this)) === null || _this$getOrderIdentit === void 0 ? void 0 : _this$getOrderIdentit.orderId);
1230
+ customerId = Number((params === null || params === void 0 ? void 0 : params.customerId) || tempOrder.customer_id || ((_tempOrder$customer = tempOrder.customer) === null || _tempOrder$customer === void 0 ? void 0 : _tempOrder$customer.id) || ((_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend.customerSnapshot) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.id) || ((_tempOrder$_extend2 = tempOrder._extend) === null || _tempOrder$_extend2 === void 0 || (_tempOrder$_extend2 = _tempOrder$_extend2.customerSnapshot) === null || _tempOrder$_extend2 === void 0 ? void 0 : _tempOrder$_extend2.customer_id) || 0);
1231
+ currentDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
1232
+ originalDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
1233
+ hasManualDiscountSelection = this.hasManualDiscountSelection || currentDiscountList.some(function (discount) {
1234
+ return discount.isManualSelect;
1235
+ });
1236
+ discountAction = (params === null || params === void 0 ? void 0 : params.action) || (orderId ? 'edit' : 'create');
1237
+ discountConfigCacheKey = [customerId, discountAction, Number(orderId) || 0].join(':');
1238
+ preparedDiscountList = [];
1239
+ if (!(customerId && customerId !== 1)) {
1240
+ _context12.next = 25;
1241
+ break;
1242
+ }
1243
+ if (!(this.discountConfigCacheKey === discountConfigCacheKey)) {
1244
+ _context12.next = 19;
1245
+ break;
1246
+ }
1247
+ preparedDiscountList = originalDiscountList;
1248
+ _context12.next = 25;
1249
+ break;
1250
+ case 19:
1251
+ _context12.next = 21;
1252
+ return this.store.order.loadDiscountConfig({
1253
+ customerId: customerId,
1254
+ action: discountAction,
1255
+ orderId: Number(orderId) || undefined,
1256
+ apply: false
1257
+ });
1258
+ case 21:
1259
+ preparedDiscountList = _context12.sent;
1260
+ this.discountConfigCacheKey = discountConfigCacheKey;
1261
+ _context12.next = 25;
1262
+ return discountModule === null || discountModule === void 0 || (_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, preparedDiscountList);
1263
+ case 25:
1264
+ if (!(hasManualDiscountSelection && currentDiscountList.length)) {
1265
+ _context12.next = 27;
1266
+ break;
1267
+ }
1268
+ return _context12.abrupt("return", {
1269
+ productList: tempOrder.products || [],
1270
+ discountList: currentDiscountList
1271
+ });
1272
+ case 27:
1273
+ nextDiscountList = this.mergeHistoricalDiscountList(preparedDiscountList || (discountModule === null || discountModule === void 0 || (_discountModule$getDi2 = discountModule.getDiscountList) === null || _discountModule$getDi2 === void 0 ? void 0 : _discountModule$getDi2.call(discountModule)) || [], tempOrder.products || []);
1274
+ nextDiscountList = this.mergeCurrentDiscountSelectionState(nextDiscountList, currentDiscountList);
1275
+ _context12.next = 31;
1276
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1277
+ case 31:
1278
+ if (!rulesModule) {
1279
+ _context12.next = 67;
1280
+ break;
1281
+ }
1282
+ holders = (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
1283
+ form_record_id: tempOrder.holder.form_record_id
1284
+ }] : [];
1285
+ result = rulesModule.calcDiscount({
1286
+ productList: tempOrder.products,
1287
+ discountList: nextDiscountList,
1288
+ holders: holders,
1289
+ isFormSubject: !!((_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form',
1290
+ orderTotalAmount: Number(((_orderStore$summary = orderStore.summary) === null || _orderStore$summary === void 0 ? void 0 : _orderStore$summary.total_amount) || 0)
1291
+ }) || {
1292
+ productList: tempOrder.products,
1293
+ discountList: nextDiscountList
1294
+ };
1295
+ if (result.productList) {
1296
+ tempOrder.products = result.productList;
1297
+ }
1298
+ _iterator = _createForOfIteratorHelper(tempOrder.products || []);
1299
+ _context12.prev = 36;
1300
+ _iterator.s();
1301
+ case 38:
1302
+ if ((_step = _iterator.n()).done) {
1303
+ _context12.next = 53;
1304
+ break;
1305
+ }
1306
+ product = _step.value;
1307
+ productUid = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.unique_identification_number;
1308
+ runtimeOrigin = productUid ? (_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3.productsByUid) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3[productUid]) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.origin : undefined;
1309
+ if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || (_product$metadata3 = product.metadata) !== null && _product$metadata3 !== void 0 && _product$metadata3.is_manual_discount)) {
1310
+ _context12.next = 44;
1311
+ break;
1312
+ }
1313
+ return _context12.abrupt("continue", 51);
1314
+ case 44:
1315
+ totalPerUnitDiscount = (product.discount_list || []).reduce(function (sum, pd) {
1316
+ return sum + Number(pd.amount || 0);
1317
+ }, 0);
1318
+ optionSum = sumOptionUnitPrice(product.product_option_item);
1319
+ sourcePrice = (_product$metadata$sou = (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
1320
+ newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1321
+ newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1322
+ if (product.metadata) {
1323
+ product.metadata.main_product_selling_price = newMainSellingPrice;
1324
+ product.metadata.price_schema_version = 2;
1325
+ }
1326
+ product.selling_price = composeLinePrice({
1327
+ mainPrice: newMainSellingPrice,
1328
+ bundle: product.product_bundle
1329
+ });
1330
+ case 51:
1331
+ _context12.next = 38;
1332
+ break;
1333
+ case 53:
1334
+ _context12.next = 58;
1335
+ break;
1336
+ case 55:
1337
+ _context12.prev = 55;
1338
+ _context12.t0 = _context12["catch"](36);
1339
+ _iterator.e(_context12.t0);
1340
+ case 58:
1341
+ _context12.prev = 58;
1342
+ _iterator.f();
1343
+ return _context12.finish(58);
1344
+ case 61:
1345
+ if (!result.discountList) {
1346
+ _context12.next = 67;
1347
+ break;
1348
+ }
1349
+ nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1350
+ OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1351
+ _context12.next = 66;
1352
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1353
+ case 66:
1354
+ tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1355
+ return discount.isSelected;
1356
+ });
1357
+ case 67:
1358
+ _context12.next = 69;
1359
+ return this.store.order.recalculateSummary({
1360
+ createIfMissing: true
1361
+ });
1362
+ case 69:
1363
+ summary = _context12.sent;
1364
+ this.store.order.persistTempOrder();
1365
+ _context12.next = 73;
1366
+ return this.effectsEmit('onDiscountApplied', {
1367
+ productList: tempOrder.products || [],
1368
+ discountList: nextDiscountList,
1369
+ selectedDiscountList: tempOrder.discount_list || [],
1370
+ tempOrder: tempOrder
1371
+ });
1372
+ case 73:
1373
+ return _context12.abrupt("return", {
1374
+ productList: tempOrder.products || [],
1375
+ discountList: nextDiscountList
1376
+ });
1377
+ case 74:
1378
+ case "end":
1379
+ return _context12.stop();
1380
+ }
1381
+ }, _callee12, this, [[36, 55, 58, 61]]);
1382
+ }));
1383
+ function loadDiscountConfig(_x7) {
1384
+ return _loadDiscountConfig.apply(this, arguments);
1385
+ }
1386
+ return loadDiscountConfig;
1387
+ }()
1388
+ }, {
1389
+ key: "bestDiscount",
1390
+ value: function () {
1391
+ var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(cb) {
1392
+ var _discountModule$getOr2, _discountModule$getDi3;
1393
+ var tempOrder, orderStore, discountModule, rulesModule, originalDiscountList, currentDiscountList, nextDiscountList, result, _tempOrder$holder3, _tempOrder$holder4, _orderStore$summary2, holders;
1394
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1395
+ while (1) switch (_context13.prev = _context13.next) {
1396
+ case 0:
1397
+ if (this.store.order) {
1398
+ _context13.next = 2;
1399
+ break;
1400
+ }
1401
+ throw new Error('order 模块未初始化');
1402
+ case 2:
1403
+ tempOrder = this.store.order.ensureTempOrder();
1404
+ orderStore = this.store.order.store || {};
1405
+ discountModule = orderStore.discount;
1406
+ rulesModule = orderStore.rules;
1407
+ originalDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getOr2 = discountModule.getOriginalDiscountList) === null || _discountModule$getOr2 === void 0 ? void 0 : _discountModule$getOr2.call(discountModule)) || this.getDiscountList();
1408
+ currentDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getDi3 = discountModule.getDiscountList) === null || _discountModule$getDi3 === void 0 ? void 0 : _discountModule$getDi3.call(discountModule)) || [];
1409
+ nextDiscountList = this.mergeHistoricalDiscountList(originalDiscountList || [], tempOrder.products || []);
1410
+ result = {
1411
+ productList: tempOrder.products || [],
1412
+ discountList: nextDiscountList
1413
+ };
1414
+ _context13.next = 12;
1415
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1416
+ case 12:
1417
+ if (!rulesModule) {
1418
+ _context13.next = 23;
1419
+ break;
1420
+ }
1421
+ holders = (_tempOrder$holder3 = tempOrder.holder) !== null && _tempOrder$holder3 !== void 0 && _tempOrder$holder3.form_record_id ? [{
1422
+ form_record_id: tempOrder.holder.form_record_id
1423
+ }] : [];
1424
+ result = rulesModule.calcDiscount({
1425
+ productList: tempOrder.products,
1426
+ discountList: nextDiscountList,
1427
+ holders: holders,
1428
+ isFormSubject: !!((_tempOrder$holder4 = tempOrder.holder) !== null && _tempOrder$holder4 !== void 0 && _tempOrder$holder4.type) && tempOrder.holder.type === 'form',
1429
+ orderTotalAmount: Number(((_orderStore$summary2 = orderStore.summary) === null || _orderStore$summary2 === void 0 ? void 0 : _orderStore$summary2.total_amount) || 0)
1430
+ }) || result;
1431
+ if (result.productList) {
1432
+ tempOrder.products = result.productList;
1433
+ }
1434
+ if (!result.discountList) {
1435
+ _context13.next = 23;
1436
+ break;
1437
+ }
1438
+ nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1439
+ OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1440
+ _context13.next = 21;
1441
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1442
+ case 21:
1443
+ tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1444
+ return discount.isSelected;
1445
+ });
1446
+ result = {
1447
+ productList: tempOrder.products,
1448
+ discountList: nextDiscountList
1449
+ };
1450
+ case 23:
1451
+ _context13.next = 25;
1452
+ return this.store.order.recalculateSummary({
1453
+ createIfMissing: true
1454
+ });
1455
+ case 25:
1456
+ this.store.order.persistTempOrder();
1457
+ cb === null || cb === void 0 || cb(result);
1458
+ return _context13.abrupt("return", result);
1459
+ case 28:
1460
+ case "end":
1461
+ return _context13.stop();
667
1462
  }
668
- }, _callee7, this, [[0, 9]]);
1463
+ }, _callee13, this);
669
1464
  }));
670
- function getSummary() {
671
- return _getSummary.apply(this, arguments);
1465
+ function bestDiscount(_x8) {
1466
+ return _bestDiscount.apply(this, arguments);
672
1467
  }
673
- return getSummary;
1468
+ return bestDiscount;
674
1469
  }()
675
1470
  }, {
676
1471
  key: "getDiscountList",
@@ -681,49 +1476,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
681
1476
  }, {
682
1477
  key: "scanPromotionCode",
683
1478
  value: function () {
684
- var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(code, customerId) {
1479
+ var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(code, customerId) {
685
1480
  var raw;
686
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
687
- while (1) switch (_context8.prev = _context8.next) {
1481
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1482
+ while (1) switch (_context14.prev = _context14.next) {
688
1483
  case 0:
689
- _context8.prev = 0;
1484
+ _context14.prev = 0;
690
1485
  if (this.store.order) {
691
- _context8.next = 3;
1486
+ _context14.next = 3;
692
1487
  break;
693
1488
  }
694
1489
  throw new Error('order 模块未初始化');
695
1490
  case 3:
696
- _context8.next = 5;
1491
+ _context14.next = 5;
697
1492
  return this.store.order.scanCode(code, customerId);
698
1493
  case 5:
699
- raw = _context8.sent;
1494
+ raw = _context14.sent;
700
1495
  if (!raw.isAvailable) {
701
- _context8.next = 10;
1496
+ _context14.next = 10;
702
1497
  break;
703
1498
  }
704
- _context8.next = 9;
1499
+ _context14.next = 9;
705
1500
  return this.store.order.recalculateSummary({
706
1501
  createIfMissing: true
707
1502
  });
708
1503
  case 9:
709
1504
  this.store.order.persistTempOrder();
710
1505
  case 10:
711
- return _context8.abrupt("return", {
1506
+ return _context14.abrupt("return", {
712
1507
  isAvailable: raw.isAvailable,
713
1508
  type: raw.type,
714
1509
  unavailableReason: raw.unavailableReason
715
1510
  });
716
1511
  case 13:
717
- _context8.prev = 13;
718
- _context8.t0 = _context8["catch"](0);
719
- throw _context8.t0;
1512
+ _context14.prev = 13;
1513
+ _context14.t0 = _context14["catch"](0);
1514
+ throw _context14.t0;
720
1515
  case 16:
721
1516
  case "end":
722
- return _context8.stop();
1517
+ return _context14.stop();
723
1518
  }
724
- }, _callee8, this, [[0, 13]]);
1519
+ }, _callee14, this, [[0, 13]]);
725
1520
  }));
726
- function scanPromotionCode(_x3, _x4) {
1521
+ function scanPromotionCode(_x9, _x10) {
727
1522
  return _scanPromotionCode.apply(this, arguments);
728
1523
  }
729
1524
  return scanPromotionCode;
@@ -731,14 +1526,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
731
1526
  }, {
732
1527
  key: "setDiscountSelected",
733
1528
  value: function () {
734
- var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
735
- var _tempOrder$holder, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder2, result, beforeSelectedIds, _iterator, _step, d, selectedResourceIds, _iterator2, _step2, _product$metadata, _tempOrder$_extend, _product$metadata2, _product$metadata$sou, _product$metadata3, _product$metadata4, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
736
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
737
- while (1) switch (_context9.prev = _context9.next) {
1529
+ var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1530
+ var _tempOrder$holder5, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder6, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, _iterator3, _step3, _product$metadata6, _tempOrder$_extend4, _product$metadata7, _product$metadata$sou2, _product$metadata8, _product$metadata9, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
1531
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1532
+ while (1) switch (_context15.prev = _context15.next) {
738
1533
  case 0:
739
- _context9.prev = 0;
1534
+ _context15.prev = 0;
740
1535
  if (this.store.order) {
741
- _context9.next = 3;
1536
+ _context15.next = 3;
742
1537
  break;
743
1538
  }
744
1539
  throw new Error('order 模块未初始化');
@@ -750,23 +1545,24 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
750
1545
  isManualSelect: !params.isSelected
751
1546
  }) : d;
752
1547
  });
1548
+ this.hasManualDiscountSelection = true;
753
1549
  tempOrder = this.store.order.ensureTempOrder();
754
1550
  orderStore = this.store.order.store || {};
755
1551
  discountModule = orderStore.discount;
756
1552
  rulesModule = orderStore.rules;
757
- holders = (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
1553
+ holders = (_tempOrder$holder5 = tempOrder.holder) !== null && _tempOrder$holder5 !== void 0 && _tempOrder$holder5.form_record_id ? [{
758
1554
  form_record_id: tempOrder.holder.form_record_id
759
1555
  }] : [];
760
1556
  nextDiscountList = updated;
761
- _context9.next = 13;
1557
+ _context15.next = 14;
762
1558
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(updated);
763
- case 13:
1559
+ case 14:
764
1560
  if (rulesModule) {
765
1561
  result = rulesModule.calcDiscount({
766
1562
  productList: tempOrder.products,
767
1563
  discountList: updated,
768
1564
  holders: holders,
769
- isFormSubject: !!((_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form'
1565
+ isFormSubject: !!((_tempOrder$holder6 = tempOrder.holder) !== null && _tempOrder$holder6 !== void 0 && _tempOrder$holder6.type) && tempOrder.holder.type === 'form'
770
1566
  }, {
771
1567
  discountId: params.discountId,
772
1568
  isSelected: params.isSelected
@@ -785,18 +1581,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
785
1581
  }).map(function (d) {
786
1582
  return d.id;
787
1583
  }));
788
- _iterator = _createForOfIteratorHelper(nextDiscountList);
1584
+ _iterator2 = _createForOfIteratorHelper(nextDiscountList);
789
1585
  try {
790
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
791
- d = _step.value;
1586
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1587
+ d = _step2.value;
792
1588
  if (d.isSelected && !beforeSelectedIds.has(d.id)) {
793
1589
  d.isSelected = false;
1590
+ d.isManualSelect = true;
794
1591
  }
795
1592
  }
796
1593
  } catch (err) {
797
- _iterator.e(err);
1594
+ _iterator2.e(err);
798
1595
  } finally {
799
- _iterator.f();
1596
+ _iterator2.f();
800
1597
  }
801
1598
  }
802
1599
  }
@@ -806,23 +1603,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
806
1603
  }).map(function (d) {
807
1604
  return d.id;
808
1605
  }));
809
- _iterator2 = _createForOfIteratorHelper(tempOrder.products);
810
- _context9.prev = 16;
811
- _iterator2.s();
812
- case 18:
813
- if ((_step2 = _iterator2.n()).done) {
814
- _context9.next = 34;
1606
+ _iterator3 = _createForOfIteratorHelper(tempOrder.products);
1607
+ _context15.prev = 17;
1608
+ _iterator3.s();
1609
+ case 19:
1610
+ if ((_step3 = _iterator3.n()).done) {
1611
+ _context15.next = 35;
815
1612
  break;
816
1613
  }
817
- product = _step2.value;
818
- productUid = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number;
819
- runtimeOrigin = productUid ? (_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend.productsByUid) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend[productUid]) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.origin : undefined;
820
- if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || (_product$metadata2 = product.metadata) !== null && _product$metadata2 !== void 0 && _product$metadata2.is_manual_discount)) {
821
- _context9.next = 24;
1614
+ product = _step3.value;
1615
+ productUid = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number;
1616
+ runtimeOrigin = productUid ? (_tempOrder$_extend4 = tempOrder._extend) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4.productsByUid) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4[productUid]) === null || _tempOrder$_extend4 === void 0 ? void 0 : _tempOrder$_extend4.origin : undefined;
1617
+ if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || (_product$metadata7 = product.metadata) !== null && _product$metadata7 !== void 0 && _product$metadata7.is_manual_discount)) {
1618
+ _context15.next = 25;
822
1619
  break;
823
1620
  }
824
- return _context9.abrupt("continue", 32);
825
- case 24:
1621
+ return _context15.abrupt("continue", 33);
1622
+ case 25:
826
1623
  product.discount_list = (product.discount_list || []).filter(function (pd) {
827
1624
  var _pd$discount$resource, _pd$discount;
828
1625
  var rid = (_pd$discount$resource = (_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) !== null && _pd$discount$resource !== void 0 ? _pd$discount$resource : pd.id;
@@ -835,7 +1632,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
835
1632
  return sum + (pd.amount || 0);
836
1633
  }, 0); // TODO 这块逻辑需要拿掉
837
1634
  optionSum = sumOptionUnitPrice(product.product_option_item);
838
- sourcePrice = (_product$metadata$sou = (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
1635
+ sourcePrice = (_product$metadata$sou2 = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.source_product_price) !== null && _product$metadata$sou2 !== void 0 ? _product$metadata$sou2 : ((_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
839
1636
  newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
840
1637
  newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
841
1638
  if (product.metadata) {
@@ -846,66 +1643,134 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
846
1643
  mainPrice: newMainSellingPrice,
847
1644
  bundle: product.product_bundle
848
1645
  });
849
- case 32:
850
- _context9.next = 18;
1646
+ case 33:
1647
+ _context15.next = 19;
851
1648
  break;
852
- case 34:
853
- _context9.next = 39;
1649
+ case 35:
1650
+ _context15.next = 40;
854
1651
  break;
855
- case 36:
856
- _context9.prev = 36;
857
- _context9.t0 = _context9["catch"](16);
858
- _iterator2.e(_context9.t0);
859
- case 39:
860
- _context9.prev = 39;
861
- _iterator2.f();
862
- return _context9.finish(39);
863
- case 42:
1652
+ case 37:
1653
+ _context15.prev = 37;
1654
+ _context15.t0 = _context15["catch"](17);
1655
+ _iterator3.e(_context15.t0);
1656
+ case 40:
1657
+ _context15.prev = 40;
1658
+ _iterator3.f();
1659
+ return _context15.finish(40);
1660
+ case 43:
864
1661
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
865
- _context9.next = 45;
1662
+ _context15.next = 46;
866
1663
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
867
- case 45:
1664
+ case 46:
868
1665
  tempOrder.discount_list = (nextDiscountList || []).filter(function (d) {
869
1666
  return d.isSelected;
870
1667
  });
871
- _context9.next = 48;
1668
+ _context15.next = 49;
872
1669
  return this.store.order.recalculateSummary({
873
1670
  createIfMissing: true
874
1671
  });
875
- case 48:
1672
+ case 49:
876
1673
  this.store.order.persistTempOrder();
877
- _context9.next = 54;
1674
+ this.effectsEmit('onDiscountApplied', {
1675
+ productList: tempOrder.products,
1676
+ discountList: nextDiscountList,
1677
+ selectedDiscountList: tempOrder.discount_list,
1678
+ tempOrder: tempOrder
1679
+ });
1680
+ _context15.next = 56;
878
1681
  break;
879
- case 51:
880
- _context9.prev = 51;
881
- _context9.t1 = _context9["catch"](0);
882
- throw _context9.t1;
883
- case 54:
1682
+ case 53:
1683
+ _context15.prev = 53;
1684
+ _context15.t1 = _context15["catch"](0);
1685
+ throw _context15.t1;
1686
+ case 56:
884
1687
  case "end":
885
- return _context9.stop();
1688
+ return _context15.stop();
886
1689
  }
887
- }, _callee9, this, [[0, 51], [16, 36, 39, 42]]);
1690
+ }, _callee15, this, [[0, 53], [17, 37, 40, 43]]);
888
1691
  }));
889
- function setDiscountSelected(_x5) {
1692
+ function setDiscountSelected(_x11) {
890
1693
  return _setDiscountSelected.apply(this, arguments);
891
1694
  }
892
1695
  return setDiscountSelected;
893
1696
  }()
1697
+ }, {
1698
+ key: "applyDiscountCalculationResult",
1699
+ value: function () {
1700
+ var _applyDiscountCalculationResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(result) {
1701
+ var tempOrder, orderStore, discountModule;
1702
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1703
+ while (1) switch (_context16.prev = _context16.next) {
1704
+ case 0:
1705
+ _context16.prev = 0;
1706
+ if (this.store.order) {
1707
+ _context16.next = 3;
1708
+ break;
1709
+ }
1710
+ throw new Error('order 模块未初始化');
1711
+ case 3:
1712
+ if (result) {
1713
+ _context16.next = 5;
1714
+ break;
1715
+ }
1716
+ return _context16.abrupt("return");
1717
+ case 5:
1718
+ tempOrder = this.store.order.ensureTempOrder();
1719
+ orderStore = this.store.order.store || {};
1720
+ discountModule = orderStore.discount;
1721
+ if (result.productList) {
1722
+ tempOrder.products = result.productList;
1723
+ }
1724
+ if (!result.discountList) {
1725
+ _context16.next = 14;
1726
+ break;
1727
+ }
1728
+ OrderModule.populateSavedAmounts(tempOrder.products, result.discountList);
1729
+ _context16.next = 13;
1730
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(result.discountList);
1731
+ case 13:
1732
+ tempOrder.discount_list = result.discountList.filter(function (discount) {
1733
+ return discount.isSelected;
1734
+ });
1735
+ case 14:
1736
+ _context16.next = 16;
1737
+ return this.store.order.recalculateSummary({
1738
+ createIfMissing: true
1739
+ });
1740
+ case 16:
1741
+ this.store.order.persistTempOrder();
1742
+ _context16.next = 22;
1743
+ break;
1744
+ case 19:
1745
+ _context16.prev = 19;
1746
+ _context16.t0 = _context16["catch"](0);
1747
+ throw _context16.t0;
1748
+ case 22:
1749
+ case "end":
1750
+ return _context16.stop();
1751
+ }
1752
+ }, _callee16, this, [[0, 19]]);
1753
+ }));
1754
+ function applyDiscountCalculationResult(_x12) {
1755
+ return _applyDiscountCalculationResult.apply(this, arguments);
1756
+ }
1757
+ return applyDiscountCalculationResult;
1758
+ }()
894
1759
  }, {
895
1760
  key: "submitScanOrder",
896
1761
  value: function () {
897
- var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
898
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
899
- while (1) switch (_context10.prev = _context10.next) {
1762
+ var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1763
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1764
+ while (1) switch (_context17.prev = _context17.next) {
900
1765
  case 0:
901
- return _context10.abrupt("return", this.submitSalesOrder(params));
1766
+ return _context17.abrupt("return", this.submitSalesOrder(params));
902
1767
  case 1:
903
1768
  case "end":
904
- return _context10.stop();
1769
+ return _context17.stop();
905
1770
  }
906
- }, _callee10, this);
1771
+ }, _callee17, this);
907
1772
  }));
908
- function submitScanOrder(_x6) {
1773
+ function submitScanOrder(_x13) {
909
1774
  return _submitScanOrder.apply(this, arguments);
910
1775
  }
911
1776
  return submitScanOrder;
@@ -919,14 +1784,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
919
1784
  }, {
920
1785
  key: "submitSalesOrder",
921
1786
  value: (function () {
922
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
923
- var _this$otherParams2, _this$otherParams3, _this$otherParams4, _this$otherParams5;
1787
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1788
+ var _this$otherParams5, _this$otherParams6, _this$otherParams7;
924
1789
  var submitParams;
925
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
926
- while (1) switch (_context11.prev = _context11.next) {
1790
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1791
+ while (1) switch (_context18.prev = _context18.next) {
927
1792
  case 0:
928
1793
  if (this.store.order) {
929
- _context11.next = 2;
1794
+ _context18.next = 2;
930
1795
  break;
931
1796
  }
932
1797
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -934,10 +1799,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
934
1799
  this.store.order.persistTempOrder();
935
1800
  submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
936
1801
  cacheId: this.cacheId,
937
- platform: (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.platform,
938
- businessCode: (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.businessCode,
939
- channel: (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.channel,
940
- type: (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.type
1802
+ platform: (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform,
1803
+ businessCode: (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode,
1804
+ channel: this.getSubmitOrderSalesChannel(),
1805
+ type: (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.type
941
1806
  }, (params === null || params === void 0 ? void 0 : params.payments) !== undefined ? {
942
1807
  payments: params.payments
943
1808
  } : {}), (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined ? {
@@ -947,14 +1812,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
947
1812
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
948
1813
  enhancePayload: params.enhancePayload
949
1814
  } : {});
950
- return _context11.abrupt("return", this.store.order.submitTempOrder(submitParams));
951
- case 5:
1815
+ console.log(submitParams, 'submitParams123');
1816
+ return _context18.abrupt("return", this.store.order.submitTempOrder(submitParams));
1817
+ case 6:
952
1818
  case "end":
953
- return _context11.stop();
1819
+ return _context18.stop();
954
1820
  }
955
- }, _callee11, this);
1821
+ }, _callee18, this);
956
1822
  }));
957
- function submitSalesOrder(_x7) {
1823
+ function submitSalesOrder(_x14) {
958
1824
  return _submitSalesOrder.apply(this, arguments);
959
1825
  }
960
1826
  return submitSalesOrder;
@@ -962,24 +1828,75 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
962
1828
  }, {
963
1829
  key: "syncPaymentsToOrder",
964
1830
  value: function () {
965
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
966
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
967
- while (1) switch (_context12.prev = _context12.next) {
1831
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
1832
+ var _params$channel;
1833
+ var channel, syncParams, syncState, payments, syncResult;
1834
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1835
+ while (1) switch (_context19.prev = _context19.next) {
968
1836
  case 0:
969
1837
  if (this.store.order) {
970
- _context12.next = 2;
1838
+ _context19.next = 2;
971
1839
  break;
972
1840
  }
973
1841
  throw new Error('order 模块未初始化');
974
1842
  case 2:
975
- return _context12.abrupt("return", this.store.order.syncPaymentsToOrder(params));
976
- case 3:
1843
+ channel = (_params$channel = params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel();
1844
+ syncParams = _objectSpread(_objectSpread({}, params), channel !== undefined ? {
1845
+ channel: channel
1846
+ } : {});
1847
+ syncState = this.store.order.getOrderSyncState();
1848
+ if (!(params.submitWhenPaid && syncState === 'submitting')) {
1849
+ _context19.next = 7;
1850
+ break;
1851
+ }
1852
+ return _context19.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
1853
+ case 7:
1854
+ payments = params.payments || [];
1855
+ _context19.next = 10;
1856
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncStart, {
1857
+ payments: payments,
1858
+ params: syncParams,
1859
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1860
+ orderSnapshot: this.store.order.getOrderSnapshot()
1861
+ });
1862
+ case 10:
1863
+ _context19.prev = 10;
1864
+ _context19.next = 13;
1865
+ return this.store.order.syncPaymentsToOrder(syncParams);
1866
+ case 13:
1867
+ syncResult = _context19.sent;
1868
+ _context19.next = 16;
1869
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
1870
+ ok: true,
1871
+ syncResult: syncResult,
1872
+ payments: this.store.order.getOrderPayments(),
1873
+ params: syncParams,
1874
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1875
+ orderSnapshot: this.store.order.getOrderSnapshot()
1876
+ });
1877
+ case 16:
1878
+ return _context19.abrupt("return", syncResult);
1879
+ case 19:
1880
+ _context19.prev = 19;
1881
+ _context19.t0 = _context19["catch"](10);
1882
+ _context19.next = 23;
1883
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
1884
+ ok: false,
1885
+ error: _context19.t0,
1886
+ payments: this.store.order.getOrderPayments(),
1887
+ params: syncParams,
1888
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1889
+ orderSnapshot: this.store.order.getOrderSnapshot()
1890
+ });
1891
+ case 23:
1892
+ throw _context19.t0;
1893
+ case 24:
977
1894
  case "end":
978
- return _context12.stop();
1895
+ return _context19.stop();
979
1896
  }
980
- }, _callee12, this);
1897
+ }, _callee19, this, [[10, 19]]);
981
1898
  }));
982
- function syncPaymentsToOrder(_x8) {
1899
+ function syncPaymentsToOrder(_x15) {
983
1900
  return _syncPaymentsToOrder.apply(this, arguments);
984
1901
  }
985
1902
  return syncPaymentsToOrder;
@@ -1003,8 +1920,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1003
1920
  }, {
1004
1921
  key: "addOrderPayment",
1005
1922
  value: function addOrderPayment(payment) {
1923
+ var _this6 = this;
1006
1924
  if (!this.store.order) throw new Error('order 模块未初始化');
1007
- return this.store.order.addOrderPayment(payment);
1925
+ var paymentRecord = payment;
1926
+ var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1927
+ if (!metadata.unique_identification_number) {
1928
+ metadata.unique_identification_number = createUuidV4();
1929
+ }
1930
+ var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1931
+ metadata: metadata
1932
+ }));
1933
+ var amountSnapshot = this.store.order.getOrderAmountSnapshot();
1934
+ var syncState = this.store.order.getOrderSyncState();
1935
+ if (amountSnapshot && syncState !== 'submitting') {
1936
+ var paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? 'paid' : 'partially_paid';
1937
+ void this.syncPaymentsToOrder({
1938
+ payments: payments,
1939
+ paymentStatus: paymentStatus,
1940
+ submitWhenPaid: true,
1941
+ smallTicketDataFlag: 1
1942
+ }).catch(function (error) {
1943
+ _this6.logError('auto sync payments failed', {
1944
+ error: error instanceof Error ? error.message : String(error)
1945
+ });
1946
+ });
1947
+ }
1948
+ return payments;
1008
1949
  }
1009
1950
 
1010
1951
  /** 更新当前订单中的指定支付项。 */
@@ -1033,20 +1974,25 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1033
1974
  }, {
1034
1975
  key: "getWalletProductList",
1035
1976
  value: function getWalletProductList() {
1036
- var _this$store$order2, _tempOrder$products;
1037
- var tempOrder = (_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 ? void 0 : _this$store$order2.getTempOrder();
1977
+ var _this$store$order3, _tempOrder$products, _tempOrder$products2;
1978
+ var tempOrder = (_this$store$order3 = this.store.order) === null || _this$store$order3 === void 0 ? void 0 : _this$store$order3.getTempOrder();
1038
1979
  if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$products = tempOrder.products) !== null && _tempOrder$products !== void 0 && _tempOrder$products.length)) return [];
1039
- return tempOrder.products.map(function (product) {
1040
- var _product$product_vari, _product$is_charge_ta, _product$holder_id, _metadata$main_produc, _metadata$main_produc2;
1980
+ // 过滤出有 product_id的商品来,如果没有代表他是自定义商品,不需要参与 wallet
1981
+ var products = tempOrder === null || tempOrder === void 0 || (_tempOrder$products2 = tempOrder.products) === null || _tempOrder$products2 === void 0 ? void 0 : _tempOrder$products2.filter(function (n) {
1982
+ return n.product_id;
1983
+ });
1984
+ return products.map(function (product) {
1985
+ var _product$product_vari2, _product$is_charge_ta, _product$holder_id, _metadata$main_produc, _metadata$main_produc2;
1041
1986
  var metadata = product.metadata || {};
1042
1987
  return {
1043
1988
  product_id: product.product_id,
1044
- product_variant_id: String((_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : ''),
1989
+ product_variant_id: String((_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : ''),
1045
1990
  quantity: product.num || 1,
1046
1991
  is_price_include_tax: tempOrder.is_price_include_tax,
1047
1992
  is_charge_tax: (_product$is_charge_ta = product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0,
1048
1993
  tax_fee: product.tax_fee,
1049
1994
  selling_price: Number(product.selling_price || 0),
1995
+ discount_list: product.discount_list || [],
1050
1996
  holder_id: (_product$holder_id = product.holder_id) !== null && _product$holder_id !== void 0 ? _product$holder_id : metadata.holder_id,
1051
1997
  original_price: product.original_price,
1052
1998
  main_product_original_price: (_metadata$main_produc = metadata.main_product_original_price) !== null && _metadata$main_produc !== void 0 ? _metadata$main_produc : product.original_price,
@@ -1057,11 +2003,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1057
2003
  surcharge_rounding_remainder: metadata.surcharge_rounding_remainder
1058
2004
  },
1059
2005
  product_bundle: (product.product_bundle || []).map(function (bundle) {
2006
+ var _bundle$bundle_id2, _bundle$bundle_produc2, _bundle$bundle_group_2;
1060
2007
  var bundleMetadata = bundle.metadata || {};
1061
2008
  return {
1062
2009
  is_price_include_tax: tempOrder.is_price_include_tax,
1063
- bundle_id: bundle.bundle_id,
1064
- bundle_product_id: bundle.bundle_product_id,
2010
+ // 套餐子项在 tempOrder 上常为 id(如 1718),prepare/deduction 协议要求 bundle_id
2011
+ bundle_id: (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id,
2012
+ bundle_product_id: (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id,
2013
+ bundle_group_id: (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id,
1065
2014
  bundle_variant_id: bundle.bundle_variant_id,
1066
2015
  price_type: bundle.price_type,
1067
2016
  price_type_ext: bundle.price_type_ext,
@@ -1082,20 +2031,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1082
2031
  }, {
1083
2032
  key: "initWalletData",
1084
2033
  value: function () {
1085
- var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
1086
- var _params$order_wait_pa, _ref, _tempOrder$is_price_i;
2034
+ var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
2035
+ var _params$order_wait_pa, _ref9, _tempOrder$is_price_i;
1087
2036
  var snapshot, tempOrder, amount, walletBusinessData, result;
1088
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1089
- while (1) switch (_context13.prev = _context13.next) {
2037
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2038
+ while (1) switch (_context20.prev = _context20.next) {
1090
2039
  case 0:
1091
2040
  if (this.store.order) {
1092
- _context13.next = 2;
2041
+ _context20.next = 2;
1093
2042
  break;
1094
2043
  }
1095
2044
  throw new Error('order 模块未初始化');
1096
2045
  case 2:
1097
2046
  if (this.store.payment) {
1098
- _context13.next = 4;
2047
+ _context20.next = 4;
1099
2048
  break;
1100
2049
  }
1101
2050
  throw new Error('payment 模块未初始化');
@@ -1104,10 +2053,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1104
2053
  tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
1105
2054
  amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
1106
2055
  if (!(!tempOrder || !amount)) {
1107
- _context13.next = 9;
2056
+ _context20.next = 9;
1108
2057
  break;
1109
2058
  }
1110
- return _context13.abrupt("return", {
2059
+ return _context20.abrupt("return", {
1111
2060
  walletRecommendList: [],
1112
2061
  userIdentificationCodes: [],
1113
2062
  transformList: [],
@@ -1126,15 +2075,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1126
2075
  },
1127
2076
  products: this.getWalletProductList(),
1128
2077
  order_wait_pay_amount: (_params$order_wait_pa = params === null || params === void 0 ? void 0 : params.order_wait_pay_amount) !== null && _params$order_wait_pa !== void 0 ? _params$order_wait_pa : Number(amount.amountGap || 0),
1129
- is_price_include_tax: (_ref = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref !== void 0 ? _ref : 1
2078
+ is_price_include_tax: (_ref9 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref9 !== void 0 ? _ref9 : 1
1130
2079
  }, snapshot.identity.orderId ? {
1131
2080
  payment_order_id: String(snapshot.identity.orderId)
1132
2081
  } : {});
1133
- _context13.next = 12;
2082
+ _context20.next = 12;
1134
2083
  return this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
1135
2084
  case 12:
1136
- result = _context13.sent;
1137
- _context13.next = 15;
2085
+ result = _context20.sent;
2086
+ _context20.next = 15;
1138
2087
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
1139
2088
  orderId: snapshot.identity.orderId,
1140
2089
  customerId: walletBusinessData.customer_id,
@@ -1146,14 +2095,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1146
2095
  timestamp: Date.now()
1147
2096
  });
1148
2097
  case 15:
1149
- return _context13.abrupt("return", result);
2098
+ return _context20.abrupt("return", result);
1150
2099
  case 16:
1151
2100
  case "end":
1152
- return _context13.stop();
2101
+ return _context20.stop();
1153
2102
  }
1154
- }, _callee13, this);
2103
+ }, _callee20, this);
1155
2104
  }));
1156
- function initWalletData(_x9) {
2105
+ function initWalletData(_x16) {
1157
2106
  return _initWalletData.apply(this, arguments);
1158
2107
  }
1159
2108
  return initWalletData;
@@ -1180,27 +2129,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1180
2129
  }, {
1181
2130
  key: "getPaymentMethodsAsync",
1182
2131
  value: (function () {
1183
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
2132
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1184
2133
  var response;
1185
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1186
- while (1) switch (_context14.prev = _context14.next) {
2134
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2135
+ while (1) switch (_context21.prev = _context21.next) {
1187
2136
  case 0:
1188
2137
  if (!this.store.payment) {
1189
- _context14.next = 2;
2138
+ _context21.next = 2;
1190
2139
  break;
1191
2140
  }
1192
- return _context14.abrupt("return", this.store.payment.getPayMethodListAsync());
2141
+ return _context21.abrupt("return", this.store.payment.getPayMethodListAsync());
1193
2142
  case 2:
1194
- _context14.next = 4;
2143
+ _context21.next = 4;
1195
2144
  return this.request.get('/pay/custom-payment/all');
1196
2145
  case 4:
1197
- response = _context14.sent;
1198
- return _context14.abrupt("return", (response === null || response === void 0 ? void 0 : response.data) || []);
2146
+ response = _context21.sent;
2147
+ return _context21.abrupt("return", (response === null || response === void 0 ? void 0 : response.data) || []);
1199
2148
  case 6:
1200
2149
  case "end":
1201
- return _context14.stop();
2150
+ return _context21.stop();
1202
2151
  }
1203
- }, _callee14, this);
2152
+ }, _callee21, this);
1204
2153
  }));
1205
2154
  function getPaymentMethodsAsync() {
1206
2155
  return _getPaymentMethodsAsync.apply(this, arguments);
@@ -1241,49 +2190,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1241
2190
  }, {
1242
2191
  key: "sendCustomerPayLink",
1243
2192
  value: (function () {
1244
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1245
- var orderIds, _ref2, _ref3, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
1246
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1247
- while (1) switch (_context15.prev = _context15.next) {
2193
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2194
+ var orderIds, _ref10, _ref11, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
2195
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2196
+ while (1) switch (_context22.prev = _context22.next) {
1248
2197
  case 0:
1249
2198
  if (this.store.order) {
1250
- _context15.next = 2;
2199
+ _context22.next = 2;
1251
2200
  break;
1252
2201
  }
1253
2202
  throw new Error('order 模块未初始化');
1254
2203
  case 2:
1255
2204
  orderIds = params.order_ids || params.orderIds || [];
1256
2205
  if (!(!orderIds.length || params.submitBeforeSend)) {
1257
- _context15.next = 11;
2206
+ _context22.next = 11;
1258
2207
  break;
1259
2208
  }
1260
- _context15.next = 6;
2209
+ _context22.next = 6;
1261
2210
  return this.submitSalesOrder({
1262
2211
  smallTicketDataFlag: 1
1263
2212
  });
1264
2213
  case 6:
1265
- submitResult = _context15.sent;
1266
- orderId = (_ref2 = (_ref3 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref3 !== void 0 ? _ref3 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref2 !== void 0 ? _ref2 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
2214
+ submitResult = _context22.sent;
2215
+ orderId = (_ref10 = (_ref11 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref11 !== void 0 ? _ref11 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref10 !== void 0 ? _ref10 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
1267
2216
  if (orderId) {
1268
- _context15.next = 10;
2217
+ _context22.next = 10;
1269
2218
  break;
1270
2219
  }
1271
2220
  throw new Error('本地订单提交云端失败,无法发送支付链接');
1272
2221
  case 10:
1273
2222
  orderIds = [orderId];
1274
2223
  case 11:
1275
- return _context15.abrupt("return", this.store.order.sendCustomerPayLink({
2224
+ return _context22.abrupt("return", this.store.order.sendCustomerPayLink({
1276
2225
  emails: params.emails,
1277
2226
  notify_action: params.notify_action,
1278
2227
  order_ids: orderIds
1279
2228
  }));
1280
2229
  case 12:
1281
2230
  case "end":
1282
- return _context15.stop();
2231
+ return _context22.stop();
1283
2232
  }
1284
- }, _callee15, this);
2233
+ }, _callee22, this);
1285
2234
  }));
1286
- function sendCustomerPayLink(_x10) {
2235
+ function sendCustomerPayLink(_x17) {
1287
2236
  return _sendCustomerPayLink.apply(this, arguments);
1288
2237
  }
1289
2238
  return sendCustomerPayLink;
@@ -1293,76 +2242,162 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1293
2242
  value: function transformBaseProductToOrderProduct(params) {
1294
2243
  return _transformBaseProductToOrderProduct(params);
1295
2244
  }
2245
+ }, {
2246
+ key: "calculateProductBookingPrice",
2247
+ value: function () {
2248
+ var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2249
+ var _params$customer_id;
2250
+ var quotation, customerId, authoritativeProduct, product;
2251
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2252
+ while (1) switch (_context23.prev = _context23.next) {
2253
+ case 0:
2254
+ quotation = this.store.quotation;
2255
+ customerId = (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : this.getCurrentOrderCustomerId();
2256
+ _context23.next = 4;
2257
+ return this.loadProductForPriceQuery(params, customerId);
2258
+ case 4:
2259
+ authoritativeProduct = _context23.sent;
2260
+ product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
2261
+ _context23.next = 8;
2262
+ return this.loadQuotationForPriceQuery({
2263
+ quotation: quotation,
2264
+ customer_id: customerId,
2265
+ channel: params.channel
2266
+ });
2267
+ case 8:
2268
+ return _context23.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
2269
+ product: product,
2270
+ fallback_price: authoritativeProduct ? undefined : params.fallback_price,
2271
+ customer_id: customerId,
2272
+ quotation: quotation
2273
+ })));
2274
+ case 9:
2275
+ case "end":
2276
+ return _context23.stop();
2277
+ }
2278
+ }, _callee23, this);
2279
+ }));
2280
+ function calculateProductBookingPrice(_x18) {
2281
+ return _calculateProductBookingPrice.apply(this, arguments);
2282
+ }
2283
+ return calculateProductBookingPrice;
2284
+ }()
1296
2285
  }, {
1297
2286
  key: "addProductToOrder",
1298
2287
  value: function () {
1299
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
2288
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(product, booking) {
1300
2289
  var products;
1301
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1302
- while (1) switch (_context16.prev = _context16.next) {
2290
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2291
+ while (1) switch (_context24.prev = _context24.next) {
1303
2292
  case 0:
1304
- _context16.prev = 0;
2293
+ _context24.prev = 0;
1305
2294
  if (this.store.order) {
1306
- _context16.next = 3;
2295
+ _context24.next = 3;
1307
2296
  break;
1308
2297
  }
1309
2298
  throw new Error('order 模块未初始化');
1310
2299
  case 3:
1311
- _context16.next = 5;
2300
+ _context24.next = 5;
1312
2301
  return this.store.order.addProductToOrder(product, booking);
1313
2302
  case 5:
1314
- products = _context16.sent;
1315
- return _context16.abrupt("return", products);
2303
+ products = _context24.sent;
2304
+ return _context24.abrupt("return", products);
1316
2305
  case 9:
1317
- _context16.prev = 9;
1318
- _context16.t0 = _context16["catch"](0);
1319
- throw _context16.t0;
2306
+ _context24.prev = 9;
2307
+ _context24.t0 = _context24["catch"](0);
2308
+ throw _context24.t0;
1320
2309
  case 12:
1321
2310
  case "end":
1322
- return _context16.stop();
2311
+ return _context24.stop();
1323
2312
  }
1324
- }, _callee16, this, [[0, 9]]);
2313
+ }, _callee24, this, [[0, 9]]);
1325
2314
  }));
1326
- function addProductToOrder(_x11, _x12) {
2315
+ function addProductToOrder(_x19, _x20) {
1327
2316
  return _addProductToOrder.apply(this, arguments);
1328
2317
  }
1329
2318
  return addProductToOrder;
1330
2319
  }()
1331
2320
  }, {
1332
- key: "updateProductInOrder",
2321
+ key: "updateOrderProduct",
1333
2322
  value: function () {
1334
- var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
2323
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
1335
2324
  var products;
1336
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1337
- while (1) switch (_context17.prev = _context17.next) {
2325
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2326
+ while (1) switch (_context25.prev = _context25.next) {
1338
2327
  case 0:
1339
- _context17.prev = 0;
2328
+ _context25.prev = 0;
1340
2329
  if (this.store.order) {
1341
- _context17.next = 3;
2330
+ _context25.next = 3;
1342
2331
  break;
1343
2332
  }
1344
2333
  throw new Error('order 模块未初始化');
1345
2334
  case 3:
1346
- _context17.next = 5;
1347
- return this.store.order.updateProductInOrder(params);
2335
+ _context25.next = 5;
2336
+ return this.store.order.updateOrderProduct(params);
1348
2337
  case 5:
1349
- products = _context17.sent;
1350
- return _context17.abrupt("return", products);
2338
+ products = _context25.sent;
2339
+ return _context25.abrupt("return", products);
1351
2340
  case 9:
1352
- _context17.prev = 9;
1353
- _context17.t0 = _context17["catch"](0);
1354
- throw _context17.t0;
2341
+ _context25.prev = 9;
2342
+ _context25.t0 = _context25["catch"](0);
2343
+ throw _context25.t0;
1355
2344
  case 12:
1356
2345
  case "end":
1357
- return _context17.stop();
2346
+ return _context25.stop();
2347
+ }
2348
+ }, _callee25, this, [[0, 9]]);
2349
+ }));
2350
+ function updateOrderProduct(_x21) {
2351
+ return _updateOrderProduct.apply(this, arguments);
2352
+ }
2353
+ return updateOrderProduct;
2354
+ }()
2355
+ }, {
2356
+ key: "updateOrderProductQuantity",
2357
+ value: function () {
2358
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2359
+ var products;
2360
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2361
+ while (1) switch (_context26.prev = _context26.next) {
2362
+ case 0:
2363
+ _context26.prev = 0;
2364
+ if (this.store.order) {
2365
+ _context26.next = 3;
2366
+ break;
2367
+ }
2368
+ throw new Error('order 模块未初始化');
2369
+ case 3:
2370
+ _context26.next = 5;
2371
+ return this.store.order.updateOrderProductQuantity(params);
2372
+ case 5:
2373
+ products = _context26.sent;
2374
+ return _context26.abrupt("return", products);
2375
+ case 9:
2376
+ _context26.prev = 9;
2377
+ _context26.t0 = _context26["catch"](0);
2378
+ throw _context26.t0;
2379
+ case 12:
2380
+ case "end":
2381
+ return _context26.stop();
1358
2382
  }
1359
- }, _callee17, this, [[0, 9]]);
2383
+ }, _callee26, this, [[0, 9]]);
1360
2384
  }));
1361
- function updateProductInOrder(_x13) {
1362
- return _updateProductInOrder.apply(this, arguments);
2385
+ function updateOrderProductQuantity(_x22) {
2386
+ return _updateOrderProductQuantity.apply(this, arguments);
1363
2387
  }
1364
- return updateProductInOrder;
2388
+ return updateOrderProductQuantity;
1365
2389
  }()
2390
+ }, {
2391
+ key: "updateOrderBooking",
2392
+ value: function updateOrderBooking(params) {
2393
+ try {
2394
+ if (!this.store.order) throw new Error('order 模块未初始化');
2395
+ return this.store.order.updateOrderBooking(params);
2396
+ } catch (error) {
2397
+ throw error;
2398
+ }
2399
+ }
2400
+
1366
2401
  /**
1367
2402
  * 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
1368
2403
  * 多行同 SKU 时必须传入与删除/更新一致的 unique_identification_number。
@@ -1370,12 +2405,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1370
2405
  }, {
1371
2406
  key: "setOrderProductLineNote",
1372
2407
  value: (function () {
1373
- var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(identity, note) {
2408
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identity, note) {
1374
2409
  var params, products;
1375
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1376
- while (1) switch (_context18.prev = _context18.next) {
2410
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2411
+ while (1) switch (_context27.prev = _context27.next) {
1377
2412
  case 0:
1378
- _context18.prev = 0;
2413
+ _context27.prev = 0;
1379
2414
  params = {
1380
2415
  product_id: identity.product_id,
1381
2416
  product_variant_id: identity.product_variant_id,
@@ -1390,22 +2425,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1390
2425
  params.product_option_item = identity.product_option_item;
1391
2426
  }
1392
2427
  if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
1393
- _context18.next = 7;
1394
- return this.updateProductInOrder(params);
2428
+ _context27.next = 7;
2429
+ return this.updateOrderProduct(params);
1395
2430
  case 7:
1396
- products = _context18.sent;
1397
- return _context18.abrupt("return", products);
2431
+ products = _context27.sent;
2432
+ return _context27.abrupt("return", products);
1398
2433
  case 11:
1399
- _context18.prev = 11;
1400
- _context18.t0 = _context18["catch"](0);
1401
- throw _context18.t0;
2434
+ _context27.prev = 11;
2435
+ _context27.t0 = _context27["catch"](0);
2436
+ throw _context27.t0;
1402
2437
  case 14:
1403
2438
  case "end":
1404
- return _context18.stop();
2439
+ return _context27.stop();
1405
2440
  }
1406
- }, _callee18, this, [[0, 11]]);
2441
+ }, _callee27, this, [[0, 11]]);
1407
2442
  }));
1408
- function setOrderProductLineNote(_x14, _x15) {
2443
+ function setOrderProductLineNote(_x23, _x24) {
1409
2444
  return _setOrderProductLineNote.apply(this, arguments);
1410
2445
  }
1411
2446
  return setOrderProductLineNote;
@@ -1413,54 +2448,138 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1413
2448
  }, {
1414
2449
  key: "removeProductFromOrder",
1415
2450
  value: function () {
1416
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
2451
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity) {
1417
2452
  var products;
1418
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1419
- while (1) switch (_context19.prev = _context19.next) {
2453
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2454
+ while (1) switch (_context28.prev = _context28.next) {
1420
2455
  case 0:
1421
- _context19.prev = 0;
2456
+ _context28.prev = 0;
1422
2457
  if (this.store.order) {
1423
- _context19.next = 3;
2458
+ _context28.next = 3;
1424
2459
  break;
1425
2460
  }
1426
2461
  throw new Error('order 模块未初始化');
1427
2462
  case 3:
1428
- _context19.next = 5;
2463
+ _context28.next = 5;
1429
2464
  return this.store.order.removeProductFromOrder(identity);
1430
2465
  case 5:
1431
- products = _context19.sent;
1432
- return _context19.abrupt("return", products);
2466
+ products = _context28.sent;
2467
+ return _context28.abrupt("return", products);
1433
2468
  case 9:
1434
- _context19.prev = 9;
1435
- _context19.t0 = _context19["catch"](0);
1436
- throw _context19.t0;
2469
+ _context28.prev = 9;
2470
+ _context28.t0 = _context28["catch"](0);
2471
+ throw _context28.t0;
1437
2472
  case 12:
1438
2473
  case "end":
1439
- return _context19.stop();
2474
+ return _context28.stop();
1440
2475
  }
1441
- }, _callee19, this, [[0, 9]]);
2476
+ }, _callee28, this, [[0, 9]]);
1442
2477
  }));
1443
- function removeProductFromOrder(_x16) {
2478
+ function removeProductFromOrder(_x25) {
1444
2479
  return _removeProductFromOrder.apply(this, arguments);
1445
2480
  }
1446
2481
  return removeProductFromOrder;
1447
- }() // 获取商品列表
2482
+ }() // ─── 促销/赠品 透传(迁移自 booking usePromotion) ────────────────
2483
+ /**
2484
+ * 注入促销评估器到底层 OrderModule。
2485
+ *
2486
+ * @example
2487
+ * solution.setPromotionEvaluator(appHelper.utils.promotionEvaluator);
2488
+ */
2489
+ }, {
2490
+ key: "setPromotionEvaluator",
2491
+ value: function setPromotionEvaluator(evaluator) {
2492
+ if (!this.store.order) throw new Error('order 模块未初始化');
2493
+ this.store.order.setPromotionEvaluator(evaluator);
2494
+ }
2495
+
2496
+ /**
2497
+ * 注入赠品选择 resolver。UI 层(SalesSdk)通过 bridge 提供。
2498
+ *
2499
+ * @example
2500
+ * solution.setGiftSelectResolver(async (ctx) => bridge.request(ctx));
2501
+ */
2502
+ }, {
2503
+ key: "setGiftSelectResolver",
2504
+ value: function setGiftSelectResolver(resolver) {
2505
+ if (!this.store.order) throw new Error('order 模块未初始化');
2506
+ this.store.order.setGiftSelectResolver(resolver);
2507
+ }
2508
+
2509
+ /**
2510
+ * 为商品目录追加促销标签,供 SalesSdkProductProvider 等商品列表入口复用。
2511
+ *
2512
+ * @example
2513
+ * const products = solution.appendPromotionTags(catalogProducts);
2514
+ */
2515
+ }, {
2516
+ key: "appendPromotionTags",
2517
+ value: function appendPromotionTags(products) {
2518
+ if (!this.store.order) throw new Error('order 模块未初始化');
2519
+ return this.store.order.appendPromotionTags(products);
2520
+ }
2521
+
2522
+ /**
2523
+ * 主动触发一次促销应用(一般写路径会自动触发,少数场景如客户切换后可手动调)。
2524
+ */
2525
+ }, {
2526
+ key: "applyPromotion",
2527
+ value: (function () {
2528
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2529
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2530
+ while (1) switch (_context29.prev = _context29.next) {
2531
+ case 0:
2532
+ if (this.store.order) {
2533
+ _context29.next = 2;
2534
+ break;
2535
+ }
2536
+ throw new Error('order 模块未初始化');
2537
+ case 2:
2538
+ _context29.next = 4;
2539
+ return this.store.order.applyPromotion();
2540
+ case 4:
2541
+ case "end":
2542
+ return _context29.stop();
2543
+ }
2544
+ }, _callee29, this);
2545
+ }));
2546
+ function applyPromotion() {
2547
+ return _applyPromotion.apply(this, arguments);
2548
+ }
2549
+ return applyPromotion;
2550
+ }() /** 最近一次促销计算输出的未满足提示。 */)
2551
+ }, {
2552
+ key: "getUnfulfilledPromotions",
2553
+ value: function getUnfulfilledPromotions() {
2554
+ var _this$store$order4;
2555
+ return ((_this$store$order4 = this.store.order) === null || _this$store$order4 === void 0 ? void 0 : _this$store$order4.getUnfulfilledPromotions()) || [];
2556
+ }
2557
+
2558
+ /** 最近一次促销计算输出的赠品操作 diff。 */
2559
+ }, {
2560
+ key: "getLastGiftActions",
2561
+ value: function getLastGiftActions() {
2562
+ var _this$store$order5;
2563
+ return ((_this$store$order5 = this.store.order) === null || _this$store$order5 === void 0 ? void 0 : _this$store$order5.getLastGiftActions()) || null;
2564
+ }
2565
+
2566
+ // 获取商品列表
1448
2567
  // TODO 需要跟 webpos 内的对齐一下
1449
2568
  }, {
1450
2569
  key: "getProductList",
1451
2570
  value: function () {
1452
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1453
- var _this$otherParams6;
2571
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2572
+ var _this$otherParams8;
1454
2573
  var menu_list_ids, _this$store$products, res;
1455
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1456
- while (1) switch (_context20.prev = _context20.next) {
2574
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2575
+ while (1) switch (_context30.prev = _context30.next) {
1457
2576
  case 0:
1458
2577
  // 可以直接通过配置里的 menu 读取
1459
- menu_list_ids = ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 || (_this$otherParams6 = _this$otherParams6.dineInConfig) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6['menu.associated_menus'].map(function (n) {
2578
+ menu_list_ids = ((_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 || (_this$otherParams8 = _this$otherParams8.dineInConfig) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8['menu.associated_menus'].map(function (n) {
1460
2579
  return Number(n.value);
1461
2580
  })) || [];
1462
- _context20.prev = 1;
1463
- _context20.next = 4;
2581
+ _context30.prev = 1;
2582
+ _context30.next = 4;
1464
2583
  return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
1465
2584
  menu_list_ids: menu_list_ids,
1466
2585
  cacheId: this.cacheId,
@@ -1468,17 +2587,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1468
2587
  schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
1469
2588
  });
1470
2589
  case 4:
1471
- res = _context20.sent;
1472
- return _context20.abrupt("return", res);
2590
+ res = _context30.sent;
2591
+ return _context30.abrupt("return", res);
1473
2592
  case 8:
1474
- _context20.prev = 8;
1475
- _context20.t0 = _context20["catch"](1);
1476
- throw _context20.t0;
2593
+ _context30.prev = 8;
2594
+ _context30.t0 = _context30["catch"](1);
2595
+ throw _context30.t0;
1477
2596
  case 11:
1478
2597
  case "end":
1479
- return _context20.stop();
2598
+ return _context30.stop();
1480
2599
  }
1481
- }, _callee20, this, [[1, 8]]);
2600
+ }, _callee30, this, [[1, 8]]);
1482
2601
  }));
1483
2602
  function getProductList() {
1484
2603
  return _getProductList.apply(this, arguments);
@@ -1493,15 +2612,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1493
2612
  }, {
1494
2613
  key: "setOtherParams",
1495
2614
  value: function () {
1496
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
1497
- var _ref4,
1498
- _ref4$cover,
2615
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
2616
+ var _ref12,
2617
+ _ref12$cover,
1499
2618
  cover,
1500
- _args21 = arguments;
1501
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1502
- while (1) switch (_context21.prev = _context21.next) {
2619
+ _args31 = arguments;
2620
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2621
+ while (1) switch (_context31.prev = _context31.next) {
1503
2622
  case 0:
1504
- _ref4 = _args21.length > 1 && _args21[1] !== undefined ? _args21[1] : {}, _ref4$cover = _ref4.cover, cover = _ref4$cover === void 0 ? false : _ref4$cover;
2623
+ _ref12 = _args31.length > 1 && _args31[1] !== undefined ? _args31[1] : {}, _ref12$cover = _ref12.cover, cover = _ref12$cover === void 0 ? false : _ref12$cover;
1505
2624
  if (cover) {
1506
2625
  this.otherParams = params;
1507
2626
  } else {
@@ -1509,11 +2628,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1509
2628
  }
1510
2629
  case 2:
1511
2630
  case "end":
1512
- return _context21.stop();
2631
+ return _context31.stop();
1513
2632
  }
1514
- }, _callee21, this);
2633
+ }, _callee31, this);
1515
2634
  }));
1516
- function setOtherParams(_x17) {
2635
+ function setOtherParams(_x26) {
1517
2636
  return _setOtherParams.apply(this, arguments);
1518
2637
  }
1519
2638
  return setOtherParams;