@pisell/pisellos 2.2.171 → 2.2.172

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 (156) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +193 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.d.ts +6 -0
  32. package/dist/modules/Customer/index.js +129 -83
  33. package/dist/modules/Customer/types.d.ts +2 -0
  34. package/dist/modules/Discount/index.d.ts +2 -4
  35. package/dist/modules/Discount/index.js +8 -93
  36. package/dist/modules/Discount/types.d.ts +1 -7
  37. package/dist/modules/Order/index.d.ts +47 -16
  38. package/dist/modules/Order/index.js +743 -334
  39. package/dist/modules/Order/types.d.ts +57 -17
  40. package/dist/modules/Order/types.js +2 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  42. package/dist/modules/Order/utils/manualProductDiscount.js +212 -0
  43. package/dist/modules/Order/utils.d.ts +23 -1
  44. package/dist/modules/Order/utils.js +139 -30
  45. package/dist/modules/Quotation/index.js +16 -5
  46. package/dist/modules/Rules/index.d.ts +4 -0
  47. package/dist/modules/Rules/index.js +26 -10
  48. package/dist/modules/SalesSummary/index.js +4 -2
  49. package/dist/modules/Schedule/index.js +6 -2
  50. package/dist/modules/index.d.ts +1 -0
  51. package/dist/modules/index.js +2 -1
  52. package/dist/server/index.js +10 -6
  53. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  54. package/dist/server/modules/products/index.js +9 -8
  55. package/dist/server/modules/schedule/index.js +13 -6
  56. package/dist/solution/BaseSales/index.d.ts +65 -7
  57. package/dist/solution/BaseSales/index.js +1066 -315
  58. package/dist/solution/BaseSales/types.d.ts +53 -1
  59. package/dist/solution/BaseSales/types.js +3 -1
  60. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  61. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  62. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +65 -15
  63. package/dist/solution/BaseSales/utils.js +46 -8
  64. package/dist/solution/BookingTicket/index.d.ts +134 -2
  65. package/dist/solution/BookingTicket/index.js +768 -175
  66. package/dist/solution/BookingTicket/types.d.ts +2 -0
  67. package/dist/solution/BookingTicket/types.js +3 -0
  68. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  69. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  70. package/dist/solution/ScanOrder/index.d.ts +9 -3
  71. package/dist/solution/ScanOrder/index.js +231 -128
  72. package/dist/solution/ScanOrder/utils.js +46 -8
  73. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  74. package/dist/solution/ShopDiscount/index.js +18 -23
  75. package/dist/solution/VenueBooking/index.d.ts +5 -9
  76. package/dist/solution/VenueBooking/index.js +103 -55
  77. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  78. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  79. package/lib/modules/BookingContext/index.d.ts +37 -0
  80. package/lib/modules/BookingContext/index.js +297 -0
  81. package/lib/modules/BookingContext/types.d.ts +102 -0
  82. package/lib/modules/BookingContext/types.js +34 -0
  83. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  84. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
  85. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  86. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  87. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  88. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  89. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  90. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  91. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  92. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  93. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  94. package/lib/modules/BookingContext/utils/index.js +43 -0
  95. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  96. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  97. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  98. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  99. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  100. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  101. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  102. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  103. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  104. package/lib/modules/BookingContext/utils/resources.js +377 -0
  105. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  106. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  107. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  108. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  109. package/lib/modules/Customer/index.d.ts +6 -0
  110. package/lib/modules/Customer/index.js +26 -11
  111. package/lib/modules/Customer/types.d.ts +2 -0
  112. package/lib/modules/Discount/index.d.ts +2 -4
  113. package/lib/modules/Discount/index.js +8 -63
  114. package/lib/modules/Discount/types.d.ts +1 -7
  115. package/lib/modules/Order/index.d.ts +47 -16
  116. package/lib/modules/Order/index.js +389 -90
  117. package/lib/modules/Order/types.d.ts +57 -17
  118. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  119. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  120. package/lib/modules/Order/utils.d.ts +23 -1
  121. package/lib/modules/Order/utils.js +145 -21
  122. package/lib/modules/Quotation/index.js +17 -6
  123. package/lib/modules/Rules/index.d.ts +4 -0
  124. package/lib/modules/Rules/index.js +22 -14
  125. package/lib/modules/SalesSummary/index.js +4 -2
  126. package/lib/modules/Schedule/index.js +3 -1
  127. package/lib/modules/index.d.ts +1 -0
  128. package/lib/modules/index.js +3 -1
  129. package/lib/server/index.js +2 -0
  130. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  131. package/lib/server/modules/products/index.js +8 -9
  132. package/lib/server/modules/schedule/index.js +2 -1
  133. package/lib/solution/BaseSales/index.d.ts +65 -7
  134. package/lib/solution/BaseSales/index.js +492 -20
  135. package/lib/solution/BaseSales/types.d.ts +53 -1
  136. package/lib/solution/BaseSales/types.js +3 -1
  137. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  138. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  139. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +70 -11
  140. package/lib/solution/BaseSales/utils.js +46 -6
  141. package/lib/solution/BookingTicket/index.d.ts +134 -2
  142. package/lib/solution/BookingTicket/index.js +341 -8
  143. package/lib/solution/BookingTicket/types.d.ts +2 -0
  144. package/lib/solution/BookingTicket/types.js +6 -0
  145. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  146. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  147. package/lib/solution/ScanOrder/index.d.ts +9 -3
  148. package/lib/solution/ScanOrder/index.js +147 -66
  149. package/lib/solution/ScanOrder/utils.js +46 -6
  150. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  151. package/lib/solution/ShopDiscount/index.js +2 -4
  152. package/lib/solution/VenueBooking/index.d.ts +5 -9
  153. package/lib/solution/VenueBooking/index.js +50 -14
  154. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  155. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  156. package/package.json +2 -2
@@ -1,10 +1,14 @@
1
1
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2
4
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
3
7
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
8
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
6
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
8
12
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
13
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -23,13 +27,16 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
23
27
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
24
28
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
25
29
  import { BaseModule } from "../../modules/BaseModule";
30
+ import { BaseSalesHookNames } from "./types";
26
31
  import { OrderModule } from "../../modules/Order";
27
32
  import Decimal from 'decimal.js';
28
33
  import { createModule } from "../BookingByStep/types";
29
34
  import { composeLinePrice, 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
  });
@@ -61,12 +69,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
61
69
 
62
70
  /**
63
71
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
64
- * 默认包含通用销售模块:products / order / salesSummary / schedule / payment。
72
+ * 默认包含通用销售模块:products / order / salesSummary / schedule / payment / quotation
65
73
  */
