@pisell/pisellos 2.2.260 → 2.2.262

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 (107) hide show
  1. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +1 -0
  2. package/dist/model/strategy/adapter/dataVariant/adapter.js +15 -0
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +2 -0
  4. package/dist/model/strategy/adapter/dataVariant/evaluator.js +25 -0
  5. package/dist/model/strategy/adapter/dataVariant/examples.js +1 -6
  6. package/dist/model/strategy/adapter/dataVariant/type.d.ts +2 -0
  7. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  8. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +23 -13
  9. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  11. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
  12. package/dist/modules/Discount/index.d.ts +5 -2
  13. package/dist/modules/Discount/index.js +30 -7
  14. package/dist/modules/Discount/types.d.ts +4 -0
  15. package/dist/modules/Order/index.d.ts +45 -2
  16. package/dist/modules/Order/index.js +1552 -926
  17. package/dist/modules/Order/types.d.ts +36 -2
  18. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  19. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  20. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  21. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  22. package/dist/modules/Order/utils.d.ts +8 -3
  23. package/dist/modules/Order/utils.js +136 -56
  24. package/dist/modules/Rules/index.d.ts +4 -10
  25. package/dist/modules/Rules/index.js +63 -12
  26. package/dist/modules/Rules/types.d.ts +12 -2
  27. package/dist/modules/SalesSummary/index.d.ts +7 -3
  28. package/dist/modules/SalesSummary/index.js +67 -39
  29. package/dist/modules/SalesSummary/types.d.ts +1 -0
  30. package/dist/modules/SalesSummary/utils.js +2 -1
  31. package/dist/modules/SurchargeList/index.d.ts +6 -4
  32. package/dist/modules/SurchargeList/index.js +62 -39
  33. package/dist/modules/SurchargeList/types.d.ts +6 -2
  34. package/dist/server/index.d.ts +8 -0
  35. package/dist/server/index.js +1365 -911
  36. package/dist/server/modules/order/index.d.ts +32 -7
  37. package/dist/server/modules/order/index.js +551 -464
  38. package/dist/server/modules/order/types.d.ts +4 -0
  39. package/dist/server/modules/products/index.d.ts +5 -1
  40. package/dist/server/modules/products/index.js +384 -315
  41. package/dist/server/modules/products/types.d.ts +4 -0
  42. package/dist/solution/BaseSales/index.d.ts +42 -2
  43. package/dist/solution/BaseSales/index.js +1416 -775
  44. package/dist/solution/BaseSales/types.d.ts +7 -1
  45. package/dist/solution/BaseSales/types.js +3 -2
  46. package/dist/solution/BaseSales/utils/cartPromotion.js +19 -7
  47. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  48. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  49. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +20 -4
  50. package/dist/solution/BookingByStep/index.d.ts +1 -1
  51. package/dist/solution/BookingTicket/index.d.ts +8 -0
  52. package/dist/solution/BookingTicket/index.js +212 -31
  53. package/dist/solution/ShopDiscount/index.js +15 -14
  54. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +1 -0
  55. package/lib/model/strategy/adapter/dataVariant/adapter.js +10 -0
  56. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +2 -0
  57. package/lib/model/strategy/adapter/dataVariant/evaluator.js +20 -1
  58. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -2
  59. package/lib/model/strategy/adapter/dataVariant/type.d.ts +2 -0
  60. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  61. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -1
  62. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
  63. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  64. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
  65. package/lib/modules/Discount/index.d.ts +5 -2
  66. package/lib/modules/Discount/index.js +23 -3
  67. package/lib/modules/Discount/types.d.ts +4 -0
  68. package/lib/modules/Order/index.d.ts +45 -2
  69. package/lib/modules/Order/index.js +720 -116
  70. package/lib/modules/Order/types.d.ts +36 -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/orderCollectionIdentity.d.ts +53 -0
  74. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  75. package/lib/modules/Order/utils.d.ts +8 -3
  76. package/lib/modules/Order/utils.js +104 -18
  77. package/lib/modules/Rules/index.d.ts +4 -10
  78. package/lib/modules/Rules/index.js +61 -9
  79. package/lib/modules/Rules/types.d.ts +12 -2
  80. package/lib/modules/SalesSummary/index.d.ts +7 -3
  81. package/lib/modules/SalesSummary/index.js +28 -11
  82. package/lib/modules/SalesSummary/types.d.ts +1 -0
  83. package/lib/modules/SalesSummary/utils.js +2 -0
  84. package/lib/modules/SurchargeList/index.d.ts +6 -4
  85. package/lib/modules/SurchargeList/index.js +41 -21
  86. package/lib/modules/SurchargeList/types.d.ts +6 -2
  87. package/lib/server/index.d.ts +8 -0
  88. package/lib/server/index.js +336 -11
  89. package/lib/server/modules/order/index.d.ts +32 -7
  90. package/lib/server/modules/order/index.js +298 -189
  91. package/lib/server/modules/order/types.d.ts +4 -0
  92. package/lib/server/modules/products/index.d.ts +5 -1
  93. package/lib/server/modules/products/index.js +21 -0
  94. package/lib/server/modules/products/types.d.ts +4 -0
  95. package/lib/solution/BaseSales/index.d.ts +42 -2
  96. package/lib/solution/BaseSales/index.js +535 -108
  97. package/lib/solution/BaseSales/types.d.ts +7 -1
  98. package/lib/solution/BaseSales/types.js +2 -1
  99. package/lib/solution/BaseSales/utils/cartPromotion.js +13 -1
  100. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  101. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  102. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -6
  103. package/lib/solution/BookingByStep/index.d.ts +1 -1
  104. package/lib/solution/BookingTicket/index.d.ts +8 -0
  105. package/lib/solution/BookingTicket/index.js +134 -8
  106. package/lib/solution/ShopDiscount/index.js +2 -1
  107. package/package.json +1 -1
@@ -1,14 +1,10 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
2
  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
3
  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
4
  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); }
7
5
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
8
6
  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
7
  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
8
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
9
  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
10
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -21,27 +17,33 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
21
17
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
22
18
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
23
19
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
24
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
26
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
27
20
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
28
21
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
29
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
30
22
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
31
23
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
24
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
25
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
32
26
  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; }
27
+ 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; }
28
+ 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; }
29
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
30
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
31
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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
+ import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollection, normalizeOrderCollections, setOrderCollectionUid } from "../../modules/Order/utils/orderCollectionIdentity";
40
41
  import dayjs from 'dayjs';
41
42
  export * from "./types";
42
43
  import { QuotationModule } from "../../modules/Quotation";
43
44
  import { transformBaseProductToOrderProduct as _transformBaseProductToOrderProduct } from "./utils/transformBaseProductToOrderProduct";
44
45
  import { calculateBaseSalesProductBookingPrice } from "./utils/quotationPrice";
46
+ var SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
45
47
  function isBaseSalesManualProductDiscountProduct(product) {
46
48
  var _product$metadata, _product$metadata2;
47
49
  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) {
@@ -70,47 +72,140 @@ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
70
72
  function isBaseSalesHistoricalDiscountEntry(discount) {
71
73
  return Boolean((discount === null || discount === void 0 ? void 0 : discount.isEditMode) || (discount === null || discount === void 0 ? void 0 : discount.isDisabled) || (discount === null || discount === void 0 ? void 0 : discount.order_discount_id) != null);
72
74
  }
73
- function getBaseSalesUniqueArrayMetadataKey(key) {
74
- if (key === 'products' || key === 'bookings') return 'unique_identification_number';
75
- if (key === 'payments' || key === 'payment') return 'unique_payment_number';
75
+ var BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND = {
76
+ product: 'order_detail_id',
77
+ booking: 'schedule_event_id',
78
+ payment: 'order_payment_id'
79
+ };
80
+ function getBaseSalesOrderCollectionKind(key) {
81
+ if (key === 'products') return 'product';
82
+ if (key === 'bookings') return 'booking';
83
+ if (key === 'payments' || key === 'payment') return 'payment';
76
84
  return null;
77
85
  }
78
- function getBaseSalesMetadataUid(item, metadataKey) {
79
- var _item$metadata$metada, _item$metadata;
80
- 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];
81
- if (uid === undefined || uid === null || uid === '') return null;
82
- return String(uid);
86
+ function isSameBaseSalesOrderRecord(left, right) {
87
+ if (!left || !right || _typeof(left) !== 'object' || _typeof(right) !== 'object') return false;
88
+ var leftIdentities = new Set([left.order_id, left.id, left.external_sale_number, left.order_number].filter(function (value) {
89
+ return value !== undefined && value !== null && value !== '';
90
+ }).map(String));
91
+ if (leftIdentities.size === 0) return false;
92
+ return [right.order_id, right.id, right.external_sale_number, right.order_number].some(function (value) {
93
+ return value !== undefined && value !== null && value !== '' && leftIdentities.has(String(value));
94
+ });
83
95
  }
84
- function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
85
- var result = [];
86
- var indexByUid = new Map();
87
- var appendOrReplaceByUid = function appendOrReplaceByUid(item) {
88
- var clonedItem = cloneDeep(item);
89
- var uid = getBaseSalesMetadataUid(clonedItem, metadataKey);
90
- if (!uid) {
91
- result.push(clonedItem);
92
- return;
96
+ function isBaseSalesBlankValue(value) {
97
+ return value === undefined || value === null || value === '';
98
+ }
99
+ function mergeBaseSalesProductSnapshotFields(currentItem, loadedItem) {
100
+ var _currentItem$metadata, _mergedItem$metadata, _mergedItem$metadata2;
101
+ var mergedItem = cloneDeep(loadedItem);
102
+ if (isBaseSalesBlankValue(mergedItem.product_cover) && !isBaseSalesBlankValue(currentItem === null || currentItem === void 0 ? void 0 : currentItem.product_cover)) {
103
+ mergedItem.product_cover = currentItem.product_cover;
104
+ }
105
+ var currentHolderConfig = currentItem === null || currentItem === void 0 || (_currentItem$metadata = currentItem.metadata) === null || _currentItem$metadata === void 0 ? void 0 : _currentItem$metadata.holder_config;
106
+ if ((((_mergedItem$metadata = mergedItem.metadata) === null || _mergedItem$metadata === void 0 ? void 0 : _mergedItem$metadata.holder_config) === undefined || ((_mergedItem$metadata2 = mergedItem.metadata) === null || _mergedItem$metadata2 === void 0 ? void 0 : _mergedItem$metadata2.holder_config) === null) && currentHolderConfig !== undefined && currentHolderConfig !== null) {
107
+ mergedItem.metadata = _objectSpread(_objectSpread({}, mergedItem.metadata || {}), {}, {
108
+ holder_config: currentHolderConfig
109
+ });
110
+ }
111
+ return mergedItem;
112
+ }
113
+ function mergeBaseSalesCollectionItem(kind, currentItem, incomingItem, uidRemaps) {
114
+ var currentReferenceUid = getOrderCollectionReferenceUid(kind, currentItem);
115
+ var incomingReferenceUid = getOrderCollectionReferenceUid(kind, incomingItem);
116
+ var identityMergedItem = mergeOrderCollectionItems(kind, currentItem, incomingItem);
117
+ var mergedUid = getOrderCollectionUid(kind, identityMergedItem);
118
+ if (mergedUid) {
119
+ var _iterator = _createForOfIteratorHelper(new Set([currentReferenceUid, incomingReferenceUid])),
120
+ _step;
121
+ try {
122
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
123
+ var from = _step.value;
124
+ if (!from || from === mergedUid) continue;
125
+ uidRemaps.push({
126
+ kind: kind,
127
+ from: from,
128
+ to: mergedUid,
129
+ persistentId: getOrderCollectionPersistentId(kind, incomingItem) || getOrderCollectionPersistentId(kind, currentItem)
130
+ });
131
+ }
132
+ } catch (err) {
133
+ _iterator.e(err);
134
+ } finally {
135
+ _iterator.f();
93
136
  }
94
- var existingIndex = indexByUid.get(uid);
95
- if (existingIndex !== undefined) {
96
- result[existingIndex] = clonedItem;
137
+ }
138
+ var mergedItem = mergedUid ? setOrderCollectionUid(kind, incomingItem, mergedUid) : cloneDeep(incomingItem);
139
+ var persistentIdField = BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND[kind];
140
+ if (isBaseSalesBlankValue(mergedItem[persistentIdField]) && !isBaseSalesBlankValue(identityMergedItem[persistentIdField])) {
141
+ mergedItem[persistentIdField] = identityMergedItem[persistentIdField];
142
+ }
143
+ return kind === 'product' ? mergeBaseSalesProductSnapshotFields(currentItem, mergedItem) : mergedItem;
144
+ }
145
+ function mergeBaseSalesOrderCollection(kind, currentValue, incomingValue, strategy, uidRemaps) {
146
+ var currentItems = normalizeOrderCollection(kind, currentValue, {
147
+ ensureUid: false
148
+ }).items;
149
+ var incomingItems = normalizeOrderCollection(kind, incomingValue, {
150
+ ensureUid: false
151
+ }).items;
152
+ if (strategy === 'authoritative-incoming') {
153
+ var _result = cloneDeep(incomingItems);
154
+ currentItems.forEach(function (currentItem) {
155
+ var incomingIndex = _result.findIndex(function (incomingItem) {
156
+ return isSameOrderCollectionItem(kind, currentItem, incomingItem);
157
+ });
158
+ if (incomingIndex !== -1) {
159
+ _result[incomingIndex] = mergeBaseSalesCollectionItem(kind, currentItem, _result[incomingIndex], uidRemaps);
160
+ return;
161
+ }
162
+
163
+ // 完整服务端快照负责已落库行;仅保留尚未提交的本地新行。
164
+ if (!getOrderCollectionPersistentId(kind, currentItem)) {
165
+ _result.push(cloneDeep(currentItem));
166
+ }
167
+ });
168
+ return _result;
169
+ }
170
+ var result = cloneDeep(currentItems);
171
+ incomingItems.forEach(function (incomingItem) {
172
+ var currentIndex = result.findIndex(function (currentItem) {
173
+ return isSameOrderCollectionItem(kind, currentItem, incomingItem);
174
+ });
175
+ if (currentIndex !== -1) {
176
+ result[currentIndex] = mergeBaseSalesCollectionItem(kind, result[currentIndex], incomingItem, uidRemaps);
97
177
  return;
98
178
  }
99
- indexByUid.set(uid, result.length);
100
- result.push(clonedItem);
101
- };
102
- currentValue.forEach(appendOrReplaceByUid);
103
- loadedValue.forEach(appendOrReplaceByUid);
179
+ result.push(cloneDeep(incomingItem));
180
+ });
104
181
  return result;
105
182
  }
106
- function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord) {
107
- if (!currentTempOrder) return loadedRecord;
108
- var mergedRecord = mergeWith(cloneDeep(currentTempOrder), cloneDeep(loadedRecord || {}), function (currentValue, loadedValue, key) {
183
+ function normalizeBaseSalesRecordCollections(sourceRecord, options) {
184
+ var normalizedRecord = normalizeOrderCollections(cloneDeep(sourceRecord || {}), options).order;
185
+
186
+ // 兼容旧调用方偶尔使用的单数 payment 字段。
187
+ if (Array.isArray(normalizedRecord.payment)) {
188
+ normalizedRecord.payment = normalizeOrderCollection('payment', normalizedRecord.payment, options).items;
189
+ }
190
+ return normalizedRecord;
191
+ }
192
+ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord, strategy) {
193
+ var normalizedLoadedRecord = normalizeBaseSalesRecordCollections(loadedRecord || {}, {
194
+ ensureUid: false
195
+ });
196
+ if (!currentTempOrder) {
197
+ return normalizeBaseSalesRecordCollections(normalizedLoadedRecord);
198
+ }
199
+ var normalizedCurrentTempOrder = normalizeBaseSalesRecordCollections(currentTempOrder, {
200
+ ensureUid: false
201
+ });
202
+ var uidRemaps = [];
203
+ var mergedRecord = mergeWith(normalizedCurrentTempOrder, normalizedLoadedRecord, function (currentValue, loadedValue, key) {
204
+ var collectionKind = getBaseSalesOrderCollectionKind(key);
205
+ if (collectionKind && Array.isArray(loadedValue)) {
206
+ return mergeBaseSalesOrderCollection(collectionKind, Array.isArray(currentValue) ? currentValue : [], loadedValue, strategy, uidRemaps);
207
+ }
109
208
  if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
110
- var metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
111
- if (metadataKey) {
112
- return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
113
- }
114
209
  return [].concat(_toConsumableArray(cloneDeep(currentValue)), _toConsumableArray(cloneDeep(loadedValue)));
115
210
  }
116
211
  if (Array.isArray(loadedValue)) return cloneDeep(loadedValue);
@@ -120,7 +215,7 @@ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord) {
120
215
  return undefined;
121
216
  });
122
217
  delete mergedRecord.request_unique_idempotency_token;
123
- return mergedRecord;
218
+ return normalizeBaseSalesRecordCollections(applyOrderCollectionUidRemaps(mergedRecord, uidRemaps));
124
219
  }
125
220
  export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
126
221
  _inherits(BaseSalesImpl, _BaseModule);
@@ -153,6 +248,16 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
153
248
  _defineProperty(_assertThisInitialized(_this), "hasManualDiscountSelection", false);
154
249
  _defineProperty(_assertThisInitialized(_this), "reusedSharedSubModuleNames", new Set());
155
250
  _defineProperty(_assertThisInitialized(_this), "paymentMethodsCache", []);
251
+ _defineProperty(_assertThisInitialized(_this), "queuedAutoPaymentSync", false);
252
+ _defineProperty(_assertThisInitialized(_this), "autoPaymentSyncFlushing", false);
253
+ _defineProperty(_assertThisInitialized(_this), "autoPaymentSyncTimer", null);
254
+ _defineProperty(_assertThisInitialized(_this), "salesDetailLoadInFlightCount", 0);
255
+ _defineProperty(_assertThisInitialized(_this), "salesDetailLoadSequence", 0);
256
+ _defineProperty(_assertThisInitialized(_this), "salesDetailHydrateQueue", Promise.resolve());
257
+ _defineProperty(_assertThisInitialized(_this), "serverOrderChangeUnsubscribe", null);
258
+ _defineProperty(_assertThisInitialized(_this), "serverOrderChangeHydrateInFlight", null);
259
+ _defineProperty(_assertThisInitialized(_this), "queuedServerOrderChanges", []);
260
+ _defineProperty(_assertThisInitialized(_this), "serverOrderChangeSyncEnabled", false);
156
261
  return _this;
157
262
  }
158
263
 
@@ -168,9 +273,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
168
273
  }, {
169
274
  key: "getReusableSharedSubModule",
170
275
  value: function getReusableSharedSubModule(moduleName) {
171
- var _this$core;
276
+ var _this$core, _this$core$getModule;
172
277
  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;
278
+ 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
279
  }
175
280
  }, {
176
281
  key: "isScheduleListLoaded",
@@ -232,6 +337,263 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
232
337
  });
233
338
  }
234
339
  }
