@pisell/pisellos 2.2.268 → 2.2.269

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 (120) hide show
  1. package/dist/core/index.d.ts +2 -0
  2. package/dist/core/index.js +7 -0
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  12. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  13. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +12 -10
  14. package/dist/modules/OpenData/index.d.ts +2 -0
  15. package/dist/modules/OpenData/index.js +8 -0
  16. package/dist/modules/Order/index.d.ts +28 -8
  17. package/dist/modules/Order/index.js +813 -498
  18. package/dist/modules/Order/payment-utils.d.ts +26 -0
  19. package/dist/modules/Order/payment-utils.js +225 -0
  20. package/dist/modules/Order/types.d.ts +35 -1
  21. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  22. package/dist/modules/Order/utils.js +10 -6
  23. package/dist/modules/Payment/index.d.ts +2 -0
  24. package/dist/modules/Payment/index.js +78 -49
  25. package/dist/modules/Payment/types.d.ts +104 -25
  26. package/dist/modules/Payment/types.js +17 -0
  27. package/dist/modules/Payment/walletpass.d.ts +38 -1
  28. package/dist/modules/Payment/walletpass.js +917 -114
  29. package/dist/modules/Rules/index.d.ts +3 -0
  30. package/dist/modules/Rules/index.js +146 -106
  31. package/dist/modules/SalesSummary/utils.js +7 -1
  32. package/dist/server/index.d.ts +16 -0
  33. package/dist/server/index.js +1940 -1043
  34. package/dist/server/modules/index.d.ts +1 -1
  35. package/dist/server/modules/order/index.d.ts +70 -4
  36. package/dist/server/modules/order/index.js +1816 -728
  37. package/dist/server/modules/order/types.d.ts +25 -3
  38. package/dist/server/modules/order/types.js +7 -1
  39. package/dist/solution/BaseSales/index.d.ts +115 -6
  40. package/dist/solution/BaseSales/index.js +1847 -478
  41. package/dist/solution/BaseSales/types.d.ts +55 -1
  42. package/dist/solution/BaseSales/types.js +2 -1
  43. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  44. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  45. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  46. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  47. package/dist/solution/BookingByStep/index.d.ts +1 -1
  48. package/dist/solution/BookingTicket/index.d.ts +9 -17
  49. package/dist/solution/BookingTicket/index.js +138 -52
  50. package/dist/solution/BookingTicket/types.d.ts +1 -0
  51. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  52. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
  53. package/dist/solution/Sales/index.d.ts +2 -0
  54. package/dist/solution/Sales/index.js +26 -4
  55. package/dist/solution/ScanOrder/index.js +31 -20
  56. package/dist/solution/VenueBooking/index.d.ts +1 -0
  57. package/dist/solution/VenueBooking/index.js +30 -19
  58. package/dist/types/index.d.ts +1 -0
  59. package/dist/utils/payment-number.d.ts +9 -0
  60. package/dist/utils/payment-number.js +69 -0
  61. package/lib/core/index.d.ts +2 -0
  62. package/lib/core/index.js +4 -0
  63. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  64. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  65. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  66. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  67. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  68. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  69. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  70. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  71. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  72. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -1
  73. package/lib/modules/OpenData/index.d.ts +2 -0
  74. package/lib/modules/OpenData/index.js +5 -0
  75. package/lib/modules/Order/index.d.ts +28 -8
  76. package/lib/modules/Order/index.js +236 -71
  77. package/lib/modules/Order/payment-utils.d.ts +26 -0
  78. package/lib/modules/Order/payment-utils.js +224 -0
  79. package/lib/modules/Order/types.d.ts +35 -1
  80. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  81. package/lib/modules/Order/utils.js +11 -4
  82. package/lib/modules/Payment/index.d.ts +2 -0
  83. package/lib/modules/Payment/index.js +33 -12
  84. package/lib/modules/Payment/types.d.ts +104 -25
  85. package/lib/modules/Payment/types.js +1 -0
  86. package/lib/modules/Payment/walletpass.d.ts +38 -1
  87. package/lib/modules/Payment/walletpass.js +730 -21
  88. package/lib/modules/Rules/index.d.ts +3 -0
  89. package/lib/modules/Rules/index.js +54 -21
  90. package/lib/modules/SalesSummary/utils.js +5 -1
  91. package/lib/server/index.d.ts +16 -0
  92. package/lib/server/index.js +670 -18
  93. package/lib/server/modules/index.d.ts +1 -1
  94. package/lib/server/modules/order/index.d.ts +70 -4
  95. package/lib/server/modules/order/index.js +818 -69
  96. package/lib/server/modules/order/types.d.ts +25 -3
  97. package/lib/server/modules/order/types.js +1 -0
  98. package/lib/solution/BaseSales/index.d.ts +115 -6
  99. package/lib/solution/BaseSales/index.js +896 -32
  100. package/lib/solution/BaseSales/types.d.ts +55 -1
  101. package/lib/solution/BaseSales/types.js +2 -1
  102. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  103. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  104. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  105. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  106. package/lib/solution/BookingByStep/index.d.ts +1 -1
  107. package/lib/solution/BookingTicket/index.d.ts +9 -17
  108. package/lib/solution/BookingTicket/index.js +63 -9
  109. package/lib/solution/BookingTicket/types.d.ts +1 -0
  110. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  111. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
  112. package/lib/solution/Sales/index.d.ts +2 -0
  113. package/lib/solution/Sales/index.js +20 -6
  114. package/lib/solution/ScanOrder/index.js +8 -0
  115. package/lib/solution/VenueBooking/index.d.ts +1 -0
  116. package/lib/solution/VenueBooking/index.js +8 -0
  117. package/lib/types/index.d.ts +1 -0
  118. package/lib/utils/payment-number.d.ts +9 -0
  119. package/lib/utils/payment-number.js +64 -0
  120. package/package.json +1 -1
@@ -1,27 +1,99 @@
1
- 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); }
1
+ 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; }
2
+ 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); } }
3
+ 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); }); }; }
4
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
5
+ 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."); }
6
+ 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; } }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
2
8
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
9
  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."); }
10
+ 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); }
4
11
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
12
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
- 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."); }
8
- 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); }
9
13
  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; }
10
- 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; } }
11
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
- 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; }
13
- 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; }
14
- 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; }
15
- 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); } }
16
- 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); }); }; }
17
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
15
  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); } }
19
16
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+ 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; }
18
+ 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; }
20
19
  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; }
21
20
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
21
  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); }
22
+ 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); }
23
23
  import { WalletPassHooks } from "./types";
24
24
  import { formatWalletPassList2PreparePayments as formatWalletPassList2PreparePaymentsUtils, sortUserIdentificationCodeList } from "./utils";
25
+ var WALLET_PAYMENT_ASSET_TAGS = new Set(['product_voucher', 'gift_card', 'point_card']);
26
+ function isWalletPaymentAsset(asset) {
27
+ return WALLET_PAYMENT_ASSET_TAGS.has(String((asset === null || asset === void 0 ? void 0 : asset.tag) || '').toLowerCase());
28
+ }
29
+ function getWalletAssetId(asset) {
30
+ var _ref, _asset$id;
31
+ return (_ref = (_asset$id = asset === null || asset === void 0 ? void 0 : asset.id) !== null && _asset$id !== void 0 ? _asset$id : asset === null || asset === void 0 ? void 0 : asset.voucher_id) !== null && _ref !== void 0 ? _ref : asset === null || asset === void 0 ? void 0 : asset.code;
32
+ }
33
+ function getWalletAssetKey(assetOrId) {
34
+ var id = assetOrId && _typeof(assetOrId) === 'object' ? getWalletAssetId(assetOrId) : assetOrId;
35
+ return id === undefined || id === null ? '' : String(id);
36
+ }
37
+ function matchesWalletAssetCode(asset, normalizedCode) {
38
+ return [asset === null || asset === void 0 ? void 0 : asset.code, asset === null || asset === void 0 ? void 0 : asset.encoded].some(function (identifier) {
39
+ return String(identifier !== null && identifier !== void 0 ? identifier : '').trim() === normalizedCode;
40
+ });
41
+ }
42
+ function normalizeWalletAssetCode(code) {
43
+ return String(code !== null && code !== void 0 ? code : '').trim().toUpperCase();
44
+ }
45
+ function getWalletAssetCodeKeys(asset) {
46
+ return [asset === null || asset === void 0 ? void 0 : asset.code, asset === null || asset === void 0 ? void 0 : asset.encoded].map(normalizeWalletAssetCode).filter(Boolean);
47
+ }
48
+ function isWalletAssetAvailable(asset) {
49
+ if (!asset) return false;
50
+ if (asset.unified_available_status !== undefined && Number(asset.unified_available_status) !== 1) {
51
+ return false;
52
+ }
53
+ if (asset._unified_available_status !== undefined && Number(asset._unified_available_status) !== 1) {
54
+ return false;
55
+ }
56
+ if (asset.available === false || asset.isDisabled === true) return false;
57
+ return true;
58
+ }
59
+ function getWalletAssetDeductionAmount(asset) {
60
+ var _ref2, _ref3, _ref4, _ref5, _ref6, _asset$actualDeductio;
61
+ var value = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_asset$actualDeductio = asset === null || asset === void 0 ? void 0 : asset.actualDeduction) !== null && _asset$actualDeductio !== void 0 ? _asset$actualDeductio : asset === null || asset === void 0 ? void 0 : asset._available_max_amount) !== null && _ref6 !== void 0 ? _ref6 : asset === null || asset === void 0 ? void 0 : asset.edit_current_amount) !== null && _ref5 !== void 0 ? _ref5 : asset === null || asset === void 0 ? void 0 : asset.recommended_usage_amount) !== null && _ref4 !== void 0 ? _ref4 : asset === null || asset === void 0 ? void 0 : asset.available_max_amount) !== null && _ref3 !== void 0 ? _ref3 : asset === null || asset === void 0 ? void 0 : asset.amount) !== null && _ref2 !== void 0 ? _ref2 : 0;
62
+ var amount = Number(value);
63
+ return Number.isFinite(amount) && amount > 0 ? amount : 0;
64
+ }
65
+ function mergeWalletAssets() {
66
+ var merged = [];
67
+ var indexByKey = new Map();
68
+ for (var _len = arguments.length, groups = new Array(_len), _key = 0; _key < _len; _key++) {
69
+ groups[_key] = arguments[_key];
70
+ }
71
+ groups.flat().forEach(function (asset) {
72
+ var key = getWalletAssetKey(asset);
73
+ if (!key) return;
74
+ var existedIndex = indexByKey.get(key);
75
+ if (existedIndex === undefined) {
76
+ indexByKey.set(key, merged.length);
77
+ merged.push(asset);
78
+ return;
79
+ }
80
+ merged[existedIndex] = _objectSpread(_objectSpread({}, merged[existedIndex]), asset);
81
+ });
82
+ return merged;
83
+ }
84
+ function createInitialWalletAssetsState() {
85
+ return {
86
+ status: 'idle',
87
+ items: [],
88
+ selectedIds: [],
89
+ selectedItems: [],
90
+ committedIds: [],
91
+ selectionSources: {},
92
+ totalSelectedAmount: 0,
93
+ error: null,
94
+ revision: 0
95
+ };
96
+ }
25
97
 