66
74
  _createClass(BaseSalesImpl, [{
67
75
  key: "getRegisteredModuleNames",
68
76
  value: function getRegisteredModuleNames() {
69
- return ['products', 'order', 'salesSummary', 'schedule', 'payment'];
77
+ return ['products', 'order', 'salesSummary', 'schedule', 'payment', 'quotation'];
70
78
  }
71
79
 
72
80
  /**
@@ -121,6 +129,63 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
121
129
  get: function get() {
122
130
  return this.store.payment;
123
131
  }
132
+ }, {
133
+ key: "getCurrentOrderCustomerId",
134
+ value: function getCurrentOrderCustomerId() {
135
+ var _this$store$order, _this$store$order$get;
136
+ 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);
137
+ var customerId = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.customer_id;
138
+ if (customerId === null || customerId === undefined) return undefined;
139
+ return customerId;
140
+ }
141
+ }, {
142
+ key: "applyQuotationScheduleResolver",
143
+ value: function applyQuotationScheduleResolver(quotation) {
144
+ var scheduleModule = this.store.schedule;
145
+ if (!scheduleModule) return;
146
+ quotation.setScheduleResolver(function (id) {
147
+ var _scheduleModule$getSc;
148
+ var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || [];
149
+ return schedules[0];
150
+ });
151
+ }
152
+ }, {
153
+ key: "loadQuotationForPriceQuery",
154
+ value: function () {
155
+ var _loadQuotationForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
156
+ var _this$otherParams;
157
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
158
+ while (1) switch (_context.prev = _context.next) {
159
+ case 0:
160
+ if (params.quotation) {
161
+ _context.next = 2;
162
+ break;
163
+ }
164
+ return _context.abrupt("return");
165
+ case 2:
166
+ this.applyQuotationScheduleResolver(params.quotation);
167
+ _context.next = 5;
168
+ return params.quotation.loadQuotations({
169
+ channel: params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel),
170
+ customer_id: params.customer_id
171
+ });
172
+ case 5:
173
+ case "end":
174
+ return _context.stop();
175
+ }
176
+ }, _callee, this);
177
+ }));
178
+ function loadQuotationForPriceQuery(_x) {
179
+ return _loadQuotationForPriceQuery.apply(this, arguments);
180
+ }
181
+ return loadQuotationForPriceQuery;
182
+ }()
183
+ }, {
184
+ key: "getSubmitOrderSalesChannel",
185
+ value: function getSubmitOrderSalesChannel() {
186
+ var _this$otherParams2;
187
+ return (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.channel;
188
+ }
124
189
 
125
190
  /**
126
191
  * 工厂入口:根据子模块名实例化对应模块。
@@ -130,6 +195,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
130
195
  }, {
131
196
  key: "createSubModule",
132
197
  value: function createSubModule(moduleName) {
198
+ if (moduleName === 'quotation') {
199
+ return new QuotationModule("".concat(this.name, "_quotation"));
200
+ }
133
201
  return createModule(moduleName, this.name);
134
202
  }
135
203
  }, {
@@ -163,39 +231,78 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
163
231
  return {};
164
232
  }
165
233
  }
234
+ }, {
235
+ key: "getAppData",
236
+ value: function getAppData(key) {
237
+ var _this$appPlugin$getDa, _this$appPlugin, _app$models, _app$models$getStore, _app$models$getStore$, _app$models$getStore$2;
238
+ var getData = (_this$appPlugin$getDa = (_this$appPlugin = this.appPlugin).getData) === null || _this$appPlugin$getDa === void 0 ? void 0 : _this$appPlugin$getDa.call(_this$appPlugin);
239
+ if (typeof getData === 'function') return getData(key);
240
+ var app = this.appPlugin.getApp();
241
+ 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');
242
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
243
+ }
244
+ }, {
245
+ key: "syncAppDataToTempOrder",
246
+ value: function syncAppDataToTempOrder(tempOrder) {
247
+ var taxCountryCode = this.getAppData('tax_country_code');
248
+ var currencyCode = this.getAppData('shop_currency_code');
249
+ var currencySymbol = this.getAppData('shop_symbol');
250
+ var isChanged = false;
251
+ if (taxCountryCode !== undefined) {
252
+ var nextTaxCountryCode = String(taxCountryCode || '');
253
+ if (tempOrder.tax_country_code !== nextTaxCountryCode) {
254
+ tempOrder.tax_country_code = nextTaxCountryCode;
255
+ isChanged = true;
256
+ }
257
+ }
258
+ if (currencyCode !== undefined) {
259
+ var nextCurrencyCode = String(currencyCode || '');
260
+ if (tempOrder.currency_code !== nextCurrencyCode) {
261
+ tempOrder.currency_code = nextCurrencyCode;
262
+ isChanged = true;
263
+ }
264
+ }
265
+ if (currencySymbol !== undefined) {
266
+ var nextCurrencySymbol = String(currencySymbol || '');
267
+ if (tempOrder.currency_symbol !== nextCurrencySymbol) {
268
+ tempOrder.currency_symbol = nextCurrencySymbol;
269
+ isChanged = true;
270
+ }
271
+ }
272
+ return isChanged;
273
+ }
166
274
  }, {
167
275
  key: "initialize",
168
276
  value: function () {
169
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core) {
170
- var _this$otherParams,
277
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core) {
278
+ var _this$otherParams3,
171
279
  _this2 = this;
172
280
  var options,
173
- appPlugin,
174
281
  app,
175
282
  targetCacheData,
176
283
  moduleNames,
177
- _args = arguments;
178
- return _regeneratorRuntime().wrap(function _callee$(_context) {
179
- while (1) switch (_context.prev = _context.next) {
284
+ _args2 = arguments;
285
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
286
+ while (1) switch (_context2.prev = _context2.next) {
180
287
  case 0:
181
- options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
288
+ options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
182
289
  this.core = core;
183
290
  this.initializeOptions = options || {};
184
291
  // this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
185
292
  this.otherParams = options.otherParams || {};
186
- this.cacheId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.cacheId;
293
+ this.cacheId = (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.cacheId;
187
294
  this.window = core.getPlugin('window');
188
295
  this.request = core.getPlugin('request');
189
296
 
190
297
  // 获取 logger 实例
191
- appPlugin = core.getPlugin('app');
192
- if (appPlugin) {
193
- _context.next = 10;
298
+ this.appPlugin = core.getPlugin('app');
299
+ if (this.appPlugin) {
300
+ _context2.next = 10;
194
301
  break;
195
302
  }
196
303
  throw new Error('Checkout 解决方案需要 app 插件支持');
197
304
  case 10:
198
- app = appPlugin.getApp();
305
+ app = this.appPlugin.getApp();
199
306
  this.logger = app.logger;
200
307
  targetCacheData = this.readSessionCacheData();
201
308
  moduleNames = this.getRegisteredModuleNames();
@@ -220,20 +327,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
220
327
  }));
221
328
  });
222
329
  if (!this.store.schedule) {
223
- _context.next = 18;
330
+ _context2.next = 18;
224
331
  break;
225
332
  }
226
- _context.next = 18;
333
+ _context2.next = 18;
227
334
  return this.store.schedule.loadAllSchedule();
228
335
  case 18:
229
336
  this.core.effects.emit("".concat(this.name, ":onInited"), {});
230
337
  case 19:
231
338
  case "end":
232
- return _context.stop();
339
+ return _context2.stop();
233
340
  }
234
- }, _callee, this);
341
+ }, _callee2, this);
235
342
  }));
236
- function initialize(_x) {
343
+ function initialize(_x2) {
237
344
  return _initialize.apply(this, arguments);
238
345
  }
239
346
  return initialize;
@@ -241,10 +348,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
241
348
  }, {
242
349
  key: "destroy",
243
350
  value: function () {
244
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
351
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
245
352
  var _this3 = this;
246
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
247
- while (1) switch (_context2.prev = _context2.next) {
353
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
354
+ while (1) switch (_context3.prev = _context3.next) {
248
355
  case 0:
249
356
  Object.keys(this.store).forEach(function (key) {
250
357
  var sub = _this3.store[key];
@@ -257,15 +364,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
257
364
  }
258
365
  });
259
366
  this.currentSalesDetail = null;
260
- _context2.next = 4;
367
+ _context3.next = 4;
261
368
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
262
369
  case 4:
263
370
  _get(_getPrototypeOf(BaseSalesImpl.prototype), "destroy", this).call(this);
264
371
  case 5:
265
372
  case "end":
266
- return _context2.stop();
373
+ return _context3.stop();
267
374
  }
268
- }, _callee2, this);
375
+ }, _callee3, this);
269
376
  }));
270
377
  function destroy() {
271
378
  return _destroy.apply(this, arguments);
@@ -282,13 +389,13 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
282
389
  }, {
283
390
  key: "loadSalesDetail",
284
391
  value: (function () {
285
- var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(orderIdOrParams) {
392
+ var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(orderIdOrParams) {
286
393
  var params, externalSaleNumber, localRecord, _sales, res, message, sales;
287
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
288
- while (1) switch (_context3.prev = _context3.next) {
394
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
395
+ while (1) switch (_context4.prev = _context4.next) {
289
396
  case 0:
290
397
  if (this.store.order) {
291
- _context3.next = 2;
398
+ _context4.next = 2;
292
399
  break;
293
400
  }
294
401
  throw new Error('order 模块未初始化');
@@ -298,107 +405,107 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
298
405
  };
299
406
  externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
300
407
  if (params.forceRemote) {
301
- _context3.next = 35;
408
+ _context4.next = 35;
302
409
  break;
303
410
  }
304
411
  if (!(params.orderId !== undefined)) {
305
- _context3.next = 11;
412
+ _context4.next = 11;
306
413
  break;
307
414
  }
308
- _context3.next = 8;
415
+ _context4.next = 8;
309
416
  return this.store.order.getLocalOrderByOrderId(params.orderId);
310
417
  case 8:
311
- _context3.t0 = _context3.sent;
312
- _context3.next = 26;
418
+ _context4.t0 = _context4.sent;
419
+ _context4.next = 26;
313
420
  break;
314
421
  case 11:
315
422
  if (!externalSaleNumber) {
316
- _context3.next = 17;
423
+ _context4.next = 17;
317
424
  break;
318
425
  }
319
- _context3.next = 14;
426
+ _context4.next = 14;
320
427
  return this.store.order.getLocalOrderByExternalSaleNumber(externalSaleNumber);
321
428
  case 14:
322
- _context3.t1 = _context3.sent;
323
- _context3.next = 25;
429
+ _context4.t1 = _context4.sent;
430
+ _context4.next = 25;
324
431
  break;
325
432
  case 17:
326
433
  if (!params.orderNumber) {
327
- _context3.next = 23;
434
+ _context4.next = 23;
328
435
  break;
329
436
  }
330
- _context3.next = 20;
437
+ _context4.next = 20;
331
438
  return this.store.order.getLocalOrderByOrderNumber(params.orderNumber);
332
439
  case 20:
333
- _context3.t2 = _context3.sent;
334
- _context3.next = 24;
440
+ _context4.t2 = _context4.sent;
441
+ _context4.next = 24;
335
442
  break;
336
443
  case 23:
337
- _context3.t2 = null;
444
+ _context4.t2 = null;
338
445
  case 24:
339
- _context3.t1 = _context3.t2;
446
+ _context4.t1 = _context4.t2;
340
447
  case 25:
341
- _context3.t0 = _context3.t1;
448
+ _context4.t0 = _context4.t1;
342
449
  case 26:
343
- localRecord = _context3.t0;
450
+ localRecord = _context4.t0;
344
451
  if (!localRecord) {
345
- _context3.next = 35;
452
+ _context4.next = 35;
346
453
  break;
347
454
  }
348
- _context3.next = 30;
455
+ _context4.next = 30;
349
456
  return this.store.order.hydrateTempOrderFromRecord(localRecord, {
350
457
  recalcOnHydrate: false
351
458
  });
352
459
  case 30:
353
- _sales = _context3.sent;
460
+ _sales = _context4.sent;
354
461
  this.currentSalesDetail = _sales;
355
- _context3.next = 34;
462
+ _context4.next = 34;
356
463
  return this.core.effects.emit("".concat(this.name, ":onSalesOrderLoaded"), {
357
464
  sales: _sales
358
465
  });
359
466
  case 34:
360
- return _context3.abrupt("return", _sales);
467
+ return _context4.abrupt("return", _sales);
361
468
  case 35:
362
469
  if (!(params.orderId === undefined || params.orderId === null)) {
363
- _context3.next = 37;
470
+ _context4.next = 37;
364
471
  break;
365
472
  }
366
473
  throw new Error('加载销售详情需要 orderId,或本地库中存在对应 externalSaleNumber/orderNumber');
367
474
  case 37:
368
- _context3.next = 39;
475
+ _context4.next = 39;
369
476
  return this.store.order.getOrderInfoByRemote(Number(params.orderId));
370
477
  case 39:
371
- res = _context3.sent;
478
+ res = _context4.sent;
372
479
  if (!(!res || res.code !== 200)) {
373
- _context3.next = 43;
480
+ _context4.next = 43;
374
481
  break;
375
482
  }
376
483
  message = res && (res.message || res.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(params.orderId);
377
484
  throw new Error(message);
378
485
  case 43:
379
- _context3.next = 45;
486
+ _context4.next = 45;
380
487
  return this.store.order.hydrateTempOrderFromRecord(res.data, {
381
488
  recalcOnHydrate: false
382
489
  });
383
490
  case 45:
384
- sales = _context3.sent;
385
- _context3.next = 48;
491
+ sales = _context4.sent;
492
+ _context4.next = 48;
386
493
  return this.store.order.saveDraft();
387
494
  case 48:
388
495
  this.currentSalesDetail = sales;
389
- _context3.next = 51;
496
+ _context4.next = 51;
390
497
  return this.core.effects.emit("".concat(this.name, ":onSalesOrderLoaded"), {
391
498
  sales: sales
392
499
  });
393
500
  case 51:
394
- return _context3.abrupt("return", sales);
501
+ return _context4.abrupt("return", sales);
395
502
  case 52:
396
503
  case "end":
397
- return _context3.stop();
504
+ return _context4.stop();
398
505
  }
399
- }, _callee3, this);
506
+ }, _callee4, this);
400
507
  }));
401
- function loadSalesDetail(_x2) {
508
+ function loadSalesDetail(_x3) {
402
509
  return _loadSalesDetail.apply(this, arguments);
403
510
  }
404
511
  return loadSalesDetail;
@@ -471,10 +578,45 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
471
578
  }, {
472
579
  key: "getTempOrder",
473
580
  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;
581
+ var _this$store$order2;
582
+ var result = ((_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 ? void 0 : _this$store$order2.getTempOrder()) || null;
476
583
  return result;
477
584
  }
585
+ }, {
586
+ key: "replaceTempOrder",
587
+ value: function () {
588
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(tempOrder) {
589
+ var nextTempOrder;
590
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
591
+ while (1) switch (_context5.prev = _context5.next) {
592
+ case 0:
593
+ if (this.store.order) {
594
+ _context5.next = 2;
595
+ break;
596
+ }
597
+ throw new Error('order 模块未初始化');
598
+ case 2:
599
+ _context5.next = 4;
600
+ return this.store.order.replaceTempOrder(tempOrder);
601
+ case 4:
602
+ nextTempOrder = _context5.sent;
603
+ _context5.next = 7;
604
+ return this.effectsEmit('onTempOrderReplaced', {
605
+ tempOrder: nextTempOrder
606
+ });
607
+ case 7:
608
+ return _context5.abrupt("return", nextTempOrder);
609
+ case 8:
610
+ case "end":
611
+ return _context5.stop();
612
+ }
613
+ }, _callee5, this);
614
+ }));
615
+ function replaceTempOrder(_x4) {
616
+ return _replaceTempOrder.apply(this, arguments);
617
+ }
618
+ return replaceTempOrder;
619
+ }()
478
620
  }, {
479
621
  key: "getOrderIdentity",
480
622
  value: function getOrderIdentity() {
@@ -508,14 +650,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
508
650
  }, {
509
651
  key: "updateTempOrderNote",
510
652
  value: function updateTempOrderNote(note) {
653
+ var sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
511
654
  try {
512
655
  if (!this.store.order) throw new Error('order 模块未初始化');
513
- var result = this.store.order.updateTempOrderNote(note);
656
+ var result = this.store.order.updateTempOrderNote(note, sync);
514
657
  return result;
515
658
  } catch (error) {
516
659
  throw error;
517
660
  }
518
661
  }
662
+ }, {
663
+ key: "updateRemoteOrderNote",
664
+ value: function updateRemoteOrderNote(orderId, note) {
665
+ if (!this.store.order) throw new Error('order 模块未初始化');
666
+ this.store.order.syncTempOrderNoteToRemote(orderId, note);
667
+ }
519
668
  }, {
520
669
  key: "updateTempOrderShopDiscount",
521
670
  value: function updateTempOrderShopDiscount(amount) {
@@ -528,6 +677,36 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
528
677
  if (!this.store.order) throw new Error('order 模块未初始化');
529
678
  return this.store.order.updateTempOrderContactsInfo(contactsInfo);
530
679
  }
680
+
681
+ /**
682
+ * 运行时切换 tempOrder 是否写入 localStorage(委托 OrderModule)。
683
+ * SalesSdk 等内存态场景可在挂载后设为 false,避免污染本地缓存。
684
+ *
685
+ * @example
686
+ * bookingTicket.setEnableTempOrderPersist(false);
687
+ * await bookingTicket.addProductToOrder(product);
688
+ */
689
+ }, {
690
+ key: "setEnableTempOrderPersist",
691
+ value: function setEnableTempOrderPersist(enabled) {
692
+ if (!this.store.order) throw new Error('order 模块未初始化');
693
+ this.store.order.setEnableTempOrderPersist(enabled);
694
+ }
695
+
696
+ /**
697
+ * 读取当前 tempOrder localStorage 持久化开关(委托 OrderModule)。
698
+ *
699
+ * @example
700
+ * if (bookingTicket.isTempOrderPersistEnabled()) {
701
+ * bookingTicket.restoreOrder();
702
+ * }
703
+ */
704
+ }, {
705
+ key: "isTempOrderPersistEnabled",
706
+ value: function isTempOrderPersistEnabled() {
707
+ if (!this.store.order) return true;
708
+ return this.store.order.isTempOrderPersistEnabled();
709
+ }
531
710
  }, {
532
711
  key: "ensureTempOrder",
533
712
  value: function ensureTempOrder() {
@@ -539,32 +718,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
539
718
  }, {
540
719
  key: "addNewOrder",
541
720
  value: function () {
542
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
721
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
543
722
  var tempOrder;
544
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
545
- while (1) switch (_context4.prev = _context4.next) {
723
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
724
+ while (1) switch (_context6.prev = _context6.next) {
546
725
  case 0:
547
- _context4.prev = 0;
726
+ _context6.prev = 0;
548
727
  if (this.store.order) {
549
- _context4.next = 3;
728
+ _context6.next = 3;
550
729
  break;
551
730
  }
552
731
  throw new Error('order 模块未初始化');
553
732
  case 3:
554
- _context4.next = 5;
733
+ _context6.next = 5;
555
734
  return this.store.order.addNewOrder();
556
735
  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:
736
+ tempOrder = _context6.sent;
737
+ if (!this.syncAppDataToTempOrder(tempOrder)) {
738
+ _context6.next = 10;
739
+ break;
740
+ }
741
+ this.store.order.persistTempOrder();
742
+ _context6.next = 10;
743
+ return this.store.order.saveDraft();
744
+ case 10:
745
+ return _context6.abrupt("return", tempOrder);
746
+ case 13:
747
+ _context6.prev = 13;
748
+ _context6.t0 = _context6["catch"](0);
749
+ throw _context6.t0;
750
+ case 16:
564
751
  case "end":
565
- return _context4.stop();
752
+ return _context6.stop();
566
753
  }
567
- }, _callee4, this, [[0, 9]]);
754
+ }, _callee6, this, [[0, 13]]);
568
755
  }));
