@pisell/pisellos 3.0.89 → 3.0.91

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 (242) hide show
  1. package/dist/apis/picoding.d.ts +0 -0
  2. package/dist/apis/picoding.js +1 -0
  3. package/dist/model/index.d.ts +1 -0
  4. package/dist/model/index.js +1 -0
  5. package/dist/model/strategy/adapter/index.d.ts +7 -0
  6. package/dist/model/strategy/adapter/index.js +7 -0
  7. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
  8. package/dist/model/strategy/adapter/itemRule/adapter.js +483 -0
  9. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  10. package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
  11. package/dist/model/strategy/adapter/itemRule/examples.d.ts +79 -0
  12. package/dist/model/strategy/adapter/itemRule/examples.js +382 -0
  13. package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
  14. package/dist/model/strategy/adapter/itemRule/index.js +5 -0
  15. package/dist/model/strategy/adapter/itemRule/type.d.ts +225 -0
  16. package/dist/model/strategy/adapter/itemRule/type.js +101 -0
  17. package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  18. package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
  19. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  20. package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
  21. package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
  22. package/dist/model/strategy/adapter/promotion/examples.js +166 -0
  23. package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
  24. package/dist/model/strategy/adapter/promotion/index.js +0 -0
  25. package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
  26. package/dist/model/strategy/adapter/promotion/type.js +209 -0
  27. package/dist/model/strategy/adapter/type.d.ts +28 -0
  28. package/dist/model/strategy/adapter/type.js +1 -0
  29. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  30. package/dist/model/strategy/adapter/walletPass/evaluator.js +502 -0
  31. package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
  32. package/dist/model/strategy/adapter/walletPass/example.js +258 -0
  33. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  34. package/dist/model/strategy/adapter/walletPass/index.js +182 -0
  35. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  36. package/dist/model/strategy/adapter/walletPass/locales.js +26 -0
  37. package/dist/model/strategy/adapter/walletPass/type.d.ts +187 -0
  38. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  39. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  40. package/dist/model/strategy/adapter/walletPass/utils.js +1104 -0
  41. package/dist/model/strategy/engine.d.ts +106 -0
  42. package/dist/model/strategy/engine.js +611 -0
  43. package/dist/model/strategy/index.d.ts +3 -0
  44. package/dist/model/strategy/index.js +8 -0
  45. package/dist/model/strategy/strategy-example.d.ts +5 -0
  46. package/dist/model/strategy/strategy-example.js +331 -0
  47. package/dist/model/strategy/type.d.ts +228 -0
  48. package/dist/model/strategy/type.js +94 -0
  49. package/dist/modules/Cart/utils/cartProduct.js +1 -0
  50. package/dist/modules/Discount/index.d.ts +4 -2
  51. package/dist/modules/Discount/index.js +90 -3
  52. package/dist/modules/Discount/types.d.ts +6 -0
  53. package/dist/modules/OpenData/index.d.ts +24 -0
  54. package/dist/modules/OpenData/index.js +173 -0
  55. package/dist/modules/OpenData/types.d.ts +73 -0
  56. package/dist/modules/OpenData/types.js +1 -0
  57. package/dist/modules/OpenData/utils.d.ts +2 -0
  58. package/dist/modules/OpenData/utils.js +75 -0
  59. package/dist/modules/Order/index.d.ts +66 -1
  60. package/dist/modules/Order/index.js +884 -10
  61. package/dist/modules/Order/types.d.ts +174 -12
  62. package/dist/modules/Order/types.js +2 -0
  63. package/dist/modules/Order/utils.d.ts +118 -0
  64. package/dist/modules/Order/utils.js +586 -2
  65. package/dist/modules/Product/utils.js +2 -2
  66. package/dist/modules/ProductList/index.d.ts +3 -1
  67. package/dist/modules/ProductList/index.js +19 -11
  68. package/dist/modules/Quotation/index.d.ts +48 -0
  69. package/dist/modules/Quotation/index.js +248 -0
  70. package/dist/modules/Quotation/types.d.ts +42 -0
  71. package/dist/modules/Quotation/types.js +1 -0
  72. package/dist/modules/Rules/index.js +17 -18
  73. package/dist/modules/SalesSummary/index.d.ts +63 -0
  74. package/dist/modules/SalesSummary/index.js +174 -0
  75. package/dist/modules/SalesSummary/types.d.ts +60 -0
  76. package/dist/modules/SalesSummary/types.js +1 -0
  77. package/dist/modules/SalesSummary/utils.d.ts +30 -0
  78. package/dist/modules/SalesSummary/utils.js +480 -0
  79. package/dist/modules/ScanOrderLogger/index.d.ts +23 -0
  80. package/dist/modules/ScanOrderLogger/index.js +174 -0
  81. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  82. package/dist/modules/ScanOrderLogger/providers/feishu.js +221 -0
  83. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  84. package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
  85. package/dist/modules/ScanOrderLogger/types.d.ts +53 -0
  86. package/dist/modules/ScanOrderLogger/types.js +1 -0
  87. package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
  88. package/dist/modules/Schedule/utils.d.ts +1 -1
  89. package/dist/modules/Summary/utils.d.ts +3 -3
  90. package/dist/modules/Summary/utils.js +41 -31
  91. package/dist/modules/index.d.ts +4 -0
  92. package/dist/modules/index.js +5 -1
  93. package/dist/solution/BookingByStep/index.d.ts +3 -3
  94. package/dist/solution/BookingByStep/index.js +2 -1
  95. package/dist/solution/BookingByStep/types.d.ts +3 -1
  96. package/dist/solution/BookingByStep/types.js +5 -1
  97. package/dist/solution/ScanOrder/index.d.ts +158 -0
  98. package/dist/solution/ScanOrder/index.js +3474 -0
  99. package/dist/solution/ScanOrder/types.d.ts +306 -0
  100. package/dist/solution/ScanOrder/types.js +35 -0
  101. package/dist/solution/ScanOrder/utils.d.ts +172 -0
  102. package/dist/solution/ScanOrder/utils.js +796 -0
  103. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  104. package/dist/solution/ShopDiscount/index.js +23 -18
  105. package/dist/solution/VenueBooking/index.d.ts +201 -0
  106. package/dist/solution/VenueBooking/index.js +3472 -0
  107. package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  108. package/dist/solution/VenueBooking/types.d.ts +154 -0
  109. package/dist/solution/VenueBooking/types.js +21 -0
  110. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  111. package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
  112. package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
  113. package/dist/solution/VenueBooking/utils/resource.js +131 -0
  114. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  115. package/dist/solution/VenueBooking/utils/slotMerge.js +239 -0
  116. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  117. package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
  118. package/dist/solution/VenueBooking/utils.d.ts +1 -0
  119. package/dist/solution/VenueBooking/utils.js +1 -0
  120. package/dist/solution/index.d.ts +2 -0
  121. package/dist/solution/index.js +3 -1
  122. package/lib/apis/picoding.d.ts +0 -0
  123. package/lib/apis/picoding.js +0 -0
  124. package/lib/model/index.d.ts +1 -0
  125. package/lib/model/index.js +23 -0
  126. package/lib/model/strategy/adapter/index.d.ts +7 -0
  127. package/lib/model/strategy/adapter/index.js +57 -0
  128. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
  129. package/lib/model/strategy/adapter/itemRule/adapter.js +377 -0
  130. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  131. package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
  132. package/lib/model/strategy/adapter/itemRule/examples.d.ts +79 -0
  133. package/lib/model/strategy/adapter/itemRule/examples.js +316 -0
  134. package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
  135. package/lib/model/strategy/adapter/itemRule/index.js +60 -0
  136. package/lib/model/strategy/adapter/itemRule/type.d.ts +225 -0
  137. package/lib/model/strategy/adapter/itemRule/type.js +46 -0
  138. package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  139. package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
  140. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  141. package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
  142. package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
  143. package/lib/model/strategy/adapter/promotion/examples.js +192 -0
  144. package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
  145. package/lib/model/strategy/adapter/promotion/index.js +0 -0
  146. package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
  147. package/lib/model/strategy/adapter/promotion/type.js +51 -0
  148. package/lib/model/strategy/adapter/type.d.ts +28 -0
  149. package/lib/model/strategy/adapter/type.js +17 -0
  150. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  151. package/lib/model/strategy/adapter/walletPass/evaluator.js +424 -0
  152. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  153. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  154. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  155. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  156. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  157. package/lib/model/strategy/adapter/walletPass/locales.js +54 -0
  158. package/lib/model/strategy/adapter/walletPass/type.d.ts +187 -0
  159. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  160. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  161. package/lib/model/strategy/adapter/walletPass/utils.js +791 -0
  162. package/lib/model/strategy/engine.d.ts +106 -0
  163. package/lib/model/strategy/engine.js +450 -0
  164. package/lib/model/strategy/index.d.ts +3 -0
  165. package/lib/model/strategy/index.js +38 -0
  166. package/lib/model/strategy/strategy-example.d.ts +5 -0
  167. package/lib/model/strategy/strategy-example.js +318 -0
  168. package/lib/model/strategy/type.d.ts +228 -0
  169. package/lib/model/strategy/type.js +44 -0
  170. package/lib/modules/Cart/utils/cartProduct.js +1 -0
  171. package/lib/modules/Discount/index.d.ts +4 -2
  172. package/lib/modules/Discount/index.js +60 -2
  173. package/lib/modules/Discount/types.d.ts +6 -0
  174. package/lib/modules/OpenData/index.d.ts +24 -0
  175. package/lib/modules/OpenData/index.js +119 -0
  176. package/lib/modules/OpenData/types.d.ts +73 -0
  177. package/lib/modules/OpenData/types.js +17 -0
  178. package/lib/modules/OpenData/utils.d.ts +2 -0
  179. package/lib/modules/OpenData/utils.js +111 -0
  180. package/lib/modules/Order/index.d.ts +66 -1
  181. package/lib/modules/Order/index.js +525 -0
  182. package/lib/modules/Order/types.d.ts +174 -12
  183. package/lib/modules/Order/utils.d.ts +118 -0
  184. package/lib/modules/Order/utils.js +483 -2
  185. package/lib/modules/Product/utils.js +2 -2
  186. package/lib/modules/ProductList/index.d.ts +3 -1
  187. package/lib/modules/ProductList/index.js +45 -34
  188. package/lib/modules/Quotation/index.d.ts +48 -0
  189. package/lib/modules/Quotation/index.js +152 -0
  190. package/lib/modules/Quotation/types.d.ts +42 -0
  191. package/lib/modules/Quotation/types.js +17 -0
  192. package/lib/modules/Rules/index.js +17 -18
  193. package/lib/modules/SalesSummary/index.d.ts +63 -0
  194. package/lib/modules/SalesSummary/index.js +105 -0
  195. package/lib/modules/SalesSummary/types.d.ts +60 -0
  196. package/lib/modules/SalesSummary/types.js +17 -0
  197. package/lib/modules/SalesSummary/utils.d.ts +30 -0
  198. package/lib/modules/SalesSummary/utils.js +420 -0
  199. package/lib/modules/ScanOrderLogger/index.d.ts +23 -0
  200. package/lib/modules/ScanOrderLogger/index.js +147 -0
  201. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  202. package/lib/modules/ScanOrderLogger/providers/feishu.js +157 -0
  203. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  204. package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
  205. package/lib/modules/ScanOrderLogger/types.d.ts +53 -0
  206. package/lib/modules/ScanOrderLogger/types.js +17 -0
  207. package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
  208. package/lib/modules/Schedule/utils.d.ts +1 -1
  209. package/lib/modules/Summary/utils.d.ts +3 -3
  210. package/lib/modules/Summary/utils.js +22 -16
  211. package/lib/modules/index.d.ts +4 -0
  212. package/lib/modules/index.js +9 -1
  213. package/lib/solution/BookingByStep/index.d.ts +3 -3
  214. package/lib/solution/BookingByStep/index.js +2 -2
  215. package/lib/solution/BookingByStep/types.d.ts +3 -1
  216. package/lib/solution/BookingByStep/types.js +10 -0
  217. package/lib/solution/ScanOrder/index.d.ts +158 -0
  218. package/lib/solution/ScanOrder/index.js +2135 -0
  219. package/lib/solution/ScanOrder/types.d.ts +306 -0
  220. package/lib/solution/ScanOrder/types.js +36 -0
  221. package/lib/solution/ScanOrder/utils.d.ts +172 -0
  222. package/lib/solution/ScanOrder/utils.js +658 -0
  223. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  224. package/lib/solution/ShopDiscount/index.js +4 -2
  225. package/lib/solution/VenueBooking/index.d.ts +201 -0
  226. package/lib/solution/VenueBooking/index.js +1937 -0
  227. package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  228. package/lib/solution/VenueBooking/types.d.ts +154 -0
  229. package/lib/solution/VenueBooking/types.js +44 -0
  230. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  231. package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
  232. package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
  233. package/lib/solution/VenueBooking/utils/resource.js +92 -0
  234. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  235. package/lib/solution/VenueBooking/utils/slotMerge.js +237 -0
  236. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  237. package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
  238. package/lib/solution/VenueBooking/utils.d.ts +1 -0
  239. package/lib/solution/VenueBooking/utils.js +69 -0
  240. package/lib/solution/index.d.ts +2 -0
  241. package/lib/solution/index.js +5 -1
  242. package/package.json +1 -1