340
+ }, {
341
+ key: "isCurrentSalesOrderRecord",
342
+ value: function isCurrentSalesOrderRecord(order) {
343
+ var _this$store$order, _this$store$order$get;
344
+ 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);
345
+ var currentRecords = [currentTempOrder, this.currentSalesDetail].filter(Boolean);
346
+ return currentRecords.some(function (record) {
347
+ return isSameBaseSalesOrderRecord(record, order);
348
+ });
349
+ }
350
+ }, {
351
+ key: "setServerOrderChangeSyncEnabled",
352
+ value: function setServerOrderChangeSyncEnabled(enabled) {
353
+ this.serverOrderChangeSyncEnabled = enabled;
354
+ if (!enabled) this.queuedServerOrderChanges = [];
355
+ }
356
+ }, {
357
+ key: "queueLatestServerOrderChange",
358
+ value: function queueLatestServerOrderChange(order) {
359
+ var snapshot = cloneDeep(order);
360
+ var existingIndex = this.queuedServerOrderChanges.findIndex(function (queued) {
361
+ return isSameBaseSalesOrderRecord(queued, snapshot);
362
+ });
363
+ if (existingIndex >= 0) {
364
+ this.queuedServerOrderChanges[existingIndex] = snapshot;
365
+ return;
366
+ }
367
+ this.queuedServerOrderChanges.push(snapshot);
368
+ }
369
+ }, {
370
+ key: "drainQueuedServerOrderChanges",
371
+ value: function () {
372
+ var _drainQueuedServerOrderChanges = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
373
+ var changedOrders;
374
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
375
+ while (1) switch (_context.prev = _context.next) {
376
+ case 0:
377
+ if (!(!this.serverOrderChangeSyncEnabled || this.salesDetailLoadInFlightCount > 0 || this.serverOrderChangeHydrateInFlight || this.queuedServerOrderChanges.length === 0)) {
378
+ _context.next = 2;
379
+ break;
380
+ }
381
+ return _context.abrupt("return");
382
+ case 2:
383
+ changedOrders = this.queuedServerOrderChanges;
384
+ this.queuedServerOrderChanges = [];
385
+ _context.next = 6;
386
+ return this.syncCurrentSalesDetailFromServerOrderChange({
387
+ changedOrders: changedOrders
388
+ });
389
+ case 6:
390
+ case "end":
391
+ return _context.stop();
392
+ }
393
+ }, _callee, this);
394
+ }));
395
+ function drainQueuedServerOrderChanges() {
396
+ return _drainQueuedServerOrderChanges.apply(this, arguments);
397
+ }
398
+ return drainQueuedServerOrderChanges;
399
+ }()
400
+ }, {
401
+ key: "syncCurrentSalesDetailFromServerOrderChange",
402
+ value: function () {
403
+ var _syncCurrentSalesDetailFromServerOrderChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(payload) {
404
+ var _this2 = this;
405
+ var changedOrders, changedOrder;
406
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
407
+ while (1) switch (_context3.prev = _context3.next) {
408
+ case 0:
409
+ 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] : [];
410
+ if (this.serverOrderChangeSyncEnabled) {
411
+ _context3.next = 3;
412
+ break;
413
+ }
414
+ return _context3.abrupt("return");
415
+ case 3:
416
+ if (!(this.salesDetailLoadInFlightCount > 0)) {
417
+ _context3.next = 6;
418
+ break;
419
+ }
420
+ changedOrders.forEach(function (order) {
421
+ return _this2.queueLatestServerOrderChange(order);
422
+ });
423
+ return _context3.abrupt("return");
424
+ case 6:
425
+ changedOrder = changedOrders.find(function (order) {
426
+ return _this2.isCurrentSalesOrderRecord(order);
427
+ });
428
+ if (changedOrder) {
429
+ _context3.next = 9;
430
+ break;
431
+ }
432
+ return _context3.abrupt("return");
433
+ case 9:
434
+ if (!this.serverOrderChangeHydrateInFlight) {
435
+ _context3.next = 12;
436
+ break;
437
+ }
438
+ this.queueLatestServerOrderChange(changedOrder);
439
+ return _context3.abrupt("return");
440
+ case 12:
441
+ if (this.store.order) {
442
+ _context3.next = 14;
443
+ break;
444
+ }
445
+ return _context3.abrupt("return");
446
+ case 14:
447
+ this.serverOrderChangeHydrateInFlight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
448
+ var _getTempOrder, _ref2;
449
+ var currentTempOrder, record, sales;
450
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
451
+ while (1) switch (_context2.prev = _context2.next) {
452
+ case 0:
453
+ currentTempOrder = (_getTempOrder = (_ref2 = _this2.store.order).getTempOrder) === null || _getTempOrder === void 0 ? void 0 : _getTempOrder.call(_ref2);
454
+ record = mergeSalesDetailRecordWithTempOrder(currentTempOrder, changedOrder, 'authoritative-incoming');
455
+ _context2.next = 4;
456
+ return _this2.store.order.hydrateTempOrderFromRecord(record, {
457
+ recalcOnHydrate: false
458
+ });
459
+ case 4:
460
+ sales = _context2.sent;
461
+ _this2.currentSalesDetail = sales;
462
+ _context2.next = 8;
463
+ return _this2.core.effects.emit("".concat(_this2.name, ":onSalesOrderLoaded"), {
464
+ sales: sales
465
+ });
466
+ case 8:
467
+ case "end":
468
+ return _context2.stop();
469
+ }
470
+ }, _callee2);
471
+ }))();
472
+ _context3.prev = 15;
473
+ _context3.next = 18;
474
+ return this.serverOrderChangeHydrateInFlight;
475
+ case 18:
476
+ _context3.prev = 18;
477
+ this.serverOrderChangeHydrateInFlight = null;
478
+ _context3.next = 22;
479
+ return this.drainQueuedServerOrderChanges();
480
+ case 22:
481
+ return _context3.finish(18);
482
+ case 23:
483
+ case "end":
484
+ return _context3.stop();
485
+ }
486
+ }, _callee3, this, [[15,, 18, 23]]);
487
+ }));
488
+ function syncCurrentSalesDetailFromServerOrderChange(_x) {
489
+ return _syncCurrentSalesDetailFromServerOrderChange.apply(this, arguments);
490
+ }
491
+ return syncCurrentSalesDetailFromServerOrderChange;
492
+ }()
493
+ }, {
494
+ key: "registerServerOrderChangeSync",
495
+ value: function registerServerOrderChangeSync() {
496
+ var _this$serverOrderChan,
497
+ _this$core2,
498
+ _this3 = this;
499
+ (_this$serverOrderChan = this.serverOrderChangeUnsubscribe) === null || _this$serverOrderChan === void 0 || _this$serverOrderChan.call(this);
500
+ var effects = (_this$core2 = this.core) === null || _this$core2 === void 0 ? void 0 : _this$core2.effects;
501
+ if (!effects || typeof effects.on !== 'function') return;
502
+ this.serverOrderChangeUnsubscribe = effects.on(SERVER_ORDER_CHANGED_EVENT, function (payload) {
503
+ return _this3.syncCurrentSalesDetailFromServerOrderChange(payload).catch(function (error) {
504
+ _this3.logError('sync sales detail from server order change failed', {
505
+ error: error instanceof Error ? error.message : String(error)
506
+ });
507
+ });
508
+ });
509
+ }
510
+ }, {
511
+ key: "hydrateLatestLoadedSalesDetail",
512
+ value: function () {
513
+ var _hydrateLatestLoadedSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(record, loadSequence) {
514
+ var _this4 = this;
515
+ var hydratedSales, skippedBeforeHydrate, hydrateTask, queuedTask;
516
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
517
+ while (1) switch (_context5.prev = _context5.next) {
518
+ case 0:
519
+ hydratedSales = null;
520
+ skippedBeforeHydrate = false;
521
+ hydrateTask = /*#__PURE__*/function () {
522
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
523
+ var sales;
524
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
525
+ while (1) switch (_context4.prev = _context4.next) {
526
+ case 0:
527
+ if (!(loadSequence !== _this4.salesDetailLoadSequence)) {
528
+ _context4.next = 3;
529
+ break;
530
+ }
531
+ skippedBeforeHydrate = true;
532
+ return _context4.abrupt("return");
533
+ case 3:
534
+ if (_this4.store.order) {
535
+ _context4.next = 5;
536
+ break;
537
+ }
538
+ throw new Error('order 模块未初始化');
539
+ case 5:
540
+ _context4.next = 7;
541
+ return _this4.store.order.hydrateTempOrderFromRecord(record, {
542
+ recalcOnHydrate: false
543
+ });
544
+ case 7:
545
+ sales = _context4.sent;
546
+ hydratedSales = sales;
547
+
548
+ // hydrate 期间可能又发起了更新请求;后续任务已串行排队,将负责最终状态。
549
+ if (!(loadSequence !== _this4.salesDetailLoadSequence)) {
550
+ _context4.next = 11;
551
+ break;
552
+ }
553
+ return _context4.abrupt("return");
554
+ case 11:
555
+ _this4.currentSalesDetail = sales;
556
+ _context4.next = 14;
557
+ return _this4.core.effects.emit("".concat(_this4.name, ":onSalesOrderLoaded"), {
558
+ sales: sales
559
+ });
560
+ case 14:
561
+ case "end":
562
+ return _context4.stop();
563
+ }
564
+ }, _callee4);
565
+ }));
566
+ return function hydrateTask() {
567
+ return _ref3.apply(this, arguments);
568
+ };
569
+ }();
570
+ queuedTask = this.salesDetailHydrateQueue.then(hydrateTask, hydrateTask);
571
+ this.salesDetailHydrateQueue = queuedTask.then(function () {
572
+ return undefined;
573
+ }, function () {
574
+ return undefined;
575
+ });
576
+ _context5.next = 7;
577
+ return queuedTask;
578
+ case 7:
579
+ if (!skippedBeforeHydrate) {
580
+ _context5.next = 9;
581
+ break;
582
+ }
583
+ return _context5.abrupt("return", record);
584
+ case 9:
585
+ return _context5.abrupt("return", hydratedSales || this.currentSalesDetail || record);
586
+ case 10:
587
+ case "end":
588
+ return _context5.stop();
589
+ }
590
+ }, _callee5, this);
591
+ }));
592
+ function hydrateLatestLoadedSalesDetail(_x2, _x3) {
593
+ return _hydrateLatestLoadedSalesDetail.apply(this, arguments);
594
+ }
595
+ return hydrateLatestLoadedSalesDetail;
596
+ }()
235
597
  }, {
236
598
  key: "hydrateOrderPaymentNames",
237
599
  value: function hydrateOrderPaymentNames(payments) {
@@ -269,8 +631,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
269
631
  }, {
270
632
  key: "getCurrentOrderCustomerId",
271
633
  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);
634
+ var _this$store$order2, _this$store$order2$ge;
635
+ 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
636
  var customerId = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.customer_id;
275
637
  if (customerId === null || customerId === undefined) return undefined;
276
638
  return customerId;
@@ -296,10 +658,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
296
658
  });
297
659
  }
298
660
  quotation.setScheduleResolver(function (id) {
299
- var _scheduleModule$getSc, _getScheduleByIds, _ref;
661
+ var _scheduleModule$getSc, _getScheduleByIds, _ref4;
300
662
  var scheduleId = String(id);
301
663
  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])) || [];
664
+ var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || ((_getScheduleByIds = (_ref4 = scheduleModule).getScheduleByIds) === null || _getScheduleByIds === void 0 ? void 0 : _getScheduleByIds.call(_ref4, [id])) || [];
303
665
  if (schedules[0]) scheduleById.set(scheduleId, schedules[0]);
304
666
  return schedules[0];
305
667
  });
@@ -307,30 +669,30 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
307
669
  }, {
308
670
  key: "loadQuotationForPriceQuery",
309
671
  value: function () {
310
- var _loadQuotationForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
672
+ var _loadQuotationForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
311
673
  var _this$otherParams;
312
- return _regeneratorRuntime().wrap(function _callee$(_context) {
313
- while (1) switch (_context.prev = _context.next) {
674
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
675
+ while (1) switch (_context6.prev = _context6.next) {
314
676
  case 0:
315
677
  if (params.quotation) {
316
- _context.next = 2;
678
+ _context6.next = 2;
317
679
  break;
318
680
  }
319
- return _context.abrupt("return");
681
+ return _context6.abrupt("return");
320
682
  case 2:
321
683
  this.applyQuotationScheduleResolver(params.quotation);
322
- _context.next = 5;
684
+ _context6.next = 5;
323
685
  return params.quotation.loadQuotations({
324
686
  channel: params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel),
325
687
  customer_id: params.customer_id
326
688
  });
327
689
  case 5:
328
690
  case "end":
329
- return _context.stop();
691
+ return _context6.stop();
330
692
  }
331
- }, _callee, this);
693
+ }, _callee6, this);
332
694
  }));
333
- function loadQuotationForPriceQuery(_x) {
695
+ function loadQuotationForPriceQuery(_x4) {
334
696
  return _loadQuotationForPriceQuery.apply(this, arguments);
335
697
  }
336
698
  return loadQuotationForPriceQuery;
@@ -374,23 +736,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
374
736
  }, {
375
737
  key: "loadProductsForPriceQuery",
376
738
  value: function () {
377
- var _loadProductsForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
739
+ var _loadProductsForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
378
740
  var ids, productsById, _this$otherParams2, _response$data, response, list;
379
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
380
- while (1) switch (_context2.prev = _context2.next) {
741
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
742
+ while (1) switch (_context7.prev = _context7.next) {
381
743
  case 0:
382
744
  ids = Array.from(new Set(params.ids.filter(function (id) {
383
745
  return Number.isFinite(id);
384
746
  })));
385
747
  productsById = new Map();
386
748
  if (!(!ids.length || !this.request)) {
387
- _context2.next = 4;
749
+ _context7.next = 4;
388
750
  break;
389
751
  }
390
- return _context2.abrupt("return", productsById);
752
+ return _context7.abrupt("return", productsById);
391
753
  case 4:
392
- _context2.prev = 4;
393
- _context2.next = 7;
754
+ _context7.prev = 4;
755
+ _context7.next = 7;
394
756
  return this.request.post('/product/query', {
395
757
  ids: ids,
396
758
  open_quotation: 1,
@@ -407,35 +769,35 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
407
769
  customToast: function customToast() {}
408
770
  });
409
771
  case 7:
410
- response = _context2.sent;
772
+ response = _context7.sent;
411
773
  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
774
  if (Array.isArray(list)) {
413
- _context2.next = 11;
775
+ _context7.next = 11;
414
776
  break;
415
777
  }
416
- return _context2.abrupt("return", productsById);
778
+ return _context7.abrupt("return", productsById);
417
779
  case 11:
418
780
  list.forEach(function (item) {
419
781
  var _item$id;
420
782
  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
783
  if (Number.isFinite(productId)) productsById.set(productId, item);
422
784
  });
423
- return _context2.abrupt("return", productsById);
785
+ return _context7.abrupt("return", productsById);
424
786
  case 15:
425
- _context2.prev = 15;
426
- _context2.t0 = _context2["catch"](4);
787
+ _context7.prev = 15;
788
+ _context7.t0 = _context7["catch"](4);
427
789
  this.logWarning('loadProductsForPriceQuery: 商品批量重查失败,使用入参 fallback', {
428
790
  ids: ids,
429
- error: _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0)
791
+ error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
430
792
  });
431
- return _context2.abrupt("return", productsById);
793
+ return _context7.abrupt("return", productsById);
432
794
  case 19:
433
795
  case "end":
434
- return _context2.stop();
796
+ return _context7.stop();
435
797
  }
436
- }, _callee2, this, [[4, 15]]);
798
+ }, _callee7, this, [[4, 15]]);
437
799
  }));
438
- function loadProductsForPriceQuery(_x2) {
800
+ function loadProductsForPriceQuery(_x5) {
439
801
  return _loadProductsForPriceQuery.apply(this, arguments);
440
802
  }
441
803
  return loadProductsForPriceQuery;
@@ -443,21 +805,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
443
805
  }, {
444
806
  key: "loadProductForPriceQuery",
445
807
  value: function () {
446
- var _loadProductForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params, customerId) {
808
+ var _loadProductForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params, customerId) {
447
809
  var product, productId, schedule, productsById;
448
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
449
- while (1) switch (_context3.prev = _context3.next) {
810
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
811
+ while (1) switch (_context8.prev = _context8.next) {
450
812
  case 0:
451
813
  product = params.product || {};
452
814
  productId = this.getPriceQueryProductId(product);
453
815
  if (!(productId === null || !this.request)) {
454
- _context3.next = 4;
816
+ _context8.next = 4;
455
817
  break;
456
818
  }
457
- return _context3.abrupt("return", null);
819
+ return _context8.abrupt("return", null);
458
820
  case 4:
459
821
  schedule = this.getPriceQuerySchedule(params);
460
- _context3.next = 7;
822
+ _context8.next = 7;
461
823
  return this.loadProductsForPriceQuery({
462
824
  ids: [productId],
463
825
  schedule: schedule,
@@ -465,15 +827,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
465
827
  channel: params.channel
466
828
  });
467
829
  case 7:
468
- productsById = _context3.sent;
469
- return _context3.abrupt("return", productsById.get(productId) || null);
830
+ productsById = _context8.sent;
831
+ return _context8.abrupt("return", productsById.get(productId) || null);
470
832
  case 9:
471
833
  case "end":
472
- return _context3.stop();
834
+ return _context8.stop();
473
835
  }
474
- }, _callee3, this);
836
+ }, _callee8, this);
475
837
  }));