569
756
  function addNewOrder() {
570
757
  return _addNewOrder.apply(this, arguments);
@@ -574,22 +761,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
574
761
  }, {
575
762
  key: "saveDraft",
576
763
  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) {
764
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
765
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
766
+ while (1) switch (_context7.prev = _context7.next) {
580
767
  case 0:
581
768
  if (this.store.order) {
582
- _context5.next = 2;
769
+ _context7.next = 2;
583
770
  break;
584
771
  }
585
772
  throw new Error('order 模块未初始化');
586
773
  case 2:
587
- return _context5.abrupt("return", this.store.order.saveDraft());
774
+ return _context7.abrupt("return", this.store.order.saveDraft());
588
775
  case 3:
589
776
  case "end":
590
- return _context5.stop();
777
+ return _context7.stop();
591
778
  }
592
- }, _callee5, this);
779
+ }, _callee7, this);
593
780
  }));
594
781
  function saveDraft() {
595
782
  return _saveDraft.apply(this, arguments);
@@ -600,36 +787,111 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
600
787
  }, {
601
788
  key: "restoreOrder",
602
789
  value: function () {
603
- var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
790
+ var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
604
791
  var tempOrder;
605
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
606
- while (1) switch (_context6.prev = _context6.next) {
792
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
793
+ while (1) switch (_context8.prev = _context8.next) {
607
794
  case 0:
608
- _context6.prev = 0;
795
+ _context8.prev = 0;
609
796
  if (this.store.order) {
610
- _context6.next = 3;
797
+ _context8.next = 3;
611
798
  break;
612
799
  }
613
800
  throw new Error('scanOrder 解决方案需要 order 模块支持');
614
801
  case 3:
615
802
  // this.store.resource = null;
616
803
  tempOrder = this.store.order.restoreOrder();
617
- return _context6.abrupt("return", tempOrder);
804
+ this.currentSalesDetail = null;
805
+ _context8.next = 7;
806
+ return this.effectsEmit('onTempOrderReplaced', {
807
+ tempOrder: tempOrder
808
+ });
618
809
  case 7:
619
- _context6.prev = 7;
620
- _context6.t0 = _context6["catch"](0);
621
- throw _context6.t0;
622
- case 10:
810
+ if (!this.syncAppDataToTempOrder(tempOrder)) {
811
+ _context8.next = 11;
812
+ break;
813
+ }
814
+ this.store.order.persistTempOrder();
815
+ _context8.next = 11;
816
+ return this.store.order.saveDraft();
817
+ case 11:
818
+ return _context8.abrupt("return", tempOrder);
819
+ case 14:
820
+ _context8.prev = 14;
821
+ _context8.t0 = _context8["catch"](0);
822
+ throw _context8.t0;
823
+ case 17:
623
824
  case "end":
624
- return _context6.stop();
825
+ return _context8.stop();
625
826
  }
626
- }, _callee6, this, [[0, 7]]);
827
+ }, _callee8, this, [[0, 14]]);
627
828
  }));
628
829
  function restoreOrder() {
629
830
  return _restoreOrder.apply(this, arguments);
630
831
  }
631
832
  return restoreOrder;
632
833
  }()
834
+ /**
835
+ * 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
836
+ * 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
837
+ */
838
+ }, {
839
+ key: "clearOrderCartLines",
840
+ value: (function () {
841
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
842
+ var tempOrder;
843
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
844
+ while (1) switch (_context9.prev = _context9.next) {
845
+ case 0:
846
+ _context9.prev = 0;
847
+ if (this.store.order) {
848
+ _context9.next = 3;
849
+ break;
850
+ }
851
+ throw new Error('order 模块未初始化');
852
+ case 3:
853
+ _context9.next = 5;
854
+ return this.store.order.clearOrderCartLines();
855
+ case 5:
856
+ tempOrder = _context9.sent;
857
+ if (this.currentSalesDetail) {
858
+ this.currentSalesDetail = _objectSpread(_objectSpread({}, this.currentSalesDetail), {}, {
859
+ products: [],
860
+ bookings: [],
861
+ rootBooking: null,
862
+ bookingsByProductUid: {},
863
+ discount_list: []
864
+ });
865
+ }
866
+ _context9.next = 9;
867
+ return this.effectsEmit('onTempOrderReplaced', {
868
+ tempOrder: tempOrder
869
+ });
870
+ case 9:
871
+ if (!this.syncAppDataToTempOrder(tempOrder)) {
872
+ _context9.next = 13;
873
+ break;
874
+ }
875
+ this.store.order.persistTempOrder();
876
+ _context9.next = 13;
877
+ return this.store.order.saveDraft();
878
+ case 13:
879
+ return _context9.abrupt("return", tempOrder);
880
+ case 16:
881
+ _context9.prev = 16;
882
+ _context9.t0 = _context9["catch"](0);
883
+ throw _context9.t0;
884
+ case 19:
885
+ case "end":
886
+ return _context9.stop();
887
+ }
888
+ }, _callee9, this, [[0, 16]]);
889
+ }));
890
+ function clearOrderCartLines() {
891
+ return _clearOrderCartLines.apply(this, arguments);
892
+ }
893
+ return clearOrderCartLines;
894
+ }())
633
895
  }, {
634
896
  key: "getOrderProducts",
635
897
  value: function getOrderProducts() {
@@ -640,38 +902,307 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
640
902
  }, {
641
903
  key: "getSummary",
642
904
  value: function () {
643
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
905
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
644
906
  var summary;
645
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
646
- while (1) switch (_context7.prev = _context7.next) {
907
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
908
+ while (1) switch (_context10.prev = _context10.next) {
647
909
  case 0:
648
- _context7.prev = 0;
910
+ _context10.prev = 0;
649
911
  if (this.store.order) {
650
- _context7.next = 3;
912
+ _context10.next = 3;
651
913
  break;
652
914
  }
653
915
  throw new Error('order 模块未初始化');
654
916
  case 3:
655
- _context7.next = 5;
917
+ _context10.next = 5;
656
918
  return this.store.order.getOrderSummary();
657
919
  case 5:
658
- summary = _context7.sent;
659
- return _context7.abrupt("return", summary);
920
+ summary = _context10.sent;
921
+ return _context10.abrupt("return", summary);
660
922
  case 9:
661
- _context7.prev = 9;
662
- _context7.t0 = _context7["catch"](0);
663
- throw _context7.t0;
923
+ _context10.prev = 9;
924
+ _context10.t0 = _context10["catch"](0);
925
+ throw _context10.t0;
664
926
  case 12:
665
927
  case "end":
666
- return _context7.stop();
928
+ return _context10.stop();
667
929
  }
668
- }, _callee7, this, [[0, 9]]);
930
+ }, _callee10, this, [[0, 9]]);
669
931
  }));