26
98
  /**
27
99
  * 钱包支付实现
@@ -34,14 +106,33 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
34
106
  _defineProperty(this, "searchResults", []);
35
107
  _defineProperty(this, "walletParams", null);
36
108
  _defineProperty(this, "walletInitData", null);
109
+ _defineProperty(this, "walletAssetsState", createInitialWalletAssetsState());
110
+ _defineProperty(this, "walletAssetsRequestSequence", 0);
111
+ _defineProperty(this, "walletAssetsBehavior", {
112
+ autoSelectAfterSearch: true
113
+ });
114
+ _defineProperty(this, "pendingAutoSelectSearchCodes", new Set());
115
+ _defineProperty(this, "walletAssetsCalculationContext", {
116
+ orderTotalAmount: 0,
117
+ products: []
118
+ });
37
119
  this.paymentModule = paymentModule;
38
120
  }
39
-
40
- /**
41
- * 发送事件的辅助方法
42
- * 支持使用WalletPassHooks或PaymentHooks
43
- */
44
121
  _createClass(WalletPassPaymentImpl, [{
122
+ key: "configureWalletAssetsBehavior",
123
+ value: function configureWalletAssetsBehavior(options) {
124
+ if (options.autoSelectAfterSearch === undefined) return;
125
+ this.walletAssetsBehavior.autoSelectAfterSearch = options.autoSelectAfterSearch;
126
+ if (!options.autoSelectAfterSearch) {
127
+ this.pendingAutoSelectSearchCodes.clear();
128
+ }
129
+ }
130
+
131
+ /**
132
+ * 发送事件的辅助方法
133
+ * 支持使用WalletPassHooks或PaymentHooks
134
+ */
135
+ }, {
45
136
  key: "emitEvent",
46
137
  value: function emitEvent(hook, data) {
47
138
  try {
@@ -55,6 +146,156 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
55
146
  });
56
147
  }
57
148
  }
149
+ }, {
150
+ key: "publishWalletAssetsState",
151
+ value: function publishWalletAssetsState(patch) {
152
+ var _patch$items, _patch$selectedIds, _patch$selectedItems, _patch$committedIds, _patch$selectionSourc;
153
+ this.walletAssetsState = _objectSpread(_objectSpread(_objectSpread({}, this.walletAssetsState), patch), {}, {
154
+ items: _toConsumableArray((_patch$items = patch.items) !== null && _patch$items !== void 0 ? _patch$items : this.walletAssetsState.items),
155
+ selectedIds: _toConsumableArray((_patch$selectedIds = patch.selectedIds) !== null && _patch$selectedIds !== void 0 ? _patch$selectedIds : this.walletAssetsState.selectedIds),
156
+ selectedItems: _toConsumableArray((_patch$selectedItems = patch.selectedItems) !== null && _patch$selectedItems !== void 0 ? _patch$selectedItems : this.walletAssetsState.selectedItems),
157
+ committedIds: _toConsumableArray((_patch$committedIds = patch.committedIds) !== null && _patch$committedIds !== void 0 ? _patch$committedIds : this.walletAssetsState.committedIds),
158
+ selectionSources: _objectSpread({}, (_patch$selectionSourc = patch.selectionSources) !== null && _patch$selectionSourc !== void 0 ? _patch$selectionSourc : this.walletAssetsState.selectionSources),
159
+ revision: this.walletAssetsState.revision + 1
160
+ });
161
+ var state = this.getWalletAssetsState();
162
+ this.emitEvent(WalletPassHooks.OnWalletAssetsStateChanged, {
163
+ state: state
164
+ });
165
+ return state;
166
+ }
167
+ }, {
168
+ key: "recalculateWalletAssets",
169
+ value: function recalculateWalletAssets(items, requestedIds, selectionSources) {
170
+ var _this$paymentModule$w, _this$paymentModule$w2;
171
+ var committedKeys = new Set(this.walletAssetsState.committedIds.map(function (id) {
172
+ return String(id);
173
+ }));
174
+ var itemsByKey = new Map(items.map(function (item) {
175
+ return [getWalletAssetKey(item), item];
176
+ }));
177
+ var requested = requestedIds.map(function (id) {
178
+ return String(id);
179
+ }).filter(function (id) {
180
+ return !committedKeys.has(id);
181
+ }).map(function (id) {
182
+ return itemsByKey.get(id);
183
+ }).filter(function (item) {
184
+ return item && isWalletAssetAvailable(item);
185
+ });
186
+ var nextItems = items;
187
+ var selectedItems = requested;
188
+ var evaluator = (_this$paymentModule$w = this.paymentModule.window) === null || _this$paymentModule$w === void 0 || (_this$paymentModule$w2 = _this$paymentModule$w.getWalletPassEvaluator) === null || _this$paymentModule$w2 === void 0 ? void 0 : _this$paymentModule$w2.call(_this$paymentModule$w);
189
+ if (evaluator !== null && evaluator !== void 0 && evaluator.recalculateVouchers) {
190
+ try {
191
+ var result = evaluator.recalculateVouchers(items, requested, this.walletAssetsCalculationContext.orderTotalAmount, this.walletAssetsCalculationContext.products);
192
+ nextItems = mergeWalletAssets(items, (result === null || result === void 0 ? void 0 : result.allWithUpdatedStatus) || []);
193
+ selectedItems = ((result === null || result === void 0 ? void 0 : result.selectedWithDetails) || []).filter(function (item) {
194
+ return isWalletAssetAvailable(item) && getWalletAssetDeductionAmount(item) > 0;
195
+ });
196
+ } catch (error) {
197
+ this.paymentModule.logWarning('[WalletPass] 共享钱包资产重新计算失败,回退接口可用状态', {
198
+ error: error instanceof Error ? error.message : String(error)
199
+ });
200
+ }
201
+ }
202
+ var selectedIds = selectedItems.map(function (item) {
203
+ return getWalletAssetId(item);
204
+ }).filter(function (id) {
205
+ return id !== undefined && id !== null;
206
+ });
207
+ var selectedKeys = new Set(selectedIds.map(function (id) {
208
+ return String(id);
209
+ }));
210
+ var nextSources = Object.entries(selectionSources).reduce(function (result, _ref7) {
211
+ var _ref8 = _slicedToArray(_ref7, 2),
212
+ key = _ref8[0],
213
+ source = _ref8[1];
214
+ if (selectedKeys.has(key)) result[key] = source;
215
+ return result;
216
+ }, {});
217
+ var totalSelectedAmount = selectedItems.reduce(function (total, item) {
218
+ return total + getWalletAssetDeductionAmount(item);
219
+ }, 0);
220
+ return this.publishWalletAssetsState({
221
+ status: 'ready',
222
+ items: nextItems,
223
+ selectedIds: selectedIds,
224
+ selectedItems: selectedItems,
225
+ selectionSources: nextSources,
226
+ totalSelectedAmount: totalSelectedAmount,
227
+ error: null
228
+ });
229
+ }
230
+
231
+ /** 获取当前缓存中所有支付类 Wallet 资产的扫码 code。 */
232
+ }, {
233
+ key: "getSearchedWalletAssetCodes",
234
+ value: function getSearchedWalletAssetCodes() {
235
+ var cachedAssets = this.searchResults.filter(isWalletPaymentAsset);
236
+ var seenCodes = new Set();
237
+ return cachedAssets.map(function (item) {
238
+ return String((item === null || item === void 0 ? void 0 : item.code) || '').trim();
239
+ }).filter(function (code) {
240
+ var normalizedCode = code.toUpperCase();
241
+ if (!normalizedCode || seenCodes.has(normalizedCode)) return false;
242
+ seenCodes.add(normalizedCode);
243
+ return true;
244
+ });
245
+ }
246
+
247
+ /**
248
+ * 用订单重算接口返回的数据更新扫码 Wallet 缓存。
249
+ * 接口暂时缺失某个扫码 code 时继续保留旧值,避免列表闪空。
250
+ */
251
+ }, {
252
+ key: "syncSearchedWalletAssets",
253
+ value: function syncSearchedWalletAssets(refreshedCandidates) {
254
+ var cachedAssets = this.searchResults.filter(isWalletPaymentAsset);
255
+ var searchedCodeKeys = new Set(this.getSearchedWalletAssetCodes().map(function (code) {
256
+ return code.toUpperCase();
257
+ }));
258
+ if (searchedCodeKeys.size === 0) return cachedAssets;
259
+ var refreshedAssets = refreshedCandidates.filter(function (item) {
260
+ return isWalletPaymentAsset(item) && searchedCodeKeys.has(String((item === null || item === void 0 ? void 0 : item.code) || '').trim().toUpperCase());
261
+ });
262
+ if (refreshedAssets.length > 0) {
263
+ var replacedCodes = new Set(refreshedAssets.map(function (item) {
264
+ return String((item === null || item === void 0 ? void 0 : item.code) || '').trim().toUpperCase();
265
+ }));
266
+ this.searchResults = [].concat(_toConsumableArray(this.searchResults.filter(function (item) {
267
+ return !replacedCodes.has(String((item === null || item === void 0 ? void 0 : item.code) || '').trim().toUpperCase());
268
+ })), _toConsumableArray(refreshedAssets));
269
+ }
270
+ return mergeWalletAssets(cachedAssets, refreshedAssets);
271
+ }
272
+ }, {
273
+ key: "isPendingAutoSelectAsset",
274
+ value: function isPendingAutoSelectAsset(asset) {
275
+ var _this = this;
276
+ return getWalletAssetCodeKeys(asset).some(function (code) {
277
+ return _this.pendingAutoSelectSearchCodes.has(code);
278
+ });
279
+ }
280
+ }, {
281
+ key: "clearPendingAutoSelectForAsset",
282
+ value: function clearPendingAutoSelectForAsset(asset) {
283
+ var _this2 = this;
284
+ getWalletAssetCodeKeys(asset).forEach(function (code) {
285
+ _this2.pendingAutoSelectSearchCodes.delete(code);
286
+ });
287
+ }
288
+ }, {
289
+ key: "queuePendingAutoSelectForAssets",
290
+ value: function queuePendingAutoSelectForAssets(assets) {
291
+ var _this3 = this;
292
+ if (!this.walletAssetsBehavior.autoSelectAfterSearch) return;
293
+ assets.forEach(function (asset) {
294
+ getWalletAssetCodeKeys(asset).forEach(function (code) {
295
+ _this3.pendingAutoSelectSearchCodes.add(code);
296
+ });
297
+ });
298
+ }
58
299
 
59
300
  /**
60
301
  * 生成钱包API默认参数
@@ -85,7 +326,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
85
326
  // 订单小计金额
86
327
  order_product_amount: subTotal,
87
328
  // 订单待支付金额
88
- order_wait_pay_amount: order_wait_pay_amount || (amountInfo !== null && amountInfo !== void 0 && amountInfo.isDeposit ? Number(amountInfo === null || amountInfo === void 0 ? void 0 : amountInfo.depositAmount) : totalAmount),
329
+ order_wait_pay_amount: order_wait_pay_amount !== null && order_wait_pay_amount !== void 0 ? order_wait_pay_amount : amountInfo !== null && amountInfo !== void 0 && amountInfo.isDeposit ? Number(amountInfo === null || amountInfo === void 0 ? void 0 : amountInfo.depositAmount) : totalAmount,
89
330
  // order_behavior_count_customer_id: 1,
90
331
  products: products,
91
332
  prepare_payments: [],
@@ -270,7 +511,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
270
511
  key: "initializeWalletDataAsync",
271
512
  value: (function () {
272
513
  var _initializeWalletDataAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(baseParams) {
273
- var _this$paymentModule$w, _this$paymentModule$w2, identificationParams, _yield$Promise$all, _yield$Promise$all2, allList, orderBasicDetail, walletPassEvaluator, products, res, recommended, transformList, noApplicableVoucher, recommendedAmount;
514
+ var _this$paymentModule$w3, _this$paymentModule$w4, identificationParams, _yield$Promise$all, _yield$Promise$all2, allList, orderBasicDetail, walletPassEvaluator, products, res, recommended, transformList, noApplicableVoucher, recommendedAmount;
274
515
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
275
516
  while (1) switch (_context3.prev = _context3.next) {
276
517
  case 0:
@@ -289,7 +530,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
289
530
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
290
531
  allList = _yield$Promise$all2[0];
291
532
  orderBasicDetail = _yield$Promise$all2[1];
292
- walletPassEvaluator = (_this$paymentModule$w = this.paymentModule.window) === null || _this$paymentModule$w === void 0 || (_this$paymentModule$w2 = _this$paymentModule$w.getWalletPassEvaluator) === null || _this$paymentModule$w2 === void 0 ? void 0 : _this$paymentModule$w2.call(_this$paymentModule$w);
533
+ walletPassEvaluator = (_this$paymentModule$w3 = this.paymentModule.window) === null || _this$paymentModule$w3 === void 0 || (_this$paymentModule$w4 = _this$paymentModule$w3.getWalletPassEvaluator) === null || _this$paymentModule$w4 === void 0 ? void 0 : _this$paymentModule$w4.call(_this$paymentModule$w3);
293
534
  if (walletPassEvaluator) {
294
535
  _context3.next = 11;
295
536
  break;
@@ -347,16 +588,115 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
347
588
  return _initializeWalletDataAsync.apply(this, arguments);
348
589
  }
349
590
  return initializeWalletDataAsync;
591
+ }()
592
+ /**
593
+ * 商品或订单金额变化后,使用聚合接口一次重算已选与剩余 WalletPass。
594
+ * Walk-In 不发送 customer_id;会员才携带真实 customer_id。
595
+ */
596
+ )
597
+ }, {
598
+ key: "aggregateRecalculateWalletAssetsAsync",
599
+ value: (function () {
600
+ var _aggregateRecalculateWalletAssetsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(businessData, selectedIds) {
601
+ var _this$paymentModule$w5, _this$paymentModule$w6;
602
+ var walletParams, customerId, requestParams, response, responseData, hasAggregateLists, recalculateList, customerWalletPassList, allList, walletPassEvaluator, evaluated, returnedSelectedKeys, authoritativeSelectedIds;
603
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
604
+ while (1) switch (_context4.prev = _context4.next) {
605
+ case 0:
606
+ walletParams = this.generateWalletParams(businessData);
607
+ customerId = Number(walletParams.customer_id || 0);
608
+ requestParams = {
609
+ ids: selectedIds.map(function (id) {
610
+ return String(id);
611
+ }),
612
+ exact_codes: this.getSearchedWalletAssetCodes(),
613
+ order_product_amount: walletParams.order_product_amount,
614
+ order_expect_amount: walletParams.order_expect_amount,
615
+ order_wait_pay_amount: walletParams.order_wait_pay_amount,
616
+ products: walletParams.products,
617
+ available: 2,
618
+ filter_prepare_wallet_pass: 1,
619
+ sale_channel: walletParams.sale_channel || 'pos'
620
+ };
621
+ if (customerId > 1) {
622
+ requestParams.customer_id = customerId;
623
+ }
624
+ _context4.next = 6;
625
+ return this.paymentModule.request.post('/machinecode/prepare/deduction/aggregate-recalculate', requestParams);
626
+ case 6:
627
+ response = _context4.sent;
628
+ responseData = response === null || response === void 0 ? void 0 : response.data;
629
+ hasAggregateLists = responseData && (Object.prototype.hasOwnProperty.call(responseData, 'recalculate_list') || Object.prototype.hasOwnProperty.call(responseData, 'customer_wallet_pass_list'));
630
+ if (hasAggregateLists) {
631
+ _context4.next = 11;
632
+ break;
633
+ }
634
+ throw new Error('WalletPass aggregate response is missing list data');
635
+ case 11:
636
+ recalculateList = Array.isArray(responseData === null || responseData === void 0 ? void 0 : responseData.recalculate_list) ? responseData.recalculate_list : [];
637
+ customerWalletPassList = Array.isArray(responseData === null || responseData === void 0 ? void 0 : responseData.customer_wallet_pass_list) ? responseData.customer_wallet_pass_list : [];
638
+ allList = mergeWalletAssets(recalculateList, customerWalletPassList);
639
+ walletPassEvaluator = (_this$paymentModule$w5 = this.paymentModule.window) === null || _this$paymentModule$w5 === void 0 || (_this$paymentModule$w6 = _this$paymentModule$w5.getWalletPassEvaluator) === null || _this$paymentModule$w6 === void 0 ? void 0 : _this$paymentModule$w6.call(_this$paymentModule$w5);
640
+ evaluated = walletPassEvaluator !== null && walletPassEvaluator !== void 0 && walletPassEvaluator.getRecommendedVouchers ? walletPassEvaluator.getRecommendedVouchers({
641
+ orderTotalAmount: walletParams.order_wait_pay_amount,
642
+ products: walletParams.products,
643
+ vouchers: allList
644
+ }) : {
645
+ recommended: [],
646
+ transformList: allList.filter(isWalletAssetAvailable),
647
+ noApplicableVoucher: allList.filter(function (item) {
648
+ return !isWalletAssetAvailable(item);
649
+ })
650
+ };
651
+ returnedSelectedKeys = new Set(recalculateList.filter(isWalletAssetAvailable).map(function (item) {
652
+ return getWalletAssetKey(item);
653
+ }));
654
+ authoritativeSelectedIds = selectedIds.filter(function (id) {
655
+ return returnedSelectedKeys.has(String(id));
656
+ });
657
+ this.walletRecommendList = evaluated.recommended || [];
658
+ this.userIdentificationCodes = allList;
659
+ this.emitEvent(WalletPassHooks.OnUserIdentificationCodesUpdated, {
660
+ userIdentificationCodes: this.userIdentificationCodes
661
+ });
662
+ this.walletInitData = {
663
+ transformList: evaluated.transformList || [],
664
+ noApplicableVoucher: evaluated.noApplicableVoucher || [],
665
+ products: walletParams.products || []
666
+ };
667
+ this.paymentModule.logInfo('[WalletPass] 聚合重算 WalletPass 完成', {
668
+ selected_count: recalculateList.length,
669
+ remaining_count: customerWalletPassList.length,
670
+ searched_codes_count: requestParams.exact_codes.length
671
+ });
672
+ return _context4.abrupt("return", {
673
+ walletRecommendList: this.walletRecommendList,
674
+ userIdentificationCodes: this.userIdentificationCodes,
675
+ transformList: evaluated.transformList || [],
676
+ noApplicableVoucher: evaluated.noApplicableVoucher || [],
677
+ products: walletParams.products || [],
678
+ authoritativeSelectedIds: authoritativeSelectedIds
679
+ });
680
+ case 24:
681
+ case "end":
682
+ return _context4.stop();
683
+ }
684
+ }, _callee4, this);
685
+ }));
686
+ function aggregateRecalculateWalletAssetsAsync(_x4, _x5) {
687
+ return _aggregateRecalculateWalletAssetsAsync.apply(this, arguments);
688
+ }
689
+ return aggregateRecalculateWalletAssetsAsync;
350
690
  }())
