@pisell/pisellos 2.2.181 → 2.2.183

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