670
932
  function getSummary() {
671
933
  return _getSummary.apply(this, arguments);
672
934
  }
673
935
  return getSummary;
674
936
  }()
937
+ }, {
938
+ key: "getHistoricalProductDiscountList",
939
+ value: function getHistoricalProductDiscountList(products) {
940
+ var _this4 = this;
941
+ var historyDiscountList = [];
942
+ products.forEach(function (item) {
943
+ if (!_this4.isPersistedOrderProduct(item)) return;
944
+ (item.discount_list || []).forEach(function (discount) {
945
+ var _discount$discount, _discount$metadata, _discount$discount2, _discount$discount3, _discount$discount4;
946
+ var discountId = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
947
+ if (!discountId || !['good_pass', 'discount_card'].includes(discount.type)) return;
948
+ var quantity = item.quantity || item.num || item.product_quantity || 1;
949
+ 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);
950
+ var index = historyDiscountList.findIndex(function (n) {
951
+ return n.id === discountId;
952
+ });
953
+ if (index !== -1) {
954
+ historyDiscountList[index] = _objectSpread(_objectSpread({}, historyDiscountList[index]), {}, {
955
+ amount: new Decimal(historyDiscountList[index].amount || 0).plus(discount.amount || 0).toNumber(),
956
+ savedAmount: savedAmount.plus(historyDiscountList[index].savedAmount || 0).toNumber()
957
+ });
958
+ return;
959
+ }
960
+ historyDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
961
+ id: discountId,
962
+ tag: discount.tag || discount.type,
963
+ 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),
964
+ format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
965
+ isEditMode: true,
966
+ limited_relation_product_data: {},
967
+ savedAmount: savedAmount.toNumber(),
968
+ isAvailable: true,
969
+ isDisabled: true,
970
+ isSelected: true,
971
+ product_id: ((_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.product_id) || discount.product_id
972
+ }));
973
+ });
974
+ });
975
+ return historyDiscountList;
976
+ }
977
+ }, {
978
+ key: "isPersistedOrderProduct",
979
+ value: function isPersistedOrderProduct(product) {
980
+ var _product$order_detail, _product$booking_id;
981
+ var orderDetailId = (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : product.orderDetailId;
982
+ if (orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '') {
983
+ return true;
984
+ }
985
+ var bookingId = (_product$booking_id = product.booking_id) !== null && _product$booking_id !== void 0 ? _product$booking_id : product.bookingId;
986
+ return bookingId !== undefined && bookingId !== null && bookingId !== '';
987
+ }
988
+ }, {
989
+ key: "mergeHistoricalDiscountList",
990
+ value: function mergeHistoricalDiscountList(discountList, products) {
991
+ var historyDiscountList = this.getHistoricalProductDiscountList(products);
992
+ var historyIds = new Set(historyDiscountList.map(function (discount) {
993
+ return discount.id;
994
+ }));
995
+ return [].concat(_toConsumableArray(historyDiscountList), _toConsumableArray((discountList || []).filter(function (discount) {
996
+ return !historyIds.has(discount.id);
997
+ })));
998
+ }
999
+ }, {
1000
+ key: "mergeCurrentDiscountSelectionState",
1001
+ value: function mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
1002
+ if (!currentDiscountList.length) return discountList;
1003
+ var currentDiscountMap = new Map(currentDiscountList.map(function (discount) {
1004
+ return [discount.id, discount];
1005
+ }));
1006
+ return discountList.map(function (discount) {
1007
+ var currentDiscount = currentDiscountMap.get(discount.id);
1008
+ if (!currentDiscount) return discount;
1009
+ if (currentDiscount.isManualSelect) {
1010
+ return _objectSpread(_objectSpread({}, discount), {}, {
1011
+ isSelected: false,
1012
+ isManualSelect: true
1013
+ });
1014
+ }
1015
+ if (currentDiscount.isSelected) {
1016
+ return _objectSpread(_objectSpread({}, discount), {}, {
1017
+ isSelected: true,
1018
+ isManualSelect: false
1019
+ });
1020
+ }
1021
+ return discount;
1022
+ });
1023
+ }
1024
+ }, {
1025
+ key: "loadDiscountConfig",
1026
+ value: function () {
1027
+ var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
1028
+ var _this$getOrderIdentit, _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _discountModule$getDi, _discountModule$getDi2;
1029
+ var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, preparedDiscountList, _discountModule$setOr, nextDiscountList, _tempOrder$holder, _tempOrder$holder2, _orderStore$summary, holders, result;
1030
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1031
+ while (1) switch (_context11.prev = _context11.next) {
1032
+ case 0:
1033
+ if (this.store.order) {
1034
+ _context11.next = 2;
1035
+ break;
1036
+ }
1037
+ throw new Error('order 模块未初始化');
1038
+ case 2:
1039
+ tempOrder = this.store.order.ensureTempOrder();
1040
+ orderStore = this.store.order.store || {};
1041
+ discountModule = orderStore.discount;
1042
+ rulesModule = orderStore.rules;
1043
+ 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);
1044
+ 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);
1045
+ currentDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
1046
+ preparedDiscountList = [];
1047
+ if (!(customerId && customerId !== 1)) {
1048
+ _context11.next = 16;
1049
+ break;
1050
+ }
1051
+ _context11.next = 13;
1052
+ return this.store.order.loadDiscountConfig({
1053
+ customerId: customerId,
1054
+ action: (params === null || params === void 0 ? void 0 : params.action) || (orderId ? 'edit' : 'create'),
1055
+ orderId: Number(orderId) || undefined,
1056
+ apply: false
1057
+ });
1058
+ case 13:
1059
+ preparedDiscountList = _context11.sent;
1060
+ _context11.next = 16;
1061
+ return discountModule === null || discountModule === void 0 || (_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, preparedDiscountList);
1062
+ case 16:
1063
+ 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 || []);
1064
+ nextDiscountList = this.mergeCurrentDiscountSelectionState(nextDiscountList, currentDiscountList);
1065
+ _context11.next = 20;
1066
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1067
+ case 20:
1068
+ if (!rulesModule) {
1069
+ _context11.next = 30;
1070
+ break;
1071
+ }
1072
+ holders = (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
1073
+ form_record_id: tempOrder.holder.form_record_id
1074
+ }] : [];
1075
+ result = rulesModule.calcDiscount({
1076
+ productList: tempOrder.products,
1077
+ discountList: nextDiscountList,
1078
+ holders: holders,
1079
+ isFormSubject: !!((_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form',
1080
+ orderTotalAmount: Number(((_orderStore$summary = orderStore.summary) === null || _orderStore$summary === void 0 ? void 0 : _orderStore$summary.total_amount) || 0)
1081
+ }) || {
1082
+ productList: tempOrder.products,
1083
+ discountList: nextDiscountList
1084
+ };
1085
+ if (result.productList) {
1086
+ tempOrder.products = result.productList;
1087
+ }
1088
+ if (!result.discountList) {
1089
+ _context11.next = 30;
1090
+ break;
1091
+ }
1092
+ nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1093
+ OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1094
+ _context11.next = 29;
1095
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1096
+ case 29:
1097
+ tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1098
+ return discount.isSelected;
1099
+ });
1100
+ case 30:
1101
+ this.store.order.persistTempOrder();
1102
+ _context11.next = 33;
1103
+ return this.effectsEmit('onDiscountApplied', {
1104
+ productList: tempOrder.products || [],
1105
+ discountList: nextDiscountList,
1106
+ selectedDiscountList: tempOrder.discount_list || [],
1107
+ tempOrder: tempOrder
1108
+ });
1109
+ case 33:
1110
+ return _context11.abrupt("return", {
1111
+ productList: tempOrder.products || [],
1112
+ discountList: nextDiscountList
1113
+ });
1114
+ case 34:
1115
+ case "end":
1116
+ return _context11.stop();
1117
+ }
1118
+ }, _callee11, this);
1119
+ }));
1120
+ function loadDiscountConfig(_x5) {
1121
+ return _loadDiscountConfig.apply(this, arguments);
1122
+ }
1123
+ return loadDiscountConfig;
1124
+ }()
1125
+ }, {
1126
+ key: "bestDiscount",
1127
+ value: function () {
1128
+ var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(cb) {
1129
+ var _discountModule$getOr;
1130
+ var tempOrder, orderStore, discountModule, rulesModule, originalDiscountList, nextDiscountList, result, _tempOrder$holder3, _tempOrder$holder4, _orderStore$summary2, holders;
1131
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1132
+ while (1) switch (_context12.prev = _context12.next) {
1133
+ case 0:
1134
+ if (this.store.order) {
1135
+ _context12.next = 2;
1136
+ break;
1137
+ }
1138
+ throw new Error('order 模块未初始化');
1139
+ case 2:
1140
+ tempOrder = this.store.order.ensureTempOrder();
1141
+ orderStore = this.store.order.store || {};
1142
+ discountModule = orderStore.discount;
1143
+ rulesModule = orderStore.rules;
1144
+ originalDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || this.getDiscountList();
1145
+ nextDiscountList = this.mergeHistoricalDiscountList(originalDiscountList || [], tempOrder.products || []);
1146
+ result = {
1147
+ productList: tempOrder.products || [],
1148
+ discountList: nextDiscountList
1149
+ };
1150
+ _context12.next = 11;
1151
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1152
+ case 11:
1153
+ if (!rulesModule) {
1154
+ _context12.next = 22;
1155
+ break;
1156
+ }
1157
+ holders = (_tempOrder$holder3 = tempOrder.holder) !== null && _tempOrder$holder3 !== void 0 && _tempOrder$holder3.form_record_id ? [{
1158
+ form_record_id: tempOrder.holder.form_record_id
1159
+ }] : [];
1160
+ result = rulesModule.calcDiscount({
1161
+ productList: tempOrder.products,
1162
+ discountList: nextDiscountList,
1163
+ holders: holders,
1164
+ isFormSubject: !!((_tempOrder$holder4 = tempOrder.holder) !== null && _tempOrder$holder4 !== void 0 && _tempOrder$holder4.type) && tempOrder.holder.type === 'form',
1165
+ orderTotalAmount: Number(((_orderStore$summary2 = orderStore.summary) === null || _orderStore$summary2 === void 0 ? void 0 : _orderStore$summary2.total_amount) || 0)
1166
+ }) || result;
1167
+ if (result.productList) {
1168
+ tempOrder.products = result.productList;
1169
+ }
1170
+ if (!result.discountList) {
1171
+ _context12.next = 22;
1172
+ break;
1173
+ }
1174
+ nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1175
+ OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1176
+ _context12.next = 20;
1177
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1178
+ case 20:
1179
+ tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1180
+ return discount.isSelected;
1181
+ });
1182
+ result = {
1183
+ productList: tempOrder.products,
1184
+ discountList: nextDiscountList
1185
+ };
1186
+ case 22:
1187
+ _context12.next = 24;
1188
+ return this.store.order.recalculateSummary({
1189
+ createIfMissing: true
1190
+ });
1191
+ case 24:
1192
+ this.store.order.persistTempOrder();
1193
+ cb === null || cb === void 0 || cb(result);
1194
+ return _context12.abrupt("return", result);
1195
+ case 27:
1196
+ case "end":
1197
+ return _context12.stop();
1198
+ }
1199
+ }, _callee12, this);
1200
+ }));
1201
+ function bestDiscount(_x6) {
1202
+ return _bestDiscount.apply(this, arguments);
1203
+ }
1204
+ return bestDiscount;
1205
+ }()
675
1206
  }, {
676
1207
  key: "getDiscountList",
677
1208
  value: function getDiscountList() {
@@ -681,49 +1212,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
681
1212
  }, {
682
1213
  key: "scanPromotionCode",
683
1214
  value: function () {
684
- var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(code, customerId) {
1215
+ var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(code, customerId) {
685
1216
  var raw;
686
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
687
- while (1) switch (_context8.prev = _context8.next) {
1217
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1218
+ while (1) switch (_context13.prev = _context13.next) {
688
1219
  case 0:
689
- _context8.prev = 0;
1220
+ _context13.prev = 0;
690
1221
  if (this.store.order) {
691
- _context8.next = 3;
1222
+ _context13.next = 3;
692
1223
  break;
693
1224
  }
694
1225
  throw new Error('order 模块未初始化');
695
1226
  case 3:
696
- _context8.next = 5;
1227
+ _context13.next = 5;
697
1228
  return this.store.order.scanCode(code, customerId);
698
1229
  case 5:
699
- raw = _context8.sent;
1230
+ raw = _context13.sent;
700
1231
  if (!raw.isAvailable) {
701
- _context8.next = 10;
1232
+ _context13.next = 10;
702
1233
  break;
703
1234
  }
704
- _context8.next = 9;
1235
+ _context13.next = 9;
705
1236
  return this.store.order.recalculateSummary({
706
1237
  createIfMissing: true
707
1238
  });
708
1239
  case 9:
709
1240
  this.store.order.persistTempOrder();
710
1241
  case 10:
711
- return _context8.abrupt("return", {
1242
+ return _context13.abrupt("return", {
712
1243
  isAvailable: raw.isAvailable,
713
1244
  type: raw.type,
714
1245
  unavailableReason: raw.unavailableReason
715
1246
  });
716
1247
  case 13:
717
- _context8.prev = 13;
718
- _context8.t0 = _context8["catch"](0);
719
- throw _context8.t0;
1248
+ _context13.prev = 13;
1249
+ _context13.t0 = _context13["catch"](0);
1250
+ throw _context13.t0;
720
1251
  case 16:
721
1252
  case "end":
722
- return _context8.stop();
1253
+ return _context13.stop();
723
1254
  }
724
- }, _callee8, this, [[0, 13]]);
1255
+ }, _callee13, this, [[0, 13]]);
725
1256
  }));
726
- function scanPromotionCode(_x3, _x4) {
1257
+ function scanPromotionCode(_x7, _x8) {
727
1258
  return _scanPromotionCode.apply(this, arguments);
728
1259
  }
729
1260
  return scanPromotionCode;
@@ -731,14 +1262,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
731
1262
  }, {
732
1263
  key: "setDiscountSelected",
733
1264
  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) {
1265
+ var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
1266
+ var _tempOrder$holder5, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder6, result, beforeSelectedIds, _iterator, _step, d, selectedResourceIds, _iterator2, _step2, _product$metadata, _tempOrder$_extend3, _product$metadata2, _product$metadata$sou, _product$metadata3, _product$metadata4, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
1267
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1268
+ while (1) switch (_context14.prev = _context14.next) {
738
1269
  case 0:
739
- _context9.prev = 0;
1270
+ _context14.prev = 0;
740
1271
  if (this.store.order) {
741
- _context9.next = 3;
1272
+ _context14.next = 3;
742
1273
  break;
743
1274
  }
744
1275
  throw new Error('order 模块未初始化');
@@ -754,11 +1285,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
754
1285
  orderStore = this.store.order.store || {};
755
1286
  discountModule = orderStore.discount;
756
1287
  rulesModule = orderStore.rules;
757
- holders = (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
1288
+ holders = (_tempOrder$holder5 = tempOrder.holder) !== null && _tempOrder$holder5 !== void 0 && _tempOrder$holder5.form_record_id ? [{
758
1289
  form_record_id: tempOrder.holder.form_record_id
759
1290
  }] : [];
760
1291
  nextDiscountList = updated;
761
- _context9.next = 13;
1292
+ _context14.next = 13;
762
1293
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(updated);
763
1294
  case 13:
764
1295
  if (rulesModule) {
@@ -766,7 +1297,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
766
1297
  productList: tempOrder.products,
767
1298
  discountList: updated,
768
1299
  holders: holders,
769
- isFormSubject: !!((_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form'
1300
+ isFormSubject: !!((_tempOrder$holder6 = tempOrder.holder) !== null && _tempOrder$holder6 !== void 0 && _tempOrder$holder6.type) && tempOrder.holder.type === 'form'
770
1301
  }, {
771
1302
  discountId: params.discountId,
772
1303
  isSelected: params.isSelected
@@ -807,21 +1338,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
807
1338
  return d.id;
808
1339
  }));
809
1340
  _iterator2 = _createForOfIteratorHelper(tempOrder.products);
810
- _context9.prev = 16;
1341
+ _context14.prev = 16;
811
1342
  _iterator2.s();
812
1343
  case 18:
813
1344
  if ((_step2 = _iterator2.n()).done) {
814
- _context9.next = 34;
1345
+ _context14.next = 34;
815
1346
  break;
816
1347
  }
817
1348
  product = _step2.value;
818
1349
  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;
1350
+ 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;
820
1351
  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;
1352
+ _context14.next = 24;
822
1353
  break;
823
1354
  }
824
- return _context9.abrupt("continue", 32);
1355
+ return _context14.abrupt("continue", 32);
825
1356
  case 24:
826
1357
  product.discount_list = (product.discount_list || []).filter(function (pd) {
827
1358
  var _pd$discount$resource, _pd$discount;
@@ -847,65 +1378,133 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
847
1378
  bundle: product.product_bundle
848
1379
  });
849
1380
  case 32:
850
- _context9.next = 18;
1381
+ _context14.next = 18;
851
1382
  break;
852
1383
  case 34:
853
- _context9.next = 39;
1384
+ _context14.next = 39;
854
1385
  break;
855
1386
  case 36:
856
- _context9.prev = 36;
857
- _context9.t0 = _context9["catch"](16);
858
- _iterator2.e(_context9.t0);
1387
+ _context14.prev = 36;
1388
+ _context14.t0 = _context14["catch"](16);
1389
+ _iterator2.e(_context14.t0);
859
1390
  case 39:
860
- _context9.prev = 39;
1391
+ _context14.prev = 39;
861
1392
  _iterator2.f();
862
- return _context9.finish(39);
1393
+ return _context14.finish(39);
863
1394
  case 42:
864
1395
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
865
- _context9.next = 45;
1396
+ _context14.next = 45;
866
1397
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
867
1398
  case 45:
868
1399
  tempOrder.discount_list = (nextDiscountList || []).filter(function (d) {
869
1400
  return d.isSelected;
870
1401
  });
871
- _context9.next = 48;
1402
+ _context14.next = 48;
872
1403
  return this.store.order.recalculateSummary({
873
1404
  createIfMissing: true
874
1405
  });
875
1406
  case 48:
876
1407
  this.store.order.persistTempOrder();
877
- _context9.next = 54;
1408
+ this.effectsEmit('onDiscountApplied', {
1409
+ productList: tempOrder.products,
1410
+ discountList: nextDiscountList,
1411
+ selectedDiscountList: tempOrder.discount_list,
1412
+ tempOrder: tempOrder
1413
+ });
1414
+ _context14.next = 55;
878
1415
  break;
879
- case 51:
880
- _context9.prev = 51;
881
- _context9.t1 = _context9["catch"](0);
882
- throw _context9.t1;
883
- case 54:
1416
+ case 52:
1417
+ _context14.prev = 52;
1418
+ _context14.t1 = _context14["catch"](0);
1419
+ throw _context14.t1;
1420
+ case 55:
884
1421
  case "end":
885
- return _context9.stop();
1422
+ return _context14.stop();
886
1423
  }
887
- }, _callee9, this, [[0, 51], [16, 36, 39, 42]]);
1424
+ }, _callee14, this, [[0, 52], [16, 36, 39, 42]]);
888
1425
  }));