351
691
  }, {
352
692
  key: "getWalletPassRecommendListAsync",
353
693
  value: function () {
354
- var _getWalletPassRecommendListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
694
+ var _getWalletPassRecommendListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
355
695
  var _this$walletParams, response;
356
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
357
- while (1) switch (_context4.prev = _context4.next) {
696
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
697
+ while (1) switch (_context5.prev = _context5.next) {
358
698
  case 0:
359
- _context4.prev = 0;
699
+ _context5.prev = 0;
360
700
  this.paymentModule.logInfo('[WalletPass] 开始获取钱包推荐列表', {
361
701
  customer_id: params.customer_id,
362
702
  order_expect_amount: params.order_expect_amount,
@@ -366,11 +706,11 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
366
706
  if (typeof params.payment_order_id === 'string' && params.payment_order_id.startsWith('LOCAL_')) {
367
707
  params.payment_order_id = undefined;
368
708
  }
369
- _context4.next = 5;
709
+ _context5.next = 5;
370
710
  return this.paymentModule.request.post('/machinecode/prepare/deduction/recommend', params // 将 params 作为请求体数据
371
711
  );
372
712
  case 5:
373
- response = _context4.sent;
713
+ response = _context5.sent;
374
714
  this.walletRecommendList = (response === null || response === void 0 ? void 0 : response.data) || [];
375
715
 
376
716
  // 发送钱包推荐列表更新事件(使用专用的WalletPassHooks)
@@ -388,24 +728,24 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
388
728
  };
389
729
  })
390
730
  });
391
- return _context4.abrupt("return", this.walletRecommendList);
731
+ return _context5.abrupt("return", this.walletRecommendList);
392
732
  case 12:
393
- _context4.prev = 12;
394
- _context4.t0 = _context4["catch"](0);
395
- this.paymentModule.logError('[WalletPass] 获取钱包推荐列表失败', _context4.t0, {
733
+ _context5.prev = 12;
734
+ _context5.t0 = _context5["catch"](0);
735
+ this.paymentModule.logError('[WalletPass] 获取钱包推荐列表失败', _context5.t0, {
396
736
  customer_id: params.customer_id,
397
737
  order_expect_amount: params.order_expect_amount,
398
738
  sale_channel: params.sale_channel
399
739
  });
400
740
  // throw error;
401
- return _context4.abrupt("return", []);
741
+ return _context5.abrupt("return", []);
402
742
  case 16:
403
743
  case "end":
404
- return _context4.stop();
744
+ return _context5.stop();
405
745
  }
406
- }, _callee4, this, [[0, 12]]);
746
+ }, _callee5, this, [[0, 12]]);
407
747
  }));
