@pisell/pisellos 2.2.260 → 2.2.261

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 (129) hide show
  1. package/dist/model/strategy/adapter/index.d.ts +0 -4
  2. package/dist/model/strategy/adapter/index.js +1 -5
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +1 -1
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  12. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  13. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
  14. package/dist/modules/Order/index.d.ts +33 -2
  15. package/dist/modules/Order/index.js +615 -288
  16. package/dist/modules/Order/types.d.ts +20 -2
  17. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  18. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  19. package/dist/modules/Order/utils.d.ts +4 -0
  20. package/dist/modules/Order/utils.js +116 -29
  21. package/dist/modules/Product/types.d.ts +0 -22
  22. package/dist/modules/ProductList/index.d.ts +1 -1
  23. package/dist/modules/ProductList/index.js +2 -4
  24. package/dist/modules/ProductList/types.d.ts +0 -2
  25. package/dist/modules/Rules/index.d.ts +4 -3
  26. package/dist/modules/Rules/index.js +42 -17
  27. package/dist/modules/Rules/types.d.ts +2 -1
  28. package/dist/modules/SalesSummary/index.d.ts +7 -3
  29. package/dist/modules/SalesSummary/index.js +67 -39
  30. package/dist/modules/SalesSummary/types.d.ts +1 -0
  31. package/dist/modules/SalesSummary/utils.js +2 -1
  32. package/dist/modules/SurchargeList/index.d.ts +6 -4
  33. package/dist/modules/SurchargeList/index.js +62 -39
  34. package/dist/modules/SurchargeList/types.d.ts +6 -2
  35. package/dist/server/index.d.ts +3 -50
  36. package/dist/server/index.js +1075 -1040
  37. package/dist/server/modules/order/index.d.ts +22 -3
  38. package/dist/server/modules/order/index.js +398 -316
  39. package/dist/server/modules/products/index.d.ts +7 -26
  40. package/dist/server/modules/products/index.js +76 -166
  41. package/dist/server/modules/products/types.d.ts +0 -14
  42. package/dist/solution/BaseSales/index.d.ts +22 -2
  43. package/dist/solution/BaseSales/index.js +995 -701
  44. package/dist/solution/BaseSales/types.d.ts +1 -0
  45. package/dist/solution/BaseSales/types.js +2 -1
  46. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  47. package/dist/solution/BaseSales/utils/cartPromotion.js +74 -29
  48. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  49. package/dist/solution/BookingByStep/index.d.ts +1 -1
  50. package/dist/solution/BookingTicket/index.d.ts +9 -1
  51. package/dist/solution/BookingTicket/index.js +153 -6
  52. package/dist/solution/BookingTicket/types.d.ts +0 -2
  53. package/dist/solution/ScanOrder/index.js +31 -20
  54. package/dist/solution/VenueBooking/index.js +30 -19
  55. package/lib/model/strategy/adapter/index.d.ts +0 -4
  56. package/lib/model/strategy/adapter/index.js +2 -13
  57. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  58. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  59. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  60. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  61. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  62. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  63. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  64. package/lib/model/strategy/adapter/promotion/index.js +2 -0
  65. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  66. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  67. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
  68. package/lib/modules/Order/index.d.ts +33 -2
  69. package/lib/modules/Order/index.js +402 -64
  70. package/lib/modules/Order/types.d.ts +20 -2
  71. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  72. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  73. package/lib/modules/Order/utils.d.ts +4 -0
  74. package/lib/modules/Order/utils.js +90 -3
  75. package/lib/modules/Product/types.d.ts +0 -22
  76. package/lib/modules/ProductList/index.d.ts +1 -1
  77. package/lib/modules/ProductList/index.js +2 -4
  78. package/lib/modules/ProductList/types.d.ts +0 -2
  79. package/lib/modules/Rules/index.d.ts +4 -3
  80. package/lib/modules/Rules/index.js +27 -7
  81. package/lib/modules/Rules/types.d.ts +2 -1
  82. package/lib/modules/SalesSummary/index.d.ts +7 -3
  83. package/lib/modules/SalesSummary/index.js +28 -11
  84. package/lib/modules/SalesSummary/types.d.ts +1 -0
  85. package/lib/modules/SalesSummary/utils.js +2 -0
  86. package/lib/modules/SurchargeList/index.d.ts +6 -4
  87. package/lib/modules/SurchargeList/index.js +41 -21
  88. package/lib/modules/SurchargeList/types.d.ts +6 -2
  89. package/lib/server/index.d.ts +3 -50
  90. package/lib/server/index.js +244 -215
  91. package/lib/server/modules/order/index.d.ts +22 -3
  92. package/lib/server/modules/order/index.js +103 -53
  93. package/lib/server/modules/products/index.d.ts +7 -26
  94. package/lib/server/modules/products/index.js +35 -113
  95. package/lib/server/modules/products/types.d.ts +0 -14
  96. package/lib/solution/BaseSales/index.d.ts +22 -2
  97. package/lib/solution/BaseSales/index.js +246 -60
  98. package/lib/solution/BaseSales/types.d.ts +1 -0
  99. package/lib/solution/BaseSales/types.js +2 -1
  100. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  101. package/lib/solution/BaseSales/utils/cartPromotion.js +59 -16
  102. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -6
  103. package/lib/solution/BookingByStep/index.d.ts +1 -1
  104. package/lib/solution/BookingTicket/index.d.ts +9 -1
  105. package/lib/solution/BookingTicket/index.js +101 -0
  106. package/lib/solution/BookingTicket/types.d.ts +0 -2
  107. package/lib/solution/ScanOrder/index.js +8 -0
  108. package/lib/solution/VenueBooking/index.js +8 -0
  109. package/package.json +1 -1
  110. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -49
  111. package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -152
  112. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -87
  113. package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -755
  114. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  115. package/dist/model/strategy/adapter/dataVariant/examples.js +0 -282
  116. package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  117. package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
  118. package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -146
  119. package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
  120. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -49
  121. package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -139
  122. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -87
  123. package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -564
  124. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  125. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -295
  126. package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  127. package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
  128. package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -146
  129. package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
@@ -3,12 +3,11 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArra
3
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
4
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
5
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
- 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); }
6
+ 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
+ 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; }
7
8
  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
9
  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
10
  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
- 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; }
11
- 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; }
12
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
12
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
14
13
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -30,18 +29,20 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
30
29
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
31
30
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
32
31
  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; }
32
+ 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); }
33
33
  import { BaseModule } from "../../modules/BaseModule";
34
34
  import { BaseSalesHookNames } from "./types";
35
35
  import { OrderModule } from "../../modules/Order";
36
36
  import Decimal from 'decimal.js';
37
37
  import { cloneDeep, mergeWith } from 'lodash-es';
38
38
  import { createModule } from "../BookingByStep/types";
39
- import { composeLinePrice, createUuidV4, ensureProductSku, getProductSkuOptions, sumOptionUnitPrice } from "../../modules/Order/utils";
39
+ import { composeLinePrice, createUuidV4, ensureProductSku, getProductSkuOptions, resolveIsFormSubject, sumOptionUnitPrice } from "../../modules/Order/utils";
40
40
  import dayjs from 'dayjs';
41
41
  export * from "./types";
42
42
  import { QuotationModule } from "../../modules/Quotation";
43
43
  import { transformBaseProductToOrderProduct as _transformBaseProductToOrderProduct } from "./utils/transformBaseProductToOrderProduct";
44
44
  import { calculateBaseSalesProductBookingPrice } from "./utils/quotationPrice";
45
+ var SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
45
46
  function isBaseSalesManualProductDiscountProduct(product) {
46
47
  var _product$metadata, _product$metadata2;
47
48
  return (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.is_manual_discount) === true || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.is_manual_discount) === 1 || ((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (item) {
@@ -75,6 +76,16 @@ function getBaseSalesUniqueArrayMetadataKey(key) {
75
76
  if (key === 'payments' || key === 'payment') return 'unique_payment_number';
76
77
  return null;
77
78
  }
79
+ function isSameBaseSalesOrderRecord(left, right) {
80
+ if (!left || !right || _typeof(left) !== 'object' || _typeof(right) !== 'object') return false;
81
+ var leftIdentities = new Set([left.order_id, left.id, left.external_sale_number, left.order_number].filter(function (value) {
82
+ return value !== undefined && value !== null && value !== '';
83
+ }).map(String));
84
+ if (leftIdentities.size === 0) return false;
85
+ return [right.order_id, right.id, right.external_sale_number, right.order_number].some(function (value) {
86
+ return value !== undefined && value !== null && value !== '' && leftIdentities.has(String(value));
87
+ });
88
+ }
78
89
  function getBaseSalesMetadataUid(item, metadataKey) {
79
90
  var _item$metadata$metada, _item$metadata;
80
91
  var uid = (_item$metadata$metada = item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata[metadataKey]) !== null && _item$metadata$metada !== void 0 ? _item$metadata$metada : item === null || item === void 0 ? void 0 : item[metadataKey];
@@ -153,6 +164,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
153
164
  _defineProperty(_assertThisInitialized(_this), "hasManualDiscountSelection", false);
154
165
  _defineProperty(_assertThisInitialized(_this), "reusedSharedSubModuleNames", new Set());
155
166
  _defineProperty(_assertThisInitialized(_this), "paymentMethodsCache", []);
167
+ _defineProperty(_assertThisInitialized(_this), "queuedAutoPaymentSync", false);
168
+ _defineProperty(_assertThisInitialized(_this), "autoPaymentSyncFlushing", false);
169
+ _defineProperty(_assertThisInitialized(_this), "autoPaymentSyncTimer", null);
170
+ _defineProperty(_assertThisInitialized(_this), "salesDetailLoadInFlight", false);
171
+ _defineProperty(_assertThisInitialized(_this), "serverOrderChangeUnsubscribe", null);
172
+ _defineProperty(_assertThisInitialized(_this), "serverOrderChangeHydrateInFlight", null);
156
173
  return _this;
157
174
  }
158
175
 
@@ -168,9 +185,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
168
185
  }, {
169
186
  key: "getReusableSharedSubModule",
170
187
  value: function getReusableSharedSubModule(moduleName) {
171
- var _this$core;
188
+ var _this$core, _this$core$getModule;
172
189
  if (moduleName !== 'schedule' && moduleName !== 'quotation') return null;
173
- return ((_this$core = this.core) === null || _this$core === void 0 ? void 0 : _this$core.getModule(moduleName)) || null;
190
+ return ((_this$core = this.core) === null || _this$core === void 0 || (_this$core$getModule = _this$core.getModule) === null || _this$core$getModule === void 0 ? void 0 : _this$core$getModule.call(_this$core, moduleName)) || null;
174
191
  }
175
192
  }, {
176
193
  key: "isScheduleListLoaded",
@@ -232,6 +249,104 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
232
249
  });
233
250
  }
234
251
  }
252
+ }, {
253
+ key: "isCurrentSalesOrderRecord",
254
+ value: function isCurrentSalesOrderRecord(order) {
255
+ var _this$store$order, _this$store$order$get;
256
+ var currentTempOrder = (_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);
257
+ var currentRecords = [currentTempOrder, this.currentSalesDetail].filter(Boolean);
258
+ return currentRecords.some(function (record) {
259
+ return isSameBaseSalesOrderRecord(record, order);
260
+ });
261
+ }
262
+ }, {
263
+ key: "syncCurrentSalesDetailFromServerOrderChange",
264
+ value: function () {
265
+ var _syncCurrentSalesDetailFromServerOrderChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(payload) {
266
+ var _this2 = this;
267
+ var changedOrders, changedOrder;
268
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
269
+ while (1) switch (_context2.prev = _context2.next) {
270
+ case 0:
271
+ changedOrders = Array.isArray(payload) ? payload : Array.isArray(payload === null || payload === void 0 ? void 0 : payload.changedOrders) ? payload.changedOrders : payload !== null && payload !== void 0 && payload.data && _typeof(payload.data) === 'object' ? [payload.data] : [];
272
+ if (!(this.salesDetailLoadInFlight || this.serverOrderChangeHydrateInFlight)) {
273
+ _context2.next = 3;
274
+ break;
275
+ }
276
+ return _context2.abrupt("return");
277
+ case 3:
278
+ changedOrder = changedOrders.find(function (order) {
279
+ return _this2.isCurrentSalesOrderRecord(order);
280
+ });
281
+ if (changedOrder) {
282
+ _context2.next = 6;
283
+ break;
284
+ }
285
+ return _context2.abrupt("return");
286
+ case 6:
287
+ if (this.store.order) {
288
+ _context2.next = 8;
289
+ break;
290
+ }
291
+ return _context2.abrupt("return");
292
+ case 8:
293
+ this.serverOrderChangeHydrateInFlight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
294
+ var sales;
295
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
296
+ while (1) switch (_context.prev = _context.next) {
297
+ case 0:
298
+ _context.next = 2;
299
+ return _this2.store.order.hydrateTempOrderFromRecord(changedOrder, {
300
+ recalcOnHydrate: false
301
+ });
302
+ case 2:
303
+ sales = _context.sent;
304
+ _this2.currentSalesDetail = sales;
305
+ _context.next = 6;
306
+ return _this2.core.effects.emit("".concat(_this2.name, ":onSalesOrderLoaded"), {
307
+ sales: sales
308
+ });
309
+ case 6:
310
+ case "end":
311
+ return _context.stop();
312
+ }
313
+ }, _callee);
314
+ }))();
315
+ _context2.prev = 9;
316
+ _context2.next = 12;
317
+ return this.serverOrderChangeHydrateInFlight;
318
+ case 12:
319
+ _context2.prev = 12;
320
+ this.serverOrderChangeHydrateInFlight = null;
321
+ return _context2.finish(12);
322
+ case 15:
323
+ case "end":
324
+ return _context2.stop();
325
+ }
326
+ }, _callee2, this, [[9,, 12, 15]]);
327
+ }));
328
+ function syncCurrentSalesDetailFromServerOrderChange(_x) {
329
+ return _syncCurrentSalesDetailFromServerOrderChange.apply(this, arguments);
330
+ }
331
+ return syncCurrentSalesDetailFromServerOrderChange;
332
+ }()
333
+ }, {
334
+ key: "registerServerOrderChangeSync",
335
+ value: function registerServerOrderChangeSync() {
336
+ var _this$serverOrderChan,
337
+ _this$core2,
338
+ _this3 = this;
339
+ (_this$serverOrderChan = this.serverOrderChangeUnsubscribe) === null || _this$serverOrderChan === void 0 || _this$serverOrderChan.call(this);
340
+ var effects = (_this$core2 = this.core) === null || _this$core2 === void 0 ? void 0 : _this$core2.effects;
341
+ if (!effects || typeof effects.on !== 'function') return;
342
+ this.serverOrderChangeUnsubscribe = effects.on(SERVER_ORDER_CHANGED_EVENT, function (payload) {
343
+ void _this3.syncCurrentSalesDetailFromServerOrderChange(payload).catch(function (error) {
344
+ _this3.logError('sync sales detail from server order change failed', {
345
+ error: error instanceof Error ? error.message : String(error)
346
+ });
347
+ });
348
+ });
349
+ }
235
350
  }, {
236
351
  key: "hydrateOrderPaymentNames",
237
352
  value: function hydrateOrderPaymentNames(payments) {
@@ -269,8 +384,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
269
384
  }, {
270
385
  key: "getCurrentOrderCustomerId",
271
386
  value: function getCurrentOrderCustomerId() {
272
- var _this$store$order, _this$store$order$get;
273
- 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);
387
+ var _this$store$order2, _this$store$order2$ge;
388
+ var tempOrder = (_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 || (_this$store$order2$ge = _this$store$order2.getTempOrder) === null || _this$store$order2$ge === void 0 ? void 0 : _this$store$order2$ge.call(_this$store$order2);
274
389
  var customerId = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.customer_id;
275
390
  if (customerId === null || customerId === undefined) return undefined;
276
391
  return customerId;
@@ -296,10 +411,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
296
411
  });
297
412
  }
298
413
  quotation.setScheduleResolver(function (id) {
299
- var _scheduleModule$getSc, _getScheduleByIds, _ref;
414
+ var _scheduleModule$getSc, _getScheduleByIds, _ref2;
300
415
  var scheduleId = String(id);
301
416
  if (scheduleById.has(scheduleId)) return scheduleById.get(scheduleId);
302
- var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || ((_getScheduleByIds = (_ref = scheduleModule).getScheduleByIds) === null || _getScheduleByIds === void 0 ? void 0 : _getScheduleByIds.call(_ref, [id])) || [];
417
+ var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || ((_getScheduleByIds = (_ref2 = scheduleModule).getScheduleByIds) === null || _getScheduleByIds === void 0 ? void 0 : _getScheduleByIds.call(_ref2, [id])) || [];
303
418
  if (schedules[0]) scheduleById.set(scheduleId, schedules[0]);
304
419
  return schedules[0];
305
420
  });
@@ -307,30 +422,30 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
307
422
  }, {
308
423
  key: "loadQuotationForPriceQuery",
309
424
  value: function () {
310
- var _loadQuotationForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
425
+ var _loadQuotationForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
311
426
  var _this$otherParams;
312
- return _regeneratorRuntime().wrap(function _callee$(_context) {
313
- while (1) switch (_context.prev = _context.next) {
427
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
428
+ while (1) switch (_context3.prev = _context3.next) {
314
429
  case 0:
315
430
  if (params.quotation) {
316
- _context.next = 2;
431
+ _context3.next = 2;
317
432
  break;
318
433
  }
319
- return _context.abrupt("return");
434
+ return _context3.abrupt("return");
320
435
  case 2:
321
436
  this.applyQuotationScheduleResolver(params.quotation);
322
- _context.next = 5;
437
+ _context3.next = 5;
323
438
  return params.quotation.loadQuotations({
324
439
  channel: params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel),
325
440
  customer_id: params.customer_id
326
441
  });
327
442
  case 5:
328
443
  case "end":
329
- return _context.stop();
444
+ return _context3.stop();
330
445
  }
331
- }, _callee, this);
446
+ }, _callee3, this);
332
447
  }));