889
- function setDiscountSelected(_x5) {
1426
+ function setDiscountSelected(_x9) {
890
1427
  return _setDiscountSelected.apply(this, arguments);
891
1428
  }
892
1429
  return setDiscountSelected;
893
1430
  }()
1431
+ }, {
1432
+ key: "applyDiscountCalculationResult",
1433
+ value: function () {
1434
+ var _applyDiscountCalculationResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(result) {
1435
+ var tempOrder, orderStore, discountModule;
1436
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1437
+ while (1) switch (_context15.prev = _context15.next) {
1438
+ case 0:
1439
+ _context15.prev = 0;
1440
+ if (this.store.order) {
1441
+ _context15.next = 3;
1442
+ break;
1443
+ }
1444
+ throw new Error('order 模块未初始化');
1445
+ case 3:
1446
+ if (result) {
1447
+ _context15.next = 5;
1448
+ break;
1449
+ }
1450
+ return _context15.abrupt("return");
1451
+ case 5:
1452
+ tempOrder = this.store.order.ensureTempOrder();
1453
+ orderStore = this.store.order.store || {};
1454
+ discountModule = orderStore.discount;
1455
+ if (result.productList) {
1456
+ tempOrder.products = result.productList;
1457
+ }
1458
+ if (!result.discountList) {
1459
+ _context15.next = 14;
1460
+ break;
1461
+ }
1462
+ OrderModule.populateSavedAmounts(tempOrder.products, result.discountList);
1463
+ _context15.next = 13;
1464
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(result.discountList);
1465
+ case 13:
1466
+ tempOrder.discount_list = result.discountList.filter(function (discount) {
1467
+ return discount.isSelected;
1468
+ });
1469
+ case 14:
1470
+ _context15.next = 16;
1471
+ return this.store.order.recalculateSummary({
1472
+ createIfMissing: true
1473
+ });
1474
+ case 16:
1475
+ this.store.order.persistTempOrder();
1476
+ _context15.next = 22;
1477
+ break;
1478
+ case 19:
1479
+ _context15.prev = 19;
1480
+ _context15.t0 = _context15["catch"](0);
1481
+ throw _context15.t0;
1482
+ case 22:
1483
+ case "end":
1484
+ return _context15.stop();
1485
+ }
1486
+ }, _callee15, this, [[0, 19]]);
1487
+ }));
1488
+ function applyDiscountCalculationResult(_x10) {
1489
+ return _applyDiscountCalculationResult.apply(this, arguments);
1490
+ }
1491
+ return applyDiscountCalculationResult;
1492
+ }()
894
1493
  }, {
895
1494
  key: "submitScanOrder",
896
1495
  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) {
1496
+ var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
1497
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1498
+ while (1) switch (_context16.prev = _context16.next) {
900
1499
  case 0:
901
- return _context10.abrupt("return", this.submitSalesOrder(params));
1500
+ return _context16.abrupt("return", this.submitSalesOrder(params));
902
1501
  case 1:
903
1502
  case "end":
904
- return _context10.stop();
1503
+ return _context16.stop();
905
1504
  }
906
- }, _callee10, this);
1505
+ }, _callee16, this);
907
1506
  }));