408
- function getWalletPassRecommendListAsync(_x4) {
748
+ function getWalletPassRecommendListAsync(_x6) {
409
749
  return _getWalletPassRecommendListAsync.apply(this, arguments);
410
750
  }
411
751
  return getWalletPassRecommendListAsync;
@@ -418,19 +758,19 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
418
758
  }, {
419
759
  key: "getUserIdentificationCodeListAsync",
420
760
  value: function () {
421
- var _getUserIdentificationCodeListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
761
+ var _getUserIdentificationCodeListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
422
762
  var _newParams$products, _newParams$prepare_pa, _this$walletParams2, newParams, response, sortedData;
423
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
424
- while (1) switch (_context5.prev = _context5.next) {
763
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
764
+ while (1) switch (_context6.prev = _context6.next) {
425
765
  case 0:
426
- _context5.prev = 0;
766
+ _context6.prev = 0;
427
767
  newParams = _objectSpread(_objectSpread({}, this.walletParams), params);
428
768
  if ((_newParams$products = newParams.products) !== null && _newParams$products !== void 0 && _newParams$products.length) {
429
- _context5.next = 5;
769
+ _context6.next = 5;
430
770
  break;
431
771
  }
432
772
  this.paymentModule.logInfo('[WalletPass] 商品列表为空,跳过获取用户识别码列表');
433
- return _context5.abrupt("return", []);
773
+ return _context6.abrupt("return", []);
434
774
  case 5:
435
775
  if (typeof newParams.payment_order_id === 'string' && newParams.payment_order_id.startsWith('LOCAL_')) {
436
776
  newParams.payment_order_id = undefined;
@@ -442,10 +782,10 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
442
782
  filter_prepare_wallet_pass: newParams.filter_prepare_wallet_pass,
443
783
  payment_order_id: (_this$walletParams2 = this.walletParams) === null || _this$walletParams2 === void 0 ? void 0 : _this$walletParams2.payment_order_id
444
784
  });
445
- _context5.next = 9;
785
+ _context6.next = 9;
446
786
  return this.paymentModule.request.post('/machinecode/prepare/deduction', newParams);
447
787
  case 9:
448
- response = _context5.sent;
788
+ response = _context6.sent;
449
789
  // 对获取到的数据进行排序,将错误码为 500100、500200、500300 的项目排到最后
450
790
  sortedData = sortUserIdentificationCodeList((response === null || response === void 0 ? void 0 : response.data) || []);
451
791
  this.userIdentificationCodes = sortedData;
@@ -464,22 +804,22 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
464
804
  };
465
805
  })
466
806
  });
467
- return _context5.abrupt("return", this.userIdentificationCodes);
807
+ return _context6.abrupt("return", this.userIdentificationCodes);
468
808
  case 17:
469
- _context5.prev = 17;
470
- _context5.t0 = _context5["catch"](0);
471
- this.paymentModule.logError('[WalletPass] 获取用户识别码列表失败', _context5.t0, {
809
+ _context6.prev = 17;
810
+ _context6.t0 = _context6["catch"](0);
811
+ this.paymentModule.logError('[WalletPass] 获取用户识别码列表失败', _context6.t0, {
472
812
  customer_id: params.customer_id,
473
813
  available: params.available
474
814
  });
475
- return _context5.abrupt("return", []);
815
+ return _context6.abrupt("return", []);
476
816
  case 21:
477
817
  case "end":
478
- return _context5.stop();
818
+ return _context6.stop();
479
819
  }
480
- }, _callee5, this, [[0, 17]]);
820
+ }, _callee6, this, [[0, 17]]);
481
821
  }));