476
- function loadProductForPriceQuery(_x3, _x4) {
838
+ function loadProductForPriceQuery(_x6, _x7) {
477
839
  return _loadProductForPriceQuery.apply(this, arguments);
478
840
  }
479
841
  return loadProductForPriceQuery;
@@ -486,10 +848,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
486
848
  return groups.flatMap(function (group) {
487
849
  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
850
  return items.map(function (item) {
489
- var _item$group_id, _ref2, _item$bundle_group_id;
851
+ var _item$group_id, _ref5, _item$bundle_group_id;
490
852
  return _objectSpread(_objectSpread({}, item), {}, {
491
853
  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
854
+ bundle_group_id: (_ref5 = (_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 && _ref5 !== void 0 ? _ref5 : group === null || group === void 0 ? void 0 : group.id
493
855
  });
494
856
  });
495
857
  });
@@ -520,21 +882,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
520
882
  }, {
521
883
  key: "getAuthoritativeBundleUnitPrice",
522
884
  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;
885
+ var _ref6, _ref7, _ref8, _bundle$price;
886
+ return (_ref6 = (_ref7 = (_ref8 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref8 !== void 0 ? _ref8 : bundle.custom_price) !== null && _ref7 !== void 0 ? _ref7 : bundle.product_price) !== null && _ref6 !== void 0 ? _ref6 : bundle.base_price;
525
887
  }
526
888
  }, {
527
889
  key: "mergeProductForPriceQuery",
528
890
  value: function mergeProductForPriceQuery(product, authoritativeProduct) {
529
- var _this2 = this,
891
+ var _this5 = this,
530
892
  _product$id,
531
- _ref6,
893
+ _ref9,
532
894
  _product$product_id2,
533
- _ref7,
895
+ _ref10,
534
896
  _product$product_vari,
535
- _ref8,
897
+ _ref11,
536
898
  _product$num,
537
- _ref9,
899
+ _ref12,
538
900
  _product$quantity,
539
901
  _product$metadata4;
540
902
  if (!authoritativeProduct) return product;
@@ -542,8 +904,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
542
904
  var authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
543
905
  var productBundle = selectedBundles.map(function (bundle) {
544
906
  var _authoritativeBundle$, _authoritativeBundle$2;
545
- var authoritativeBundle = _this2.findAuthoritativeBundleItem(bundle, authoritativeBundles);
546
- var unitPrice = authoritativeBundle ? _this2.getAuthoritativeBundleUnitPrice(authoritativeBundle) : undefined;
907
+ var authoritativeBundle = _this5.findAuthoritativeBundleItem(bundle, authoritativeBundles);
908
+ var unitPrice = authoritativeBundle ? _this5.getAuthoritativeBundleUnitPrice(authoritativeBundle) : undefined;
547
909
  if (unitPrice === undefined || unitPrice === null || unitPrice === '') return bundle;
548
910
  return _objectSpread(_objectSpread({}, bundle), {}, {
549
911
  price: unitPrice,
@@ -554,10 +916,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
554
916
  });
555
917
  return _objectSpread(_objectSpread(_objectSpread({}, product), authoritativeProduct), {}, {
556
918
  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,
919
+ product_id: (_ref9 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref9 !== void 0 ? _ref9 : authoritativeProduct.id,
920
+ product_variant_id: (_ref10 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref10 !== void 0 ? _ref10 : 0,
921
+ num: (_ref11 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref11 !== void 0 ? _ref11 : authoritativeProduct.num,
922
+ quantity: (_ref12 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref12 !== void 0 ? _ref12 : authoritativeProduct.quantity,
561
923
  product_sku: function () {
562
924
  var authoritativeSku = ensureProductSku(authoritativeProduct);
563
925
  var productSku = ensureProductSku(product);
@@ -631,61 +993,61 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
631
993
  }, {
632
994
  key: "syncOtherParamsToSubModules",
633
995
  value: (function () {
634
- var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(changedParams) {
635
- var _this3 = this;
636
- var _ref10,
637
- _ref10$cover,
996
+ var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(changedParams) {
997
+ var _this6 = this;
998
+ var _ref13,
999
+ _ref13$cover,
638
1000
  cover,
639
1001
  nextSubModuleOtherParams,
640
- _args5 = arguments;
641
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
642
- while (1) switch (_context5.prev = _context5.next) {
1002
+ _args10 = arguments;
1003
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1004
+ while (1) switch (_context10.prev = _context10.next) {
643
1005
  case 0:
644
- _ref10 = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {}, _ref10$cover = _ref10.cover, cover = _ref10$cover === void 0 ? false : _ref10$cover;
1006
+ _ref13 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref13$cover = _ref13.cover, cover = _ref13$cover === void 0 ? false : _ref13$cover;
645
1007
  nextSubModuleOtherParams = this.buildSubModuleOtherParams();
646
- _context5.next = 4;
1008
+ _context10.next = 4;
647
1009
  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) {
1010
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref14) {
1011
+ var _ref16, moduleName, subModule, targetModule;
1012
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1013
+ while (1) switch (_context9.prev = _context9.next) {
652
1014
  case 0:
653
- _ref13 = _slicedToArray(_ref11, 2), moduleName = _ref13[0], subModule = _ref13[1];
654
- if (!_this3.reusedSharedSubModuleNames.has(moduleName)) {
655
- _context4.next = 3;
1015
+ _ref16 = _slicedToArray(_ref14, 2), moduleName = _ref16[0], subModule = _ref16[1];
1016
+ if (!_this6.reusedSharedSubModuleNames.has(moduleName)) {
1017
+ _context9.next = 3;
656
1018
  break;
657
1019
  }
658
- return _context4.abrupt("return");
1020
+ return _context9.abrupt("return");
659
1021
  case 3:
660
1022
  targetModule = subModule;
661
1023
  if (!(!targetModule || typeof targetModule.updateOtherParams !== 'function')) {
662
- _context4.next = 6;
1024
+ _context9.next = 6;
663
1025
  break;
664
1026
  }
665
- return _context4.abrupt("return");
1027
+ return _context9.abrupt("return");
666
1028
  case 6:
667
- _context4.next = 8;
1029
+ _context9.next = 8;
668
1030
  return targetModule.updateOtherParams(nextSubModuleOtherParams, {
669
1031
  changedParams: changedParams,
670
1032
  cover: cover
671
1033
  });
672
1034
  case 8:
673
1035
  case "end":
674
- return _context4.stop();
1036
+ return _context9.stop();
675
1037
  }
676
- }, _callee4);
1038
+ }, _callee9);
677
1039
  }));
678
- return function (_x6) {
679
- return _ref12.apply(this, arguments);
1040
+ return function (_x9) {
1041
+ return _ref15.apply(this, arguments);
680
1042
  };
681
1043
  }()));
682
1044
  case 4:
683
1045
  case "end":
684
- return _context5.stop();
1046
+ return _context10.stop();
685
1047
  }
686
- }, _callee5, this);
1048
+ }, _callee10, this);
687
1049
  }));
688
- function syncOtherParamsToSubModules(_x5) {
1050
+ function syncOtherParamsToSubModules(_x8) {
689
1051
  return _syncOtherParamsToSubModules.apply(this, arguments);
690
1052
  }
691
1053
  return syncOtherParamsToSubModules;
@@ -759,19 +1121,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
759
1121
  }, {
760
1122
  key: "initialize",
761
1123
  value: function () {
762
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(core) {
1124
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(core) {
763
1125
  var _this$otherParams4,
764
- _this4 = this,
1126
+ _this7 = this,
765
1127
  _this$otherParams5;
766
1128
  var options,
767
1129
  app,
768
1130
  targetCacheData,
769
1131
  moduleNames,
770
- _args6 = arguments;
771
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
772
- while (1) switch (_context6.prev = _context6.next) {
1132
+ _args11 = arguments;
1133
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1134
+ while (1) switch (_context11.prev = _context11.next) {
773
1135
  case 0:
774
- options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
1136
+ options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {};
775
1137
  this.core = core;
776
1138
  this.initializeOptions = options || {};
777
1139
  // this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
@@ -784,7 +1146,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
784
1146
  // 获取 logger 实例
785
1147
  this.appPlugin = core.getPlugin('app');
786
1148
  if (this.appPlugin) {
787
- _context6.next = 11;
1149
+ _context11.next = 11;
788
1150
  break;
789
1151
  }
790
1152
  throw new Error('Checkout 解决方案需要 app 插件支持');
@@ -794,47 +1156,48 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
794
1156
  targetCacheData = this.readSessionCacheData();
795
1157
  moduleNames = this.getRegisteredModuleNames();
796
1158
  moduleNames.forEach(function (step) {
797
- var reusedModule = _this4.getReusableSharedSubModule(step);
1159
+ var reusedModule = _this7.getReusableSharedSubModule(step);
798
1160
  if (reusedModule) {
799
- _this4.store[step] = reusedModule;
800
- _this4.reusedSharedSubModuleNames.add(step);
1161
+ _this7.store[step] = reusedModule;
1162
+ _this7.reusedSharedSubModuleNames.add(step);
801
1163
  return;
802
1164
  }
803
- var targetModule = _this4.createSubModule(step);
1165
+ var targetModule = _this7.createSubModule(step);
804
1166
  if (!targetModule) {
805
1167
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
806
1168
  }
807
- var hooks = _this4.getSubModuleHooks(step);
808
- _this4.store[step] = targetModule;
809
- _this4.core.registerModule(targetModule, _objectSpread(_objectSpread({
1169
+ var hooks = _this7.getSubModuleHooks(step);
1170
+ _this7.store[step] = targetModule;
1171
+ _this7.core.registerModule(targetModule, _objectSpread(_objectSpread({
810
1172
  initialState: (targetCacheData === null || targetCacheData === void 0 ? void 0 : targetCacheData[targetModule.name]) || {}
811
1173
  }, hooks ? {
812
1174
  hooks: hooks
813
1175
  } : {}), {}, {
814
- otherParams: _this4.buildSubModuleOtherParams()
1176
+ otherParams: _this7.buildSubModuleOtherParams()
815
1177
  }));
816
1178
  });
817
1179
  if (!(this.store.schedule && !this.isScheduleListLoaded(this.store.schedule))) {
818
- _context6.next = 19;
1180
+ _context11.next = 19;
819
1181
  break;
820
1182
  }
821
- _context6.next = 19;
1183
+ _context11.next = 19;
822
1184
  return this.store.schedule.loadAllSchedule();
823
1185
  case 19:
824
1186
  if (this.store.order && typeof ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.enableTempOrderPersist) === 'boolean') {
825
1187
  this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
826
1188
  }
827
- _context6.next = 22;
1189
+ _context11.next = 22;
828
1190
  return this.getPaymentMethodsAsync();
829
1191
  case 22:
1192
+ this.registerServerOrderChangeSync();
830
1193
  this.core.effects.emit("".concat(this.name, ":onInited"), {});
831
- case 23:
1194
+ case 24:
832
1195
  case "end":
833
- return _context6.stop();
1196
+ return _context11.stop();
834
1197
  }
835
- }, _callee6, this);
1198
+ }, _callee11, this);
836
1199
  }));
837
- function initialize(_x7) {
1200
+ function initialize(_x10) {
838
1201
  return _initialize.apply(this, arguments);
839
1202
  }
840
1203
  return initialize;
@@ -842,14 +1205,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
842
1205
  }, {
843
1206
  key: "destroy",
844
1207
  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) {
1208
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1209
+ var _this$serverOrderChan2,
1210
+ _this8 = this;
1211
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1212
+ while (1) switch (_context12.prev = _context12.next) {
849
1213
  case 0:
1214
+ (_this$serverOrderChan2 = this.serverOrderChangeUnsubscribe) === null || _this$serverOrderChan2 === void 0 || _this$serverOrderChan2.call(this);
1215
+ this.serverOrderChangeUnsubscribe = null;
850
1216
  Object.keys(this.store).forEach(function (key) {
851
- if (_this5.reusedSharedSubModuleNames.has(key)) return;
852
- var sub = _this5.store[key];
1217
+ if (_this8.reusedSharedSubModuleNames.has(key)) return;
1218
+ var sub = _this8.store[key];
853
1219
  if (sub && typeof sub.destroy === 'function') {
854
1220
  try {
855
1221
  sub.destroy();
@@ -859,15 +1225,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
859
1225
  }
860
1226
  });
861
1227
  this.currentSalesDetail = null;
862
- _context7.next = 4;
1228
+ this.queuedServerOrderChanges = [];
1229
+ this.salesDetailLoadSequence += 1;
1230
+ _context12.next = 8;
863
1231
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
864
- case 4:
1232
+ case 8:
865
1233
  _get(_getPrototypeOf(BaseSalesImpl.prototype), "destroy", this).call(this);
866
- case 5:
1234
+ case 9:
867
1235
  case "end":
868
- return _context7.stop();
1236
+ return _context12.stop();
869
1237
  }
870
- }, _callee7, this);
1238
+ }, _callee12, this);
871
1239
  }));
872
1240
  function destroy() {
873
1241
  return _destroy.apply(this, arguments);
@@ -884,77 +1252,91 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
884
1252
  }, {
885
1253
  key: "loadSalesDetail",
886
1254
  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) {
1255
+ var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderIdOrParams) {
1256
+ var loadSequence, _ref17, _ref18, _ref19, _ref20, _params$orderId, params, externalSaleNumber, preloadedSalesDetail, lookup, loadedRecord, message, remoteRecord, currentTempOrder, record;
1257
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1258
+ while (1) switch (_context13.prev = _context13.next) {
892
1259
  case 0:
893
1260
  if (this.store.order) {
894
- _context8.next = 2;
1261
+ _context13.next = 2;
895
1262
  break;
896
1263
  }
897
1264
  throw new Error('order 模块未初始化');
898
1265
  case 2:
1266
+ loadSequence = ++this.salesDetailLoadSequence;
1267
+ this.salesDetailLoadInFlightCount += 1;
1268
+ _context13.prev = 4;
899
1269
  params = _typeof(orderIdOrParams) === 'object' ? orderIdOrParams : {
900
1270
  orderId: orderIdOrParams
901
1271
  };
902
1272
  externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
903
1273
  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;
1274
+ lookup = (_ref17 = (_ref18 = (_ref19 = (_ref20 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref20 !== void 0 ? _ref20 : params.orderNumber) !== null && _ref19 !== void 0 ? _ref19 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_id) !== null && _ref18 !== void 0 ? _ref18 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.external_sale_number) !== null && _ref17 !== void 0 ? _ref17 : preloadedSalesDetail === null || preloadedSalesDetail === void 0 ? void 0 : preloadedSalesDetail.order_number;
905
1275
  if (!(!preloadedSalesDetail && (lookup === undefined || lookup === null || lookup === ''))) {
906
- _context8.next = 8;
1276
+ _context13.next = 11;
907
1277
  break;
908
1278
  }
909
1279
  throw new Error('加载销售详情需要 orderId、externalSaleNumber 或 orderNumber');
910
- case 8:
1280
+ case 11:
911
1281
  if (!(preloadedSalesDetail !== null && preloadedSalesDetail !== void 0)) {
912
- _context8.next = 12;
1282
+ _context13.next = 15;
913
1283
  break;
914
1284
  }
915
- _context8.t0 = preloadedSalesDetail;
916
- _context8.next = 15;
1285
+ _context13.t0 = preloadedSalesDetail;
1286
+ _context13.next = 18;
917
1287
  break;
918
- case 12:
919
- _context8.next = 14;
1288
+ case 15:
1289
+ _context13.next = 17;
920
1290
  return this.store.order.getSalesOrderByLookup({
921
1291
  lookup: lookup,
922
1292
  forceRemote: params.forceRemote
923
1293
  });
924
- case 14:
925
- _context8.t0 = _context8.sent;
926
- case 15:
927
- loadedRecord = _context8.t0;
1294
+ case 17:
1295
+ _context13.t0 = _context13.sent;
1296
+ case 18:
1297
+ loadedRecord = _context13.t0;
928
1298
  if (!(!preloadedSalesDetail && (!loadedRecord || loadedRecord.code !== 200))) {
929
- _context8.next = 19;
1299
+ _context13.next = 22;
930
1300
  break;
931
1301
  }
932
1302
  message = loadedRecord && (loadedRecord.message || loadedRecord.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(lookup);
933
1303
  throw new Error(message);
934
- case 19:
1304
+ case 22:
935
1305
  remoteRecord = preloadedSalesDetail !== null && preloadedSalesDetail !== void 0 ? preloadedSalesDetail : loadedRecord.data;
936
1306
  currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
937
- record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord) : remoteRecord;
938
- _context8.next = 24;
939
- return this.store.order.hydrateTempOrderFromRecord(record, {
940
- recalcOnHydrate: false
941
- });
942
- case 24:
943
- sales = _context8.sent;
944
- this.currentSalesDetail = sales;
945
- _context8.next = 28;
946
- return this.core.effects.emit("".concat(this.name, ":onSalesOrderLoaded"), {
947
- sales: sales
948
- });
1307
+ record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, remoteRecord, 'preserve-local') : remoteRecord;
1308
+ _context13.next = 27;
1309
+ return this.hydrateLatestLoadedSalesDetail(record, loadSequence);
1310
+ case 27:
1311
+ return _context13.abrupt("return", _context13.sent);
949
1312
  case 28:
950
- return _context8.abrupt("return", sales);
951
- case 29:
1313
+ _context13.prev = 28;
1314
+ this.salesDetailLoadInFlightCount = Math.max(0, this.salesDetailLoadInFlightCount - 1);
1315
+ if (!(this.salesDetailLoadInFlightCount === 0)) {
1316
+ _context13.next = 39;
1317
+ break;
1318
+ }
1319
+ _context13.prev = 31;
1320
+ _context13.next = 34;
1321
+ return this.drainQueuedServerOrderChanges();
1322
+ case 34:
1323
+ _context13.next = 39;
1324
+ break;
1325
+ case 36:
1326
+ _context13.prev = 36;
1327
+ _context13.t1 = _context13["catch"](31);
1328
+ this.logError('drain queued server order changes failed', {
1329
+ error: _context13.t1 instanceof Error ? _context13.t1.message : String(_context13.t1)
1330
+ });
1331
+ case 39:
1332
+ return _context13.finish(28);
1333
+ case 40:
952
1334
  case "end":
953
- return _context8.stop();
1335
+ return _context13.stop();
954
1336
  }
955
- }, _callee8, this);
1337
+ }, _callee13, this, [[4,, 28, 40], [31, 36]]);
956
1338
  }));
957
- function loadSalesDetail(_x8) {
1339
+ function loadSalesDetail(_x11) {
958
1340
  return _loadSalesDetail.apply(this, arguments);
959
1341
  }
960
1342
  return loadSalesDetail;
@@ -1027,41 +1409,41 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1027
1409
  }, {
1028
1410
  key: "getTempOrder",
1029
1411
  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;
1412
+ var _this$store$order3;
1413
+ var result = ((_this$store$order3 = this.store.order) === null || _this$store$order3 === void 0 ? void 0 : _this$store$order3.getTempOrder()) || null;
1032
1414
  return result;
1033
1415
  }
1034
1416
  }, {
1035
1417
  key: "replaceTempOrder",
1036
1418
  value: function () {
1037
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(tempOrder) {
1419
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(tempOrder) {
1038
1420
  var nextTempOrder;
1039
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1040
- while (1) switch (_context9.prev = _context9.next) {
1421
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1422
+ while (1) switch (_context14.prev = _context14.next) {
1041
1423
  case 0:
1042
1424
  if (this.store.order) {
1043
- _context9.next = 2;
1425
+ _context14.next = 2;
1044
1426
  break;
1045
1427
  }
1046
1428
  throw new Error('order 模块未初始化');
1047
1429
  case 2:
1048
- _context9.next = 4;
1430
+ _context14.next = 4;
1049
1431
  return this.store.order.replaceTempOrder(tempOrder);
1050
1432
  case 4:
1051
- nextTempOrder = _context9.sent;
1052
- _context9.next = 7;
1433
+ nextTempOrder = _context14.sent;
1434
+ _context14.next = 7;
1053
1435
  return this.effectsEmit('onTempOrderReplaced', {
1054
1436
  tempOrder: nextTempOrder
1055
1437
  });
1056
1438
  case 7:
1057
- return _context9.abrupt("return", nextTempOrder);
1439
+ return _context14.abrupt("return", nextTempOrder);
1058
1440
  case 8:
1059
1441
  case "end":
1060
- return _context9.stop();
1442
+ return _context14.stop();
1061
1443
  }
1062
- }, _callee9, this);
1444
+ }, _callee14, this);
1063
1445
  }));
1064
- function replaceTempOrder(_x9) {
1446
+ function replaceTempOrder(_x12) {
1065
1447
  return _replaceTempOrder.apply(this, arguments);
1066
1448
  }
1067
1449
  return replaceTempOrder;
@@ -1159,40 +1541,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1159
1541
  }, {
1160
1542
  key: "addNewOrder",
1161
1543
  value: function () {
1162
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1544
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1163
1545
  var tempOrder;
1164
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1165
- while (1) switch (_context10.prev = _context10.next) {
1546
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1547
+ while (1) switch (_context15.prev = _context15.next) {
1166
1548
  case 0:
1167
- _context10.prev = 0;
1549
+ _context15.prev = 0;
1168
1550
  if (this.store.order) {
1169
- _context10.next = 3;
1551
+ _context15.next = 3;
1170
1552
  break;
1171
1553
  }
1172
1554
  throw new Error('order 模块未初始化');
1173
1555
  case 3:
1174
- _context10.next = 5;
1556
+ _context15.next = 5;
1175
1557
  return this.store.order.addNewOrder();
1176
1558
  case 5:
1177
- tempOrder = _context10.sent;
1559
+ tempOrder = _context15.sent;
1178
1560
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1179
- _context10.next = 10;
1561
+ _context15.next = 10;
1180
1562
  break;
1181
1563
  }
1182
1564
  this.store.order.persistTempOrder();
1183
- _context10.next = 10;
1565
+ _context15.next = 10;
1184
1566
  return this.store.order.saveDraft();
1185
1567
  case 10:
1186
- return _context10.abrupt("return", tempOrder);
1568
+ return _context15.abrupt("return", tempOrder);
1187
1569
  case 13:
1188
- _context10.prev = 13;
1189
- _context10.t0 = _context10["catch"](0);
1190
- throw _context10.t0;
1570
+ _context15.prev = 13;
1571
+ _context15.t0 = _context15["catch"](0);
1572
+ throw _context15.t0;
1191
1573
  case 16:
1192
1574
  case "end":
1193
- return _context10.stop();
1575
+ return _context15.stop();
1194
1576
  }
1195
- }, _callee10, this, [[0, 13]]);
1577
+ }, _callee15, this, [[0, 13]]);
1196
1578
  }));