908
- function submitScanOrder(_x6) {
1507
+ function submitScanOrder(_x11) {
909
1508
  return _submitScanOrder.apply(this, arguments);
910
1509
  }
911
1510
  return submitScanOrder;
@@ -919,14 +1518,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
919
1518
  }, {
920
1519
  key: "submitSalesOrder",
921
1520
  value: (function () {
922
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
923
- var _this$otherParams2, _this$otherParams3, _this$otherParams4, _this$otherParams5;
1521
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1522
+ var _this$otherParams4, _this$otherParams5, _this$otherParams6;
924
1523
  var submitParams;
925
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
926
- while (1) switch (_context11.prev = _context11.next) {
1524
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1525
+ while (1) switch (_context17.prev = _context17.next) {
927
1526
  case 0:
928
1527
  if (this.store.order) {
929
- _context11.next = 2;
1528
+ _context17.next = 2;
930
1529
  break;
931
1530
  }
932
1531
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -934,10 +1533,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
934
1533
  this.store.order.persistTempOrder();
935
1534
  submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
936
1535
  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
1536
+ platform: (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.platform,
1537
+ businessCode: (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.businessCode,
1538
+ channel: this.getSubmitOrderSalesChannel(),
1539
+ type: (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.type
941
1540
  }, (params === null || params === void 0 ? void 0 : params.payments) !== undefined ? {
942
1541
  payments: params.payments
943
1542
  } : {}), (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined ? {
@@ -947,14 +1546,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
947
1546
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
948
1547
  enhancePayload: params.enhancePayload
949
1548
  } : {});
950
- return _context11.abrupt("return", this.store.order.submitTempOrder(submitParams));
951
- case 5:
1549
+ console.log(submitParams, 'submitParams123');
1550
+ return _context17.abrupt("return", this.store.order.submitTempOrder(submitParams));
1551
+ case 6:
952
1552
  case "end":
953
- return _context11.stop();
1553
+ return _context17.stop();
954
1554
  }
955
- }, _callee11, this);
1555
+ }, _callee17, this);
956
1556
  }));
957
- function submitSalesOrder(_x7) {
1557
+ function submitSalesOrder(_x12) {
958
1558
  return _submitSalesOrder.apply(this, arguments);
959
1559
  }
960
1560
  return submitSalesOrder;
@@ -962,24 +1562,75 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
962
1562
  }, {
963
1563
  key: "syncPaymentsToOrder",
964
1564
  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) {
1565
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1566
+ var _params$channel;
1567
+ var channel, syncParams, syncState, payments, syncResult;
1568
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1569
+ while (1) switch (_context18.prev = _context18.next) {
968
1570
  case 0:
969
1571
  if (this.store.order) {
970
- _context12.next = 2;
1572
+ _context18.next = 2;
971
1573
  break;
972
1574
  }
973
1575
  throw new Error('order 模块未初始化');
974
1576
  case 2:
975
- return _context12.abrupt("return", this.store.order.syncPaymentsToOrder(params));
976
- case 3:
1577
+ channel = (_params$channel = params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel();
1578
+ syncParams = _objectSpread(_objectSpread({}, params), channel !== undefined ? {
1579
+ channel: channel
1580
+ } : {});
1581
+ syncState = this.store.order.getOrderSyncState();
1582
+ if (!(params.submitWhenPaid && syncState === 'submitting')) {
1583
+ _context18.next = 7;
1584
+ break;
1585
+ }
1586
+ return _context18.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
1587
+ case 7:
1588
+ payments = params.payments || [];
1589
+ _context18.next = 10;
1590
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncStart, {
1591
+ payments: payments,
1592
+ params: syncParams,
1593
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1594
+ orderSnapshot: this.store.order.getOrderSnapshot()
1595
+ });
1596
+ case 10:
1597
+ _context18.prev = 10;
1598
+ _context18.next = 13;
1599
+ return this.store.order.syncPaymentsToOrder(syncParams);
1600
+ case 13:
1601
+ syncResult = _context18.sent;
1602
+ _context18.next = 16;
1603
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
1604
+ ok: true,
1605
+ syncResult: syncResult,
1606
+ payments: this.store.order.getOrderPayments(),
1607
+ params: syncParams,
1608
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1609
+ orderSnapshot: this.store.order.getOrderSnapshot()
1610
+ });
1611
+ case 16:
1612
+ return _context18.abrupt("return", syncResult);
1613
+ case 19:
1614
+ _context18.prev = 19;
1615
+ _context18.t0 = _context18["catch"](10);
1616
+ _context18.next = 23;
1617
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
1618
+ ok: false,
1619
+ error: _context18.t0,
1620
+ payments: this.store.order.getOrderPayments(),
1621
+ params: syncParams,
1622
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1623
+ orderSnapshot: this.store.order.getOrderSnapshot()
1624
+ });
1625
+ case 23:
1626
+ throw _context18.t0;
1627
+ case 24:
977
1628
  case "end":
978
- return _context12.stop();
1629
+ return _context18.stop();
979
1630
  }
980
- }, _callee12, this);
1631
+ }, _callee18, this, [[10, 19]]);
981
1632
  }));
982
- function syncPaymentsToOrder(_x8) {
1633
+ function syncPaymentsToOrder(_x13) {
983
1634
  return _syncPaymentsToOrder.apply(this, arguments);
984
1635
  }
985
1636
  return syncPaymentsToOrder;
@@ -1003,8 +1654,25 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1003
1654
  }, {
1004
1655
  key: "addOrderPayment",
1005
1656
  value: function addOrderPayment(payment) {
1657
+ var _this5 = this;
1006
1658
  if (!this.store.order) throw new Error('order 模块未初始化');
1007
- return this.store.order.addOrderPayment(payment);
1659
+ var payments = this.store.order.addOrderPayment(payment);
1660
+ var amountSnapshot = this.store.order.getOrderAmountSnapshot();
1661
+ var syncState = this.store.order.getOrderSyncState();
1662
+ if (amountSnapshot && syncState !== 'submitting') {
1663
+ var paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? 'paid' : 'partially_paid';
1664
+ void this.syncPaymentsToOrder({
1665
+ payments: payments,
1666
+ paymentStatus: paymentStatus,
1667
+ submitWhenPaid: true,
1668
+ smallTicketDataFlag: 1
1669
+ }).catch(function (error) {
1670
+ _this5.logError('auto sync payments failed', {
1671
+ error: error instanceof Error ? error.message : String(error)
1672
+ });
1673
+ });
1674
+ }
1675
+ return payments;
1008
1676
  }
1009
1677
 
1010
1678
  /** 更新当前订单中的指定支付项。 */
@@ -1033,8 +1701,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1033
1701
  }, {
1034
1702
  key: "getWalletProductList",
1035
1703
  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();
1704
+ var _this$store$order3, _tempOrder$products;
1705
+ var tempOrder = (_this$store$order3 = this.store.order) === null || _this$store$order3 === void 0 ? void 0 : _this$store$order3.getTempOrder();
1038
1706
  if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$products = tempOrder.products) !== null && _tempOrder$products !== void 0 && _tempOrder$products.length)) return [];