333
- function loadQuotationForPriceQuery(_x) {
448
+ function loadQuotationForPriceQuery(_x2) {
334
449
  return _loadQuotationForPriceQuery.apply(this, arguments);
335
450
  }
336
451
  return loadQuotationForPriceQuery;
@@ -374,23 +489,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
374
489
  }, {
375
490
  key: "loadProductsForPriceQuery",
376
491
  value: function () {
377
- var _loadProductsForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
492
+ var _loadProductsForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
378
493
  var ids, productsById, _this$otherParams2, _response$data, response, list;
379
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
380
- while (1) switch (_context2.prev = _context2.next) {
494
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
495
+ while (1) switch (_context4.prev = _context4.next) {
381
496
  case 0:
382
497
  ids = Array.from(new Set(params.ids.filter(function (id) {
383
498
  return Number.isFinite(id);
384
499
  })));
385
500
  productsById = new Map();
386
501
  if (!(!ids.length || !this.request)) {
387
- _context2.next = 4;
502
+ _context4.next = 4;
388
503
  break;
389
504
  }
390
- return _context2.abrupt("return", productsById);
505
+ return _context4.abrupt("return", productsById);
391
506
  case 4:
392
- _context2.prev = 4;
393
- _context2.next = 7;
507
+ _context4.prev = 4;
508
+ _context4.next = 7;
394
509
  return this.request.post('/product/query', {
395
510
  ids: ids,
396
511
  open_quotation: 1,
@@ -407,35 +522,35 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
407
522
  customToast: function customToast() {}
408
523
  });
409
524
  case 7:
410
- response = _context2.sent;
525
+ response = _context4.sent;
411
526
  list = (response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) || (response === null || response === void 0 ? void 0 : response.list) || [];
412
527
  if (Array.isArray(list)) {
413
- _context2.next = 11;
528
+ _context4.next = 11;
414
529
  break;
415
530
  }
416
- return _context2.abrupt("return", productsById);
531
+ return _context4.abrupt("return", productsById);
417
532
  case 11:
418
533
  list.forEach(function (item) {
419
534
  var _item$id;
420
535
  var productId = Number((_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.product_id);
421
536
  if (Number.isFinite(productId)) productsById.set(productId, item);
422
537
  });
423
- return _context2.abrupt("return", productsById);
538
+ return _context4.abrupt("return", productsById);
424
539
  case 15:
425
- _context2.prev = 15;
426
- _context2.t0 = _context2["catch"](4);
540
+ _context4.prev = 15;
541
+ _context4.t0 = _context4["catch"](4);
427
542
  this.logWarning('loadProductsForPriceQuery: 商品批量重查失败,使用入参 fallback', {
428
543
  ids: ids,
429
- error: _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0)
544
+ error: _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0)
430
545
  });
431
- return _context2.abrupt("return", productsById);
546
+ return _context4.abrupt("return", productsById);
432
547
  case 19:
433
548
  case "end":
434
- return _context2.stop();
549
+ return _context4.stop();
435
550
  }
436
- }, _callee2, this, [[4, 15]]);
551
+ }, _callee4, this, [[4, 15]]);
437
552
  }));
438
- function loadProductsForPriceQuery(_x2) {
553
+ function loadProductsForPriceQuery(_x3) {
439
554
  return _loadProductsForPriceQuery.apply(this, arguments);
440
555
  }
441
556
  return loadProductsForPriceQuery;
@@ -443,21 +558,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
443
558
  }, {
444
559
  key: "loadProductForPriceQuery",
445
560
  value: function () {
446
- var _loadProductForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params, customerId) {
561
+ var _loadProductForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params, customerId) {
447
562
  var product, productId, schedule, productsById;
448
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
449
- while (1) switch (_context3.prev = _context3.next) {
563
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
564
+ while (1) switch (_context5.prev = _context5.next) {
450
565
  case 0:
451
566
  product = params.product || {};
452
567
  productId = this.getPriceQueryProductId(product);
453
568
  if (!(productId === null || !this.request)) {
454
- _context3.next = 4;
569
+ _context5.next = 4;
455
570
  break;
456
571
  }
457
- return _context3.abrupt("return", null);
572
+ return _context5.abrupt("return", null);
458
573
  case 4:
459
574
  schedule = this.getPriceQuerySchedule(params);
460
- _context3.next = 7;
575
+ _context5.next = 7;
461
576
  return this.loadProductsForPriceQuery({
462
577
  ids: [productId],
463
578
  schedule: schedule,
@@ -465,15 +580,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
465
580
  channel: params.channel
466
581
  });
467
582
  case 7:
468
- productsById = _context3.sent;
469
- return _context3.abrupt("return", productsById.get(productId) || null);
583
+ productsById = _context5.sent;
584
+ return _context5.abrupt("return", productsById.get(productId) || null);
470
585
  case 9:
471
586
  case "end":
472
- return _context3.stop();
587
+ return _context5.stop();
473
588
  }
474
- }, _callee3, this);
589
+ }, _callee5, this);
475
590
  }));
476
- function loadProductForPriceQuery(_x3, _x4) {
591
+ function loadProductForPriceQuery(_x4, _x5) {
477
592
  return _loadProductForPriceQuery.apply(this, arguments);
478
593
  }
479
594
  return loadProductForPriceQuery;
@@ -486,10 +601,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
486
601
  return groups.flatMap(function (group) {
487
602
  var items = Array.isArray(group === null || group === void 0 ? void 0 : group.bundle_item) ? group.bundle_item : Array.isArray(group === null || group === void 0 ? void 0 : group.bundleItem) ? group.bundleItem : [];
488
603
  return items.map(function (item) {
489
- var _item$group_id, _ref2, _item$bundle_group_id;
604
+ var _item$group_id, _ref3, _item$bundle_group_id;
490
605
  return _objectSpread(_objectSpread({}, item), {}, {
491
606
  group_id: (_item$group_id = item === null || item === void 0 ? void 0 : item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : group === null || group === void 0 ? void 0 : group.id,
492
- bundle_group_id: (_ref2 = (_item$bundle_group_id = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item === null || item === void 0 ? void 0 : item.group_id) !== null && _ref2 !== void 0 ? _ref2 : group === null || group === void 0 ? void 0 : group.id
607
+ bundle_group_id: (_ref3 = (_item$bundle_group_id = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item === null || item === void 0 ? void 0 : item.group_id) !== null && _ref3 !== void 0 ? _ref3 : group === null || group === void 0 ? void 0 : group.id
493
608
  });
494
609
  });
495
610
  });
@@ -520,21 +635,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
520
635
  }, {
521
636
  key: "getAuthoritativeBundleUnitPrice",
522
637
  value: function getAuthoritativeBundleUnitPrice(bundle) {
523
- var _ref3, _ref4, _ref5, _bundle$price;
524
- return (_ref3 = (_ref4 = (_ref5 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref5 !== void 0 ? _ref5 : bundle.custom_price) !== null && _ref4 !== void 0 ? _ref4 : bundle.product_price) !== null && _ref3 !== void 0 ? _ref3 : bundle.base_price;
638
+ var _ref4, _ref5, _ref6, _bundle$price;
639
+ return (_ref4 = (_ref5 = (_ref6 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref6 !== void 0 ? _ref6 : bundle.custom_price) !== null && _ref5 !== void 0 ? _ref5 : bundle.product_price) !== null && _ref4 !== void 0 ? _ref4 : bundle.base_price;
525
640
  }
526
641
  }, {
527
642
  key: "mergeProductForPriceQuery",
528
643
  value: function mergeProductForPriceQuery(product, authoritativeProduct) {
529
- var _this2 = this,
644
+ var _this4 = this,
530
645
  _product$id,
531
- _ref6,
532
- _product$product_id2,
533
646
  _ref7,
534
- _product$product_vari,
647
+ _product$product_id2,
535
648
  _ref8,
536
- _product$num,
649
+ _product$product_vari,
537
650
  _ref9,
651
+ _product$num,
652
+ _ref10,
538
653
  _product$quantity,
539
654
  _product$metadata4;
540
655
  if (!authoritativeProduct) return product;
@@ -542,8 +657,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
542
657
  var authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
543
658
  var productBundle = selectedBundles.map(function (bundle) {
544
659
  var _authoritativeBundle$, _authoritativeBundle$2;
545
- var authoritativeBundle = _this2.findAuthoritativeBundleItem(bundle, authoritativeBundles);
546
- var unitPrice = authoritativeBundle ? _this2.getAuthoritativeBundleUnitPrice(authoritativeBundle) : undefined;
660
+ var authoritativeBundle = _this4.findAuthoritativeBundleItem(bundle, authoritativeBundles);
661
+ var unitPrice = authoritativeBundle ? _this4.getAuthoritativeBundleUnitPrice(authoritativeBundle) : undefined;
547
662
  if (unitPrice === undefined || unitPrice === null || unitPrice === '') return bundle;
548
663
  return _objectSpread(_objectSpread({}, bundle), {}, {
549
664
  price: unitPrice,
@@ -554,10 +669,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
554
669
  });
555
670
  return _objectSpread(_objectSpread(_objectSpread({}, product), authoritativeProduct), {}, {
556
671
  id: (_product$id = product.id) !== null && _product$id !== void 0 ? _product$id : authoritativeProduct.id,
557
- product_id: (_ref6 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref6 !== void 0 ? _ref6 : authoritativeProduct.id,
558
- product_variant_id: (_ref7 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref7 !== void 0 ? _ref7 : 0,
559
- num: (_ref8 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref8 !== void 0 ? _ref8 : authoritativeProduct.num,
560
- quantity: (_ref9 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref9 !== void 0 ? _ref9 : authoritativeProduct.quantity,
672
+ product_id: (_ref7 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref7 !== void 0 ? _ref7 : authoritativeProduct.id,
673
+ product_variant_id: (_ref8 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref8 !== void 0 ? _ref8 : 0,
674
+ num: (_ref9 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref9 !== void 0 ? _ref9 : authoritativeProduct.num,
675
+ quantity: (_ref10 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref10 !== void 0 ? _ref10 : authoritativeProduct.quantity,
561
676
  product_sku: function () {
562
677
  var authoritativeSku = ensureProductSku(authoritativeProduct);
563
678
  var productSku = ensureProductSku(product);
@@ -631,61 +746,61 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
631
746
  }, {
632
747
  key: "syncOtherParamsToSubModules",
633
748
  value: (function () {
634
- var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(changedParams) {
635
- var _this3 = this;
636
- var _ref10,
637
- _ref10$cover,
749
+ var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(changedParams) {
750
+ var _this5 = this;
751
+ var _ref11,
752
+ _ref11$cover,
638
753
  cover,
639
754
  nextSubModuleOtherParams,
640
- _args5 = arguments;
641
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
642
- while (1) switch (_context5.prev = _context5.next) {
755
+ _args7 = arguments;
756
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
757
+ while (1) switch (_context7.prev = _context7.next) {
643
758
  case 0:
644
- _ref10 = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {}, _ref10$cover = _ref10.cover, cover = _ref10$cover === void 0 ? false : _ref10$cover;
759
+ _ref11 = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {}, _ref11$cover = _ref11.cover, cover = _ref11$cover === void 0 ? false : _ref11$cover;
645
760
  nextSubModuleOtherParams = this.buildSubModuleOtherParams();
646
- _context5.next = 4;
761
+ _context7.next = 4;
647
762
  return Promise.all(Object.entries(this.store).map( /*#__PURE__*/function () {
648
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref11) {
649
- var _ref13, moduleName, subModule, targetModule;
650
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
651
- while (1) switch (_context4.prev = _context4.next) {
763
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref12) {
764
+ var _ref14, moduleName, subModule, targetModule;
765
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
766
+ while (1) switch (_context6.prev = _context6.next) {
652
767
  case 0:
653
- _ref13 = _slicedToArray(_ref11, 2), moduleName = _ref13[0], subModule = _ref13[1];
654
- if (!_this3.reusedSharedSubModuleNames.has(moduleName)) {
655
- _context4.next = 3;
768
+ _ref14 = _slicedToArray(_ref12, 2), moduleName = _ref14[0], subModule = _ref14[1];
769
+ if (!_this5.reusedSharedSubModuleNames.has(moduleName)) {
770
+ _context6.next = 3;
656
771
  break;
657
772
  }
658
- return _context4.abrupt("return");
773
+ return _context6.abrupt("return");
659
774
  case 3:
660
775
  targetModule = subModule;
661
776
  if (!(!targetModule || typeof targetModule.updateOtherParams !== 'function')) {
662
- _context4.next = 6;
777
+ _context6.next = 6;
663
778
  break;
664
779
  }
665
- return _context4.abrupt("return");
780
+ return _context6.abrupt("return");
666
781
  case 6:
667
- _context4.next = 8;
782
+ _context6.next = 8;
668
783
  return targetModule.updateOtherParams(nextSubModuleOtherParams, {
669
784
  changedParams: changedParams,
670
785
  cover: cover
671
786
  });
672
787
  case 8:
673
788
  case "end":
674
- return _context4.stop();
789
+ return _context6.stop();
675
790
  }
676
- }, _callee4);
791
+ }, _callee6);
677
792
  }));
678
- return function (_x6) {
679
- return _ref12.apply(this, arguments);
793
+ return function (_x7) {
794
+ return _ref13.apply(this, arguments);
680
795
  };
681
796
  }()));
682
797
  case 4:
683
798
  case "end":
684
- return _context5.stop();
799
+ return _context7.stop();
685
800
  }
686
- }, _callee5, this);
801
+ }, _callee7, this);
687
802
  }));
688
- function syncOtherParamsToSubModules(_x5) {
803
+ function syncOtherParamsToSubModules(_x6) {
689
804
  return _syncOtherParamsToSubModules.apply(this, arguments);
690
805
  }
691
806
  return syncOtherParamsToSubModules;
@@ -759,19 +874,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
759
874
  }, {
760
875
  key: "initialize",
761
876
  value: function () {
762
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(core) {
877
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(core) {
763
878
  var _this$otherParams4,
764
- _this4 = this,
879
+ _this6 = this,
765
880
  _this$otherParams5;
766
881
  var options,
767
882
  app,
768
883
  targetCacheData,
769
884
  moduleNames,
770
- _args6 = arguments;
771
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
772
- while (1) switch (_context6.prev = _context6.next) {
885
+ _args8 = arguments;
886
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
887
+ while (1) switch (_context8.prev = _context8.next) {
773
888
  case 0:
774
- options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
889
+ options = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
775
890
  this.core = core;
776
891
  this.initializeOptions = options || {};
777
892
  // this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
@@ -784,7 +899,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
784
899
  // 获取 logger 实例
785
900
  this.appPlugin = core.getPlugin('app');
786
901
  if (this.appPlugin) {
787
- _context6.next = 11;
902
+ _context8.next = 11;
788
903
  break;
789
904
  }
790
905
  throw new Error('Checkout 解决方案需要 app 插件支持');
@@ -794,47 +909,48 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
794
909
  targetCacheData = this.readSessionCacheData();
795
910
  moduleNames = this.getRegisteredModuleNames();
796
911
  moduleNames.forEach(function (step) {
797
- var reusedModule = _this4.getReusableSharedSubModule(step);
912
+ var reusedModule = _this6.getReusableSharedSubModule(step);
798
913
  if (reusedModule) {
799
- _this4.store[step] = reusedModule;
800
- _this4.reusedSharedSubModuleNames.add(step);
914
+ _this6.store[step] = reusedModule;
915
+ _this6.reusedSharedSubModuleNames.add(step);
801
916
  return;
802
917
  }
803
- var targetModule = _this4.createSubModule(step);
918
+ var targetModule = _this6.createSubModule(step);
804
919
  if (!targetModule) {
805
920
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
806
921
  }
807
- var hooks = _this4.getSubModuleHooks(step);
808
- _this4.store[step] = targetModule;
809
- _this4.core.registerModule(targetModule, _objectSpread(_objectSpread({
922
+ var hooks = _this6.getSubModuleHooks(step);
923
+ _this6.store[step] = targetModule;
924
+ _this6.core.registerModule(targetModule, _objectSpread(_objectSpread({
810
925
  initialState: (targetCacheData === null || targetCacheData === void 0 ? void 0 : targetCacheData[targetModule.name]) || {}
811
926
  }, hooks ? {
812
927
  hooks: hooks
813
928
  } : {}), {}, {
814
- otherParams: _this4.buildSubModuleOtherParams()
929
+ otherParams: _this6.buildSubModuleOtherParams()
815
930
  }));
816
931
  });
817
932
  if (!(this.store.schedule && !this.isScheduleListLoaded(this.store.schedule))) {
818
- _context6.next = 19;
933
+ _context8.next = 19;
819
934
  break;
820
935
  }
821
- _context6.next = 19;
936
+ _context8.next = 19;
822
937
  return this.store.schedule.loadAllSchedule();
823
938
  case 19:
824
939
  if (this.store.order && typeof ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.enableTempOrderPersist) === 'boolean') {
825
940
  this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
826
941
  }
827
- _context6.next = 22;
942
+ _context8.next = 22;
828
943
  return this.getPaymentMethodsAsync();
829
944
  case 22:
945
+ this.registerServerOrderChangeSync();
830
946
  this.core.effects.emit("".concat(this.name, ":onInited"), {});
831
- case 23:
947
+ case 24:
832
948
  case "end":
833
- return _context6.stop();
949
+ return _context8.stop();
834
950
  }
835
- }, _callee6, this);
951
+ }, _callee8, this);
836
952
  }));
837
- function initialize(_x7) {
953
+ function initialize(_x8) {
838
954
  return _initialize.apply(this, arguments);
839
955
  }
840
956
  return initialize;
@@ -842,14 +958,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
842
958
  }, {
843
959
  key: "destroy",
844
960
  value: function () {
845
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
846
- var _this5 = this;
847
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
848
- while (1) switch (_context7.prev = _context7.next) {
961
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
962
+ var _this$serverOrderChan2,
963
+ _this7 = this;
964
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
965
+ while (1) switch (_context9.prev = _context9.next) {
849
966
  case 0:
967
+ (_this$serverOrderChan2 = this.serverOrderChangeUnsubscribe) === null || _this$serverOrderChan2 === void 0 || _this$serverOrderChan2.call(this);
968
+ this.serverOrderChangeUnsubscribe = null;
850
969
  Object.keys(this.store).forEach(function (key) {
851
- if (_this5.reusedSharedSubModuleNames.has(key)) return;
852
- var sub = _this5.store[key];
970
+ if (_this7.reusedSharedSubModuleNames.has(key)) return;
971
+ var sub = _this7.store[key];
853
972
  if (sub && typeof sub.destroy === 'function') {
854
973
  try {
855
974
  sub.destroy();
@@ -859,15 +978,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
859
978
  }
860
979
  });
861
980
  this.currentSalesDetail = null;
862
- _context7.next = 4;
981
+ _context9.next = 6;
863
982
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
864
- case 4:
983
+ case 6:
865
984
  _get(_getPrototypeOf(BaseSalesImpl.prototype), "destroy", this).call(this);
866
- case 5:
985
+ case 7:
867
986
  case "end":
868
- return _context7.stop();
987
+ return _context9.stop();
869
988
  }
870
- }, _callee7, this);
989
+ }, _callee9, this);
871
990
  }));
872
991
  function destroy() {
873
992
  return _destroy.apply(this, arguments);
@@ -884,77 +1003,82 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
884
1003
  }, {
885
1004
  key: "loadSalesDetail",
886
1005
  value: (function () {
887
- var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(orderIdOrParams) {
888
- var _ref14, _ref15, _ref16, _ref17, _params$orderId;
889
- var params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, remoteRecord, currentTempOrder, record, sales;
890
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
891
- while (1) switch (_context8.prev = _context8.next) {
1006
+ var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderIdOrParams) {
1007
+ var _ref15, _ref16, _ref17, _ref18, _params$orderId, params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, remoteRecord, currentTempOrder, record, sales;
1008
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1009
+ while (1) switch (_context10.prev = _context10.next) {
892
1010
  case 0:
893
1011
  if (this.store.order) {
894
- _context8.next = 2;
1012
+ _context10.next = 2;
895
1013
  break;
896
1014
  }
897
1015
  throw new Error('order 模块未初始化');
898
1016
  case 2:
1017
+ this.salesDetailLoadInFlight = true;
1018
+ _context10.prev = 3;
899
1019
  params = _typeof(orderIdOrParams) === 'object' ? orderIdOrParams : {
900
1020
  orderId: orderIdOrParams
901
1021
  };
902
1022
  externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
903
1023
  preloadedSalesDetail = params.preloadedSalesDetail;
904
- lookup = (_ref14 = (_ref15 = (_ref16 = (_ref17 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref17 !== void 0 ? _ref17 : params.orderNumber) !== null && _ref16 !== void 0 ? _ref16 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_id) !== null && _ref15 !== void 0 ? _ref15 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.external_sale_number) !== null && _ref14 !== void 0 ? _ref14 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_number;
1024
+ lookup = (_ref15 = (_ref16 = (_ref17 = (_ref18 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref18 !== void 0 ? _ref18 : params.orderNumber) !== null && _ref17 !== void 0 ? _ref17 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_id) !== null && _ref16 !== void 0 ? _ref16 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.external_sale_number) !== null && _ref15 !== void 0 ? _ref15 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_number;
905
1025
  if (!(!preloadedSalesDetail && (lookup === undefined || lookup === null || lookup === ''))) {
906
- _context8.next = 8;
1026
+ _context10.next = 10;
907
1027
  break;
908
1028
  }
909
1029
  throw new Error('加载销售详情需要 orderId、externalSaleNumber 或 orderNumber');
910
- case 8:
1030
+ case 10:
911
1031
  if (!(preloadedSalesDetail !== null && preloadedSalesDetail !== void 0)) {
912
- _context8.next = 12;
1032
+ _context10.next = 14;
913
1033
  break;
914
1034
  }
915
- _context8.t0 = preloadedSalesDetail;
916
- _context8.next = 15;
1035
+ _context10.t0 = preloadedSalesDetail;
1036
+ _context10.next = 17;
917
1037
  break;
918
- case 12:
919
- _context8.next = 14;
1038
+ case 14:
1039
+ _context10.next = 16;
920
1040
  return this.store.order.getSalesOrderByLookup({
921
1041
  lookup: lookup,
922
1042
  forceRemote: params.forceRemote
923
1043
  });
924
- case 14:
925
- _context8.t0 = _context8.sent;
926
- case 15:
927
- loadedRecord = _context8.t0;
1044
+ case 16:
1045
+ _context10.t0 = _context10.sent;
1046
+ case 17:
1047
+ loadedRecord = _context10.t0;
928
1048
  if (!(!preloadedSalesDetail && (!loadedRecord || loadedRecord.code !== 200))) {
929
- _context8.next = 19;
1049
+ _context10.next = 21;
930
1050
  break;
931
1051
  }
932
1052
  message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(lookup);
933
1053
  throw new Error(message);
934
- case 19:
1054
+ case 21:
935
1055
  remoteRecord = preloadedSalesDetail !== null && preloadedSalesDetail !== void 0 ? preloadedSalesDetail : loadedRecord.data;
936
1056
  currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
937
1057
  record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord) : remoteRecord;
938
- _context8.next = 24;
1058
+ _context10.next = 26;
939
1059
  return this.store.order.hydrateTempOrderFromRecord(record, {
940
1060
  recalcOnHydrate: false
941
1061
  });
942
- case 24:
943
- sales = _context8.sent;
1062
+ case 26:
1063
+ sales = _context10.sent;
944
1064
  this.currentSalesDetail = sales;
945
- _context8.next = 28;
1065
+ _context10.next = 30;
946
1066
  return this.core.effects.emit("".concat(this.name, ":onSalesOrderLoaded"), {
947
1067
  sales: sales
948
1068
  });
949
- case 28:
950
- return _context8.abrupt("return", sales);
951
- case 29:
1069
+ case 30:
1070
+ return _context10.abrupt("return", sales);
1071
+ case 31:
1072
+ _context10.prev = 31;
1073
+ this.salesDetailLoadInFlight = false;
1074
+ return _context10.finish(31);
1075
+ case 34:
952
1076
  case "end":
953
- return _context8.stop();
1077
+ return _context10.stop();
954
1078
  }
955
- }, _callee8, this);
1079
+ }, _callee10, this, [[3,, 31, 34]]);
956
1080
  }));
957
- function loadSalesDetail(_x8) {
1081
+ function loadSalesDetail(_x9) {
958
1082
  return _loadSalesDetail.apply(this, arguments);
959
1083
  }
960
1084
  return loadSalesDetail;
@@ -1027,41 +1151,41 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1027
1151
  }, {
1028
1152
  key: "getTempOrder",
1029
1153
  value: function getTempOrder() {
1030
- var _this$store$order2;
1031
- var result = ((_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 ? void 0 : _this$store$order2.getTempOrder()) || null;
1154
+ var _this$store$order3;
1155
+ var result = ((_this$store$order3 = this.store.order) === null || _this$store$order3 === void 0 ? void 0 : _this$store$order3.getTempOrder()) || null;
1032
1156
  return result;
1033
1157
  }
1034
1158
  }, {
1035
1159
  key: "replaceTempOrder",
1036
1160
  value: function () {
1037
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(tempOrder) {
1161
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(tempOrder) {
1038
1162
  var nextTempOrder;
1039
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1040
- while (1) switch (_context9.prev = _context9.next) {
1163
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1164
+ while (1) switch (_context11.prev = _context11.next) {
1041
1165
  case 0:
1042
1166
  if (this.store.order) {
1043
- _context9.next = 2;
1167
+ _context11.next = 2;
1044
1168
  break;
1045
1169
  }
1046
1170
  throw new Error('order 模块未初始化');
1047
1171
  case 2:
1048
- _context9.next = 4;
1172
+ _context11.next = 4;
1049
1173
  return this.store.order.replaceTempOrder(tempOrder);
1050
1174
  case 4:
1051
- nextTempOrder = _context9.sent;
1052
- _context9.next = 7;
1175
+ nextTempOrder = _context11.sent;
1176
+ _context11.next = 7;
1053
1177
  return this.effectsEmit('onTempOrderReplaced', {
1054
1178
  tempOrder: nextTempOrder
1055
1179
  });
1056
1180
  case 7:
1057
- return _context9.abrupt("return", nextTempOrder);
1181
+ return _context11.abrupt("return", nextTempOrder);
1058
1182
  case 8:
1059
1183
  case "end":
1060
- return _context9.stop();
1184
+ return _context11.stop();
1061
1185
  }
1062
- }, _callee9, this);
1186
+ }, _callee11, this);
1063
1187
  }));
1064
- function replaceTempOrder(_x9) {
1188
+ function replaceTempOrder(_x10) {
1065
1189
  return _replaceTempOrder.apply(this, arguments);
1066
1190
  }
1067
1191
  return replaceTempOrder;
@@ -1159,40 +1283,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1159
1283
  }, {
1160
1284
  key: "addNewOrder",
1161
1285
  value: function () {
1162
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1286
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1163
1287
  var tempOrder;
1164
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1165
- while (1) switch (_context10.prev = _context10.next) {
1288
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1289
+ while (1) switch (_context12.prev = _context12.next) {
1166
1290
  case 0:
1167
- _context10.prev = 0;
1291
+ _context12.prev = 0;
1168
1292
  if (this.store.order) {
1169
- _context10.next = 3;
1293
+ _context12.next = 3;
1170
1294
  break;
1171
1295
  }
1172
1296
  throw new Error('order 模块未初始化');
1173
1297
  case 3:
1174
- _context10.next = 5;
1298
+ _context12.next = 5;
1175
1299
  return this.store.order.addNewOrder();
1176
1300
  case 5:
1177
- tempOrder = _context10.sent;
1301
+ tempOrder = _context12.sent;
1178
1302
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1179
- _context10.next = 10;
1303
+ _context12.next = 10;
1180
1304
  break;
1181
1305
  }
1182
1306
  this.store.order.persistTempOrder();
1183
- _context10.next = 10;
1307
+ _context12.next = 10;
1184
1308
  return this.store.order.saveDraft();
1185
1309
  case 10:
1186
- return _context10.abrupt("return", tempOrder);
1310
+ return _context12.abrupt("return", tempOrder);
1187
1311
  case 13:
1188
- _context10.prev = 13;
1189
- _context10.t0 = _context10["catch"](0);
1190
- throw _context10.t0;
1312
+ _context12.prev = 13;
1313
+ _context12.t0 = _context12["catch"](0);
1314
+ throw _context12.t0;
1191
1315
  case 16:
1192
1316
  case "end":
1193
- return _context10.stop();
1317
+ return _context12.stop();
1194
1318
  }
1195
- }, _callee10, this, [[0, 13]]);
1319
+ }, _callee12, this, [[0, 13]]);
1196
1320
  }));
1197
1321
  function addNewOrder() {
1198
1322
  return _addNewOrder.apply(this, arguments);
@@ -1202,22 +1326,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1202
1326
  }, {
1203
1327
  key: "saveDraft",
1204
1328
  value: function () {
1205
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1206
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1207
- while (1) switch (_context11.prev = _context11.next) {
1329
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1330
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1331
+ while (1) switch (_context13.prev = _context13.next) {
1208
1332
  case 0:
1209
1333
  if (this.store.order) {
1210
- _context11.next = 2;
1334
+ _context13.next = 2;
1211
1335
  break;
1212
1336
  }
1213
1337
  throw new Error('order 模块未初始化');
1214
1338
  case 2:
1215
- return _context11.abrupt("return", this.store.order.saveDraft());
1339
+ return _context13.abrupt("return", this.store.order.saveDraft());
1216
1340
  case 3:
1217
1341
  case "end":
1218
- return _context11.stop();
1342
+ return _context13.stop();
1219
1343
  }
1220
- }, _callee11, this);
1344
+ }, _callee13, this);
1221
1345
  }));
1222
1346
  function saveDraft() {
1223
1347
  return _saveDraft.apply(this, arguments);
@@ -1228,14 +1352,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1228
1352
  }, {
1229
1353
  key: "restoreOrder",
1230
1354
  value: function () {
1231
- var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1355
+ var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1232
1356
  var tempOrder;
1233
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1234
- while (1) switch (_context12.prev = _context12.next) {
1357
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1358
+ while (1) switch (_context14.prev = _context14.next) {
1235
1359
  case 0:
1236
- _context12.prev = 0;
1360
+ _context14.prev = 0;
1237
1361
  if (this.store.order) {
1238
- _context12.next = 3;
1362
+ _context14.next = 3;
1239
1363
  break;
1240
1364
  }
1241
1365
  throw new Error('scanOrder 解决方案需要 order 模块支持');
@@ -1245,29 +1369,29 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1245
1369
  this.currentSalesDetail = null;
1246
1370
  this.discountConfigCacheKey = null;
1247
1371
  this.hasManualDiscountSelection = false;
1248
- _context12.next = 9;
1372
+ _context14.next = 9;
1249
1373
  return this.effectsEmit('onTempOrderReplaced', {
1250
1374
  tempOrder: tempOrder
1251
1375
  });
1252
1376
  case 9:
1253
1377
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1254
- _context12.next = 13;
1378
+ _context14.next = 13;
1255
1379
  break;
1256
1380
  }
1257
1381
  this.store.order.persistTempOrder();
1258
- _context12.next = 13;
1382
+ _context14.next = 13;
1259
1383
  return this.store.order.saveDraft();
1260
1384
  case 13:
1261
- return _context12.abrupt("return", tempOrder);
1385
+ return _context14.abrupt("return", tempOrder);
1262
1386
  case 16:
1263
- _context12.prev = 16;
1264
- _context12.t0 = _context12["catch"](0);
1265
- throw _context12.t0;
1387
+ _context14.prev = 16;
1388
+ _context14.t0 = _context14["catch"](0);
1389
+ throw _context14.t0;
1266
1390
  case 19:
1267
1391
  case "end":
1268
- return _context12.stop();
1392
+ return _context14.stop();
1269
1393
  }
1270
- }, _callee12, this, [[0, 16]]);
1394
+ }, _callee14, this, [[0, 16]]);
1271
1395
  }));