1197
1579
  function addNewOrder() {
1198
1580
  return _addNewOrder.apply(this, arguments);
@@ -1202,22 +1584,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1202
1584
  }, {
1203
1585
  key: "saveDraft",
1204
1586
  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) {
1587
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1588
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1589
+ while (1) switch (_context16.prev = _context16.next) {
1208
1590
  case 0:
1209
1591
  if (this.store.order) {
1210
- _context11.next = 2;
1592
+ _context16.next = 2;
1211
1593
  break;
1212
1594
  }
1213
1595
  throw new Error('order 模块未初始化');
1214
1596
  case 2:
1215
- return _context11.abrupt("return", this.store.order.saveDraft());
1597
+ return _context16.abrupt("return", this.store.order.saveDraft());
1216
1598
  case 3:
1217
1599
  case "end":
1218
- return _context11.stop();
1600
+ return _context16.stop();
1219
1601
  }
1220
- }, _callee11, this);
1602
+ }, _callee16, this);
1221
1603
  }));
1222
1604
  function saveDraft() {
1223
1605
  return _saveDraft.apply(this, arguments);
@@ -1228,14 +1610,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1228
1610
  }, {
1229
1611
  key: "restoreOrder",
1230
1612
  value: function () {
1231
- var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1613
+ var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1232
1614
  var tempOrder;
1233
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1234
- while (1) switch (_context12.prev = _context12.next) {
1615
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1616
+ while (1) switch (_context17.prev = _context17.next) {
1235
1617
  case 0:
1236
- _context12.prev = 0;
1618
+ _context17.prev = 0;
1237
1619
  if (this.store.order) {
1238
- _context12.next = 3;
1620
+ _context17.next = 3;
1239
1621
  break;
1240
1622
  }
1241
1623
  throw new Error('scanOrder 解决方案需要 order 模块支持');
@@ -1245,29 +1627,29 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1245
1627
  this.currentSalesDetail = null;
1246
1628
  this.discountConfigCacheKey = null;
1247
1629
  this.hasManualDiscountSelection = false;
1248
- _context12.next = 9;
1630
+ _context17.next = 9;
1249
1631
  return this.effectsEmit('onTempOrderReplaced', {
1250
1632
  tempOrder: tempOrder
1251
1633
  });
1252
1634
  case 9:
1253
1635
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1254
- _context12.next = 13;
1636
+ _context17.next = 13;
1255
1637
  break;
1256
1638
  }
1257
1639
  this.store.order.persistTempOrder();
1258
- _context12.next = 13;
1640
+ _context17.next = 13;
1259
1641
  return this.store.order.saveDraft();
1260
1642
  case 13:
1261
- return _context12.abrupt("return", tempOrder);
1643
+ return _context17.abrupt("return", tempOrder);
1262
1644
  case 16:
1263
- _context12.prev = 16;
1264
- _context12.t0 = _context12["catch"](0);
1265
- throw _context12.t0;
1645
+ _context17.prev = 16;
1646
+ _context17.t0 = _context17["catch"](0);
1647
+ throw _context17.t0;
1266
1648
  case 19:
1267
1649
  case "end":
1268
- return _context12.stop();
1650
+ return _context17.stop();
1269
1651
  }
1270
- }, _callee12, this, [[0, 16]]);
1652
+ }, _callee17, this, [[0, 16]]);
1271
1653
  }));
1272
1654
  function restoreOrder() {
1273
1655
  return _restoreOrder.apply(this, arguments);
@@ -1281,22 +1663,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1281
1663
  }, {
1282
1664
  key: "clearOrderCartLines",
1283
1665
  value: (function () {
1284
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1666
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1285
1667
  var tempOrder;
1286
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1287
- while (1) switch (_context13.prev = _context13.next) {
1668
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1669
+ while (1) switch (_context18.prev = _context18.next) {
1288
1670
  case 0:
1289
- _context13.prev = 0;
1671
+ _context18.prev = 0;
1290
1672
  if (this.store.order) {
1291
- _context13.next = 3;
1673
+ _context18.next = 3;
1292
1674
  break;
1293
1675
  }
1294
1676
  throw new Error('order 模块未初始化');
1295
1677
  case 3:
1296
- _context13.next = 5;
1678
+ _context18.next = 5;
1297
1679
  return this.store.order.clearOrderCartLines();
1298
1680
  case 5:
1299
- tempOrder = _context13.sent;
1681
+ tempOrder = _context18.sent;
1300
1682
  if (this.currentSalesDetail) {
1301
1683
  this.currentSalesDetail = _objectSpread(_objectSpread({}, this.currentSalesDetail), {}, {
1302
1684
  products: [],
@@ -1306,29 +1688,29 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1306
1688
  discount_list: []
1307
1689
  });
1308
1690
  }
1309
- _context13.next = 9;
1691
+ _context18.next = 9;
1310
1692
  return this.effectsEmit('onTempOrderReplaced', {
1311
1693
  tempOrder: tempOrder
1312
1694
  });
1313
1695
  case 9:
1314
1696
  if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1315
- _context13.next = 13;
1697
+ _context18.next = 13;
1316
1698
  break;
1317
1699
  }
1318
1700
  this.store.order.persistTempOrder();
1319
- _context13.next = 13;
1701
+ _context18.next = 13;
1320
1702
  return this.store.order.saveDraft();
1321
1703
  case 13:
1322
- return _context13.abrupt("return", tempOrder);
1704
+ return _context18.abrupt("return", tempOrder);
1323
1705
  case 16:
1324
- _context13.prev = 16;
1325
- _context13.t0 = _context13["catch"](0);
1326
- throw _context13.t0;
1706
+ _context18.prev = 16;
1707
+ _context18.t0 = _context18["catch"](0);
1708
+ throw _context18.t0;
1327
1709
  case 19:
1328
1710
  case "end":
1329
- return _context13.stop();
1711
+ return _context18.stop();
1330
1712
  }
1331
- }, _callee13, this, [[0, 16]]);
1713
+ }, _callee18, this, [[0, 16]]);
1332
1714
  }));
1333
1715
  function clearOrderCartLines() {
1334
1716
  return _clearOrderCartLines.apply(this, arguments);
@@ -1345,32 +1727,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1345
1727
  }, {
1346
1728
  key: "getSummary",
1347
1729
  value: function () {
1348
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1730
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1349
1731
  var summary;
1350
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1351
- while (1) switch (_context14.prev = _context14.next) {
1732
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1733
+ while (1) switch (_context19.prev = _context19.next) {
1352
1734
  case 0:
1353
- _context14.prev = 0;
1735
+ _context19.prev = 0;
1354
1736
  if (this.store.order) {
1355
- _context14.next = 3;
1737
+ _context19.next = 3;
1356
1738
  break;
1357
1739
  }
1358
1740
  throw new Error('order 模块未初始化');
1359
1741
  case 3:
1360
- _context14.next = 5;
1742
+ _context19.next = 5;
1361
1743
  return this.store.order.getOrderSummary();
1362
1744
  case 5:
1363
- summary = _context14.sent;
1364
- return _context14.abrupt("return", summary);
1745
+ summary = _context19.sent;
1746
+ return _context19.abrupt("return", summary);
1365
1747
  case 9:
1366
- _context14.prev = 9;
1367
- _context14.t0 = _context14["catch"](0);
1368
- throw _context14.t0;
1748
+ _context19.prev = 9;
1749
+ _context19.t0 = _context19["catch"](0);
1750
+ throw _context19.t0;
1369
1751
  case 12:
1370
1752
  case "end":
1371
- return _context14.stop();
1753
+ return _context19.stop();
1372
1754
  }
1373
- }, _callee14, this, [[0, 9]]);
1755
+ }, _callee19, this, [[0, 9]]);
1374
1756
  }));
1375
1757
  function getSummary() {
1376
1758
  return _getSummary.apply(this, arguments);
@@ -1380,10 +1762,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1380
1762
  }, {
1381
1763
  key: "getHistoricalProductDiscountList",
1382
1764
  value: function getHistoricalProductDiscountList(products) {
1383
- var _this6 = this;
1765
+ var _this9 = this;
1384
1766
  var historyDiscountList = [];
1385
1767
  products.forEach(function (item) {
1386
- if (!_this6.isPersistedOrderProduct(item)) return;
1768
+ if (!_this9.isPersistedOrderProduct(item)) return;
1387
1769
  (item.discount_list || []).forEach(function (discount) {
1388
1770
  var _discount$discount, _discount$metadata, _discount$discount2, _discount$discount3, _discount$discount4;
1389
1771
  var discountId = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
@@ -1443,11 +1825,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1443
1825
  }, {
1444
1826
  key: "shouldSkipAutoApplyFetchedDiscountsInEditMode",
1445
1827
  value: function shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
1446
- var _this7 = this;
1828
+ var _this10 = this;
1447
1829
  if (params.discountAction !== 'edit') return false;
1448
1830
  if (!params.products.length) return false;
1449
1831
  var hasDraftProduct = params.products.some(function (product) {
1450
- return !_this7.isPersistedOrderProduct(product);
1832
+ return !_this10.isPersistedOrderProduct(product);
1451
1833
  });
1452
1834
  if (hasDraftProduct) return false;
1453
1835
  var hasSelectedDiscount = params.currentDiscountList.some(function (discount) {
@@ -1487,14 +1869,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1487
1869
  }, {
1488
1870
  key: "loadDiscountConfig",
1489
1871
  value: function () {
1490
- var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1872
+ var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
1491
1873
  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) {
1874
+ var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _orderStore$summary, orderTotalAmount, result, _iterator2, _step2, _product$metadata5, _tempOrder$_extend3, _product$metadata$sou, _product$metadata6, _product$metadata7, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
1875
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1876
+ while (1) switch (_context20.prev = _context20.next) {
1495
1877
  case 0:
1496
1878
  if (this.store.order) {
1497
- _context15.next = 2;
1879
+ _context20.next = 2;
1498
1880
  break;
1499
1881
  }
1500
1882
  throw new Error('order 模块未初始化');
@@ -1514,18 +1896,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1514
1896
  discountConfigCacheKey = [customerId, discountAction, Number(orderId) || 0].join(':');
1515
1897
  preparedDiscountList = [];
1516
1898
  if (!(customerId && customerId !== 1)) {
1517
- _context15.next = 25;
1899
+ _context20.next = 25;
1518
1900
  break;
1519
1901
  }
1520
1902
  if (!(this.discountConfigCacheKey === discountConfigCacheKey)) {
1521
- _context15.next = 19;
1903
+ _context20.next = 19;
1522
1904
  break;
1523
1905
  }
1524
1906
  preparedDiscountList = originalDiscountList;
1525
- _context15.next = 25;
1907
+ _context20.next = 25;
1526
1908
  break;
1527
1909
  case 19:
1528
- _context15.next = 21;
1910
+ _context20.next = 21;
1529
1911
  return this.store.order.loadDiscountConfig({
1530
1912
  customerId: customerId,
1531
1913
  action: discountAction,
@@ -1533,23 +1915,24 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1533
1915
  apply: false
1534
1916
  });
1535
1917
  case 21:
1536
- preparedDiscountList = _context15.sent;
1918
+ preparedDiscountList = _context20.sent;
1537
1919
  this.discountConfigCacheKey = discountConfigCacheKey;
1538
- _context15.next = 25;
1920
+ _context20.next = 25;
1539
1921
  return discountModule === null || discountModule === void 0 || (_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, preparedDiscountList);
1540
1922
  case 25:
1541
1923
  if (!(hasManualDiscountSelection && currentDiscountList.length)) {
1542
- _context15.next = 27;
1924
+ _context20.next = 27;
1543
1925
  break;
1544
1926
  }
1545
- return _context15.abrupt("return", {
1927
+ return _context20.abrupt("return", {
1546
1928
  productList: tempOrder.products || [],
1547
- discountList: currentDiscountList
1929
+ discountList: currentDiscountList,
1930
+ availableWalletIds: this.getAvailableWalletIds()
1548
1931
  });
1549
1932
  case 27:
1550
1933
  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
1934
  nextDiscountList = this.mergeCurrentDiscountSelectionState(nextDiscountList, currentDiscountList);
1552
- _context15.next = 31;
1935
+ _context20.next = 31;
1553
1936
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1554
1937
  case 31:
1555
1938
  shouldSkipAutoApplyFetchedDiscounts = this.shouldSkipAutoApplyFetchedDiscountsInEditMode({
@@ -1559,17 +1942,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1559
1942
  nextDiscountList: nextDiscountList
1560
1943
  });
1561
1944
  if (!shouldSkipAutoApplyFetchedDiscounts) {
1562
- _context15.next = 40;
1945
+ _context20.next = 40;
1563
1946
  break;
1564
1947
  }
1565
- _context15.next = 35;
1948
+ _context20.next = 35;
1566
1949
  return this.store.order.recalculateSummary({
1567
1950
  createIfMissing: true
1568
1951
  });
1569
1952
  case 35:
1570
- _summary = _context15.sent;
1953
+ _summary = _context20.sent;
1571
1954
  this.store.order.persistTempOrder();
1572
- _context15.next = 39;
1955
+ _context20.next = 39;
1573
1956
  return this.effectsEmit('onDiscountApplied', {
1574
1957
  productList: tempOrder.products || [],
1575
1958
  discountList: nextDiscountList,
@@ -1577,24 +1960,26 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1577
1960
  tempOrder: tempOrder
1578
1961
  });
1579
1962
  case 39:
1580
- return _context15.abrupt("return", {
1963
+ return _context20.abrupt("return", {
1581
1964
  productList: tempOrder.products || [],
1582
- discountList: nextDiscountList
1965
+ discountList: nextDiscountList,
1966
+ availableWalletIds: this.getAvailableWalletIds()
1583
1967
  });
1584
1968
  case 40:
1585
1969
  if (!rulesModule) {
1586
- _context15.next = 76;
1970
+ _context20.next = 77;
1587
1971
  break;
1588
1972
  }
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
- }] : [];
1973
+ orderTotalAmount = Number(((_orderStore$summary = orderStore.summary) === null || _orderStore$summary === void 0 ? void 0 : _orderStore$summary.total_amount) || 0);
1974
+ console.log('[BaseSales.applyDiscountConfig.calcDiscount]');
1592
1975
  result = rulesModule.calcDiscount({
1593
1976
  productList: tempOrder.products,
1594
1977
  discountList: nextDiscountList,
1595
- 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)
1978
+ holders: [],
1979
+ isFormSubject: function isFormSubject(product) {
1980
+ return resolveIsFormSubject(tempOrder, product);
1981
+ },
1982
+ orderTotalAmount: orderTotalAmount
1598
1983
  }) || {
1599
1984
  productList: tempOrder.products,
1600
1985
  discountList: nextDiscountList
@@ -1602,23 +1987,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1602
1987
  if (result.productList) {
1603
1988
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1604
1989
  }
1605
- _iterator = _createForOfIteratorHelper(tempOrder.products || []);
1606
- _context15.prev = 45;
1607
- _iterator.s();
1608
- case 47:
1609
- if ((_step = _iterator.n()).done) {
1610
- _context15.next = 62;
1990
+ _iterator2 = _createForOfIteratorHelper(tempOrder.products || []);
1991
+ _context20.prev = 46;
1992
+ _iterator2.s();
1993
+ case 48:
1994
+ if ((_step2 = _iterator2.n()).done) {
1995
+ _context20.next = 63;
1611
1996
  break;
1612
1997
  }
1613
- product = _step.value;
1998
+ product = _step2.value;
1614
1999
  productUid = (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number;
1615
2000
  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
2001
  if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
1617
- _context15.next = 53;
2002
+ _context20.next = 54;
1618
2003
  break;
1619
2004
  }
1620
- return _context15.abrupt("continue", 60);
1621
- case 53:
2005
+ return _context20.abrupt("continue", 61);
2006
+ case 54:
1622
2007
  totalPerUnitDiscount = (product.discount_list || []).reduce(function (sum, pd) {
1623
2008
  return sum + Number(pd.amount || 0);
1624
2009
  }, 0);
@@ -1634,75 +2019,83 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1634
2019
  mainPrice: newMainSellingPrice,
1635
2020
  bundle: product.product_bundle
1636
2021
  });
1637
- case 60:
1638
- _context15.next = 47;
2022
+ case 61:
2023
+ _context20.next = 48;
1639
2024
  break;
1640
- case 62:
1641
- _context15.next = 67;
2025
+ case 63:
2026
+ _context20.next = 68;
1642
2027
  break;
1643
- case 64:
1644
- _context15.prev = 64;
1645
- _context15.t0 = _context15["catch"](45);
1646
- _iterator.e(_context15.t0);
1647
- case 67:
1648
- _context15.prev = 67;
1649
- _iterator.f();
1650
- return _context15.finish(67);
1651
- case 70:
2028
+ case 65:
2029
+ _context20.prev = 65;
2030
+ _context20.t0 = _context20["catch"](46);
2031
+ _iterator2.e(_context20.t0);
2032
+ case 68:
2033
+ _context20.prev = 68;
2034
+ _iterator2.f();
2035
+ return _context20.finish(68);
2036
+ case 71:
1652
2037
  if (!result.discountList) {
1653
- _context15.next = 76;
2038
+ _context20.next = 77;
1654
2039
  break;
1655
2040
  }
1656
2041
  nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1657
2042
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1658
- _context15.next = 75;
2043
+ _context20.next = 76;
1659
2044
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1660
- case 75:
2045
+ case 76:
1661
2046
  tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1662
2047
  return discount.isSelected;
1663
2048
  });
1664
- case 76:
1665
- _context15.next = 78;
2049
+ case 77:
2050
+ _context20.next = 79;
1666
2051
  return this.store.order.recalculateSummary({
1667
2052
  createIfMissing: true
1668
2053
  });
1669
- case 78:
1670
- summary = _context15.sent;
2054
+ case 79:
2055
+ summary = _context20.sent;
1671
2056
  this.store.order.persistTempOrder();
1672
- _context15.next = 82;
2057
+ _context20.next = 83;
1673
2058
  return this.effectsEmit('onDiscountApplied', {
1674
2059
  productList: tempOrder.products || [],
1675
2060
  discountList: nextDiscountList,
1676
2061
  selectedDiscountList: tempOrder.discount_list || [],
1677
2062
  tempOrder: tempOrder
1678
2063
  });
1679
- case 82:
1680
- return _context15.abrupt("return", {
2064
+ case 83:
2065
+ return _context20.abrupt("return", {
1681
2066
  productList: tempOrder.products || [],
1682
- discountList: nextDiscountList
2067
+ discountList: nextDiscountList,
2068
+ availableWalletIds: this.getAvailableWalletIds()
1683
2069
  });
1684
- case 83:
2070
+ case 84:
1685
2071
  case "end":
1686
- return _context15.stop();
2072
+ return _context20.stop();
1687
2073
  }
1688
- }, _callee15, this, [[45, 64, 67, 70]]);
2074
+ }, _callee20, this, [[46, 65, 68, 71]]);
1689
2075
  }));
1690
- function loadDiscountConfig(_x10) {
2076
+ function loadDiscountConfig(_x13) {
1691
2077
  return _loadDiscountConfig.apply(this, arguments);
1692
2078
  }
1693
2079
  return loadDiscountConfig;
1694
2080
  }()
2081
+ }, {
2082
+ key: "getAvailableWalletIds",
2083
+ value: function getAvailableWalletIds() {
2084
+ var _this$store$order4;
2085
+ if (!((_this$store$order4 = this.store.order) !== null && _this$store$order4 !== void 0 && _this$store$order4.getAvailableWalletIds)) return [];
2086
+ return this.store.order.getAvailableWalletIds();
2087
+ }
1695
2088
  }, {
1696
2089
  key: "bestDiscount",
1697
2090
  value: function () {
1698
- var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(cb) {
2091
+ var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(cb) {
1699
2092
  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) {
2093
+ var tempOrder, orderStore, discountModule, rulesModule, originalDiscountList, currentDiscountList, nextDiscountList, result, _orderStore$summary2, orderTotalAmount;
2094
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2095
+ while (1) switch (_context21.prev = _context21.next) {
1703
2096
  case 0:
1704
2097
  if (this.store.order) {
1705
- _context16.next = 2;
2098
+ _context21.next = 2;
1706
2099
  break;
1707
2100
  }
1708
2101
  throw new Error('order 模块未初始化');
@@ -1718,35 +2111,36 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1718
2111
  productList: tempOrder.products || [],
1719
2112
  discountList: nextDiscountList
1720
2113
  };
1721
- _context16.next = 12;
2114
+ _context21.next = 12;
1722
2115
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1723
2116
  case 12:
1724
2117
  if (!rulesModule) {
1725
- _context16.next = 23;
2118
+ _context21.next = 24;
1726
2119
  break;
1727
2120
  }
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
- }] : [];
2121
+ orderTotalAmount = Number(((_orderStore$summary2 = orderStore.summary) === null || _orderStore$summary2 === void 0 ? void 0 : _orderStore$summary2.total_amount) || 0);
2122
+ console.log('[BaseSales.bestDiscount.calcDiscount]');
1731
2123
  result = rulesModule.calcDiscount({
1732
2124
  productList: tempOrder.products,
1733
2125
  discountList: nextDiscountList,
1734
- 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)
2126
+ holders: [],
2127
+ isFormSubject: function isFormSubject(product) {
2128
+ return resolveIsFormSubject(tempOrder, product);
2129
+ },
2130
+ orderTotalAmount: orderTotalAmount
1737
2131
  }) || result;
1738
2132
  if (result.productList) {
1739
2133
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1740
2134
  }
1741
2135
  if (!result.discountList) {
1742
- _context16.next = 23;
2136
+ _context21.next = 24;
1743
2137
  break;
1744
2138
  }
1745
2139
  nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1746
2140
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1747
- _context16.next = 21;
2141
+ _context21.next = 22;
1748
2142
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1749
- case 21:
2143
+ case 22:
1750
2144
  tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1751
2145
  return discount.isSelected;
1752
2146
  });
@@ -1754,22 +2148,30 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1754
2148
  productList: tempOrder.products,
1755
2149
  discountList: nextDiscountList
1756
2150
  };