1039
1707
  return tempOrder.products.map(function (product) {
1040
1708
  var _product$product_vari, _product$is_charge_ta, _product$holder_id, _metadata$main_produc, _metadata$main_produc2;
@@ -1047,6 +1715,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1047
1715
  is_charge_tax: (_product$is_charge_ta = product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0,
1048
1716
  tax_fee: product.tax_fee,
1049
1717
  selling_price: Number(product.selling_price || 0),
1718
+ discount_list: product.discount_list || [],
1050
1719
  holder_id: (_product$holder_id = product.holder_id) !== null && _product$holder_id !== void 0 ? _product$holder_id : metadata.holder_id,
1051
1720
  original_price: product.original_price,
1052
1721
  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 +1726,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1057
1726
  surcharge_rounding_remainder: metadata.surcharge_rounding_remainder
1058
1727
  },
1059
1728
  product_bundle: (product.product_bundle || []).map(function (bundle) {
1729
+ var _bundle$bundle_id, _bundle$bundle_produc, _bundle$bundle_group_;
1060
1730
  var bundleMetadata = bundle.metadata || {};
1061
1731
  return {
1062
1732
  is_price_include_tax: tempOrder.is_price_include_tax,
1063
- bundle_id: bundle.bundle_id,
1064
- bundle_product_id: bundle.bundle_product_id,
1733
+ // 套餐子项在 tempOrder 上常为 id(如 1718),prepare/deduction 协议要求 bundle_id
1734
+ bundle_id: (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id,
1735
+ bundle_product_id: (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id,
1736
+ bundle_group_id: (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id,
1065
1737
  bundle_variant_id: bundle.bundle_variant_id,
1066
1738
  price_type: bundle.price_type,
1067
1739
  price_type_ext: bundle.price_type_ext,
@@ -1082,20 +1754,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1082
1754
  }, {
1083
1755
  key: "initWalletData",
1084
1756
  value: function () {
1085
- var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
1757
+ var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
1086
1758
  var _params$order_wait_pa, _ref, _tempOrder$is_price_i;
1087
1759
  var snapshot, tempOrder, amount, walletBusinessData, result;
1088
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1089
- while (1) switch (_context13.prev = _context13.next) {
1760
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1761
+ while (1) switch (_context19.prev = _context19.next) {
1090
1762
  case 0:
1091
1763
  if (this.store.order) {
1092
- _context13.next = 2;
1764
+ _context19.next = 2;
1093
1765
  break;
1094
1766
  }
1095
1767
  throw new Error('order 模块未初始化');
1096
1768
  case 2:
1097
1769
  if (this.store.payment) {
1098
- _context13.next = 4;
1770
+ _context19.next = 4;
1099
1771
  break;
1100
1772
  }
1101
1773
  throw new Error('payment 模块未初始化');
@@ -1104,10 +1776,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1104
1776
  tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
1105
1777
  amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
1106
1778
  if (!(!tempOrder || !amount)) {
1107
- _context13.next = 9;
1779
+ _context19.next = 9;
1108
1780
  break;
1109
1781
  }
1110
- return _context13.abrupt("return", {
1782
+ return _context19.abrupt("return", {
1111
1783
  walletRecommendList: [],
1112
1784
  userIdentificationCodes: [],
1113
1785
  transformList: [],
@@ -1130,11 +1802,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1130
1802
  }, snapshot.identity.orderId ? {
1131
1803
  payment_order_id: String(snapshot.identity.orderId)
1132
1804
  } : {});
1133
- _context13.next = 12;
1805
+ _context19.next = 12;
1134
1806
  return this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
1135
1807
  case 12:
1136
- result = _context13.sent;
1137
- _context13.next = 15;
1808
+ result = _context19.sent;
1809
+ _context19.next = 15;
1138
1810
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
1139
1811
  orderId: snapshot.identity.orderId,
1140
1812
  customerId: walletBusinessData.customer_id,
@@ -1146,14 +1818,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1146
1818
  timestamp: Date.now()
1147
1819
  });
1148
1820
  case 15:
1149
- return _context13.abrupt("return", result);
1821
+ return _context19.abrupt("return", result);
1150
1822
  case 16:
1151
1823
  case "end":
1152
- return _context13.stop();
1824
+ return _context19.stop();
1153
1825
  }
1154
- }, _callee13, this);
1826
+ }, _callee19, this);
1155
1827
  }));
1156
- function initWalletData(_x9) {
1828
+ function initWalletData(_x14) {
1157
1829
  return _initWalletData.apply(this, arguments);
1158
1830
  }
1159
1831
  return initWalletData;
@@ -1180,27 +1852,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1180
1852
  }, {
1181
1853
  key: "getPaymentMethodsAsync",
1182
1854
  value: (function () {
1183
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1855
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1184
1856
  var response;
1185
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1186
- while (1) switch (_context14.prev = _context14.next) {
1857
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1858
+ while (1) switch (_context20.prev = _context20.next) {
1187
1859
  case 0:
1188
1860
  if (!this.store.payment) {
1189
- _context14.next = 2;
1861
+ _context20.next = 2;
1190
1862
  break;
1191
1863
  }
1192
- return _context14.abrupt("return", this.store.payment.getPayMethodListAsync());
1864
+ return _context20.abrupt("return", this.store.payment.getPayMethodListAsync());
1193
1865
  case 2:
1194
- _context14.next = 4;
1866
+ _context20.next = 4;
1195
1867
  return this.request.get('/pay/custom-payment/all');
1196
1868
  case 4:
1197
- response = _context14.sent;
1198
- return _context14.abrupt("return", (response === null || response === void 0 ? void 0 : response.data) || []);
1869
+ response = _context20.sent;
1870
+ return _context20.abrupt("return", (response === null || response === void 0 ? void 0 : response.data) || []);
1199
1871
  case 6:
1200
1872
  case "end":
1201
- return _context14.stop();
1873
+ return _context20.stop();
1202
1874
  }
1203
- }, _callee14, this);
1875
+ }, _callee20, this);
1204
1876
  }));
1205
1877
  function getPaymentMethodsAsync() {
1206
1878
  return _getPaymentMethodsAsync.apply(this, arguments);
@@ -1241,49 +1913,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1241
1913
  }, {
1242
1914
  key: "sendCustomerPayLink",
1243
1915
  value: (function () {
1244
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1916
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
1245
1917
  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) {
1918
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1919
+ while (1) switch (_context21.prev = _context21.next) {
1248
1920
  case 0:
1249
1921
  if (this.store.order) {
1250
- _context15.next = 2;
1922
+ _context21.next = 2;
1251
1923
  break;
1252
1924
  }
1253
1925
  throw new Error('order 模块未初始化');
1254
1926
  case 2:
1255
1927
  orderIds = params.order_ids || params.orderIds || [];
1256
1928
  if (!(!orderIds.length || params.submitBeforeSend)) {
1257
- _context15.next = 11;
1929
+ _context21.next = 11;
1258
1930
  break;
1259
1931
  }
1260
- _context15.next = 6;
1932
+ _context21.next = 6;
1261
1933
  return this.submitSalesOrder({
1262
1934
  smallTicketDataFlag: 1
1263
1935
  });
1264
1936
  case 6:
1265
- submitResult = _context15.sent;
1937
+ submitResult = _context21.sent;
1266
1938
  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;
1267
1939
  if (orderId) {
1268
- _context15.next = 10;
1940
+ _context21.next = 10;
1269
1941
  break;
1270
1942
  }
1271
1943
  throw new Error('本地订单提交云端失败,无法发送支付链接');
1272
1944
  case 10:
1273
1945
  orderIds = [orderId];
1274
1946
  case 11:
1275
- return _context15.abrupt("return", this.store.order.sendCustomerPayLink({
1947
+ return _context21.abrupt("return", this.store.order.sendCustomerPayLink({
1276
1948
  emails: params.emails,
1277
1949
  notify_action: params.notify_action,
1278
1950
  order_ids: orderIds
1279
1951
  }));
1280
1952
  case 12:
1281
1953
  case "end":
1282
- return _context15.stop();
1954
+ return _context21.stop();
1283
1955
  }
1284
- }, _callee15, this);
1956
+ }, _callee21, this);
1285
1957
  }));
1286
- function sendCustomerPayLink(_x10) {
1958
+ function sendCustomerPayLink(_x15) {
1287
1959
  return _sendCustomerPayLink.apply(this, arguments);
1288
1960
  }
1289
1961
  return sendCustomerPayLink;
@@ -1293,76 +1965,155 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1293
1965
  value: function transformBaseProductToOrderProduct(params) {
1294
1966
  return _transformBaseProductToOrderProduct(params);
1295
1967
  }
1968
+ }, {
1969
+ key: "calculateProductBookingPrice",
1970
+ value: function () {
1971
+ var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
1972
+ var _params$customer_id;
1973
+ var quotation, customerId;
1974
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1975
+ while (1) switch (_context22.prev = _context22.next) {
1976
+ case 0:
1977
+ quotation = this.store.quotation;
1978
+ customerId = (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : this.getCurrentOrderCustomerId();
1979
+ _context22.next = 4;
1980
+ return this.loadQuotationForPriceQuery({
1981
+ quotation: quotation,
1982
+ customer_id: customerId,
1983
+ channel: params.channel
1984
+ });
1985
+ case 4:
1986
+ return _context22.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
1987
+ customer_id: customerId,
1988
+ quotation: quotation
1989
+ })));
1990
+ case 5:
1991
+ case "end":
1992
+ return _context22.stop();
1993
+ }
1994
+ }, _callee22, this);
1995
+ }));
1996
+ function calculateProductBookingPrice(_x16) {
1997
+ return _calculateProductBookingPrice.apply(this, arguments);
1998
+ }
1999
+ return calculateProductBookingPrice;
2000
+ }()
1296
2001
  }, {
1297
2002
  key: "addProductToOrder",
1298
2003
  value: function () {
1299
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
2004
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(product, booking) {
1300
2005
  var products;
1301
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1302
- while (1) switch (_context16.prev = _context16.next) {
2006
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2007
+ while (1) switch (_context23.prev = _context23.next) {
1303
2008
  case 0:
1304
- _context16.prev = 0;
2009
+ _context23.prev = 0;
1305
2010
  if (this.store.order) {
1306
- _context16.next = 3;
2011
+ _context23.next = 3;
1307
2012
  break;
1308
2013
  }
1309
2014
  throw new Error('order 模块未初始化');
1310
2015
  case 3:
1311
- _context16.next = 5;
2016
+ _context23.next = 5;
1312
2017
  return this.store.order.addProductToOrder(product, booking);
1313
2018
  case 5:
1314
- products = _context16.sent;
1315
- return _context16.abrupt("return", products);
2019
+ products = _context23.sent;
2020
+ return _context23.abrupt("return", products);
1316
2021
  case 9:
1317
- _context16.prev = 9;
1318
- _context16.t0 = _context16["catch"](0);
1319
- throw _context16.t0;
2022
+ _context23.prev = 9;
2023
+ _context23.t0 = _context23["catch"](0);
2024
+ throw _context23.t0;
1320
2025
  case 12:
1321
2026
  case "end":
1322
- return _context16.stop();
2027
+ return _context23.stop();
1323
2028
  }
1324
- }, _callee16, this, [[0, 9]]);
2029
+ }, _callee23, this, [[0, 9]]);
1325
2030
  }));
1326
- function addProductToOrder(_x11, _x12) {
2031
+ function addProductToOrder(_x17, _x18) {
1327
2032
  return _addProductToOrder.apply(this, arguments);
1328
2033
  }
1329
2034
  return addProductToOrder;
1330
2035
  }()