1272
1396
  function restoreOrder() {
1273
1397
  return _restoreOrder.apply(this, arguments);
@@ -1281,22 +1405,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1281
1405
  }, {
1282
1406
  key: "clearOrderCartLines",
1283
1407
  value: (function () {
1284
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1408
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1285
1409
  var tempOrder;
1286
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1287
- while (1) switch (_context13.prev = _context13.next) {
1410
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1411
+ while (1) switch (_context15.prev = _context15.next) {
1288
1412
  case 0:
1289
- _context13.prev = 0;
1413
+ _context15.prev = 0;
1290
1414
  if (this.store.order) {
1291
- _context13.next = 3;
1415
+ _context15.next = 3;
1292
1416
  break;
1293
1417
  }
1294
1418
  throw new Error('order 模块未初始化');
1295
1419
  case 3:
1296
- _context13.next = 5;
1420
+ _context15.next = 5;
1297
1421
  return this.store.order.clearOrderCartLines();
1298
1422
  case 5:
1299
- tempOrder = _context13.sent;
1423
+ tempOrder = _context15.sent;
1300
1424
  if (this.currentSalesDetail) {
1301
1425
  this.currentSalesDetail = _objectSpread(_objectSpread({}, this.currentSalesDetail), {}, {
1302
1426
  products: [],
@@ -1306,29 +1430,29 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1306
1430
  discount_list: []
1307
1431
  });
1308
1432
  }
1309
- _context13.next = 9;
1433
+ _context15.next = 9;
1310
1434
  return this.effectsEmit('onTempOrderReplaced', {
1311
1435
  tempOrder: tempOrder
1312
1436
  });
1313
1437
  case 9:
1314
1438
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1315
- _context13.next = 13;
1439
+ _context15.next = 13;
1316
1440
  break;
1317
1441
  }
1318
1442
  this.store.order.persistTempOrder();
1319
- _context13.next = 13;
1443
+ _context15.next = 13;
1320
1444
  return this.store.order.saveDraft();
1321
1445
  case 13:
1322
- return _context13.abrupt("return", tempOrder);
1446
+ return _context15.abrupt("return", tempOrder);
1323
1447
  case 16:
1324
- _context13.prev = 16;
1325
- _context13.t0 = _context13["catch"](0);
1326
- throw _context13.t0;
1448
+ _context15.prev = 16;
1449
+ _context15.t0 = _context15["catch"](0);
1450
+ throw _context15.t0;
1327
1451
  case 19:
1328
1452
  case "end":
1329
- return _context13.stop();
1453
+ return _context15.stop();
1330
1454
  }
1331
- }, _callee13, this, [[0, 16]]);
1455
+ }, _callee15, this, [[0, 16]]);
1332
1456
  }));
1333
1457
  function clearOrderCartLines() {
1334
1458
  return _clearOrderCartLines.apply(this, arguments);
@@ -1345,32 +1469,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1345
1469
  }, {
1346
1470
  key: "getSummary",
1347
1471
  value: function () {
1348
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1472
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1349
1473
  var summary;
1350
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1351
- while (1) switch (_context14.prev = _context14.next) {
1474
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1475
+ while (1) switch (_context16.prev = _context16.next) {
1352
1476
  case 0:
1353
- _context14.prev = 0;
1477
+ _context16.prev = 0;
1354
1478
  if (this.store.order) {
1355
- _context14.next = 3;
1479
+ _context16.next = 3;
1356
1480
  break;
1357
1481
  }
1358
1482
  throw new Error('order 模块未初始化');
1359
1483
  case 3:
1360
- _context14.next = 5;
1484
+ _context16.next = 5;
1361
1485
  return this.store.order.getOrderSummary();
1362
1486
  case 5:
1363
- summary = _context14.sent;
1364
- return _context14.abrupt("return", summary);
1487
+ summary = _context16.sent;
1488
+ return _context16.abrupt("return", summary);
1365
1489
  case 9:
1366
- _context14.prev = 9;
1367
- _context14.t0 = _context14["catch"](0);
1368
- throw _context14.t0;
1490
+ _context16.prev = 9;
1491
+ _context16.t0 = _context16["catch"](0);
1492
+ throw _context16.t0;
1369
1493
  case 12:
1370
1494
  case "end":
1371
- return _context14.stop();
1495
+ return _context16.stop();
1372
1496
  }
1373
- }, _callee14, this, [[0, 9]]);
1497
+ }, _callee16, this, [[0, 9]]);
1374
1498
  }));