1757
- case 23:
1758
- _context16.next = 25;
2151
+ case 24:
2152
+ _context21.next = 26;
1759
2153
  return this.store.order.recalculateSummary({
1760
2154
  createIfMissing: true
1761
2155
  });
1762
- case 25:
2156
+ case 26:
1763
2157
  this.store.order.persistTempOrder();
2158
+ _context21.next = 29;
2159
+ return this.effectsEmit('onDiscountApplied', {
2160
+ productList: tempOrder.products || [],
2161
+ discountList: nextDiscountList,
2162
+ selectedDiscountList: tempOrder.discount_list || [],
2163
+ tempOrder: tempOrder
2164
+ });
2165
+ case 29:
1764
2166
  cb === null || cb === void 0 || cb(result);
1765
- return _context16.abrupt("return", result);
1766
- case 28:
2167
+ return _context21.abrupt("return", result);
2168
+ case 31:
1767
2169
  case "end":
1768
- return _context16.stop();
2170
+ return _context21.stop();
1769
2171
  }
1770
- }, _callee16, this);
2172
+ }, _callee21, this);
1771
2173
  }));
1772
- function bestDiscount(_x11) {
2174
+ function bestDiscount(_x14) {
1773
2175
  return _bestDiscount.apply(this, arguments);
1774
2176
  }
1775
2177
  return bestDiscount;
@@ -1780,52 +2182,118 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1780
2182
  if (!this.store.order) return [];
1781
2183
  return this.store.order.getDiscountList();
1782
2184
  }
2185
+
2186
+ /** 读取 Discount 模块原始券列表(未经过 bookingTime 等过滤)。 */
2187
+ }, {
2188
+ key: "getOriginalDiscountList",
2189
+ value: function getOriginalDiscountList() {
2190
+ var _store, _discountModule$getOr3;
2191
+ if (!this.store.order) return [];
2192
+ var discountModule = (_store = this.store.order.store) === null || _store === void 0 ? void 0 : _store.discount;
2193
+ return (discountModule === null || discountModule === void 0 || (_discountModule$getOr3 = discountModule.getOriginalDiscountList) === null || _discountModule$getOr3 === void 0 ? void 0 : _discountModule$getOr3.call(discountModule)) || [];
2194
+ }
2195
+
2196
+ /**
2197
+ * 同步写入 Discount 模块的 discountList / originalDiscountList。
2198
+ * 供 Holder 补全等场景在 OS store 层更新 machinecode holder 字段。
2199
+ */
2200
+ }, {
2201
+ key: "replaceDiscountStoreLists",
2202
+ value: (function () {
2203
+ var _replaceDiscountStoreLists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2204
+ var _store2;
2205
+ var discountModule;
2206
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2207
+ while (1) switch (_context22.prev = _context22.next) {
2208
+ case 0:
2209
+ if (this.store.order) {
2210
+ _context22.next = 2;
2211
+ break;
2212
+ }
2213
+ throw new Error('order 模块未初始化');
2214
+ case 2:
2215
+ discountModule = (_store2 = this.store.order.store) === null || _store2 === void 0 ? void 0 : _store2.discount;
2216
+ if (discountModule) {
2217
+ _context22.next = 5;
2218
+ break;
2219
+ }
2220
+ return _context22.abrupt("return");
2221
+ case 5:
2222
+ if (!params.originalDiscountList) {
2223
+ _context22.next = 8;
2224
+ break;
2225
+ }
2226
+ _context22.next = 8;
2227
+ return discountModule.setOriginalDiscountList(params.originalDiscountList);
2228
+ case 8:
2229
+ _context22.next = 10;
2230
+ return discountModule.setDiscountList(params.discountList);
2231
+ case 10:
2232
+ case "end":
2233
+ return _context22.stop();
2234
+ }
2235
+ }, _callee22, this);
2236
+ }));
2237
+ function replaceDiscountStoreLists(_x15) {
2238
+ return _replaceDiscountStoreLists.apply(this, arguments);
2239
+ }
2240
+ return replaceDiscountStoreLists;
2241
+ }())
1783
2242
  }, {
1784
2243
  key: "scanPromotionCode",
1785
- value: function () {
1786
- var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(code, customerId) {
1787
- var raw;
1788
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1789
- while (1) switch (_context17.prev = _context17.next) {
2244
+ value: function () {
2245
+ var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(code, customerId) {
2246
+ var raw, tempOrder;
2247
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2248
+ while (1) switch (_context23.prev = _context23.next) {
1790
2249
  case 0:
1791
- _context17.prev = 0;
2250
+ _context23.prev = 0;
1792
2251
  if (this.store.order) {
1793
- _context17.next = 3;
2252
+ _context23.next = 3;
1794
2253
  break;
1795
2254
  }
1796
2255
  throw new Error('order 模块未初始化');
1797
2256
  case 3:
1798
- _context17.next = 5;
2257
+ _context23.next = 5;
1799
2258
  return this.store.order.scanCode(code, customerId);
1800
2259
  case 5:
1801
- raw = _context17.sent;
2260
+ raw = _context23.sent;
1802
2261
  if (!raw.isAvailable) {
1803
- _context17.next = 10;
2262
+ _context23.next = 13;
1804
2263
  break;
1805
2264
  }
1806
- _context17.next = 9;
2265
+ _context23.next = 9;
1807
2266
  return this.store.order.recalculateSummary({
1808
2267
  createIfMissing: true
1809
2268
  });
1810
2269
  case 9:
1811
2270
  this.store.order.persistTempOrder();
1812
- case 10:
1813
- return _context17.abrupt("return", {
2271
+ tempOrder = this.store.order.ensureTempOrder();
2272
+ _context23.next = 13;
2273
+ return this.effectsEmit('onDiscountApplied', {
2274
+ productList: tempOrder.products || [],
2275
+ discountList: this.store.order.getDiscountList(),
2276
+ selectedDiscountList: tempOrder.discount_list || [],
2277
+ tempOrder: tempOrder
2278
+ });
2279
+ case 13:
2280
+ return _context23.abrupt("return", {
1814
2281
  isAvailable: raw.isAvailable,
1815
2282
  type: raw.type,
1816
- unavailableReason: raw.unavailableReason
2283
+ unavailableReason: raw.unavailableReason,
2284
+ scannedDiscountList: raw.scannedDiscountList
1817
2285
  });
1818
- case 13:
1819
- _context17.prev = 13;
1820
- _context17.t0 = _context17["catch"](0);
1821
- throw _context17.t0;
1822
2286
  case 16:
2287
+ _context23.prev = 16;
2288
+ _context23.t0 = _context23["catch"](0);
2289
+ throw _context23.t0;
2290
+ case 19:
1823
2291
  case "end":
1824
- return _context17.stop();
2292
+ return _context23.stop();
1825
2293
  }
1826
- }, _callee17, this, [[0, 13]]);
2294
+ }, _callee23, this, [[0, 16]]);
1827
2295
  }));
1828
- function scanPromotionCode(_x12, _x13) {
2296
+ function scanPromotionCode(_x16, _x17) {
1829
2297
  return _scanPromotionCode.apply(this, arguments);
1830
2298
  }
1831
2299
  return scanPromotionCode;
@@ -1833,14 +2301,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1833
2301
  }, {
1834
2302
  key: "setDiscountSelected",
1835
2303
  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) {
2304
+ var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2305
+ var list, updated, tempOrder, orderStore, discountModule, rulesModule, nextDiscountList, _orderStore$summary3, orderTotalAmount, result, beforeSelectedIds, _iterator3, _step3, d, selectedResourceIds, filterSelectedDiscountDetails, _iterator4, _step4, _product$metadata8, _tempOrder$_extend4, _product$metadata$sou2, _product$metadata9, _product$metadata10, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
2306
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2307
+ while (1) switch (_context24.prev = _context24.next) {
1840
2308
  case 0:
1841
- _context18.prev = 0;
2309
+ _context24.prev = 0;
1842
2310
  if (this.store.order) {
1843
- _context18.next = 3;
2311
+ _context24.next = 3;
1844
2312
  break;
1845
2313
  }
1846
2314
  throw new Error('order 模块未初始化');
@@ -1857,19 +2325,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1857
2325
  orderStore = this.store.order.store || {};
1858
2326
  discountModule = orderStore.discount;
1859
2327
  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
- }] : [];
1863
2328
  nextDiscountList = updated;
1864
- _context18.next = 14;
2329
+ _context24.next = 13;
1865
2330
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(updated);
1866
- case 14:
2331
+ case 13:
1867
2332
  if (rulesModule) {
2333
+ orderTotalAmount = Number(((_orderStore$summary3 = orderStore.summary) === null || _orderStore$summary3 === void 0 ? void 0 : _orderStore$summary3.total_amount) || 0);
2334
+ console.log('[BaseSales.setDiscountSelected.calcDiscount]');
1868
2335
  result = rulesModule.calcDiscount({
1869
2336
  productList: tempOrder.products,
1870
2337
  discountList: updated,
1871
- holders: holders,
1872
- isFormSubject: !!((_tempOrder$holder6 = tempOrder.holder) !== null && _tempOrder$holder6 !== void 0 && _tempOrder$holder6.type) && tempOrder.holder.type === 'form'
2338
+ holders: [],
2339
+ isFormSubject: function isFormSubject(product) {
2340
+ return resolveIsFormSubject(tempOrder, product);
2341
+ },
2342
+ orderTotalAmount: orderTotalAmount
1873
2343
  }, {
1874
2344
  discountId: params.discountId,
1875
2345
  isSelected: params.isSelected
@@ -1888,19 +2358,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1888
2358
  }).map(function (d) {
1889
2359
  return d.id;
1890
2360
  }));
1891
- _iterator2 = _createForOfIteratorHelper(nextDiscountList);
2361
+ _iterator3 = _createForOfIteratorHelper(nextDiscountList);
1892
2362
  try {
1893
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1894
- d = _step2.value;
2363
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2364
+ d = _step3.value;
1895
2365
  if (d.isSelected && !beforeSelectedIds.has(d.id)) {
1896
2366
  d.isSelected = false;
1897
2367
  d.isManualSelect = true;
2368
+ d.appliedProductDetails = [];
1898
2369
  }
1899
2370
  }
1900
2371
  } catch (err) {
1901
- _iterator2.e(err);
2372
+ _iterator3.e(err);
1902
2373
  } finally {
1903
- _iterator2.f();
2374
+ _iterator3.f();
1904
2375
  }
1905
2376
  }
1906
2377
  }
@@ -1910,28 +2381,45 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1910
2381
  }).map(function (d) {
1911
2382
  return d.id;
1912
2383
  }));
1913
- _iterator3 = _createForOfIteratorHelper(tempOrder.products);
1914
- _context18.prev = 17;
1915
- _iterator3.s();
2384
+ filterSelectedDiscountDetails = function filterSelectedDiscountDetails(discountList) {
2385
+ return (discountList || []).filter(function (pd) {
2386
+ var _pd$discount$resource, _pd$discount;
2387
+ 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;
2388
+ return rid != null && selectedResourceIds.has(rid);
2389
+ });
2390
+ };
2391
+ _iterator4 = _createForOfIteratorHelper(tempOrder.products);
2392
+ _context24.prev = 17;
2393
+ _iterator4.s();
1916
2394
  case 19:
1917
- if ((_step3 = _iterator3.n()).done) {
1918
- _context18.next = 35;
2395
+ if ((_step4 = _iterator4.n()).done) {
2396
+ _context24.next = 36;
1919
2397
  break;
1920
2398
  }
1921
- product = _step3.value;
2399
+ product = _step4.value;
1922
2400
  productUid = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.unique_identification_number;
1923
2401
  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
2402
  if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
1925
- _context18.next = 25;
2403
+ _context24.next = 25;
1926
2404
  break;
1927
2405
  }
1928
- return _context18.abrupt("continue", 33);
2406
+ return _context24.abrupt("continue", 34);
1929
2407
  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
- });
2408
+ product.discount_list = filterSelectedDiscountDetails(product.discount_list);
2409
+ if (Array.isArray(product.product_bundle)) {
2410
+ product.product_bundle = product.product_bundle.map(function (bundle) {
2411
+ var _ref21, _bundle$original_pric;
2412
+ var nextBundleDiscountList = filterSelectedDiscountDetails(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list);
2413
+ var shouldRestoreBundlePrice = nextBundleDiscountList.length === 0;
2414
+ var restoredBundlePrice = (_ref21 = (_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 && _ref21 !== void 0 ? _ref21 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
2415
+ return _objectSpread(_objectSpread(_objectSpread({}, bundle), shouldRestoreBundlePrice ? {
2416
+ price: restoredBundlePrice,
2417
+ bundle_selling_price: restoredBundlePrice
2418
+ } : {}), {}, {
2419
+ discount_list: nextBundleDiscountList
2420
+ });
2421
+ });
2422
+ }
1935
2423
 
1936
2424
  // 券作用于 source(不含 option、不含 bundle);算出新 source 折后价后补回 options
1937
2425
  // 写入含 option 的 main_product_selling_price,再合成 composite 回写 selling_price。
@@ -1950,33 +2438,33 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1950
2438
  mainPrice: newMainSellingPrice,
1951
2439
  bundle: product.product_bundle
1952
2440
  });
1953
- case 33:
1954
- _context18.next = 19;
2441
+ case 34:
2442
+ _context24.next = 19;
1955
2443
  break;
1956
- case 35:
1957
- _context18.next = 40;
2444
+ case 36:
2445
+ _context24.next = 41;
1958
2446
  break;
1959
- case 37:
1960
- _context18.prev = 37;
1961
- _context18.t0 = _context18["catch"](17);
1962
- _iterator3.e(_context18.t0);
1963
- case 40:
1964
- _context18.prev = 40;
1965
- _iterator3.f();
1966
- return _context18.finish(40);
1967
- case 43:
2447
+ case 38:
2448
+ _context24.prev = 38;
2449
+ _context24.t0 = _context24["catch"](17);
2450
+ _iterator4.e(_context24.t0);
2451
+ case 41:
2452
+ _context24.prev = 41;
2453
+ _iterator4.f();
2454
+ return _context24.finish(41);
2455
+ case 44:
1968
2456
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1969
- _context18.next = 46;
2457
+ _context24.next = 47;
1970
2458
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1971
- case 46:
2459
+ case 47:
1972
2460
  tempOrder.discount_list = (nextDiscountList || []).filter(function (d) {
1973
2461
  return d.isSelected;
1974
2462
  });
1975
- _context18.next = 49;
2463
+ _context24.next = 50;
1976
2464
  return this.store.order.recalculateSummary({
1977
2465
  createIfMissing: true
1978
2466
  });
1979
- case 49:
2467
+ case 50:
1980
2468
  this.store.order.persistTempOrder();
1981
2469
  this.effectsEmit('onDiscountApplied', {
1982
2470
  productList: tempOrder.products,
@@ -1984,19 +2472,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1984
2472
  selectedDiscountList: tempOrder.discount_list,
1985
2473
  tempOrder: tempOrder
1986
2474
  });
1987
- _context18.next = 56;
2475
+ _context24.next = 57;
1988
2476
  break;
1989
- case 53:
1990
- _context18.prev = 53;
1991
- _context18.t1 = _context18["catch"](0);
1992
- throw _context18.t1;
1993
- case 56:
2477
+ case 54:
2478
+ _context24.prev = 54;
2479
+ _context24.t1 = _context24["catch"](0);
2480
+ throw _context24.t1;
2481
+ case 57:
1994
2482
  case "end":
1995
- return _context18.stop();
2483
+ return _context24.stop();
1996
2484
  }
1997
- }, _callee18, this, [[0, 53], [17, 37, 40, 43]]);
2485
+ }, _callee24, this, [[0, 54], [17, 38, 41, 44]]);
1998
2486
  }));