1331
2036
  }, {
1332
- key: "updateProductInOrder",
2037
+ key: "updateOrderProduct",
1333
2038
  value: function () {
1334
- var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
2039
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
1335
2040
  var products;
1336
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1337
- while (1) switch (_context17.prev = _context17.next) {
2041
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2042
+ while (1) switch (_context24.prev = _context24.next) {
1338
2043
  case 0:
1339
- _context17.prev = 0;
2044
+ _context24.prev = 0;
1340
2045
  if (this.store.order) {
1341
- _context17.next = 3;
2046
+ _context24.next = 3;
1342
2047
  break;
1343
2048
  }
1344
2049
  throw new Error('order 模块未初始化');
1345
2050
  case 3:
1346
- _context17.next = 5;
1347
- return this.store.order.updateProductInOrder(params);
2051
+ _context24.next = 5;
2052
+ return this.store.order.updateOrderProduct(params);
1348
2053
  case 5:
1349
- products = _context17.sent;
1350
- return _context17.abrupt("return", products);
2054
+ products = _context24.sent;
2055
+ return _context24.abrupt("return", products);
1351
2056
  case 9:
1352
- _context17.prev = 9;
1353
- _context17.t0 = _context17["catch"](0);
1354
- throw _context17.t0;
2057
+ _context24.prev = 9;
2058
+ _context24.t0 = _context24["catch"](0);
2059
+ throw _context24.t0;
1355
2060
  case 12:
1356
2061
  case "end":
1357
- return _context17.stop();
2062
+ return _context24.stop();
2063
+ }
2064
+ }, _callee24, this, [[0, 9]]);
2065
+ }));
2066
+ function updateOrderProduct(_x19) {
2067
+ return _updateOrderProduct.apply(this, arguments);
2068
+ }
2069
+ return updateOrderProduct;
2070
+ }()
2071
+ }, {
2072
+ key: "updateOrderProductQuantity",
2073
+ value: function () {
2074
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
2075
+ var products;
2076
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2077
+ while (1) switch (_context25.prev = _context25.next) {
2078
+ case 0:
2079
+ _context25.prev = 0;
2080
+ if (this.store.order) {
2081
+ _context25.next = 3;
2082
+ break;
2083
+ }
2084
+ throw new Error('order 模块未初始化');
2085
+ case 3:
2086
+ _context25.next = 5;
2087
+ return this.store.order.updateOrderProductQuantity(params);
2088
+ case 5:
2089
+ products = _context25.sent;
2090
+ return _context25.abrupt("return", products);
2091
+ case 9:
2092
+ _context25.prev = 9;
2093
+ _context25.t0 = _context25["catch"](0);
2094
+ throw _context25.t0;
2095
+ case 12:
2096
+ case "end":
2097
+ return _context25.stop();
1358
2098
  }
1359
- }, _callee17, this, [[0, 9]]);
2099
+ }, _callee25, this, [[0, 9]]);
1360
2100
  }));
1361
- function updateProductInOrder(_x13) {
1362
- return _updateProductInOrder.apply(this, arguments);
2101
+ function updateOrderProductQuantity(_x20) {
2102
+ return _updateOrderProductQuantity.apply(this, arguments);
1363
2103
  }
1364
- return updateProductInOrder;
2104
+ return updateOrderProductQuantity;
1365
2105
  }()
2106
+ }, {
2107
+ key: "updateOrderBooking",
2108
+ value: function updateOrderBooking(params) {
2109
+ try {
2110
+ if (!this.store.order) throw new Error('order 模块未初始化');
2111
+ return this.store.order.updateOrderBooking(params);
2112
+ } catch (error) {
2113
+ throw error;
2114
+ }
2115
+ }
2116
+
1366
2117
  /**
1367
2118
  * 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
1368
2119
  * 多行同 SKU 时必须传入与删除/更新一致的 unique_identification_number。
@@ -1370,12 +2121,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1370
2121
  }, {
1371
2122
  key: "setOrderProductLineNote",
1372
2123
  value: (function () {
1373
- var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(identity, note) {
2124
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(identity, note) {
1374
2125
  var params, products;
1375
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1376
- while (1) switch (_context18.prev = _context18.next) {
2126
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2127
+ while (1) switch (_context26.prev = _context26.next) {
1377
2128
  case 0:
1378
- _context18.prev = 0;
2129
+ _context26.prev = 0;
1379
2130
  params = {
1380
2131
  product_id: identity.product_id,
1381
2132
  product_variant_id: identity.product_variant_id,
@@ -1390,22 +2141,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1390
2141
  params.product_option_item = identity.product_option_item;
1391
2142
  }
1392
2143
  if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
1393
- _context18.next = 7;
1394
- return this.updateProductInOrder(params);
2144
+ _context26.next = 7;
2145
+ return this.updateOrderProduct(params);
1395
2146
  case 7:
1396
- products = _context18.sent;
1397
- return _context18.abrupt("return", products);
2147
+ products = _context26.sent;
2148
+ return _context26.abrupt("return", products);
1398
2149
  case 11:
1399
- _context18.prev = 11;
1400
- _context18.t0 = _context18["catch"](0);
1401
- throw _context18.t0;
2150
+ _context26.prev = 11;
2151
+ _context26.t0 = _context26["catch"](0);
2152
+ throw _context26.t0;
1402
2153
  case 14:
1403
2154
  case "end":
1404
- return _context18.stop();
2155
+ return _context26.stop();
1405
2156
  }
1406
- }, _callee18, this, [[0, 11]]);
2157
+ }, _callee26, this, [[0, 11]]);
1407
2158
  }));
1408
- function setOrderProductLineNote(_x14, _x15) {
2159
+ function setOrderProductLineNote(_x21, _x22) {
1409
2160
  return _setOrderProductLineNote.apply(this, arguments);
1410
2161
  }
1411
2162
  return setOrderProductLineNote;
@@ -1413,34 +2164,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1413
2164
  }, {
1414
2165
  key: "removeProductFromOrder",
1415
2166
  value: function () {
1416
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
2167
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identity) {
1417
2168
  var products;
1418
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1419
- while (1) switch (_context19.prev = _context19.next) {
2169
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2170
+ while (1) switch (_context27.prev = _context27.next) {
1420
2171
  case 0:
1421
- _context19.prev = 0;
2172
+ _context27.prev = 0;
1422
2173
  if (this.store.order) {
1423
- _context19.next = 3;
2174
+ _context27.next = 3;
1424
2175
  break;
1425
2176
  }
1426
2177
  throw new Error('order 模块未初始化');
1427
2178
  case 3:
1428
- _context19.next = 5;
2179
+ _context27.next = 5;
1429
2180
  return this.store.order.removeProductFromOrder(identity);
1430
2181
  case 5:
1431
- products = _context19.sent;
1432
- return _context19.abrupt("return", products);
2182
+ products = _context27.sent;
2183
+ return _context27.abrupt("return", products);
1433
2184
  case 9:
1434
- _context19.prev = 9;
1435
- _context19.t0 = _context19["catch"](0);
1436
- throw _context19.t0;
2185
+ _context27.prev = 9;
2186
+ _context27.t0 = _context27["catch"](0);
2187
+ throw _context27.t0;
1437
2188
  case 12:
1438
2189
  case "end":
1439
- return _context19.stop();
2190
+ return _context27.stop();
1440
2191
  }
1441
- }, _callee19, this, [[0, 9]]);
2192
+ }, _callee27, this, [[0, 9]]);
1442
2193
  }));
1443
- function removeProductFromOrder(_x16) {
2194
+ function removeProductFromOrder(_x23) {
1444
2195
  return _removeProductFromOrder.apply(this, arguments);
1445
2196
  }
1446
2197
  return removeProductFromOrder;
@@ -1449,18 +2200,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1449
2200
  }, {
1450
2201
  key: "getProductList",
1451
2202
  value: function () {
1452
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1453
- var _this$otherParams6;
2203
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2204
+ var _this$otherParams7;
1454
2205
  var menu_list_ids, _this$store$products, res;
1455
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1456
- while (1) switch (_context20.prev = _context20.next) {
2206
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2207
+ while (1) switch (_context28.prev = _context28.next) {
1457
2208
  case 0:
1458
2209
  // 可以直接通过配置里的 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) {
2210
+ menu_list_ids = ((_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 || (_this$otherParams7 = _this$otherParams7.dineInConfig) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7['menu.associated_menus'].map(function (n) {
1460
2211
  return Number(n.value);
1461
2212
  })) || [];
1462
- _context20.prev = 1;
1463
- _context20.next = 4;
2213
+ _context28.prev = 1;
2214
+ _context28.next = 4;
1464
2215
  return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
1465
2216
  menu_list_ids: menu_list_ids,
1466
2217
  cacheId: this.cacheId,
@@ -1468,17 +2219,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1468
2219
  schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
1469
2220
  });
1470
2221
  case 4:
1471
- res = _context20.sent;
1472
- return _context20.abrupt("return", res);
2222
+ res = _context28.sent;
2223
+ return _context28.abrupt("return", res);
1473
2224
  case 8:
1474
- _context20.prev = 8;
1475
- _context20.t0 = _context20["catch"](1);
1476
- throw _context20.t0;
2225
+ _context28.prev = 8;
2226
+ _context28.t0 = _context28["catch"](1);
2227
+ throw _context28.t0;
1477
2228
  case 11:
1478
2229
  case "end":
1479
- return _context20.stop();
2230
+ return _context28.stop();
1480
2231
  }
1481
- }, _callee20, this, [[1, 8]]);
2232
+ }, _callee28, this, [[1, 8]]);
1482
2233
  }));
1483
2234
  function getProductList() {
1484
2235
  return _getProductList.apply(this, arguments);
@@ -1493,15 +2244,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1493
2244
  }, {
1494
2245
  key: "setOtherParams",
1495
2246
  value: function () {
1496
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2247
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
1497
2248
  var _ref4,
1498
2249
  _ref4$cover,
1499
2250
  cover,
1500
- _args21 = arguments;
1501
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1502
- while (1) switch (_context21.prev = _context21.next) {
2251
+ _args29 = arguments;
2252
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2253
+ while (1) switch (_context29.prev = _context29.next) {
1503
2254
  case 0:
1504
- _ref4 = _args21.length > 1 && _args21[1] !== undefined ? _args21[1] : {}, _ref4$cover = _ref4.cover, cover = _ref4$cover === void 0 ? false : _ref4$cover;
2255
+ _ref4 = _args29.length > 1 && _args29[1] !== undefined ? _args29[1] : {}, _ref4$cover = _ref4.cover, cover = _ref4$cover === void 0 ? false : _ref4$cover;
1505
2256
  if (cover) {
1506
2257
  this.otherParams = params;
1507
2258
  } else {
@@ -1509,11 +2260,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1509
2260
  }
1510
2261
  case 2:
1511
2262
  case "end":
1512
- return _context21.stop();
2263
+ return _context29.stop();
1513
2264
  }
1514
- }, _callee21, this);
2265
+ }, _callee29, this);
1515
2266
  }));
1516
- function setOtherParams(_x17) {
2267
+ function setOtherParams(_x24) {
1517
2268
  return _setOtherParams.apply(this, arguments);
1518
2269
  }
1519
2270
  return setOtherParams;