1375
1499
  function getSummary() {
1376
1500
  return _getSummary.apply(this, arguments);
@@ -1380,10 +1504,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1380
1504
  }, {
1381
1505
  key: "getHistoricalProductDiscountList",
1382
1506
  value: function getHistoricalProductDiscountList(products) {
1383
- var _this6 = this;
1507
+ var _this8 = this;
1384
1508
  var historyDiscountList = [];
1385
1509
  products.forEach(function (item) {
1386
- if (!_this6.isPersistedOrderProduct(item)) return;
1510
+ if (!_this8.isPersistedOrderProduct(item)) return;
1387
1511
  (item.discount_list || []).forEach(function (discount) {
1388
1512
  var _discount$discount, _discount$metadata, _discount$discount2, _discount$discount3, _discount$discount4;
1389
1513
  var discountId = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
@@ -1443,11 +1567,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1443
1567
  }, {
1444
1568
  key: "shouldSkipAutoApplyFetchedDiscountsInEditMode",
1445
1569
  value: function shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
1446
- var _this7 = this;
1570
+ var _this9 = this;
1447
1571
  if (params.discountAction !== 'edit') return false;
1448
1572
  if (!params.products.length) return false;
1449
1573
  var hasDraftProduct = params.products.some(function (product) {
1450
- return !_this7.isPersistedOrderProduct(product);
1574
+ return !_this9.isPersistedOrderProduct(product);
1451
1575
  });
1452
1576
  if (hasDraftProduct) return false;
1453
1577
  var hasSelectedDiscount = params.currentDiscountList.some(function (discount) {
@@ -1487,14 +1611,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1487
1611
  }, {
1488
1612
  key: "loadDiscountConfig",
1489
1613
  value: function () {
1490
- var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1614
+ var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1491
1615
  var _this$getOrderIdentit, _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _discountModule$getDi, _discountModule$getOr, _discountModule$getDi2;
1492
- var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _tempOrder$holder, _tempOrder$holder2, _orderStore$summary, holders, result, _iterator, _step, _product$metadata5, _tempOrder$_extend3, _product$metadata$sou, _product$metadata6, _product$metadata7, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
1493
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1494
- while (1) switch (_context15.prev = _context15.next) {
1616
+ var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _tempOrder$holder, _orderStore$summary, holders, orderTotalAmount, result, _iterator, _step, _product$metadata5, _tempOrder$_extend3, _product$metadata$sou, _product$metadata6, _product$metadata7, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
1617
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1618
+ while (1) switch (_context17.prev = _context17.next) {
1495
1619
  case 0:
1496
1620
  if (this.store.order) {
1497
- _context15.next = 2;
1621
+ _context17.next = 2;
1498
1622
  break;
1499
1623
  }
1500
1624
  throw new Error('order 模块未初始化');
@@ -1514,18 +1638,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1514
1638
  discountConfigCacheKey = [customerId, discountAction, Number(orderId) || 0].join(':');
1515
1639
  preparedDiscountList = [];
1516
1640
  if (!(customerId && customerId !== 1)) {
1517
- _context15.next = 25;
1641
+ _context17.next = 25;
1518
1642
  break;
1519
1643
  }
1520
1644
  if (!(this.discountConfigCacheKey === discountConfigCacheKey)) {
1521
- _context15.next = 19;
1645
+ _context17.next = 19;
1522
1646
  break;
1523
1647
  }
1524
1648
  preparedDiscountList = originalDiscountList;
1525
- _context15.next = 25;
1649
+ _context17.next = 25;
1526
1650
  break;
1527
1651
  case 19:
1528
- _context15.next = 21;
1652
+ _context17.next = 21;
1529
1653
  return this.store.order.loadDiscountConfig({
1530
1654
  customerId: customerId,
1531
1655
  action: discountAction,
@@ -1533,23 +1657,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1533
1657
  apply: false
1534
1658
  });
1535
1659
  case 21:
1536
- preparedDiscountList = _context15.sent;
1660
+ preparedDiscountList = _context17.sent;
1537
1661
  this.discountConfigCacheKey = discountConfigCacheKey;
1538
- _context15.next = 25;
1662
+ _context17.next = 25;
1539
1663
  return discountModule === null || discountModule === void 0 || (_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, preparedDiscountList);
1540
1664
  case 25:
1541
1665
  if (!(hasManualDiscountSelection && currentDiscountList.length)) {
1542
- _context15.next = 27;
1666
+ _context17.next = 27;
1543
1667
  break;
1544
1668
  }
1545
- return _context15.abrupt("return", {
1669
+ return _context17.abrupt("return", {
1546
1670
  productList: tempOrder.products || [],
1547
1671
  discountList: currentDiscountList
1548
1672
  });
1549
1673
  case 27:
1550
1674
  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 || []);
1551
1675
  nextDiscountList = this.mergeCurrentDiscountSelectionState(nextDiscountList, currentDiscountList);
1552
- _context15.next = 31;
1676
+ _context17.next = 31;
1553
1677
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1554
1678
  case 31:
1555
1679
  shouldSkipAutoApplyFetchedDiscounts = this.shouldSkipAutoApplyFetchedDiscountsInEditMode({
@@ -1559,17 +1683,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1559
1683
  nextDiscountList: nextDiscountList
1560
1684
  });
1561
1685
  if (!shouldSkipAutoApplyFetchedDiscounts) {
1562
- _context15.next = 40;
1686
+ _context17.next = 40;
1563
1687
  break;
1564
1688
  }
1565
- _context15.next = 35;
1689
+ _context17.next = 35;
1566
1690
  return this.store.order.recalculateSummary({
1567
1691
  createIfMissing: true
1568
1692
  });
1569
1693
  case 35:
1570
- _summary = _context15.sent;
1694
+ _summary = _context17.sent;
1571
1695
  this.store.order.persistTempOrder();
1572
- _context15.next = 39;
1696
+ _context17.next = 39;
1573
1697
  return this.effectsEmit('onDiscountApplied', {
1574
1698
  productList: tempOrder.products || [],
1575
1699
  discountList: nextDiscountList,
@@ -1577,24 +1701,26 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1577
1701
  tempOrder: tempOrder
1578
1702
  });
1579
1703
  case 39:
1580
- return _context15.abrupt("return", {
1704
+ return _context17.abrupt("return", {
1581
1705
  productList: tempOrder.products || [],
1582
1706
  discountList: nextDiscountList
1583
1707
  });
1584
1708
  case 40:
1585
1709
  if (!rulesModule) {
1586
- _context15.next = 76;
1710
+ _context17.next = 78;
1587
1711
  break;
1588
1712
  }
1589
- holders = (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
1590
- form_record_id: tempOrder.holder.form_record_id
1591
- }] : [];
1713
+ holders = ((_tempOrder$holder = tempOrder.holder) === null || _tempOrder$holder === void 0 ? void 0 : _tempOrder$holder.form_record) || [];
1714
+ orderTotalAmount = Number(((_orderStore$summary = orderStore.summary) === null || _orderStore$summary === void 0 ? void 0 : _orderStore$summary.total_amount) || 0);
1715
+ console.log('[BaseSales.applyDiscountConfig.calcDiscount]');
1592
1716
  result = rulesModule.calcDiscount({
1593
1717
  productList: tempOrder.products,
1594
1718
  discountList: nextDiscountList,
1595
1719
  holders: holders,
1596
- isFormSubject: !!((_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form',
1597
- orderTotalAmount: Number(((_orderStore$summary = orderStore.summary) === null || _orderStore$summary === void 0 ? void 0 : _orderStore$summary.total_amount) || 0)
1720
+ isFormSubject: function isFormSubject(product) {
1721
+ return resolveIsFormSubject(tempOrder, product);
1722
+ },
1723
+ orderTotalAmount: orderTotalAmount
1598
1724
  }) || {
1599
1725
  productList: tempOrder.products,
1600
1726
  discountList: nextDiscountList
@@ -1603,22 +1729,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1603
1729
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1604
1730
  }
1605
1731
  _iterator = _createForOfIteratorHelper(tempOrder.products || []);
1606
- _context15.prev = 45;
1732
+ _context17.prev = 47;
1607
1733
  _iterator.s();
1608
- case 47:
1734
+ case 49:
1609
1735
  if ((_step = _iterator.n()).done) {
1610
- _context15.next = 62;
1736
+ _context17.next = 64;
1611
1737
  break;
1612
1738
  }
1613
1739
  product = _step.value;
1614
1740
  productUid = (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number;
1615
1741
  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;
1616
1742
  if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
1617
- _context15.next = 53;
1743
+ _context17.next = 55;
1618
1744
  break;
1619
1745
  }
1620
- return _context15.abrupt("continue", 60);
1621
- case 53:
1746
+ return _context17.abrupt("continue", 62);
1747
+ case 55:
1622
1748
  totalPerUnitDiscount = (product.discount_list || []).reduce(function (sum, pd) {
1623
1749
  return sum + Number(pd.amount || 0);
1624
1750
  }, 0);
@@ -1634,60 +1760,60 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1634
1760
  mainPrice: newMainSellingPrice,
1635
1761
  bundle: product.product_bundle
1636
1762
  });
1637
- case 60:
1638
- _context15.next = 47;
1639
- break;
1640
1763
  case 62:
1641
- _context15.next = 67;
1764
+ _context17.next = 49;
1642
1765
  break;
1643
1766
  case 64:
1644
- _context15.prev = 64;
1645
- _context15.t0 = _context15["catch"](45);
1646
- _iterator.e(_context15.t0);
1647
- case 67:
1648
- _context15.prev = 67;
1767
+ _context17.next = 69;
1768
+ break;
1769
+ case 66:
1770
+ _context17.prev = 66;
1771
+ _context17.t0 = _context17["catch"](47);
1772
+ _iterator.e(_context17.t0);
1773
+ case 69:
1774
+ _context17.prev = 69;
1649
1775
  _iterator.f();
1650
- return _context15.finish(67);
1651
- case 70:
1776
+ return _context17.finish(69);
1777
+ case 72:
1652
1778
  if (!result.discountList) {
1653
- _context15.next = 76;
1779
+ _context17.next = 78;
1654
1780
  break;
1655
1781
  }
1656
1782
  nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1657
1783
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1658
- _context15.next = 75;
1784
+ _context17.next = 77;
1659
1785
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1660
- case 75:
1786
+ case 77:
1661
1787
  tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1662
1788
  return discount.isSelected;
1663
1789
  });
1664
- case 76:
1665
- _context15.next = 78;
1790
+ case 78:
1791
+ _context17.next = 80;
1666
1792
  return this.store.order.recalculateSummary({
1667
1793
  createIfMissing: true
1668
1794
  });
1669
- case 78:
1670
- summary = _context15.sent;
1795
+ case 80:
1796
+ summary = _context17.sent;
1671
1797
  this.store.order.persistTempOrder();
1672
- _context15.next = 82;
1798
+ _context17.next = 84;
1673
1799
  return this.effectsEmit('onDiscountApplied', {
1674
1800
  productList: tempOrder.products || [],
1675
1801
  discountList: nextDiscountList,
1676
1802
  selectedDiscountList: tempOrder.discount_list || [],
1677
1803
  tempOrder: tempOrder
1678
1804
  });
1679
- case 82:
1680
- return _context15.abrupt("return", {
1805
+ case 84:
1806
+ return _context17.abrupt("return", {
1681
1807
  productList: tempOrder.products || [],
1682
1808
  discountList: nextDiscountList
1683
1809
  });
1684
- case 83:
1810
+ case 85:
1685
1811
  case "end":
1686
- return _context15.stop();
1812
+ return _context17.stop();
1687
1813
  }
1688
- }, _callee15, this, [[45, 64, 67, 70]]);
1814
+ }, _callee17, this, [[47, 66, 69, 72]]);
1689
1815
  }));
1690
- function loadDiscountConfig(_x10) {
1816
+ function loadDiscountConfig(_x11) {
1691
1817
  return _loadDiscountConfig.apply(this, arguments);
1692
1818
  }
1693
1819
  return loadDiscountConfig;
@@ -1695,14 +1821,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1695
1821
  }, {
1696
1822
  key: "bestDiscount",
1697
1823
  value: function () {
1698
- var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(cb) {
1824
+ var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(cb) {
1699
1825
  var _discountModule$getOr2, _discountModule$getDi3;
1700
- var tempOrder, orderStore, discountModule, rulesModule, originalDiscountList, currentDiscountList, nextDiscountList, result, _tempOrder$holder3, _tempOrder$holder4, _orderStore$summary2, holders;
1701
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1702
- while (1) switch (_context16.prev = _context16.next) {
1826
+ var tempOrder, orderStore, discountModule, rulesModule, originalDiscountList, currentDiscountList, nextDiscountList, result, _tempOrder$holder2, _orderStore$summary2, holders, orderTotalAmount;
1827
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1828
+ while (1) switch (_context18.prev = _context18.next) {
1703
1829
  case 0:
1704
1830
  if (this.store.order) {
1705
- _context16.next = 2;
1831
+ _context18.next = 2;
1706
1832
  break;
1707
1833
  }
1708
1834
  throw new Error('order 模块未初始化');
@@ -1718,35 +1844,37 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1718
1844
  productList: tempOrder.products || [],
1719
1845
  discountList: nextDiscountList
1720
1846
  };
1721
- _context16.next = 12;
1847
+ _context18.next = 12;
1722
1848
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1723
1849
  case 12:
1724
1850
  if (!rulesModule) {
1725
- _context16.next = 23;
1851
+ _context18.next = 25;
1726
1852
  break;
1727
1853
  }
1728
- holders = (_tempOrder$holder3 = tempOrder.holder) !== null && _tempOrder$holder3 !== void 0 && _tempOrder$holder3.form_record_id ? [{
1729
- form_record_id: tempOrder.holder.form_record_id
1730
- }] : [];
1854
+ holders = ((_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_record) || [];
1855
+ orderTotalAmount = Number(((_orderStore$summary2 = orderStore.summary) === null || _orderStore$summary2 === void 0 ? void 0 : _orderStore$summary2.total_amount) || 0);
1856
+ console.log('[BaseSales.bestDiscount.calcDiscount]');
1731
1857
  result = rulesModule.calcDiscount({
1732
1858
  productList: tempOrder.products,
1733
1859
  discountList: nextDiscountList,
1734
1860
  holders: holders,
1735
- isFormSubject: !!((_tempOrder$holder4 = tempOrder.holder) !== null && _tempOrder$holder4 !== void 0 && _tempOrder$holder4.type) && tempOrder.holder.type === 'form',
1736
- orderTotalAmount: Number(((_orderStore$summary2 = orderStore.summary) === null || _orderStore$summary2 === void 0 ? void 0 : _orderStore$summary2.total_amount) || 0)
1861
+ isFormSubject: function isFormSubject(product) {
1862
+ return resolveIsFormSubject(tempOrder, product);
1863
+ },
1864
+ orderTotalAmount: orderTotalAmount
1737
1865
  }) || result;
1738
1866
  if (result.productList) {
1739
1867
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1740
1868
  }
1741
1869
  if (!result.discountList) {
1742
- _context16.next = 23;
1870
+ _context18.next = 25;
1743
1871
  break;
1744
1872
  }
1745
1873
  nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1746
1874
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1747
- _context16.next = 21;
1875
+ _context18.next = 23;
1748
1876
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1749
- case 21:
1877
+ case 23:
1750
1878
  tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1751
1879
  return discount.isSelected;
1752
1880
  });
@@ -1754,22 +1882,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1754
1882
  productList: tempOrder.products,
1755
1883
  discountList: nextDiscountList
1756
1884
  };
1757
- case 23:
1758
- _context16.next = 25;
1885
+ case 25:
1886
+ _context18.next = 27;
1759
1887
  return this.store.order.recalculateSummary({
1760
1888
  createIfMissing: true
1761
1889
  });
1762
- case 25:
1890
+ case 27:
1763
1891
  this.store.order.persistTempOrder();
1764
1892
  cb === null || cb === void 0 || cb(result);
1765
- return _context16.abrupt("return", result);
1766
- case 28:
1893
+ return _context18.abrupt("return", result);
1894
+ case 30:
1767
1895
  case "end":
1768
- return _context16.stop();
1896
+ return _context18.stop();
1769
1897
  }
1770
- }, _callee16, this);
1898
+ }, _callee18, this);
1771
1899
  }));
1772
- function bestDiscount(_x11) {
1900
+ function bestDiscount(_x12) {
1773
1901
  return _bestDiscount.apply(this, arguments);
1774
1902
  }
1775
1903
  return bestDiscount;
@@ -1783,49 +1911,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1783
1911
  }, {
1784
1912
  key: "scanPromotionCode",
1785
1913
  value: function () {
1786
- var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(code, customerId) {
1914
+ var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(code, customerId) {
1787
1915
  var raw;
1788
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1789
- while (1) switch (_context17.prev = _context17.next) {
1916
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1917
+ while (1) switch (_context19.prev = _context19.next) {
1790
1918
  case 0:
1791
- _context17.prev = 0;
1919
+ _context19.prev = 0;
1792
1920
  if (this.store.order) {
1793
- _context17.next = 3;
1921
+ _context19.next = 3;
1794
1922
  break;
1795
1923
  }
1796
1924
  throw new Error('order 模块未初始化');
1797
1925
  case 3:
1798
- _context17.next = 5;
1926
+ _context19.next = 5;
1799
1927
  return this.store.order.scanCode(code, customerId);
1800
1928
  case 5:
1801
- raw = _context17.sent;
1929
+ raw = _context19.sent;
1802
1930
  if (!raw.isAvailable) {
1803
- _context17.next = 10;
1931
+ _context19.next = 10;
1804
1932
  break;
1805
1933
  }
1806
- _context17.next = 9;
1934
+ _context19.next = 9;
1807
1935
  return this.store.order.recalculateSummary({
1808
1936
  createIfMissing: true
1809
1937
  });
1810
1938
  case 9:
1811
1939
  this.store.order.persistTempOrder();
1812
1940
  case 10:
1813
- return _context17.abrupt("return", {
1941
+ return _context19.abrupt("return", {
1814
1942
  isAvailable: raw.isAvailable,
1815
1943
  type: raw.type,
1816
1944
  unavailableReason: raw.unavailableReason
1817
1945
  });
1818
1946
  case 13:
1819
- _context17.prev = 13;
1820
- _context17.t0 = _context17["catch"](0);
1821
- throw _context17.t0;
1947
+ _context19.prev = 13;
1948
+ _context19.t0 = _context19["catch"](0);
1949
+ throw _context19.t0;
1822
1950
  case 16:
1823
1951
  case "end":
1824
- return _context17.stop();
1952
+ return _context19.stop();
1825
1953
  }
1826
- }, _callee17, this, [[0, 13]]);
1954
+ }, _callee19, this, [[0, 13]]);
1827
1955
  }));