482
- function getUserIdentificationCodeListAsync(_x5) {
822
+ function getUserIdentificationCodeListAsync(_x7) {
483
823
  return _getUserIdentificationCodeListAsync.apply(this, arguments);
484
824
  }
485
825
  return getUserIdentificationCodeListAsync;
@@ -493,10 +833,21 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
493
833
  }, {
494
834
  key: "searchIdentificationCodeAsync",
495
835
  value: (function () {
496
- var _searchIdentificationCodeAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
836
+ var _searchIdentificationCodeAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
497
837
  var config,
498
- _ref,
499
- _response2,
838
+ _ref9,
839
+ _params$sale_channel,
840
+ _params$customer_id,
841
+ _params$order_expect_,
842
+ _params$order_product,
843
+ _params$order_wait_pa,
844
+ _ref10,
845
+ _ref11,
846
+ _params$order_behavio,
847
+ _ref12,
848
+ _params$products,
849
+ _ref13,
850
+ _params$prepare_payme,
500
851
  code,
501
852
  isWalletCode,
502
853
  walletDetailParams,
@@ -509,12 +860,12 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
509
860
  _this$searchResults,
510
861
  existingCodes,
511
862
  newResults,
512
- _args6 = arguments;
513
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
514
- while (1) switch (_context6.prev = _context6.next) {
863
+ _args7 = arguments;
864
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
865
+ while (1) switch (_context7.prev = _context7.next) {
515
866
  case 0:
516
- config = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
517
- _context6.prev = 1;
867
+ config = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {};
868
+ _context7.prev = 1;
518
869
  code = params.code;
519
870
  this.paymentModule.logInfo('[WalletPass] 开始搜索识别码', {
520
871
  code: code,
@@ -525,7 +876,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
525
876
  // 新钱包规则
526
877
  isWalletCode = code.startsWith('WL') || code.startsWith('200') && code.length === 10;
527
878
  if (!isWalletCode) {
528
- _context6.next = 14;
879
+ _context7.next = 14;
529
880
  break;
530
881
  }
531
882
  // 钱包识别码直接调用专门接口,不缓存,直接返回
@@ -539,17 +890,17 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
539
890
  with_customer: walletDetailParams.with_customer,
540
891
  with: walletDetailParams.with
541
892
  });
542
- _context6.next = 10;
893
+ _context7.next = 10;
543
894
  return this.paymentModule.request.post('/wallet/detail/search', walletDetailParams);
544
895
  case 10:
545
- _response = _context6.sent;
896
+ _response = _context7.sent;
546
897
  _searchResults = (_response === null || _response === void 0 ? void 0 : _response.data) || [];
547
898
  this.paymentModule.logInfo('[WalletPass] 钱包识别码搜索完成', {
548
899
  code: code,
549
900
  results_count: _searchResults.length,
550
901
  type: 'walletCode'
551
902
  });
552
- return _context6.abrupt("return", {
903
+ return _context7.abrupt("return", {
553
904
  type: 'walletCode',
554
905
  data: _searchResults
555
906
  });
@@ -558,14 +909,14 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
558
909
  baseWalletParams = this.walletParams; // 构建完整的搜索参数,包含钱包扣款推荐的所有参数
559
910
  searchParams = {
560
911
  // 基础钱包参数
561
- sale_channel: params.sale_channel || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.sale_channel) || 'pos',
562
- customer_id: params.customer_id || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.customer_id),
563
- order_expect_amount: params.order_expect_amount || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_expect_amount),
564
- order_product_amount: params.order_product_amount || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_product_amount),
565
- order_wait_pay_amount: params.order_wait_pay_amount || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_wait_pay_amount),
566
- order_behavior_count_customer_id: params.order_behavior_count_customer_id || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_behavior_count_customer_id) || params.customer_id || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.customer_id),
567
- products: params.products || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.products),
568
- prepare_payments: params.prepare_payments || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.prepare_payments),
912
+ sale_channel: (_ref9 = (_params$sale_channel = params.sale_channel) !== null && _params$sale_channel !== void 0 ? _params$sale_channel : baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.sale_channel) !== null && _ref9 !== void 0 ? _ref9 : 'pos',
913
+ customer_id: (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.customer_id,
914
+ order_expect_amount: (_params$order_expect_ = params.order_expect_amount) !== null && _params$order_expect_ !== void 0 ? _params$order_expect_ : baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_expect_amount,
915
+ order_product_amount: (_params$order_product = params.order_product_amount) !== null && _params$order_product !== void 0 ? _params$order_product : baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_product_amount,
916
+ order_wait_pay_amount: (_params$order_wait_pa = params.order_wait_pay_amount) !== null && _params$order_wait_pa !== void 0 ? _params$order_wait_pa : baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_wait_pay_amount,
917
+ order_behavior_count_customer_id: (_ref10 = (_ref11 = (_params$order_behavio = params.order_behavior_count_customer_id) !== null && _params$order_behavio !== void 0 ? _params$order_behavio : baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_behavior_count_customer_id) !== null && _ref11 !== void 0 ? _ref11 : params.customer_id) !== null && _ref10 !== void 0 ? _ref10 : baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.customer_id,
918
+ products: (_ref12 = (_params$products = params.products) !== null && _params$products !== void 0 ? _params$products : baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.products) !== null && _ref12 !== void 0 ? _ref12 : [],
919
+ prepare_payments: (_ref13 = (_params$prepare_payme = params.prepare_payments) !== null && _params$prepare_payme !== void 0 ? _params$prepare_payme : baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.prepare_payments) !== null && _ref13 !== void 0 ? _ref13 : [],
569
920
  multiple: 1,
570
921
  // 搜索特有参数
571
922
  code: params.code,
@@ -581,31 +932,20 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
581
932
  if (typeof searchParams.payment_order_id === 'string' && searchParams.payment_order_id.startsWith('LOCAL_')) {
582
933
  searchParams.payment_order_id = undefined;
583
934
  }
584
- if (!(!searchParams.products || ((_ref = searchParams.products || []) === null || _ref === void 0 ? void 0 : _ref.length) === 0)) {
585
- _context6.next = 22;
586
- break;
587
- }
588
- response = {
589
- data: []
590
- };
591
- _context6.next = 25;
592
- break;
593
- case 22:
594
- _context6.next = 24;
935
+ _context7.next = 20;
595
936
  return this.paymentModule.request.post('/machinecode/prepare/deduction/search', searchParams);
596
- case 24:
597
- response = _context6.sent;
598
- case 25:
599
- searchResults = ((_response2 = response) === null || _response2 === void 0 ? void 0 : _response2.data) || [];
937
+ case 20:
938
+ response = _context7.sent;
939
+ searchResults = (response === null || response === void 0 ? void 0 : response.data) || [];
600
940
  if (!config.noCache) {
601
- _context6.next = 28;
941
+ _context7.next = 24;
602
942
  break;
603
943
  }
604
- return _context6.abrupt("return", {
944
+ return _context7.abrupt("return", {
605
945
  type: 'normalCode',
606
946
  data: searchResults
607
947
  });
608
- case 28:
948
+ case 24:
609
949
  // 将搜索结果存储到缓存数组中
610
950
  if (searchResults.length > 0) {
611
951
  // 避免重复存储相同的识别码
@@ -631,49 +971,503 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
631
971
  cached_results_count: this.searchResults.length,
632
972
  type: 'normalCode'
633
973
  });
634
- return _context6.abrupt("return", {
974
+ return _context7.abrupt("return", {
635
975
  type: 'normalCode',
636
976
  data: searchResults
637
977
  });
638
- case 34:
639
- _context6.prev = 34;
640
- _context6.t0 = _context6["catch"](1);
641
- this.paymentModule.logError('[WalletPass] 搜索识别码信息失败', _context6.t0, {
978
+ case 30:
979
+ _context7.prev = 30;
980
+ _context7.t0 = _context7["catch"](1);
981
+ this.paymentModule.logError('[WalletPass] 搜索识别码信息失败', _context7.t0, {
642
982
  code: params.code,
643
983
  customer_id: params.customer_id,
644
984
  order_expect_amount: params.order_expect_amount
645
985
  });
646
- throw _context6.t0;
647
- case 38:
986
+ throw _context7.t0;
987
+ case 34:
648
988
  case "end":
649
- return _context6.stop();
989
+ return _context7.stop();
650
990
  }
651
- }, _callee6, this, [[1, 34]]);
991
+ }, _callee7, this, [[1, 30]]);
652
992
  }));