@@ -0,0 +1,3474 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ 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."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
6
+ 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); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
11
+ 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; }
12
+ 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; }
13
+ 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); }
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
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 _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
18
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
19
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
20
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
22
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
23
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
25
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
26
+ 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; }
27
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
28
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
29
+ import { BaseModule } from "../../modules/BaseModule";
30
+ import { ScanOrderHooks } from "./types";
31
+ import { OrderModule } from "../../modules/Order";
32
+ import { AccountHooks } from "../../modules/Account/types";
33
+ import { RegisterAndLoginHooks } from "../RegisterAndLogin/types";
34
+ import Decimal from 'decimal.js';
35
+ import { attachItemRuleLimitsToTopLevelProducts, buildProductKey, buildItemRuleBusinessData, collectLinkProductIdsFromReservationRules, computeResourceIsFull, createEmptySummary, findReservationRuleProductByResourceId, getProductIdentityIndex, getSafeProductNum, hasCustomCapacityProduct, pickFirstCustomCapacityDimensionId, pickFirstCustomCapacityPaxBounds, normalizeEnabledItemRuleIds, normalizeOrderProduct, normalizeItemRuleStrategies, pickFirstDurationMinutesFromProducts, toNonNegativeInt, toPriceString, toBoolean, toPositiveString } from "./utils";
36
+ import { createModule } from "../BookingByStep/types";
37
+ import { ProductList } from "../../modules/ProductList";
38
+ import { ScheduleModule } from "../../modules/Schedule";
39
+ import { getDateIsInSchedule } from "../../modules/Schedule/getDateIsInSchedule";
40
+ import { composeLinePrice, createUuidV4, normalizeSubmitCollectPaxValue, sumOptionUnitPrice } from "../../modules/Order/utils";
41
+ import dayjs from 'dayjs';
42
+ import { ItemRuleEvaluator } from "../../model/strategy/adapter/itemRule";
43
+ export * from "./types";
44
+ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
45
+ _inherits(ScanOrderImpl, _BaseModule);
46
+ var _super = _createSuper(ScanOrderImpl);
47
+ function ScanOrderImpl(name, version) {
48
+ var _this;
49
+ _classCallCheck(this, ScanOrderImpl);
50
+ _this = _super.call(this, name, version);
51
+ _defineProperty(_assertThisInitialized(_this), "defaultName", 'scanOrder');
52
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
53
+ _defineProperty(_assertThisInitialized(_this), "isSolution", true);
54
+ _defineProperty(_assertThisInitialized(_this), "initializeOptions", {});
55
+ _defineProperty(_assertThisInitialized(_this), "store", {
56
+ entryContext: null,
57
+ status: 'idle',
58
+ config: null,
59
+ resource: null,
60
+ flow: {},
61
+ error: null,
62
+ products: undefined,
63
+ itemRuleQuantityLimits: [],
64
+ cartValidation: {
65
+ passed: null,
66
+ failures: []
67
+ },
68
+ entryPaxNumber: 1
69
+ });
70
+ _defineProperty(_assertThisInitialized(_this), "otherParams", {});
71
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
72
+ _defineProperty(_assertThisInitialized(_this), "window", void 0);
73
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
74
+ _defineProperty(_assertThisInitialized(_this), "itemRuleEvaluator", new ItemRuleEvaluator());
75
+ _defineProperty(_assertThisInitialized(_this), "itemRuleConfigs", []);
76
+ _defineProperty(_assertThisInitialized(_this), "itemRuleConfigsPromise", null);
77
+ _defineProperty(_assertThisInitialized(_this), "itemRulePrefillApplied", false);
78
+ _defineProperty(_assertThisInitialized(_this), "itemRuleRuntimeConfig", {});
79
+ /** 最近一次 checkResourceAvailable 从预约规则 link 拉取的商品快照 */
80
+ _defineProperty(_assertThisInitialized(_this), "enabledReservationRuleProducts", []);
81
+ _defineProperty(_assertThisInitialized(_this), "loginEffectDisposers", []);
82
+ _defineProperty(_assertThisInitialized(_this), "customerLoginRefreshInFlight", null);
83
+ _defineProperty(_assertThisInitialized(_this), "customerLoginRefreshIdInFlight", null);
84
+ return _this;
85
+ }
86
+
87
+ /** 与 `otherParams.cacheId` 一致,供宿主在 URL 变化时判断是否需要重新注册模块 */
88
+ _createClass(ScanOrderImpl, [{
89
+ key: "getScanOrderLoggerContext",
90
+ value: function getScanOrderLoggerContext() {
91
+ return {
92
+ cacheId: this.cacheId,
93
+ solutionName: this.name,
94
+ moduleName: 'scanOrder'
95
+ };
96
+ }
97
+ }, {
98
+ key: "safeStringify",
99
+ value: function safeStringify(value) {
100
+ try {
101
+ return JSON.stringify(value);
102
+ } catch (_unused) {
103
+ return undefined;
104
+ }
105
+ }
106
+ }, {
107
+ key: "pickErrorMessage",
108
+ value: function pickErrorMessage(error) {
109
+ var _error$data, _error$response, _error$error;
110
+ var candidates = [error.message, (_error$data = error.data) === null || _error$data === void 0 ? void 0 : _error$data.message, (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.data) === null || _error$response === void 0 ? void 0 : _error$response.message, (_error$error = error.error) === null || _error$error === void 0 ? void 0 : _error$error.message];
111
+ for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
112
+ var candidate = _candidates[_i];
113
+ if (typeof candidate === 'string' && candidate.trim()) return candidate;
114
+ }
115
+ return undefined;
116
+ }
117
+ }, {
118
+ key: "serializeError",
119
+ value: function serializeError(error) {
120
+ if (error instanceof Error) {
121
+ return {
122
+ name: error.name,
123
+ message: error.message,
124
+ stack: error.stack
125
+ };
126
+ }
127
+ if (error && _typeof(error) === 'object') {
128
+ var raw = error;
129
+ var message = this.pickErrorMessage(raw) || this.safeStringify(raw) || String(error);
130
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, typeof raw.name === 'string' ? {
131
+ name: raw.name
132
+ } : {}), {}, {
133
+ message: message
134
+ }, 'code' in raw ? {
135
+ code: raw.code
136
+ } : {}), 'status' in raw ? {
137
+ status: raw.status
138
+ } : {}), this.safeStringify(raw) ? {
139
+ raw: this.safeStringify(raw)
140
+ } : {});
141
+ }
142
+ return {
143
+ message: String(error)
144
+ };
145
+ }
146
+ }, {
147
+ key: "addScanOrderLog",
148
+ value: function () {
149
+ var _addScanOrderLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
150
+ var payload, extra, logger;
151
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
152
+ while (1) switch (_context.prev = _context.next) {
153
+ case 0:
154
+ payload = _objectSpread({
155
+ cacheId: this.cacheId
156
+ }, params.payload || {});
157
+ extra = _objectSpread({}, params.extra || {});
158
+ logger = this.store.scanOrderLogger;
159
+ if (logger) {
160
+ _context.next = 6;
161
+ break;
162
+ }
163
+ if ((params.level || 'info') === 'error') {
164
+ console.error('[ScanOrder][log-fallback]', params.title, {
165
+ payload: payload,
166
+ extra: extra
167
+ });
168
+ } else {
169
+ console.log('[ScanOrder][log-fallback]', params.title, {
170
+ payload: payload,
171
+ extra: extra
172
+ });
173
+ }
174
+ return _context.abrupt("return");
175
+ case 6:
176
+ _context.next = 8;
177
+ return logger.addLog(_objectSpread(_objectSpread({}, params), {}, {
178
+ payload: payload,
179
+ extra: extra
180
+ }));
181
+ case 8:
182
+ case "end":
183
+ return _context.stop();
184
+ }
185
+ }, _callee, this);
186
+ }));
187
+ function addScanOrderLog(_x) {
188
+ return _addScanOrderLog.apply(this, arguments);
189
+ }
190
+ return addScanOrderLog;
191
+ }()
192
+ }, {
193
+ key: "logMethodStart",
194
+ value: function logMethodStart(method) {
195
+ var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
196
+ void this.addScanOrderLog({
197
+ level: 'info',
198
+ title: "[ScanOrder] ".concat(method, " start"),
199
+ payload: _objectSpread({
200
+ method: method
201
+ }, payload)
202
+ });
203
+ }
204
+ }, {
205
+ key: "logMethodSuccess",
206
+ value: function logMethodSuccess(method) {
207
+ var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
208
+ void this.addScanOrderLog({
209
+ level: 'info',
210
+ title: "[ScanOrder] ".concat(method, " success"),
211
+ payload: _objectSpread({
212
+ method: method
213
+ }, payload)
214
+ });
215
+ }
216
+ }, {
217
+ key: "logMethodError",
218
+ value: function logMethodError(method, error) {
219
+ var payload = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
220
+ void this.addScanOrderLog({
221
+ level: 'error',
222
+ title: "[ScanOrder] ".concat(method, " failed"),
223
+ payload: _objectSpread(_objectSpread({
224
+ method: method
225
+ }, payload), {}, {
226
+ error: this.serializeError(error)
227
+ })
228
+ });
229
+ }
230
+ }, {
231
+ key: "assertProductListLoaded",
232
+ value: function assertProductListLoaded(method, result) {
233
+ var payload = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
234
+ if (Array.isArray(result)) return result;
235
+ var error = result instanceof Error ? result : new Error('商品列表接口返回异常');
236
+ this.logMethodError(method, error, payload);
237
+ error.__scanOrderLogged = true;
238
+ throw error;
239
+ }
240
+ }, {
241
+ key: "addLog",
242
+ value: function () {
243
+ var _addLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
244
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
245
+ while (1) switch (_context2.prev = _context2.next) {
246
+ case 0:
247
+ _context2.next = 2;
248
+ return this.addScanOrderLog(_objectSpread(_objectSpread({}, params), {}, {
249
+ payload: _objectSpread({
250
+ source: 'ui-bridge'
251
+ }, params.payload || {})
252
+ }));
253
+ case 2:
254
+ case "end":
255
+ return _context2.stop();
256
+ }
257
+ }, _callee2, this);
258
+ }));
259
+ function addLog(_x2) {
260
+ return _addLog.apply(this, arguments);
261
+ }
262
+ return addLog;
263
+ }()
264
+ }, {
265
+ key: "normalizeCustomerId",
266
+ value: function normalizeCustomerId(value) {
267
+ var customerId = Number(value);
268
+ if (!Number.isFinite(customerId) || customerId <= 0) return null;
269
+ return customerId;
270
+ }
271
+ }, {
272
+ key: "resolveCustomerIdFromLoginPayload",
273
+ value: function resolveCustomerIdFromLoginPayload(payload) {
274
+ var _payload$user, _payload$user2, _payload$user3, _payload$user4, _payload$account, _payload$account2, _payload$account3, _payload$_origin;
275
+ var candidates = [payload === null || payload === void 0 ? void 0 : payload.customerId, payload === null || payload === void 0 ? void 0 : payload.customer_id, payload === null || payload === void 0 ? void 0 : payload.id, payload === null || payload === void 0 || (_payload$user = payload.user) === null || _payload$user === void 0 ? void 0 : _payload$user.customerId, payload === null || payload === void 0 || (_payload$user2 = payload.user) === null || _payload$user2 === void 0 ? void 0 : _payload$user2.customer_id, payload === null || payload === void 0 || (_payload$user3 = payload.user) === null || _payload$user3 === void 0 ? void 0 : _payload$user3.id, payload === null || payload === void 0 || (_payload$user4 = payload.user) === null || _payload$user4 === void 0 || (_payload$user4 = _payload$user4._origin) === null || _payload$user4 === void 0 ? void 0 : _payload$user4.customer_id, payload === null || payload === void 0 || (_payload$account = payload.account) === null || _payload$account === void 0 ? void 0 : _payload$account.customerId, payload === null || payload === void 0 || (_payload$account2 = payload.account) === null || _payload$account2 === void 0 ? void 0 : _payload$account2.customer_id, payload === null || payload === void 0 || (_payload$account3 = payload.account) === null || _payload$account3 === void 0 ? void 0 : _payload$account3.id, payload === null || payload === void 0 || (_payload$_origin = payload._origin) === null || _payload$_origin === void 0 ? void 0 : _payload$_origin.customer_id];
276
+ for (var _i2 = 0, _candidates2 = candidates; _i2 < _candidates2.length; _i2++) {
277
+ var candidate = _candidates2[_i2];
278
+ var customerId = this.normalizeCustomerId(candidate);
279
+ if (customerId) return customerId;
280
+ }
281
+ return null;
282
+ }
283
+ }, {
284
+ key: "clearLoginEffectListeners",
285
+ value: function clearLoginEffectListeners() {
286
+ var _iterator = _createForOfIteratorHelper(this.loginEffectDisposers),
287
+ _step;
288
+ try {
289
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
290
+ var dispose = _step.value;
291
+ dispose();
292
+ }
293
+ } catch (err) {
294
+ _iterator.e(err);
295
+ } finally {
296
+ _iterator.f();
297
+ }
298
+ this.loginEffectDisposers = [];
299
+ }
300
+ }, {
301
+ key: "registerLoginEffect",
302
+ value: function registerLoginEffect(event, callback) {
303
+ var _this$core;
304
+ var effects = (_this$core = this.core) === null || _this$core === void 0 ? void 0 : _this$core.effects;
305
+ if (!(effects !== null && effects !== void 0 && effects.on)) return;
306
+ effects.on(event, callback);
307
+ this.loginEffectDisposers.push(function () {
308
+ if (typeof effects.off === 'function') {
309
+ effects.off(event, callback);
310
+ }
311
+ });
312
+ }
313
+ }, {
314
+ key: "registerCustomerLoginListeners",
315
+ value: function registerCustomerLoginListeners() {
316
+ var _this2 = this;
317
+ this.clearLoginEffectListeners();
318
+ var createHandleLogin = function createHandleLogin() {
319
+ return /*#__PURE__*/function () {
320
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(payload) {
321
+ var customerId;
322
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
323
+ while (1) switch (_context3.prev = _context3.next) {
324
+ case 0:
325
+ customerId = _this2.resolveCustomerIdFromLoginPayload(payload);
326
+ if (customerId) {
327
+ _context3.next = 3;
328
+ break;
329
+ }
330
+ return _context3.abrupt("return");
331
+ case 3:
332
+ _context3.next = 5;
333
+ return _this2.refreshOrderMarketingAfterLogin({
334
+ customerId: customerId
335
+ });
336
+ case 5:
337
+ case "end":
338
+ return _context3.stop();
339
+ }
340
+ }, _callee3);
341
+ }));
342
+ return function (_x3) {
343
+ return _ref.apply(this, arguments);
344
+ };
345
+ }();
346
+ };
347
+ this.registerLoginEffect(ScanOrderImpl.PISELL1_LOGIN_SUCCESS, createHandleLogin());
348
+ this.registerLoginEffect(AccountHooks.OnLogin, createHandleLogin());
349
+ this.registerLoginEffect(RegisterAndLoginHooks.onLoginSuccess, createHandleLogin());
350
+ }
351
+ }, {
352
+ key: "refreshOrderMarketingAfterLogin",
353
+ value: function () {
354
+ var _refreshOrderMarketingAfterLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
355
+ var _this3 = this;
356
+ var refreshTask;
357
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
358
+ while (1) switch (_context5.prev = _context5.next) {
359
+ case 0:
360
+ if (this.store.order) {
361
+ _context5.next = 2;
362
+ break;
363
+ }
364
+ throw new Error('order 模块未初始化');
365
+ case 2:
366
+ if (!this.customerLoginRefreshInFlight) {
367
+ _context5.next = 9;
368
+ break;
369
+ }
370
+ if (!(this.customerLoginRefreshIdInFlight === params.customerId)) {
371
+ _context5.next = 7;
372
+ break;
373
+ }
374
+ _context5.next = 6;
375
+ return this.customerLoginRefreshInFlight;
376
+ case 6:
377
+ return _context5.abrupt("return");
378
+ case 7:
379
+ _context5.next = 9;
380
+ return this.customerLoginRefreshInFlight;
381
+ case 9:
382
+ this.customerLoginRefreshIdInFlight = params.customerId;
383
+ refreshTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
384
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
385
+ while (1) switch (_context4.prev = _context4.next) {
386
+ case 0:
387
+ _context4.next = 2;
388
+ return _this3.store.order.loadDiscountConfig({
389
+ customerId: params.customerId
390
+ });
391
+ case 2:
392
+ _context4.next = 4;
393
+ return _this3.store.order.recalculateSummary({
394
+ createIfMissing: true
395
+ });
396
+ case 4:
397
+ _this3.store.order.persistTempOrder();
398
+ _context4.next = 7;
399
+ return _this3.refreshItemRuleQuantityLimits();
400
+ case 7:
401
+ _context4.next = 9;
402
+ return _this3.refreshCartValidationPassed();
403
+ case 9:
404
+ case "end":
405
+ return _context4.stop();
406
+ }
407
+ }, _callee4);
408
+ }))();
409
+ this.customerLoginRefreshInFlight = refreshTask;
410
+ _context5.prev = 12;
411
+ _context5.next = 15;
412
+ return refreshTask;
413
+ case 15:
414
+ _context5.next = 20;
415
+ break;
416
+ case 17:
417
+ _context5.prev = 17;
418
+ _context5.t0 = _context5["catch"](12);
419
+ throw _context5.t0;
420
+ case 20:
421
+ _context5.prev = 20;
422
+ if (this.customerLoginRefreshInFlight === refreshTask) {
423
+ this.customerLoginRefreshInFlight = null;
424
+ this.customerLoginRefreshIdInFlight = null;
425
+ }
426
+ return _context5.finish(20);
427
+ case 23:
428
+ case "end":
429
+ return _context5.stop();
430
+ }
431
+ }, _callee5, this, [[12, 17, 20, 23]]);
432
+ }));
433
+ function refreshOrderMarketingAfterLogin(_x4) {
434
+ return _refreshOrderMarketingAfterLogin.apply(this, arguments);
435
+ }
436
+ return refreshOrderMarketingAfterLogin;
437
+ }()
438
+ }, {
439
+ key: "getCacheId",
440
+ value: function getCacheId() {
441
+ return this.cacheId;
442
+ }
443
+ }, {
444
+ key: "destroyRegisteredChildModules",
445
+ value: function () {
446
+ var _destroyRegisteredChildModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
447
+ var modules, _i3, _modules, mod;
448
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
449
+ while (1) switch (_context6.prev = _context6.next) {
450
+ case 0:
451
+ modules = [this.store.schedule, this.store.salesSummary, this.store.order, this.store.products, this.store.scanOrderLogger];
452
+ _i3 = 0, _modules = modules;
453
+ case 2:
454
+ if (!(_i3 < _modules.length)) {
455
+ _context6.next = 10;
456
+ break;
457
+ }
458
+ mod = _modules[_i3];
459
+ if (!(mod && typeof mod.destroy === 'function')) {
460
+ _context6.next = 7;
461
+ break;
462
+ }
463
+ _context6.next = 7;
464
+ return Promise.resolve(mod.destroy());
465
+ case 7:
466
+ _i3++;
467
+ _context6.next = 2;
468
+ break;
469
+ case 10:
470
+ case "end":
471
+ return _context6.stop();
472
+ }
473
+ }, _callee6, this);
474
+ }));
475
+ function destroyRegisteredChildModules() {
476
+ return _destroyRegisteredChildModules.apply(this, arguments);
477
+ }
478
+ return destroyRegisteredChildModules;
479
+ }()
480
+ }, {
481
+ key: "initialize",
482
+ value: function () {
483
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(core) {
484
+ var _options$otherParams,
485
+ _this$otherParams,
486
+ _this$otherParams2,
487
+ _this$otherParams3,
488
+ _this4 = this;
489
+ var options,
490
+ moduleArr,
491
+ scheduleModule,
492
+ _this$store$order,
493
+ _this$store$order2,
494
+ _args7 = arguments;
495
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
496
+ while (1) switch (_context7.prev = _context7.next) {
497
+ case 0:
498
+ options = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {};
499
+ this.logMethodStart('initialize');
500
+ this.core = core;
501
+ this.initializeOptions = options || {};
502
+ this.store = _objectSpread(_objectSpread({}, this.store), options.store);
503
+ this.store.entryContext = ((_options$otherParams = options.otherParams) === null || _options$otherParams === void 0 ? void 0 : _options$otherParams.entryContext) || this.store.entryContext;
504
+ this.store.status = 'initializing';
505
+ this.store.error = null;
506
+ this.otherParams = options.otherParams || {};
507
+ this.cacheId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.cacheId;
508
+ this.itemRuleRuntimeConfig = ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.scanOrderItemRule) || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.itemRule) || {};
509
+ this.itemRuleConfigs = [];
510
+ this.itemRuleConfigsPromise = null;
511
+ this.itemRulePrefillApplied = false;
512
+ this.store.itemRuleQuantityLimits = [];
513
+ this.store.cartValidation = {
514
+ passed: null,
515
+ failures: []
516
+ };
517
+ this.window = core.getPlugin('window');
518
+ this.request = core.getPlugin('request');
519
+ if (this.window) {
520
+ _context7.next = 21;
521
+ break;
522
+ }
523
+ this.logMethodError('initialize', 'window plugin missing');
524
+ throw new Error('scanOrder解决方案需要 window 插件支持');
525
+ case 21:
526
+ if (this.request) {
527
+ _context7.next = 24;
528
+ break;
529
+ }
530
+ this.logMethodError('initialize', 'request plugin missing');
531
+ throw new Error('scanOrder解决方案需要 request 插件支持');
532
+ case 24:
533
+ moduleArr = ['scanOrderLogger', 'products', 'order', 'salesSummary'];
534
+ moduleArr.forEach(function (step) {
535
+ var targetModule = createModule(step, _this4.name);
536
+ if (targetModule) {
537
+ var _this4$store$order, _this4$otherParams, _this4$otherParams2, _this4$otherParams3, _this4$otherParams4;
538
+ _this4.store[step] = targetModule;
539
+ var initialState = step === 'salesSummary' ? {
540
+ summary: ((_this4$store$order = _this4.store.order) === null || _this4$store$order === void 0 || (_this4$store$order = _this4$store$order.getTempOrder()) === null || _this4$store$order === void 0 ? void 0 : _this4$store$order.summary) || createEmptySummary()
541
+ } : {};
542
+ var loggerProvider = ((_this4$otherParams = _this4.otherParams) === null || _this4$otherParams === void 0 ? void 0 : _this4$otherParams.scanOrderLoggerProvider) || 'feishu';
543
+ var loggerConfig = ((_this4$otherParams2 = _this4.otherParams) === null || _this4$otherParams2 === void 0 ? void 0 : _this4$otherParams2.scanOrderLoggerConfig) || {
544
+ feishu: {
545
+ webhook: 'https://open.feishu.cn/open-apis/bot/v2/hook/216b3fe6-af98-424e-8706-f0471241a7ed',
546
+ errorHook: 'https://open.feishu.cn/open-apis/bot/v2/hook/015b7c2a-dd3c-4c30-9898-ef0f5253111f'
547
+ }
548
+ };
549
+ _this4.core.registerModule(targetModule, {
550
+ initialState: initialState,
551
+ otherParams: _objectSpread(_objectSpread({}, _this4.otherParams), {}, {
552
+ fatherModule: _this4.name,
553
+ openCache: (_this4$otherParams3 = _this4.otherParams) !== null && _this4$otherParams3 !== void 0 && _this4$otherParams3.cacheId ? true : false,
554
+ cacheId: (_this4$otherParams4 = _this4.otherParams) === null || _this4$otherParams4 === void 0 ? void 0 : _this4$otherParams4.cacheId,
555
+ salesSummaryModuleName: "".concat(_this4.name, "_salesSummary"),
556
+ provider: loggerProvider,
557
+ providerConfig: loggerConfig,
558
+ context: _this4.getScanOrderLoggerContext()
559
+ })
560
+ });
561
+ } else {
562
+ _this4.logMethodError('initialize', "module ".concat(step, " missing"));
563
+ throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
564
+ }
565
+ });
566
+ if (this.store.scanOrderLogger) {
567
+ this.store.scanOrderLogger.setContext(this.getScanOrderLoggerContext());
568
+ }
569
+ scheduleModule = new ScheduleModule("".concat(this.name, "_schedule"));
570
+ this.store.schedule = scheduleModule;
571
+ this.core.registerModule(scheduleModule, {
572
+ otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
573
+ fatherModule: this.name
574
+ })
575
+ });
576
+ this.registerCustomerLoginListeners();
577
+ console.log('[ScanOrder] 初始化开始');
578
+ _context7.prev = 32;
579
+ _context7.next = 35;
580
+ return (_this$store$order = this.store.order) === null || _this$store$order === void 0 ? void 0 : _this$store$order.recalculateSummary({
581
+ createIfMissing: false
582
+ });
583
+ case 35:
584
+ (_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 || _this$store$order2.persistTempOrder();
585
+ _context7.next = 38;
586
+ return this.loadRuntimeConfigs();
587
+ case 38:
588
+ if (!this.store.schedule) {
589
+ _context7.next = 47;
590
+ break;
591
+ }
592
+ _context7.prev = 39;
593
+ _context7.next = 42;
594
+ return this.store.schedule.loadAllSchedule();
595
+ case 42:
596
+ _context7.next = 47;
597
+ break;
598
+ case 44:
599
+ _context7.prev = 44;
600
+ _context7.t0 = _context7["catch"](39);
601
+ console.warn('[ScanOrder] loadAllSchedule 失败,operating_hours 判定将跳过', _context7.t0);
602
+ case 47:
603
+ _context7.next = 49;
604
+ return this.refreshItemRuleQuantityLimits();
605
+ case 49:
606
+ this.store.status = 'ready';
607
+ console.log('[ScanOrder] 初始化完成');
608
+ _context7.next = 53;
609
+ return this.core.effects.emit(ScanOrderHooks.onInited, {
610
+ status: this.store.status
611
+ });
612
+ case 53:
613
+ this.logMethodSuccess('initialize', {
614
+ status: this.store.status
615
+ });
616
+ _context7.next = 63;
617
+ break;
618
+ case 56:
619
+ _context7.prev = 56;
620
+ _context7.t1 = _context7["catch"](32);
621
+ this.store.status = 'error';
622
+ this.store.error = _context7.t1 instanceof Error ? _context7.t1.message : '初始化失败';
623
+ console.error('[ScanOrder] 初始化失败', _context7.t1);
624
+ this.logMethodError('initialize', _context7.t1, {
625
+ status: this.store.status
626
+ });
627
+ throw _context7.t1;
628
+ case 63:
629
+ case "end":
630
+ return _context7.stop();
631
+ }
632
+ }, _callee7, this, [[32, 56], [39, 44]]);
633
+ }));
634
+ function initialize(_x5) {
635
+ return _initialize.apply(this, arguments);
636
+ }
637
+ return initialize;
638
+ }()
639
+ }, {
640
+ key: "destroy",
641
+ value: function () {
642
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
643
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
644
+ while (1) switch (_context8.prev = _context8.next) {
645
+ case 0:
646
+ this.logMethodStart('destroy');
647
+ this.clearLoginEffectListeners();
648
+ _context8.next = 4;
649
+ return this.core.effects.emit(ScanOrderHooks.onDestroy, {});
650
+ case 4:
651
+ _context8.next = 6;
652
+ return this.destroyRegisteredChildModules();
653
+ case 6:
654
+ _get(_getPrototypeOf(ScanOrderImpl.prototype), "destroy", this).call(this);
655
+ console.log('[ScanOrder] 已销毁');
656
+ this.logMethodSuccess('destroy');
657
+ case 9:
658
+ case "end":
659
+ return _context8.stop();
660
+ }
661
+ }, _callee8, this);
662
+ }));
663
+ function destroy() {
664
+ return _destroy.apply(this, arguments);
665
+ }
666
+ return destroy;
667
+ }()
668
+ }, {
669
+ key: "retryInit",
670
+ value: function () {
671
+ var _retryInit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
672
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
673
+ while (1) switch (_context9.prev = _context9.next) {
674
+ case 0:
675
+ this.logMethodStart('retryInit');
676
+ // TODO: 细化重试策略(指数退避、最大重试次数)后替换当前实现
677
+ console.log('[ScanOrder] retryInit 调用');
678
+ _context9.next = 4;
679
+ return this.core.effects.emit(ScanOrderHooks.onRetryInit, {});
680
+ case 4:
681
+ _context9.prev = 4;
682
+ _context9.next = 7;
683
+ return this.initialize(this.core, this.initializeOptions);
684
+ case 7:
685
+ this.logMethodSuccess('retryInit');
686
+ _context9.next = 14;
687
+ break;
688
+ case 10:
689
+ _context9.prev = 10;
690
+ _context9.t0 = _context9["catch"](4);
691
+ this.logMethodError('retryInit', _context9.t0);
692
+ throw _context9.t0;
693
+ case 14:
694
+ case "end":
695
+ return _context9.stop();
696
+ }
697
+ }, _callee9, this, [[4, 10]]);
698
+ }));
699
+ function retryInit() {
700
+ return _retryInit.apply(this, arguments);
701
+ }
702
+ return retryInit;
703
+ }()
704
+ }, {
705
+ key: "refresh",
706
+ value: function () {
707
+ var _refresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
708
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
709
+ while (1) switch (_context10.prev = _context10.next) {
710
+ case 0:
711
+ this.logMethodStart('refresh');
712
+ // TODO: 接入真实刷新逻辑(资源重拉取、流程重建)后替换当前实现
713
+ console.log('[ScanOrder] refresh 调用');
714
+ _context10.prev = 2;
715
+ this.store.status = 'initializing';
716
+ _context10.next = 6;
717
+ return this.loadRuntimeConfigs();
718
+ case 6:
719
+ _context10.next = 8;
720
+ return this.refreshItemRuleQuantityLimits();
721
+ case 8:
722
+ this.store.status = 'ready';
723
+ _context10.next = 11;
724
+ return this.core.effects.emit(ScanOrderHooks.onRefresh, {
725
+ status: this.store.status
726
+ });
727
+ case 11:
728
+ this.logMethodSuccess('refresh', {
729
+ status: this.store.status
730
+ });
731
+ _context10.next = 18;
732
+ break;
733
+ case 14:
734
+ _context10.prev = 14;
735
+ _context10.t0 = _context10["catch"](2);
736
+ this.logMethodError('refresh', _context10.t0);
737
+ throw _context10.t0;
738
+ case 18:
739
+ case "end":
740
+ return _context10.stop();
741
+ }
742
+ }, _callee10, this, [[2, 14]]);
743
+ }));
744
+ function refresh() {
745
+ return _refresh.apply(this, arguments);
746
+ }
747
+ return refresh;
748
+ }()
749
+ }, {
750
+ key: "getStatus",
751
+ value: function getStatus() {
752
+ this.logMethodStart('getStatus');
753
+ var result = this.store.status;
754
+ this.logMethodSuccess('getStatus', {
755
+ status: result
756
+ });
757
+ return result;
758
+ }
759
+ }, {
760
+ key: "getEntryContext",
761
+ value: function getEntryContext() {
762
+ this.logMethodStart('getEntryContext');
763
+ var result = this.store.entryContext;
764
+ this.logMethodSuccess('getEntryContext', {
765
+ hasEntryContext: Boolean(result)
766
+ });
767
+ return result;
768
+ }
769
+ }, {
770
+ key: "getConfig",
771
+ value: function getConfig() {
772
+ this.logMethodStart('getConfig');
773
+ var result = this.store.config || {};
774
+ this.logMethodSuccess('getConfig', {
775
+ configKeys: Object.keys(result || {})
776
+ });
777
+ return result;
778
+ }
779
+ }, {
780
+ key: "getItemRuleQuantityLimits",
781
+ value: function getItemRuleQuantityLimits() {
782
+ this.logMethodStart('getItemRuleQuantityLimits');
783
+ var result = this.store.itemRuleQuantityLimits || [];
784
+ this.logMethodSuccess('getItemRuleQuantityLimits', {
785
+ limitCount: result.length
786
+ });
787
+ return result;
788
+ }
789
+ }, {
790
+ key: "getCartValidationPassed",
791
+ value: function getCartValidationPassed() {
792
+ var _this$store$cartValid, _this$store$cartValid2;
793
+ this.logMethodStart('getCartValidationPassed');
794
+ var result = (_this$store$cartValid = (_this$store$cartValid2 = this.store.cartValidation) === null || _this$store$cartValid2 === void 0 ? void 0 : _this$store$cartValid2.passed) !== null && _this$store$cartValid !== void 0 ? _this$store$cartValid : null;
795
+ this.logMethodSuccess('getCartValidationPassed', {
796
+ cartValidationPassed: result
797
+ });
798
+ return result;
799
+ }
800
+ }, {
801
+ key: "getCartValidation",
802
+ value: function getCartValidation() {
803
+ this.logMethodStart('getCartValidation');
804
+ var result = this.store.cartValidation || {
805
+ passed: null,
806
+ failures: []
807
+ };
808
+ this.logMethodSuccess('getCartValidation', {
809
+ cartValidationPassed: result.passed,
810
+ failureCount: Array.isArray(result.failures) ? result.failures.length : 0
811
+ });
812
+ return result;
813
+ }
814
+ }, {
815
+ key: "getTempOrder",
816
+ value: function getTempOrder() {
817
+ var _this$store$order3, _result$products, _result$note;
818
+ this.logMethodStart('getTempOrder');
819
+ var result = ((_this$store$order3 = this.store.order) === null || _this$store$order3 === void 0 ? void 0 : _this$store$order3.getTempOrder()) || null;
820
+ this.logMethodSuccess('getTempOrder', {
821
+ hasTempOrder: Boolean(result),
822
+ productCount: (result === null || result === void 0 || (_result$products = result.products) === null || _result$products === void 0 ? void 0 : _result$products.length) || 0,
823
+ noteLength: (result === null || result === void 0 || (_result$note = result.note) === null || _result$note === void 0 ? void 0 : _result$note.length) || 0
824
+ });
825
+ return result;
826
+ }
827
+ }, {
828
+ key: "updateTempOrderNote",
829
+ value: function updateTempOrderNote(note) {
830
+ this.logMethodStart('updateTempOrderNote', {
831
+ noteLength: String(note || '').length
832
+ });
833
+ try {
834
+ if (!this.store.order) throw new Error('order 模块未初始化');
835
+ var result = this.store.order.updateTempOrderNote(note);
836
+ this.logMethodSuccess('updateTempOrderNote', {
837
+ noteLength: result.length
838
+ });
839
+ return result;
840
+ } catch (error) {
841
+ this.logMethodError('updateTempOrderNote', error);
842
+ throw error;
843
+ }
844
+ }
845
+
846
+ // 存储 UI 层选择的取餐方式到 tempOrder.metadata.shop_service_data
847
+ // service_type 在扫码点餐场景固定为 dine_in
848
+ }, {
849
+ key: "setPickupReferenceMode",
850
+ value: function setPickupReferenceMode(mode) {
851
+ this.logMethodStart('setPickupReferenceMode', {
852
+ mode: mode
853
+ });
854
+ try {
855
+ var _this$otherParams4;
856
+ if (!this.store.order) throw new Error('order 模块未初始化');
857
+ var tempOrder = this.store.order.ensureTempOrder();
858
+ tempOrder.metadata = _objectSpread(_objectSpread({}, tempOrder.metadata || {}), {}, {
859
+ shop_service_data: _objectSpread(_objectSpread({}, (tempOrder.metadata || {}).shop_service_data || {}), {}, {
860
+ service_type: ((_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.businessCode) === 'dine_in' ? 'dine_in' : '',
861
+ pickup_reference_mode: mode
862
+ })
863
+ });
864
+ this.store.order.persistTempOrder();
865
+ this.logMethodSuccess('setPickupReferenceMode', {
866
+ mode: mode
867
+ });
868
+ return tempOrder.metadata.shop_service_data;
869
+ } catch (error) {
870
+ this.logMethodError('setPickupReferenceMode', error, {
871
+ mode: mode
872
+ });
873
+ throw error;
874
+ }
875
+ }
876
+
877
+ // 存储用户自定义取餐标识到 tempOrder.buzzer
878
+ }, {
879
+ key: "setPickupRef",
880
+ value: function setPickupRef(buzzer) {
881
+ this.logMethodStart('setPickupRef', {
882
+ buzzerLength: String(buzzer || '').length
883
+ });
884
+ try {
885
+ if (!this.store.order) throw new Error('order 模块未初始化');
886
+ var result = this.store.order.updateTempOrderBuzzer(buzzer);
887
+ this.logMethodSuccess('setPickupRef', {
888
+ buzzerLength: result.length
889
+ });
890
+ return result;
891
+ } catch (error) {
892
+ this.logMethodError('setPickupRef', error);
893
+ throw error;
894
+ }
895
+ }
896
+ }, {
897
+ key: "ensureTempOrder",
898
+ value: function ensureTempOrder() {
899
+ if (!this.store.order) throw new Error('order 模块未初始化');
900
+ return this.store.order.ensureTempOrder();
901
+ }
902
+
903
+ // 主动创建临时订单;若已存在则直接返回已有订单
904
+ }, {
905
+ key: "addNewOrder",
906
+ value: function () {
907
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
908
+ var tempOrder;
909
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
910
+ while (1) switch (_context11.prev = _context11.next) {
911
+ case 0:
912
+ this.logMethodStart('addNewOrder');
913
+ _context11.prev = 1;
914
+ if (this.store.order) {
915
+ _context11.next = 4;
916
+ break;
917
+ }
918
+ throw new Error('order 模块未初始化');
919
+ case 4:
920
+ _context11.next = 6;
921
+ return this.store.order.addNewOrder();
922
+ case 6:
923
+ tempOrder = _context11.sent;
924
+ this.logMethodSuccess('addNewOrder', {
925
+ productCount: tempOrder.products.length
926
+ });
927
+ return _context11.abrupt("return", tempOrder);
928
+ case 11:
929
+ _context11.prev = 11;
930
+ _context11.t0 = _context11["catch"](1);
931
+ this.logMethodError('addNewOrder', _context11.t0);
932
+ throw _context11.t0;
933
+ case 15:
934
+ case "end":
935
+ return _context11.stop();
936
+ }
937
+ }, _callee11, this, [[1, 11]]);
938
+ }));
939
+ function addNewOrder() {
940
+ return _addNewOrder.apply(this, arguments);
941
+ }
942
+ return addNewOrder;
943
+ }() // 重置 tempOrder 与与上一单强相关的运行态(resource/entryPaxNumber/enabledReservationRuleProducts),
944
+ // 适用于从支付页通过 react-router 跳回继续下单时清理残留数据
945
+ }, {
946
+ key: "restoreOrder",
947
+ value: function () {
948
+ var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
949
+ var tempOrder;
950
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
951
+ while (1) switch (_context12.prev = _context12.next) {
952
+ case 0:
953
+ this.logMethodStart('restoreOrder');
954
+ _context12.prev = 1;
955
+ if (this.store.order) {
956
+ _context12.next = 4;
957
+ break;
958
+ }
959
+ throw new Error('scanOrder 解决方案需要 order 模块支持');
960
+ case 4:
961
+ this.store.resource = null;
962
+ this.store.entryPaxNumber = 1;
963
+ this.enabledReservationRuleProducts = [];
964
+ tempOrder = this.store.order.restoreOrder();
965
+ this.logMethodSuccess('restoreOrder');
966
+ return _context12.abrupt("return", tempOrder);
967
+ case 12:
968
+ _context12.prev = 12;
969
+ _context12.t0 = _context12["catch"](1);
970
+ this.logMethodError('restoreOrder', _context12.t0);
971
+ throw _context12.t0;
972
+ case 16:
973
+ case "end":
974
+ return _context12.stop();
975
+ }
976
+ }, _callee12, this, [[1, 12]]);
977
+ }));
978
+ function restoreOrder() {
979
+ return _restoreOrder.apply(this, arguments);
980
+ }
981
+ return restoreOrder;
982
+ }()
983
+ }, {
984
+ key: "getOrderProducts",
985
+ value: function getOrderProducts() {
986
+ this.logMethodStart('getOrderProducts');
987
+ if (!this.store.order) throw new Error('order 模块未初始化');
988
+ var products = this.store.order.getOrderProducts();
989
+ this.logMethodSuccess('getOrderProducts', {
990
+ productCount: products.length
991
+ });
992
+ return products;
993
+ }
994
+ }, {
995
+ key: "getSummary",
996
+ value: function () {
997
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
998
+ var summary;
999
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1000
+ while (1) switch (_context13.prev = _context13.next) {
1001
+ case 0:
1002
+ this.logMethodStart('getSummary');
1003
+ _context13.prev = 1;
1004
+ if (this.store.order) {
1005
+ _context13.next = 4;
1006
+ break;
1007
+ }
1008
+ throw new Error('order 模块未初始化');
1009
+ case 4:
1010
+ _context13.next = 6;
1011
+ return this.store.order.getScanOrderSummary();
1012
+ case 6:
1013
+ summary = _context13.sent;
1014
+ this.logMethodSuccess('getSummary', {
1015
+ totalAmount: summary.total_amount
1016
+ });
1017
+ return _context13.abrupt("return", summary);
1018
+ case 11:
1019
+ _context13.prev = 11;
1020
+ _context13.t0 = _context13["catch"](1);
1021
+ this.logMethodError('getSummary', _context13.t0);
1022
+ throw _context13.t0;
1023
+ case 15:
1024
+ case "end":
1025
+ return _context13.stop();
1026
+ }
1027
+ }, _callee13, this, [[1, 11]]);
1028
+ }));
1029
+ function getSummary() {
1030
+ return _getSummary.apply(this, arguments);
1031
+ }
1032
+ return getSummary;
1033
+ }()
1034
+ }, {
1035
+ key: "getDiscountList",
1036
+ value: function getDiscountList() {
1037
+ if (!this.store.order) return [];
1038
+ return this.store.order.getDiscountList();
1039
+ }
1040
+ }, {
1041
+ key: "scanCode",
1042
+ value: function () {
1043
+ var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(code, customerId) {
1044
+ var raw;
1045
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1046
+ while (1) switch (_context14.prev = _context14.next) {
1047
+ case 0:
1048
+ this.logMethodStart('scanCode', {
1049
+ code: code
1050
+ });
1051
+ _context14.prev = 1;
1052
+ if (this.store.order) {
1053
+ _context14.next = 4;
1054
+ break;
1055
+ }
1056
+ throw new Error('order 模块未初始化');
1057
+ case 4:
1058
+ _context14.next = 6;
1059
+ return this.store.order.scanCode(code, customerId);
1060
+ case 6:
1061
+ raw = _context14.sent;
1062
+ if (!raw.isAvailable) {
1063
+ _context14.next = 11;
1064
+ break;
1065
+ }
1066
+ _context14.next = 10;
1067
+ return this.store.order.recalculateSummary({
1068
+ createIfMissing: true
1069
+ });
1070
+ case 10:
1071
+ this.store.order.persistTempOrder();
1072
+ case 11:
1073
+ this.logMethodSuccess('scanCode', {
1074
+ isAvailable: raw.isAvailable
1075
+ });
1076
+ return _context14.abrupt("return", {
1077
+ isAvailable: raw.isAvailable,
1078
+ type: raw.type,
1079
+ unavailableReason: raw.unavailableReason
1080
+ });
1081
+ case 15:
1082
+ _context14.prev = 15;
1083
+ _context14.t0 = _context14["catch"](1);
1084
+ this.logMethodError('scanCode', _context14.t0);
1085
+ throw _context14.t0;
1086
+ case 19:
1087
+ case "end":
1088
+ return _context14.stop();
1089
+ }
1090
+ }, _callee14, this, [[1, 15]]);
1091
+ }));
1092
+ function scanCode(_x6, _x7) {
1093
+ return _scanCode.apply(this, arguments);
1094
+ }
1095
+ return scanCode;
1096
+ }()
1097
+ }, {
1098
+ key: "setDiscountSelected",
1099
+ value: function () {
1100
+ var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1101
+ var _tempOrder$holder, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder2, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, _iterator3, _step3, _product$_origin, _product$metadata$sou, _product$metadata, _product$metadata2, _product$original_pri, product, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
1102
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1103
+ while (1) switch (_context15.prev = _context15.next) {
1104
+ case 0:
1105
+ this.logMethodStart('setDiscountSelected', params);
1106
+ _context15.prev = 1;
1107
+ if (this.store.order) {
1108
+ _context15.next = 4;
1109
+ break;
1110
+ }
1111
+ throw new Error('order 模块未初始化');
1112
+ case 4:
1113
+ list = this.store.order.getDiscountList();
1114
+ updated = list.map(function (d) {
1115
+ return d.id === params.discountId ? _objectSpread(_objectSpread({}, d), {}, {
1116
+ isSelected: params.isSelected,
1117
+ isManualSelect: !params.isSelected
1118
+ }) : d;
1119
+ });
1120
+ tempOrder = this.store.order.ensureTempOrder();
1121
+ orderStore = this.store.order.store || {};
1122
+ discountModule = orderStore.discount;
1123
+ rulesModule = orderStore.rules;
1124
+ holders = (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
1125
+ form_record_id: tempOrder.holder.form_record_id
1126
+ }] : [];
1127
+ nextDiscountList = updated;
1128
+ _context15.next = 14;
1129
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(updated);
1130
+ case 14:
1131
+ if (rulesModule) {
1132
+ result = rulesModule.calcDiscount({
1133
+ productList: tempOrder.products,
1134
+ discountList: updated,
1135
+ holders: holders,
1136
+ isFormSubject: !!((_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form'
1137
+ }, {
1138
+ discountId: params.discountId,
1139
+ isSelected: params.isSelected
1140
+ }) || {
1141
+ productList: tempOrder.products,
1142
+ discountList: updated
1143
+ };
1144
+ if (result !== null && result !== void 0 && result.productList) {
1145
+ tempOrder.products = result.productList;
1146
+ }
1147
+ if (result !== null && result !== void 0 && result.discountList) {
1148
+ nextDiscountList = result.discountList;
1149
+ if (!params.isSelected) {
1150
+ beforeSelectedIds = new Set(updated.filter(function (d) {
1151
+ return d.isSelected;
1152
+ }).map(function (d) {
1153
+ return d.id;
1154
+ }));
1155
+ _iterator2 = _createForOfIteratorHelper(nextDiscountList);
1156
+ try {
1157
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1158
+ d = _step2.value;
1159
+ if (d.isSelected && !beforeSelectedIds.has(d.id)) {
1160
+ d.isSelected = false;
1161
+ }
1162
+ }
1163
+ } catch (err) {
1164
+ _iterator2.e(err);
1165
+ } finally {
1166
+ _iterator2.f();
1167
+ }
1168
+ }
1169
+ }
1170
+ }
1171
+ selectedResourceIds = new Set(nextDiscountList.filter(function (d) {
1172
+ return d.isSelected;
1173
+ }).map(function (d) {
1174
+ return d.id;
1175
+ }));
1176
+ _iterator3 = _createForOfIteratorHelper(tempOrder.products);
1177
+ _context15.prev = 17;
1178
+ _iterator3.s();
1179
+ case 19:
1180
+ if ((_step3 = _iterator3.n()).done) {
1181
+ _context15.next = 33;
1182
+ break;
1183
+ }
1184
+ product = _step3.value;
1185
+ if (!((_product$_origin = product._origin) !== null && _product$_origin !== void 0 && _product$_origin.isManualDiscount)) {
1186
+ _context15.next = 23;
1187
+ break;
1188
+ }
1189
+ return _context15.abrupt("continue", 31);
1190
+ case 23:
1191
+ product.discount_list = (product.discount_list || []).filter(function (pd) {
1192
+ var _pd$discount$resource, _pd$discount;
1193
+ var rid = (_pd$discount$resource = (_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) !== null && _pd$discount$resource !== void 0 ? _pd$discount$resource : pd.id;
1194
+ return rid != null && selectedResourceIds.has(rid);
1195
+ });
1196
+
1197
+ // 券作用于 source(不含 option、不含 bundle);算出新 source 折后价后补回 options
1198
+ // 写入含 option 的 main_product_selling_price,再合成 composite 回写 selling_price。
1199
+ totalPerUnitDiscount = (product.discount_list || []).reduce(function (sum, pd) {
1200
+ return sum + (pd.amount || 0);
1201
+ }, 0);
1202
+ optionSum = sumOptionUnitPrice(product.product_option_item);
1203
+ sourcePrice = (_product$metadata$sou = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
1204
+ newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1205
+ newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1206
+ if (product.metadata) {
1207
+ product.metadata.main_product_selling_price = newMainSellingPrice;
1208
+ product.metadata.price_schema_version = 2;
1209
+ }
1210
+ product.selling_price = composeLinePrice({
1211
+ mainPrice: newMainSellingPrice,
1212
+ bundle: product.product_bundle
1213
+ });
1214
+ case 31:
1215
+ _context15.next = 19;
1216
+ break;
1217
+ case 33:
1218
+ _context15.next = 38;
1219
+ break;
1220
+ case 35:
1221
+ _context15.prev = 35;
1222
+ _context15.t0 = _context15["catch"](17);
1223
+ _iterator3.e(_context15.t0);
1224
+ case 38:
1225
+ _context15.prev = 38;
1226
+ _iterator3.f();
1227
+ return _context15.finish(38);
1228
+ case 41:
1229
+ OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1230
+ _context15.next = 44;
1231
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1232
+ case 44:
1233
+ tempOrder.discount_list = (nextDiscountList || []).filter(function (d) {
1234
+ return d.isSelected;
1235
+ });
1236
+ _context15.next = 47;
1237
+ return this.store.order.recalculateSummary({
1238
+ createIfMissing: true
1239
+ });
1240
+ case 47:
1241
+ this.store.order.persistTempOrder();
1242
+ this.logMethodSuccess('setDiscountSelected', params);
1243
+ _context15.next = 55;
1244
+ break;
1245
+ case 51:
1246
+ _context15.prev = 51;
1247
+ _context15.t1 = _context15["catch"](1);
1248
+ this.logMethodError('setDiscountSelected', _context15.t1);
1249
+ throw _context15.t1;
1250
+ case 55:
1251
+ case "end":
1252
+ return _context15.stop();
1253
+ }
1254
+ }, _callee15, this, [[1, 51], [17, 35, 38, 41]]);
1255
+ }));
1256
+ function setDiscountSelected(_x8) {
1257
+ return _setDiscountSelected.apply(this, arguments);
1258
+ }
1259
+ return setDiscountSelected;
1260
+ }()
1261
+ }, {
1262
+ key: "onCustomerLogin",
1263
+ value: function () {
1264
+ var _onCustomerLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
1265
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1266
+ while (1) switch (_context16.prev = _context16.next) {
1267
+ case 0:
1268
+ this.logMethodStart('onCustomerLogin', {
1269
+ customerId: params.customerId
1270
+ });
1271
+ _context16.prev = 1;
1272
+ _context16.next = 4;
1273
+ return this.refreshOrderMarketingAfterLogin({
1274
+ customerId: params.customerId
1275
+ });
1276
+ case 4:
1277
+ this.logMethodSuccess('onCustomerLogin', {
1278
+ customerId: params.customerId
1279
+ });
1280
+ _context16.next = 11;
1281
+ break;
1282
+ case 7:
1283
+ _context16.prev = 7;
1284
+ _context16.t0 = _context16["catch"](1);
1285
+ this.logMethodError('onCustomerLogin', _context16.t0);
1286
+ throw _context16.t0;
1287
+ case 11:
1288
+ case "end":
1289
+ return _context16.stop();
1290
+ }
1291
+ }, _callee16, this, [[1, 7]]);
1292
+ }));
1293
+ function onCustomerLogin(_x9) {
1294
+ return _onCustomerLogin.apply(this, arguments);
1295
+ }
1296
+ return onCustomerLogin;
1297
+ }()
1298
+ }, {
1299
+ key: "findReservationRuleResource",
1300
+ value: function findReservationRuleResource(formId) {
1301
+ if (formId == null) return undefined;
1302
+ var numericFormId = Number(formId);
1303
+ if (!Number.isFinite(numericFormId) || numericFormId <= 0) return undefined;
1304
+ var _iterator4 = _createForOfIteratorHelper(this.enabledReservationRuleProducts),
1305
+ _step4;
1306
+ try {
1307
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1308
+ var _product$product_reso;
1309
+ var product = _step4.value;
1310
+ var resources = product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 ? void 0 : _product$product_reso.resources;
1311
+ if (!Array.isArray(resources)) continue;
1312
+ var matched = resources.find(function (resource) {
1313
+ return Number(resource === null || resource === void 0 ? void 0 : resource.id) === numericFormId;
1314
+ });
1315
+ if (matched) return matched;
1316
+ }
1317
+ } catch (err) {
1318
+ _iterator4.e(err);
1319
+ } finally {
1320
+ _iterator4.f();
1321
+ }
1322
+ return undefined;
1323
+ }
1324
+ }, {
1325
+ key: "buildScanOrderResourceMetadata",
1326
+ value: function buildScanOrderResourceMetadata(params) {
1327
+ var _ruleResource$title;
1328
+ var resourceState = params.resourceState,
1329
+ resourceName = params.resourceName;
1330
+ var ruleResource = this.findReservationRuleResource(resourceState.tableFormId);
1331
+ var combined = ruleResource === null || ruleResource === void 0 ? void 0 : ruleResource.combined_resource;
1332
+ var isCombined = !!(combined && combined.status === 1 && Array.isArray(combined.resource_ids));
1333
+ return {
1334
+ form_name: (_ruleResource$title = ruleResource === null || ruleResource === void 0 ? void 0 : ruleResource.title) !== null && _ruleResource$title !== void 0 ? _ruleResource$title : '',
1335
+ resource_name: resourceName,
1336
+ combined_resource: isCombined ? combined : null
1337
+ };
1338
+ }
1339
+ }, {
1340
+ key: "prepareRetailAvailability",
1341
+ value: function () {
1342
+ var _prepareRetailAvailability = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1343
+ var _this$store$order4, _this$otherParams5;
1344
+ var tempOrder, hasOrderId, resourceId, reason, resourceState, availabilityInfo;
1345
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1346
+ while (1) switch (_context17.prev = _context17.next) {
1347
+ case 0:
1348
+ tempOrder = params.tempOrder, hasOrderId = params.hasOrderId, resourceId = params.resourceId, reason = params.reason;
1349
+ this.enabledReservationRuleProducts = [];
1350
+ tempOrder.bookings = [];
1351
+ tempOrder.order_id = null;
1352
+ delete tempOrder.relation_id;
1353
+ delete tempOrder.table_form_id;
1354
+ delete tempOrder.resource_id;
1355
+ delete tempOrder.table_number;
1356
+ tempOrder.metadata = _objectSpread({}, tempOrder.metadata || {});
1357
+ delete tempOrder.metadata.table_occupancy_duration;
1358
+ resourceState = {
1359
+ mode: 'idle',
1360
+ deskmate_valid: false,
1361
+ allowSnack: false,
1362
+ deskmateValid: false,
1363
+ isExclusive: false,
1364
+ isFull: false,
1365
+ raw: null
1366
+ };
1367
+ this.store.resource = resourceState;
1368
+ (_this$store$order4 = this.store.order) === null || _this$store$order4 === void 0 || _this$store$order4.persistTempOrder();
1369
+ _context17.next = 15;
1370
+ return this.addNewOrder();
1371
+ case 15:
1372
+ _context17.next = 17;
1373
+ return this.setItemRuleRuntimeConfig({
1374
+ serviceType: (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.businessCode,
1375
+ submissionIndex: hasOrderId ? 1 : 0,
1376
+ historicalItems: []
1377
+ });
1378
+ case 17:
1379
+ availabilityInfo = {
1380
+ mode: 'idle',
1381
+ deskmate_valid: false
1382
+ };
1383
+ this.logMethodSuccess('checkResourceAvailable', {
1384
+ resourceId: resourceId,
1385
+ mode: availabilityInfo.mode,
1386
+ retailMode: true,
1387
+ retailReason: reason,
1388
+ persistedRelationId: tempOrder.relation_id,
1389
+ persistedResourceId: tempOrder.resource_id
1390
+ });
1391
+ return _context17.abrupt("return", availabilityInfo);
1392
+ case 20:
1393
+ case "end":
1394
+ return _context17.stop();
1395
+ }
1396
+ }, _callee17, this);
1397
+ }));
1398
+ function prepareRetailAvailability(_x10) {
1399
+ return _prepareRetailAvailability.apply(this, arguments);
1400
+ }
1401
+ return prepareRetailAvailability;
1402
+ }() // ScanOrder 提交 payload enhancer:
1403
+ // - 给所有 booking 注入 appointment_status: 'started'(扫码点餐语义)
1404
+ // - 给所有 booking 的 metadata 注入 resource_select_type(来自预约规则商品的 resource.type)
1405
+ // - 给第一条 booking 补 resources 与 product_uid(仅当存在 resource / rule product)
1406
+ // - 追加一条 is_rule=true 的 rule product,与 booking 互相关联
1407
+ }, {
1408
+ key: "buildSubmitPayloadEnhancer",
1409
+ value: function buildSubmitPayloadEnhancer() {
1410
+ var _this5 = this;
1411
+ var ruleProduct = this.enabledReservationRuleProducts[0];
1412
+ var resourceState = this.store.resource;
1413
+ var resourceSelectType = resourceState === null || resourceState === void 0 ? void 0 : resourceState.resourceSelectType;
1414
+
1415
+ // ScanOrder 的 booking 容量只由预约规则决定:single 占用整张桌台,multiple 占用 1 个容量位。
1416
+ var resolveBookingCapacityValue = function resolveBookingCapacityValue() {
1417
+ if (resourceSelectType === 'single') {
1418
+ var _resourceState$table_;
1419
+ var raw = resourceState === null || resourceState === void 0 || (_resourceState$table_ = resourceState.table_form_record) === null || _resourceState$table_ === void 0 ? void 0 : _resourceState$table_.capacity;
1420
+ var num = Number(raw);
1421
+ if (Number.isFinite(num) && num > 0) return Math.max(1, Math.floor(num));
1422
+ return 1;
1423
+ }
1424
+ return 1;
1425
+ };
1426
+ return function (payload, _ref3) {
1427
+ var _ref4, _tempOrder$resource_i, _tempOrder$metadata, _ref5, _pickOriginal, _resourceState$table_2, _resourceState$relati, _pickFirstCustomCapac;
1428
+ var bookingUuid = _ref3.bookingUuid,
1429
+ tempOrder = _ref3.tempOrder;
1430
+ var resourceId = String((_ref4 = (_tempOrder$resource_i = tempOrder.resource_id) !== null && _tempOrder$resource_i !== void 0 ? _tempOrder$resource_i : resourceState === null || resourceState === void 0 ? void 0 : resourceState.relationId) !== null && _ref4 !== void 0 ? _ref4 : '').trim();
1431
+ var hasReservationBookingContext = Boolean(ruleProduct && resourceState && resourceId && (tempOrder.relation_id || resourceState.relationId) && (tempOrder.table_form_id || resourceState.tableFormId));
1432
+ if (!hasReservationBookingContext) {
1433
+ return _objectSpread(_objectSpread({}, payload), {}, {
1434
+ bookings: [],
1435
+ products: _toConsumableArray(payload.products || [])
1436
+ });
1437
+ }
1438
+ var rawCollectPax = (_tempOrder$metadata = tempOrder.metadata) === null || _tempOrder$metadata === void 0 ? void 0 : _tempOrder$metadata.collect_pax;
1439
+ var hasExplicitCollectPax = rawCollectPax !== null && rawCollectPax !== undefined && rawCollectPax !== '';
1440
+ var bookingCapacityValue = resolveBookingCapacityValue();
1441
+ var pickOriginal = function pickOriginal(value) {
1442
+ if (value && _typeof(value) === 'object' && !Array.isArray(value)) {
1443
+ var original = value.original;
1444
+ return typeof original === 'string' && original.length > 0 ? original : undefined;
1445
+ }
1446
+ return undefined;
1447
+ };
1448
+ var mainField = (_ref5 = (_pickOriginal = pickOriginal(tempOrder.table_number)) !== null && _pickOriginal !== void 0 ? _pickOriginal : pickOriginal(resourceState === null || resourceState === void 0 || (_resourceState$table_2 = resourceState.table_form_record) === null || _resourceState$table_2 === void 0 ? void 0 : _resourceState$table_2.name)) !== null && _ref5 !== void 0 ? _ref5 : '';
1449
+ var resourceEntry = resourceState && resourceId ? {
1450
+ relation_type: 'form',
1451
+ like_status: 'common',
1452
+ id: Number(resourceId),
1453
+ main_field: mainField,
1454
+ form_id: resourceState.tableFormId,
1455
+ relation_id: (_resourceState$relati = resourceState.relationId) !== null && _resourceState$relati !== void 0 ? _resourceState$relati : resourceId,
1456
+ capacity: bookingCapacityValue,
1457
+ metadata: _this5.buildScanOrderResourceMetadata({
1458
+ resourceState: resourceState,
1459
+ resourceName: mainField
1460
+ })
1461
+ } : undefined;
1462
+ var ruleProductUid = ruleProduct ? createUuidV4() : undefined;
1463
+ var bookingCapacityDimensionId = (_pickFirstCustomCapac = pickFirstCustomCapacityDimensionId(_this5.enabledReservationRuleProducts)) !== null && _pickFirstCustomCapac !== void 0 ? _pickFirstCustomCapac : 0;
1464
+ var nextBookings = (payload.bookings || []).map(function (booking, idx) {
1465
+ var metadata = _objectSpread({}, booking.metadata || {});
1466
+ if (hasExplicitCollectPax) {
1467
+ metadata.collect_pax = normalizeSubmitCollectPaxValue(rawCollectPax);
1468
+ } else {
1469
+ delete metadata.collect_pax;
1470
+ }
1471
+ return _objectSpread(_objectSpread(_objectSpread({}, booking), {}, {
1472
+ number: bookingCapacityValue,
1473
+ appointment_status: 'started',
1474
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, metadata), resourceSelectType ? {
1475
+ resource_select_type: resourceSelectType
1476
+ } : {}), resourceSelectType ? {
1477
+ capacity: [{
1478
+ id: bookingCapacityDimensionId,
1479
+ value: bookingCapacityValue,
1480
+ name: ''
1481
+ }]
1482
+ } : {})
1483
+ }, idx === 0 && resourceEntry ? {
1484
+ resources: [resourceEntry]
1485
+ } : {}), idx === 0 && ruleProductUid ? {
1486
+ product_uid: ruleProductUid
1487
+ } : {});
1488
+ });
1489
+ var nextProducts = _toConsumableArray(payload.products || []);
1490
+ // 加餐(已有 order_id)走 scanOrderMore,原单已含 booking 规则行,勿再追加虚拟规则商品
1491
+ if (ruleProduct && ruleProductUid && !tempOrder.order_id) {
1492
+ var _ruleProduct$price, _ref6, _ruleProduct$original, _ruleProduct$is_gst;
1493
+ var sellingPrice = String((_ruleProduct$price = ruleProduct.price) !== null && _ruleProduct$price !== void 0 ? _ruleProduct$price : '0.00');
1494
+ var originalPrice = String((_ref6 = (_ruleProduct$original = ruleProduct.original_price) !== null && _ruleProduct$original !== void 0 ? _ruleProduct$original : ruleProduct.price) !== null && _ref6 !== void 0 ? _ref6 : '0.00');
1495
+ nextProducts.push({
1496
+ product_id: ruleProduct.id,
1497
+ product_variant_id: 0,
1498
+ num: 1,
1499
+ selling_price: sellingPrice,
1500
+ original_price: originalPrice,
1501
+ payment_price: sellingPrice,
1502
+ is_charge_tax: (_ruleProduct$is_gst = ruleProduct.is_gst) !== null && _ruleProduct$is_gst !== void 0 ? _ruleProduct$is_gst : 0,
1503
+ product_option_item: [],
1504
+ discount_list: [],
1505
+ product_bundle: [],
1506
+ booking_uid: bookingUuid,
1507
+ metadata: {
1508
+ is_rule: true,
1509
+ unique_identification_number: ruleProductUid,
1510
+ booking_uid: bookingUuid
1511
+ }
1512
+ });
1513
+ }
1514
+ return _objectSpread(_objectSpread({}, payload), {}, {
1515
+ bookings: nextBookings,
1516
+ products: nextProducts
1517
+ });
1518
+ };
1519
+ }
1520
+ }, {
1521
+ key: "submitScanOrder",
1522
+ value: function () {
1523
+ var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1524
+ var _this$store$resource, _this$otherParams6, _this$otherParams7, _this$otherParams8, _this$otherParams9, _tempOrder$products, tempOrderForSubmit, resourceTableName, enhancePayload, result, tempOrder;
1525
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1526
+ while (1) switch (_context18.prev = _context18.next) {
1527
+ case 0:
1528
+ this.logMethodStart('submitScanOrder');
1529
+ _context18.prev = 1;
1530
+ _context18.next = 4;
1531
+ return this.validateBeforeSubmitByItemRule();
1532
+ case 4:
1533
+ if (this.store.order) {
1534
+ _context18.next = 6;
1535
+ break;
1536
+ }
1537
+ throw new Error('scanOrder解决方案需要 order 模块支持');
1538
+ case 6:
1539
+ tempOrderForSubmit = this.store.order.ensureTempOrder();
1540
+ tempOrderForSubmit.delivery_type = 'shop_service';
1541
+ resourceTableName = (_this$store$resource = this.store.resource) === null || _this$store$resource === void 0 || (_this$store$resource = _this$store$resource.table_form_record) === null || _this$store$resource === void 0 ? void 0 : _this$store$resource.name;
1542
+ if (resourceTableName && _typeof(resourceTableName) === 'object') {
1543
+ tempOrderForSubmit.table_number = resourceTableName;
1544
+ } else {
1545
+ delete tempOrderForSubmit.table_number;
1546
+ }
1547
+ this.store.order.persistTempOrder();
1548
+ enhancePayload = this.buildSubmitPayloadEnhancer();
1549
+ _context18.next = 14;
1550
+ return this.store.order.submitTempOrder({
1551
+ cacheId: this.cacheId,
1552
+ platform: (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform,
1553
+ businessCode: (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode,
1554
+ channel: (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.channel,
1555
+ type: (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.type,
1556
+ enhancePayload: enhancePayload
1557
+ });
1558
+ case 14:
1559
+ result = _context18.sent;
1560
+ tempOrder = this.store.order.getTempOrder();
1561
+ this.logMethodSuccess('submitScanOrder', {
1562
+ productCount: (tempOrder === null || tempOrder === void 0 || (_tempOrder$products = tempOrder.products) === null || _tempOrder$products === void 0 ? void 0 : _tempOrder$products.length) || 0
1563
+ });
1564
+ return _context18.abrupt("return", result);
1565
+ case 20:
1566
+ _context18.prev = 20;
1567
+ _context18.t0 = _context18["catch"](1);
1568
+ this.logMethodError('submitScanOrder', _context18.t0);
1569
+ throw _context18.t0;
1570
+ case 24:
1571
+ case "end":
1572
+ return _context18.stop();
1573
+ }
1574
+ }, _callee18, this, [[1, 20]]);
1575
+ }));
1576
+ function submitScanOrder() {
1577
+ return _submitScanOrder.apply(this, arguments);
1578
+ }
1579
+ return submitScanOrder;
1580
+ }()
1581
+ }, {
1582
+ key: "addProductToOrder",
1583
+ value: function () {
1584
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(product) {
1585
+ var products;
1586
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1587
+ while (1) switch (_context19.prev = _context19.next) {
1588
+ case 0:
1589
+ this.logMethodStart('addProductToOrder', {
1590
+ product_id: product.product_id,
1591
+ product_variant_id: product.product_variant_id
1592
+ });
1593
+ _context19.prev = 1;
1594
+ if (this.store.order) {
1595
+ _context19.next = 4;
1596
+ break;
1597
+ }
1598
+ throw new Error('order 模块未初始化');
1599
+ case 4:
1600
+ _context19.next = 6;
1601
+ return this.store.order.addProductToOrder(product);
1602
+ case 6:
1603
+ products = _context19.sent;
1604
+ _context19.next = 9;
1605
+ return this.refreshItemRuleQuantityLimits();
1606
+ case 9:
1607
+ _context19.next = 11;
1608
+ return this.refreshCartValidationPassed();
1609
+ case 11:
1610
+ this.logMethodSuccess('addProductToOrder', {
1611
+ productCount: products.length
1612
+ });
1613
+ return _context19.abrupt("return", products);
1614
+ case 15:
1615
+ _context19.prev = 15;
1616
+ _context19.t0 = _context19["catch"](1);
1617
+ this.logMethodError('addProductToOrder', _context19.t0);
1618
+ throw _context19.t0;
1619
+ case 19:
1620
+ case "end":
1621
+ return _context19.stop();
1622
+ }
1623
+ }, _callee19, this, [[1, 15]]);
1624
+ }));
1625
+ function addProductToOrder(_x11) {
1626
+ return _addProductToOrder.apply(this, arguments);
1627
+ }
1628
+ return addProductToOrder;
1629
+ }()
1630
+ }, {
1631
+ key: "updateProductInOrder",
1632
+ value: function () {
1633
+ var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
1634
+ var products;
1635
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1636
+ while (1) switch (_context20.prev = _context20.next) {
1637
+ case 0:
1638
+ this.logMethodStart('updateProductInOrder', {
1639
+ product_id: params.product_id,
1640
+ product_variant_id: params.product_variant_id
1641
+ });
1642
+ _context20.prev = 1;
1643
+ if (this.store.order) {
1644
+ _context20.next = 4;
1645
+ break;
1646
+ }
1647
+ throw new Error('order 模块未初始化');
1648
+ case 4:
1649
+ _context20.next = 6;
1650
+ return this.store.order.updateProductInOrder(params);
1651
+ case 6:
1652
+ products = _context20.sent;
1653
+ _context20.next = 9;
1654
+ return this.refreshItemRuleQuantityLimits();
1655
+ case 9:
1656
+ _context20.next = 11;
1657
+ return this.refreshCartValidationPassed();
1658
+ case 11:
1659
+ this.logMethodSuccess('updateProductInOrder', {
1660
+ productCount: products.length
1661
+ });
1662
+ return _context20.abrupt("return", products);
1663
+ case 15:
1664
+ _context20.prev = 15;
1665
+ _context20.t0 = _context20["catch"](1);
1666
+ this.logMethodError('updateProductInOrder', _context20.t0);
1667
+ throw _context20.t0;
1668
+ case 19:
1669
+ case "end":
1670
+ return _context20.stop();
1671
+ }
1672
+ }, _callee20, this, [[1, 15]]);
1673
+ }));
1674
+ function updateProductInOrder(_x12) {
1675
+ return _updateProductInOrder.apply(this, arguments);
1676
+ }
1677
+ return updateProductInOrder;
1678
+ }()
1679
+ /**
1680
+ * 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
1681
+ * 多行同 SKU 时必须传入与删除/更新一致的 identity(如 `identity_key`)。
1682
+ */
1683
+ }, {
1684
+ key: "setOrderProductLineNote",
1685
+ value: (function () {
1686
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(identity, note) {
1687
+ var params, products;
1688
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1689
+ while (1) switch (_context21.prev = _context21.next) {
1690
+ case 0:
1691
+ this.logMethodStart('setOrderProductLineNote', {
1692
+ product_id: identity.product_id,
1693
+ product_variant_id: identity.product_variant_id
1694
+ });
1695
+ _context21.prev = 1;
1696
+ params = {
1697
+ product_id: identity.product_id,
1698
+ product_variant_id: identity.product_variant_id,
1699
+ updates: {
1700
+ note: String(note || '')
1701
+ }
1702
+ };
1703
+ if (identity.identity_key !== undefined) params.identity_key = identity.identity_key;
1704
+ if (identity.product_option_item !== undefined) {
1705
+ params.product_option_item = identity.product_option_item;
1706
+ }
1707
+ if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
1708
+ _context21.next = 8;
1709
+ return this.updateProductInOrder(params);
1710
+ case 8:
1711
+ products = _context21.sent;
1712
+ this.logMethodSuccess('setOrderProductLineNote', {
1713
+ productCount: products.length
1714
+ });
1715
+ return _context21.abrupt("return", products);
1716
+ case 13:
1717
+ _context21.prev = 13;
1718
+ _context21.t0 = _context21["catch"](1);
1719
+ this.logMethodError('setOrderProductLineNote', _context21.t0);
1720
+ throw _context21.t0;
1721
+ case 17:
1722
+ case "end":
1723
+ return _context21.stop();
1724
+ }
1725
+ }, _callee21, this, [[1, 13]]);
1726
+ }));
1727
+ function setOrderProductLineNote(_x13, _x14) {
1728
+ return _setOrderProductLineNote.apply(this, arguments);
1729
+ }
1730
+ return setOrderProductLineNote;
1731
+ }())
1732
+ }, {
1733
+ key: "removeProductFromOrder",
1734
+ value: function () {
1735
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(identity) {
1736
+ var products;
1737
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1738
+ while (1) switch (_context22.prev = _context22.next) {
1739
+ case 0:
1740
+ this.logMethodStart('removeProductFromOrder', {
1741
+ product_id: identity.product_id,
1742
+ product_variant_id: identity.product_variant_id
1743
+ });
1744
+ _context22.prev = 1;
1745
+ if (this.store.order) {
1746
+ _context22.next = 4;
1747
+ break;
1748
+ }
1749
+ throw new Error('order 模块未初始化');
1750
+ case 4:
1751
+ _context22.next = 6;
1752
+ return this.store.order.removeProductFromOrder(identity);
1753
+ case 6:
1754
+ products = _context22.sent;
1755
+ _context22.next = 9;
1756
+ return this.refreshItemRuleQuantityLimits();
1757
+ case 9:
1758
+ _context22.next = 11;
1759
+ return this.refreshCartValidationPassed();
1760
+ case 11:
1761
+ this.logMethodSuccess('removeProductFromOrder', {
1762
+ productCount: products.length
1763
+ });
1764
+ return _context22.abrupt("return", products);
1765
+ case 15:
1766
+ _context22.prev = 15;
1767
+ _context22.t0 = _context22["catch"](1);
1768
+ this.logMethodError('removeProductFromOrder', _context22.t0);
1769
+ throw _context22.t0;
1770
+ case 19:
1771
+ case "end":
1772
+ return _context22.stop();
1773
+ }
1774
+ }, _callee22, this, [[1, 15]]);
1775
+ }));
1776
+ function removeProductFromOrder(_x15) {
1777
+ return _removeProductFromOrder.apply(this, arguments);
1778
+ }
1779
+ return removeProductFromOrder;
1780
+ }()
1781
+ }, {
1782
+ key: "loadRuntimeConfigs",
1783
+ value: function () {
1784
+ var _loadRuntimeConfigs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1785
+ var itemRuleConfigs;
1786
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1787
+ while (1) switch (_context23.prev = _context23.next) {
1788
+ case 0:
1789
+ _context23.next = 2;
1790
+ return this.ensureItemRuleConfigsLoaded();
1791
+ case 2:
1792
+ itemRuleConfigs = _context23.sent;
1793
+ this.logMethodSuccess('loadRuntimeConfigs', {
1794
+ itemRuleCount: itemRuleConfigs.length
1795
+ });
1796
+ return _context23.abrupt("return", {
1797
+ itemRuleConfigs: itemRuleConfigs
1798
+ });
1799
+ case 5:
1800
+ case "end":
1801
+ return _context23.stop();
1802
+ }
1803
+ }, _callee23, this);
1804
+ }));
1805
+ function loadRuntimeConfigs() {
1806
+ return _loadRuntimeConfigs.apply(this, arguments);
1807
+ }
1808
+ return loadRuntimeConfigs;
1809
+ }()
1810
+ }, {
1811
+ key: "syncItemRuleConfigsFromDineInConfig",
1812
+ value: function () {
1813
+ var _syncItemRuleConfigsFromDineInConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(dineInConfig) {
1814
+ var enableItemRules, strategyModelIds, itemRuleConfigs;
1815
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1816
+ while (1) switch (_context24.prev = _context24.next) {
1817
+ case 0:
1818
+ enableItemRules = toBoolean(dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['sale.enable_item_rules']);
1819
+ strategyModelIds = normalizeEnabledItemRuleIds(dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['sale.enabled_item_rules']);
1820
+ if (!(!enableItemRules || !strategyModelIds.length)) {
1821
+ _context24.next = 8;
1822
+ break;
1823
+ }
1824
+ this.itemRuleConfigs = [];
1825
+ this.itemRuleConfigsPromise = Promise.resolve([]);
1826
+ this.itemRuleEvaluator.setStrategyConfigs([]);
1827
+ this.logMethodSuccess('syncItemRuleConfigsFromDineInConfig', {
1828
+ enabled: enableItemRules,
1829
+ strategyModelIds: [],
1830
+ itemRuleCount: 0
1831
+ });
1832
+ return _context24.abrupt("return", []);
1833
+ case 8:
1834
+ _context24.next = 10;
1835
+ return this.fetchItemRuleConfigsByModelIds(strategyModelIds);
1836
+ case 10:
1837
+ itemRuleConfigs = _context24.sent;
1838
+ this.itemRuleConfigs = itemRuleConfigs;
1839
+ this.itemRuleConfigsPromise = Promise.resolve(itemRuleConfigs);
1840
+ this.itemRuleEvaluator.setStrategyConfigs(itemRuleConfigs);
1841
+ this.logMethodSuccess('syncItemRuleConfigsFromDineInConfig', {
1842
+ enabled: enableItemRules,
1843
+ strategyModelIds: strategyModelIds,
1844
+ itemRuleCount: itemRuleConfigs.length
1845
+ });
1846
+ return _context24.abrupt("return", itemRuleConfigs);
1847
+ case 16:
1848
+ case "end":
1849
+ return _context24.stop();
1850
+ }
1851
+ }, _callee24, this);
1852
+ }));
1853
+ function syncItemRuleConfigsFromDineInConfig(_x16) {
1854
+ return _syncItemRuleConfigsFromDineInConfig.apply(this, arguments);
1855
+ }
1856
+ return syncItemRuleConfigsFromDineInConfig;
1857
+ }()
1858
+ }, {
1859
+ key: "fetchItemRuleConfigsByModelIds",
1860
+ value: function () {
1861
+ var _fetchItemRuleConfigsByModelIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(strategyModelIds) {
1862
+ var result, configs;
1863
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1864
+ while (1) switch (_context25.prev = _context25.next) {
1865
+ case 0:
1866
+ this.logMethodStart('fetchItemRuleConfigsByModelIds', {
1867
+ strategyModelIds: strategyModelIds
1868
+ });
1869
+ if (strategyModelIds.length) {
1870
+ _context25.next = 3;
1871
+ break;
1872
+ }
1873
+ return _context25.abrupt("return", []);
1874
+ case 3:
1875
+ _context25.prev = 3;
1876
+ _context25.next = 6;
1877
+ return this.request.get('/promotion', {
1878
+ skip: 1,
1879
+ num: 99,
1880
+ status: 'active',
1881
+ ids: strategyModelIds
1882
+ });
1883
+ case 6:
1884
+ result = _context25.sent;
1885
+ configs = [];
1886
+ if (result.code === 200) {
1887
+ configs = result.data.list.map(function (item) {
1888
+ return item.metadata;
1889
+ });
1890
+ }
1891
+ this.logMethodSuccess('fetchItemRuleConfigsByModelIds', {
1892
+ strategyModelIds: strategyModelIds,
1893
+ strategyCount: configs.length
1894
+ });
1895
+ return _context25.abrupt("return", configs);
1896
+ case 13:
1897
+ _context25.prev = 13;
1898
+ _context25.t0 = _context25["catch"](3);
1899
+ this.logMethodError('fetchItemRuleConfigsByModelIds', _context25.t0, {
1900
+ strategyModelIds: strategyModelIds
1901
+ });
1902
+ // A:策略加载失败时不阻塞下单
1903
+ return _context25.abrupt("return", []);
1904
+ case 17:
1905
+ case "end":
1906
+ return _context25.stop();
1907
+ }
1908
+ }, _callee25, this, [[3, 13]]);
1909
+ }));
1910
+ function fetchItemRuleConfigsByModelIds(_x17) {
1911
+ return _fetchItemRuleConfigsByModelIds.apply(this, arguments);
1912
+ }
1913
+ return fetchItemRuleConfigsByModelIds;
1914
+ }()
1915
+ }, {
1916
+ key: "buildPrefillProductSourceMap",
1917
+ value: function () {
1918
+ var _buildPrefillProductSourceMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
1919
+ var sourceMap, productList, visited, collectFromValue;
1920
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1921
+ while (1) switch (_context26.prev = _context26.next) {
1922
+ case 0:
1923
+ sourceMap = new Map();
1924
+ _context26.prev = 1;
1925
+ _context26.next = 4;
1926
+ return this.getProductList();
1927
+ case 4:
1928
+ productList = _context26.sent;
1929
+ if (Array.isArray(productList)) {
1930
+ _context26.next = 7;
1931
+ break;
1932
+ }
1933
+ return _context26.abrupt("return", sourceMap);
1934
+ case 7:
1935
+ visited = new Set();
1936
+ collectFromValue = function collectFromValue(value) {
1937
+ var _node$product_id;
1938
+ if (!value || _typeof(value) !== 'object') return;
1939
+ if (visited.has(value)) return;
1940
+ visited.add(value);
1941
+ if (Array.isArray(value)) {
1942
+ var _iterator5 = _createForOfIteratorHelper(value),
1943
+ _step5;
1944
+ try {
1945
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1946
+ var item = _step5.value;
1947
+ collectFromValue(item);
1948
+ }
1949
+ } catch (err) {
1950
+ _iterator5.e(err);
1951
+ } finally {
1952
+ _iterator5.f();
1953
+ }
1954
+ return;
1955
+ }
1956
+ var node = value;
1957
+ var rawProductId = (_node$product_id = node.product_id) !== null && _node$product_id !== void 0 ? _node$product_id : node.id;
1958
+ var productId = Number(rawProductId);
1959
+ if (Number.isFinite(productId) && productId > 0) {
1960
+ var _ref7, _node$product_variant;
1961
+ var productVariantId = Number((_ref7 = (_node$product_variant = node.product_variant_id) !== null && _node$product_variant !== void 0 ? _node$product_variant : node.variant_id) !== null && _ref7 !== void 0 ? _ref7 : 0);
1962
+ var normalizedVariantId = Number.isNaN(productVariantId) ? 0 : productVariantId;
1963
+ var key = buildProductKey(productId, normalizedVariantId);
1964
+ if (!sourceMap.has(key)) {
1965
+ sourceMap.set(key, node);
1966
+ }
1967
+ }
1968
+ for (var _i4 = 0, _Object$values = Object.values(node); _i4 < _Object$values.length; _i4++) {
1969
+ var childValue = _Object$values[_i4];
1970
+ if (childValue && _typeof(childValue) === 'object') {
1971
+ collectFromValue(childValue);
1972
+ }
1973
+ }
1974
+ };
1975
+ collectFromValue(productList);
1976
+ _context26.next = 15;
1977
+ break;
1978
+ case 12:
1979
+ _context26.prev = 12;
1980
+ _context26.t0 = _context26["catch"](1);
1981
+ this.logMethodError('buildPrefillProductSourceMap', _context26.t0);
1982
+ case 15:
1983
+ return _context26.abrupt("return", sourceMap);
1984
+ case 16:
1985
+ case "end":
1986
+ return _context26.stop();
1987
+ }
1988
+ }, _callee26, this, [[1, 12]]);
1989
+ }));
1990
+ function buildPrefillProductSourceMap() {
1991
+ return _buildPrefillProductSourceMap.apply(this, arguments);
1992
+ }
1993
+ return buildPrefillProductSourceMap;
1994
+ }()
1995
+ }, {
1996
+ key: "getItemRuleRuntimeConfig",
1997
+ value: function getItemRuleRuntimeConfig() {
1998
+ return this.itemRuleRuntimeConfig || {};
1999
+ }
2000
+ }, {
2001
+ key: "ensureItemRuleConfigsLoaded",
2002
+ value: function () {
2003
+ var _ensureItemRuleConfigsLoaded = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2004
+ var _this6 = this;
2005
+ var loadedConfigs;
2006
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2007
+ while (1) switch (_context28.prev = _context28.next) {
2008
+ case 0:
2009
+ if (!(this.itemRuleConfigs.length > 0)) {
2010
+ _context28.next = 2;
2011
+ break;
2012
+ }
2013
+ return _context28.abrupt("return", this.itemRuleConfigs);
2014
+ case 2:
2015
+ if (!this.itemRuleConfigsPromise) {
2016
+ _context28.next = 4;
2017
+ break;
2018
+ }
2019
+ return _context28.abrupt("return", this.itemRuleConfigsPromise);
2020
+ case 4:
2021
+ this.itemRuleConfigsPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2022
+ var runtimeConfig, staticConfigs;
2023
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2024
+ while (1) switch (_context27.prev = _context27.next) {
2025
+ case 0:
2026
+ runtimeConfig = _this6.getItemRuleRuntimeConfig();
2027
+ staticConfigs = normalizeItemRuleStrategies(runtimeConfig.strategyConfigs);
2028
+ if (!(staticConfigs.length > 0)) {
2029
+ _context27.next = 6;
2030
+ break;
2031
+ }
2032
+ _this6.itemRuleConfigs = staticConfigs;
2033
+ _this6.itemRuleEvaluator.setStrategyConfigs(staticConfigs);
2034
+ return _context27.abrupt("return", _this6.itemRuleConfigs);
2035
+ case 6:
2036
+ _this6.itemRuleConfigs = [];
2037
+ _this6.itemRuleEvaluator.setStrategyConfigs([]);
2038
+ return _context27.abrupt("return", _this6.itemRuleConfigs);
2039
+ case 9:
2040
+ case "end":
2041
+ return _context27.stop();
2042
+ }
2043
+ }, _callee27);
2044
+ }))();
2045
+ _context28.next = 7;
2046
+ return this.itemRuleConfigsPromise;
2047
+ case 7:
2048
+ loadedConfigs = _context28.sent;
2049
+ return _context28.abrupt("return", loadedConfigs);
2050
+ case 9:
2051
+ case "end":
2052
+ return _context28.stop();
2053
+ }
2054
+ }, _callee28, this);
2055
+ }));
2056
+ function ensureItemRuleConfigsLoaded() {
2057
+ return _ensureItemRuleConfigsLoaded.apply(this, arguments);
2058
+ }
2059
+ return ensureItemRuleConfigsLoaded;
2060
+ }()
2061
+ }, {
2062
+ key: "refreshItemRuleQuantityLimits",
2063
+ value: function () {
2064
+ var _refreshItemRuleQuantityLimits = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2065
+ var strategyConfigs, businessData, limits;
2066
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2067
+ while (1) switch (_context29.prev = _context29.next) {
2068
+ case 0:
2069
+ _context29.prev = 0;
2070
+ _context29.next = 3;
2071
+ return this.ensureItemRuleConfigsLoaded();
2072
+ case 3:
2073
+ strategyConfigs = _context29.sent;
2074
+ if (strategyConfigs.length) {
2075
+ _context29.next = 7;
2076
+ break;
2077
+ }
2078
+ this.store.itemRuleQuantityLimits = [];
2079
+ return _context29.abrupt("return", []);
2080
+ case 7:
2081
+ businessData = buildItemRuleBusinessData({
2082
+ tempOrder: this.ensureTempOrder(),
2083
+ runtimeConfig: this.getItemRuleRuntimeConfig(),
2084
+ itemRuleConfigs: this.itemRuleConfigs
2085
+ });
2086
+ limits = this.itemRuleEvaluator.getQuantityLimits(businessData);
2087
+ this.store.itemRuleQuantityLimits = limits;
2088
+ this.logMethodSuccess('refreshItemRuleQuantityLimits', {
2089
+ limitCount: limits.length
2090
+ });
2091
+ return _context29.abrupt("return", limits);
2092
+ case 14:
2093
+ _context29.prev = 14;
2094
+ _context29.t0 = _context29["catch"](0);
2095
+ this.store.itemRuleQuantityLimits = [];
2096
+ this.logMethodError('refreshItemRuleQuantityLimits', _context29.t0);
2097
+ return _context29.abrupt("return", []);
2098
+ case 19:
2099
+ case "end":
2100
+ return _context29.stop();
2101
+ }
2102
+ }, _callee29, this, [[0, 14]]);
2103
+ }));
2104
+ function refreshItemRuleQuantityLimits() {
2105
+ return _refreshItemRuleQuantityLimits.apply(this, arguments);
2106
+ }
2107
+ return refreshItemRuleQuantityLimits;
2108
+ }()
2109
+ }, {
2110
+ key: "applyPrefillByItemRule",
2111
+ value: function () {
2112
+ var _applyPrefillByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2113
+ var strategyConfigs, businessData, prefillItems, productSourceMap, tempOrder, hasChanges, _iterator6, _step6, _prefillItem$product_, _targetProduct$_origi, _targetProduct$_origi2, _targetProduct$_origi3, prefillItem, productId, productVariantId, targetQuantity, sourceItem, productIndex, _sourceItem$price, sellingPrice, targetProduct, existedQuantity, delta, nextProduct, hasQuantityChanged, hasOriginChanged;
2114
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2115
+ while (1) switch (_context30.prev = _context30.next) {
2116
+ case 0:
2117
+ if (!this.itemRulePrefillApplied) {
2118
+ _context30.next = 2;
2119
+ break;
2120
+ }
2121
+ return _context30.abrupt("return");
2122
+ case 2:
2123
+ if (this.store.order) {
2124
+ _context30.next = 4;
2125
+ break;
2126
+ }
2127
+ return _context30.abrupt("return");
2128
+ case 4:
2129
+ _context30.next = 6;
2130
+ return this.ensureItemRuleConfigsLoaded();
2131
+ case 6:
2132
+ strategyConfigs = _context30.sent;
2133
+ if (strategyConfigs.length) {
2134
+ _context30.next = 9;
2135
+ break;
2136
+ }
2137
+ return _context30.abrupt("return");
2138
+ case 9:
2139
+ businessData = buildItemRuleBusinessData({
2140
+ tempOrder: this.ensureTempOrder(),
2141
+ runtimeConfig: this.getItemRuleRuntimeConfig(),
2142
+ itemRuleConfigs: this.itemRuleConfigs
2143
+ });
2144
+ prefillItems = this.itemRuleEvaluator.getPrefillItems(businessData);
2145
+ if (prefillItems.length) {
2146
+ _context30.next = 14;
2147
+ break;
2148
+ }
2149
+ this.itemRulePrefillApplied = true;
2150
+ return _context30.abrupt("return");
2151
+ case 14:
2152
+ _context30.next = 16;
2153
+ return this.buildPrefillProductSourceMap();
2154
+ case 16:
2155
+ productSourceMap = _context30.sent;
2156
+ tempOrder = this.ensureTempOrder();
2157
+ hasChanges = false;
2158
+ _iterator6 = _createForOfIteratorHelper(prefillItems);
2159
+ _context30.prev = 20;
2160
+ _iterator6.s();
2161
+ case 22:
2162
+ if ((_step6 = _iterator6.n()).done) {
2163
+ _context30.next = 47;
2164
+ break;
2165
+ }
2166
+ prefillItem = _step6.value;
2167
+ productId = Number(prefillItem.product_id);
2168
+ productVariantId = Number((_prefillItem$product_ = prefillItem.product_variant_id) !== null && _prefillItem$product_ !== void 0 ? _prefillItem$product_ : 0);
2169
+ targetQuantity = toNonNegativeInt(prefillItem.quantity);
2170
+ if (!(!Number.isFinite(productId) || targetQuantity <= 0)) {
2171
+ _context30.next = 29;
2172
+ break;
2173
+ }
2174
+ return _context30.abrupt("continue", 45);
2175
+ case 29:
2176
+ if (!Number.isNaN(productVariantId)) {
2177
+ _context30.next = 31;
2178
+ break;
2179
+ }
2180
+ return _context30.abrupt("continue", 45);
2181
+ case 31:
2182
+ sourceItem = productSourceMap.get(buildProductKey(productId, productVariantId)) || productSourceMap.get(buildProductKey(productId, 0)) || null;
2183
+ productIndex = getProductIdentityIndex(tempOrder.products, {
2184
+ product_id: productId,
2185
+ product_variant_id: productVariantId
2186
+ });
2187
+ if (!(productIndex === -1)) {
2188
+ _context30.next = 38;
2189
+ break;
2190
+ }
2191
+ sellingPrice = toPriceString((_sourceItem$price = sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price) !== null && _sourceItem$price !== void 0 ? _sourceItem$price : sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.selling_price, '0.00');
2192
+ tempOrder.products.push(normalizeOrderProduct(_objectSpread(_objectSpread({}, sourceItem), {}, {
2193
+ product_id: productId,
2194
+ product_variant_id: productVariantId,
2195
+ num: targetQuantity,
2196
+ selling_price: sellingPrice,
2197
+ original_price: sellingPrice,
2198
+ metadata: {
2199
+ item_rule_prefill: true,
2200
+ item_rule_id: prefillItem.ruleId
2201
+ },
2202
+ _origin: _objectSpread(_objectSpread({}, sourceItem || {}), {}, {
2203
+ item_rule_prefill: true,
2204
+ item_rule_id: prefillItem.ruleId
2205
+ })
2206
+ })));
2207
+ hasChanges = true;
2208
+ return _context30.abrupt("continue", 45);
2209
+ case 38:
2210
+ targetProduct = tempOrder.products[productIndex];
2211
+ existedQuantity = toNonNegativeInt(targetProduct.num);
2212
+ delta = targetQuantity - existedQuantity;
2213
+ nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), delta > 0 ? {
2214
+ num: getSafeProductNum(existedQuantity + delta)
2215
+ } : {}), {}, {
2216
+ metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
2217
+ item_rule_prefill: true,
2218
+ item_rule_id: prefillItem.ruleId
2219
+ }),
2220
+ _origin: sourceItem ? _objectSpread(_objectSpread({}, targetProduct._origin || {}), sourceItem) : targetProduct._origin
2221
+ });
2222
+ hasQuantityChanged = delta > 0;
2223
+ hasOriginChanged = Boolean(sourceItem && (!targetProduct._origin || ((_targetProduct$_origi = targetProduct._origin) === null || _targetProduct$_origi === void 0 ? void 0 : _targetProduct$_origi.name) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.name) || ((_targetProduct$_origi2 = targetProduct._origin) === null || _targetProduct$_origi2 === void 0 ? void 0 : _targetProduct$_origi2.title) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.title) || ((_targetProduct$_origi3 = targetProduct._origin) === null || _targetProduct$_origi3 === void 0 ? void 0 : _targetProduct$_origi3.price) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price)));
2224
+ if (hasQuantityChanged || hasOriginChanged) {
2225
+ tempOrder.products[productIndex] = nextProduct;
2226
+ hasChanges = true;
2227
+ }
2228
+ case 45:
2229
+ _context30.next = 22;
2230
+ break;
2231
+ case 47:
2232
+ _context30.next = 52;
2233
+ break;
2234
+ case 49:
2235
+ _context30.prev = 49;
2236
+ _context30.t0 = _context30["catch"](20);
2237
+ _iterator6.e(_context30.t0);
2238
+ case 52:
2239
+ _context30.prev = 52;
2240
+ _iterator6.f();
2241
+ return _context30.finish(52);
2242
+ case 55:
2243
+ if (!hasChanges) {
2244
+ _context30.next = 60;
2245
+ break;
2246
+ }
2247
+ // Prefill 属于 products CRUD 的一种形式:新增后让 Rules 重算,以支持自动应用可用优惠券。
2248
+ this.store.order.applyDiscount();
2249
+ _context30.next = 59;
2250
+ return this.store.order.recalculateSummary({
2251
+ createIfMissing: true
2252
+ });
2253
+ case 59:
2254
+ this.store.order.persistTempOrder();
2255
+ case 60:
2256
+ _context30.next = 62;
2257
+ return this.refreshItemRuleQuantityLimits();
2258
+ case 62:
2259
+ this.itemRulePrefillApplied = true;
2260
+ this.logMethodSuccess('applyPrefillByItemRule', {
2261
+ prefillCount: prefillItems.length,
2262
+ hasChanges: hasChanges
2263
+ });
2264
+ case 64:
2265
+ case "end":
2266
+ return _context30.stop();
2267
+ }
2268
+ }, _callee30, this, [[20, 49, 52, 55]]);
2269
+ }));
2270
+ function applyPrefillByItemRule() {
2271
+ return _applyPrefillByItemRule.apply(this, arguments);
2272
+ }
2273
+ return applyPrefillByItemRule;
2274
+ }()
2275
+ }, {
2276
+ key: "applyItemRulePrefill",
2277
+ value: function () {
2278
+ var _applyItemRulePrefill = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2279
+ var _this$store$order5, _this$store$order5$ge;
2280
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2281
+ while (1) switch (_context31.prev = _context31.next) {
2282
+ case 0:
2283
+ if (!((_this$store$order5 = this.store.order) !== null && _this$store$order5 !== void 0 && (_this$store$order5$ge = _this$store$order5.getLastOrderInfo) !== null && _this$store$order5$ge !== void 0 && _this$store$order5$ge.call(_this$store$order5))) {
2284
+ _context31.next = 2;
2285
+ break;
2286
+ }
2287
+ return _context31.abrupt("return");
2288
+ case 2:
2289
+ this.logMethodStart('applyItemRulePrefill');
2290
+ _context31.next = 5;
2291
+ return this.applyPrefillByItemRule();
2292
+ case 5:
2293
+ _context31.next = 7;
2294
+ return this.refreshItemRuleQuantityLimits();
2295
+ case 7:
2296
+ _context31.next = 9;
2297
+ return this.refreshCartValidationPassed();
2298
+ case 9:
2299
+ case "end":
2300
+ return _context31.stop();
2301
+ }
2302
+ }, _callee31, this);
2303
+ }));
2304
+ function applyItemRulePrefill() {
2305
+ return _applyItemRulePrefill.apply(this, arguments);
2306
+ }
2307
+ return applyItemRulePrefill;
2308
+ }()
2309
+ }, {
2310
+ key: "evaluateCartValidationByItemRule",
2311
+ value: function () {
2312
+ var _evaluateCartValidationByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
2313
+ var strategyConfigs, businessData;
2314
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2315
+ while (1) switch (_context32.prev = _context32.next) {
2316
+ case 0:
2317
+ _context32.next = 2;
2318
+ return this.ensureItemRuleConfigsLoaded();
2319
+ case 2:
2320
+ strategyConfigs = _context32.sent;
2321
+ if (strategyConfigs.length) {
2322
+ _context32.next = 5;
2323
+ break;
2324
+ }
2325
+ return _context32.abrupt("return", {
2326
+ passed: true,
2327
+ failures: []
2328
+ });
2329
+ case 5:
2330
+ businessData = buildItemRuleBusinessData({
2331
+ tempOrder: this.ensureTempOrder(),
2332
+ runtimeConfig: this.getItemRuleRuntimeConfig(),
2333
+ itemRuleConfigs: this.itemRuleConfigs
2334
+ });
2335
+ return _context32.abrupt("return", this.itemRuleEvaluator.validateCart(businessData));
2336
+ case 7:
2337
+ case "end":
2338
+ return _context32.stop();
2339
+ }
2340
+ }, _callee32, this);
2341
+ }));
2342
+ function evaluateCartValidationByItemRule() {
2343
+ return _evaluateCartValidationByItemRule.apply(this, arguments);
2344
+ }
2345
+ return evaluateCartValidationByItemRule;
2346
+ }()
2347
+ }, {
2348
+ key: "validateBeforeSubmitByItemRule",
2349
+ value: function () {
2350
+ var _validateBeforeSubmitByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2351
+ var validationResult, firstFailure, errorMessage, error;
2352
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2353
+ while (1) switch (_context33.prev = _context33.next) {
2354
+ case 0:
2355
+ _context33.next = 2;
2356
+ return this.evaluateCartValidationByItemRule();
2357
+ case 2:
2358
+ validationResult = _context33.sent;
2359
+ if (!validationResult.passed) {
2360
+ _context33.next = 5;
2361
+ break;
2362
+ }
2363
+ return _context33.abrupt("return");
2364
+ case 5:
2365
+ firstFailure = validationResult.failures[0];
2366
+ errorMessage = (firstFailure === null || firstFailure === void 0 ? void 0 : firstFailure.validationMessage) || '当前购物车未满足商品规则,请调整后再提交';
2367
+ error = new Error(String(errorMessage));
2368
+ error.failures = validationResult.failures;
2369
+ throw error;
2370
+ case 10:
2371
+ case "end":
2372
+ return _context33.stop();
2373
+ }
2374
+ }, _callee33, this);
2375
+ }));
2376
+ function validateBeforeSubmitByItemRule() {
2377
+ return _validateBeforeSubmitByItemRule.apply(this, arguments);
2378
+ }
2379
+ return validateBeforeSubmitByItemRule;
2380
+ }()
2381
+ }, {
2382
+ key: "refreshCartValidationPassed",
2383
+ value: function () {
2384
+ var _refreshCartValidationPassed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2385
+ var previous, nextState, validationResult, changed;
2386
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2387
+ while (1) switch (_context34.prev = _context34.next) {
2388
+ case 0:
2389
+ previous = this.store.cartValidation || {
2390
+ passed: null,
2391
+ failures: []
2392
+ };
2393
+ nextState = {
2394
+ passed: null,
2395
+ failures: []
2396
+ };
2397
+ _context34.prev = 2;
2398
+ _context34.next = 5;
2399
+ return this.evaluateCartValidationByItemRule();
2400
+ case 5:
2401
+ validationResult = _context34.sent;
2402
+ nextState = {
2403
+ passed: validationResult.passed,
2404
+ failures: validationResult.failures || []
2405
+ };
2406
+ _context34.next = 12;
2407
+ break;
2408
+ case 9:
2409
+ _context34.prev = 9;
2410
+ _context34.t0 = _context34["catch"](2);
2411
+ nextState = {
2412
+ passed: false,
2413
+ failures: []
2414
+ };
2415
+ case 12:
2416
+ this.store.cartValidation = nextState;
2417
+ changed = previous.passed !== nextState.passed || previous.failures !== nextState.failures;
2418
+ if (!changed) {
2419
+ _context34.next = 17;
2420
+ break;
2421
+ }
2422
+ _context34.next = 17;
2423
+ return this.core.effects.emit(ScanOrderHooks.onCartValidationChanged, {
2424
+ cartValidation: nextState,
2425
+ cartValidationPassed: nextState.passed
2426
+ });
2427
+ case 17:
2428
+ return _context34.abrupt("return", nextState.passed);
2429
+ case 18:
2430
+ case "end":
2431
+ return _context34.stop();
2432
+ }
2433
+ }, _callee34, this, [[2, 9]]);
2434
+ }));
2435
+ function refreshCartValidationPassed() {
2436
+ return _refreshCartValidationPassed.apply(this, arguments);
2437
+ }
2438
+ return refreshCartValidationPassed;
2439
+ }()
2440
+ }, {
2441
+ key: "setItemRuleRuntimeConfig",
2442
+ value: function () {
2443
+ var _setItemRuleRuntimeConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
2444
+ var _this$itemRuleRuntime, _this$itemRuleRuntime2;
2445
+ var config,
2446
+ _args35 = arguments;
2447
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2448
+ while (1) switch (_context35.prev = _context35.next) {
2449
+ case 0:
2450
+ config = _args35.length > 0 && _args35[0] !== undefined ? _args35[0] : {};
2451
+ this.logMethodStart('setItemRuleRuntimeConfig');
2452
+ this.itemRuleRuntimeConfig = _objectSpread(_objectSpread(_objectSpread({}, this.itemRuleRuntimeConfig), config), {}, {
2453
+ pax: _objectSpread(_objectSpread({}, ((_this$itemRuleRuntime = this.itemRuleRuntimeConfig) === null || _this$itemRuleRuntime === void 0 ? void 0 : _this$itemRuleRuntime.pax) || {}), (config === null || config === void 0 ? void 0 : config.pax) || {}),
2454
+ custom: _objectSpread(_objectSpread({}, ((_this$itemRuleRuntime2 = this.itemRuleRuntimeConfig) === null || _this$itemRuleRuntime2 === void 0 ? void 0 : _this$itemRuleRuntime2.custom) || {}), (config === null || config === void 0 ? void 0 : config.custom) || {})
2455
+ });
2456
+ if ('strategyConfigs' in config) {
2457
+ this.itemRuleConfigs = [];
2458
+ this.itemRuleConfigsPromise = null;
2459
+ this.itemRuleEvaluator.setStrategyConfigs([]);
2460
+ }
2461
+ this.itemRulePrefillApplied = false;
2462
+ _context35.next = 7;
2463
+ return this.refreshItemRuleQuantityLimits();
2464
+ case 7:
2465
+ _context35.next = 9;
2466
+ return this.refreshCartValidationPassed();
2467
+ case 9:
2468
+ this.logMethodSuccess('setItemRuleRuntimeConfig', {
2469
+ strategyCount: Array.isArray(this.itemRuleRuntimeConfig.strategyConfigs) ? this.itemRuleRuntimeConfig.strategyConfigs.length : 0
2470
+ });
2471
+ case 10:
2472
+ case "end":
2473
+ return _context35.stop();
2474
+ }
2475
+ }, _callee35, this);
2476
+ }));
2477
+ function setItemRuleRuntimeConfig() {
2478
+ return _setItemRuleRuntimeConfig.apply(this, arguments);
2479
+ }
2480
+ return setItemRuleRuntimeConfig;
2481
+ }()
2482
+ }, {
2483
+ key: "normalizeResourceState",
2484
+ value: function normalizeResourceState(detail, resourceSelectType, hasOrderId) {
2485
+ var _detail$form_record, _this$otherParams10, _detail$resource_capa, _detail$resource_capa2;
2486
+ var currentOrderId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.order_id);
2487
+ var lastOrderId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.last_order_id);
2488
+ var relationId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.form_record_id);
2489
+ var tableFormId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.form_id);
2490
+ var formRecord = (_detail$form_record = detail === null || detail === void 0 ? void 0 : detail.form_record) !== null && _detail$form_record !== void 0 ? _detail$form_record : null;
2491
+ // 是否允许加餐
2492
+ var allowSnack = ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 || (_this$otherParams10 = _this$otherParams10.dineInConfig) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10['sale.allow_add_items']) || false;
2493
+ // 开启同桌验证 - 本期没有这个配置,默认关掉
2494
+ var deskmateValid = false;
2495
+ var isExclusive = resourceSelectType === 'single';
2496
+ var isFull = computeResourceIsFull({
2497
+ resourceSelectType: resourceSelectType,
2498
+ lastOrderId: lastOrderId,
2499
+ capacityList: (_detail$resource_capa = detail === null || detail === void 0 || (_detail$resource_capa2 = detail.resource_capacity) === null || _detail$resource_capa2 === void 0 || (_detail$resource_capa2 = _detail$resource_capa2[0]) === null || _detail$resource_capa2 === void 0 ? void 0 : _detail$resource_capa2.capacity_list) !== null && _detail$resource_capa !== void 0 ? _detail$resource_capa : [],
2500
+ capacity: formRecord === null || formRecord === void 0 ? void 0 : formRecord.capacity
2501
+ });
2502
+ var availabilityInfo = {
2503
+ mode: 'idle',
2504
+ deskmate_valid: deskmateValid
2505
+ };
2506
+
2507
+ // 有currentOrderId代表是我点的单
2508
+ // 如果 url 上没有 hasOrderId,则跳转到订单详情,通过返回 resource_busy 实现
2509
+ if (currentOrderId) {
2510
+ if (!hasOrderId) {
2511
+ availabilityInfo = {
2512
+ mode: 'resource_busy',
2513
+ order_id: currentOrderId,
2514
+ relation_id: relationId,
2515
+ table_form_id: tableFormId,
2516
+ deskmate_valid: deskmateValid
2517
+ };
2518
+ } else {
2519
+ // 如果有 hasOrderId,需要检测是否允许加餐,如果允许则返回additional_order,否则也是 resource_busy
2520
+ availabilityInfo = {
2521
+ mode: allowSnack ? 'additional_order' : 'resource_busy',
2522
+ order_id: currentOrderId,
2523
+ relation_id: relationId,
2524
+ table_form_id: tableFormId,
2525
+ deskmate_valid: deskmateValid
2526
+ };
2527
+ }
2528
+ } else if (lastOrderId) {
2529
+ // 如果有其他人点的单
2530
+ // multiple 预约且容量仍有剩余时,其他人的单不影响当前用户下单,保持 idle 走正常下单流程
2531
+ var canFallthroughToIdle = resourceSelectType === 'multiple' && !isFull;
2532
+ if (!canFallthroughToIdle) {
2533
+ availabilityInfo = {
2534
+ mode: 'resource_busy',
2535
+ order_id: '0',
2536
+ relation_id: relationId,
2537
+ table_form_id: tableFormId,
2538
+ deskmate_valid: deskmateValid
2539
+ };
2540
+ }
2541
+ }
2542
+ return _objectSpread(_objectSpread({}, availabilityInfo), {}, {
2543
+ currentOrderId: currentOrderId,
2544
+ lastOrderId: lastOrderId,
2545
+ relationId: relationId,
2546
+ tableFormId: tableFormId,
2547
+ allowSnack: allowSnack,
2548
+ deskmateValid: deskmateValid,
2549
+ isExclusive: isExclusive,
2550
+ isFull: isFull,
2551
+ resourceSelectType: resourceSelectType,
2552
+ raw: detail,
2553
+ table_form_record: formRecord
2554
+ });
2555
+ }
2556
+
2557
+ // 从首个预约规则商品的 product_resource.resources 中,按 form_id 匹配返回 type
2558
+ }, {
2559
+ key: "resolveResourceSelectType",
2560
+ value: function resolveResourceSelectType(formId) {
2561
+ var _firstProduct$product;
2562
+ var firstProduct = this.enabledReservationRuleProducts[0];
2563
+ var resources = (firstProduct === null || firstProduct === void 0 || (_firstProduct$product = firstProduct.product_resource) === null || _firstProduct$product === void 0 ? void 0 : _firstProduct$product.resources) || [];
2564
+ var numericFormId = Number(formId);
2565
+ if (!Number.isFinite(numericFormId) || numericFormId <= 0) return undefined;
2566
+ var matched = resources.find(function (r) {
2567
+ return Number(r === null || r === void 0 ? void 0 : r.id) === numericFormId;
2568
+ });
2569
+ return matched === null || matched === void 0 ? void 0 : matched.type;
2570
+ }
2571
+ }, {
2572
+ key: "fetchResourceOccupyDetailsByResourceId",
2573
+ value: function () {
2574
+ var _fetchResourceOccupyDetailsByResourceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(resourceId) {
2575
+ var _this$otherParams11, _this$otherParams11$g, _response$data$occupy, _response$data;
2576
+ var formRecordId, shopId, response;
2577
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2578
+ while (1) switch (_context36.prev = _context36.next) {
2579
+ case 0:
2580
+ formRecordId = Number(resourceId);
2581
+ if (!(!Number.isFinite(formRecordId) || formRecordId <= 0)) {
2582
+ _context36.next = 3;
2583
+ break;
2584
+ }
2585
+ throw new Error("[ScanOrder] \u975E\u6CD5\u684C\u53F0 resourceId: ".concat(resourceId));
2586
+ case 3:
2587
+ shopId = (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 || (_this$otherParams11$g = _this$otherParams11.getStateData) === null || _this$otherParams11$g === void 0 ? void 0 : _this$otherParams11$g.call(_this$otherParams11, 'shop_id');
2588
+ if (shopId) {
2589
+ _context36.next = 6;
2590
+ break;
2591
+ }
2592
+ throw new Error('[ScanOrder] 无法获取 shop_id');
2593
+ case 6:
2594
+ _context36.next = 8;
2595
+ return this.request.get('/order/resource/occupy-detail', {
2596
+ shop_id: shopId,
2597
+ 'form_record_ids[]': formRecordId,
2598
+ with_resource_capacity_info: 1,
2599
+ with_resource_order_info: 1,
2600
+ with_resource_form_info: 1
2601
+ });
2602
+ case 8:
2603
+ response = _context36.sent;
2604
+ if (response !== null && response !== void 0 && response.status) {
2605
+ _context36.next = 11;
2606
+ break;
2607
+ }
2608
+ throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取资源占用详情失败');
2609
+ case 11:
2610
+ return _context36.abrupt("return", (_response$data$occupy = response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.occupy_details) !== null && _response$data$occupy !== void 0 ? _response$data$occupy : []);
2611
+ case 12:
2612
+ case "end":
2613
+ return _context36.stop();
2614
+ }
2615
+ }, _callee36, this);
2616
+ }));
2617
+ function fetchResourceOccupyDetailsByResourceId(_x18) {
2618
+ return _fetchResourceOccupyDetailsByResourceId.apply(this, arguments);
2619
+ }
2620
+ return fetchResourceOccupyDetailsByResourceId;
2621
+ }()
2622
+ }, {
2623
+ key: "resolveAdditionalOrderFromOccupyDetail",
2624
+ value: function resolveAdditionalOrderFromOccupyDetail(detail, resourceSelectType, allowAddItems) {
2625
+ var currentOrderId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.order_id);
2626
+ if (currentOrderId) {
2627
+ return {
2628
+ matched: true,
2629
+ order_id: currentOrderId
2630
+ };
2631
+ }
2632
+ var orderListIds = (Array.isArray(detail === null || detail === void 0 ? void 0 : detail.order_list) ? (detail === null || detail === void 0 ? void 0 : detail.order_list) || [] : []).map(function (order) {
2633
+ return toPositiveString(order === null || order === void 0 ? void 0 : order.id);
2634
+ }).filter(Boolean);
2635
+ if (resourceSelectType !== 'single') {
2636
+ return {
2637
+ matched: false,
2638
+ reason: 'no_order'
2639
+ };
2640
+ }
2641
+ if (!orderListIds.length) {
2642
+ return {
2643
+ matched: false,
2644
+ reason: 'no_order'
2645
+ };
2646
+ }
2647
+ if (!allowAddItems) {
2648
+ return {
2649
+ matched: false,
2650
+ reason: 'add_items_disabled'
2651
+ };
2652
+ }
2653
+ if (orderListIds.length === 1) {
2654
+ return {
2655
+ matched: true,
2656
+ order_id: orderListIds[0]
2657
+ };
2658
+ }
2659
+ if (orderListIds.length > 1) {
2660
+ return {
2661
+ matched: false,
2662
+ reason: 'multiple_orders'
2663
+ };
2664
+ }
2665
+ return {
2666
+ matched: false,
2667
+ reason: 'no_order'
2668
+ };
2669
+ }
2670
+
2671
+ // 检测当前链接是否可用
2672
+ // 通过 resource_id + 店铺配置
2673
+ // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
2674
+ }, {
2675
+ key: "checkResourceAvailable",
2676
+ value: function () {
2677
+ var _checkResourceAvailable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(resourceId) {
2678
+ var hasOrderId,
2679
+ normalizedResourceId,
2680
+ _this$otherParams$bus,
2681
+ _this$otherParams12,
2682
+ _this$otherParams$cha,
2683
+ _this$otherParams13,
2684
+ _this$otherParams14,
2685
+ _this$otherParams14$g,
2686
+ _occupyDetails$,
2687
+ _occupyDetail$form_re,
2688
+ _occupyDetail$form_re2,
2689
+ _this$otherParams15,
2690
+ _this$store$order6,
2691
+ _this$store$order7,
2692
+ _this$store$order7$ge,
2693
+ _this$otherParams16,
2694
+ businessCode,
2695
+ channel,
2696
+ openDataTarget,
2697
+ openData,
2698
+ dineInConfig,
2699
+ closedBehaviorValue,
2700
+ closedMessage,
2701
+ basicUnavailableMessage,
2702
+ pauseMessage,
2703
+ makeShopClosed,
2704
+ operatingHourIds,
2705
+ outsideOperatingHours,
2706
+ scheduleList,
2707
+ now,
2708
+ tempOrder,
2709
+ reservationLinkIds,
2710
+ pendingRequestEntryPax,
2711
+ pendingRequestPaxMin,
2712
+ pendingRequestPaxMax,
2713
+ reservationProductList,
2714
+ scheduleDate,
2715
+ scheduleDatetime,
2716
+ loaded,
2717
+ matchedRuleProduct,
2718
+ ruleProductsForResource,
2719
+ occupancyMinutes,
2720
+ paxBounds,
2721
+ error,
2722
+ occupyDetails,
2723
+ occupyDetail,
2724
+ resourceSelectType,
2725
+ allowAddItems,
2726
+ additionalOrderResult,
2727
+ _occupyDetail$order_l,
2728
+ multipleOrdersState,
2729
+ _availabilityInfo,
2730
+ resourceState,
2731
+ additionalOrderId,
2732
+ availabilityInfo,
2733
+ isAdditionalOrderMode,
2734
+ lastOrderInfo,
2735
+ historicalItems,
2736
+ _args37 = arguments;
2737
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2738
+ while (1) switch (_context37.prev = _context37.next) {
2739
+ case 0:
2740
+ hasOrderId = _args37.length > 1 && _args37[1] !== undefined ? _args37[1] : false;
2741
+ normalizedResourceId = String(resourceId !== null && resourceId !== void 0 ? resourceId : '').trim();
2742
+ this.logMethodStart('checkResourceAvailable', {
2743
+ resourceId: normalizedResourceId
2744
+ });
2745
+ _context37.prev = 3;
2746
+ businessCode = String((_this$otherParams$bus = (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.businessCode) !== null && _this$otherParams$bus !== void 0 ? _this$otherParams$bus : '').trim();
2747
+ channel = String((_this$otherParams$cha = (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.channel) !== null && _this$otherParams$cha !== void 0 ? _this$otherParams$cha : '').trim();
2748
+ openDataTarget = businessCode && channel ? "".concat(businessCode, "+").concat(channel) : 'dine_in+scan_to_order';
2749
+ _context37.next = 9;
2750
+ return (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 || (_this$otherParams14$g = _this$otherParams14.getOpenData) === null || _this$otherParams14$g === void 0 ? void 0 : _this$otherParams14$g.call(_this$otherParams14, {
2751
+ scope: 'board',
2752
+ target: openDataTarget,
2753
+ section_code: ['basic', 'fulfillment', 'reservation', 'sale', 'menu', 'availability', 'workflow']
2754
+ });
2755
+ case 9:
2756
+ openData = _context37.sent;
2757
+ if (!((openData === null || openData === void 0 ? void 0 : openData.status) === false)) {
2758
+ _context37.next = 12;
2759
+ break;
2760
+ }
2761
+ throw new Error((openData === null || openData === void 0 ? void 0 : openData.message) || '获取店铺配置失败');
2762
+ case 12:
2763
+ dineInConfig = (openData === null || openData === void 0 ? void 0 : openData.data) || {};
2764
+ this.otherParams.dineInConfig = dineInConfig;
2765
+ _context37.next = 16;
2766
+ return this.syncItemRuleConfigsFromDineInConfig(dineInConfig);
2767
+ case 16:
2768
+ closedBehaviorValue = dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.closed_behavior'];
2769
+ closedMessage = (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.closed_message']) || (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.message']) || (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['basic.closed_message']);
2770
+ basicUnavailableMessage = (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['basic.unavailable_message']) || closedMessage;
2771
+ pauseMessage = (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.pause_message']) || closedMessage;
2772
+ makeShopClosed = function makeShopClosed(errorTips, closed_behavior) {
2773
+ return {
2774
+ mode: 'shop_closed',
2775
+ order_id: undefined,
2776
+ relation_id: undefined,
2777
+ table_form_id: undefined,
2778
+ deskmate_valid: false,
2779
+ errorTips: errorTips,
2780
+ closed_behavior: closed_behavior
2781
+ };
2782
+ }; // 1. 基础开关 basic.enable 关闭
2783
+ if (!((dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['basic.enable']) === false)) {
2784
+ _context37.next = 23;
2785
+ break;
2786
+ }
2787
+ return _context37.abrupt("return", makeShopClosed(basicUnavailableMessage));
2788
+ case 23:
2789
+ if (!toBoolean(dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.paused'])) {
2790
+ _context37.next = 26;
2791
+ break;
2792
+ }
2793
+ if (!((dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.pause_behavior']) === 'hide_all')) {
2794
+ _context37.next = 26;
2795
+ break;
2796
+ }
2797
+ return _context37.abrupt("return", makeShopClosed(pauseMessage));
2798
+ case 26:
2799
+ // 3. 营业时间 operating_hours 闸门
2800
+ operatingHourIds = Array.isArray(dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.operating_hours']) ? dineInConfig['availability.operating_hours'].map(function (id) {
2801
+ return Number(id);
2802
+ }).filter(function (id) {
2803
+ return Number.isFinite(id) && id > 0;
2804
+ }) : [];
2805
+ outsideOperatingHours = false;
2806
+ if (operatingHourIds.length && this.store.schedule) {
2807
+ scheduleList = this.store.schedule.getScheduleListByIds(operatingHourIds);
2808
+ if (scheduleList.length) {
2809
+ now = dayjs().format('YYYY-MM-DD HH:mm:ss');
2810
+ outsideOperatingHours = !getDateIsInSchedule(now, scheduleList);
2811
+ }
2812
+ }
2813
+ if (!(outsideOperatingHours && closedBehaviorValue !== 'show_menu_disabled')) {
2814
+ _context37.next = 31;
2815
+ break;
2816
+ }
2817
+ return _context37.abrupt("return", makeShopClosed(closedMessage, closedBehaviorValue));
2818
+ case 31:
2819
+ // Step1: 先加载预约规则商品,拿到 enabledReservationRuleProducts 与容量附加信息
2820
+ // (resourceSelectType 需要基于这些商品 + 占用接口的 form_id 计算,故必须前置)
2821
+ tempOrder = this.ensureTempOrder();
2822
+ reservationLinkIds = collectLinkProductIdsFromReservationRules(dineInConfig['fulfillment.enabled_resource_rules']);
2823
+ if (!(!normalizedResourceId || reservationLinkIds.length === 0)) {
2824
+ _context37.next = 37;
2825
+ break;
2826
+ }
2827
+ _context37.next = 36;
2828
+ return this.prepareRetailAvailability({
2829
+ tempOrder: tempOrder,
2830
+ hasOrderId: hasOrderId,
2831
+ resourceId: normalizedResourceId,
2832
+ reason: !normalizedResourceId ? 'missing_resource_id' : 'missing_enabled_resource_rules'
2833
+ });
2834
+ case 36:
2835
+ return _context37.abrupt("return", _context37.sent);
2836
+ case 37:
2837
+ tempOrder.metadata = _objectSpread({}, tempOrder.metadata || {});
2838
+ delete tempOrder.metadata.table_occupancy_duration;
2839
+ reservationProductList = new ProductList("".concat(this.name, "_reservationEnabledRules"), this.defaultVersion);
2840
+ _context37.next = 42;
2841
+ return reservationProductList.initialize(this.core, {
2842
+ store: {
2843
+ list: [],
2844
+ selectProducts: []
2845
+ },
2846
+ otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
2847
+ fatherModule: this.name,
2848
+ openCache: Boolean(this.cacheId),
2849
+ cacheId: this.cacheId
2850
+ })
2851
+ });
2852
+ case 42:
2853
+ scheduleDate = dayjs().format('YYYY-MM-DD');
2854
+ scheduleDatetime = dayjs().format('YYYY-MM-DD HH:mm:ss');
2855
+ _context37.next = 46;
2856
+ return reservationProductList.loadProducts({
2857
+ product_ids: reservationLinkIds,
2858
+ schedule_date: scheduleDate,
2859
+ schedule_datetime: scheduleDatetime,
2860
+ cacheId: this.cacheId
2861
+ });
2862
+ case 46:
2863
+ loaded = _context37.sent;
2864
+ if (Array.isArray(loaded)) {
2865
+ matchedRuleProduct = findReservationRuleProductByResourceId(loaded, normalizedResourceId);
2866
+ ruleProductsForResource = matchedRuleProduct ? [matchedRuleProduct] : [];
2867
+ this.enabledReservationRuleProducts = ruleProductsForResource;
2868
+ occupancyMinutes = pickFirstDurationMinutesFromProducts(ruleProductsForResource);
2869
+ if (occupancyMinutes !== undefined) {
2870
+ tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
2871
+ }
2872
+ if (hasCustomCapacityProduct(ruleProductsForResource)) {
2873
+ pendingRequestEntryPax = 1;
2874
+ paxBounds = pickFirstCustomCapacityPaxBounds(ruleProductsForResource);
2875
+ if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.min) !== undefined) pendingRequestPaxMin = paxBounds.min;
2876
+ if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.max) !== undefined) pendingRequestPaxMax = paxBounds.max;
2877
+ }
2878
+ } else {
2879
+ this.enabledReservationRuleProducts = [];
2880
+ error = loaded instanceof Error ? loaded : new Error('预约规则商品列表接口返回异常');
2881
+ this.logMethodError('loadReservationRuleProducts', error, {
2882
+ resourceId: normalizedResourceId,
2883
+ reservationLinkIds: reservationLinkIds,
2884
+ scheduleDate: scheduleDate,
2885
+ scheduleDatetime: scheduleDatetime,
2886
+ cacheId: this.cacheId
2887
+ });
2888
+ }
2889
+
2890
+ // Step2: 请求新的资源占用详情接口。occupy_details 第一维是资源,不是订单。
2891
+ _context37.next = 50;
2892
+ return this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
2893
+ case 50:
2894
+ occupyDetails = _context37.sent;
2895
+ occupyDetail = (_occupyDetails$ = occupyDetails[0]) !== null && _occupyDetails$ !== void 0 ? _occupyDetails$ : null; // Step3: 结合预约规则商品的 product_resource.resources 与占用接口返回的 form_id,
2896
+ // 计算当前桌台的 resourceSelectType(single/multiple/capacity)
2897
+ resourceSelectType = this.resolveResourceSelectType(toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id));
2898
+ allowAddItems = toBoolean(dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['sale.allow_add_items']);
2899
+ additionalOrderResult = this.resolveAdditionalOrderFromOccupyDetail(occupyDetail, resourceSelectType, allowAddItems);
2900
+ if (!(additionalOrderResult.reason === 'multiple_orders')) {
2901
+ _context37.next = 61;
2902
+ break;
2903
+ }
2904
+ multipleOrdersState = _objectSpread(_objectSpread({}, this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId)), {}, {
2905
+ mode: 'multiple_orders'
2906
+ });
2907
+ this.store.resource = multipleOrdersState;
2908
+ _availabilityInfo = {
2909
+ mode: 'multiple_orders',
2910
+ deskmate_valid: multipleOrdersState.deskmate_valid,
2911
+ relation_id: multipleOrdersState.relationId,
2912
+ table_form_id: multipleOrdersState.tableFormId,
2913
+ table_form_record: multipleOrdersState.table_form_record
2914
+ };
2915
+ this.logMethodSuccess('checkResourceAvailable', {
2916
+ resourceId: normalizedResourceId,
2917
+ mode: _availabilityInfo.mode,
2918
+ orderListCount: (occupyDetail === null || occupyDetail === void 0 || (_occupyDetail$order_l = occupyDetail.order_list) === null || _occupyDetail$order_l === void 0 ? void 0 : _occupyDetail$order_l.length) || 0,
2919
+ resourceSelectType: resourceSelectType
2920
+ });
2921
+ return _context37.abrupt("return", _availabilityInfo);
2922
+ case 61:
2923
+ // Step4: 用 occupyDetail + resourceSelectType 规整为 resourceState
2924
+ resourceState = this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId);
2925
+ additionalOrderId = additionalOrderResult.order_id;
2926
+ if (additionalOrderId) {
2927
+ resourceState.mode = 'additional_order';
2928
+ resourceState.order_id = additionalOrderId;
2929
+ } else if (additionalOrderResult.reason === 'add_items_disabled') {
2930
+ resourceState.mode = 'resource_busy';
2931
+ resourceState.order_id = '0';
2932
+ } else if (resourceSelectType === 'multiple' && resourceState.isFull) {
2933
+ resourceState.mode = 'resource_busy';
2934
+ resourceState.order_id = '0';
2935
+ }
2936
+ this.store.resource = resourceState;
2937
+
2938
+ // Step5: 把预约规则商品阶段暂存的 requestEntryPax 等注入 store.resource
2939
+ if (pendingRequestEntryPax !== undefined) {
2940
+ this.store.resource.requestEntryPax = pendingRequestEntryPax;
2941
+ }
2942
+ if (pendingRequestPaxMin !== undefined) {
2943
+ this.store.resource.requestPaxMin = pendingRequestPaxMin;
2944
+ }
2945
+ if (pendingRequestPaxMax !== undefined) {
2946
+ this.store.resource.requestPaxMax = pendingRequestPaxMax;
2947
+ }
2948
+ availabilityInfo = _objectSpread(_objectSpread(_objectSpread({
2949
+ mode: resourceState.mode,
2950
+ order_id: resourceState.order_id,
2951
+ relation_id: resourceState.relationId,
2952
+ table_form_id: resourceState.tableFormId,
2953
+ deskmate_valid: resourceState.deskmate_valid,
2954
+ table_form_record: resourceState.table_form_record,
2955
+ policy: occupyDetail === null || occupyDetail === void 0 || (_occupyDetail$form_re = occupyDetail.form_record) === null || _occupyDetail$form_re === void 0 ? void 0 : _occupyDetail$form_re.policy,
2956
+ partyroom_booking: occupyDetail === null || occupyDetail === void 0 || (_occupyDetail$form_re2 = occupyDetail.form_record) === null || _occupyDetail$form_re2 === void 0 ? void 0 : _occupyDetail$form_re2.partyroom_booking
2957
+ }, this.store.resource.requestEntryPax !== undefined ? {
2958
+ requestEntryPax: this.store.resource.requestEntryPax
2959
+ } : {}), this.store.resource.requestPaxMin !== undefined ? {
2960
+ requestPaxMin: this.store.resource.requestPaxMin
2961
+ } : {}), this.store.resource.requestPaxMax !== undefined ? {
2962
+ requestPaxMax: this.store.resource.requestPaxMax
2963
+ } : {});
2964
+ tempOrder.relation_id = normalizedResourceId || ((_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.relation_id);
2965
+ tempOrder.table_form_id = resourceState.tableFormId;
2966
+ tempOrder.resource_id = normalizedResourceId;
2967
+ (_this$store$order6 = this.store.order) === null || _this$store$order6 === void 0 || _this$store$order6.persistTempOrder();
2968
+
2969
+ // 空闲状态下自动准备本地临时订单,供后续“购物车式”商品操作使用
2970
+ if (!(availabilityInfo.mode === 'idle')) {
2971
+ _context37.next = 76;
2972
+ break;
2973
+ }
2974
+ _context37.next = 76;
2975
+ return this.addNewOrder();
2976
+ case 76:
2977
+ isAdditionalOrderMode = availabilityInfo.mode === 'additional_order' || availabilityInfo.mode === 'additional_order_with_code'; // 如果是加单模式,tempOrder 里需要记录目标订单 id,提交的时候走加单接口
2978
+ if (isAdditionalOrderMode) {
2979
+ tempOrder.order_id = additionalOrderId;
2980
+ }
2981
+ lastOrderInfo = (_this$store$order7 = this.store.order) === null || _this$store$order7 === void 0 || (_this$store$order7$ge = _this$store$order7.getLastOrderInfo) === null || _this$store$order7$ge === void 0 ? void 0 : _this$store$order7$ge.call(_this$store$order7);
2982
+ historicalItems = isAdditionalOrderMode && Array.isArray(lastOrderInfo === null || lastOrderInfo === void 0 ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce(function (acc, p) {
2983
+ if (typeof (p === null || p === void 0 ? void 0 : p.product_id) !== 'number') return acc;
2984
+ acc.push(_objectSpread({
2985
+ product_id: p.product_id,
2986
+ quantity: Number(p.product_quantity) || 0
2987
+ }, typeof p.product_variant_id === 'number' ? {
2988
+ product_variant_id: p.product_variant_id
2989
+ } : {}));
2990
+ return acc;
2991
+ }, []) : []; // pax 由 setEntryPaxNumber 负责写入 itemRuleRuntimeConfig.pax
2992
+ _context37.next = 82;
2993
+ return this.setItemRuleRuntimeConfig({
2994
+ serviceType: (_this$otherParams16 = this.otherParams) === null || _this$otherParams16 === void 0 ? void 0 : _this$otherParams16.businessCode,
2995
+ submissionIndex: isAdditionalOrderMode ? 1 : 0,
2996
+ historicalItems: historicalItems
2997
+ });
2998
+ case 82:
2999
+ // operating_hours 超出营业时段 + closed_behavior=show_menu_disabled:
3000
+ // 允许浏览商品但 UI 层需拦截“下一步”,这里覆盖最终 mode 并回传错误提示
3001
+ if (outsideOperatingHours && closedBehaviorValue === 'show_menu_disabled') {
3002
+ availabilityInfo.mode = 'submit_disabled';
3003
+ availabilityInfo.errorTips = closedMessage;
3004
+ availabilityInfo.closed_behavior = closedBehaviorValue;
3005
+ }
3006
+ this.logMethodSuccess('checkResourceAvailable', {
3007
+ resourceId: normalizedResourceId,
3008
+ mode: availabilityInfo.mode,
3009
+ orderId: availabilityInfo.order_id,
3010
+ relationId: availabilityInfo.relation_id,
3011
+ tableFormId: availabilityInfo.table_form_id,
3012
+ persistedRelationId: tempOrder.relation_id,
3013
+ persistedResourceId: tempOrder.resource_id,
3014
+ deskmateValid: availabilityInfo.deskmate_valid,
3015
+ resourceSelectType: resourceState.resourceSelectType,
3016
+ isExclusive: resourceState.isExclusive,
3017
+ isFull: resourceState.isFull
3018
+ });
3019
+ return _context37.abrupt("return", availabilityInfo);
3020
+ case 87:
3021
+ _context37.prev = 87;
3022
+ _context37.t0 = _context37["catch"](3);
3023
+ this.logMethodError('checkResourceAvailable', _context37.t0.message, {
3024
+ resourceId: normalizedResourceId
3025
+ });
3026
+ throw _context37.t0;
3027
+ case 91:
3028
+ case "end":
3029
+ return _context37.stop();
3030
+ }
3031
+ }, _callee37, this, [[3, 87]]);
3032
+ }));
3033
+ function checkResourceAvailable(_x19) {
3034
+ return _checkResourceAvailable.apply(this, arguments);
3035
+ }
3036
+ return checkResourceAvailable;
3037
+ }() // 恢复之前订单的数据,读取 entrypax
3038
+ }, {
3039
+ key: "restorePreviousOrderData",
3040
+ value: function () {
3041
+ var _restorePreviousOrderData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
3042
+ var tempOrder, _this$store$order8, _res$data, res, entryPaxNumber;
3043
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3044
+ while (1) switch (_context38.prev = _context38.next) {
3045
+ case 0:
3046
+ tempOrder = this.ensureTempOrder();
3047
+ if (!tempOrder.order_id) {
3048
+ _context38.next = 9;
3049
+ break;
3050
+ }
3051
+ _context38.next = 4;
3052
+ return (_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 ? void 0 : _this$store$order8.getOrderInfoByRemote(tempOrder.order_id);
3053
+ case 4:
3054
+ res = _context38.sent;
3055
+ // 找到下单的时候输入的 entryPaxNumber
3056
+ entryPaxNumber = res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 || (_res$data = _res$data.bookings) === null || _res$data === void 0 || (_res$data = _res$data.find(function (p) {
3057
+ var _p$metadata;
3058
+ return (_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.collect_pax;
3059
+ })) === null || _res$data === void 0 || (_res$data = _res$data.metadata) === null || _res$data === void 0 ? void 0 : _res$data.collect_pax;
3060
+ if (!entryPaxNumber) {
3061
+ _context38.next = 9;
3062
+ break;
3063
+ }
3064
+ _context38.next = 9;
3065
+ return this.setEntryPaxNumber(entryPaxNumber);
3066
+ case 9:
3067
+ case "end":
3068
+ return _context38.stop();
3069
+ }
3070
+ }, _callee38, this);
3071
+ }));
3072
+ function restorePreviousOrderData() {
3073
+ return _restorePreviousOrderData.apply(this, arguments);
3074
+ }
3075
+ return restorePreviousOrderData;
3076
+ }() // 如果是加单的情况,提供返回当前订单相关信息的能力
3077
+ }, {
3078
+ key: "getAdditionalOrderInfo",
3079
+ value: function () {
3080
+ var _getAdditionalOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3081
+ var result;
3082
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3083
+ while (1) switch (_context39.prev = _context39.next) {
3084
+ case 0:
3085
+ this.logMethodStart('getAdditionalOrderInfo');
3086
+ result = {
3087
+ orderId: '123567890',
3088
+ orderStatus: 'pending',
3089
+ orderTime: '2026-03-31 10:00:00',
3090
+ orderAmount: 100,
3091
+ orderItems: []
3092
+ };
3093
+ this.logMethodSuccess('getAdditionalOrderInfo', {
3094
+ orderId: result.orderId,
3095
+ orderStatus: result.orderStatus
3096
+ });
3097
+ return _context39.abrupt("return", result);
3098
+ case 4:
3099
+ case "end":
3100
+ return _context39.stop();
3101
+ }
3102
+ }, _callee39, this);
3103
+ }));
3104
+ function getAdditionalOrderInfo() {
3105
+ return _getAdditionalOrderInfo.apply(this, arguments);
3106
+ }
3107
+ return getAdditionalOrderInfo;
3108
+ }() // 获取商品列表
3109
+ }, {
3110
+ key: "getProductList",
3111
+ value: function () {
3112
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3113
+ var _this$otherParams17;
3114
+ var menu_list_ids, res, productList, formattedRes;
3115
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3116
+ while (1) switch (_context40.prev = _context40.next) {
3117
+ case 0:
3118
+ this.logMethodStart('getProductList');
3119
+ // 可以直接通过配置里的 menu 读取
3120
+ menu_list_ids = ((_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 || (_this$otherParams17 = _this$otherParams17.dineInConfig) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17['menu.associated_menus'].map(function (n) {
3121
+ return Number(n.value);
3122
+ })) || [];
3123
+ _context40.prev = 2;
3124
+ if (this.store.products) {
3125
+ _context40.next = 5;
3126
+ break;
3127
+ }
3128
+ throw new Error('products 模块未初始化');
3129
+ case 5:
3130
+ _context40.next = 7;
3131
+ return this.store.products.loadProducts({
3132
+ menu_list_ids: menu_list_ids,
3133
+ cacheId: this.cacheId,
3134
+ schedule_date: dayjs().format('YYYY-MM-DD'),
3135
+ schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
3136
+ });
3137
+ case 7:
3138
+ res = _context40.sent;
3139
+ productList = this.assertProductListLoaded('getProductList', res, {
3140
+ menu_list_ids: menu_list_ids,
3141
+ cacheId: this.cacheId
3142
+ });
3143
+ formattedRes = attachItemRuleLimitsToTopLevelProducts(productList, this.store.itemRuleQuantityLimits || []);
3144
+ this.logMethodSuccess('getProductList', {
3145
+ menuCount: menu_list_ids.length
3146
+ });
3147
+ return _context40.abrupt("return", formattedRes);
3148
+ case 14:
3149
+ _context40.prev = 14;
3150
+ _context40.t0 = _context40["catch"](2);
3151
+ if (!(_context40.t0 !== null && _context40.t0 !== void 0 && _context40.t0.__scanOrderLogged)) {
3152
+ this.logMethodError('getProductList', _context40.t0, {
3153
+ menu_list_ids: menu_list_ids,
3154
+ cacheId: this.cacheId
3155
+ });
3156
+ }
3157
+ throw _context40.t0;
3158
+ case 18:
3159
+ case "end":
3160
+ return _context40.stop();
3161
+ }
3162
+ }, _callee40, this, [[2, 14]]);
3163
+ }));
3164
+ function getProductList() {
3165
+ return _getProductList.apply(this, arguments);
3166
+ }
3167
+ return getProductList;
3168
+ }()
3169
+ }, {
3170
+ key: "getOtherParams",
3171
+ value: function getOtherParams() {
3172
+ return this.otherParams;
3173
+ }
3174
+ }, {
3175
+ key: "setOtherParams",
3176
+ value: function () {
3177
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
3178
+ var _ref9,
3179
+ _ref9$cover,
3180
+ cover,
3181
+ _args41 = arguments;
3182
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3183
+ while (1) switch (_context41.prev = _context41.next) {
3184
+ case 0:
3185
+ _ref9 = _args41.length > 1 && _args41[1] !== undefined ? _args41[1] : {}, _ref9$cover = _ref9.cover, cover = _ref9$cover === void 0 ? false : _ref9$cover;
3186
+ if (cover) {
3187
+ this.otherParams = params;
3188
+ } else {
3189
+ this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
3190
+ }
3191
+ case 2:
3192
+ case "end":
3193
+ return _context41.stop();
3194
+ }
3195
+ }, _callee41, this);
3196
+ }));
3197
+ function setOtherParams(_x20) {
3198
+ return _setOtherParams.apply(this, arguments);
3199
+ }
3200
+ return setOtherParams;
3201
+ }() // ─── UI 状态缓存(按 cacheId 分桶,localStorage) ───
3202
+ //
3203
+ // 用于物料层持久化 UI 层面的轻量状态(如当前步骤、gate 标记、登录回跳意图等)。
3204
+ // 桶键:pisell.scanOrder.uiState:<cacheId>;内部以 JSON object 形式存储多个字段。
3205
+ // 无 cacheId 时所有方法自动降级为 no-op,上层不用判空。
3206
+ //
3207
+ // 之所以用 localStorage 而不是 sessionStorage:
3208
+ // 1. 与 Order 模块 openCache 下的 tempOrder 同栈,购物车在 / UIState 在,行为对齐;
3209
+ // 2. pisell1.login 整页 OAuth 跳转在 H5 壳 / iOS Safari 场景下可能丢 sessionStorage,
3210
+ // 导致登录回跳后 gate 标记失效、pax 弹窗重开、落点错误;localStorage 稳定不受影响。
3211
+ // 3. 失效由上层显式控制:提交成功 clearStepCache / entryContext 不一致 clearUIState /
3212
+ // pendingStep 登录回调 deleteUIState,足够约束生命周期。
3213
+ }, {
3214
+ key: "getUIStateBucketKey",
3215
+ value: function getUIStateBucketKey() {
3216
+ if (!this.cacheId) return null;
3217
+ return "".concat(ScanOrderImpl.UI_STATE_KEY_PREFIX).concat(this.cacheId);
3218
+ }
3219
+ }, {
3220
+ key: "readUIStateBucket",
3221
+ value: function readUIStateBucket() {
3222
+ var _this$window;
3223
+ var key = this.getUIStateBucketKey();
3224
+ if (!key || !((_this$window = this.window) !== null && _this$window !== void 0 && _this$window.localStorage)) return {};
3225
+ try {
3226
+ var raw = this.window.localStorage.getItem(key) || '{}';
3227
+ var parsed = JSON.parse(raw);
3228
+ return parsed && _typeof(parsed) === 'object' ? parsed : {};
3229
+ } catch (_unused2) {
3230
+ return {};
3231
+ }
3232
+ }
3233
+ }, {
3234
+ key: "writeUIStateBucket",
3235
+ value: function writeUIStateBucket(bucket) {
3236
+ var _this$window2;
3237
+ var key = this.getUIStateBucketKey();
3238
+ if (!key || !((_this$window2 = this.window) !== null && _this$window2 !== void 0 && _this$window2.localStorage)) return;
3239
+ try {
3240
+ this.window.localStorage.setItem(key, JSON.stringify(bucket));
3241
+ } catch (error) {
3242
+ console.warn('[ScanOrder] writeUIStateBucket failed', error);
3243
+ }
3244
+ }
3245
+ }, {
3246
+ key: "setUIState",
3247
+ value: function setUIState(key, value) {
3248
+ if (!this.getUIStateBucketKey()) return;
3249
+ var bucket = this.readUIStateBucket();
3250
+ bucket[key] = value;
3251
+ this.writeUIStateBucket(bucket);
3252
+ }
3253
+ }, {
3254
+ key: "getUIState",
3255
+ value: function getUIState(key) {
3256
+ if (!this.getUIStateBucketKey()) return undefined;
3257
+ var bucket = this.readUIStateBucket();
3258
+ return bucket[key];
3259
+ }
3260
+ }, {
3261
+ key: "deleteUIState",
3262
+ value: function deleteUIState(key) {
3263
+ if (!this.getUIStateBucketKey()) return;
3264
+ var bucket = this.readUIStateBucket();
3265
+ if (key in bucket) {
3266
+ delete bucket[key];
3267
+ this.writeUIStateBucket(bucket);
3268
+ }
3269
+ }
3270
+
3271
+ // 整桶清空(用于扫新桌、提交成功、restoreOrder 等场景)
3272
+ }, {
3273
+ key: "clearUIState",
3274
+ value: function clearUIState() {
3275
+ var _this$window3;
3276
+ var key = this.getUIStateBucketKey();
3277
+ if (!key || !((_this$window3 = this.window) !== null && _this$window3 !== void 0 && _this$window3.localStorage)) return;
3278
+ try {
3279
+ this.window.localStorage.removeItem(key);
3280
+ } catch (error) {
3281
+ console.warn('[ScanOrder] clearUIState failed', error);
3282
+ }
3283
+ }
3284
+ }, {
3285
+ key: "setEntryPaxNumber",
3286
+ value: function () {
3287
+ var _setEntryPaxNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(number) {
3288
+ var pax, t;
3289
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3290
+ while (1) switch (_context42.prev = _context42.next) {
3291
+ case 0:
3292
+ pax = normalizeSubmitCollectPaxValue(number);
3293
+ this.store.entryPaxNumber = pax;
3294
+ if (this.store.order) {
3295
+ t = this.store.order.ensureTempOrder();
3296
+ t.metadata = _objectSpread(_objectSpread({}, t.metadata), {}, {
3297
+ collect_pax: pax
3298
+ });
3299
+ this.store.order.persistTempOrder();
3300
+ }
3301
+
3302
+ // pax 变化后同步到 itemRuleRuntimeConfig,并刷新限购 / 校验
3303
+ this.itemRuleRuntimeConfig = _objectSpread(_objectSpread({}, this.itemRuleRuntimeConfig), {}, {
3304
+ pax: {
3305
+ total: pax,
3306
+ adult: 0,
3307
+ child: 0
3308
+ }
3309
+ });
3310
+ this.itemRulePrefillApplied = false;
3311
+ _context42.next = 7;
3312
+ return this.refreshItemRuleQuantityLimits();
3313
+ case 7:
3314
+ _context42.next = 9;
3315
+ return this.refreshCartValidationPassed();
3316
+ case 9:
3317
+ case "end":
3318
+ return _context42.stop();
3319
+ }
3320
+ }, _callee42, this);
3321
+ }));
3322
+ function setEntryPaxNumber(_x21) {
3323
+ return _setEntryPaxNumber.apply(this, arguments);
3324
+ }
3325
+ return setEntryPaxNumber;
3326
+ }()
3327
+ }, {
3328
+ key: "getEntryPaxNumber",
3329
+ value: function getEntryPaxNumber() {
3330
+ return this.store.entryPaxNumber;
3331
+ }
3332
+ }, {
3333
+ key: "syncAdditionalOrderFromResource",
3334
+ value: function () {
3335
+ var _syncAdditionalOrderFromResource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(resourceId) {
3336
+ var _ref10, _ref11, _ref12, _this$store$resource2, _this$store$resource3, _occupyDetails$2, _this$store$resource4, _this$otherParams18, _this$store$order9;
3337
+ var tempOrder, normalizedResourceId, _result, occupyDetails, occupyDetail, resourceSelectType, allowAddItems, result;
3338
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3339
+ while (1) switch (_context43.prev = _context43.next) {
3340
+ case 0:
3341
+ tempOrder = this.ensureTempOrder();
3342
+ normalizedResourceId = String((_ref10 = (_ref11 = (_ref12 = resourceId !== null && resourceId !== void 0 ? resourceId : tempOrder.resource_id) !== null && _ref12 !== void 0 ? _ref12 : (_this$store$resource2 = this.store.resource) === null || _this$store$resource2 === void 0 ? void 0 : _this$store$resource2.relationId) !== null && _ref11 !== void 0 ? _ref11 : (_this$store$resource3 = this.store.resource) === null || _this$store$resource3 === void 0 ? void 0 : _this$store$resource3.relation_id) !== null && _ref10 !== void 0 ? _ref10 : '').trim();
3343
+ this.logMethodStart('syncAdditionalOrderFromResource', {
3344
+ resourceId: normalizedResourceId
3345
+ });
3346
+ if (normalizedResourceId) {
3347
+ _context43.next = 7;
3348
+ break;
3349
+ }
3350
+ _result = {
3351
+ matched: false,
3352
+ reason: 'missing_resource_id'
3353
+ };
3354
+ this.logMethodSuccess('syncAdditionalOrderFromResource', _result);
3355
+ return _context43.abrupt("return", _result);
3356
+ case 7:
3357
+ _context43.next = 9;
3358
+ return this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
3359
+ case 9:
3360
+ occupyDetails = _context43.sent;
3361
+ occupyDetail = (_occupyDetails$2 = occupyDetails[0]) !== null && _occupyDetails$2 !== void 0 ? _occupyDetails$2 : null;
3362
+ resourceSelectType = ((_this$store$resource4 = this.store.resource) === null || _this$store$resource4 === void 0 ? void 0 : _this$store$resource4.resourceSelectType) || this.resolveResourceSelectType(toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id));
3363
+ allowAddItems = toBoolean((_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 || (_this$otherParams18 = _this$otherParams18.dineInConfig) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18['sale.allow_add_items']);
3364
+ result = this.resolveAdditionalOrderFromOccupyDetail(occupyDetail, resourceSelectType, allowAddItems);
3365
+ if (!(!result.matched || !result.order_id)) {
3366
+ _context43.next = 17;
3367
+ break;
3368
+ }
3369
+ this.logMethodSuccess('syncAdditionalOrderFromResource', _objectSpread(_objectSpread({}, result), {}, {
3370
+ resourceId: normalizedResourceId,
3371
+ resourceSelectType: resourceSelectType,
3372
+ allowAddItems: allowAddItems
3373
+ }));
3374
+ return _context43.abrupt("return", result);
3375
+ case 17:
3376
+ tempOrder.order_id = result.order_id;
3377
+ tempOrder.resource_id = normalizedResourceId;
3378
+ tempOrder.relation_id = toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_record_id) || normalizedResourceId || tempOrder.relation_id;
3379
+ tempOrder.table_form_id = toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id) || tempOrder.table_form_id;
3380
+ (_this$store$order9 = this.store.order) === null || _this$store$order9 === void 0 || _this$store$order9.persistTempOrder();
3381
+ this.logMethodSuccess('syncAdditionalOrderFromResource', _objectSpread(_objectSpread({}, result), {}, {
3382
+ resourceId: normalizedResourceId,
3383
+ resourceSelectType: resourceSelectType,
3384
+ allowAddItems: allowAddItems
3385
+ }));
3386
+ return _context43.abrupt("return", result);
3387
+ case 24:
3388
+ case "end":
3389
+ return _context43.stop();
3390
+ }
3391
+ }, _callee43, this);
3392
+ }));
3393
+ function syncAdditionalOrderFromResource(_x22) {
3394
+ return _syncAdditionalOrderFromResource.apply(this, arguments);
3395
+ }
3396
+ return syncAdditionalOrderFromResource;
3397
+ }() // 读取预约规则商品的资源选择类型:single=单个预约,multiple=多个预约,capacity=容量型预约
3398
+ // 依赖 checkResourceAvailable 已根据预约规则商品与 occupy-detail 的 form_id 计算并缓存 store.resource
3399
+ }, {
3400
+ key: "getReservationResourceSelectType",
3401
+ value: function getReservationResourceSelectType() {
3402
+ var _this$store$resource5;
3403
+ this.logMethodStart('getReservationResourceSelectType');
3404
+ var resourceSelectType = (_this$store$resource5 = this.store.resource) === null || _this$store$resource5 === void 0 ? void 0 : _this$store$resource5.resourceSelectType;
3405
+ var result = _objectSpread(_objectSpread({}, resourceSelectType ? {
3406
+ resourceSelectType: resourceSelectType
3407
+ } : {}), {}, {
3408
+ isSingleReservation: resourceSelectType === 'single',
3409
+ isMultipleReservation: resourceSelectType === 'multiple',
3410
+ isCapacityReservation: resourceSelectType === 'capacity'
3411
+ });
3412
+ this.logMethodSuccess('getReservationResourceSelectType', result);
3413
+ return result;
3414
+ }
3415
+
3416
+ // 判定后台是否开启允许加餐
3417
+ // 依赖 checkResourceAvailable 已缓存的 dineInConfig
3418
+ }, {
3419
+ key: "checkAllowAddItems",
3420
+ value: function checkAllowAddItems() {
3421
+ var _this$otherParams19;
3422
+ this.logMethodStart('checkAllowAddItems');
3423
+ var dineInConfig = ((_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.dineInConfig) || {};
3424
+ var result = {
3425
+ enabled: toBoolean(dineInConfig['sale.allow_add_items'])
3426
+ };
3427
+ this.logMethodSuccess('checkAllowAddItems', result);
3428
+ return result;
3429
+ }
3430
+
3431
+ // 读取取餐/送餐开关
3432
+ // 依赖 checkResourceAvailable 已缓存的 dineInConfig
3433
+ }, {
3434
+ key: "getFulfillmentModes",
3435
+ value: function getFulfillmentModes() {
3436
+ var _this$otherParams20;
3437
+ this.logMethodStart('getFulfillmentModes');
3438
+ var dineInConfig = ((_this$otherParams20 = this.otherParams) === null || _this$otherParams20 === void 0 ? void 0 : _this$otherParams20.dineInConfig) || {};
3439
+ var result = {
3440
+ enablePickup: Boolean(dineInConfig['fulfillment.enable_pickup']),
3441
+ enableTableService: Boolean(dineInConfig['fulfillment.enable_table_service'])
3442
+ };
3443
+ this.logMethodSuccess('getFulfillmentModes', result);
3444
+ return result;
3445
+ }
3446
+
3447
+ // 判定后台是否开启客户自定义取餐标识
3448
+ // 依赖 checkResourceAvailable 已缓存的 dineInConfig
3449
+ }, {
3450
+ key: "checkManualPickupRef",
3451
+ value: function checkManualPickupRef() {
3452
+ var _this$otherParams21;
3453
+ this.logMethodStart('checkManualPickupRef');
3454
+ var dineInConfig = ((_this$otherParams21 = this.otherParams) === null || _this$otherParams21 === void 0 ? void 0 : _this$otherParams21.dineInConfig) || {};
3455
+ var refMode = dineInConfig['fulfillment.fulfillment_ref_mode'];
3456
+ var manualInputType = dineInConfig['fulfillment.manual_input_type'];
3457
+ var enabled = refMode === 'manual_input';
3458
+ var result = enabled ? {
3459
+ enabled: true,
3460
+ manualInputType: manualInputType
3461
+ } : {
3462
+ enabled: false
3463
+ };
3464
+ this.logMethodSuccess('checkManualPickupRef', {
3465
+ enabled: enabled,
3466
+ manualInputType: enabled ? manualInputType : undefined
3467
+ });
3468
+ return result;
3469
+ }
3470
+ }]);
3471
+ return ScanOrderImpl;
3472
+ }(BaseModule);
3473
+ _defineProperty(ScanOrderImpl, "PISELL1_LOGIN_SUCCESS", 'pisell1.login.success');
3474
+ _defineProperty(ScanOrderImpl, "UI_STATE_KEY_PREFIX", 'pisell.scanOrder.uiState:');