1828
- function scanPromotionCode(_x12, _x13) {
1956
+ function scanPromotionCode(_x13, _x14) {
1829
1957
  return _scanPromotionCode.apply(this, arguments);
1830
1958
  }
1831
1959
  return scanPromotionCode;
@@ -1833,14 +1961,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1833
1961
  }, {
1834
1962
  key: "setDiscountSelected",
1835
1963
  value: function () {
1836
- var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1837
- var _tempOrder$holder5, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder6, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, _iterator3, _step3, _product$metadata8, _tempOrder$_extend4, _product$metadata$sou2, _product$metadata9, _product$metadata10, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
1838
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1839
- while (1) switch (_context18.prev = _context18.next) {
1964
+ var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
1965
+ var _tempOrder$holder3, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _orderStore$summary3, orderTotalAmount, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, filterSelectedDiscountDetails, _iterator3, _step3, _product$metadata8, _tempOrder$_extend4, _product$metadata$sou2, _product$metadata9, _product$metadata10, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
1966
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1967
+ while (1) switch (_context20.prev = _context20.next) {
1840
1968
  case 0:
1841
- _context18.prev = 0;
1969
+ _context20.prev = 0;
1842
1970
  if (this.store.order) {
1843
- _context18.next = 3;
1971
+ _context20.next = 3;
1844
1972
  break;
1845
1973
  }
1846
1974
  throw new Error('order 模块未初始化');
@@ -1857,19 +1985,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1857
1985
  orderStore = this.store.order.store || {};
1858
1986
  discountModule = orderStore.discount;
1859
1987
  rulesModule = orderStore.rules;
1860
- holders = (_tempOrder$holder5 = tempOrder.holder) !== null && _tempOrder$holder5 !== void 0 && _tempOrder$holder5.form_record_id ? [{
1861
- form_record_id: tempOrder.holder.form_record_id
1862
- }] : [];
1988
+ holders = ((_tempOrder$holder3 = tempOrder.holder) === null || _tempOrder$holder3 === void 0 ? void 0 : _tempOrder$holder3.form_record) || [];
1863
1989
  nextDiscountList = updated;
1864
- _context18.next = 14;
1990
+ _context20.next = 14;
1865
1991
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(updated);
1866
1992
  case 14:
1867
1993
  if (rulesModule) {
1994
+ orderTotalAmount = Number(((_orderStore$summary3 = orderStore.summary) === null || _orderStore$summary3 === void 0 ? void 0 : _orderStore$summary3.total_amount) || 0);
1995
+ console.log('[BaseSales.setDiscountSelected.calcDiscount]');
1868
1996
  result = rulesModule.calcDiscount({
1869
1997
  productList: tempOrder.products,
1870
1998
  discountList: updated,
1871
1999
  holders: holders,
1872
- isFormSubject: !!((_tempOrder$holder6 = tempOrder.holder) !== null && _tempOrder$holder6 !== void 0 && _tempOrder$holder6.type) && tempOrder.holder.type === 'form'
2000
+ isFormSubject: function isFormSubject(product) {
2001
+ return resolveIsFormSubject(tempOrder, product);
2002
+ },
2003
+ orderTotalAmount: orderTotalAmount
1873
2004
  }, {
1874
2005
  discountId: params.discountId,
1875
2006
  isSelected: params.isSelected
@@ -1895,6 +2026,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1895
2026
  if (d.isSelected && !beforeSelectedIds.has(d.id)) {
1896
2027
  d.isSelected = false;
1897
2028
  d.isManualSelect = true;
2029
+ d.appliedProductDetails = [];
1898
2030
  }
1899
2031
  }
1900
2032
  } catch (err) {
@@ -1910,28 +2042,45 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1910
2042
  }).map(function (d) {
1911
2043
  return d.id;
1912
2044
  }));
2045
+ filterSelectedDiscountDetails = function filterSelectedDiscountDetails(discountList) {
2046
+ return (discountList || []).filter(function (pd) {
2047
+ var _pd$discount$resource, _pd$discount;
2048
+ var rid = (_pd$discount$resource = (_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) !== null && _pd$discount$resource !== void 0 ? _pd$discount$resource : pd.id;
2049
+ return rid != null && selectedResourceIds.has(rid);
2050
+ });
2051
+ };
1913
2052
  _iterator3 = _createForOfIteratorHelper(tempOrder.products);
1914
- _context18.prev = 17;
2053
+ _context20.prev = 18;
1915
2054
  _iterator3.s();
1916
- case 19:
2055
+ case 20:
1917
2056
  if ((_step3 = _iterator3.n()).done) {
1918
- _context18.next = 35;
2057
+ _context20.next = 37;
1919
2058
  break;
1920
2059
  }
1921
2060
  product = _step3.value;
1922
2061
  productUid = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.unique_identification_number;
1923
2062
  runtimeOrigin = productUid ? (_tempOrder$_extend4 = tempOrder._extend) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4.productsByUid) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4[productUid]) === null || _tempOrder$_extend4 === void 0 ? void 0 : _tempOrder$_extend4.origin : undefined;
1924
2063
  if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
1925
- _context18.next = 25;
2064
+ _context20.next = 26;
1926
2065
  break;
1927
2066
  }
1928
- return _context18.abrupt("continue", 33);
1929
- case 25:
1930
- product.discount_list = (product.discount_list || []).filter(function (pd) {
1931
- var _pd$discount$resource, _pd$discount;
1932
- var rid = (_pd$discount$resource = (_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) !== null && _pd$discount$resource !== void 0 ? _pd$discount$resource : pd.id;
1933
- return rid != null && selectedResourceIds.has(rid);
1934
- });
2067
+ return _context20.abrupt("continue", 35);
2068
+ case 26:
2069
+ product.discount_list = filterSelectedDiscountDetails(product.discount_list);
2070
+ if (Array.isArray(product.product_bundle)) {
2071
+ product.product_bundle = product.product_bundle.map(function (bundle) {
2072
+ var _ref19, _bundle$original_pric;
2073
+ var nextBundleDiscountList = filterSelectedDiscountDetails(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
2074
+ var shouldRestoreBundlePrice = nextBundleDiscountList.length === 0;
2075
+ var restoredBundlePrice = (_ref19 = (_bundle$original_pric = bundle === null || bundle === void 0 ? void 0 : bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle === null || bundle === void 0 ? void 0 : bundle.product_price) !== null && _ref19 !== void 0 ? _ref19 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
2076
+ return _objectSpread(_objectSpread(_objectSpread({}, bundle), shouldRestoreBundlePrice ? {
2077
+ price: restoredBundlePrice,
2078
+ bundle_selling_price: restoredBundlePrice
2079
+ } : {}), {}, {
2080
+ discount_list: nextBundleDiscountList
2081
+ });
2082
+ });
2083
+ }
1935
2084
 
1936
2085
  // 券作用于 source(不含 option、不含 bundle);算出新 source 折后价后补回 options
1937
2086
  // 写入含 option 的 main_product_selling_price,再合成 composite 回写 selling_price。
@@ -1950,33 +2099,33 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1950
2099
  mainPrice: newMainSellingPrice,
1951
2100
  bundle: product.product_bundle
1952
2101
  });
1953
- case 33:
1954
- _context18.next = 19;
1955
- break;
1956
2102
  case 35:
1957
- _context18.next = 40;
2103
+ _context20.next = 20;
1958
2104
  break;
1959
2105
  case 37:
1960
- _context18.prev = 37;
1961
- _context18.t0 = _context18["catch"](17);
1962
- _iterator3.e(_context18.t0);
1963
- case 40:
1964
- _context18.prev = 40;
2106
+ _context20.next = 42;
2107
+ break;
2108
+ case 39:
2109
+ _context20.prev = 39;
2110
+ _context20.t0 = _context20["catch"](18);
2111
+ _iterator3.e(_context20.t0);
2112
+ case 42:
2113
+ _context20.prev = 42;
1965
2114
  _iterator3.f();
1966
- return _context18.finish(40);
1967
- case 43:
2115
+ return _context20.finish(42);
2116
+ case 45:
1968
2117
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1969
- _context18.next = 46;
2118
+ _context20.next = 48;
1970
2119
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1971
- case 46:
2120
+ case 48:
1972
2121
  tempOrder.discount_list = (nextDiscountList || []).filter(function (d) {
1973
2122
  return d.isSelected;
1974
2123
  });
1975
- _context18.next = 49;
2124
+ _context20.next = 51;
1976
2125
  return this.store.order.recalculateSummary({
1977
2126
  createIfMissing: true
1978
2127
  });
1979
- case 49:
2128
+ case 51:
1980
2129
  this.store.order.persistTempOrder();
1981
2130
  this.effectsEmit('onDiscountApplied', {
1982
2131
  productList: tempOrder.products,
@@ -1984,19 +2133,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1984
2133
  selectedDiscountList: tempOrder.discount_list,
1985
2134
  tempOrder: tempOrder
1986
2135
  });
1987
- _context18.next = 56;
2136
+ _context20.next = 58;
1988
2137
  break;
1989
- case 53:
1990
- _context18.prev = 53;
1991
- _context18.t1 = _context18["catch"](0);
1992
- throw _context18.t1;
1993
- case 56:
2138
+ case 55:
2139
+ _context20.prev = 55;
2140
+ _context20.t1 = _context20["catch"](0);
2141
+ throw _context20.t1;
2142
+ case 58:
1994
2143
  case "end":
1995
- return _context18.stop();
2144
+ return _context20.stop();
1996
2145
  }
1997
- }, _callee18, this, [[0, 53], [17, 37, 40, 43]]);
2146
+ }, _callee20, this, [[0, 55], [18, 39, 42, 45]]);
1998
2147
  }));
1999
- function setDiscountSelected(_x14) {
2148
+ function setDiscountSelected(_x15) {
2000
2149
  return _setDiscountSelected.apply(this, arguments);
2001
2150
  }
2002
2151
  return setDiscountSelected;
@@ -2004,23 +2153,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2004
2153
  }, {
2005
2154
  key: "applyDiscountCalculationResult",
2006
2155
  value: function () {
2007
- var _applyDiscountCalculationResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(result) {
2156
+ var _applyDiscountCalculationResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(result) {
2008
2157
  var tempOrder, orderStore, discountModule;
2009
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2010
- while (1) switch (_context19.prev = _context19.next) {
2158
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2159
+ while (1) switch (_context21.prev = _context21.next) {
2011
2160
  case 0:
2012
- _context19.prev = 0;
2161
+ _context21.prev = 0;
2013
2162
  if (this.store.order) {
2014
- _context19.next = 3;
2163
+ _context21.next = 3;
2015
2164
  break;
2016
2165
  }
2017
2166
  throw new Error('order 模块未初始化');
2018
2167
  case 3:
2019
2168
  if (result) {
2020
- _context19.next = 5;
2169
+ _context21.next = 5;
2021
2170
  break;
2022
2171
  }
2023
- return _context19.abrupt("return");
2172
+ return _context21.abrupt("return");
2024
2173
  case 5:
2025
2174
  tempOrder = this.store.order.ensureTempOrder();
2026
2175
  orderStore = this.store.order.store || {};
@@ -2029,36 +2178,36 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2029
2178
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
2030
2179
  }
2031
2180
  if (!result.discountList) {
2032
- _context19.next = 14;
2181
+ _context21.next = 14;
2033
2182
  break;
2034
2183
  }
2035
2184
  OrderModule.populateSavedAmounts(tempOrder.products, result.discountList);
2036
- _context19.next = 13;
2185
+ _context21.next = 13;
2037
2186
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(result.discountList);
2038
2187
  case 13:
2039
2188
  tempOrder.discount_list = result.discountList.filter(function (discount) {
2040
2189
  return discount.isSelected;
2041
2190
  });
2042
2191
  case 14:
2043
- _context19.next = 16;
2192
+ _context21.next = 16;
2044
2193
  return this.store.order.recalculateSummary({
2045
2194
  createIfMissing: true
2046
2195
  });
2047
2196
  case 16:
2048
2197
  this.store.order.persistTempOrder();
2049
- _context19.next = 22;
2198
+ _context21.next = 22;
2050
2199
  break;
2051
2200
  case 19:
2052
- _context19.prev = 19;
2053
- _context19.t0 = _context19["catch"](0);
2054
- throw _context19.t0;
2201
+ _context21.prev = 19;
2202
+ _context21.t0 = _context21["catch"](0);
2203
+ throw _context21.t0;
2055
2204
  case 22:
2056
2205
  case "end":
2057
- return _context19.stop();
2206
+ return _context21.stop();
2058
2207
  }
2059
- }, _callee19, this, [[0, 19]]);
2208
+ }, _callee21, this, [[0, 19]]);
2060
2209
  }));
2061
- function applyDiscountCalculationResult(_x15) {
2210
+ function applyDiscountCalculationResult(_x16) {
2062
2211
  return _applyDiscountCalculationResult.apply(this, arguments);
2063
2212
  }
2064
2213
  return applyDiscountCalculationResult;
@@ -2066,18 +2215,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2066
2215
  }, {
2067
2216
  key: "submitScanOrder",
2068
2217
  value: function () {
2069
- var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
2070
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2071
- while (1) switch (_context20.prev = _context20.next) {
2218
+ var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2219
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2220
+ while (1) switch (_context22.prev = _context22.next) {
2072
2221
  case 0:
2073
- return _context20.abrupt("return", this.submitSalesOrder(params));
2222
+ return _context22.abrupt("return", this.submitSalesOrder(params));
2074
2223
  case 1:
2075
2224
  case "end":
2076
- return _context20.stop();
2225
+ return _context22.stop();
2077
2226
  }
2078
- }, _callee20, this);
2227
+ }, _callee22, this);
2079
2228
  }));
2080
- function submitScanOrder(_x16) {
2229
+ function submitScanOrder(_x17) {
2081
2230
  return _submitScanOrder.apply(this, arguments);
2082
2231
  }
2083
2232
  return submitScanOrder;
@@ -2091,21 +2240,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2091
2240
  }, {
2092
2241
  key: "submitSalesOrder",
2093
2242
  value: (function () {
2094
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2243
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2095
2244
  var _this$otherParams6, _this$otherParams7, _this$otherParams8, _this$otherParams9;
2096
2245
  var inferredPaymentStatus, submitParams;
2097
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2098
- while (1) switch (_context21.prev = _context21.next) {
2246
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2247
+ while (1) switch (_context23.prev = _context23.next) {
2099
2248
  case 0:
2100
2249
  if (this.store.order) {
2101
- _context21.next = 2;
2250
+ _context23.next = 2;
2102
2251
  break;
2103
2252
  }
2104
2253
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2105
2254
  case 2:
2106
2255
  // this.store.order.persistTempOrder();
2107
2256
  inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
2108
- submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
2257
+ submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
2109
2258
  cacheId: this.cacheId,
2110
2259
  platform: (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform,
2111
2260
  businessCode: ((_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) || ((_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code),
@@ -2118,17 +2267,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2118
2267
  paymentStatus: inferredPaymentStatus
2119
2268
  } : {}), (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined ? {
2120
2269
  smallTicketDataFlag: params.smallTicketDataFlag
2270
+ } : {}), (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== undefined ? {
2271
+ confirmPendingVoucherPayments: params.confirmPendingVoucherPayments
2121
2272
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2122
2273
  enhancePayload: params.enhancePayload
2123
2274
  } : {});
2124
- return _context21.abrupt("return", this.store.order.submitTempOrder(submitParams));
2275
+ return _context23.abrupt("return", this.store.order.submitTempOrder(submitParams));
2125
2276
  case 5:
2126
2277
  case "end":
2127
- return _context21.stop();
2278
+ return _context23.stop();
2128
2279
  }
2129
- }, _callee21, this);
2280
+ }, _callee23, this);
2130
2281
  }));
2131
- function submitSalesOrder(_x17) {
2282
+ function submitSalesOrder(_x18) {
2132
2283
  return _submitSalesOrder.apply(this, arguments);
2133
2284
  }
2134
2285
  return submitSalesOrder;
@@ -2136,20 +2287,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2136
2287
  }, {
2137
2288
  key: "submitTempOrderAsync",
2138
2289
  value: function () {
2139
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2290
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2140
2291
  var _this$otherParams10, _this$otherParams11, _this$otherParams12, _this$otherParams13;
2141
2292
  var inferredPaymentStatus, submitParams;
2142
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2143
- while (1) switch (_context22.prev = _context22.next) {
2293
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2294
+ while (1) switch (_context24.prev = _context24.next) {
2144
2295
  case 0:
2145
2296
  if (this.store.order) {
2146
- _context22.next = 2;
2297
+ _context24.next = 2;
2147
2298
  break;
2148
2299
  }
2149
2300
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2150
2301
  case 2:
2151
2302
  inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
2152
- submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
2303
+ submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
2153
2304
  cacheId: this.cacheId,
2154
2305
  platform: (_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform,
2155
2306
  businessCode: ((_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code),
@@ -2161,17 +2312,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2161
2312
  paymentStatus: inferredPaymentStatus
2162
2313
  } : {}), (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined ? {
2163
2314
  smallTicketDataFlag: params.smallTicketDataFlag
2315
+ } : {}), (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== undefined ? {
2316
+ confirmPendingVoucherPayments: params.confirmPendingVoucherPayments
2164
2317
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2165
2318
  enhancePayload: params.enhancePayload
2166
2319
  } : {});
2167
- return _context22.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2320
+ return _context24.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2168
2321
  case 5:
2169
2322
  case "end":
2170
- return _context22.stop();
2323
+ return _context24.stop();
2171
2324
  }
2172
- }, _callee22, this);
2325
+ }, _callee24, this);
2173
2326
  }));
2174
- function submitTempOrderAsync(_x18) {
2327
+ function submitTempOrderAsync(_x19) {
2175
2328
  return _submitTempOrderAsync.apply(this, arguments);
2176
2329
  }
2177
2330
  return submitTempOrderAsync;
@@ -2179,14 +2332,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2179
2332
  }, {
2180
2333
  key: "printLocalOrderReceipt",
2181
2334
  value: function () {
2182
- var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(lookup) {
2335
+ var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(lookup) {
2183
2336
  var _this$otherParams14, _this$otherParams15, _this$otherParams16, _this$otherParams17;
2184
- var hasLookup, lookupPayload, context, payload, response, _this$store$order$app, _this$store$order3, _data;
2185
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2186
- while (1) switch (_context23.prev = _context23.next) {
2337
+ var hasLookup, lookupPayload, context, payload, response, _this$store$order$app, _this$store$order4, _data;
2338
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2339
+ while (1) switch (_context25.prev = _context25.next) {
2187
2340
  case 0:
2188
2341
  if (this.store.order) {
2189
- _context23.next = 2;
2342
+ _context25.next = 2;
2190
2343
  break;
2191
2344
  }
2192
2345
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -2217,28 +2370,28 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2217
2370
  channel: context.channel,
2218
2371
  type: context.type
2219
2372
  });
2220
- _context23.next = 8;
2373
+ _context25.next = 8;
2221
2374
  return this.request.post('/local/print-order', payload, {
2222
2375
  osServer: true,
2223
2376
  customToast: function customToast() {}
2224
2377
  });
2225
2378
  case 8:
2226
- response = _context23.sent;
2379
+ response = _context25.sent;
2227
2380
  if (hasLookup) {
2228
- _context23.next = 12;
2381
+ _context25.next = 12;
2229
2382
  break;
2230
2383
  }
2231
- _context23.next = 12;
2232
- return (_this$store$order$app = (_this$store$order3 = this.store.order).applyLocalPrintOrderNumbers) === null || _this$store$order$app === void 0 ? void 0 : _this$store$order$app.call(_this$store$order3, response === null || response === void 0 || (_data = response.data) === null || _data === void 0 ? void 0 : _data.order);
2384
+ _context25.next = 12;
2385
+ return (_this$store$order$app = (_this$store$order4 = this.store.order).applyLocalPrintOrderNumbers) === null || _this$store$order$app === void 0 ? void 0 : _this$store$order$app.call(_this$store$order4, response === null || response === void 0 || (_data = response.data) === null || _data === void 0 ? void 0 : _data.order);
2233
2386
  case 12:
2234
- return _context23.abrupt("return", response);
2387
+ return _context25.abrupt("return", response);
2235
2388
  case 13:
2236
2389
  case "end":
2237
- return _context23.stop();
2390
+ return _context25.stop();
2238
2391
  }
2239
- }, _callee23, this);
2392
+ }, _callee25, this);
2240
2393
  }));