653
- function searchIdentificationCodeAsync(_x6) {
993
+ function searchIdentificationCodeAsync(_x8) {
654
994
  return _searchIdentificationCodeAsync.apply(this, arguments);
655
995
  }
656
996
  return searchIdentificationCodeAsync;
997
+ }()
998
+ /**
999
+ * 刷新购物车与结账共享的钱包资产。
1000
+ *
1001
+ * 与 legacy initializeWalletDataFromBusinessAsync 不同,这里维护选择状态;
1002
+ * 推荐结果只作为可用性/金额计算输入,不会自动成为 selectedIds。
1003
+ */
1004
+ )
1005
+ }, {
1006
+ key: "refreshWalletAssetsFromBusinessAsync",
1007
+ value: (function () {
1008
+ var _refreshWalletAssetsFromBusinessAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(businessData) {
1009
+ var _businessData$product2,
1010
+ _this4 = this;
1011
+ var options,
1012
+ requestSequence,
1013
+ nextCustomerId,
1014
+ previousCustomerId,
1015
+ customerChanged,
1016
+ preserveSelection,
1017
+ committedKeys,
1018
+ committedItems,
1019
+ selectedIds,
1020
+ selectionSources,
1021
+ scanSelectedAssets,
1022
+ restoredSearchedAssets,
1023
+ searchedWalletAssetCodes,
1024
+ useAggregateRecalculate,
1025
+ aggregateResult,
1026
+ result,
1027
+ authoritativeSelectedIds,
1028
+ returnedAggregateKeys,
1029
+ missingSelectedKeys,
1030
+ searchedWalletAssets,
1031
+ recommendedKeys,
1032
+ items,
1033
+ latestSelectedIds,
1034
+ latestSelectionSources,
1035
+ pendingAutoSelectAssets,
1036
+ requestedKeySet,
1037
+ nextState,
1038
+ selectedKeySet,
1039
+ droppedScanSelectedAssets,
1040
+ _args8 = arguments;
1041
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1042
+ while (1) switch (_context8.prev = _context8.next) {
1043
+ case 0:
1044
+ options = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
1045
+ requestSequence = ++this.walletAssetsRequestSequence;
1046
+ nextCustomerId = businessData.customer_id;
1047
+ previousCustomerId = this.walletAssetsState.customerId;
1048
+ customerChanged = String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '');
1049
+ preserveSelection = options.preserveSelection !== false && !customerChanged;
1050
+ if (customerChanged) {
1051
+ this.clearSearchResults();
1052
+ }
1053
+ committedKeys = new Set(this.walletAssetsState.committedIds.map(function (id) {
1054
+ return String(id);
1055
+ }));
1056
+ committedItems = this.walletAssetsState.items.filter(function (item) {
1057
+ return committedKeys.has(getWalletAssetKey(item));
1058
+ });
1059
+ selectedIds = preserveSelection ? _toConsumableArray(this.walletAssetsState.selectedIds) : [];
1060
+ selectionSources = preserveSelection ? _objectSpread({}, this.walletAssetsState.selectionSources) : {};
1061
+ scanSelectedAssets = preserveSelection ? this.walletAssetsState.selectedItems.filter(function (asset) {
1062
+ var assetId = getWalletAssetId(asset);
1063
+ return assetId !== undefined && assetId !== null && selectionSources[String(assetId)] === 'scan';
1064
+ }) : []; // aggregate-recalculate 不接受空商品列表。
1065
+ // 清空购物车时保留扫码资产供后续加购恢复;只有手动 Remove/Clear
1066
+ // 会取消自动应用资格,商品变化导致的自动失效需要重新进入待选队列。
1067
+ if ((_businessData$product2 = businessData.products) !== null && _businessData$product2 !== void 0 && _businessData$product2.length) {
1068
+ _context8.next = 22;
1069
+ break;
1070
+ }
1071
+ this.queuePendingAutoSelectForAssets(scanSelectedAssets);
1072
+ this.generateWalletParams(businessData);
1073
+ restoredSearchedAssets = this.searchResults.filter(isWalletPaymentAsset).map(function (item) {
1074
+ return _objectSpread(_objectSpread({}, item), {}, {
1075
+ actualDeduction: 0,
1076
+ deductionDetails: [],
1077
+ _available_max_amount: 0,
1078
+ _unified_available_status: 0,
1079
+ _wallet_asset_recommended: false
1080
+ });
1081
+ });
1082
+ this.walletRecommendList = [];
1083
+ this.userIdentificationCodes = [];
1084
+ this.walletInitData = {
1085
+ transformList: [],
1086
+ noApplicableVoucher: restoredSearchedAssets,
1087
+ products: []
1088
+ };
1089
+ this.walletAssetsCalculationContext = {
1090
+ orderTotalAmount: 0,
1091
+ products: []
1092
+ };
1093
+ this.emitEvent(WalletPassHooks.OnUserIdentificationCodesUpdated, {
1094
+ userIdentificationCodes: []
1095
+ });
1096
+ return _context8.abrupt("return", this.publishWalletAssetsState({
1097
+ status: 'ready',
1098
+ customerId: nextCustomerId,
1099
+ items: mergeWalletAssets(restoredSearchedAssets, committedItems),
1100
+ selectedIds: [],
1101
+ selectedItems: [],
1102
+ selectionSources: {},
1103
+ totalSelectedAmount: 0,
1104
+ error: null
1105
+ }));
1106
+ case 22:
1107
+ this.publishWalletAssetsState({
1108
+ status: 'loading',
1109
+ customerId: nextCustomerId,
1110
+ items: preserveSelection ? this.walletAssetsState.items : committedItems,
1111
+ selectedIds: selectedIds,
1112
+ selectedItems: preserveSelection ? this.walletAssetsState.selectedItems : [],
1113
+ selectionSources: selectionSources,
1114
+ totalSelectedAmount: preserveSelection ? this.walletAssetsState.totalSelectedAmount : 0,
1115
+ error: null
1116
+ });
1117
+ _context8.prev = 23;
1118
+ searchedWalletAssetCodes = preserveSelection ? this.getSearchedWalletAssetCodes() : [];
1119
+ useAggregateRecalculate = preserveSelection && (selectedIds.length > 0 || searchedWalletAssetCodes.length > 0);
1120
+ if (!useAggregateRecalculate) {
1121
+ _context8.next = 32;
1122
+ break;
1123
+ }
1124
+ _context8.next = 29;
1125
+ return this.aggregateRecalculateWalletAssetsAsync(businessData, selectedIds);
1126
+ case 29:
1127
+ _context8.t0 = _context8.sent;
1128
+ _context8.next = 33;
1129
+ break;
1130
+ case 32:
1131
+ _context8.t0 = null;
1132
+ case 33:
1133
+ aggregateResult = _context8.t0;
1134
+ _context8.t1 = aggregateResult;
1135
+ if (_context8.t1) {
1136
+ _context8.next = 39;
1137
+ break;
1138
+ }
1139
+ _context8.next = 38;
1140
+ return this.initializeWalletDataFromBusinessAsync(businessData);
1141
+ case 38:
1142
+ _context8.t1 = _context8.sent;
1143
+ case 39:
1144
+ result = _context8.t1;
1145
+ if (!(requestSequence !== this.walletAssetsRequestSequence)) {
1146
+ _context8.next = 42;
1147
+ break;
1148
+ }
1149
+ return _context8.abrupt("return", this.getWalletAssetsState());
1150
+ case 42:
1151
+ this.walletAssetsCalculationContext = {
1152
+ orderTotalAmount: Number(businessData.order_wait_pay_amount || 0),
1153
+ products: result.products || businessData.products || []
1154
+ };
1155
+ authoritativeSelectedIds = (aggregateResult === null || aggregateResult === void 0 ? void 0 : aggregateResult.authoritativeSelectedIds) || selectedIds;
1156
+ if (aggregateResult) {
1157
+ returnedAggregateKeys = new Set([].concat(_toConsumableArray(result.transformList || []), _toConsumableArray(result.noApplicableVoucher || [])).map(function (item) {
1158
+ return getWalletAssetKey(item);
1159
+ }));
1160
+ missingSelectedKeys = new Set(selectedIds.map(function (id) {
1161
+ return String(id);
1162
+ }).filter(function (id) {
1163
+ return !returnedAggregateKeys.has(id);
1164
+ }));
1165
+ if (missingSelectedKeys.size > 0) {
1166
+ this.searchResults = this.searchResults.filter(function (item) {
1167
+ return !missingSelectedKeys.has(getWalletAssetKey(item));
1168
+ });
1169
+ }
1170
+ }
1171
+ searchedWalletAssets = preserveSelection ? this.syncSearchedWalletAssets([].concat(_toConsumableArray(result.transformList || []), _toConsumableArray(result.noApplicableVoucher || []))) : [];
1172
+ if (!(requestSequence !== this.walletAssetsRequestSequence)) {
1173
+ _context8.next = 48;
1174
+ break;
1175
+ }
1176
+ return _context8.abrupt("return", this.getWalletAssetsState());
1177
+ case 48:
1178
+ recommendedKeys = new Set((result.walletRecommendList || []).map(function (asset) {
1179
+ return getWalletAssetKey(asset);
1180
+ }));
1181
+ items = mergeWalletAssets(preserveSelection && !aggregateResult ? this.walletAssetsState.selectedItems : [], searchedWalletAssets, result.transformList || [], result.noApplicableVoucher || []).map(function (asset) {
1182
+ return _objectSpread(_objectSpread({}, asset), {}, {
1183
+ _wallet_asset_recommended: recommendedKeys.has(getWalletAssetKey(asset))
1184
+ });
1185
+ });
1186
+ latestSelectedIds = preserveSelection ? authoritativeSelectedIds : [];
1187
+ latestSelectionSources = preserveSelection ? _objectSpread({}, this.walletAssetsState.selectionSources) : {};
1188
+ pendingAutoSelectAssets = this.walletAssetsBehavior.autoSelectAfterSearch ? items.filter(function (asset) {
1189
+ return _this4.isPendingAutoSelectAsset(asset) && isWalletAssetAvailable(asset);
1190
+ }) : [];
1191
+ requestedKeySet = new Set(latestSelectedIds.map(function (id) {
1192
+ return String(id);
1193
+ }));
1194
+ pendingAutoSelectAssets.forEach(function (asset) {
1195
+ var assetId = getWalletAssetId(asset);
1196
+ if (assetId === undefined || assetId === null) return;
1197
+ var assetKey = String(assetId);
1198
+ if (!requestedKeySet.has(assetKey)) {
1199
+ requestedKeySet.add(assetKey);
1200
+ latestSelectedIds.push(assetId);
1201
+ }
1202
+ latestSelectionSources[assetKey] = 'scan';
1203
+ });
1204
+ nextState = this.recalculateWalletAssets(items, latestSelectedIds, latestSelectionSources);
1205
+ selectedKeySet = new Set(nextState.selectedIds.map(function (id) {
1206
+ return String(id);
1207
+ }));
1208
+ pendingAutoSelectAssets.forEach(function (asset) {
1209
+ var assetId = getWalletAssetId(asset);
1210
+ if (assetId !== undefined && assetId !== null && selectedKeySet.has(String(assetId))) {
1211
+ _this4.clearPendingAutoSelectForAsset(asset);
1212
+ }
1213
+ });
1214
+ droppedScanSelectedAssets = scanSelectedAssets.filter(function (asset) {
1215
+ var assetId = getWalletAssetId(asset);
1216
+ return assetId !== undefined && assetId !== null && !selectedKeySet.has(String(assetId));
1217
+ });
1218
+ this.queuePendingAutoSelectForAssets(droppedScanSelectedAssets);
1219
+ return _context8.abrupt("return", nextState);
1220
+ case 63:
1221
+ _context8.prev = 63;
1222
+ _context8.t2 = _context8["catch"](23);
1223
+ if (!(requestSequence !== this.walletAssetsRequestSequence)) {
1224
+ _context8.next = 67;
1225
+ break;
1226
+ }
1227
+ return _context8.abrupt("return", this.getWalletAssetsState());
1228
+ case 67:
1229
+ this.paymentModule.logError('[WalletPass] 刷新共享钱包资产失败,保留刷新前状态', _context8.t2, {
1230
+ customer_id: businessData.customer_id,
1231
+ selected_ids: selectedIds,
1232
+ searched_codes: this.getSearchedWalletAssetCodes()
1233
+ });
1234
+ return _context8.abrupt("return", this.publishWalletAssetsState({
1235
+ status: 'error',
1236
+ items: preserveSelection ? this.walletAssetsState.items : committedItems,
1237
+ selectedIds: preserveSelection ? this.walletAssetsState.selectedIds : [],
1238
+ selectedItems: preserveSelection ? this.walletAssetsState.selectedItems : [],
1239
+ selectionSources: preserveSelection ? this.walletAssetsState.selectionSources : {},
1240
+ totalSelectedAmount: preserveSelection ? this.walletAssetsState.totalSelectedAmount : 0,
1241
+ customerId: nextCustomerId,
1242
+ error: _context8.t2 instanceof Error ? _context8.t2.message : String(_context8.t2)
1243
+ }));
1244
+ case 69:
1245
+ case "end":
1246
+ return _context8.stop();
1247
+ }
1248
+ }, _callee8, this, [[23, 63]]);
1249
+ }));
1250
+ function refreshWalletAssetsFromBusinessAsync(_x9) {
1251
+ return _refreshWalletAssetsFromBusinessAsync.apply(this, arguments);
1252
+ }
1253
+ return refreshWalletAssetsFromBusinessAsync;
657
1254
  }())