1999
- function setDiscountSelected(_x14) {
2487
+ function setDiscountSelected(_x18) {
2000
2488
  return _setDiscountSelected.apply(this, arguments);
2001
2489
  }
2002
2490
  return setDiscountSelected;
@@ -2004,23 +2492,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2004
2492
  }, {
2005
2493
  key: "applyDiscountCalculationResult",
2006
2494
  value: function () {
2007
- var _applyDiscountCalculationResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(result) {
2495
+ var _applyDiscountCalculationResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(result) {
2008
2496
  var tempOrder, orderStore, discountModule;
2009
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2010
- while (1) switch (_context19.prev = _context19.next) {
2497
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2498
+ while (1) switch (_context25.prev = _context25.next) {
2011
2499
  case 0:
2012
- _context19.prev = 0;
2500
+ _context25.prev = 0;
2013
2501
  if (this.store.order) {
2014
- _context19.next = 3;
2502
+ _context25.next = 3;
2015
2503
  break;
2016
2504
  }
2017
2505
  throw new Error('order 模块未初始化');
2018
2506
  case 3:
2019
2507
  if (result) {
2020
- _context19.next = 5;
2508
+ _context25.next = 5;
2021
2509
  break;
2022
2510
  }
2023
- return _context19.abrupt("return");
2511
+ return _context25.abrupt("return");
2024
2512
  case 5:
2025
2513
  tempOrder = this.store.order.ensureTempOrder();
2026
2514
  orderStore = this.store.order.store || {};
@@ -2029,36 +2517,44 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2029
2517
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
2030
2518
  }
2031
2519
  if (!result.discountList) {
2032
- _context19.next = 14;
2520
+ _context25.next = 14;
2033
2521
  break;
2034
2522
  }
2035
2523
  OrderModule.populateSavedAmounts(tempOrder.products, result.discountList);
2036
- _context19.next = 13;
2524
+ _context25.next = 13;
2037
2525
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(result.discountList);
2038
2526
  case 13:
2039
2527
  tempOrder.discount_list = result.discountList.filter(function (discount) {
2040
2528
  return discount.isSelected;
2041
2529
  });
2042
2530
  case 14:
2043
- _context19.next = 16;
2531
+ _context25.next = 16;
2044
2532
  return this.store.order.recalculateSummary({
2045
2533
  createIfMissing: true
2046
2534
  });
2047
2535
  case 16:
2048
2536
  this.store.order.persistTempOrder();
2049
- _context19.next = 22;
2050
- break;
2537
+ _context25.next = 19;
2538
+ return this.effectsEmit('onDiscountApplied', {
2539
+ productList: tempOrder.products || [],
2540
+ discountList: result.discountList || [],
2541
+ selectedDiscountList: tempOrder.discount_list || [],
2542
+ tempOrder: tempOrder
2543
+ });
2051
2544
  case 19:
2052
- _context19.prev = 19;
2053
- _context19.t0 = _context19["catch"](0);
2054
- throw _context19.t0;
2055
- case 22:
2545
+ _context25.next = 24;
2546
+ break;
2547
+ case 21:
2548
+ _context25.prev = 21;
2549
+ _context25.t0 = _context25["catch"](0);
2550
+ throw _context25.t0;
2551
+ case 24:
2056
2552
  case "end":
2057
- return _context19.stop();
2553
+ return _context25.stop();
2058
2554
  }
2059
- }, _callee19, this, [[0, 19]]);
2555
+ }, _callee25, this, [[0, 21]]);
2060
2556
  }));
2061
- function applyDiscountCalculationResult(_x15) {
2557
+ function applyDiscountCalculationResult(_x19) {
2062
2558
  return _applyDiscountCalculationResult.apply(this, arguments);
2063
2559
  }
2064
2560
  return applyDiscountCalculationResult;
@@ -2066,18 +2562,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2066
2562
  }, {
2067
2563
  key: "submitScanOrder",
2068
2564
  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) {
2565
+ var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2566
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2567
+ while (1) switch (_context26.prev = _context26.next) {
2072
2568
  case 0:
2073
- return _context20.abrupt("return", this.submitSalesOrder(params));
2569
+ return _context26.abrupt("return", this.submitSalesOrder(params));
2074
2570
  case 1:
2075
2571
  case "end":
2076
- return _context20.stop();
2572
+ return _context26.stop();
2077
2573
  }
2078
- }, _callee20, this);
2574
+ }, _callee26, this);
2079
2575
  }));
2080
- function submitScanOrder(_x16) {
2576
+ function submitScanOrder(_x20) {
2081
2577
  return _submitScanOrder.apply(this, arguments);
2082
2578
  }
2083
2579
  return submitScanOrder;
@@ -2091,21 +2587,21 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2091
2587
  }, {
2092
2588
  key: "submitSalesOrder",
2093
2589
  value: (function () {
2094
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2590
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2095
2591
  var _this$otherParams6, _this$otherParams7, _this$otherParams8, _this$otherParams9;
2096
2592
  var inferredPaymentStatus, submitParams;
2097
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2098
- while (1) switch (_context21.prev = _context21.next) {
2593
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2594
+ while (1) switch (_context27.prev = _context27.next) {
2099
2595
  case 0:
2100
2596
  if (this.store.order) {
2101
- _context21.next = 2;
2597
+ _context27.next = 2;
2102
2598
  break;
2103
2599
  }
2104
2600
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2105
2601
  case 2:
2106
2602
  // this.store.order.persistTempOrder();
2107
2603
  inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
2108
- submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
2604
+ submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
2109
2605
  cacheId: this.cacheId,
2110
2606
  platform: (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform,
2111
2607
  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 +2614,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2118
2614
  paymentStatus: inferredPaymentStatus
2119
2615
  } : {}), (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined ? {
2120
2616
  smallTicketDataFlag: params.smallTicketDataFlag
2617
+ } : {}), (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== undefined ? {
2618
+ confirmPendingVoucherPayments: params.confirmPendingVoucherPayments
2121
2619
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2122
2620
  enhancePayload: params.enhancePayload
2123
2621
  } : {});
2124
- return _context21.abrupt("return", this.store.order.submitTempOrder(submitParams));
2622
+ return _context27.abrupt("return", this.store.order.submitTempOrder(submitParams));
2125
2623
  case 5:
2126
2624
  case "end":
2127
- return _context21.stop();
2625
+ return _context27.stop();
2128
2626
  }
2129
- }, _callee21, this);
2627
+ }, _callee27, this);
2130
2628
  }));
2131
- function submitSalesOrder(_x17) {
2629
+ function submitSalesOrder(_x21) {
2132
2630
  return _submitSalesOrder.apply(this, arguments);
2133
2631
  }
2134
2632
  return submitSalesOrder;
@@ -2136,20 +2634,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2136
2634
  }, {
2137
2635
  key: "submitTempOrderAsync",
2138
2636
  value: function () {
2139
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2637
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
2140
2638
  var _this$otherParams10, _this$otherParams11, _this$otherParams12, _this$otherParams13;
2141
2639
  var inferredPaymentStatus, submitParams;
2142
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2143
- while (1) switch (_context22.prev = _context22.next) {
2640
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2641
+ while (1) switch (_context28.prev = _context28.next) {
2144
2642
  case 0:
2145
2643
  if (this.store.order) {
2146
- _context22.next = 2;
2644
+ _context28.next = 2;
2147
2645
  break;
2148
2646
  }
2149
2647
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2150
2648
  case 2:
2151
2649
  inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
2152
- submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
2650
+ submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
2153
2651
  cacheId: this.cacheId,
2154
2652
  platform: (_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform,
2155
2653
  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 +2659,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2161
2659
  paymentStatus: inferredPaymentStatus
2162
2660
  } : {}), (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined ? {
2163
2661
  smallTicketDataFlag: params.smallTicketDataFlag
2662
+ } : {}), (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== undefined ? {
2663
+ confirmPendingVoucherPayments: params.confirmPendingVoucherPayments
2164
2664
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2165
2665
  enhancePayload: params.enhancePayload
2166
2666
  } : {});
2167
- return _context22.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2667
+ return _context28.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2168
2668
  case 5:
2169
2669
  case "end":
2170
- return _context22.stop();
2670
+ return _context28.stop();
2171
2671
  }
2172
- }, _callee22, this);
2672
+ }, _callee28, this);
2173
2673
  }));
2174
- function submitTempOrderAsync(_x18) {
2674
+ function submitTempOrderAsync(_x22) {
2175
2675
  return _submitTempOrderAsync.apply(this, arguments);
2176
2676
  }
2177
2677
  return submitTempOrderAsync;
@@ -2179,14 +2679,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2179
2679
  }, {
2180
2680
  key: "printLocalOrderReceipt",
2181
2681
  value: function () {
2182
- var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(lookup) {
2682
+ var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(lookup) {
2183
2683
  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) {
2684
+ var hasLookup, lookupPayload, context, payload, response, _this$store$order$app, _this$store$order5, _data;
2685
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2686
+ while (1) switch (_context29.prev = _context29.next) {
2187
2687
  case 0:
2188
2688
  if (this.store.order) {
2189
- _context23.next = 2;
2689
+ _context29.next = 2;
2190
2690
  break;
2191
2691
  }
2192
2692
  throw new Error('BaseSales 解决方案需要 order 模块支持');
@@ -2217,28 +2717,28 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2217
2717
  channel: context.channel,
2218
2718
  type: context.type
2219
2719
  });
2220
- _context23.next = 8;
2720
+ _context29.next = 8;
2221
2721
  return this.request.post('/local/print-order', payload, {
2222
2722
  osServer: true,
2223
2723
  customToast: function customToast() {}
2224
2724
  });
2225
2725
  case 8:
2226
- response = _context23.sent;
2726
+ response = _context29.sent;
2227
2727
  if (hasLookup) {
2228
- _context23.next = 12;
2728
+ _context29.next = 12;
2229
2729
  break;
2230
2730
  }
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);
2731
+ _context29.next = 12;
2732
+ return (_this$store$order$app = (_this$store$order5 = this.store.order).applyLocalPrintOrderNumbers) === null || _this$store$order$app === void 0 ? void 0 : _this$store$order$app.call(_this$store$order5, response === null || response === void 0 || (_data = response.data) === null || _data === void 0 ? void 0 : _data.order);
2233
2733
  case 12:
2234
- return _context23.abrupt("return", response);
2734
+ return _context29.abrupt("return", response);
2235
2735
  case 13:
2236
2736
  case "end":
2237
- return _context23.stop();
2737
+ return _context29.stop();
2238
2738
  }
2239
- }, _callee23, this);
2739
+ }, _callee29, this);
2240
2740
  }));
2241
- function printLocalOrderReceipt(_x19) {
2741
+ function printLocalOrderReceipt(_x23) {
2242
2742
  return _printLocalOrderReceipt.apply(this, arguments);
2243
2743
  }
2244
2744
  return printLocalOrderReceipt;
@@ -2246,9 +2746,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2246
2746
  }, {
2247
2747
  key: "getSubmitPaymentStatus",
2248
2748
  value: function getSubmitPaymentStatus(paymentStatus) {
2249
- var _this$store$order4, _this$store$order4$ge;
2749
+ var _this$store$order6, _this$store$order6$ge;
2250
2750
  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);
2751
+ var amountSnapshot = (_this$store$order6 = this.store.order) === null || _this$store$order6 === void 0 || (_this$store$order6$ge = _this$store$order6.getOrderAmountSnapshot) === null || _this$store$order6$ge === void 0 ? void 0 : _this$store$order6$ge.call(_this$store$order6);
2252
2752
  if (!amountSnapshot) return undefined;
2253
2753
  try {
2254
2754
  return new Decimal(amountSnapshot.amountGap || 0).lte(0) ? 'paid' : undefined;
@@ -2259,19 +2759,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2259
2759
  }, {
2260
2760
  key: "syncPaymentsToOrder",
2261
2761
  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) {
2762
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
2763
+ var _ref22, _params$businessCode, _this$otherParams18, _this$otherParams19, _params$channel;
2764
+ var businessCode, channel, syncParams, syncState, payments, syncResult, latestPayments, amountSnapshot, orderSnapshot, syncPayload;
2765
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2766
+ while (1) switch (_context30.prev = _context30.next) {
2267
2767
  case 0:
2268
2768
  if (this.store.order) {
2269
- _context24.next = 2;
2769
+ _context30.next = 2;
2270
2770
  break;
2271
2771
  }
2272
2772
  throw new Error('order 模块未初始化');
2273
2773
  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;
2774
+ businessCode = (_ref22 = (_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 && _ref22 !== void 0 ? _ref22 : (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.business_code;
2275
2775
  channel = (_params$channel = params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel();
2276
2776
  syncParams = _objectSpread(_objectSpread(_objectSpread({}, params), businessCode !== undefined ? {
2277
2777
  businessCode: businessCode
@@ -2280,57 +2780,77 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2280
2780
  } : {});
2281
2781
  syncState = this.store.order.getOrderSyncState();
2282
2782
  if (!(params.submitWhenPaid && syncState === 'submitting')) {
2283
- _context24.next = 8;
2783
+ _context30.next = 9;
2284
2784
  break;
2285
2785
  }
2286
- return _context24.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2287
- case 8:
2786
+ this.queueLatestAutoPaymentSync();
2787
+ return _context30.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2788
+ case 9:
2288
2789
  payments = params.payments || [];
2289
- _context24.next = 11;
2790
+ _context30.next = 12;
2290
2791
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncStart, {
2291
2792
  payments: payments,
2292
2793
  params: syncParams,
2293
2794
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
2294
2795
  orderSnapshot: this.store.order.getOrderSnapshot()
2295
2796
  });
2296
- case 11:
2297
- _context24.prev = 11;
2298
- _context24.next = 14;
2797
+ case 12:
2798
+ _context30.prev = 12;
2799
+ _context30.next = 15;
2299
2800
  return this.store.order.syncPaymentsToOrder(syncParams);
2300
- case 14:
2301
- syncResult = _context24.sent;
2302
- _context24.next = 17;
2303
- return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2801
+ case 15:
2802
+ syncResult = _context30.sent;
2803
+ latestPayments = this.store.order.getOrderPayments();
2804
+ amountSnapshot = this.store.order.getOrderAmountSnapshot();
2805
+ orderSnapshot = this.store.order.getOrderSnapshot();
2806
+ syncPayload = {
2304
2807
  ok: true,
2305
2808
  syncResult: syncResult,
2306
- payments: this.store.order.getOrderPayments(),
2809
+ payments: latestPayments,
2307
2810
  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;
2811
+ amountSnapshot: amountSnapshot,
2812
+ orderSnapshot: orderSnapshot,
2813
+ isFullyPaid: syncResult.isFullyPaid,
2814
+ isOrderFullyPaid: syncResult.isOrderFullyPaid,
2815
+ isDepositFullyPaid: syncResult.isDepositFullyPaid,
2816
+ paymentStage: syncResult.paymentStage,
2817
+ depositAmount: syncResult.depositAmount,
2818
+ orderExpectedAmount: syncResult.orderExpectedAmount
2819
+ };
2820
+ _context30.next = 22;
2821
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, syncPayload);
2822
+ case 22:
2823
+ if (!(syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid)) {
2824
+ _context30.next = 25;
2825
+ break;
2826
+ }
2827
+ _context30.next = 25;
2828
+ return this.effectsEmit(BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
2829
+ case 25:
2830
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
2831
+ return _context30.abrupt("return", syncResult);
2832
+ case 29:
2833
+ _context30.prev = 29;
2834
+ _context30.t0 = _context30["catch"](12);
2835
+ _context30.next = 33;
2317
2836
  return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2318
2837
  ok: false,
2319
- error: _context24.t0,
2838
+ error: _context30.t0,
2320
2839
  payments: this.store.order.getOrderPayments(),
2321
2840
  params: syncParams,
2322
2841
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
2323
2842
  orderSnapshot: this.store.order.getOrderSnapshot()
2324
2843
  });
2325
- case 24:
2326
- throw _context24.t0;
2327
- case 25:
2844
+ case 33:
2845
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
2846
+ throw _context30.t0;
2847
+ case 35:
2328
2848
  case "end":
2329
- return _context24.stop();
2849
+ return _context30.stop();
2330
2850
  }
2331
- }, _callee24, this, [[11, 20]]);
2851
+ }, _callee30, this, [[12, 29]]);
2332
2852
  }));
2333
- function syncPaymentsToOrder(_x20) {
2853
+ function syncPaymentsToOrder(_x24) {
2334
2854
  return _syncPaymentsToOrder.apply(this, arguments);
2335
2855
  }
2336
2856
  return syncPaymentsToOrder;
@@ -2350,17 +2870,120 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2350
2870
  if (!this.store.order) throw new Error('order 模块未初始化');
2351
2871
  return this.store.order.setOrderPayments(payments);
2352
2872
  }
2353
-
2354
- /** 追加单个支付项到当前订单。 */
2873
+ }, {
2874
+ key: "getPaymentStatusForSync",
2875
+ value: function getPaymentStatusForSync(payments) {
2876
+ var order = this.store.order;
2877
+ if (!order) throw new Error('order 模块未初始化');
2878
+ var completion = order.getPaymentCompletion(payments);
2879
+ return completion.isOrderFullyPaid ? 'paid' : 'partially_paid';
2880
+ }
2881
+ }, {
2882
+ key: "queueLatestAutoPaymentSync",
2883
+ value: function queueLatestAutoPaymentSync() {
2884
+ this.queuedAutoPaymentSync = true;
2885
+ this.scheduleQueuedAutoPaymentSyncFlush();
2886
+ }
2887
+ }, {
2888
+ key: "scheduleQueuedAutoPaymentSyncFlush",
2889
+ value: function scheduleQueuedAutoPaymentSyncFlush() {
2890
+ var _this11 = this;
2891
+ var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
2892
+ if (!this.queuedAutoPaymentSync) return;
2893
+ if (this.autoPaymentSyncTimer) return;
2894
+ this.autoPaymentSyncTimer = setTimeout(function () {
2895
+ _this11.autoPaymentSyncTimer = null;
2896
+ void _this11.flushQueuedAutoPaymentSync();
2897
+ }, delay);
2898
+ }
2899
+ }, {
2900
+ key: "flushQueuedAutoPaymentSync",
2901
+ value: function () {
2902
+ var _flushQueuedAutoPaymentSync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2903
+ var payments;
2904
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2905
+ while (1) switch (_context31.prev = _context31.next) {
2906
+ case 0:
2907
+ if (this.store.order) {
2908
+ _context31.next = 2;
2909
+ break;
2910
+ }
2911
+ return _context31.abrupt("return");
2912
+ case 2:
2913
+ if (!(!this.queuedAutoPaymentSync || this.autoPaymentSyncFlushing)) {
2914
+ _context31.next = 4;
2915
+ break;
2916
+ }
2917
+ return _context31.abrupt("return");
2918
+ case 4:
2919
+ if (!(this.store.order.getOrderSyncState() === 'submitting')) {
2920
+ _context31.next = 7;
2921
+ break;
2922
+ }
2923
+ this.scheduleQueuedAutoPaymentSyncFlush();
2924
+ return _context31.abrupt("return");
2925
+ case 7:
2926
+ this.autoPaymentSyncFlushing = true;
2927
+ _context31.prev = 8;
2928
+ case 9:
2929
+ if (!this.queuedAutoPaymentSync) {
2930
+ _context31.next = 18;
2931
+ break;
2932
+ }
2933
+ this.queuedAutoPaymentSync = false;
2934
+ payments = this.store.order.getOrderPayments();
2935
+ if (payments.length) {
2936
+ _context31.next = 14;
2937
+ break;
2938
+ }
2939
+ return _context31.abrupt("continue", 9);
2940
+ case 14:
2941
+ _context31.next = 16;
2942
+ return this.syncPaymentsToOrder({
2943
+ payments: payments,
2944
+ paymentStatus: this.getPaymentStatusForSync(payments),
2945
+ submitWhenPaid: true,
2946
+ smallTicketDataFlag: 1
2947
+ });
2948
+ case 16:
2949
+ _context31.next = 9;
2950
+ break;
2951
+ case 18:
2952
+ _context31.next = 23;
2953
+ break;
2954
+ case 20:
2955
+ _context31.prev = 20;
2956
+ _context31.t0 = _context31["catch"](8);
2957
+ this.logError('queued auto sync payments failed', {
2958
+ error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0)
2959
+ });
2960
+ case 23:
2961
+ _context31.prev = 23;
2962
+ this.autoPaymentSyncFlushing = false;
2963
+ if (this.queuedAutoPaymentSync) {
2964
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
2965
+ }
2966
+ return _context31.finish(23);
2967
+ case 27:
2968
+ case "end":
2969
+ return _context31.stop();
2970
+ }
2971
+ }, _callee31, this, [[8, 20, 23, 27]]);
2972
+ }));
2973
+ function flushQueuedAutoPaymentSync() {
2974
+ return _flushQueuedAutoPaymentSync.apply(this, arguments);
2975
+ }
2976
+ return flushQueuedAutoPaymentSync;
2977
+ }() /** 追加单个支付项到当前订单。 */
2355
2978
  }, {
2356
2979
  key: "addOrderPayment",
2357
2980
  value: function addOrderPayment(payment) {
2358
2981
  var _this$otherParams20,
2359
2982
  _paymentRecord$paymen,
2360
2983
  _paymentRecord$create,
2361
- _ref19,
2984
+ _ref23,
2362
2985
  _paymentRecord$origin,
2363
- _this8 = this;
2986
+ _this12 = this;
2364
2987
  if (!this.store.order) throw new Error('order 模块未初始化');
2365
2988
  var paymentRecord = payment;
2366
2989
  var paymentAmount = new Decimal(paymentRecord.amount || 0);
@@ -2382,7 +3005,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2382
3005
  var paymentTime = (_paymentRecord$paymen = paymentRecord.payment_time) !== null && _paymentRecord$paymen !== void 0 ? _paymentRecord$paymen : paymentTimestamp;
2383
3006
  var createdAt = (_paymentRecord$create = paymentRecord.created_at) !== null && _paymentRecord$create !== void 0 ? _paymentRecord$create : paymentTimestamp;
2384
3007
  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;
3008
+ var calculatedServiceFee = serviceCharge ? new Decimal((_ref23 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref23 !== void 0 ? _ref23 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
2386
3009
  var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, paymentRecord), calculatedServiceFee !== undefined ? {
2387
3010
  service_fee: calculatedServiceFee
2388
3011
  } : {}), {}, {
@@ -2392,19 +3015,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2392
3015
  }));