2241
- function printLocalOrderReceipt(_x19) {
2394
+ function printLocalOrderReceipt(_x20) {
2242
2395
  return _printLocalOrderReceipt.apply(this, arguments);
2243
2396
  }
2244
2397
  return printLocalOrderReceipt;
@@ -2246,9 +2399,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2246
2399
  }, {
2247
2400
  key: "getSubmitPaymentStatus",
2248
2401
  value: function getSubmitPaymentStatus(paymentStatus) {
2249
- var _this$store$order4, _this$store$order4$ge;
2402
+ var _this$store$order5, _this$store$order5$ge;
2250
2403
  if (paymentStatus !== undefined) return paymentStatus;
2251
- var amountSnapshot = (_this$store$order4 = this.store.order) === null || _this$store$order4 === void 0 || (_this$store$order4$ge = _this$store$order4.getOrderAmountSnapshot) === null || _this$store$order4$ge === void 0 ? void 0 : _this$store$order4$ge.call(_this$store$order4);
2404
+ var amountSnapshot = (_this$store$order5 = this.store.order) === null || _this$store$order5 === void 0 || (_this$store$order5$ge = _this$store$order5.getOrderAmountSnapshot) === null || _this$store$order5$ge === void 0 ? void 0 : _this$store$order5$ge.call(_this$store$order5);
2252
2405
  if (!amountSnapshot) return undefined;
2253
2406
  try {
2254
2407
  return new Decimal(amountSnapshot.amountGap || 0).lte(0) ? 'paid' : undefined;
@@ -2259,19 +2412,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2259
2412
  }, {
2260
2413
  key: "syncPaymentsToOrder",
2261
2414
  value: function () {
2262
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2263
- var _ref18, _params$businessCode, _this$otherParams18, _this$otherParams19, _params$channel;
2264
- var businessCode, channel, syncParams, syncState, payments, syncResult;
2265
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2266
- while (1) switch (_context24.prev = _context24.next) {
2415
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2416
+ var _ref20, _params$businessCode, _this$otherParams18, _this$otherParams19, _params$channel;
2417
+ var businessCode, channel, syncParams, syncState, payments, syncResult, latestPayments, amountSnapshot, orderSnapshot, syncPayload;
2418
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2419
+ while (1) switch (_context26.prev = _context26.next) {
2267
2420
  case 0:
2268
2421
  if (this.store.order) {
2269
- _context24.next = 2;
2422
+ _context26.next = 2;
2270
2423
  break;
2271
2424
  }
2272
2425
  throw new Error('order 模块未初始化');
2273
2426
  case 2:
2274
- businessCode = (_ref18 = (_params$businessCode = params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.businessCode) !== null && _ref18 !== void 0 ? _ref18 : (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.business_code;
2427
+ businessCode = (_ref20 = (_params$businessCode = params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.businessCode) !== null && _ref20 !== void 0 ? _ref20 : (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.business_code;
2275
2428
  channel = (_params$channel = params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel();
2276
2429
  syncParams = _objectSpread(_objectSpread(_objectSpread({}, params), businessCode !== undefined ? {
2277
2430
  businessCode: businessCode
@@ -2280,57 +2433,77 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2280
2433
  } : {});
2281
2434
  syncState = this.store.order.getOrderSyncState();
2282
2435
  if (!(params.submitWhenPaid && syncState === 'submitting')) {
2283
- _context24.next = 8;
2436
+ _context26.next = 9;
2284
2437
  break;
2285
2438
  }
2286
- return _context24.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2287
- case 8:
2439
+ this.queueLatestAutoPaymentSync();
2440
+ return _context26.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2441
+ case 9:
2288
2442
  payments = params.payments || [];
2289
- _context24.next = 11;
2443
+ _context26.next = 12;
2290
2444
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncStart, {
2291
2445
  payments: payments,
2292
2446
  params: syncParams,
2293
2447
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
2294
2448
  orderSnapshot: this.store.order.getOrderSnapshot()
2295
2449
  });
2296
- case 11:
2297
- _context24.prev = 11;
2298
- _context24.next = 14;
2450
+ case 12:
2451
+ _context26.prev = 12;
2452
+ _context26.next = 15;
2299
2453
  return this.store.order.syncPaymentsToOrder(syncParams);
2300
- case 14:
2301
- syncResult = _context24.sent;
2302
- _context24.next = 17;
2303
- return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2454
+ case 15:
2455
+ syncResult = _context26.sent;
2456
+ latestPayments = this.store.order.getOrderPayments();
2457
+ amountSnapshot = this.store.order.getOrderAmountSnapshot();
2458
+ orderSnapshot = this.store.order.getOrderSnapshot();
2459
+ syncPayload = {
2304
2460
  ok: true,
2305
2461
  syncResult: syncResult,
2306
- payments: this.store.order.getOrderPayments(),
2462
+ payments: latestPayments,
2307
2463
  params: syncParams,
2308
- amountSnapshot: this.store.order.getOrderAmountSnapshot(),
2309
- orderSnapshot: this.store.order.getOrderSnapshot()
2310
- });
2311
- case 17:
2312
- return _context24.abrupt("return", syncResult);
2313
- case 20:
2314
- _context24.prev = 20;
2315
- _context24.t0 = _context24["catch"](11);
2316
- _context24.next = 24;
2464
+ amountSnapshot: amountSnapshot,
2465
+ orderSnapshot: orderSnapshot,
2466
+ isFullyPaid: syncResult.isFullyPaid,
2467
+ isOrderFullyPaid: syncResult.isOrderFullyPaid,
2468
+ isDepositFullyPaid: syncResult.isDepositFullyPaid,
2469
+ paymentStage: syncResult.paymentStage,
2470
+ depositAmount: syncResult.depositAmount,
2471
+ orderExpectedAmount: syncResult.orderExpectedAmount
2472
+ };
2473
+ _context26.next = 22;
2474
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, syncPayload);
2475
+ case 22:
2476
+ if (!(syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid)) {
2477
+ _context26.next = 25;
2478
+ break;
2479
+ }
2480
+ _context26.next = 25;
2481
+ return this.effectsEmit(BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
2482
+ case 25:
2483
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
2484
+ return _context26.abrupt("return", syncResult);
2485
+ case 29:
2486
+ _context26.prev = 29;
2487
+ _context26.t0 = _context26["catch"](12);
2488
+ _context26.next = 33;
2317
2489
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2318
2490
  ok: false,
2319
- error: _context24.t0,
2491
+ error: _context26.t0,
2320
2492
  payments: this.store.order.getOrderPayments(),
2321
2493
  params: syncParams,
2322
2494
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
2323
2495
  orderSnapshot: this.store.order.getOrderSnapshot()
2324
2496
  });
2325
- case 24:
2326
- throw _context24.t0;
2327
- case 25:
2497
+ case 33:
2498
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
2499
+ throw _context26.t0;
2500
+ case 35:
2328
2501
  case "end":
2329
- return _context24.stop();
2502
+ return _context26.stop();
2330
2503
  }
2331
- }, _callee24, this, [[11, 20]]);
2504
+ }, _callee26, this, [[12, 29]]);
2332
2505
  }));
2333
- function syncPaymentsToOrder(_x20) {
2506
+ function syncPaymentsToOrder(_x21) {
2334
2507
  return _syncPaymentsToOrder.apply(this, arguments);
2335
2508
  }
2336
2509
  return syncPaymentsToOrder;
@@ -2350,17 +2523,120 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2350
2523
  if (!this.store.order) throw new Error('order 模块未初始化');
2351
2524
  return this.store.order.setOrderPayments(payments);
2352
2525
  }
2353
-
2354
- /** 追加单个支付项到当前订单。 */
2526
+ }, {
2527
+ key: "getPaymentStatusForSync",
2528
+ value: function getPaymentStatusForSync(payments) {
2529
+ var order = this.store.order;
2530
+ if (!order) throw new Error('order 模块未初始化');
2531
+ var completion = order.getPaymentCompletion(payments);
2532
+ return completion.isOrderFullyPaid ? 'paid' : 'partially_paid';
2533
+ }
2534
+ }, {
2535
+ key: "queueLatestAutoPaymentSync",
2536
+ value: function queueLatestAutoPaymentSync() {
2537
+ this.queuedAutoPaymentSync = true;
2538
+ this.scheduleQueuedAutoPaymentSyncFlush();
2539
+ }
2540
+ }, {
2541
+ key: "scheduleQueuedAutoPaymentSyncFlush",
2542
+ value: function scheduleQueuedAutoPaymentSyncFlush() {
2543
+ var _this10 = this;
2544
+ var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
2545
+ if (!this.queuedAutoPaymentSync) return;
2546
+ if (this.autoPaymentSyncTimer) return;
2547
+ this.autoPaymentSyncTimer = setTimeout(function () {
2548
+ _this10.autoPaymentSyncTimer = null;
2549
+ void _this10.flushQueuedAutoPaymentSync();
2550
+ }, delay);
2551
+ }
2552
+ }, {
2553
+ key: "flushQueuedAutoPaymentSync",
2554
+ value: function () {
2555
+ var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2556
+ var payments;
2557
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2558
+ while (1) switch (_context27.prev = _context27.next) {
2559
+ case 0:
2560
+ if (this.store.order) {
2561
+ _context27.next = 2;
2562
+ break;
2563
+ }
2564
+ return _context27.abrupt("return");
2565
+ case 2:
2566
+ if (!(!this.queuedAutoPaymentSync || this.autoPaymentSyncFlushing)) {
2567
+ _context27.next = 4;
2568
+ break;
2569
+ }
2570
+ return _context27.abrupt("return");
2571
+ case 4:
2572
+ if (!(this.store.order.getOrderSyncState() === 'submitting')) {
2573
+ _context27.next = 7;
2574
+ break;
2575
+ }
2576
+ this.scheduleQueuedAutoPaymentSyncFlush();
2577
+ return _context27.abrupt("return");
2578
+ case 7:
2579
+ this.autoPaymentSyncFlushing = true;
2580
+ _context27.prev = 8;
2581
+ case 9:
2582
+ if (!this.queuedAutoPaymentSync) {
2583
+ _context27.next = 18;
2584
+ break;
2585
+ }
2586
+ this.queuedAutoPaymentSync = false;
2587
+ payments = this.store.order.getOrderPayments();
2588
+ if (payments.length) {
2589
+ _context27.next = 14;
2590
+ break;
2591
+ }
2592
+ return _context27.abrupt("continue", 9);
2593
+ case 14:
2594
+ _context27.next = 16;
2595
+ return this.syncPaymentsToOrder({
2596
+ payments: payments,
2597
+ paymentStatus: this.getPaymentStatusForSync(payments),
2598
+ submitWhenPaid: true,
2599
+ smallTicketDataFlag: 1
2600
+ });
2601
+ case 16:
2602
+ _context27.next = 9;
2603
+ break;
2604
+ case 18:
2605
+ _context27.next = 23;
2606
+ break;
2607
+ case 20:
2608
+ _context27.prev = 20;
2609
+ _context27.t0 = _context27["catch"](8);
2610
+ this.logError('queued auto sync payments failed', {
2611
+ error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0)
2612
+ });
2613
+ case 23:
2614
+ _context27.prev = 23;
2615
+ this.autoPaymentSyncFlushing = false;
2616
+ if (this.queuedAutoPaymentSync) {
2617
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
2618
+ }
2619
+ return _context27.finish(23);
2620
+ case 27:
2621
+ case "end":
2622
+ return _context27.stop();
2623
+ }
2624
+ }, _callee27, this, [[8, 20, 23, 27]]);
2625
+ }));
2626
+ function flushQueuedAutoPaymentSync() {
2627
+ return _flushQueuedAutoPaymentSync.apply(this, arguments);
2628
+ }
2629
+ return flushQueuedAutoPaymentSync;
2630
+ }() /** 追加单个支付项到当前订单。 */
2355
2631
  }, {
2356
2632
  key: "addOrderPayment",
2357
2633
  value: function addOrderPayment(payment) {
2358
2634
  var _this$otherParams20,
2359
2635
  _paymentRecord$paymen,
2360
2636
  _paymentRecord$create,
2361
- _ref19,
2637
+ _ref21,
2362
2638
  _paymentRecord$origin,
2363
- _this8 = this;
2639
+ _this11 = this;
2364
2640
  if (!this.store.order) throw new Error('order 模块未初始化');
2365
2641
  var paymentRecord = payment;
2366
2642
  var paymentAmount = new Decimal(paymentRecord.amount || 0);
@@ -2382,7 +2658,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2382
2658
  var paymentTime = (_paymentRecord$paymen = paymentRecord.payment_time) !== null && _paymentRecord$paymen !== void 0 ? _paymentRecord$paymen : paymentTimestamp;
2383
2659
  var createdAt = (_paymentRecord$create = paymentRecord.created_at) !== null && _paymentRecord$create !== void 0 ? _paymentRecord$create : paymentTimestamp;
2384
2660
  var serviceCharge = paymentRecord.service_charge && _typeof(paymentRecord.service_charge) === 'object' ? paymentRecord.service_charge : null;
2385
- var calculatedServiceFee = serviceCharge ? new Decimal((_ref19 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref19 !== void 0 ? _ref19 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
2661
+ var calculatedServiceFee = serviceCharge ? new Decimal((_ref21 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref21 !== void 0 ? _ref21 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
2386
2662
  var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, paymentRecord), calculatedServiceFee !== undefined ? {
2387
2663
  service_fee: calculatedServiceFee
2388
2664
  } : {}), {}, {
@@ -2392,19 +2668,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2392
2668
  }));
2393
2669
  var amountSnapshot = this.store.order.getOrderAmountSnapshot();
2394
2670
  var syncState = this.store.order.getOrderSyncState();
2395
- if (amountSnapshot && syncState !== 'submitting') {
2396
- var paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? 'paid' : 'partially_paid';
2671
+ if (amountSnapshot) {
2672
+ if (syncState === 'submitting') {
2673
+ this.queueLatestAutoPaymentSync();
2674
+ return payments;
2675
+ }
2397
2676
  void this.syncPaymentsToOrder({
2398
2677
  payments: payments,
2399
- paymentStatus: paymentStatus,
2678
+ paymentStatus: this.getPaymentStatusForSync(payments),
2400
2679
  submitWhenPaid: true,
2401
2680
  smallTicketDataFlag: 1
2402
2681
  }).catch(function (error) {
2403
- _this8.logError('auto sync payments failed', {
2682
+ _this11.logError('auto sync payments failed', {
2404
2683
  error: error instanceof Error ? error.message : String(error)
2405
2684
  });
2406
2685
  });
2407
- } else {}
2686
+ }
2408
2687
  return payments;
2409
2688
  }
2410
2689
 
@@ -2427,25 +2706,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2427
2706
  /** 覆盖 wallet pass 支付项,同时保留普通支付项。 */
2428
2707
  }, {
2429
2708
  key: "updateVoucherOrderPayments",
2430
- value: function updateVoucherOrderPayments(payments) {
2709
+ value: function updateVoucherOrderPayments(payments, options) {
2431
2710
  if (!this.store.order) throw new Error('order 模块未初始化');
2432
- return this.store.order.updateVoucherOrderPayments(payments);
2711
+ return this.store.order.updateVoucherOrderPayments(payments, options);
2712
+ }
2713
+ }, {
2714
+ key: "confirmPendingVoucherPayments",
2715
+ value: function confirmPendingVoucherPayments() {
2716
+ if (!this.store.order) throw new Error('order 模块未初始化');
2717
+ return this.store.order.confirmPendingVoucherPayments();
2718
+ }
2719
+ }, {
2720
+ key: "discardPendingVoucherPayments",
2721
+ value: function discardPendingVoucherPayments() {
2722
+ if (!this.store.order) throw new Error('order 模块未初始化');
2723
+ return this.store.order.discardPendingVoucherPayments();
2433
2724
  }
2434
2725
  }, {
2435
2726
  key: "getWalletProductList",
2436
2727
  value: function getWalletProductList() {
2437
- var _this$store$order5, _tempOrder$products, _tempOrder$products2;
2438
- var tempOrder = (_this$store$order5 = this.store.order) === null || _this$store$order5 === void 0 ? void 0 : _this$store$order5.getTempOrder();
2728
+ var _this$store$order6, _tempOrder$products;
2729
+ var tempOrder = (_this$store$order6 = this.store.order) === null || _this$store$order6 === void 0 ? void 0 : _this$store$order6.getTempOrder();
2439
2730
  if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$products = tempOrder.products) !== null && _tempOrder$products !== void 0 && _tempOrder$products.length)) return [];
2440
2731
  // 过滤出有 product_id的商品来,如果没有代表他是自定义商品,不需要参与 wallet
2441
- var products = tempOrder === null || tempOrder === void 0 || (_tempOrder$products2 = tempOrder.products) === null || _tempOrder$products2 === void 0 ? void 0 : _tempOrder$products2.filter(function (n) {
2442
- return n.product_id;
2443
- });
2444
- var walletProducts = products.map(function (product) {
2445
- var _product$product_vari2, _product$is_charge_ta, _product$holder_id, _metadata$main_produc, _metadata$main_produc2;
2732
+ // debugger
2733
+ // const products = tempOrder?.products?.filter(n => n.product_id)
2734
+
2735
+ var walletProducts = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.products.map(function (product) {
2736
+ var _product$holder_id, _product$product_vari2, _product$is_charge_ta, _metadata$main_produc, _metadata$main_produc2;
2446
2737
  var metadata = product.metadata || {};
2738
+ var rawHolderId = (_product$holder_id = product.holder_id) !== null && _product$holder_id !== void 0 ? _product$holder_id : metadata.holder_id;
2739
+ var holderIdValue = Array.isArray(rawHolderId) ? rawHolderId[0] : rawHolderId;
2740
+ var holder_id = Number.isInteger(Number(holderIdValue)) ? Number(holderIdValue) : undefined;
2447
2741
  return {
2448
- product_id: product.product_id,
2742
+ product_id: product.product_id || 0,
2449
2743
  product_variant_id: String((_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : ''),
2450
2744
  quantity: product.num || 1,
2451
2745
  is_price_include_tax: tempOrder.is_price_include_tax,
@@ -2453,7 +2747,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2453
2747
  tax_fee: product.tax_fee,
2454
2748
  selling_price: Number(product.selling_price || 0),
2455
2749
  discount_list: product.discount_list || [],
2456
- holder_id: (_product$holder_id = product.holder_id) !== null && _product$holder_id !== void 0 ? _product$holder_id : metadata.holder_id,
2750
+ holder_id: holder_id,
2457
2751
  original_price: product.original_price,
2458
2752
  main_product_original_price: (_metadata$main_produc = metadata.main_product_original_price) !== null && _metadata$main_produc !== void 0 ? _metadata$main_produc : product.original_price,
2459
2753
  main_product_selling_price: (_metadata$main_produc2 = metadata.main_product_selling_price) !== null && _metadata$main_produc2 !== void 0 ? _metadata$main_produc2 : product.selling_price,
@@ -2492,20 +2786,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2492
2786
  }, {
2493
2787
  key: "initWalletData",
2494
2788
  value: function () {
2495
- var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
2496
- var _params$order_wait_pa, _ref20, _tempOrder$is_price_i;
2789
+ var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2790
+ var _params$order_wait_pa, _ref22, _tempOrder$is_price_i;
2497
2791
  var snapshot, tempOrder, amount, walletBusinessData, result;
2498
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2499
- while (1) switch (_context25.prev = _context25.next) {
2792
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2793
+ while (1) switch (_context28.prev = _context28.next) {
2500
2794
  case 0:
2501
2795
  if (this.store.order) {
2502
- _context25.next = 2;
2796
+ _context28.next = 2;
2503
2797
  break;
2504
2798
  }
2505
2799
  throw new Error('order 模块未初始化');
2506
2800
  case 2:
2507
2801
  if (this.store.payment) {
2508
- _context25.next = 4;
2802
+ _context28.next = 4;
2509
2803
  break;
2510
2804
  }
2511
2805
  throw new Error('payment 模块未初始化');
@@ -2514,10 +2808,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2514
2808
  tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
2515
2809
  amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
2516
2810
  if (!(!tempOrder || !amount)) {
2517
- _context25.next = 9;
2811
+ _context28.next = 9;
2518
2812
  break;
2519
2813
  }
2520
- return _context25.abrupt("return", {
2814
+ return _context28.abrupt("return", {
2521
2815
  walletRecommendList: [],
2522
2816
  userIdentificationCodes: [],
2523
2817
  transformList: [],
@@ -2536,15 +2830,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2536
2830
  },
2537
2831
  products: this.getWalletProductList(),
2538
2832
  order_wait_pay_amount: (_params$order_wait_pa = params === null || params === void 0 ? void 0 : params.order_wait_pay_amount) !== null && _params$order_wait_pa !== void 0 ? _params$order_wait_pa : Number(amount.amountGap || 0),
2539
- is_price_include_tax: (_ref20 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref20 !== void 0 ? _ref20 : 1
2833
+ is_price_include_tax: (_ref22 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref22 !== void 0 ? _ref22 : 1
2540
2834
  }, snapshot.identity.orderId ? {
2541
2835
  payment_order_id: String(snapshot.identity.orderId)
2542
2836
  } : {});
2543
- _context25.next = 12;
2837
+ _context28.next = 12;
2544
2838
  return this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
2545
2839
  case 12:
2546
- result = _context25.sent;
2547
- _context25.next = 15;
2840
+ result = _context28.sent;
2841
+ _context28.next = 15;
2548
2842
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
2549
2843
  orderId: snapshot.identity.orderId,
2550
2844
  customerId: walletBusinessData.customer_id,
@@ -2556,14 +2850,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2556
2850
  timestamp: Date.now()
2557
2851
  });
2558
2852
  case 15:
2559
- return _context25.abrupt("return", result);
2853
+ return _context28.abrupt("return", result);
2560
2854
  case 16:
2561
2855
  case "end":
2562
- return _context25.stop();
2856
+ return _context28.stop();
2563
2857
  }
2564
- }, _callee25, this);
2858
+ }, _callee28, this);
2565
2859
  }));
2566
- function initWalletData(_x21) {
2860
+ function initWalletData(_x22) {
2567
2861
  return _initWalletData.apply(this, arguments);
2568
2862
  }
2569
2863
  return initWalletData;
@@ -2590,35 +2884,35 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2590
2884
  }, {
2591
2885
  key: "getPaymentMethodsAsync",
2592
2886
  value: (function () {
2593
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2887
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2594
2888
  var response, paymentMethods;
2595
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2596
- while (1) switch (_context26.prev = _context26.next) {
2889
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2890
+ while (1) switch (_context29.prev = _context29.next) {
2597
2891
  case 0:
2598
- _context26.prev = 0;
2599
- _context26.next = 3;
2892
+ _context29.prev = 0;
2893
+ _context29.next = 3;
2600
2894
  return this.request.get('/pay/custom-payment/all', {
2601
2895
  filterPaymentMethods: true
2602
2896
  }, {
2603
2897
  osServer: true
2604
2898
  });
2605
2899
  case 3:
2606
- response = _context26.sent;
2900
+ response = _context29.sent;
2607
2901
  paymentMethods = (response === null || response === void 0 ? void 0 : response.data) || [];
2608
2902
  this.paymentMethodsCache = Array.isArray(paymentMethods) ? _toConsumableArray(paymentMethods) : [];
2609
- return _context26.abrupt("return", this.getPaymentMethods());
2903
+ return _context29.abrupt("return", this.getPaymentMethods());
2610
2904
  case 9:
2611
- _context26.prev = 9;
2612
- _context26.t0 = _context26["catch"](0);
2905
+ _context29.prev = 9;
2906
+ _context29.t0 = _context29["catch"](0);
2613
2907
  this.logWarning('getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表', {
2614
- error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0)
2908
+ error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0)
2615
2909
  });
2616
- return _context26.abrupt("return", this.getPaymentMethods());
2910
+ return _context29.abrupt("return", this.getPaymentMethods());
2617
2911
  case 13:
2618
2912
  case "end":
2619
- return _context26.stop();
2913
+ return _context29.stop();
2620
2914
  }
2621
- }, _callee26, this, [[0, 9]]);
2915
+ }, _callee29, this, [[0, 9]]);
2622
2916
  }));