1255
+ }, {
1256
+ key: "getWalletAssetsState",
1257
+ value: function getWalletAssetsState() {
1258
+ return _objectSpread(_objectSpread({}, this.walletAssetsState), {}, {
1259
+ items: _toConsumableArray(this.walletAssetsState.items),
1260
+ selectedIds: _toConsumableArray(this.walletAssetsState.selectedIds),
1261
+ selectedItems: _toConsumableArray(this.walletAssetsState.selectedItems),
1262
+ committedIds: _toConsumableArray(this.walletAssetsState.committedIds),
1263
+ selectionSources: _objectSpread({}, this.walletAssetsState.selectionSources)
1264
+ });
1265
+ }
1266
+ }, {
1267
+ key: "exportWalletAssetsSnapshot",
1268
+ value: function exportWalletAssetsSnapshot() {
1269
+ return {
1270
+ state: this.getWalletAssetsState(),
1271
+ searchResults: _toConsumableArray(this.searchResults),
1272
+ pendingAutoSelectSearchCodes: _toConsumableArray(this.pendingAutoSelectSearchCodes),
1273
+ walletParams: this.walletParams ? _objectSpread({}, this.walletParams) : null,
1274
+ calculationContext: {
1275
+ orderTotalAmount: this.walletAssetsCalculationContext.orderTotalAmount,
1276
+ products: _toConsumableArray(this.walletAssetsCalculationContext.products)
1277
+ }
1278
+ };
1279
+ }
1280
+ }, {
1281
+ key: "importWalletAssetsSnapshot",
1282
+ value: function importWalletAssetsSnapshot(snapshot) {
1283
+ var _snapshot$calculation, _snapshot$calculation2;
1284
+ if (!(snapshot !== null && snapshot !== void 0 && snapshot.state)) return this.getWalletAssetsState();
1285
+ this.walletAssetsRequestSequence += 1;
1286
+ this.searchResults = Array.isArray(snapshot.searchResults) ? _toConsumableArray(snapshot.searchResults) : [];
1287
+ this.pendingAutoSelectSearchCodes = this.walletAssetsBehavior.autoSelectAfterSearch && Array.isArray(snapshot.pendingAutoSelectSearchCodes) ? new Set(snapshot.pendingAutoSelectSearchCodes.map(normalizeWalletAssetCode).filter(Boolean)) : new Set();
1288
+ this.walletParams = snapshot.walletParams ? _objectSpread({}, snapshot.walletParams) : null;
1289
+ this.walletAssetsCalculationContext = {
1290
+ orderTotalAmount: Number(((_snapshot$calculation = snapshot.calculationContext) === null || _snapshot$calculation === void 0 ? void 0 : _snapshot$calculation.orderTotalAmount) || 0),
1291
+ products: Array.isArray((_snapshot$calculation2 = snapshot.calculationContext) === null || _snapshot$calculation2 === void 0 ? void 0 : _snapshot$calculation2.products) ? _toConsumableArray(snapshot.calculationContext.products) : []
1292
+ };
1293
+ return this.publishWalletAssetsState(_objectSpread(_objectSpread({}, snapshot.state), {}, {
1294
+ items: Array.isArray(snapshot.state.items) ? snapshot.state.items : [],
1295
+ selectedIds: Array.isArray(snapshot.state.selectedIds) ? snapshot.state.selectedIds : [],
1296
+ selectedItems: Array.isArray(snapshot.state.selectedItems) ? snapshot.state.selectedItems : [],
1297
+ committedIds: Array.isArray(snapshot.state.committedIds) ? snapshot.state.committedIds : [],
1298
+ selectionSources: snapshot.state.selectionSources || {}
1299
+ }));
1300
+ }
1301
+ }, {
1302
+ key: "selectWalletAsset",
1303
+ value: function selectWalletAsset(assetId, options) {
1304
+ var assetKey = String(assetId);
1305
+ var asset = this.walletAssetsState.items.find(function (item) {
1306
+ return getWalletAssetKey(item) === assetKey;
1307
+ });
1308
+ var committedKeys = new Set(this.walletAssetsState.committedIds.map(function (id) {
1309
+ return String(id);
1310
+ }));
1311
+ if (committedKeys.has(assetKey)) return this.getWalletAssetsState();
1312
+ var selectedIds = this.walletAssetsState.selectedIds.filter(function (id) {
1313
+ return String(id) !== assetKey;
1314
+ });
1315
+ var selectionSources = _objectSpread({}, this.walletAssetsState.selectionSources);
1316
+ delete selectionSources[assetKey];
1317
+ if (options.selected) {
1318
+ if (!asset || !isWalletAssetAvailable(asset)) {
1319
+ return this.getWalletAssetsState();
1320
+ }
1321
+ selectedIds.push(assetId);
1322
+ selectionSources[assetKey] = options.source || 'manual';
1323
+ } else if (asset) {
1324
+ this.clearPendingAutoSelectForAsset(asset);
1325
+ }
1326
+ var nextState = this.recalculateWalletAssets(this.walletAssetsState.items, selectedIds, selectionSources);
1327
+ if (options.selected && asset && nextState.selectedIds.some(function (id) {
1328
+ return String(id) === assetKey;
1329
+ })) {
1330
+ this.clearPendingAutoSelectForAsset(asset);
1331
+ }
1332
+ return nextState;
1333
+ }
1334
+ }, {
1335
+ key: "scanWalletAssetAsync",
1336
+ value: function () {
1337
+ var _scanWalletAssetAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(code) {
1338
+ var normalizedCode, selectedAsset, result, paymentAssets, asset, items, recalculatedState, assetId, selected, isSelected;
1339
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1340
+ while (1) switch (_context9.prev = _context9.next) {
1341
+ case 0:
1342
+ normalizedCode = String(code || '').trim();
1343
+ if (normalizedCode) {
1344
+ _context9.next = 3;
1345
+ break;
1346
+ }
1347
+ return _context9.abrupt("return", {
1348
+ type: 'normalCode',
1349
+ selected: false,
1350
+ state: this.getWalletAssetsState()
1351
+ });
1352
+ case 3:
1353
+ selectedAsset = this.walletAssetsState.selectedItems.find(function (asset) {
1354
+ return matchesWalletAssetCode(asset, normalizedCode);
1355
+ });
1356
+ if (!selectedAsset) {
1357
+ _context9.next = 6;
1358
+ break;
1359
+ }
1360
+ return _context9.abrupt("return", {
1361
+ type: 'normalCode',
1362
+ asset: selectedAsset,
1363
+ selected: true,
1364
+ state: this.getWalletAssetsState()
1365
+ });
1366
+ case 6:
1367
+ this.walletAssetsRequestSequence += 1;
1368
+ _context9.next = 9;
1369
+ return this.searchIdentificationCodeAsync(_objectSpread(_objectSpread({}, this.walletParams || {}), {}, {
1370
+ code: normalizedCode,
1371
+ prepare_payments: this.formatWalletPassList2PreparePayments(this.walletAssetsState.selectedItems)
1372
+ }));
1373
+ case 9:
1374
+ result = _context9.sent;
1375
+ paymentAssets = result.data.filter(isWalletPaymentAsset);
1376
+ asset = paymentAssets.find(function (item) {
1377
+ return String((item === null || item === void 0 ? void 0 : item.code) || '') === normalizedCode;
1378
+ }) || paymentAssets[0];
1379
+ if (!(!asset || result.type === 'walletCode')) {
1380
+ _context9.next = 14;
1381
+ break;
1382
+ }
1383
+ return _context9.abrupt("return", {
1384
+ type: result.type,
1385
+ asset: asset,
1386
+ selected: false,
1387
+ state: this.getWalletAssetsState()
1388
+ });
1389
+ case 14:
1390
+ items = mergeWalletAssets(this.walletAssetsState.items, [asset]);
1391
+ recalculatedState = this.recalculateWalletAssets(items, this.walletAssetsState.selectedIds, this.walletAssetsState.selectionSources);
1392
+ assetId = getWalletAssetId(asset);
1393
+ selected = this.walletAssetsBehavior.autoSelectAfterSearch && assetId !== undefined && isWalletAssetAvailable(asset) ? this.selectWalletAsset(assetId, {
1394
+ selected: true,
1395
+ source: 'scan'
1396
+ }) : recalculatedState;
1397
+ isSelected = assetId !== undefined && selected.selectedIds.some(function (id) {
1398
+ return String(id) === String(assetId);
1399
+ });
1400
+ if (isSelected) {
1401
+ this.clearPendingAutoSelectForAsset(asset);
1402
+ } else if (this.walletAssetsBehavior.autoSelectAfterSearch) {
1403
+ this.pendingAutoSelectSearchCodes.add(normalizeWalletAssetCode(normalizedCode));
1404
+ this.queuePendingAutoSelectForAssets([asset]);
1405
+ }
1406
+ return _context9.abrupt("return", {
1407
+ type: result.type,
1408
+ asset: asset,
1409
+ selected: isSelected,
1410
+ state: selected
1411
+ });
1412
+ case 21:
1413
+ case "end":
1414
+ return _context9.stop();
1415
+ }
1416
+ }, _callee9, this);
1417
+ }));
1418
+ function scanWalletAssetAsync(_x10) {
1419
+ return _scanWalletAssetAsync.apply(this, arguments);
1420
+ }
1421
+ return scanWalletAssetAsync;
1422
+ }()
1423
+ }, {
1424
+ key: "clearWalletAssetSelection",
1425
+ value: function clearWalletAssetSelection() {
1426
+ this.pendingAutoSelectSearchCodes.clear();
1427
+ return this.recalculateWalletAssets(this.walletAssetsState.items, [], {});
1428
+ }
1429
+ }, {
1430
+ key: "setCommittedWalletAssets",
1431
+ value: function setCommittedWalletAssets(committedIds) {
1432
+ var committedAssets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1433
+ var committedKeys = new Set(committedIds.map(function (id) {
1434
+ return String(id);
1435
+ }));
1436
+ var selectedIds = this.walletAssetsState.selectedIds.filter(function (id) {
1437
+ return !committedKeys.has(String(id));
1438
+ });
1439
+ var selectionSources = Object.entries(this.walletAssetsState.selectionSources).reduce(function (result, _ref14) {
1440
+ var _ref15 = _slicedToArray(_ref14, 2),
1441
+ key = _ref15[0],
1442
+ source = _ref15[1];
1443
+ if (!committedKeys.has(key)) result[key] = source;
1444
+ return result;
1445
+ }, {});
1446
+ this.publishWalletAssetsState({
1447
+ items: mergeWalletAssets(this.walletAssetsState.items, committedAssets),
1448
+ committedIds: committedIds
1449
+ });
1450
+ return this.recalculateWalletAssets(this.walletAssetsState.items, selectedIds, selectionSources);
1451
+ }
658
1452
  }, {
659
1453
  key: "processWalletPayment",
660
1454
  value: function () {
661
- var _processWalletPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(amount, orderUuid, voucherId) {
1455
+ var _processWalletPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(amount, orderUuid, voucherId) {
662
1456
  var walletMethod, paymentItem;
663
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
664
- while (1) switch (_context7.prev = _context7.next) {
1457
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1458
+ while (1) switch (_context10.prev = _context10.next) {
665
1459
  case 0:
666
1460
  this.paymentModule.logInfo('[WalletPass] 开始处理钱包支付', {
667
1461
  amount: amount,
668
1462
  orderUuid: orderUuid,
669
1463
  voucherId: voucherId || 'none'
670
1464
  });
671
- _context7.next = 3;
1465
+ _context10.next = 3;
672
1466
  return this.paymentModule.getWalletPaymentMethod();
673
1467
  case 3:
674
- walletMethod = _context7.sent;
1468
+ walletMethod = _context10.sent;
675
1469
  if (walletMethod) {
676
- _context7.next = 7;
1470
+ _context10.next = 7;
677
1471
  break;
678
1472
  }
679
1473
  this.paymentModule.logError('[WalletPass] 钱包支付方式未找到', null, {
@@ -691,7 +1485,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
691
1485
  type: walletMethod.type,
692
1486
  voucher_id: voucherId || ''
693
1487
  };
694
- _context7.next = 10;
1488
+ _context10.next = 10;
695
1489
  return this.paymentModule.addPaymentItemAsync(orderUuid, paymentItem);
696
1490
  case 10:
697
1491
  this.paymentModule.logInfo('[WalletPass] 钱包支付处理完成', {
@@ -702,11 +1496,11 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
702
1496
  });
703
1497
  case 11:
704
1498
  case "end":
705
- return _context7.stop();
1499
+ return _context10.stop();
706
1500
  }
707
- }, _callee7, this);
1501
+ }, _callee10, this);
708
1502
  }));