2393
3016
  var amountSnapshot = this.store.order.getOrderAmountSnapshot();
2394
3017
  var syncState = this.store.order.getOrderSyncState();
2395
- if (amountSnapshot && syncState !== 'submitting') {
2396
- var paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? 'paid' : 'partially_paid';
3018
+ if (amountSnapshot) {
3019
+ if (syncState === 'submitting') {
3020
+ this.queueLatestAutoPaymentSync();
3021
+ return payments;
3022
+ }
2397
3023
  void this.syncPaymentsToOrder({
2398
3024
  payments: payments,
2399
- paymentStatus: paymentStatus,
3025
+ paymentStatus: this.getPaymentStatusForSync(payments),
2400
3026
  submitWhenPaid: true,
2401
3027
  smallTicketDataFlag: 1
2402
3028
  }).catch(function (error) {
2403
- _this8.logError('auto sync payments failed', {
3029
+ _this12.logError('auto sync payments failed', {
2404
3030
  error: error instanceof Error ? error.message : String(error)
2405
3031
  });
2406
3032
  });
2407
- } else {}
3033
+ }
2408
3034
  return payments;
2409
3035
  }
2410
3036
 
@@ -2427,25 +3053,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2427
3053
  /** 覆盖 wallet pass 支付项,同时保留普通支付项。 */
2428
3054
  }, {
2429
3055
  key: "updateVoucherOrderPayments",
2430
- value: function updateVoucherOrderPayments(payments) {
3056
+ value: function updateVoucherOrderPayments(payments, options) {
3057
+ if (!this.store.order) throw new Error('order 模块未初始化');
3058
+ return this.store.order.updateVoucherOrderPayments(payments, options);
3059
+ }
3060
+ }, {
3061
+ key: "confirmPendingVoucherPayments",
3062
+ value: function confirmPendingVoucherPayments() {
3063
+ if (!this.store.order) throw new Error('order 模块未初始化');
3064
+ return this.store.order.confirmPendingVoucherPayments();
3065
+ }
3066
+ }, {
3067
+ key: "discardPendingVoucherPayments",
3068
+ value: function discardPendingVoucherPayments() {
2431
3069
  if (!this.store.order) throw new Error('order 模块未初始化');
2432
- return this.store.order.updateVoucherOrderPayments(payments);
3070
+ return this.store.order.discardPendingVoucherPayments();
2433
3071
  }
2434
3072
  }, {
2435
3073
  key: "getWalletProductList",
2436
3074
  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();
3075
+ var _this$store$order7, _tempOrder$products;
3076
+ var tempOrder = (_this$store$order7 = this.store.order) === null || _this$store$order7 === void 0 ? void 0 : _this$store$order7.getTempOrder();
2439
3077
  if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$products = tempOrder.products) !== null && _tempOrder$products !== void 0 && _tempOrder$products.length)) return [];
2440
3078
  // 过滤出有 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;
3079
+ // debugger
3080
+ // const products = tempOrder?.products?.filter(n => n.product_id)
3081
+
3082
+ var walletProducts = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.products.map(function (product) {
3083
+ var _product$holder_id, _product$product_vari2, _product$is_charge_ta, _metadata$main_produc, _metadata$main_produc2;
2446
3084
  var metadata = product.metadata || {};
3085
+ var rawHolderId = (_product$holder_id = product.holder_id) !== null && _product$holder_id !== void 0 ? _product$holder_id : metadata.holder_id;
3086
+ var holderIdValue = Array.isArray(rawHolderId) ? rawHolderId[0] : rawHolderId;
3087
+ var holder_id = Number.isInteger(Number(holderIdValue)) ? Number(holderIdValue) : undefined;
2447
3088
  return {
2448
- product_id: product.product_id,
3089
+ product_id: product.product_id || 0,
2449
3090
  product_variant_id: String((_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : ''),
2450
3091
  quantity: product.num || 1,
2451
3092
  is_price_include_tax: tempOrder.is_price_include_tax,
@@ -2453,7 +3094,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2453
3094
  tax_fee: product.tax_fee,
2454
3095
  selling_price: Number(product.selling_price || 0),
2455
3096
  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,
3097
+ holder_id: holder_id,
2457
3098
  original_price: product.original_price,
2458
3099
  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
3100
  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 +3133,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2492
3133
  }, {
2493
3134
  key: "initWalletData",
2494
3135
  value: function () {
2495
- var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
2496
- var _params$order_wait_pa, _ref20, _tempOrder$is_price_i;
3136
+ var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
3137
+ var _params$order_wait_pa, _ref24, _tempOrder$is_price_i;
2497
3138
  var snapshot, tempOrder, amount, walletBusinessData, result;
2498
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2499
- while (1) switch (_context25.prev = _context25.next) {
3139
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3140
+ while (1) switch (_context32.prev = _context32.next) {
2500
3141
  case 0:
2501
3142
  if (this.store.order) {
2502
- _context25.next = 2;
3143
+ _context32.next = 2;
2503
3144
  break;
2504
3145
  }
2505
3146
  throw new Error('order 模块未初始化');
2506
3147
  case 2:
2507
3148
  if (this.store.payment) {
2508
- _context25.next = 4;
3149
+ _context32.next = 4;
2509
3150
  break;
2510
3151
  }
2511
3152
  throw new Error('payment 模块未初始化');
@@ -2514,10 +3155,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2514
3155
  tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
2515
3156
  amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
2516
3157
  if (!(!tempOrder || !amount)) {
2517
- _context25.next = 9;
3158
+ _context32.next = 9;
2518
3159
  break;
2519
3160
  }
2520
- return _context25.abrupt("return", {
3161
+ return _context32.abrupt("return", {
2521
3162
  walletRecommendList: [],
2522
3163
  userIdentificationCodes: [],
2523
3164
  transformList: [],
@@ -2536,15 +3177,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2536
3177
  },
2537
3178
  products: this.getWalletProductList(),
2538
3179
  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
3180
+ is_price_include_tax: (_ref24 = (_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 && _ref24 !== void 0 ? _ref24 : 1
2540
3181
  }, snapshot.identity.orderId ? {
2541
3182
  payment_order_id: String(snapshot.identity.orderId)
2542
3183
  } : {});
2543
- _context25.next = 12;
3184
+ _context32.next = 12;
2544
3185
  return this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
2545
3186
  case 12:
2546
- result = _context25.sent;
2547
- _context25.next = 15;
3187
+ result = _context32.sent;
3188
+ _context32.next = 15;
2548
3189
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
2549
3190
  orderId: snapshot.identity.orderId,
2550
3191
  customerId: walletBusinessData.customer_id,
@@ -2556,14 +3197,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2556
3197
  timestamp: Date.now()
2557
3198
  });
2558
3199
  case 15:
2559
- return _context25.abrupt("return", result);
3200
+ return _context32.abrupt("return", result);
2560
3201
  case 16:
2561
3202
  case "end":
2562
- return _context25.stop();
3203
+ return _context32.stop();
2563
3204
  }
2564
- }, _callee25, this);
3205
+ }, _callee32, this);
2565
3206
  }));
2566
- function initWalletData(_x21) {
3207
+ function initWalletData(_x25) {
2567
3208
  return _initWalletData.apply(this, arguments);
2568
3209
  }
2569
3210
  return initWalletData;
@@ -2590,35 +3231,35 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2590
3231
  }, {
2591
3232
  key: "getPaymentMethodsAsync",
2592
3233
  value: (function () {
2593
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
3234
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2594
3235
  var response, paymentMethods;
2595
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2596
- while (1) switch (_context26.prev = _context26.next) {
3236
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3237
+ while (1) switch (_context33.prev = _context33.next) {
2597
3238
  case 0:
2598
- _context26.prev = 0;
2599
- _context26.next = 3;
3239
+ _context33.prev = 0;
3240
+ _context33.next = 3;
2600
3241
  return this.request.get('/pay/custom-payment/all', {
2601
3242
  filterPaymentMethods: true
2602
3243
  }, {
2603
3244
  osServer: true
2604
3245
  });
2605
3246
  case 3:
2606
- response = _context26.sent;
3247
+ response = _context33.sent;
2607
3248
  paymentMethods = (response === null || response === void 0 ? void 0 : response.data) || [];
2608
3249
  this.paymentMethodsCache = Array.isArray(paymentMethods) ? _toConsumableArray(paymentMethods) : [];
2609
- return _context26.abrupt("return", this.getPaymentMethods());
3250
+ return _context33.abrupt("return", this.getPaymentMethods());
2610
3251
  case 9:
2611
- _context26.prev = 9;
2612
- _context26.t0 = _context26["catch"](0);
3252
+ _context33.prev = 9;
3253
+ _context33.t0 = _context33["catch"](0);
2613
3254
  this.logWarning('getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表', {
2614
- error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0)
3255
+ error: _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0)
2615
3256
  });
2616
- return _context26.abrupt("return", this.getPaymentMethods());
3257
+ return _context33.abrupt("return", this.getPaymentMethods());
2617
3258
  case 13:
2618
3259
  case "end":
2619
- return _context26.stop();
3260
+ return _context33.stop();
2620
3261
  }
2621
- }, _callee26, this, [[0, 9]]);
3262
+ }, _callee33, this, [[0, 9]]);
2622
3263
  }));
2623
3264
  function getPaymentMethodsAsync() {
2624
3265
  return _getPaymentMethodsAsync.apply(this, arguments);
@@ -2666,49 +3307,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2666
3307
  }, {
2667
3308
  key: "sendCustomerPayLink",
2668
3309
  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) {
3310
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
3311
+ var orderIds, _ref25, _ref26, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
3312
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3313
+ while (1) switch (_context34.prev = _context34.next) {
2673
3314
  case 0:
2674
3315
  if (this.store.order) {
2675
- _context27.next = 2;
3316
+ _context34.next = 2;
2676
3317
  break;
2677
3318
  }
2678
3319
  throw new Error('order 模块未初始化');
2679
3320
  case 2:
2680
3321
  orderIds = params.order_ids || params.orderIds || [];
2681
3322
  if (!(!orderIds.length || params.submitBeforeSend)) {
2682
- _context27.next = 11;
3323
+ _context34.next = 11;
2683
3324
  break;
2684
3325
  }
2685
- _context27.next = 6;
3326
+ _context34.next = 6;
2686
3327
  return this.submitSalesOrder({
2687
3328
  smallTicketDataFlag: 1
2688
3329
  });
2689
3330
  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;
3331
+ submitResult = _context34.sent;
3332
+ orderId = (_ref25 = (_ref26 = (_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 && _ref26 !== void 0 ? _ref26 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref25 !== void 0 ? _ref25 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
2692
3333
  if (orderId) {
2693
- _context27.next = 10;
3334
+ _context34.next = 10;
2694
3335
  break;
2695
3336
  }
2696
3337
  throw new Error('本地订单提交云端失败,无法发送支付链接');
2697
3338
  case 10:
2698
3339
  orderIds = [orderId];
2699
3340
  case 11:
2700
- return _context27.abrupt("return", this.store.order.sendCustomerPayLink({
3341
+ return _context34.abrupt("return", this.store.order.sendCustomerPayLink({
2701
3342
  emails: params.emails,
2702
3343
  notify_action: params.notify_action,
2703
3344
  order_ids: orderIds
2704
3345
  }));
2705
3346
  case 12:
2706
3347
  case "end":
2707
- return _context27.stop();
3348
+ return _context34.stop();
2708
3349
  }
2709
- }, _callee27, this);
3350
+ }, _callee34, this);
2710
3351
  }));
2711
- function sendCustomerPayLink(_x22) {
3352
+ function sendCustomerPayLink(_x26) {
2712
3353
  return _sendCustomerPayLink.apply(this, arguments);
2713
3354
  }
2714
3355
  return sendCustomerPayLink;
@@ -2721,27 +3362,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2721
3362
  }, {
2722
3363
  key: "calculateProductBookingPrice",
2723
3364
  value: function () {
2724
- var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
3365
+ var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
2725
3366
  var _params$customer_id;
2726
3367
  var quotation, customerId, authoritativeProduct, product;
2727
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2728
- while (1) switch (_context28.prev = _context28.next) {
3368
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3369
+ while (1) switch (_context35.prev = _context35.next) {
2729
3370
  case 0:
2730
3371
  quotation = this.store.quotation;
2731
3372
  customerId = (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : this.getCurrentOrderCustomerId();
2732
- _context28.next = 4;
3373
+ _context35.next = 4;
2733
3374
  return this.loadProductForPriceQuery(params, customerId);
2734
3375
  case 4:
2735
- authoritativeProduct = _context28.sent;
3376
+ authoritativeProduct = _context35.sent;
2736
3377
  product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
2737
- _context28.next = 8;
3378
+ _context35.next = 8;
2738
3379
  return this.loadQuotationForPriceQuery({
2739
3380
  quotation: quotation,
2740
3381
  customer_id: customerId,
2741
3382
  channel: params.channel
2742
3383
  });
2743
3384
  case 8:
2744
- return _context28.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
3385
+ return _context35.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
2745
3386
  product: product,
2746
3387
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
2747
3388
  customer_id: customerId,
@@ -2749,11 +3390,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2749
3390
  })));
2750
3391
  case 9:
2751
3392
  case "end":
2752
- return _context28.stop();
3393
+ return _context35.stop();
2753
3394
  }
2754
- }, _callee28, this);
3395
+ }, _callee35, this);
2755
3396
  }));
2756
- function calculateProductBookingPrice(_x23) {
3397
+ function calculateProductBookingPrice(_x27) {
2757
3398
  return _calculateProductBookingPrice.apply(this, arguments);
2758
3399
  }
2759
3400
  return calculateProductBookingPrice;
@@ -2761,7 +3402,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2761
3402
  }, {
2762
3403
  key: "getQuotationCustomerScopeInfo",
2763
3404
  value: function getQuotationCustomerScopeInfo() {
2764
- var _this9 = this;
3405
+ var _this13 = this;
2765
3406
  var quotation = this.store.quotation;
2766
3407
  if (quotation && typeof quotation.getQuotationCustomerScopeInfo === 'function') {
2767
3408
  return quotation.getQuotationCustomerScopeInfo();
@@ -2773,7 +3414,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2773
3414
  }).map(function (item) {
2774
3415
  var localSeen = new Set();
2775
3416
  var customers = item.customer.filter(function (customer) {
2776
- var customerId = _this9.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
3417
+ var customerId = _this13.normalizePriceContextCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
2777
3418
  if (!customerId || localSeen.has(customerId)) return false;
2778
3419
  localSeen.add(customerId);
2779
3420
  if (!customerById.has(customerId)) customerById.set(customerId, customer);
@@ -2823,32 +3464,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2823
3464
  }, {
2824
3465
  key: "calculateProductBookingPrices",
2825
3466
  value: function () {
2826
- var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(paramsList) {
3467
+ var _calculateProductBookingPrices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(paramsList) {
2827
3468
  var _paramsList$0$custome,
2828
3469
  _paramsList$,
2829
- _this10 = this,
3470
+ _this14 = this,
2830
3471
  _paramsList$2;
2831
3472
  var quotation, customerId, productMapsByGroup, groups;
2832
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2833
- while (1) switch (_context30.prev = _context30.next) {
3473
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3474
+ while (1) switch (_context37.prev = _context37.next) {
2834
3475
  case 0:
2835
3476
  if (paramsList.length) {
2836
- _context30.next = 2;
3477
+ _context37.next = 2;
2837
3478
  break;
2838
3479
  }
2839
- return _context30.abrupt("return", []);
3480
+ return _context37.abrupt("return", []);
2840
3481
  case 2:
2841
3482
  quotation = this.store.quotation;
2842
3483
  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
3484
  productMapsByGroup = new Map();
2844
3485
  groups = new Map();
2845
3486
  paramsList.forEach(function (params) {
2846
- var _this10$otherParams;
3487
+ var _this14$otherParams;
2847
3488
  var product = params.product || {};
2848
- var productId = _this10.getPriceQueryProductId(product);
3489
+ var productId = _this14.getPriceQueryProductId(product);
2849
3490
  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);
3491
+ var schedule = _this14.getPriceQuerySchedule(params);
3492
+ var channel = params.channel || ((_this14$otherParams = _this14.otherParams) === null || _this14$otherParams === void 0 ? void 0 : _this14$otherParams.channel);
2852
3493
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
2853
3494
  var group = groups.get(groupKey) || {
2854
3495
  ids: new Set(),
@@ -2858,51 +3499,51 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2858
3499
  group.ids.add(productId);
2859
3500
  groups.set(groupKey, group);
2860
3501
  });
2861
- _context30.next = 9;
3502
+ _context37.next = 9;
2862
3503
  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) {
3504
+ var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(_ref27) {
3505
+ var _ref29, groupKey, group, productsById;
3506
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3507
+ while (1) switch (_context36.prev = _context36.next) {
2867
3508
  case 0:
2868
- _ref25 = _slicedToArray(_ref23, 2), groupKey = _ref25[0], group = _ref25[1];
2869
- _context29.next = 3;
2870
- return _this10.loadProductsForPriceQuery({
3509
+ _ref29 = _slicedToArray(_ref27, 2), groupKey = _ref29[0], group = _ref29[1];
3510
+ _context36.next = 3;
3511
+ return _this14.loadProductsForPriceQuery({
2871
3512
  ids: Array.from(group.ids),
2872
3513
  schedule: group.schedule,
2873
3514
  customerId: customerId,
2874
3515
  channel: group.channel
2875
3516
  });
2876
3517
  case 3:
2877
- productsById = _context29.sent;
3518
+ productsById = _context36.sent;
2878
3519
  productMapsByGroup.set(groupKey, productsById);
2879
3520
  case 5:
2880
3521
  case "end":
2881
- return _context29.stop();
3522
+ return _context36.stop();
2882
3523
  }
2883
- }, _callee29);
3524
+ }, _callee36);
2884
3525
  }));
2885
- return function (_x25) {
2886
- return _ref24.apply(this, arguments);
3526
+ return function (_x29) {
3527
+ return _ref28.apply(this, arguments);
2887
3528
  };
2888
3529
  }()));
2889
3530
  case 9:
2890
- _context30.next = 11;
3531
+ _context37.next = 11;
2891
3532
  return this.loadQuotationForPriceQuery({
2892
3533
  quotation: quotation,
2893
3534
  customer_id: customerId,
2894
3535
  channel: (_paramsList$2 = paramsList[0]) === null || _paramsList$2 === void 0 ? void 0 : _paramsList$2.channel
2895
3536
  });
2896
3537
  case 11:
2897
- return _context30.abrupt("return", paramsList.map(function (params) {
2898
- var _this10$otherParams2, _productMapsByGroup$g;
3538
+ return _context37.abrupt("return", paramsList.map(function (params) {
3539
+ var _this14$otherParams2, _productMapsByGroup$g;
2899
3540
  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);
3541
+ var productId = _this14.getPriceQueryProductId(productInput);
3542
+ var schedule = _this14.getPriceQuerySchedule(params);
3543
+ var channel = params.channel || ((_this14$otherParams2 = _this14.otherParams) === null || _this14$otherParams2 === void 0 ? void 0 : _this14$otherParams2.channel);
2903
3544
  var groupKey = [schedule.schedule_date, schedule.schedule_datetime, channel || ''].join('|');
2904
3545
  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);
3546
+ var product = _this14.mergeProductForPriceQuery(productInput, authoritativeProduct);
2906
3547
  return calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
2907
3548
  product: product,
2908
3549
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
@@ -2912,11 +3553,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2912
3553
  }));
2913
3554
  case 12:
2914
3555
  case "end":
2915
- return _context30.stop();
3556
+ return _context37.stop();
2916
3557
  }
2917
- }, _callee30, this);
3558
+ }, _callee37, this);
2918
3559
  }));