2623
2917
  function getPaymentMethodsAsync() {
2624
2918
  return _getPaymentMethodsAsync.apply(this, arguments);
@@ -2666,49 +2960,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2666
2960
  }, {
2667
2961
  key: "sendCustomerPayLink",
2668
2962
  value: (function () {
2669
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2670
- var orderIds, _ref21, _ref22, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
2671
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2672
- while (1) switch (_context27.prev = _context27.next) {
2963
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
2964
+ var orderIds, _ref23, _ref24, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
2965
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2966
+ while (1) switch (_context30.prev = _context30.next) {
2673
2967
  case 0:
2674
2968
  if (this.store.order) {
2675
- _context27.next = 2;
2969
+ _context30.next = 2;
2676
2970
  break;
2677
2971
  }
2678
2972
  throw new Error('order 模块未初始化');
2679
2973
  case 2:
2680
2974
  orderIds = params.order_ids || params.orderIds || [];
2681
2975
  if (!(!orderIds.length || params.submitBeforeSend)) {
2682
- _context27.next = 11;
2976
+ _context30.next = 11;
2683
2977
  break;
2684
2978
  }
2685
- _context27.next = 6;
2979
+ _context30.next = 6;
2686
2980
  return this.submitSalesOrder({
2687
2981
  smallTicketDataFlag: 1
2688
2982
  });
2689
2983
  case 6:
2690
- submitResult = _context27.sent;
2691
- orderId = (_ref21 = (_ref22 = (_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 && _ref22 !== void 0 ? _ref22 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref21 !== void 0 ? _ref21 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
2984
+ submitResult = _context30.sent;
2985
+ orderId = (_ref23 = (_ref24 = (_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 && _ref24 !== void 0 ? _ref24 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref23 !== void 0 ? _ref23 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
2692
2986
  if (orderId) {
2693
- _context27.next = 10;
2987
+ _context30.next = 10;
2694
2988
  break;
2695
2989
  }
2696
2990
  throw new Error('本地订单提交云端失败,无法发送支付链接');
2697
2991
  case 10:
2698
2992
  orderIds = [orderId];
2699
2993
  case 11:
2700
- return _context27.abrupt("return", this.store.order.sendCustomerPayLink({
2994
+ return _context30.abrupt("return", this.store.order.sendCustomerPayLink({
2701
2995
  emails: params.emails,
2702
2996
  notify_action: params.notify_action,
2703
2997
  order_ids: orderIds
2704
2998
  }));
2705
2999
  case 12:
2706
3000
  case "end":
2707
- return _context27.stop();
3001
+ return _context30.stop();
2708
3002
  }
2709
- }, _callee27, this);
3003
+ }, _callee30, this);
2710
3004
  }));
2711
- function sendCustomerPayLink(_x22) {
3005
+ function sendCustomerPayLink(_x23) {
2712
3006
  return _sendCustomerPayLink.apply(this, arguments);
2713
3007
  }
2714
3008
  return sendCustomerPayLink;
@@ -2721,27 +3015,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2721
3015
  }, {
2722
3016
  key: "calculateProductBookingPrice",
2723
3017
  value: function () {
2724
- var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
3018
+ var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
2725
3019
  var _params$customer_id;
2726
3020
  var quotation, customerId, authoritativeProduct, product;
2727
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2728
- while (1) switch (_context28.prev = _context28.next) {
3021
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
3022
+ while (1) switch (_context31.prev = _context31.next) {
2729
3023
  case 0:
2730
3024
  quotation = this.store.quotation;
2731
3025
  customerId = (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : this.getCurrentOrderCustomerId();
2732
- _context28.next = 4;
3026
+ _context31.next = 4;
2733
3027
  return this.loadProductForPriceQuery(params, customerId);
2734
3028
  case 4:
2735
- authoritativeProduct = _context28.sent;
3029
+ authoritativeProduct = _context31.sent;
2736
3030
  product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
2737
- _context28.next = 8;
3031
+ _context31.next = 8;
2738
3032
  return this.loadQuotationForPriceQuery({
2739
3033
  quotation: quotation,
2740
3034
  customer_id: customerId,
2741
3035
  channel: params.channel
2742
3036
  });
2743
3037
  case 8:
2744
- return _context28.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3038
+ return _context31.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
2745
3039
  product: product,
2746
3040
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
2747
3041
  customer_id: customerId,
@@ -2749,11 +3043,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2749
3043
  })));
2750
3044
  case 9:
2751
3045
  case "end":
2752
- return _context28.stop();
3046
+ return _context31.stop();
2753
3047
  }
2754
- }, _callee28, this);
3048
+ }, _callee31, this);
2755
3049
  }));
2756
- function calculateProductBookingPrice(_x23) {
3050
+ function calculateProductBookingPrice(_x24) {
2757
3051
  return _calculateProductBookingPrice.apply(this, arguments);
2758
3052
  }
2759
3053
  return calculateProductBookingPrice;
@@ -2761,7 +3055,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2761
3055
  }, {
2762
3056
  key: "getQuotationCustomerScopeInfo",
2763
3057
  value: function getQuotationCustomerScopeInfo() {
2764
- var _this9 = this;
3058
+ var _this12 = this;
2765
3059
  var quotation = this.store.quotation;
2766
3060
  if (quotation && typeof quotation.getQuotationCustomerScopeInfo === 'function') {
2767
3061
  return quotation.getQuotationCustomerScopeInfo();
@@ -2773,7 +3067,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2773
3067
  }).map(function (item) {
2774
3068
  var localSeen = new Set();
2775
3069
  var customers = item.customer.filter(function (customer) {
2776
- var customerId = _this9.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
3070
+ var customerId = _this12.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
2777
3071
  if (!customerId || localSeen.has(customerId)) return false;
2778
3072
  localSeen.add(customerId);
2779
3073
  if (!customerById.has(customerId)) customerById.set(customerId, customer);
@@ -2823,32 +3117,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2823
3117
  }, {
2824
3118
  key: "calculateProductBookingPrices",
2825
3119
  value: function () {
2826
- var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(paramsList) {
3120
+ var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(paramsList) {
2827
3121
  var _paramsList$0$custome,
2828
3122
  _paramsList$,
2829
- _this10 = this,
3123
+ _this13 = this,
2830
3124
  _paramsList$2;
2831
3125
  var quotation, customerId, productMapsByGroup, groups;
2832
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2833
- while (1) switch (_context30.prev = _context30.next) {
3126
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3127
+ while (1) switch (_context33.prev = _context33.next) {
2834
3128
  case 0:
2835
3129
  if (paramsList.length) {
2836
- _context30.next = 2;
3130
+ _context33.next = 2;
2837
3131
  break;
2838
3132
  }
2839
- return _context30.abrupt("return", []);
3133
+ return _context33.abrupt("return", []);
2840
3134
  case 2:
2841
3135
  quotation = this.store.quotation;
2842
3136
  customerId = (_paramsList$0$custome = (_paramsList$ = paramsList[0]) === null || _paramsList$ === void 0 ? void 0 : _paramsList$.customer_id) !== null && _paramsList$0$custome !== void 0 ? _paramsList$0$custome : this.getCurrentOrderCustomerId();
2843
3137
  productMapsByGroup = new Map();
2844
3138
  groups = new Map();
2845
3139
  paramsList.forEach(function (params) {
2846
- var _this10$otherParams;
3140
+ var _this13$otherParams;
2847
3141
  var product = params.product || {};
2848
- var productId = _this10.getPriceQueryProductId(product);
3142
+ var productId = _this13.getPriceQueryProductId(product);
2849
3143
  if (productId === null) return;
2850
- var schedule = _this10.getPriceQuerySchedule(params);
2851
- var channel = params.channel || ((_this10$otherParams = _this10.otherParams) === null || _this10$otherParams === void 0 ? void 0 : _this10$otherParams.channel);
3144
+ var schedule = _this13.getPriceQuerySchedule(params);
3145
+ var channel = params.channel || ((_this13$otherParams = _this13.otherParams) === null || _this13$otherParams === void 0 ? void 0 : _this13$otherParams.channel);
2852
3146
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
2853
3147
  var group = groups.get(groupKey) || {
2854
3148
  ids: new Set(),
@@ -2858,51 +3152,51 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2858
3152
  group.ids.add(productId);
2859
3153
  groups.set(groupKey, group);
2860
3154
  });
2861
- _context30.next = 9;
3155
+ _context33.next = 9;
2862
3156
  return Promise.all(Array.from(groups.entries()).map( /*#__PURE__*/function () {
2863
- var _ref24 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(_ref23) {
2864
- var _ref25, groupKey, group, productsById;
2865
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2866
- while (1) switch (_context29.prev = _context29.next) {
3157
+ var _ref26 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(_ref25) {
3158
+ var _ref27, groupKey, group, productsById;
3159
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3160
+ while (1) switch (_context32.prev = _context32.next) {
2867
3161
  case 0:
2868
- _ref25 = _slicedToArray(_ref23, 2), groupKey = _ref25[0], group = _ref25[1];
2869
- _context29.next = 3;
2870
- return _this10.loadProductsForPriceQuery({
3162
+ _ref27 = _slicedToArray(_ref25, 2), groupKey = _ref27[0], group = _ref27[1];
3163
+ _context32.next = 3;
3164
+ return _this13.loadProductsForPriceQuery({
2871
3165
  ids: Array.from(group.ids),
2872
3166
  schedule: group.schedule,
2873
3167
  customerId: customerId,
2874
3168
  channel: group.channel
2875
3169
  });
2876
3170
  case 3:
2877
- productsById = _context29.sent;
3171
+ productsById = _context32.sent;
2878
3172
  productMapsByGroup.set(groupKey, productsById);
2879
3173
  case 5:
2880
3174
  case "end":
2881
- return _context29.stop();
3175
+ return _context32.stop();
2882
3176
  }
2883
- }, _callee29);
3177
+ }, _callee32);
2884
3178
  }));
2885
- return function (_x25) {
2886
- return _ref24.apply(this, arguments);
3179
+ return function (_x26) {
3180
+ return _ref26.apply(this, arguments);
2887
3181
  };
2888
3182
  }()));
2889
3183
  case 9:
2890
- _context30.next = 11;
3184
+ _context33.next = 11;
2891
3185
  return this.loadQuotationForPriceQuery({
2892
3186
  quotation: quotation,
2893
3187
  customer_id: customerId,
2894
3188
  channel: (_paramsList$2 = paramsList[0]) === null || _paramsList$2 === void 0 ? void 0 : _paramsList$2.channel
2895
3189
  });
2896
3190
  case 11:
2897
- return _context30.abrupt("return", paramsList.map(function (params) {
2898
- var _this10$otherParams2, _productMapsByGroup$g;
3191
+ return _context33.abrupt("return", paramsList.map(function (params) {
3192
+ var _this13$otherParams2, _productMapsByGroup$g;
2899
3193
  var productInput = params.product || {};
2900
- var productId = _this10.getPriceQueryProductId(productInput);
2901
- var schedule = _this10.getPriceQuerySchedule(params);
2902
- var channel = params.channel || ((_this10$otherParams2 = _this10.otherParams) === null || _this10$otherParams2 === void 0 ? void 0 : _this10$otherParams2.channel);
3194
+ var productId = _this13.getPriceQueryProductId(productInput);
3195
+ var schedule = _this13.getPriceQuerySchedule(params);
3196
+ var channel = params.channel || ((_this13$otherParams2 = _this13.otherParams) === null || _this13$otherParams2 === void 0 ? void 0 : _this13$otherParams2.channel);
2903
3197
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
2904
3198
  var authoritativeProduct = productId === null ? null : ((_productMapsByGroup$g = productMapsByGroup.get(groupKey)) === null || _productMapsByGroup$g === void 0 ? void 0 : _productMapsByGroup$g.get(productId)) || null;
2905
- var product = _this10.mergeProductForPriceQuery(productInput, authoritativeProduct);
3199
+ var product = _this13.mergeProductForPriceQuery(productInput, authoritativeProduct);
2906
3200
  return calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
2907
3201
  product: product,
2908
3202
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
@@ -2912,11 +3206,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2912
3206
  }));
2913
3207
  case 12:
2914
3208
  case "end":
2915
- return _context30.stop();
3209
+ return _context33.stop();
2916
3210
  }
2917
- }, _callee30, this);
3211
+ }, _callee33, this);
2918
3212
  }));
2919
- function calculateProductBookingPrices(_x24) {
3213
+ function calculateProductBookingPrices(_x25) {
2920
3214
  return _calculateProductBookingPrices.apply(this, arguments);
2921
3215
  }
2922
3216
  return calculateProductBookingPrices;
@@ -2924,34 +3218,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2924
3218
  }, {
2925
3219
  key: "addProductToOrder",
2926
3220
  value: function () {
2927
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(product, booking) {
3221
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(product, booking) {
2928
3222
  var products;
2929
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2930
- while (1) switch (_context31.prev = _context31.next) {
3223
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3224
+ while (1) switch (_context34.prev = _context34.next) {
2931
3225
  case 0:
2932
- _context31.prev = 0;
3226
+ _context34.prev = 0;
2933
3227
  if (this.store.order) {
2934
- _context31.next = 3;
3228
+ _context34.next = 3;
2935
3229
  break;
2936
3230
  }
2937
3231
  throw new Error('order 模块未初始化');
2938
3232
  case 3:
2939
- _context31.next = 5;
3233
+ _context34.next = 5;
2940
3234
  return this.store.order.addProductToOrder(product, booking);
2941
3235
  case 5:
2942
- products = _context31.sent;
2943
- return _context31.abrupt("return", products);
3236
+ products = _context34.sent;
3237
+ return _context34.abrupt("return", products);
2944
3238
  case 9:
2945
- _context31.prev = 9;
2946
- _context31.t0 = _context31["catch"](0);
2947
- throw _context31.t0;
3239
+ _context34.prev = 9;
3240
+ _context34.t0 = _context34["catch"](0);
3241
+ throw _context34.t0;
2948
3242
  case 12:
2949
3243
  case "end":
2950
- return _context31.stop();
3244
+ return _context34.stop();
2951
3245
  }
2952
- }, _callee31, this, [[0, 9]]);
3246
+ }, _callee34, this, [[0, 9]]);
2953
3247
  }));
2954
- function addProductToOrder(_x26, _x27) {
3248
+ function addProductToOrder(_x27, _x28) {
2955
3249
  return _addProductToOrder.apply(this, arguments);
2956
3250
  }
2957
3251
  return addProductToOrder;
@@ -2959,34 +3253,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2959
3253
  }, {
2960
3254
  key: "updateOrderProduct",
2961
3255
  value: function () {
2962
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
3256
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
2963
3257
  var products;
2964
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2965
- while (1) switch (_context32.prev = _context32.next) {
3258
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3259
+ while (1) switch (_context35.prev = _context35.next) {
2966
3260
  case 0:
2967
- _context32.prev = 0;
3261
+ _context35.prev = 0;
2968
3262
  if (this.store.order) {
2969
- _context32.next = 3;
3263
+ _context35.next = 3;
2970
3264
  break;
2971
3265
  }
2972
3266
  throw new Error('order 模块未初始化');
2973
3267
  case 3:
2974
- _context32.next = 5;
3268
+ _context35.next = 5;
2975
3269
  return this.store.order.updateOrderProduct(params);
2976
3270
  case 5:
2977
- products = _context32.sent;
2978
- return _context32.abrupt("return", products);
3271
+ products = _context35.sent;
3272
+ return _context35.abrupt("return", products);
2979
3273
  case 9:
2980
- _context32.prev = 9;
2981
- _context32.t0 = _context32["catch"](0);
2982
- throw _context32.t0;
3274
+ _context35.prev = 9;
3275
+ _context35.t0 = _context35["catch"](0);
3276
+ throw _context35.t0;
2983
3277
  case 12:
2984
3278
  case "end":
2985
- return _context32.stop();
3279
+ return _context35.stop();
2986
3280
  }
2987
- }, _callee32, this, [[0, 9]]);
3281
+ }, _callee35, this, [[0, 9]]);
2988
3282
  }));