709
- function processWalletPayment(_x7, _x8, _x9) {
1503
+ function processWalletPayment(_x11, _x12, _x13) {
710
1504
  return _processWalletPayment.apply(this, arguments);
711
1505
  }
712
1506
  return processWalletPayment;
@@ -714,18 +1508,18 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
714
1508
  }, {
715
1509
  key: "getWalletBalance",
716
1510
  value: function () {
717
- var _getWalletBalance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(voucherId) {
718
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
719
- while (1) switch (_context8.prev = _context8.next) {
1511
+ var _getWalletBalance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(voucherId) {
1512
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1513
+ while (1) switch (_context11.prev = _context11.next) {
720
1514
  case 0:
721
- return _context8.abrupt("return", 0);
1515
+ return _context11.abrupt("return", 0);
722
1516
  case 1:
723
1517
  case "end":
724
- return _context8.stop();
1518
+ return _context11.stop();
725
1519
  }
726
- }, _callee8);
1520
+ }, _callee11);
727
1521
  }));
728
- function getWalletBalance(_x10) {
1522
+ function getWalletBalance(_x14) {
729
1523
  return _getWalletBalance.apply(this, arguments);
730
1524
  }
731
1525
  return getWalletBalance;
@@ -805,6 +1599,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
805
1599
  key: "clearSearchResults",
806
1600
  value: function clearSearchResults() {
807
1601
  this.searchResults = [];
1602
+ this.pendingAutoSelectSearchCodes.clear();
808
1603
  this.paymentModule.logInfo('[WalletPass] 搜索结果缓存已清除');
809
1604
  }
810
1605
 
@@ -836,8 +1631,16 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
836
1631
  this.walletRecommendList = [];
837
1632
  this.userIdentificationCodes = [];
838
1633
  this.searchResults = [];
1634
+ this.pendingAutoSelectSearchCodes.clear();
839
1635
  this.walletParams = null;
840
1636
  this.walletInitData = null;
1637
+ this.walletAssetsRequestSequence += 1;
1638
+ this.walletAssetsCalculationContext = {
1639
+ orderTotalAmount: 0,
1640
+ products: []
1641
+ };
1642
+ this.walletAssetsState = createInitialWalletAssetsState();
1643
+ this.publishWalletAssetsState({});
841
1644
 
842
1645
  // 发送所有缓存清除事件
843
1646
  this.emitEvent(WalletPassHooks.OnWalletCacheCleared, {