2919
- function calculateProductBookingPrices(_x24) {
3560
+ function calculateProductBookingPrices(_x28) {
2920
3561
  return _calculateProductBookingPrices.apply(this, arguments);
2921
3562
  }
2922
3563
  return calculateProductBookingPrices;
@@ -2924,34 +3565,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2924
3565
  }, {
2925
3566
  key: "addProductToOrder",
2926
3567
  value: function () {
2927
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(product, booking) {
3568
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(product, booking) {
2928
3569
  var products;
2929
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2930
- while (1) switch (_context31.prev = _context31.next) {
3570
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3571
+ while (1) switch (_context38.prev = _context38.next) {
2931
3572
  case 0:
2932
- _context31.prev = 0;
3573
+ _context38.prev = 0;
2933
3574
  if (this.store.order) {
2934
- _context31.next = 3;
3575
+ _context38.next = 3;
2935
3576
  break;
2936
3577
  }
2937
3578
  throw new Error('order 模块未初始化');
2938
3579
  case 3:
2939
- _context31.next = 5;
3580
+ _context38.next = 5;
2940
3581
  return this.store.order.addProductToOrder(product, booking);
2941
3582
  case 5:
2942
- products = _context31.sent;
2943
- return _context31.abrupt("return", products);
3583
+ products = _context38.sent;
3584
+ return _context38.abrupt("return", products);
2944
3585
  case 9:
2945
- _context31.prev = 9;
2946
- _context31.t0 = _context31["catch"](0);
2947
- throw _context31.t0;
3586
+ _context38.prev = 9;
3587
+ _context38.t0 = _context38["catch"](0);
3588
+ throw _context38.t0;
2948
3589
  case 12:
2949
3590
  case "end":
2950
- return _context31.stop();
3591
+ return _context38.stop();
2951
3592
  }
2952
- }, _callee31, this, [[0, 9]]);
3593
+ }, _callee38, this, [[0, 9]]);
2953
3594
  }));
2954
- function addProductToOrder(_x26, _x27) {
3595
+ function addProductToOrder(_x30, _x31) {
2955
3596
  return _addProductToOrder.apply(this, arguments);
2956
3597
  }
2957
3598
  return addProductToOrder;
@@ -2959,34 +3600,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2959
3600
  }, {
2960
3601
  key: "updateOrderProduct",
2961
3602
  value: function () {
2962
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
3603
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
2963
3604
  var products;
2964
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2965
- while (1) switch (_context32.prev = _context32.next) {
3605
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3606
+ while (1) switch (_context39.prev = _context39.next) {
2966
3607
  case 0:
2967
- _context32.prev = 0;
3608
+ _context39.prev = 0;
2968
3609
  if (this.store.order) {
2969
- _context32.next = 3;
3610
+ _context39.next = 3;
2970
3611
  break;
2971
3612
  }
2972
3613
  throw new Error('order 模块未初始化');
2973
3614
  case 3:
2974
- _context32.next = 5;
3615
+ _context39.next = 5;
2975
3616
  return this.store.order.updateOrderProduct(params);
2976
3617
  case 5:
2977
- products = _context32.sent;
2978
- return _context32.abrupt("return", products);
3618
+ products = _context39.sent;
3619
+ return _context39.abrupt("return", products);
2979
3620
  case 9:
2980
- _context32.prev = 9;
2981
- _context32.t0 = _context32["catch"](0);
2982
- throw _context32.t0;
3621
+ _context39.prev = 9;
3622
+ _context39.t0 = _context39["catch"](0);
3623
+ throw _context39.t0;
2983
3624
  case 12:
2984
3625
  case "end":
2985
- return _context32.stop();
3626
+ return _context39.stop();
2986
3627
  }
2987
- }, _callee32, this, [[0, 9]]);
3628
+ }, _callee39, this, [[0, 9]]);
2988
3629
  }));
2989
- function updateOrderProduct(_x28) {
3630
+ function updateOrderProduct(_x32) {
2990
3631
  return _updateOrderProduct.apply(this, arguments);
2991
3632
  }
2992
3633
  return updateOrderProduct;
@@ -2994,34 +3635,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2994
3635
  }, {
2995
3636
  key: "updateOrderProducts",
2996
3637
  value: function () {
2997
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(paramsList) {
3638
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(paramsList) {
2998
3639
  var products;
2999
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3000
- while (1) switch (_context33.prev = _context33.next) {
3640
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3641
+ while (1) switch (_context40.prev = _context40.next) {
3001
3642
  case 0:
3002
- _context33.prev = 0;
3643
+ _context40.prev = 0;
3003
3644
  if (this.store.order) {
3004
- _context33.next = 3;
3645
+ _context40.next = 3;
3005
3646
  break;
3006
3647
  }
3007
3648
  throw new Error('order 模块未初始化');
3008
3649
  case 3:
3009
- _context33.next = 5;
3650
+ _context40.next = 5;
3010
3651
  return this.store.order.updateOrderProducts(paramsList);
3011
3652
  case 5:
3012
- products = _context33.sent;
3013
- return _context33.abrupt("return", products);
3653
+ products = _context40.sent;
3654
+ return _context40.abrupt("return", products);
3014
3655
  case 9:
3015
- _context33.prev = 9;
3016
- _context33.t0 = _context33["catch"](0);
3017
- throw _context33.t0;
3656
+ _context40.prev = 9;
3657
+ _context40.t0 = _context40["catch"](0);
3658
+ throw _context40.t0;
3018
3659
  case 12:
3019
3660
  case "end":
3020
- return _context33.stop();
3661
+ return _context40.stop();
3021
3662
  }
3022
- }, _callee33, this, [[0, 9]]);
3663
+ }, _callee40, this, [[0, 9]]);
3023
3664
  }));
3024
- function updateOrderProducts(_x29) {
3665
+ function updateOrderProducts(_x33) {
3025
3666
  return _updateOrderProducts.apply(this, arguments);
3026
3667
  }
3027
3668
  return updateOrderProducts;
@@ -3029,34 +3670,34 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3029
3670
  }, {
3030
3671
  key: "updateOrderProductQuantity",
3031
3672
  value: function () {
3032
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
3673
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
3033
3674
  var products;
3034
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3035
- while (1) switch (_context34.prev = _context34.next) {
3675
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3676
+ while (1) switch (_context41.prev = _context41.next) {
3036
3677
  case 0:
3037
- _context34.prev = 0;
3678
+ _context41.prev = 0;
3038
3679
  if (this.store.order) {
3039
- _context34.next = 3;
3680
+ _context41.next = 3;
3040
3681
  break;
3041
3682
  }
3042
3683
  throw new Error('order 模块未初始化');
3043
3684
  case 3:
3044
- _context34.next = 5;
3685
+ _context41.next = 5;
3045
3686
  return this.store.order.updateOrderProductQuantity(params);
3046
3687
  case 5:
3047
- products = _context34.sent;
3048
- return _context34.abrupt("return", products);
3688
+ products = _context41.sent;
3689
+ return _context41.abrupt("return", products);
3049
3690
  case 9:
3050
- _context34.prev = 9;
3051
- _context34.t0 = _context34["catch"](0);
3052
- throw _context34.t0;
3691
+ _context41.prev = 9;
3692
+ _context41.t0 = _context41["catch"](0);
3693
+ throw _context41.t0;
3053
3694
  case 12:
3054
3695
  case "end":
3055
- return _context34.stop();
3696
+ return _context41.stop();
3056
3697
  }
3057
- }, _callee34, this, [[0, 9]]);
3698
+ }, _callee41, this, [[0, 9]]);
3058
3699
  }));
3059
- function updateOrderProductQuantity(_x30) {
3700
+ function updateOrderProductQuantity(_x34) {
3060
3701
  return _updateOrderProductQuantity.apply(this, arguments);
3061
3702
  }
3062
3703
  return updateOrderProductQuantity;
@@ -3079,12 +3720,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3079
3720
  }, {
3080
3721
  key: "setOrderProductLineNote",
3081
3722
  value: (function () {
3082
- var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(identity, note) {
3723
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(identity, note) {
3083
3724
  var params, products;
3084
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3085
- while (1) switch (_context35.prev = _context35.next) {
3725
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3726
+ while (1) switch (_context42.prev = _context42.next) {
3086
3727
  case 0:
3087
- _context35.prev = 0;
3728
+ _context42.prev = 0;
3088
3729
  params = {
3089
3730
  product_id: identity.product_id,
3090
3731
  product_variant_id: identity.product_variant_id,
@@ -3099,22 +3740,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3099
3740
  params.product_sku = identity.product_sku;
3100
3741
  }
3101
3742
  if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
3102
- _context35.next = 7;
3743
+ _context42.next = 7;
3103
3744
  return this.updateOrderProduct(params);
3104
3745
  case 7:
3105
- products = _context35.sent;
3106
- return _context35.abrupt("return", products);
3746
+ products = _context42.sent;
3747
+ return _context42.abrupt("return", products);
3107
3748
  case 11:
3108
- _context35.prev = 11;
3109
- _context35.t0 = _context35["catch"](0);
3110
- throw _context35.t0;
3749
+ _context42.prev = 11;
3750
+ _context42.t0 = _context42["catch"](0);
3751
+ throw _context42.t0;
3111
3752
  case 14:
3112
3753
  case "end":
3113
- return _context35.stop();
3754
+ return _context42.stop();
3114
3755
  }
3115
- }, _callee35, this, [[0, 11]]);
3756
+ }, _callee42, this, [[0, 11]]);
3116
3757
  }));
3117
- function setOrderProductLineNote(_x31, _x32) {
3758
+ function setOrderProductLineNote(_x35, _x36) {
3118
3759
  return _setOrderProductLineNote.apply(this, arguments);
3119
3760
  }
3120
3761
  return setOrderProductLineNote;
@@ -3129,32 +3770,32 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3129
3770
  }, {
3130
3771
  key: "removeProductsFromOrder",
3131
3772
  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) {
3773
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(identities) {
3774
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3775
+ while (1) switch (_context43.prev = _context43.next) {
3135
3776
  case 0:
3136
- _context36.prev = 0;
3777
+ _context43.prev = 0;
3137
3778
  if (this.store.order) {
3138
- _context36.next = 3;
3779
+ _context43.next = 3;
3139
3780
  break;
3140
3781
  }
3141
3782
  throw new Error('order 模块未初始化');
3142
3783
  case 3:
3143
- _context36.next = 5;
3784
+ _context43.next = 5;
3144
3785
  return this.store.order.removeProductsFromOrder(identities);
3145
3786
  case 5:
3146
- return _context36.abrupt("return", _context36.sent);
3787
+ return _context43.abrupt("return", _context43.sent);
3147
3788
  case 8:
3148
- _context36.prev = 8;
3149
- _context36.t0 = _context36["catch"](0);
3150
- throw _context36.t0;
3789
+ _context43.prev = 8;
3790
+ _context43.t0 = _context43["catch"](0);
3791
+ throw _context43.t0;
3151
3792
  case 11:
3152
3793
  case "end":
3153
- return _context36.stop();
3794
+ return _context43.stop();
3154
3795
  }
3155
- }, _callee36, this, [[0, 8]]);
3796
+ }, _callee43, this, [[0, 8]]);
3156
3797
  }));
3157
- function removeProductsFromOrder(_x33) {
3798
+ function removeProductsFromOrder(_x37) {
3158
3799
  return _removeProductsFromOrder.apply(this, arguments);
3159
3800
  }
3160
3801
  return removeProductsFromOrder;
@@ -3162,18 +3803,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3162
3803
  }, {
3163
3804
  key: "removeProductFromOrder",
3164
3805
  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) {
3806
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(identity) {
3807
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3808
+ while (1) switch (_context44.prev = _context44.next) {
3168
3809
  case 0:
3169
- return _context37.abrupt("return", this.removeProductsFromOrder([identity]));
3810
+ return _context44.abrupt("return", this.removeProductsFromOrder([identity]));
3170
3811
  case 1:
3171
3812
  case "end":
3172
- return _context37.stop();
3813
+ return _context44.stop();
3173
3814
  }
3174
- }, _callee37, this);
3815
+ }, _callee44, this);
3175
3816
  }));
3176
- function removeProductFromOrder(_x34) {
3817
+ function removeProductFromOrder(_x38) {
3177
3818
  return _removeProductFromOrder.apply(this, arguments);
3178
3819
  }
3179
3820
  return removeProductFromOrder;
@@ -3223,23 +3864,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3223
3864
  }, {
3224
3865
  key: "applyPromotion",
3225
3866
  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) {
3867
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45() {
3868
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
3869
+ while (1) switch (_context45.prev = _context45.next) {
3229
3870
  case 0:
3230
3871
  if (this.store.order) {
3231
- _context38.next = 2;
3872
+ _context45.next = 2;
3232
3873
  break;
3233
3874
  }
3234
3875
  throw new Error('order 模块未初始化');
3235
3876
  case 2:
3236
- _context38.next = 4;
3877
+ _context45.next = 4;
3237
3878
  return this.store.order.applyPromotion();
3238
3879
  case 4:
3239
3880
  case "end":
3240
- return _context38.stop();
3881
+ return _context45.stop();
3241
3882
  }
3242
- }, _callee38, this);
3883
+ }, _callee45, this);
3243
3884
  }));
3244
3885
  function applyPromotion() {
3245
3886
  return _applyPromotion.apply(this, arguments);
@@ -3249,16 +3890,16 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3249
3890
  }, {
3250
3891
  key: "getUnfulfilledPromotions",
3251
3892
  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()) || [];
3893
+ var _this$store$order8;
3894
+ return ((_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 ? void 0 : _this$store$order8.getUnfulfilledPromotions()) || [];
3254
3895
  }
3255
3896
 
3256
3897
  /** 最近一次促销计算输出的赠品操作 diff。 */
3257
3898
  }, {
3258
3899
  key: "getLastGiftActions",
3259
3900
  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;
3901
+ var _this$store$order9;
3902
+ return ((_this$store$order9 = this.store.order) === null || _this$store$order9 === void 0 ? void 0 : _this$store$order9.getLastGiftActions()) || null;
3262
3903
  }
3263
3904
 
3264
3905
  // 获取商品列表
@@ -3266,18 +3907,18 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3266
3907
  }, {
3267
3908
  key: "getProductList",
3268
3909
  value: function () {
3269
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3910
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
3270
3911
  var _this$otherParams21;
3271
3912
  var menu_list_ids, _this$store$products, res;
3272
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3273
- while (1) switch (_context39.prev = _context39.next) {
3913
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3914
+ while (1) switch (_context46.prev = _context46.next) {
3274
3915
  case 0:
3275
3916
  // 可以直接通过配置里的 menu 读取
3276
3917
  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
3918
  return Number(n.value);
3278
3919
  })) || [];
3279
- _context39.prev = 1;
3280
- _context39.next = 4;
3920
+ _context46.prev = 1;
3921
+ _context46.next = 4;
3281
3922
  return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
3282
3923
  menu_list_ids: menu_list_ids,
3283
3924
  cacheId: this.cacheId,
@@ -3285,17 +3926,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3285
3926
  schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
3286
3927
  });
3287
3928
  case 4:
3288
- res = _context39.sent;
3289
- return _context39.abrupt("return", res);
3929
+ res = _context46.sent;
3930
+ return _context46.abrupt("return", res);
3290
3931
  case 8:
3291
- _context39.prev = 8;
3292
- _context39.t0 = _context39["catch"](1);
3293
- throw _context39.t0;
3932
+ _context46.prev = 8;
3933
+ _context46.t0 = _context46["catch"](1);
3934
+ throw _context46.t0;
3294
3935
  case 11:
3295
3936
  case "end":
3296
- return _context39.stop();
3937
+ return _context46.stop();
3297
3938
  }
3298
- }, _callee39, this, [[1, 8]]);
3939
+ }, _callee46, this, [[1, 8]]);
3299
3940
  }));
3300
3941
  function getProductList() {
3301
3942
  return _getProductList.apply(this, arguments);
@@ -3310,33 +3951,33 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
3310
3951
  }, {
3311
3952
  key: "setOtherParams",
3312
3953
  value: function () {
3313
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3954
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(params) {
3314
3955
  var _this$otherParams22;
3315
- var _ref26,
3316
- _ref26$cover,
3956
+ var _ref30,
3957
+ _ref30$cover,
3317
3958
  cover,
3318
- _args40 = arguments;
3319
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3320
- while (1) switch (_context40.prev = _context40.next) {
3959
+ _args47 = arguments;
3960
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
3961
+ while (1) switch (_context47.prev = _context47.next) {
3321
3962
  case 0:
3322
- _ref26 = _args40.length > 1 && _args40[1] !== undefined ? _args40[1] : {}, _ref26$cover = _ref26.cover, cover = _ref26$cover === void 0 ? false : _ref26$cover;
3963
+ _ref30 = _args47.length > 1 && _args47[1] !== undefined ? _args47[1] : {}, _ref30$cover = _ref30.cover, cover = _ref30$cover === void 0 ? false : _ref30$cover;
3323
3964
  if (cover) {
3324
3965
  this.otherParams = _objectSpread({}, params);
3325
3966
  } else {
3326
3967
  this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
3327
3968
  }
3328
3969
  this.cacheId = (_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22.cacheId;
3329
- _context40.next = 5;
3970
+ _context47.next = 5;
3330
3971
  return this.syncOtherParamsToSubModules(params, {
3331
3972
  cover: cover
3332
3973
  });
3333
3974
  case 5:
3334
3975
  case "end":
3335
- return _context40.stop();
3976
+ return _context47.stop();
3336
3977
  }
3337
- }, _callee40, this);
3978
+ }, _callee47, this);
3338
3979
  }));
3339
- function setOtherParams(_x35) {
3980
+ function setOtherParams(_x39) {
3340
3981
  return _setOtherParams.apply(this, arguments);
3341
3982
  }
3342
3983
  return setOtherParams;