2989
- function updateOrderProduct(_x28) {
3283
+ function updateOrderProduct(_x29) {
2990
3284
  return _updateOrderProduct.apply(this, arguments);
2991
3285
  }
2992
3286
  return updateOrderProduct;
@@ -2994,34 +3288,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2994
3288
  }, {
2995
3289
  key: "updateOrderProducts",
2996
3290
  value: function () {
2997
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(paramsList) {
3291
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(paramsList) {
2998
3292
  var products;
2999
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3000
- while (1) switch (_context33.prev = _context33.next) {
3293
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3294
+ while (1) switch (_context36.prev = _context36.next) {
3001
3295
  case 0:
3002
- _context33.prev = 0;
3296
+ _context36.prev = 0;
3003
3297
  if (this.store.order) {
3004
- _context33.next = 3;
3298
+ _context36.next = 3;
3005
3299
  break;
3006
3300
  }
3007
3301
  throw new Error('order 模块未初始化');
3008
3302
  case 3:
3009
- _context33.next = 5;
3303
+ _context36.next = 5;
3010
3304
  return this.store.order.updateOrderProducts(paramsList);
3011
3305
  case 5:
3012
- products = _context33.sent;
3013
- return _context33.abrupt("return", products);
3306
+ products = _context36.sent;
3307
+ return _context36.abrupt("return", products);
3014
3308
  case 9:
3015
- _context33.prev = 9;
3016
- _context33.t0 = _context33["catch"](0);
3017
- throw _context33.t0;
3309
+ _context36.prev = 9;
3310
+ _context36.t0 = _context36["catch"](0);
3311
+ throw _context36.t0;
3018
3312
  case 12:
3019
3313
  case "end":
3020
- return _context33.stop();
3314
+ return _context36.stop();
3021
3315
  }
3022
- }, _callee33, this, [[0, 9]]);
3316
+ }, _callee36, this, [[0, 9]]);
3023
3317
  }));
3024
- function updateOrderProducts(_x29) {
3318
+ function updateOrderProducts(_x30) {
3025
3319
  return _updateOrderProducts.apply(this, arguments);
3026
3320
  }
3027
3321
  return updateOrderProducts;
@@ -3029,34 +3323,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3029
3323
  }, {
3030
3324
  key: "updateOrderProductQuantity",
3031
3325
  value: function () {
3032
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
3326
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
3033
3327
  var products;
3034
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3035
- while (1) switch (_context34.prev = _context34.next) {
3328
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3329
+ while (1) switch (_context37.prev = _context37.next) {
3036
3330
  case 0:
3037
- _context34.prev = 0;
3331
+ _context37.prev = 0;
3038
3332
  if (this.store.order) {
3039
- _context34.next = 3;
3333
+ _context37.next = 3;
3040
3334
  break;
3041
3335
  }
3042
3336
  throw new Error('order 模块未初始化');
3043
3337
  case 3:
3044
- _context34.next = 5;
3338
+ _context37.next = 5;
3045
3339
  return this.store.order.updateOrderProductQuantity(params);
3046
3340
  case 5:
3047
- products = _context34.sent;
3048
- return _context34.abrupt("return", products);
3341
+ products = _context37.sent;
3342
+ return _context37.abrupt("return", products);
3049
3343
  case 9:
3050
- _context34.prev = 9;
3051
- _context34.t0 = _context34["catch"](0);
3052
- throw _context34.t0;
3344
+ _context37.prev = 9;
3345
+ _context37.t0 = _context37["catch"](0);
3346
+ throw _context37.t0;
3053
3347
  case 12:
3054
3348
  case "end":
3055
- return _context34.stop();
3349
+ return _context37.stop();
3056
3350
  }
3057
- }, _callee34, this, [[0, 9]]);
3351
+ }, _callee37, this, [[0, 9]]);
3058
3352
  }));
3059
- function updateOrderProductQuantity(_x30) {
3353
+ function updateOrderProductQuantity(_x31) {
3060
3354
  return _updateOrderProductQuantity.apply(this, arguments);
3061
3355
  }
3062
3356
  return updateOrderProductQuantity;
@@ -3079,12 +3373,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3079
3373
  }, {
3080
3374
  key: "setOrderProductLineNote",
3081
3375
  value: (function () {
3082
- var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(identity, note) {
3376
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(identity, note) {
3083
3377
  var params, products;
3084
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3085
- while (1) switch (_context35.prev = _context35.next) {
3378
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3379
+ while (1) switch (_context38.prev = _context38.next) {
3086
3380
  case 0:
3087
- _context35.prev = 0;
3381
+ _context38.prev = 0;
3088
3382
  params = {
3089
3383
  product_id: identity.product_id,
3090
3384
  product_variant_id: identity.product_variant_id,
@@ -3099,22 +3393,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3099
3393
  params.product_sku = identity.product_sku;
3100
3394
  }
3101
3395
  if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
3102
- _context35.next = 7;
3396
+ _context38.next = 7;
3103
3397
  return this.updateOrderProduct(params);
3104
3398
  case 7:
3105
- products = _context35.sent;
3106
- return _context35.abrupt("return", products);
3399
+ products = _context38.sent;
3400
+ return _context38.abrupt("return", products);
3107
3401
  case 11:
3108
- _context35.prev = 11;
3109
- _context35.t0 = _context35["catch"](0);
3110
- throw _context35.t0;
3402
+ _context38.prev = 11;
3403
+ _context38.t0 = _context38["catch"](0);
3404
+ throw _context38.t0;
3111
3405
  case 14:
3112
3406
  case "end":
3113
- return _context35.stop();
3407
+ return _context38.stop();
3114
3408
  }
3115
- }, _callee35, this, [[0, 11]]);
3409
+ }, _callee38, this, [[0, 11]]);
3116
3410
  }));
3117
- function setOrderProductLineNote(_x31, _x32) {
3411
+ function setOrderProductLineNote(_x32, _x33) {
3118
3412
  return _setOrderProductLineNote.apply(this, arguments);
3119
3413
  }
3120
3414
  return setOrderProductLineNote;
@@ -3129,32 +3423,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3129
3423
  }, {
3130
3424
  key: "removeProductsFromOrder",
3131
3425
  value: (function () {
3132
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(identities) {
3133
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3134
- while (1) switch (_context36.prev = _context36.next) {
3426
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(identities) {
3427
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3428
+ while (1) switch (_context39.prev = _context39.next) {
3135
3429
  case 0:
3136
- _context36.prev = 0;
3430
+ _context39.prev = 0;
3137
3431
  if (this.store.order) {
3138
- _context36.next = 3;
3432
+ _context39.next = 3;
3139
3433
  break;
3140
3434
  }
3141
3435
  throw new Error('order 模块未初始化');
3142
3436
  case 3:
3143
- _context36.next = 5;
3437
+ _context39.next = 5;
3144
3438
  return this.store.order.removeProductsFromOrder(identities);
3145
3439
  case 5:
3146
- return _context36.abrupt("return", _context36.sent);
3440
+ return _context39.abrupt("return", _context39.sent);
3147
3441
  case 8:
3148
- _context36.prev = 8;
3149
- _context36.t0 = _context36["catch"](0);
3150
- throw _context36.t0;
3442
+ _context39.prev = 8;
3443
+ _context39.t0 = _context39["catch"](0);
3444
+ throw _context39.t0;
3151
3445
  case 11:
3152
3446
  case "end":
3153
- return _context36.stop();
3447
+ return _context39.stop();
3154
3448
  }
3155
- }, _callee36, this, [[0, 8]]);
3449
+ }, _callee39, this, [[0, 8]]);
3156
3450
  }));
3157
- function removeProductsFromOrder(_x33) {
3451
+ function removeProductsFromOrder(_x34) {
3158
3452
  return _removeProductsFromOrder.apply(this, arguments);
3159
3453
  }
3160
3454
  return removeProductsFromOrder;
@@ -3162,18 +3456,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3162
3456
  }, {
3163
3457
  key: "removeProductFromOrder",
3164
3458
  value: function () {
3165
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(identity) {
3166
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3167
- while (1) switch (_context37.prev = _context37.next) {
3459
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(identity) {
3460
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3461
+ while (1) switch (_context40.prev = _context40.next) {
3168
3462
  case 0:
3169
- return _context37.abrupt("return", this.removeProductsFromOrder([identity]));
3463
+ return _context40.abrupt("return", this.removeProductsFromOrder([identity]));
3170
3464
  case 1:
3171
3465
  case "end":
3172
- return _context37.stop();
3466
+ return _context40.stop();
3173
3467
  }
3174
- }, _callee37, this);
3468
+ }, _callee40, this);
3175
3469
  }));
3176
- function removeProductFromOrder(_x34) {
3470
+ function removeProductFromOrder(_x35) {
3177
3471
  return _removeProductFromOrder.apply(this, arguments);
3178
3472
  }
3179
3473
  return removeProductFromOrder;
@@ -3223,23 +3517,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3223
3517
  }, {
3224
3518
  key: "applyPromotion",
3225
3519
  value: (function () {
3226
- var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
3227
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3228
- while (1) switch (_context38.prev = _context38.next) {
3520
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3521
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3522
+ while (1) switch (_context41.prev = _context41.next) {
3229
3523
  case 0:
3230
3524
  if (this.store.order) {
3231
- _context38.next = 2;
3525
+ _context41.next = 2;
3232
3526
  break;
3233
3527
  }
3234
3528
  throw new Error('order 模块未初始化');
3235
3529
  case 2:
3236
- _context38.next = 4;
3530
+ _context41.next = 4;
3237
3531
  return this.store.order.applyPromotion();
3238
3532
  case 4:
3239
3533
  case "end":
3240
- return _context38.stop();
3534
+ return _context41.stop();
3241
3535
  }
3242
- }, _callee38, this);
3536
+ }, _callee41, this);
3243
3537
  }));
3244
3538
  function applyPromotion() {
3245
3539
  return _applyPromotion.apply(this, arguments);
@@ -3249,16 +3543,16 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3249
3543
  }, {
3250
3544
  key: "getUnfulfilledPromotions",
3251
3545
  value: function getUnfulfilledPromotions() {
3252
- var _this$store$order6;
3253
- return ((_this$store$order6 = this.store.order) === null || _this$store$order6 === void 0 ? void 0 : _this$store$order6.getUnfulfilledPromotions()) || [];
3546
+ var _this$store$order7;
3547
+ return ((_this$store$order7 = this.store.order) === null || _this$store$order7 === void 0 ? void 0 : _this$store$order7.getUnfulfilledPromotions()) || [];
3254
3548
  }
3255
3549
 
3256
3550
  /** 最近一次促销计算输出的赠品操作 diff。 */
3257
3551
  }, {
3258
3552
  key: "getLastGiftActions",
3259
3553
  value: function getLastGiftActions() {
3260
- var _this$store$order7;
3261
- return ((_this$store$order7 = this.store.order) === null || _this$store$order7 === void 0 ? void 0 : _this$store$order7.getLastGiftActions()) || null;
3554
+ var _this$store$order8;
3555
+ return ((_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 ? void 0 : _this$store$order8.getLastGiftActions()) || null;
3262
3556
  }
3263
3557
 
3264
3558
  // 获取商品列表
@@ -3266,18 +3560,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3266
3560
  }, {
3267
3561
  key: "getProductList",
3268
3562
  value: function () {
3269
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3563
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3270
3564
  var _this$otherParams21;
3271
3565
  var menu_list_ids, _this$store$products, res;
3272
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3273
- while (1) switch (_context39.prev = _context39.next) {
3566
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3567
+ while (1) switch (_context42.prev = _context42.next) {
3274
3568
  case 0:
3275
3569
  // 可以直接通过配置里的 menu 读取
3276
3570
  menu_list_ids = ((_this$otherParams21 = this.otherParams) === null || _this$otherParams21 === void 0 || (_this$otherParams21 = _this$otherParams21.dineInConfig) === null || _this$otherParams21 === void 0 ? void 0 : _this$otherParams21['menu.associated_menus'].map(function (n) {
3277
3571
  return Number(n.value);
3278
3572
  })) || [];
3279
- _context39.prev = 1;
3280
- _context39.next = 4;
3573
+ _context42.prev = 1;
3574
+ _context42.next = 4;
3281
3575
  return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
3282
3576
  menu_list_ids: menu_list_ids,
3283
3577
  cacheId: this.cacheId,
@@ -3285,17 +3579,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3285
3579
  schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
3286
3580
  });
3287
3581
  case 4:
3288
- res = _context39.sent;
3289
- return _context39.abrupt("return", res);
3582
+ res = _context42.sent;
3583
+ return _context42.abrupt("return", res);
3290
3584
  case 8:
3291
- _context39.prev = 8;
3292
- _context39.t0 = _context39["catch"](1);
3293
- throw _context39.t0;
3585
+ _context42.prev = 8;
3586
+ _context42.t0 = _context42["catch"](1);
3587
+ throw _context42.t0;
3294
3588
  case 11:
3295
3589
  case "end":
3296
- return _context39.stop();
3590
+ return _context42.stop();
3297
3591
  }
3298
- }, _callee39, this, [[1, 8]]);
3592
+ }, _callee42, this, [[1, 8]]);
3299
3593
  }));
3300
3594
  function getProductList() {
3301
3595
  return _getProductList.apply(this, arguments);
@@ -3310,33 +3604,33 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3310
3604
  }, {
3311
3605
  key: "setOtherParams",
3312
3606
  value: function () {
3313
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3607
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
3314
3608
  var _this$otherParams22;
3315
- var _ref26,
3316
- _ref26$cover,
3609
+ var _ref28,
3610
+ _ref28$cover,
3317
3611
  cover,
3318
- _args40 = arguments;
3319
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3320
- while (1) switch (_context40.prev = _context40.next) {
3612
+ _args43 = arguments;
3613
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3614
+ while (1) switch (_context43.prev = _context43.next) {
3321
3615
  case 0:
3322
- _ref26 = _args40.length > 1 && _args40[1] !== undefined ? _args40[1] : {}, _ref26$cover = _ref26.cover, cover = _ref26$cover === void 0 ? false : _ref26$cover;
3616
+ _ref28 = _args43.length > 1 && _args43[1] !== undefined ? _args43[1] : {}, _ref28$cover = _ref28.cover, cover = _ref28$cover === void 0 ? false : _ref28$cover;
3323
3617
  if (cover) {
3324
3618
  this.otherParams = _objectSpread({}, params);
3325
3619
  } else {
3326
3620
  this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
3327
3621
  }
3328
3622
  this.cacheId = (_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22.cacheId;
3329
- _context40.next = 5;
3623
+ _context43.next = 5;
3330
3624
  return this.syncOtherParamsToSubModules(params, {
3331
3625
  cover: cover
3332
3626
  });
3333
3627
  case 5:
3334
3628
  case "end":
3335
- return _context40.stop();
3629
+ return _context43.stop();
3336
3630
  }
3337
- }, _callee40, this);
3631
+ }, _callee43, this);
3338
3632
  }));
3339
- function setOtherParams(_x35) {
3633
+ function setOtherParams(_x36) {
3340
3634
  return _setOtherParams.apply(this, arguments);
3341
3635
  }
3342
3636
  return setOtherParams;