@pisell/pisellos 0.10.43 → 0.10.45

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 (118) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +135 -35
  3. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  4. package/dist/model/strategy/adapter/itemRule/evaluator.js +25 -1
  5. package/dist/model/strategy/adapter/itemRule/type.d.ts +44 -0
  6. package/dist/model/strategy/adapter/itemRule/type.js +19 -1
  7. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  8. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  9. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  10. package/dist/modules/Customer/index.js +2 -1
  11. package/dist/modules/Discount/availability.d.ts +7 -0
  12. package/dist/modules/Discount/availability.js +49 -0
  13. package/dist/modules/Discount/index.d.ts +1 -3
  14. package/dist/modules/Discount/index.js +12 -151
  15. package/dist/modules/Discount/types.d.ts +6 -0
  16. package/dist/modules/Order/index.d.ts +41 -9
  17. package/dist/modules/Order/index.js +1457 -872
  18. package/dist/modules/Order/salesNotes.d.ts +31 -0
  19. package/dist/modules/Order/salesNotes.js +492 -0
  20. package/dist/modules/Order/types.d.ts +105 -8
  21. package/dist/modules/Order/types.js +6 -1
  22. package/dist/modules/Order/utils.d.ts +4 -2
  23. package/dist/modules/Order/utils.js +224 -79
  24. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
  25. package/dist/modules/Payment/cashRecommendationAlgorithm.js +17 -367
  26. package/dist/modules/Product/index.d.ts +1 -1
  27. package/dist/modules/ProductList/index.d.ts +2 -1
  28. package/dist/modules/ProductList/index.js +100 -20
  29. package/dist/modules/ProductList/types.d.ts +10 -0
  30. package/dist/modules/Rules/index.js +50 -16
  31. package/dist/server/index.d.ts +7 -0
  32. package/dist/server/index.js +45 -3
  33. package/dist/server/modules/order/index.js +6 -0
  34. package/dist/server/modules/order/types.d.ts +9 -0
  35. package/dist/server/utils/small-ticket.d.ts +1 -0
  36. package/dist/server/utils/small-ticket.js +142 -14
  37. package/dist/solution/BaseSales/index.d.ts +15 -1
  38. package/dist/solution/BaseSales/index.js +1240 -877
  39. package/dist/solution/BaseSales/types.d.ts +2 -2
  40. package/dist/solution/BookingByStep/index.d.ts +1 -1
  41. package/dist/solution/BookingTicket/index.d.ts +1 -0
  42. package/dist/solution/BookingTicket/index.js +37 -16
  43. package/dist/solution/BookingTicket/utils/orderCustomer.js +3 -2
  44. package/dist/solution/RegisterAndLogin/config.d.ts +9 -3
  45. package/dist/solution/RegisterAndLogin/config.js +95 -40
  46. package/dist/solution/RegisterAndLogin/index.js +4 -1
  47. package/dist/solution/ScanOrder/index.d.ts +1 -0
  48. package/dist/solution/ScanOrder/index.js +31 -27
  49. package/dist/solution/ScanOrder/utils.d.ts +1 -0
  50. package/dist/solution/ScanOrder/utils.js +2 -0
  51. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  52. package/dist/solution/ShopDiscount/index.js +59 -22
  53. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  54. package/dist/solution/ShopDiscount/utils.js +40 -21
  55. package/dist/solution/UnifiedBookingSales/index.d.ts +15 -2
  56. package/dist/solution/UnifiedBookingSales/index.js +777 -510
  57. package/dist/solution/UnifiedBookingSales/types.d.ts +14 -1
  58. package/dist/solution/VenueBooking/index.d.ts +1 -0
  59. package/dist/solution/VenueBooking/index.js +8 -4
  60. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  61. package/lib/model/strategy/adapter/itemRule/adapter.js +73 -4
  62. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  63. package/lib/model/strategy/adapter/itemRule/evaluator.js +23 -1
  64. package/lib/model/strategy/adapter/itemRule/type.d.ts +44 -0
  65. package/lib/model/strategy/adapter/itemRule/type.js +19 -1
  66. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  67. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  68. package/lib/modules/Customer/index.js +1 -0
  69. package/lib/modules/Discount/availability.d.ts +7 -0
  70. package/lib/modules/Discount/availability.js +43 -0
  71. package/lib/modules/Discount/index.d.ts +1 -3
  72. package/lib/modules/Discount/index.js +10 -131
  73. package/lib/modules/Discount/types.d.ts +6 -0
  74. package/lib/modules/Order/index.d.ts +41 -9
  75. package/lib/modules/Order/index.js +456 -69
  76. package/lib/modules/Order/salesNotes.d.ts +31 -0
  77. package/lib/modules/Order/salesNotes.js +382 -0
  78. package/lib/modules/Order/types.d.ts +105 -8
  79. package/lib/modules/Order/types.js +5 -1
  80. package/lib/modules/Order/utils.d.ts +4 -2
  81. package/lib/modules/Order/utils.js +134 -3
  82. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
  83. package/lib/modules/Payment/cashRecommendationAlgorithm.js +9 -354
  84. package/lib/modules/Product/index.d.ts +1 -1
  85. package/lib/modules/ProductList/index.d.ts +2 -1
  86. package/lib/modules/ProductList/index.js +47 -2
  87. package/lib/modules/ProductList/types.d.ts +10 -0
  88. package/lib/modules/Rules/index.js +42 -5
  89. package/lib/server/index.d.ts +7 -0
  90. package/lib/server/index.js +39 -3
  91. package/lib/server/modules/order/index.js +6 -0
  92. package/lib/server/modules/order/types.d.ts +9 -0
  93. package/lib/server/utils/small-ticket.d.ts +1 -0
  94. package/lib/server/utils/small-ticket.js +136 -12
  95. package/lib/solution/BaseSales/index.d.ts +15 -1
  96. package/lib/solution/BaseSales/index.js +192 -22
  97. package/lib/solution/BaseSales/types.d.ts +2 -2
  98. package/lib/solution/BookingByStep/index.d.ts +1 -1
  99. package/lib/solution/BookingTicket/index.d.ts +1 -0
  100. package/lib/solution/BookingTicket/index.js +23 -5
  101. package/lib/solution/BookingTicket/utils/orderCustomer.js +2 -1
  102. package/lib/solution/RegisterAndLogin/config.d.ts +9 -3
  103. package/lib/solution/RegisterAndLogin/config.js +49 -8
  104. package/lib/solution/RegisterAndLogin/index.js +4 -1
  105. package/lib/solution/ScanOrder/index.d.ts +1 -0
  106. package/lib/solution/ScanOrder/index.js +5 -1
  107. package/lib/solution/ScanOrder/utils.d.ts +1 -0
  108. package/lib/solution/ScanOrder/utils.js +1 -0
  109. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  110. package/lib/solution/ShopDiscount/index.js +29 -3
  111. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  112. package/lib/solution/ShopDiscount/utils.js +39 -23
  113. package/lib/solution/UnifiedBookingSales/index.d.ts +15 -2
  114. package/lib/solution/UnifiedBookingSales/index.js +125 -1
  115. package/lib/solution/UnifiedBookingSales/types.d.ts +14 -1
  116. package/lib/solution/VenueBooking/index.d.ts +1 -0
  117. package/lib/solution/VenueBooking/index.js +5 -1
  118. package/package.json +1 -1
@@ -32,10 +32,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
32
32
  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); }
33
33
  import { BaseModule } from "../BaseModule";
34
34
  import { OrderHooks } from "./types";
35
- import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeOrderMetaList, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, buildPointCardSnapshotFromWalletPassList, mergeOrderProductDisplayFields, resolveIsFormSubject, isMarkdownBundle } from "./utils";
35
+ import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeOrderMetaList, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, buildPointCardSnapshotFromWalletPassList, buildVirtualCurrencySnapshotFromList, mergeOrderProductDisplayFields, resolveIsFormSubject, isMarkdownBundle } from "./utils";
36
36
  import { isNormalProduct } from "../Product/utils";
37
37
  import dayjs from 'dayjs';
38
+ import { getDiscountLifecycleReason } from "../Discount/availability";
38
39
  import { stripOsPrivatePayloadFields } from "../../utils/os-private-payload";
40
+ import { buildSalesNoteText, decodeSalesNotesSnapshot, getSalesNotePolicy } from "./salesNotes";
39
41
  import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
40
42
  import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
41
43
  import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid, PRODUCT_LINE_MERGE_DISABLED_METADATA_KEY } from "../../solution/BaseSales/utils/cartPromotion";
@@ -166,6 +168,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
166
168
  _defineProperty(_assertThisInitialized(_this), "openCache", false);
167
169
  _defineProperty(_assertThisInitialized(_this), "sessionStoragePersistEnabled", false);
168
170
  _defineProperty(_assertThisInitialized(_this), "sessionStorageRestoreRecord", null);
171
+ /** 只允许当前订单最新的 prepare/config 请求回写客户资产态。 */
172
+ _defineProperty(_assertThisInitialized(_this), "customerWalletPrepareConfigEpoch", 0);
169
173
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
170
174
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
171
175
  _defineProperty(_assertThisInitialized(_this), "moduleHooksOverride", void 0);
@@ -176,8 +180,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
176
180
  _defineProperty(_assertThisInitialized(_this), "promotionEvaluator", null);
177
181
  /** 赠品选择 resolver;由 SDK host bridge 注入 */
178
182
  _defineProperty(_assertThisInitialized(_this), "giftSelectResolver", null);
179
- /** applyPromotion 递归保护 flag(写路径同步调 applyPromotion,禁止重入) */
183
+ /** 促销评估递归保护 flag(写路径同步评估促销,禁止重入) */
180
184
  _defineProperty(_assertThisInitialized(_this), "isApplyingPromotion", false);
185
+ /** 保持旧事件语义:同步事件监听器内触发的订单写入不得递归评估促销。 */
186
+ _defineProperty(_assertThisInitialized(_this), "isEmittingPromotionApplied", false);
181
187
  /** 商品曾应用过客户券卡,客户变更剥离后需强制跑一次 calcDiscount 复位价格 */
182
188
  _defineProperty(_assertThisInitialized(_this), "hasActiveCustomerBoundDiscount", false);
183
189
  /** 最近一次 applyPromotion 的未满足促销提示 */
@@ -592,7 +598,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
592
598
  }, {
593
599
  key: "createDefaultRulesHooks",
594
600
  value: function createDefaultRulesHooks() {
595
- return createDefaultOrderRulesHooks();
601
+ var _this2 = this;
602
+ return createDefaultOrderRulesHooks(function () {
603
+ var _this2$store$tempOrde;
604
+ return ((_this2$store$tempOrde = _this2.store.tempOrder) === null || _this2$store$tempOrde === void 0 ? void 0 : _this2$store$tempOrde.bookings) || [];
605
+ });
606
+ }
607
+
608
+ /**
609
+ * Stable across notifyTempOrderChanged's immutable copy, but changes when a
610
+ * different local/server order becomes current.
611
+ */
612
+ }, {
613
+ key: "getDiscountConfigOrderIdentityKey",
614
+ value: function getDiscountConfigOrderIdentityKey(tempOrder) {
615
+ var _ref12, _identity$orderId, _tempOrder$request_un, _ref13, _identity$externalSal, _ref14, _ref15, _identity$localId, _tempOrder$_extend;
616
+ var identity = this.getOrderIdentity();
617
+ return JSON.stringify([(_ref12 = (_identity$orderId = identity === null || identity === void 0 ? void 0 : identity.orderId) !== null && _identity$orderId !== void 0 ? _identity$orderId : tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.order_id) !== null && _ref12 !== void 0 ? _ref12 : '', (_tempOrder$request_un = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.request_unique_idempotency_token) !== null && _tempOrder$request_un !== void 0 ? _tempOrder$request_un : '', (_ref13 = (_identity$externalSal = identity === null || identity === void 0 ? void 0 : identity.externalSaleNumber) !== null && _identity$externalSal !== void 0 ? _identity$externalSal : tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.external_sale_number) !== null && _ref13 !== void 0 ? _ref13 : '', (_ref14 = (_ref15 = (_identity$localId = identity === null || identity === void 0 ? void 0 : identity.localId) !== null && _identity$localId !== void 0 ? _identity$localId : tempOrder === null || tempOrder === void 0 || (_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.localId) !== null && _ref15 !== void 0 ? _ref15 : this.cacheId) !== null && _ref14 !== void 0 ? _ref14 : '']);
596
618
  }
597
619
 
598
620
  // ─── Discount: 公共 API ───
@@ -600,13 +622,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
600
622
  key: "loadDiscountConfig",
601
623
  value: function () {
602
624
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
603
- var _this$store$tempOrder, _this$store$discount, _this$store$tempOrder2;
604
- var orderId, prepareConfigResult, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentDiscountList, currentCommittedDiscounts, currentScanDiscounts, currentScanDiscountById, committedDiscountById, mergedCommittedDiscountIds, refreshedScanDiscountIds, runtimeDiscountIds, runtimeDiscounts, retainedCommittedDiscounts, retainedScanDiscounts, mergedDiscountList;
625
+ var _this$store$tempOrder,
626
+ _this$store$discount,
627
+ _this3 = this,
628
+ _this$store$tempOrder2;
629
+ var orderId, requestEpoch, requestOrderIdentityKey, prepareConfigResult, isCurrentRequest, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentDiscountList, currentCommittedDiscounts, currentScanDiscounts, currentScanDiscountById, committedDiscountById, mergedCommittedDiscountIds, refreshedScanDiscountIds, runtimeDiscountIds, runtimeDiscounts, retainedCommittedDiscounts, retainedScanDiscounts, mergedDiscountList;
605
630
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
606
631
  while (1) switch (_context3.prev = _context3.next) {
607
632
  case 0:
608
633
  orderId = params.orderId || ((_this$store$tempOrder = this.store.tempOrder) === null || _this$store$tempOrder === void 0 ? void 0 : _this$store$tempOrder.order_id) || undefined;
609
- _context3.next = 3;
634
+ requestEpoch = ++this.customerWalletPrepareConfigEpoch;
635
+ requestOrderIdentityKey = this.getDiscountConfigOrderIdentityKey(this.store.tempOrder);
636
+ _context3.next = 5;
610
637
  return (_this$store$discount = this.store.discount) === null || _this$store$discount === void 0 ? void 0 : _this$store$discount.loadPrepareConfig(_objectSpread({
611
638
  customer_id: params.customerId,
612
639
  action: params.action || (orderId ? 'edit' : 'create'),
@@ -617,23 +644,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
617
644
  with_available_wallet_pass_flag: 1,
618
645
  with_virtual_currency: 1,
619
646
  with_entitlement_pass: 1,
647
+ filter_order_wallet_pass_usage: 0,
620
648
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
621
649
  }, orderId ? {
622
650
  order_id: orderId
623
651
  } : {}));
624
- case 3:
652
+ case 5:
625
653
  prepareConfigResult = _context3.sent;
654
+ isCurrentRequest = function isCurrentRequest() {
655
+ var _this3$store$tempOrde, _this3$store$tempOrde2;
656
+ return requestEpoch === _this3.customerWalletPrepareConfigEpoch && _this3.getDiscountConfigOrderIdentityKey(_this3.store.tempOrder) === requestOrderIdentityKey && String((_this3$store$tempOrde = (_this3$store$tempOrde2 = _this3.store.tempOrder) === null || _this3$store$tempOrde2 === void 0 ? void 0 : _this3$store$tempOrde2.customer_id) !== null && _this3$store$tempOrde !== void 0 ? _this3$store$tempOrde : '') === String(params.customerId);
657
+ };
658
+ if (isCurrentRequest()) {
659
+ _context3.next = 9;
660
+ break;
661
+ }
662
+ return _context3.abrupt("return", this.getDiscountList());
663
+ case 9:
626
664
  discountList = prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.discountList;
627
- this.store.availableWalletIds = (prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.availableWalletIds) || [];
628
- this.store.virtualCurrencyList = (prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.virtualCurrencyList) || [];
629
665
  if (prepareConfigResult) {
630
- this.writePointCardSnapshotFromPrepareConfig({
666
+ this.writeCustomerWalletSnapshotsFromPrepareConfig({
631
667
  customerId: params.customerId,
632
- availableWalletPassList: prepareConfigResult.availableWalletPassList || []
668
+ availableWalletIds: prepareConfigResult.availableWalletIds || [],
669
+ availableWalletPassList: prepareConfigResult.availableWalletPassList || [],
670
+ virtualCurrencyList: prepareConfigResult.virtualCurrencyList || []
633
671
  });
634
672
  }
635
673
  if (!discountList) {
636
- _context3.next = 25;
674
+ _context3.next = 32;
637
675
  break;
638
676
  }
639
677
  currentDiscountList = ((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || [];
@@ -699,17 +737,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
699
737
  return id === null || !refreshedScanDiscountIds.has(id);
700
738
  });
701
739
  mergedDiscountList = [].concat(_toConsumableArray(retainedCommittedDiscounts), _toConsumableArray(retainedScanDiscounts), _toConsumableArray(runtimeDiscounts));
702
- _context3.next = 23;
740
+ if (isCurrentRequest()) {
741
+ _context3.next = 26;
742
+ break;
743
+ }
744
+ return _context3.abrupt("return", this.getDiscountList());
745
+ case 26:
746
+ _context3.next = 28;
703
747
  return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
704
- case 23:
705
- _context3.next = 25;
748
+ case 28:
749
+ if (isCurrentRequest()) {
750
+ _context3.next = 30;
751
+ break;
752
+ }
753
+ return _context3.abrupt("return", this.getDiscountList());
754
+ case 30:
755
+ _context3.next = 32;
706
756
  return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
707
- case 25:
757
+ case 32:
758
+ if (isCurrentRequest()) {
759
+ _context3.next = 34;
760
+ break;
761
+ }
762
+ return _context3.abrupt("return", this.getDiscountList());
763
+ case 34:
708
764
  if (params.apply !== false && (_this$store$tempOrder2 = this.store.tempOrder) !== null && _this$store$tempOrder2 !== void 0 && (_this$store$tempOrder2 = _this$store$tempOrder2.products) !== null && _this$store$tempOrder2 !== void 0 && _this$store$tempOrder2.length) {
709
765
  this.applyDiscount();
710
766
  }
711
767
  return _context3.abrupt("return", this.getDiscountList());
712
- case 27:
768
+ case 36:
713
769
  case "end":
714
770
  return _context3.stop();
715
771
  }
@@ -736,6 +792,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
736
792
  value: function getVirtualCurrencyList() {
737
793
  return cloneDeep(this.store.virtualCurrencyList || []);
738
794
  }
795
+ }, {
796
+ key: "getCustomerWalletPrepareConfigEpoch",
797
+ value: function getCustomerWalletPrepareConfigEpoch() {
798
+ return this.customerWalletPrepareConfigEpoch;
799
+ }
739
800
  }, {
740
801
  key: "syncScannedDiscountsToOriginalDiscountList",
741
802
  value: function () {
@@ -778,13 +839,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
778
839
  key: "ensureEditDiscountConfigForProductChange",
779
840
  value: function () {
780
841
  var _ensureEditDiscountConfigForProductChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(tempOrder) {
781
- var _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _this$store$discount10;
842
+ var _tempOrder$customer, _tempOrder$_extend2, _tempOrder$_extend3, _this$store$discount10;
782
843
  var orderId, customerId, currentDiscountList, hasRuntimeDiscounts;
783
844
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
784
845
  while (1) switch (_context5.prev = _context5.next) {
785
846
  case 0:
786
847
  orderId = tempOrder.order_id;
787
- customerId = Number(tempOrder.customer_id || ((_tempOrder$customer = tempOrder.customer) === null || _tempOrder$customer === void 0 ? void 0 : _tempOrder$customer.id) || ((_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend.customerSnapshot) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.id) || ((_tempOrder$_extend2 = tempOrder._extend) === null || _tempOrder$_extend2 === void 0 || (_tempOrder$_extend2 = _tempOrder$_extend2.customerSnapshot) === null || _tempOrder$_extend2 === void 0 ? void 0 : _tempOrder$_extend2.customer_id) || 0);
848
+ customerId = Number(tempOrder.customer_id || ((_tempOrder$customer = tempOrder.customer) === null || _tempOrder$customer === void 0 ? void 0 : _tempOrder$customer.id) || ((_tempOrder$_extend2 = tempOrder._extend) === null || _tempOrder$_extend2 === void 0 || (_tempOrder$_extend2 = _tempOrder$_extend2.customerSnapshot) === null || _tempOrder$_extend2 === void 0 ? void 0 : _tempOrder$_extend2.id) || ((_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3.customerSnapshot) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.customer_id) || 0);
788
849
  if (!(!orderId || !customerId || customerId === 1)) {
789
850
  _context5.next = 4;
790
851
  break;
@@ -824,7 +885,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
824
885
  value: function () {
825
886
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
826
887
  var _this$store$discount11, _tempOrder$holder, _this$store$summary;
827
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref12, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, shouldRetainForLater, normalizedNewDiscountList, retainedDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13;
888
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref16, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, scannedIds, evaluatedScannedDiscounts, shouldRetainForLater, normalizedNewDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13, retainedDiscounts;
828
889
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
829
890
  while (1) switch (_context6.prev = _context6.next) {
830
891
  case 0:
@@ -914,7 +975,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
914
975
  case 20:
915
976
  tempOrder = this.store.tempOrder;
916
977
  holders = (tempOrder === null || tempOrder === void 0 || (_tempOrder$holder = tempOrder.holder) === null || _tempOrder$holder === void 0 ? void 0 : _tempOrder$holder.form_record) || [];
917
- _ref12 = rulesModule.isDiscountListAvailable({
978
+ _ref16 = rulesModule.isDiscountListAvailable({
918
979
  productList: (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.products) || [],
919
980
  oldDiscountList: this.getDiscountList(),
920
981
  newDiscountList: withScanList,
@@ -926,47 +987,66 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
926
987
  }) || {
927
988
  isAvailable: false,
928
989
  discountList: this.getDiscountList()
929
- }, isAvailable = _ref12.isAvailable, newDiscountList = _ref12.discountList, evaluatedDiscountList = _ref12.evaluatedDiscountList, unavailableReason = _ref12.unavailableReason;
930
- shouldRetainForLater = !isAvailable && unavailableReason === UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
990
+ }, isAvailable = _ref16.isAvailable, newDiscountList = _ref16.discountList, evaluatedDiscountList = _ref16.evaluatedDiscountList, unavailableReason = _ref16.unavailableReason;
991
+ scannedIds = new Set(withScanList.map(function (discount) {
992
+ return String(discount.id);
993
+ }));
994
+ evaluatedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(function (discount) {
995
+ return scannedIds.has(String(discount.id)) && isCustomerPromotionDiscount(discount) && !getDiscountLifecycleReason(discount);
996
+ });
997
+ shouldRetainForLater = !isAvailable && evaluatedScannedDiscounts.length > 0;
931
998
  normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
932
- retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
933
999
  resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
934
1000
  if (!(isAvailable && normalizedNewDiscountList)) {
935
- _context6.next = 36;
1001
+ _context6.next = 37;
936
1002
  break;
937
1003
  }
938
- _context6.next = 30;
1004
+ _context6.next = 31;
939
1005
  return (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList(normalizedNewDiscountList);
940
- case 30:
1006
+ case 31:
941
1007
  this.applyDiscount();
942
- _context6.next = 33;
1008
+ _context6.next = 34;
943
1009
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
944
- case 33:
1010
+ case 34:
945
1011
  resolvedDiscountList = this.getDiscountList();
946
- _context6.next = 42;
1012
+ _context6.next = 45;
947
1013
  break;
948
- case 36:
949
- if (!(shouldRetainForLater && retainedDiscountList)) {
950
- _context6.next = 42;
1014
+ case 37:
1015
+ if (!shouldRetainForLater) {
1016
+ _context6.next = 45;
951
1017
  break;
952
1018
  }
953
- _context6.next = 39;
954
- return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
955
- case 39:
956
- _context6.next = 41;
1019
+ // 只合并本次识别的卡券;不把试算产生的其他选券状态写回订单。
1020
+ retainedDiscounts = new Map(this.getDiscountList().map(function (discount) {
1021
+ return [String(discount.id), discount];
1022
+ }));
1023
+ evaluatedScannedDiscounts.forEach(function (discount) {
1024
+ retainedDiscounts.set(String(discount.id), _objectSpread(_objectSpread({}, discount), {}, {
1025
+ isScan: true,
1026
+ isAvailable: false,
1027
+ isSelected: false,
1028
+ reasonCode: discount.reasonCode || 'product_not_applicable',
1029
+ appliedProductDetails: [],
1030
+ savedAmount: 0
1031
+ }));
1032
+ });
1033
+ _context6.next = 42;
1034
+ return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(_toConsumableArray(retainedDiscounts.values()));
1035
+ case 42:
1036
+ _context6.next = 44;
957
1037
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
958
- case 41:
1038
+ case 44:
959
1039
  resolvedDiscountList = this.getDiscountList();
960
- case 42:
1040
+ case 45:
961
1041
  return _context6.abrupt("return", {
962
1042
  type: 'clientCalc',
963
1043
  isAvailable: isAvailable || false,
964
1044
  isAccepted: Boolean(isAvailable || shouldRetainForLater),
965
1045
  discountList: resolvedDiscountList,
966
- scannedDiscountList: resultDiscountList,
1046
+ scannedDiscountList: evaluatedScannedDiscounts,
967
1047
  unavailableReason: unavailableReason
968
1048
  });
969
- case 43:
1049
+ case 46:
970
1050
  case "end":
971
1051
  return _context6.stop();
972
1052
  }
@@ -982,7 +1062,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
982
1062
  value: function applyDiscount(options) {
983
1063
  var _this$store$discount16,
984
1064
  _this$store$summary2,
985
- _this2 = this;
1065
+ _this4 = this;
986
1066
  var tempOrder = this.store.tempOrder;
987
1067
  // 任意 products CRUD 后都应当重算 discount 状态;即使 products 为空,
988
1068
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
@@ -1018,9 +1098,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1018
1098
  if (result !== null && result !== void 0 && result.productList) {
1019
1099
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
1020
1100
  tempOrder.products = this.applyProductDiscountPrices((result.productList || []).map(function (product, index) {
1021
- var _ref13;
1101
+ var _ref17;
1022
1102
  var uid = getOrderProductLineUid(product);
1023
- var previous = (_ref13 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref13 !== void 0 ? _ref13 : previousProductsByUid.get("__index__:".concat(index));
1103
+ var previous = (_ref17 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref17 !== void 0 ? _ref17 : previousProductsByUid.get("__index__:".concat(index));
1024
1104
  if (isManualProductDiscountProduct(previous)) {
1025
1105
  return previous;
1026
1106
  }
@@ -1038,7 +1118,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1038
1118
  (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 || _this$store$discount17.setDiscountList(result.discountList);
1039
1119
  }
1040
1120
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
1041
- return _this2.productHasCustomerBoundDiscount(product);
1121
+ return _this4.productHasCustomerBoundDiscount(product);
1042
1122
  });
1043
1123
  }
1044
1124
 
@@ -1084,7 +1164,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1084
1164
  }
1085
1165
 
1086
1166
  /**
1087
- * 应用购物车促销:计算 → 差异化赠品 → 写回 tempOrder.products → emit onPromotionApplied。
1167
+ * 只执行购物车促销评估与赠品写回,不发布稳定态事件。
1088
1168
  *
1089
1169
  * 调用时机:写路径(add/update/remove/clear/setCustomer)末尾自动触发;外部一般无需手动调。
1090
1170
  *
@@ -1092,51 +1172,52 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1092
1172
  * - 不调用任何公开 CRUD API(如 removeProductFromOrder),全部内部 mutate tempOrder.products,避免事件风暴;
1093
1173
  * - 用 `isApplyingPromotion` 防递归;
1094
1174
  * - 多选项赠品依赖 giftSelectResolver,未注入则跳过且 console.warn;
1095
- * - 不主动调用 applyDiscount / recalculateSummary,调用方负责跟进。
1175
+ * - 不主动调用 applyDiscount / recalculateSummary,调用方负责跟进;
1176
+ * - 返回的 payload 只能在 applyDiscount(商品写路径还需 summary/persist)完成后发布。
1096
1177
  */
1097
1178
  }, {
1098
- key: "applyPromotion",
1179
+ key: "evaluatePromotion",
1099
1180
  value: (function () {
1100
- var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1181
+ var _evaluatePromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1101
1182
  var _this$promotionEvalua,
1102
1183
  _this$promotionEvalua2,
1103
- _this3 = this;
1184
+ _this5 = this;
1104
1185
  var tempOrder, strategyConfigs, result, removeSet, _iterator3, _step3, reduce, _iterator6, _step6, _loop2, _iterator4, _step4, _loop, payload;
1105
1186
  return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1106
1187
  while (1) switch (_context9.prev = _context9.next) {
1107
1188
  case 0:
1108
- if (!this.isApplyingPromotion) {
1189
+ if (!(this.isApplyingPromotion || this.isEmittingPromotionApplied)) {
1109
1190
  _context9.next = 2;
1110
1191
  break;
1111
1192
  }
1112
- return _context9.abrupt("return");
1193
+ return _context9.abrupt("return", null);
1113
1194
  case 2:
1114
1195
  if (this.promotionEvaluator) {
1115
1196
  _context9.next = 4;
1116
1197
  break;
1117
1198
  }
1118
- return _context9.abrupt("return");
1199
+ return _context9.abrupt("return", null);
1119
1200
  case 4:
1120
1201
  tempOrder = this.store.tempOrder;
1121
1202
  if (tempOrder) {
1122
1203
  _context9.next = 7;
1123
1204
  break;
1124
1205
  }
1125
- return _context9.abrupt("return");
1206
+ return _context9.abrupt("return", null);
1126
1207
  case 7:
1127
1208
  if (!this.isActiveVirtualSettlementOrder(tempOrder)) {
1128
1209
  _context9.next = 10;
1129
1210
  break;
1130
1211
  }
1131
1212
  tempOrder.products = normalizeVirtualSettlementProducts(tempOrder.products);
1132
- return _context9.abrupt("return");
1213
+ return _context9.abrupt("return", null);
1133
1214
  case 10:
1134
1215
  strategyConfigs = (_this$promotionEvalua = (_this$promotionEvalua2 = this.promotionEvaluator).getStrategyConfigs) === null || _this$promotionEvalua === void 0 ? void 0 : _this$promotionEvalua.call(_this$promotionEvalua2);
1135
1216
  if (!(Array.isArray(strategyConfigs) && strategyConfigs.length === 0)) {
1136
1217
  _context9.next = 13;
1137
1218
  break;
1138
1219
  }
1139
- return _context9.abrupt("return");
1220
+ return _context9.abrupt("return", null);
1140
1221
  case 13:
1141
1222
  this.isApplyingPromotion = true;
1142
1223
  _context9.prev = 14;
@@ -1259,7 +1340,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1259
1340
  case 6:
1260
1341
  _context7.prev = 6;
1261
1342
  _context7.next = 9;
1262
- return _this3.giftSelectResolver({
1343
+ return _this5.giftSelectResolver({
1263
1344
  strategyId: addAction.strategyId,
1264
1345
  strategyName: addAction.strategyName,
1265
1346
  giftCount: addAction.giftCount,
@@ -1294,7 +1375,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1294
1375
  _context7.next = 26;
1295
1376
  break;
1296
1377
  }
1297
- linked = _this3.createLinkedProductAndBooking({
1378
+ linked = _this5.createLinkedProductAndBooking({
1298
1379
  product: gp,
1299
1380
  booking: booking
1300
1381
  });
@@ -1376,22 +1457,84 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1376
1457
  }),
1377
1458
  products: tempOrder.products
1378
1459
  };
1379
- this.effectsEmit('onPromotionApplied', payload);
1380
- _context9.next = 81;
1381
- break;
1460
+ return _context9.abrupt("return", payload);
1382
1461
  case 78:
1383
1462
  _context9.prev = 78;
1384
1463
  _context9.t5 = _context9["catch"](14);
1385
1464
  console.error('[OrderModule] applyPromotion failed', _context9.t5);
1386
- case 81:
1387
- _context9.prev = 81;
1465
+ return _context9.abrupt("return", null);
1466
+ case 82:
1467
+ _context9.prev = 82;
1388
1468
  this.isApplyingPromotion = false;
1389
- return _context9.finish(81);
1390
- case 84:
1469
+ return _context9.finish(82);
1470
+ case 85:
1391
1471
  case "end":
1392
1472
  return _context9.stop();
1393
1473
  }
1394
- }, _callee7, this, [[14, 78, 81, 84], [18, 42, 45, 48], [23, 32, 35, 38], [54, 65, 68, 71]]);
1474
+ }, _callee7, this, [[14, 78, 82, 85], [18, 42, 45, 48], [23, 32, 35, 38], [54, 65, 68, 71]]);
1475
+ }));
1476
+ function evaluatePromotion() {
1477
+ return _evaluatePromotion.apply(this, arguments);
1478
+ }
1479
+ return evaluatePromotion;
1480
+ }() /** 发布促销稳定态;products 必须读取折扣计算后的当前数组。 */)
1481
+ }, {
1482
+ key: "emitPromotionApplied",
1483
+ value: function emitPromotionApplied(payload) {
1484
+ var _this$store$tempOrder3;
1485
+ if (!payload) return;
1486
+ var products = ((_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.products) || payload.products;
1487
+ this.isEmittingPromotionApplied = true;
1488
+ try {
1489
+ void this.effectsEmit('onPromotionApplied', _objectSpread(_objectSpread({}, payload), {}, {
1490
+ products: products
1491
+ }));
1492
+ } finally {
1493
+ // effectsEmit 同步调用监听器后返回 Promise;保持既有的非阻塞事件行为。
1494
+ this.isEmittingPromotionApplied = false;
1495
+ }
1496
+ }
1497
+
1498
+ /** 公开入口:促销、折扣、summary 与持久化完成后发布稳定态事件。 */
1499
+ }, {
1500
+ key: "applyPromotion",
1501
+ value: (function () {
1502
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1503
+ var payload, tempOrder;
1504
+ return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1505
+ while (1) switch (_context10.prev = _context10.next) {
1506
+ case 0:
1507
+ _context10.next = 2;
1508
+ return this.evaluatePromotion();
1509
+ case 2:
1510
+ payload = _context10.sent;
1511
+ if (payload) {
1512
+ _context10.next = 5;
1513
+ break;
1514
+ }
1515
+ return _context10.abrupt("return");
1516
+ case 5:
1517
+ tempOrder = this.store.tempOrder;
1518
+ if (tempOrder) {
1519
+ _context10.next = 8;
1520
+ break;
1521
+ }
1522
+ return _context10.abrupt("return");
1523
+ case 8:
1524
+ this.applyDiscount();
1525
+ this.sanitizeTempOrderProducts(tempOrder);
1526
+ _context10.next = 12;
1527
+ return this.recalculateSummary({
1528
+ createIfMissing: true
1529
+ });
1530
+ case 12:
1531
+ this.persistTempOrder();
1532
+ this.emitPromotionApplied(payload);
1533
+ case 14:
1534
+ case "end":
1535
+ return _context10.stop();
1536
+ }
1537
+ }, _callee8, this);
1395
1538
  }));
1396
1539
  function applyPromotion() {
1397
1540
  return _applyPromotion.apply(this, arguments);
@@ -1517,6 +1660,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1517
1660
  if (!this.store.tempOrder) return;
1518
1661
  this.store.tempOrder = _objectSpread(_objectSpread({}, this.store.tempOrder), {}, {
1519
1662
  products: _toConsumableArray(this.store.tempOrder.products),
1663
+ notes: _toConsumableArray(this.store.tempOrder.notes || []),
1520
1664
  bookings: this.store.tempOrder.bookings ? _toConsumableArray(this.store.tempOrder.bookings) : []
1521
1665
  });
1522
1666
  this.persistTempOrder();
@@ -1531,12 +1675,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1531
1675
  });
1532
1676
  }
1533
1677
  }, {
1534
- key: "clearTempOrderPointCardSnapshot",
1535
- value: function clearTempOrderPointCardSnapshot(tempOrder) {
1678
+ key: "clearTempOrderCustomerWalletSnapshots",
1679
+ value: function clearTempOrderCustomerWalletSnapshots(tempOrder) {
1536
1680
  var orderMetaList = normalizeOrderMetaList(tempOrder.order_meta_list);
1537
1681
  if (!orderMetaList) return;
1538
1682
  var nextOrderMetaList = _objectSpread({}, orderMetaList);
1539
1683
  delete nextOrderMetaList.point_cards_snapshot;
1684
+ delete nextOrderMetaList.virtual_currency_snapshot;
1540
1685
  if (Object.keys(nextOrderMetaList).length === 0) {
1541
1686
  delete tempOrder.order_meta_list;
1542
1687
  return;
@@ -1544,15 +1689,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1544
1689
  tempOrder.order_meta_list = nextOrderMetaList;
1545
1690
  }
1546
1691
  }, {
1547
- key: "writePointCardSnapshotFromPrepareConfig",
1548
- value: function writePointCardSnapshotFromPrepareConfig(params) {
1692
+ key: "clearCustomerWalletState",
1693
+ value: function clearCustomerWalletState(tempOrder) {
1694
+ this.clearCustomerWalletRuntimeState();
1695
+ this.clearTempOrderCustomerWalletSnapshots(tempOrder);
1696
+ }
1697
+ }, {
1698
+ key: "clearCustomerWalletRuntimeState",
1699
+ value: function clearCustomerWalletRuntimeState() {
1700
+ this.customerWalletPrepareConfigEpoch += 1;
1701
+ this.store.availableWalletIds = [];
1702
+ this.store.virtualCurrencyList = [];
1703
+ }
1704
+ }, {
1705
+ key: "writeCustomerWalletSnapshotsFromPrepareConfig",
1706
+ value: function writeCustomerWalletSnapshotsFromPrepareConfig(params) {
1549
1707
  var _tempOrder$customer_i;
1550
1708
  var tempOrder = this.store.tempOrder;
1551
1709
  if (!tempOrder) return;
1552
1710
  if (String((_tempOrder$customer_i = tempOrder.customer_id) !== null && _tempOrder$customer_i !== void 0 ? _tempOrder$customer_i : '') !== String(params.customerId)) return;
1711
+ var virtualCurrencyList = Array.isArray(params.virtualCurrencyList) ? params.virtualCurrencyList : [];
1553
1712
  tempOrder.order_meta_list = _objectSpread(_objectSpread({}, normalizeOrderMetaList(tempOrder.order_meta_list) || {}), {}, {
1554
- point_cards_snapshot: buildPointCardSnapshotFromWalletPassList(params.availableWalletPassList)
1713
+ point_cards_snapshot: buildPointCardSnapshotFromWalletPassList(params.availableWalletPassList),
1714
+ virtual_currency_snapshot: buildVirtualCurrencySnapshotFromList(virtualCurrencyList)
1555
1715
  });
1716
+ this.store.availableWalletIds = _toConsumableArray(params.availableWalletIds);
1717
+ this.store.virtualCurrencyList = cloneDeep(virtualCurrencyList);
1556
1718
  this.persistTempOrder();
1557
1719
  this.saveDraftInBackground();
1558
1720
  }
@@ -1615,14 +1777,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1615
1777
  }, {
1616
1778
  key: "saveDraft",
1617
1779
  value: function () {
1618
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1619
- return _regeneratorRuntime().wrap(function _callee8$(_context10) {
1620
- while (1) switch (_context10.prev = _context10.next) {
1780
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1781
+ return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1782
+ while (1) switch (_context11.prev = _context11.next) {
1621
1783
  case 0:
1622
1784
  case "end":
1623
- return _context10.stop();
1785
+ return _context11.stop();
1624
1786
  }
1625
- }, _callee8);
1787
+ }, _callee9);
1626
1788
  }));
1627
1789
  function saveDraft() {
1628
1790
  return _saveDraft.apply(this, arguments);
@@ -1637,16 +1799,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1637
1799
  }, {
1638
1800
  key: "hydrateTempOrderFromLocalRecord",
1639
1801
  value: function () {
1640
- var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(record) {
1641
- return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1642
- while (1) switch (_context11.prev = _context11.next) {
1802
+ var _hydrateTempOrderFromLocalRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(record) {
1803
+ return _regeneratorRuntime().wrap(function _callee10$(_context12) {
1804
+ while (1) switch (_context12.prev = _context12.next) {
1643
1805
  case 0:
1644
- return _context11.abrupt("return", this.hydrateTempOrderFromRecord(record));
1806
+ return _context12.abrupt("return", this.hydrateTempOrderFromRecord(record));
1645
1807
  case 1:
1646
1808
  case "end":
1647
- return _context11.stop();
1809
+ return _context12.stop();
1648
1810
  }
1649
- }, _callee9, this);
1811
+ }, _callee10, this);
1650
1812
  }));
1651
1813
  function hydrateTempOrderFromLocalRecord(_x8) {
1652
1814
  return _hydrateTempOrderFromLocalRecord.apply(this, arguments);
@@ -1656,15 +1818,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1656
1818
  }, {
1657
1819
  key: "extractOrderIdFromSubmitResult",
1658
1820
  value: function extractOrderIdFromSubmitResult(result) {
1659
- var _ref14, _ref15, _ref16, _result$data$order_id, _result$data, _result$data2;
1660
- return (_ref14 = (_ref15 = (_ref16 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref16 !== void 0 ? _ref16 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref15 !== void 0 ? _ref15 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref14 !== void 0 ? _ref14 : null;
1821
+ var _ref18, _ref19, _ref20, _result$data$order_id, _result$data, _result$data2;
1822
+ return (_ref18 = (_ref19 = (_ref20 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref20 !== void 0 ? _ref20 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref19 !== void 0 ? _ref19 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref18 !== void 0 ? _ref18 : null;
1661
1823
  }
1662
1824
  }, {
1663
1825
  key: "calculatePaymentEffectiveAmount",
1664
1826
  value: function calculatePaymentEffectiveAmount(payment) {
1665
- var _ref17, _payment$origin_amoun;
1827
+ var _ref21, _payment$origin_amoun;
1666
1828
  var amount = new Decimal(payment.amount || 0);
1667
- var originAmount = new Decimal((_ref17 = (_payment$origin_amoun = payment.origin_amount) !== null && _payment$origin_amoun !== void 0 ? _payment$origin_amoun : payment.amount) !== null && _ref17 !== void 0 ? _ref17 : 0);
1829
+ var originAmount = new Decimal((_ref21 = (_payment$origin_amoun = payment.origin_amount) !== null && _payment$origin_amoun !== void 0 ? _payment$origin_amoun : payment.amount) !== null && _ref21 !== void 0 ? _ref21 : 0);
1668
1830
  var serviceFee = new Decimal(payment.service_fee || 0);
1669
1831
  // TODO: 后端允许 amount 表示顾客实际支付总额后,移除这个兼容分支。
1670
1832
  var effectiveAmount = serviceFee.gt(0) && amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
@@ -1674,23 +1836,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1674
1836
  }, {
1675
1837
  key: "calculatePaymentTotal",
1676
1838
  value: function calculatePaymentTotal(payments) {
1677
- var _this4 = this;
1839
+ var _this6 = this;
1678
1840
  return mapPaymentItemsToOrderPayments(payments, {
1679
1841
  includeVoided: false
1680
1842
  }).reduce(function (sum, payment) {
1681
1843
  if (!isPaidPaymentRecord(payment)) return sum;
1682
- return sum.plus(_this4.calculatePaymentEffectiveAmount(payment));
1844
+ return sum.plus(_this6.calculatePaymentEffectiveAmount(payment));
1683
1845
  }, new Decimal(0));
1684
1846
  }
1685
1847
  }, {
1686
1848
  key: "calculateOrderPaidPaymentTotal",
1687
1849
  value: function calculateOrderPaidPaymentTotal(payments) {
1688
- var _this5 = this;
1850
+ var _this7 = this;
1689
1851
  return mapPaymentItemsToOrderPayments(payments, {
1690
1852
  includeVoided: false
1691
1853
  }).reduce(function (sum, payment) {
1692
1854
  if (!isPaidPaymentRecord(payment)) return sum;
1693
- return sum.plus(_this5.calculatePaymentGapAmount(payment));
1855
+ return sum.plus(_this7.calculatePaymentGapAmount(payment));
1694
1856
  }, new Decimal(0));
1695
1857
  }
1696
1858
  }, {
@@ -1826,13 +1988,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1826
1988
  }, {
1827
1989
  key: "calculateDepositPaidAmount",
1828
1990
  value: function calculateDepositPaidAmount(payments) {
1829
- var _this6 = this;
1991
+ var _this8 = this;
1830
1992
  return (payments || []).reduce(function (sum, payment) {
1831
1993
  var paymentRecord = payment;
1832
1994
  if (!isPaidPaymentRecord(paymentRecord)) return sum;
1833
1995
  var isDepositPayment = paymentRecord.type === 'deposit' || paymentRecord.order_payment_type === 'deposit';
1834
1996
  if (!isDepositPayment) return sum;
1835
- return sum.plus(_this6.calculatePaymentGapAmount(paymentRecord));
1997
+ return sum.plus(_this8.calculatePaymentGapAmount(paymentRecord));
1836
1998
  }, new Decimal(0));
1837
1999
  }
1838
2000
  }, {
@@ -1869,28 +2031,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1869
2031
  }, {
1870
2032
  key: "getPaymentNumberDevicePrefixSync",
1871
2033
  value: function getPaymentNumberDevicePrefixSync() {
1872
- var _this7 = this;
2034
+ var _this9 = this;
1873
2035
  return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1874
- return _this7.getPaymentNumberAppData(key);
2036
+ return _this9.getPaymentNumberAppData(key);
1875
2037
  });
1876
2038
  }
1877
2039
  }, {
1878
2040
  key: "getPaymentNumberDevicePrefixAsync",
1879
2041
  value: function getPaymentNumberDevicePrefixAsync() {
1880
- var _this8 = this;
2042
+ var _this10 = this;
1881
2043
  return resolvePaymentNumberDevicePrefix(function (key) {
1882
- return _this8.getPaymentNumberAppData(key);
2044
+ return _this10.getPaymentNumberAppData(key);
1883
2045
  });
1884
2046
  }
1885
2047
  }, {
1886
2048
  key: "normalizePaymentSource",
1887
2049
  value: function normalizePaymentSource(payment, options) {
1888
- var _ref18, _paymentRecord$origin;
2050
+ var _ref22, _paymentRecord$origin;
1889
2051
  var paymentRecord = payment;
1890
2052
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1891
2053
  var normalized = ensureOrderPaymentNumber(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1892
2054
  metadata: metadata,
1893
- origin_amount: (_ref18 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref18 !== void 0 ? _ref18 : '0.00'
2055
+ origin_amount: (_ref22 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref22 !== void 0 ? _ref22 : '0.00'
1894
2056
  }), (options === null || options === void 0 ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(), createUuidV4);
1895
2057
  if (paymentRecord.status !== undefined) {
1896
2058
  normalized.status = paymentRecord.status;
@@ -2009,16 +2171,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2009
2171
  }, {
2010
2172
  key: "calculatePaidPaymentSummary",
2011
2173
  value: function calculatePaidPaymentSummary(payments) {
2012
- var _this9 = this;
2174
+ var _this11 = this;
2013
2175
  return (payments || []).reduce(function (summary, payment) {
2014
2176
  var paymentRecord = payment;
2015
2177
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
2016
2178
  return {
2017
2179
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
2018
- orderPaidAmount: summary.orderPaidAmount.plus(_this9.calculatePaymentOrderAmount(paymentRecord)),
2019
- gapPaidAmount: summary.gapPaidAmount.plus(_this9.calculatePaymentGapAmount(paymentRecord)),
2020
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this9.calculatePaymentServiceFee(paymentRecord)),
2021
- roundingAmount: summary.roundingAmount.plus(_this9.calculatePaymentRoundingAmount(paymentRecord))
2180
+ orderPaidAmount: summary.orderPaidAmount.plus(_this11.calculatePaymentOrderAmount(paymentRecord)),
2181
+ gapPaidAmount: summary.gapPaidAmount.plus(_this11.calculatePaymentGapAmount(paymentRecord)),
2182
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this11.calculatePaymentServiceFee(paymentRecord)),
2183
+ roundingAmount: summary.roundingAmount.plus(_this11.calculatePaymentRoundingAmount(paymentRecord))
2022
2184
  };
2023
2185
  }, {
2024
2186
  customerPaidAmount: new Decimal(0),
@@ -2225,15 +2387,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2225
2387
  }, {
2226
2388
  key: "normalizeFingerprintValue",
2227
2389
  value: function normalizeFingerprintValue(value) {
2228
- var _this10 = this;
2390
+ var _this12 = this;
2229
2391
  if (Array.isArray(value)) {
2230
2392
  return value.map(function (item) {
2231
- return _this10.normalizeFingerprintValue(item);
2393
+ return _this12.normalizeFingerprintValue(item);
2232
2394
  });
2233
2395
  }
2234
2396
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
2235
2397
  return Object.keys(value).sort().reduce(function (result, key) {
2236
- result[key] = _this10.normalizeFingerprintValue(value[key]);
2398
+ result[key] = _this12.normalizeFingerprintValue(value[key]);
2237
2399
  return result;
2238
2400
  }, {});
2239
2401
  }
@@ -2246,9 +2408,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2246
2408
  _product$payment_pric,
2247
2409
  _sku$code,
2248
2410
  _sku$barcode,
2249
- _ref19,
2411
+ _ref23,
2250
2412
  _sku$variant_id,
2251
- _this11 = this;
2413
+ _this13 = this;
2252
2414
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
2253
2415
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
2254
2416
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -2276,37 +2438,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2276
2438
  product_sku: this.normalizeFingerprintValue({
2277
2439
  code: (_sku$code = sku.code) !== null && _sku$code !== void 0 ? _sku$code : '',
2278
2440
  barcode: (_sku$barcode = sku.barcode) !== null && _sku$barcode !== void 0 ? _sku$barcode : '',
2279
- variant_id: (_ref19 = (_sku$variant_id = sku.variant_id) !== null && _sku$variant_id !== void 0 ? _sku$variant_id : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref19 !== void 0 ? _ref19 : 0,
2441
+ variant_id: (_ref23 = (_sku$variant_id = sku.variant_id) !== null && _sku$variant_id !== void 0 ? _sku$variant_id : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref23 !== void 0 ? _ref23 : 0,
2280
2442
  variant: sku.variant || [],
2281
2443
  option: getProductSkuOptions(product || {}).map(function (option) {
2282
- var _ref20, _option$id, _option$option_group_, _ref21, _option$option_group_2, _option$num, _option$add_price;
2444
+ var _ref24, _option$id, _option$option_group_, _ref25, _option$option_group_2, _option$num, _option$add_price;
2283
2445
  return {
2284
- id: (_ref20 = (_option$id = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id !== void 0 ? _option$id : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref20 !== void 0 ? _ref20 : null,
2446
+ id: (_ref24 = (_option$id = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id !== void 0 ? _option$id : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref24 !== void 0 ? _ref24 : null,
2285
2447
  option_group_id: (_option$option_group_ = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : null,
2286
- option_group_item_id: (_ref21 = (_option$option_group_2 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref21 !== void 0 ? _ref21 : null,
2448
+ option_group_item_id: (_ref25 = (_option$option_group_2 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref25 !== void 0 ? _ref25 : null,
2287
2449
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
2288
- add_price: _this11.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
2450
+ add_price: _this13.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
2289
2451
  };
2290
2452
  })
2291
2453
  }),
2292
2454
  product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
2293
- var _ref22, _ref23, _bundle$bundle_produc, _ref24, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
2455
+ var _ref26, _ref27, _bundle$bundle_produc, _ref28, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
2294
2456
  return {
2295
- bundle_product_id: (_ref22 = (_ref23 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref23 !== void 0 ? _ref23 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref22 !== void 0 ? _ref22 : null,
2296
- bundle_variant_id: (_ref24 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref24 !== void 0 ? _ref24 : 0,
2457
+ bundle_product_id: (_ref26 = (_ref27 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref27 !== void 0 ? _ref27 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref26 !== void 0 ? _ref26 : null,
2458
+ bundle_variant_id: (_ref28 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref28 !== void 0 ? _ref28 : 0,
2297
2459
  num: getSafeProductNum((_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
2298
- price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2299
- bundle_selling_price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2460
+ price: _this13.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2461
+ bundle_selling_price: _this13.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2300
2462
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
2301
2463
  price_type_ext: (_bundle$price_type_ex = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex !== void 0 ? _bundle$price_type_ex : ''
2302
2464
  };
2303
2465
  })),
2304
2466
  discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2305
- var _ref25, _discount$type2, _ref26, _ref27, _discount$discount_id, _discount$discount;
2467
+ var _ref29, _discount$type2, _ref30, _ref31, _discount$discount_id, _discount$discount;
2306
2468
  return {
2307
- type: (_ref25 = (_discount$type2 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type2 !== void 0 ? _discount$type2 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref25 !== void 0 ? _ref25 : '',
2308
- discount_id: (_ref26 = (_ref27 = (_discount$discount_id = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id !== void 0 ? _discount$discount_id : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref27 !== void 0 ? _ref27 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref26 !== void 0 ? _ref26 : null,
2309
- amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2469
+ type: (_ref29 = (_discount$type2 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type2 !== void 0 ? _discount$type2 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref29 !== void 0 ? _ref29 : '',
2470
+ discount_id: (_ref30 = (_ref31 = (_discount$discount_id = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id !== void 0 ? _discount$discount_id : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref31 !== void 0 ? _ref31 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref30 !== void 0 ? _ref30 : null,
2471
+ amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2310
2472
  };
2311
2473
  }))
2312
2474
  };
@@ -2314,9 +2476,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2314
2476
  }, {
2315
2477
  key: "buildOrderProductsFingerprint",
2316
2478
  value: function buildOrderProductsFingerprint(products) {
2317
- var _this12 = this;
2479
+ var _this14 = this;
2318
2480
  var items = (products || []).map(function (product) {
2319
- return _this12.buildProductFingerprintItem(product);
2481
+ return _this14.buildProductFingerprintItem(product);
2320
2482
  });
2321
2483
  items.sort(function (left, right) {
2322
2484
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2329,16 +2491,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2329
2491
  var _product$product_id3,
2330
2492
  _product$product_vari2,
2331
2493
  _product$num2,
2332
- _ref28,
2494
+ _ref32,
2333
2495
  _metadata$unique_iden,
2334
2496
  _metadata$price_overr,
2335
2497
  _metadata$is_manual_d,
2336
2498
  _metadata$product_dis,
2337
2499
  _sku$code2,
2338
2500
  _sku$barcode2,
2339
- _ref29,
2501
+ _ref33,
2340
2502
  _sku$variant_id2,
2341
- _this13 = this;
2503
+ _this15 = this;
2342
2504
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
2343
2505
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
2344
2506
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -2355,7 +2517,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2355
2517
  extension_type: extensionType,
2356
2518
  num: getSafeProductNum((_product$num2 = product === null || product === void 0 ? void 0 : product.num) !== null && _product$num2 !== void 0 ? _product$num2 : product === null || product === void 0 ? void 0 : product.product_quantity),
2357
2519
  metadata: {
2358
- unique_identification_number: (_ref28 = (_metadata$unique_iden = metadata.unique_identification_number) !== null && _metadata$unique_iden !== void 0 ? _metadata$unique_iden : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref28 !== void 0 ? _ref28 : '',
2520
+ unique_identification_number: (_ref32 = (_metadata$unique_iden = metadata.unique_identification_number) !== null && _metadata$unique_iden !== void 0 ? _metadata$unique_iden : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref32 !== void 0 ? _ref32 : '',
2359
2521
  price_override: (_metadata$price_overr = metadata.price_override) !== null && _metadata$price_overr !== void 0 ? _metadata$price_overr : '',
2360
2522
  is_manual_discount: (_metadata$is_manual_d = metadata.is_manual_discount) !== null && _metadata$is_manual_d !== void 0 ? _metadata$is_manual_d : '',
2361
2523
  product_discount_reason: (_metadata$product_dis = metadata.product_discount_reason) !== null && _metadata$product_dis !== void 0 ? _metadata$product_dis : ''
@@ -2363,47 +2525,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2363
2525
  product_sku: this.normalizeFingerprintValue({
2364
2526
  code: (_sku$code2 = sku.code) !== null && _sku$code2 !== void 0 ? _sku$code2 : '',
2365
2527
  barcode: (_sku$barcode2 = sku.barcode) !== null && _sku$barcode2 !== void 0 ? _sku$barcode2 : '',
2366
- variant_id: (_ref29 = (_sku$variant_id2 = sku.variant_id) !== null && _sku$variant_id2 !== void 0 ? _sku$variant_id2 : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref29 !== void 0 ? _ref29 : 0,
2528
+ variant_id: (_ref33 = (_sku$variant_id2 = sku.variant_id) !== null && _sku$variant_id2 !== void 0 ? _sku$variant_id2 : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref33 !== void 0 ? _ref33 : 0,
2367
2529
  variant: sku.variant || [],
2368
2530
  option: getProductSkuOptions(product || {}).map(function (option) {
2369
- var _ref30, _option$id2, _option$option_group_3, _ref31, _option$option_group_4, _option$num2, _option$add_price2;
2531
+ var _ref34, _option$id2, _option$option_group_3, _ref35, _option$option_group_4, _option$num2, _option$add_price2;
2370
2532
  return {
2371
- id: (_ref30 = (_option$id2 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id2 !== void 0 ? _option$id2 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref30 !== void 0 ? _ref30 : null,
2533
+ id: (_ref34 = (_option$id2 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id2 !== void 0 ? _option$id2 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref34 !== void 0 ? _ref34 : null,
2372
2534
  option_group_id: (_option$option_group_3 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_3 !== void 0 ? _option$option_group_3 : null,
2373
- option_group_item_id: (_ref31 = (_option$option_group_4 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_4 !== void 0 ? _option$option_group_4 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref31 !== void 0 ? _ref31 : null,
2535
+ option_group_item_id: (_ref35 = (_option$option_group_4 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_4 !== void 0 ? _option$option_group_4 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref35 !== void 0 ? _ref35 : null,
2374
2536
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
2375
- add_price: _this13.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
2537
+ add_price: _this15.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
2376
2538
  };
2377
2539
  })
2378
2540
  }),
2379
2541
  product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
2380
- var _ref32, _bundle$bundle_id, _ref33, _bundle$bundle_group_, _ref34, _ref35, _bundle$bundle_produc2, _ref36, _bundle$bundle_varian2, _bundle$num2, _bundle$price_type2, _bundle$price_type_ex2;
2542
+ var _ref36, _bundle$bundle_id, _ref37, _bundle$bundle_group_, _ref38, _ref39, _bundle$bundle_produc2, _ref40, _bundle$bundle_varian2, _bundle$num2, _bundle$price_type2, _bundle$price_type_ex2;
2381
2543
  return {
2382
- bundle_id: (_ref32 = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref32 !== void 0 ? _ref32 : null,
2383
- bundle_group_id: (_ref33 = (_bundle$bundle_group_ = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle === null || bundle === void 0 ? void 0 : bundle.group_id) !== null && _ref33 !== void 0 ? _ref33 : null,
2384
- bundle_product_id: (_ref34 = (_ref35 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref35 !== void 0 ? _ref35 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref34 !== void 0 ? _ref34 : null,
2385
- bundle_variant_id: (_ref36 = (_bundle$bundle_varian2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian2 !== void 0 ? _bundle$bundle_varian2 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref36 !== void 0 ? _ref36 : 0,
2544
+ bundle_id: (_ref36 = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref36 !== void 0 ? _ref36 : null,
2545
+ bundle_group_id: (_ref37 = (_bundle$bundle_group_ = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle === null || bundle === void 0 ? void 0 : bundle.group_id) !== null && _ref37 !== void 0 ? _ref37 : null,
2546
+ bundle_product_id: (_ref38 = (_ref39 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref39 !== void 0 ? _ref39 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref38 !== void 0 ? _ref38 : null,
2547
+ bundle_variant_id: (_ref40 = (_bundle$bundle_varian2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian2 !== void 0 ? _bundle$bundle_varian2 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref40 !== void 0 ? _ref40 : 0,
2386
2548
  num: getSafeProductNum((_bundle$num2 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num2 !== void 0 ? _bundle$num2 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
2387
2549
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
2388
2550
  price_type_ext: (_bundle$price_type_ex2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : '',
2389
- option: _this13.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2390
- var _ref37, _option$id3, _option$option_group_5, _ref38, _option$option_group_6, _option$num3, _option$add_price3;
2551
+ option: _this15.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2552
+ var _ref41, _option$id3, _option$option_group_5, _ref42, _option$option_group_6, _option$num3, _option$add_price3;
2391
2553
  return {
2392
- id: (_ref37 = (_option$id3 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id3 !== void 0 ? _option$id3 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref37 !== void 0 ? _ref37 : null,
2554
+ id: (_ref41 = (_option$id3 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id3 !== void 0 ? _option$id3 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref41 !== void 0 ? _ref41 : null,
2393
2555
  option_group_id: (_option$option_group_5 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_5 !== void 0 ? _option$option_group_5 : null,
2394
- option_group_item_id: (_ref38 = (_option$option_group_6 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_6 !== void 0 ? _option$option_group_6 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref38 !== void 0 ? _ref38 : null,
2556
+ option_group_item_id: (_ref42 = (_option$option_group_6 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_6 !== void 0 ? _option$option_group_6 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref42 !== void 0 ? _ref42 : null,
2395
2557
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
2396
- add_price: _this13.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2558
+ add_price: _this15.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2397
2559
  };
2398
2560
  }))
2399
2561
  };
2400
2562
  })),
2401
2563
  discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2402
- var _ref39, _discount$type4, _ref40, _ref41, _discount$discount_id2, _discount$discount2;
2564
+ var _ref43, _discount$type4, _ref44, _ref45, _discount$discount_id2, _discount$discount2;
2403
2565
  return {
2404
- type: (_ref39 = (_discount$type4 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type4 !== void 0 ? _discount$type4 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref39 !== void 0 ? _ref39 : '',
2405
- discount_id: (_ref40 = (_ref41 = (_discount$discount_id2 = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id2 !== void 0 ? _discount$discount_id2 : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref41 !== void 0 ? _ref41 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref40 !== void 0 ? _ref40 : null,
2406
- amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2566
+ type: (_ref43 = (_discount$type4 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type4 !== void 0 ? _discount$type4 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref43 !== void 0 ? _ref43 : '',
2567
+ discount_id: (_ref44 = (_ref45 = (_discount$discount_id2 = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id2 !== void 0 ? _discount$discount_id2 : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref45 !== void 0 ? _ref45 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref44 !== void 0 ? _ref44 : null,
2568
+ amount: _this15.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2407
2569
  };
2408
2570
  }))
2409
2571
  };
@@ -2411,9 +2573,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2411
2573
  }, {
2412
2574
  key: "buildOrderProductsStructuralFingerprint",
2413
2575
  value: function buildOrderProductsStructuralFingerprint(products) {
2414
- var _this14 = this;
2576
+ var _this16 = this;
2415
2577
  var items = (products || []).map(function (product) {
2416
- return _this14.buildProductStructuralFingerprintItem(product);
2578
+ return _this16.buildProductStructuralFingerprintItem(product);
2417
2579
  });
2418
2580
  items.sort(function (left, right) {
2419
2581
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2423,8 +2585,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2423
2585
  }, {
2424
2586
  key: "getManualDepositOverride",
2425
2587
  value: function getManualDepositOverride(tempOrder) {
2426
- var _tempOrder$_extend3;
2427
- var override = (_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.manualDepositOverride;
2588
+ var _tempOrder$_extend4;
2589
+ var override = (_tempOrder$_extend4 = tempOrder._extend) === null || _tempOrder$_extend4 === void 0 ? void 0 : _tempOrder$_extend4.manualDepositOverride;
2428
2590
  if (!override || _typeof(override) !== 'object') return null;
2429
2591
  if (typeof override.amount !== 'string') return null;
2430
2592
  if (typeof override.productStructuralFingerprint !== 'string') return null;
@@ -2443,16 +2605,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2443
2605
  }, {
2444
2606
  key: "clearManualDepositOverride",
2445
2607
  value: function clearManualDepositOverride(tempOrder) {
2446
- var _tempOrder$_extend4;
2447
- if (!((_tempOrder$_extend4 = tempOrder._extend) !== null && _tempOrder$_extend4 !== void 0 && _tempOrder$_extend4.manualDepositOverride)) return;
2608
+ var _tempOrder$_extend5;
2609
+ if (!((_tempOrder$_extend5 = tempOrder._extend) !== null && _tempOrder$_extend5 !== void 0 && _tempOrder$_extend5.manualDepositOverride)) return;
2448
2610
  tempOrder._extend = _objectSpread({}, tempOrder._extend);
2449
2611
  delete tempOrder._extend.manualDepositOverride;
2450
2612
  }
2451
2613
  }, {
2452
2614
  key: "getOriginalSalesSnapshot",
2453
2615
  value: function getOriginalSalesSnapshot(tempOrder) {
2454
- var _tempOrder$_extend5;
2455
- var snapshot = (_tempOrder$_extend5 = tempOrder._extend) === null || _tempOrder$_extend5 === void 0 ? void 0 : _tempOrder$_extend5.originalSalesSnapshot;
2616
+ var _tempOrder$_extend6;
2617
+ var snapshot = (_tempOrder$_extend6 = tempOrder._extend) === null || _tempOrder$_extend6 === void 0 ? void 0 : _tempOrder$_extend6.originalSalesSnapshot;
2456
2618
  if (!snapshot || _typeof(snapshot) !== 'object') return null;
2457
2619
  if (typeof snapshot.productFingerprint !== 'string') return null;
2458
2620
  return snapshot;
@@ -2656,6 +2818,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2656
2818
  var freshTempOrder = this.createDefaultTempOrderInstance();
2657
2819
  this.ensureExternalSaleNumber(freshTempOrder);
2658
2820
  this.store.tempOrder = freshTempOrder;
2821
+ this.clearCustomerWalletRuntimeState();
2659
2822
  this.store.summary = createEmptySummary();
2660
2823
  this.store.lastOrderInfo = undefined;
2661
2824
  this.store.syncState = undefined;
@@ -2672,13 +2835,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2672
2835
  }, {
2673
2836
  key: "replaceTempOrder",
2674
2837
  value: function () {
2675
- var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(tempOrder, options) {
2838
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(tempOrder, options) {
2676
2839
  var nextTempOrder;
2677
- return _regeneratorRuntime().wrap(function _callee10$(_context12) {
2678
- while (1) switch (_context12.prev = _context12.next) {
2840
+ return _regeneratorRuntime().wrap(function _callee11$(_context13) {
2841
+ while (1) switch (_context13.prev = _context13.next) {
2679
2842
  case 0:
2680
2843
  if (isTempOrder(tempOrder)) {
2681
- _context12.next = 2;
2844
+ _context13.next = 2;
2682
2845
  break;
2683
2846
  }
2684
2847
  throw new Error('无效的 tempOrder 数据');
@@ -2688,36 +2851,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2688
2851
  ensureIdentity: false
2689
2852
  });
2690
2853
  this.store.tempOrder = nextTempOrder;
2854
+ this.clearCustomerWalletRuntimeState();
2691
2855
  if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
2692
- _context12.next = 10;
2856
+ _context13.next = 11;
2693
2857
  break;
2694
2858
  }
2695
- _context12.next = 8;
2859
+ _context13.next = 9;
2696
2860
  return this.recalculateSummary({
2697
2861
  createIfMissing: false
2698
2862
  });
2699
- case 8:
2700
- _context12.next = 11;
2863
+ case 9:
2864
+ _context13.next = 12;
2701
2865
  break;
2702
- case 10:
2703
- this.store.summary = createEmptySummary();
2704
2866
  case 11:
2867
+ this.store.summary = createEmptySummary();
2868
+ case 12:
2705
2869
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
2706
2870
  this.persistTempOrder();
2707
2871
  }
2708
2872
  if (!(options !== null && options !== void 0 && options.saveDraft)) {
2709
- _context12.next = 15;
2873
+ _context13.next = 16;
2710
2874
  break;
2711
2875
  }
2712
- _context12.next = 15;
2876
+ _context13.next = 16;
2713
2877
  return this.saveDraft();
2714
- case 15:
2715
- return _context12.abrupt("return", nextTempOrder);
2716
2878
  case 16:
2879
+ return _context13.abrupt("return", nextTempOrder);
2880
+ case 17:
2717
2881
  case "end":
2718
- return _context12.stop();
2882
+ return _context13.stop();
2719
2883
  }
2720
- }, _callee10, this);
2884
+ }, _callee11, this);
2721
2885
  }));
2722
2886
  function replaceTempOrder(_x9, _x10) {
2723
2887
  return _replaceTempOrder.apply(this, arguments);
@@ -2727,13 +2891,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2727
2891
  }, {
2728
2892
  key: "getOrderIdentity",
2729
2893
  value: function getOrderIdentity() {
2730
- var _ref42, _ref43, _tempOrder$order_id, _tempOrder$_extend6;
2894
+ var _ref46, _ref47, _tempOrder$order_id, _tempOrder$_extend7;
2731
2895
  var tempOrder = this.store.tempOrder;
2732
2896
  if (!tempOrder) return null;
2733
2897
  var lastOrderInfo = this.store.lastOrderInfo || {};
2734
- var orderId = (_ref42 = (_ref43 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref43 !== void 0 ? _ref43 : lastOrderInfo.id) !== null && _ref42 !== void 0 ? _ref42 : null;
2898
+ var orderId = (_ref46 = (_ref47 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref47 !== void 0 ? _ref47 : lastOrderInfo.id) !== null && _ref46 !== void 0 ? _ref46 : null;
2735
2899
  return {
2736
- localId: this.cacheId || ((_tempOrder$_extend6 = tempOrder._extend) === null || _tempOrder$_extend6 === void 0 ? void 0 : _tempOrder$_extend6.localId),
2900
+ localId: this.cacheId || ((_tempOrder$_extend7 = tempOrder._extend) === null || _tempOrder$_extend7 === void 0 ? void 0 : _tempOrder$_extend7.localId),
2737
2901
  orderId: orderId,
2738
2902
  externalSaleNumber: tempOrder.external_sale_number || lastOrderInfo.external_sale_number || '',
2739
2903
  orderNumber: tempOrder.order_number || lastOrderInfo.order_number || '',
@@ -2805,32 +2969,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2805
2969
  }, {
2806
2970
  key: "addNewOrder",
2807
2971
  value: function () {
2808
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
2972
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
2809
2973
  var tempOrder;
2810
- return _regeneratorRuntime().wrap(function _callee11$(_context13) {
2811
- while (1) switch (_context13.prev = _context13.next) {
2974
+ return _regeneratorRuntime().wrap(function _callee12$(_context14) {
2975
+ while (1) switch (_context14.prev = _context14.next) {
2812
2976
  case 0:
2813
2977
  tempOrder = this.ensureTempOrder();
2814
2978
  this.ensureExternalSaleNumber(tempOrder);
2815
- _context13.next = 4;
2979
+ _context14.next = 4;
2816
2980
  return this.recalculateSummary({
2817
2981
  createIfMissing: true
2818
2982
  });
2819
2983
  case 4:
2820
2984
  this.persistTempOrder();
2821
2985
  if (!this.draftPersistEnabled) {
2822
- _context13.next = 8;
2986
+ _context14.next = 8;
2823
2987
  break;
2824
2988
  }
2825
- _context13.next = 8;
2989
+ _context14.next = 8;
2826
2990
  return this.saveDraft();
2827
2991
  case 8:
2828
- return _context13.abrupt("return", tempOrder);
2992
+ return _context14.abrupt("return", tempOrder);
2829
2993
  case 9:
2830
2994
  case "end":
2831
- return _context13.stop();
2995
+ return _context14.stop();
2832
2996
  }
2833
- }, _callee11, this);
2997
+ }, _callee12, this);
2834
2998
  }));
2835
2999
  function addNewOrder() {
2836
3000
  return _addNewOrder.apply(this, arguments);
@@ -2863,9 +3027,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2863
3027
  }, {
2864
3028
  key: "sanitizeTempOrderProducts",
2865
3029
  value: function sanitizeTempOrderProducts(tempOrder) {
2866
- var _this15 = this;
3030
+ var _this17 = this;
2867
3031
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2868
- return _this15.sanitizeOrderProductForTempOrder(_this15.normalizeVirtualSettlementProductIfEnabled(product));
3032
+ return _this17.sanitizeOrderProductForTempOrder(_this17.normalizeVirtualSettlementProductIfEnabled(product));
2869
3033
  });
2870
3034
  this.syncTempOrderSettlementState(tempOrder);
2871
3035
  ensureUniqueProductLineUids(tempOrder);
@@ -2886,8 +3050,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2886
3050
  }, {
2887
3051
  key: "repairDuplicateProductLineIdentities",
2888
3052
  value: function repairDuplicateProductLineIdentities(tempOrder) {
2889
- var _tempOrder$_extend7;
2890
- var result = repairDuplicateOrderProductLineIdentities(tempOrder.products, (_tempOrder$_extend7 = tempOrder._extend) === null || _tempOrder$_extend7 === void 0 ? void 0 : _tempOrder$_extend7.productsByUid);
3053
+ var _tempOrder$_extend8;
3054
+ var result = repairDuplicateOrderProductLineIdentities(tempOrder.products, (_tempOrder$_extend8 = tempOrder._extend) === null || _tempOrder$_extend8 === void 0 ? void 0 : _tempOrder$_extend8.productsByUid);
2891
3055
  if (!result.repairs.length) return;
2892
3056
  tempOrder.products = result.products;
2893
3057
  if (result.productsByUid) {
@@ -2901,11 +3065,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2901
3065
  }, {
2902
3066
  key: "captureProductRuntime",
2903
3067
  value: function captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
2904
- var _extend$productsByUid, _ref44, _rawProduct$_origin;
3068
+ var _extend$productsByUid, _ref48, _rawProduct$_origin;
2905
3069
  var uid = existedUid || this.getProductUid(normalizedProduct);
2906
3070
  var extend = this.ensureExtend(tempOrder);
2907
3071
  var existed = ((_extend$productsByUid = extend.productsByUid) === null || _extend$productsByUid === void 0 ? void 0 : _extend$productsByUid[uid]) || {};
2908
- var origin = (_ref44 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref44 !== void 0 ? _ref44 : existed.origin;
3072
+ var origin = (_ref48 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref48 !== void 0 ? _ref48 : existed.origin;
2909
3073
  extend.productsByUid[uid] = _objectSpread(_objectSpread({}, existed), origin !== undefined ? {
2910
3074
  origin: origin
2911
3075
  } : {});
@@ -2985,7 +3149,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2985
3149
  }, {
2986
3150
  key: "syncLinkedBookingHoldersToProducts",
2987
3151
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
2988
- var _this16 = this;
3152
+ var _this18 = this;
2989
3153
  var bookings = tempOrder.bookings || [];
2990
3154
  var products = tempOrder.products || [];
2991
3155
  if (!bookings.length || !products.length) return;
@@ -3010,7 +3174,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3010
3174
  var bookingUid = product.booking_uid || ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.booking_uid);
3011
3175
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
3012
3176
  if (linkedBooking) {
3013
- _this16.setProductHolderFromBooking(product, linkedBooking);
3177
+ _this18.setProductHolderFromBooking(product, linkedBooking);
3014
3178
  }
3015
3179
  });
3016
3180
  }
@@ -3048,7 +3212,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3048
3212
  }, {
3049
3213
  key: "buildTempOrderHolderFromBookings",
3050
3214
  value: function buildTempOrderHolderFromBookings(tempOrder) {
3051
- var _baseHolder$customer_, _baseHolder, _ref45, _baseHolder$form_id, _baseHolder2, _tempOrder$holder2, _baseHolder3, _this$otherParams2;
3215
+ var _baseHolder$customer_, _baseHolder, _ref49, _baseHolder$form_id, _baseHolder2, _tempOrder$holder2, _baseHolder3, _this$otherParams2;
3052
3216
  var holderRecords = [];
3053
3217
  var holderNames = [];
3054
3218
  var baseHolder = null;
@@ -3095,7 +3259,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3095
3259
  }
3096
3260
  var nextHolder = {
3097
3261
  customer_id: (_baseHolder$customer_ = (_baseHolder = baseHolder) === null || _baseHolder === void 0 ? void 0 : _baseHolder.customer_id) !== null && _baseHolder$customer_ !== void 0 ? _baseHolder$customer_ : tempOrder.customer_id,
3098
- form_id: (_ref45 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_id) !== null && _ref45 !== void 0 ? _ref45 : 0,
3262
+ form_id: (_ref49 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_id) !== null && _ref49 !== void 0 ? _ref49 : 0,
3099
3263
  form_record: holderRecords
3100
3264
  };
3101
3265
  if (holderNames.length) {
@@ -3138,9 +3302,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3138
3302
  }, {
3139
3303
  key: "findBookingIndexByUniqueIdentificationNumber",
3140
3304
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
3141
- var _this17 = this;
3305
+ var _this19 = this;
3142
3306
  return (tempOrder.bookings || []).findIndex(function (booking) {
3143
- return _this17.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
3307
+ return _this19.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
3144
3308
  });
3145
3309
  }
3146
3310
  }, {
@@ -3148,12 +3312,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3148
3312
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
3149
3313
  var _product$metadata5,
3150
3314
  _product$metadata6,
3151
- _this18 = this;
3315
+ _this20 = this;
3152
3316
  var productUid = (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
3153
3317
  var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
3154
3318
  if (!productUid && !bookingUid) return;
3155
3319
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
3156
- var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
3320
+ var currentBookingUid = _this20.getBookingUniqueIdentificationNumber(booking);
3157
3321
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
3158
3322
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
3159
3323
  return true;
@@ -3170,9 +3334,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3170
3334
  }, {
3171
3335
  key: "applyOrderProductsDepositSummary",
3172
3336
  value: function applyOrderProductsDepositSummary(tempOrder, summary) {
3173
- var _tempOrder$_extend8;
3337
+ var _tempOrder$_extend9;
3174
3338
  var depositSummary = calculateOrderProductsDeposit(tempOrder.products || [], {
3175
- productsByUid: (_tempOrder$_extend8 = tempOrder._extend) === null || _tempOrder$_extend8 === void 0 ? void 0 : _tempOrder$_extend8.productsByUid
3339
+ productsByUid: (_tempOrder$_extend9 = tempOrder._extend) === null || _tempOrder$_extend9 === void 0 ? void 0 : _tempOrder$_extend9.productsByUid
3176
3340
  });
3177
3341
  var manualDepositOverride = this.getManualDepositOverride(tempOrder);
3178
3342
  var currentStructuralFingerprint = manualDepositOverride ? this.buildOrderProductsStructuralFingerprint(tempOrder.products) : '';
@@ -3199,18 +3363,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3199
3363
  }, {
3200
3364
  key: "recalculateSummary",
3201
3365
  value: function () {
3202
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(options) {
3203
- var _this$otherParams3, _ref46, _salesSummaryResult$e;
3366
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(options) {
3367
+ var _this$otherParams3, _ref50, _salesSummaryResult$e;
3204
3368
  var tempOrder, originalSnapshot, hasShopDiscountChanged, shouldReuseOriginalSnapshot, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
3205
- return _regeneratorRuntime().wrap(function _callee12$(_context14) {
3206
- while (1) switch (_context14.prev = _context14.next) {
3369
+ return _regeneratorRuntime().wrap(function _callee13$(_context15) {
3370
+ while (1) switch (_context15.prev = _context15.next) {
3207
3371
  case 0:
3208
3372
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
3209
3373
  if (tempOrder) {
3210
- _context14.next = 3;
3374
+ _context15.next = 3;
3211
3375
  break;
3212
3376
  }
3213
- return _context14.abrupt("return", null);
3377
+ return _context15.abrupt("return", null);
3214
3378
  case 3:
3215
3379
  this.sanitizeTempOrderProducts(tempOrder);
3216
3380
  originalSnapshot = this.getOriginalSalesSnapshot(tempOrder);
@@ -3218,10 +3382,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3218
3382
  shouldReuseOriginalSnapshot = originalSnapshot && !hasShopDiscountChanged;
3219
3383
  snapshotSummary = shouldReuseOriginalSnapshot ? this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder, originalSnapshot) : null;
3220
3384
  if (!snapshotSummary) {
3221
- _context14.next = 10;
3385
+ _context15.next = 10;
3222
3386
  break;
3223
3387
  }
3224
- return _context14.abrupt("return", snapshotSummary);
3388
+ return _context15.abrupt("return", snapshotSummary);
3225
3389
  case 10:
3226
3390
  shouldFullRecalculateFromSnapshot = Boolean(originalSnapshot);
3227
3391
  summaryProducts = shouldFullRecalculateFromSnapshot ? cloneDeep(tempOrder.products || []) : tempOrder.products;
@@ -3233,7 +3397,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3233
3397
  totalRefundAmount = existedSummary.total_refund_amount || '0.00';
3234
3398
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
3235
3399
  if (salesSummary) {
3236
- _context14.next = 26;
3400
+ _context15.next = 26;
3237
3401
  break;
3238
3402
  }
3239
3403
  emptyBaseSummary = _objectSpread(_objectSpread(_objectSpread({}, createEmptySummary()), existedSummary), {}, {
@@ -3259,9 +3423,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3259
3423
  previousSummary: existedSummary,
3260
3424
  summary: emptySummary
3261
3425
  });
3262
- return _context14.abrupt("return", this.store.summary);
3426
+ return _context15.abrupt("return", this.store.summary);
3263
3427
  case 26:
3264
- _context14.next = 28;
3428
+ _context15.next = 28;
3265
3429
  return salesSummary.getSummary(_objectSpread({
3266
3430
  products: summaryProducts,
3267
3431
  isPriceIncludeTax: tempOrder.is_price_include_tax,
@@ -3271,7 +3435,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3271
3435
  channel: this.otherParams.channel
3272
3436
  } : {}));
3273
3437
  case 28:
3274
- salesSummaryResult = _context14.sent;
3438
+ salesSummaryResult = _context15.sent;
3275
3439
  if (shouldFullRecalculateFromSnapshot) {
3276
3440
  tempOrder.products = summaryProducts;
3277
3441
  }
@@ -3279,7 +3443,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3279
3443
  roundingAmount = paidPaymentSummary.roundingAmount;
3280
3444
  payServiceChargeAmount = paidPaymentSummary.payServiceChargeAmount;
3281
3445
  hasSalesSummaryAmount = salesSummaryResult.expect_amount !== undefined || salesSummaryResult.total_amount !== undefined;
3282
- expectAmount = hasSalesSummaryAmount ? new Decimal((_ref46 = (_salesSummaryResult$e = salesSummaryResult.expect_amount) !== null && _salesSummaryResult$e !== void 0 ? _salesSummaryResult$e : salesSummaryResult.total_amount) !== null && _ref46 !== void 0 ? _ref46 : 0) : null;
3446
+ expectAmount = hasSalesSummaryAmount ? new Decimal((_ref50 = (_salesSummaryResult$e = salesSummaryResult.expect_amount) !== null && _salesSummaryResult$e !== void 0 ? _salesSummaryResult$e : salesSummaryResult.total_amount) !== null && _ref50 !== void 0 ? _ref50 : 0) : null;
3283
3447
  amountPaymentPatch = hasSalesSummaryAmount || !roundingAmount.eq(0) || !payServiceChargeAmount.eq(0) ? _objectSpread({
3284
3448
  rounding_amount: roundingAmount.toFixed(2)
3285
3449
  }, expectAmount ? {
@@ -3316,12 +3480,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3316
3480
  previousSummary: existedSummary,
3317
3481
  summary: summary
3318
3482
  });
3319
- return _context14.abrupt("return", this.store.summary);
3483
+ return _context15.abrupt("return", this.store.summary);
3320
3484
  case 46:
3321
3485
  case "end":
3322
- return _context14.stop();
3486
+ return _context15.stop();
3323
3487
  }
3324
- }, _callee12, this);
3488
+ }, _callee13, this);
3325
3489
  }));
3326
3490
  function recalculateSummary(_x11) {
3327
3491
  return _recalculateSummary.apply(this, arguments);
@@ -3331,30 +3495,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3331
3495
  }, {
3332
3496
  key: "getOrderSummary",
3333
3497
  value: function () {
3334
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
3498
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
3335
3499
  var summary;
3336
- return _regeneratorRuntime().wrap(function _callee13$(_context15) {
3337
- while (1) switch (_context15.prev = _context15.next) {
3500
+ return _regeneratorRuntime().wrap(function _callee14$(_context16) {
3501
+ while (1) switch (_context16.prev = _context16.next) {
3338
3502
  case 0:
3339
- _context15.next = 2;
3503
+ _context16.next = 2;
3340
3504
  return this.recalculateSummary({
3341
3505
  createIfMissing: true
3342
3506
  });
3343
3507
  case 2:
3344
- summary = _context15.sent;
3508
+ summary = _context16.sent;
3345
3509
  if (summary) {
3346
- _context15.next = 5;
3510
+ _context16.next = 5;
3347
3511
  break;
3348
3512
  }
3349
- return _context15.abrupt("return", createEmptySummary());
3513
+ return _context16.abrupt("return", createEmptySummary());
3350
3514
  case 5:
3351
3515
  this.persistTempOrder();
3352
- return _context15.abrupt("return", summary);
3516
+ return _context16.abrupt("return", summary);
3353
3517
  case 7:
3354
3518
  case "end":
3355
- return _context15.stop();
3519
+ return _context16.stop();
3356
3520
  }
3357
- }, _callee13, this);
3521
+ }, _callee14, this);
3358
3522
  }));
3359
3523
  function getOrderSummary() {
3360
3524
  return _getOrderSummary.apply(this, arguments);
@@ -3378,21 +3542,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3378
3542
  }, {
3379
3543
  key: "syncTempOrderNoteToRemote",
3380
3544
  value: function () {
3381
- var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderId, note) {
3382
- return _regeneratorRuntime().wrap(function _callee14$(_context16) {
3383
- while (1) switch (_context16.prev = _context16.next) {
3545
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderId, note) {
3546
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3547
+ while (1) switch (_context17.prev = _context17.next) {
3384
3548
  case 0:
3385
- _context16.next = 2;
3549
+ _context17.next = 2;
3386
3550
  return this.request.put("/order/order/".concat(orderId, "/note"), {
3387
3551
  note: note
3388
3552
  });
3389
3553
  case 2:
3390
- return _context16.abrupt("return", note);
3554
+ return _context17.abrupt("return", note);
3391
3555
  case 3:
3392
3556
  case "end":
3393
- return _context16.stop();
3557
+ return _context17.stop();
3394
3558
  }
3395
- }, _callee14, this);
3559
+ }, _callee15, this);
3396
3560
  }));
3397
3561
  function syncTempOrderNoteToRemote(_x12, _x13) {
3398
3562
  return _syncTempOrderNoteToRemote.apply(this, arguments);
@@ -3402,72 +3566,370 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3402
3566
  }, {
3403
3567
  key: "getTempOrderNote",
3404
3568
  value: function getTempOrderNote() {
3405
- var _this$store$tempOrder3;
3406
- return ((_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.note) || '';
3569
+ var _this$store$tempOrder4;
3570
+ return ((_this$store$tempOrder4 = this.store.tempOrder) === null || _this$store$tempOrder4 === void 0 ? void 0 : _this$store$tempOrder4.note) || '';
3407
3571
  }
3408
3572
  }, {
3409
- key: "updateTempOrderShopDiscount",
3410
- value: function updateTempOrderShopDiscount(amount) {
3411
- var tempOrder = this.ensureTempOrder();
3412
- var discount = Decimal.max(new Decimal(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
3413
- tempOrder.shop_discount = discount;
3414
- this.persistTempOrder();
3415
- return tempOrder.shop_discount;
3573
+ key: "ensureSalesNotesRuntimeState",
3574
+ value: function ensureSalesNotesRuntimeState(tempOrder) {
3575
+ var hadNotesSnapshot = Array.isArray(tempOrder.notes);
3576
+ if (!Array.isArray(tempOrder.notes)) tempOrder.notes = [];
3577
+ if (!tempOrder._extend || _typeof(tempOrder._extend) !== 'object') {
3578
+ tempOrder._extend = {
3579
+ productsByUid: {}
3580
+ };
3581
+ }
3582
+ if (!tempOrder._extend.salesNotesState) {
3583
+ tempOrder._extend.salesNotesState = {
3584
+ loaded: hadNotesSnapshot,
3585
+ dirty: false
3586
+ };
3587
+ }
3588
+ return tempOrder._extend.salesNotesState;
3416
3589
  }
3417
3590
  }, {
3418
- key: "updateTempOrderDepositAmount",
3419
- value: function updateTempOrderDepositAmount(amount) {
3420
- var tempOrder = this.ensureTempOrder();
3421
- var depositAmount = this.normalizeDepositAmount(amount);
3422
- var previousSummary = this.store.summary || createEmptySummary();
3423
- var summaryWithDeposit = this.applyDepositAmountToSummary(tempOrder, _objectSpread(_objectSpread({}, createEmptySummary()), previousSummary), depositAmount);
3424
- this.setManualDepositOverride(tempOrder, depositAmount);
3425
- var paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
3426
- var summary = _objectSpread(_objectSpread({}, summaryWithDeposit), {}, {
3427
- amount_gap: this.calculateSummaryAmountGap({
3428
- tempOrder: tempOrder,
3429
- summary: summaryWithDeposit,
3430
- orderPaidAmount: paidPaymentSummary.gapPaidAmount
3431
- })
3591
+ key: "ensureSalesNotesLoadedForMutation",
3592
+ value: function ensureSalesNotesLoadedForMutation(tempOrder) {
3593
+ var state = this.ensureSalesNotesRuntimeState(tempOrder);
3594
+ if (state.loaded) return;
3595
+ if (tempOrder.order_id === null || tempOrder.order_id === undefined) {
3596
+ state.loaded = true;
3597
+ tempOrder.notes = [];
3598
+ return;
3599
+ }
3600
+ throw new Error('[Order Notes] 当前订单 Notes 尚未完整加载,禁止提交部分快照');
3601
+ }
3602
+ }, {
3603
+ key: "normalizeSalesNoteUuid",
3604
+ value: function normalizeSalesNoteUuid(value, field) {
3605
+ var uuid = String(value !== null && value !== void 0 ? value : '').trim();
3606
+ if (!uuid) throw new Error("[Order Notes] ".concat(field, " \u4E0D\u80FD\u4E3A\u7A7A"));
3607
+ if (uuid.length > 255) {
3608
+ throw new Error("[Order Notes] ".concat(field, " \u4E0D\u80FD\u8D85\u8FC7 255 \u4E2A\u5B57\u7B26"));
3609
+ }
3610
+ return uuid;
3611
+ }
3612
+ }, {
3613
+ key: "getSalesNotePrimaryRelation",
3614
+ value: function getSalesNotePrimaryRelation(note) {
3615
+ return note.note_relations.find(function (relation) {
3616
+ return relation.is_primary === 1;
3617
+ }) || null;
3618
+ }
3619
+ }, {
3620
+ key: "removeSalesNotesForMissingProductLines",
3621
+ value: function removeSalesNotesForMissingProductLines(tempOrder) {
3622
+ var _this21 = this;
3623
+ var state = this.ensureSalesNotesRuntimeState(tempOrder);
3624
+ if (!state.loaded || !Array.isArray(tempOrder.notes) || tempOrder.notes.length === 0) {
3625
+ return;
3626
+ }
3627
+ var remainingProductUids = new Set((tempOrder.products || []).map(function (product) {
3628
+ var _product$metadata7;
3629
+ return ((_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number) || product.unique_identification_number;
3630
+ }).filter(function (uid) {
3631
+ return typeof uid === 'string' && uid.length > 0;
3632
+ }));
3633
+ var nextNotes = tempOrder.notes.filter(function (note) {
3634
+ var primary = _this21.getSalesNotePrimaryRelation(note);
3635
+ if (!primary || primary.target_type !== 'order_detail') return true;
3636
+ return remainingProductUids.has(primary.target_uuid);
3432
3637
  });
3433
- this.store.summary = summary;
3434
- this.updateTempOrderPaymentStatus(tempOrder, {
3435
- previousSummary: previousSummary,
3436
- summary: summary
3638
+ if (nextNotes.length === tempOrder.notes.length) return;
3639
+ tempOrder.notes = nextNotes;
3640
+ state.dirty = true;
3641
+ }
3642
+ }, {
3643
+ key: "setSalesNoteOnTempOrder",
3644
+ value: function setSalesNoteOnTempOrder(tempOrder, input) {
3645
+ var _input$target,
3646
+ _this22 = this,
3647
+ _tempOrder$shop_order;
3648
+ this.ensureSalesNotesLoadedForMutation(tempOrder);
3649
+ var note_type = String(input.note_type || '').trim();
3650
+ var policy = getSalesNotePolicy(note_type);
3651
+ if (!policy) {
3652
+ throw new Error("[Order Notes] \u5F53\u524D\u672A\u6CE8\u518C\u5907\u6CE8\u7C7B\u578B: ".concat(note_type || '(empty)'));
3653
+ }
3654
+ if (((_input$target = input.target) === null || _input$target === void 0 ? void 0 : _input$target.target_type) !== 'order_detail') {
3655
+ throw new Error('[Order Notes] 本期只支持 order_detail 作为主体');
3656
+ }
3657
+ var target_uuid = this.normalizeSalesNoteUuid(input.target.target_uuid, 'target_uuid');
3658
+ var targetProductExists = (tempOrder.products || []).some(function (product) {
3659
+ var _product$metadata8;
3660
+ var productLineUid = ((_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.unique_identification_number) || product.unique_identification_number;
3661
+ return String(productLineUid !== null && productLineUid !== void 0 ? productLineUid : '') === target_uuid;
3437
3662
  });
3438
- this.persistTempOrder();
3439
- return summary;
3663
+ if (!targetProductExists) {
3664
+ throw new Error('[Order Notes] 目标商品行不存在');
3665
+ }
3666
+ var text = buildSalesNoteText(input.text);
3667
+ var notes = tempOrder.notes || [];
3668
+ // 当前 allergy policy 固定同一商品行只保留一条;业务调用方不参与去重规则。
3669
+ var existingIndex = policy.uniquePerPrimaryTarget ? notes.findIndex(function (note) {
3670
+ var primary = _this22.getSalesNotePrimaryRelation(note);
3671
+ return note.note_type === note_type && (primary === null || primary === void 0 ? void 0 : primary.target_type) === 'order_detail' && primary.target_uuid === target_uuid;
3672
+ }) : -1;
3673
+ var existing = existingIndex >= 0 ? notes[existingIndex] : null;
3674
+ var existingPrimary = existing === null || existing === void 0 ? void 0 : existing.note_relations.find(function (relation) {
3675
+ return relation.is_primary === 1 && relation.target_type === 'order_detail';
3676
+ });
3677
+ var existingOrderRelation = existing === null || existing === void 0 ? void 0 : existing.note_relations.find(function (relation) {
3678
+ return relation.is_primary === 0 && relation.target_type === 'order';
3679
+ });
3680
+ var note = {
3681
+ uuid: (existing === null || existing === void 0 ? void 0 : existing.uuid) || createUuidV4(),
3682
+ note_type: policy.note_type,
3683
+ content: {
3684
+ text: text
3685
+ },
3686
+ importance: policy.importance,
3687
+ note_relations: [{
3688
+ uuid: (existingPrimary === null || existingPrimary === void 0 ? void 0 : existingPrimary.uuid) || createUuidV4(),
3689
+ relation_type: policy.primary_relation_type,
3690
+ target_type: 'order_detail',
3691
+ target_uuid: target_uuid,
3692
+ is_primary: 1
3693
+ }, {
3694
+ uuid: (existingOrderRelation === null || existingOrderRelation === void 0 ? void 0 : existingOrderRelation.uuid) || createUuidV4(),
3695
+ relation_type: policy.secondary_order_relation_type,
3696
+ target_type: 'order',
3697
+ target_uuid: String((_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : ''),
3698
+ is_primary: 0
3699
+ }]
3700
+ };
3701
+ var duplicateIndex = notes.findIndex(function (item, index) {
3702
+ return item.uuid === note.uuid && index !== existingIndex;
3703
+ });
3704
+ if (duplicateIndex >= 0) {
3705
+ throw new Error('[Order Notes] uuid 已被其他 Note 使用');
3706
+ }
3707
+ tempOrder.notes = existingIndex >= 0 ? notes.map(function (item, index) {
3708
+ return index === existingIndex ? note : item;
3709
+ }) : [].concat(_toConsumableArray(notes), [note]);
3710
+ var state = this.ensureSalesNotesRuntimeState(tempOrder);
3711
+ state.loaded = true;
3712
+ state.dirty = true;
3713
+ return note;
3440
3714
  }
3441
3715
  }, {
3442
- key: "updateTempOrderBuzzer",
3443
- value: function updateTempOrderBuzzer(buzzer) {
3716
+ key: "getSalesNotes",
3717
+ value: function getSalesNotes() {
3444
3718
  var tempOrder = this.ensureTempOrder();
3445
- tempOrder.buzzer = String(buzzer || '');
3446
- this.persistTempOrder();
3447
- return tempOrder.buzzer;
3719
+ this.ensureSalesNotesRuntimeState(tempOrder);
3720
+ return cloneDeep(tempOrder.notes || []);
3448
3721
  }
3449
3722
  }, {
3450
- key: "updateTempOrderContactsInfo",
3451
- value: function updateTempOrderContactsInfo(contactsInfo) {
3723
+ key: "createSalesNotesMutationSnapshot",
3724
+ value: function createSalesNotesMutationSnapshot() {
3725
+ var _tempOrder$order_id2;
3452
3726
  var tempOrder = this.ensureTempOrder();
3453
- tempOrder.contacts_info = contactsInfo && _typeof(contactsInfo) === 'object' && !Array.isArray(contactsInfo) ? contactsInfo : null;
3454
- this.persistTempOrder();
3455
- return tempOrder.contacts_info;
3727
+ var state = this.ensureSalesNotesRuntimeState(tempOrder);
3728
+ return {
3729
+ orderIdentity: {
3730
+ orderId: (_tempOrder$order_id2 = tempOrder.order_id) !== null && _tempOrder$order_id2 !== void 0 ? _tempOrder$order_id2 : null,
3731
+ externalSaleNumber: String(tempOrder.external_sale_number || '')
3732
+ },
3733
+ notes: cloneDeep(tempOrder.notes || []),
3734
+ state: cloneDeep(state)
3735
+ };
3736
+ }
3737
+ }, {
3738
+ key: "restoreSalesNotesMutationSnapshot",
3739
+ value: function restoreSalesNotesMutationSnapshot(snapshot) {
3740
+ var _snapshot$state, _snapshot$state2;
3741
+ if (!snapshot || !Array.isArray(snapshot.notes) || !snapshot.orderIdentity || typeof snapshot.orderIdentity.externalSaleNumber !== 'string' || typeof ((_snapshot$state = snapshot.state) === null || _snapshot$state === void 0 ? void 0 : _snapshot$state.loaded) !== 'boolean' || typeof ((_snapshot$state2 = snapshot.state) === null || _snapshot$state2 === void 0 ? void 0 : _snapshot$state2.dirty) !== 'boolean') {
3742
+ throw new Error('[Order Notes] 无效的 mutation snapshot');
3743
+ }
3744
+ var tempOrder = this.store.tempOrder;
3745
+ if (!tempOrder) throw new Error('[Order Notes] 当前订单不存在');
3746
+ var snapshotOrderId = snapshot.orderIdentity.orderId;
3747
+ var currentOrderId = tempOrder.order_id;
3748
+ var hasSnapshotOrderId = snapshotOrderId !== null && snapshotOrderId !== undefined && String(snapshotOrderId).trim().length > 0;
3749
+ var hasCurrentOrderId = currentOrderId !== null && currentOrderId !== undefined && String(currentOrderId).trim().length > 0;
3750
+ var isSameOrder = hasSnapshotOrderId && hasCurrentOrderId ? String(snapshotOrderId) === String(currentOrderId) : Boolean(snapshot.orderIdentity.externalSaleNumber) && snapshot.orderIdentity.externalSaleNumber === String(tempOrder.external_sale_number || '');
3751
+ if (!isSameOrder) {
3752
+ throw new Error('[Order Notes] 当前订单已切换,拒绝恢复旧订单快照');
3753
+ }
3754
+ this.ensureSalesNotesRuntimeState(tempOrder);
3755
+ tempOrder.notes = cloneDeep(snapshot.notes);
3756
+ tempOrder._extend.salesNotesState = cloneDeep(snapshot.state);
3757
+ this.notifyTempOrderChanged();
3758
+ }
3759
+ }, {
3760
+ key: "setSalesNote",
3761
+ value: function () {
3762
+ var _setSalesNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(input) {
3763
+ var tempOrder, note;
3764
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3765
+ while (1) switch (_context18.prev = _context18.next) {
3766
+ case 0:
3767
+ tempOrder = this.ensureTempOrder();
3768
+ note = this.setSalesNoteOnTempOrder(tempOrder, input);
3769
+ this.notifyTempOrderChanged();
3770
+ return _context18.abrupt("return", cloneDeep(note));
3771
+ case 4:
3772
+ case "end":
3773
+ return _context18.stop();
3774
+ }
3775
+ }, _callee16, this);
3776
+ }));
3777
+ function setSalesNote(_x14) {
3778
+ return _setSalesNote.apply(this, arguments);
3779
+ }
3780
+ return setSalesNote;
3781
+ }()
3782
+ }, {
3783
+ key: "removeSalesNote",
3784
+ value: function () {
3785
+ var _removeSalesNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(uuid) {
3786
+ var tempOrder, normalizedUuid, notes, nextNotes, state;
3787
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3788
+ while (1) switch (_context19.prev = _context19.next) {
3789
+ case 0:
3790
+ tempOrder = this.ensureTempOrder();
3791
+ this.ensureSalesNotesLoadedForMutation(tempOrder);
3792
+ normalizedUuid = this.normalizeSalesNoteUuid(uuid, 'uuid');
3793
+ notes = tempOrder.notes || [];
3794
+ nextNotes = notes.filter(function (note) {
3795
+ return note.uuid !== normalizedUuid;
3796
+ });
3797
+ if (!(nextNotes.length === notes.length)) {
3798
+ _context19.next = 7;
3799
+ break;
3800
+ }
3801
+ return _context19.abrupt("return");
3802
+ case 7:
3803
+ tempOrder.notes = nextNotes;
3804
+ state = this.ensureSalesNotesRuntimeState(tempOrder);
3805
+ state.dirty = true;
3806
+ this.notifyTempOrderChanged();
3807
+ case 11:
3808
+ case "end":
3809
+ return _context19.stop();
3810
+ }
3811
+ }, _callee17, this);
3812
+ }));
3813
+ function removeSalesNote(_x15) {
3814
+ return _removeSalesNote.apply(this, arguments);
3815
+ }
3816
+ return removeSalesNote;
3817
+ }()
3818
+ }, {
3819
+ key: "clearSalesNotes",
3820
+ value: function () {
3821
+ var _clearSalesNotes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
3822
+ var tempOrder, state;
3823
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3824
+ while (1) switch (_context20.prev = _context20.next) {
3825
+ case 0:
3826
+ tempOrder = this.ensureTempOrder();
3827
+ tempOrder.notes = [];
3828
+ state = this.ensureSalesNotesRuntimeState(tempOrder);
3829
+ state.loaded = true;
3830
+ state.dirty = true;
3831
+ this.notifyTempOrderChanged();
3832
+ case 6:
3833
+ case "end":
3834
+ return _context20.stop();
3835
+ }
3836
+ }, _callee18, this);
3837
+ }));
3838
+ function clearSalesNotes() {
3839
+ return _clearSalesNotes.apply(this, arguments);
3840
+ }
3841
+ return clearSalesNotes;
3842
+ }()
3843
+ }, {
3844
+ key: "updateTempOrderShopDiscount",
3845
+ value: function updateTempOrderShopDiscount(amount) {
3846
+ var tempOrder = this.ensureTempOrder();
3847
+ var discount = Decimal.max(new Decimal(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
3848
+ tempOrder.shop_discount = discount;
3849
+ this.persistTempOrder();
3850
+ return tempOrder.shop_discount;
3851
+ }
3852
+ }, {
3853
+ key: "updateTempOrderDepositAmount",
3854
+ value: function updateTempOrderDepositAmount(amount) {
3855
+ var tempOrder = this.ensureTempOrder();
3856
+ var depositAmount = this.normalizeDepositAmount(amount);
3857
+ var previousSummary = this.store.summary || createEmptySummary();
3858
+ var summaryWithDeposit = this.applyDepositAmountToSummary(tempOrder, _objectSpread(_objectSpread({}, createEmptySummary()), previousSummary), depositAmount);
3859
+ this.setManualDepositOverride(tempOrder, depositAmount);
3860
+ var paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
3861
+ var summary = _objectSpread(_objectSpread({}, summaryWithDeposit), {}, {
3862
+ amount_gap: this.calculateSummaryAmountGap({
3863
+ tempOrder: tempOrder,
3864
+ summary: summaryWithDeposit,
3865
+ orderPaidAmount: paidPaymentSummary.gapPaidAmount
3866
+ })
3867
+ });
3868
+ this.store.summary = summary;
3869
+ this.updateTempOrderPaymentStatus(tempOrder, {
3870
+ previousSummary: previousSummary,
3871
+ summary: summary
3872
+ });
3873
+ this.persistTempOrder();
3874
+ return summary;
3875
+ }
3876
+ }, {
3877
+ key: "updateTempOrderBuzzer",
3878
+ value: function updateTempOrderBuzzer(buzzer) {
3879
+ var tempOrder = this.ensureTempOrder();
3880
+ tempOrder.buzzer = String(buzzer || '');
3881
+ this.persistTempOrder();
3882
+ return tempOrder.buzzer;
3883
+ }
3884
+ }, {
3885
+ key: "updateTempOrderShopServiceData",
3886
+ value: function updateTempOrderShopServiceData(patch) {
3887
+ var tempOrder = this.ensureTempOrder();
3888
+ var metadata = tempOrder.metadata && _typeof(tempOrder.metadata) === 'object' && !Array.isArray(tempOrder.metadata) ? tempOrder.metadata : {};
3889
+ var currentShopServiceData = metadata.shop_service_data && _typeof(metadata.shop_service_data) === 'object' && !Array.isArray(metadata.shop_service_data) ? metadata.shop_service_data : {};
3890
+ var shopServiceData = _objectSpread(_objectSpread({}, currentShopServiceData), patch);
3891
+ tempOrder.metadata = _objectSpread(_objectSpread({}, metadata), {}, {
3892
+ shop_service_data: shopServiceData
3893
+ });
3894
+ this.persistTempOrder();
3895
+ return shopServiceData;
3896
+ }
3897
+ }, {
3898
+ key: "updateTempOrderPickupReferenceMode",
3899
+ value: function updateTempOrderPickupReferenceMode(mode) {
3900
+ return this.updateTempOrderShopServiceData({
3901
+ pickup_reference_mode: mode
3902
+ });
3903
+ }
3904
+ }, {
3905
+ key: "updateTempOrderServiceType",
3906
+ value: function updateTempOrderServiceType(serviceType) {
3907
+ return this.updateTempOrderShopServiceData({
3908
+ service_type: serviceType
3909
+ });
3910
+ }
3911
+ }, {
3912
+ key: "updateTempOrderContactsInfo",
3913
+ value: function updateTempOrderContactsInfo(contactsInfo) {
3914
+ var tempOrder = this.ensureTempOrder();
3915
+ tempOrder.contacts_info = contactsInfo && _typeof(contactsInfo) === 'object' && !Array.isArray(contactsInfo) ? contactsInfo : null;
3916
+ this.persistTempOrder();
3917
+ return tempOrder.contacts_info;
3456
3918
  }
3457
3919
  }, {
3458
3920
  key: "buildTempOrderCustomer",
3459
3921
  value: function buildTempOrderCustomer(params) {
3460
- var _ref47, _ref48, _ref49, _source$name, _ref50, _ref51, _ref52, _source$customer_name, _source$id, _source$customer_id, _ref53, _source$country_calli, _source$phone, _source$email;
3922
+ var _ref51, _ref52, _ref53, _source$name, _ref54, _ref55, _ref56, _source$customer_name, _source$id, _source$customer_id, _ref57, _source$country_calli, _source$phone, _source$email;
3461
3923
  if (!params.customerId) return null;
3462
3924
  var source = params.source ? cloneDeep(params.source) : {};
3463
- var name = (_ref47 = (_ref48 = (_ref49 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref49 !== void 0 ? _ref49 : source.customerName) !== null && _ref48 !== void 0 ? _ref48 : source.customer_name) !== null && _ref47 !== void 0 ? _ref47 : params.customerName;
3464
- var customerName = (_ref50 = (_ref51 = (_ref52 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref52 !== void 0 ? _ref52 : source.display_name) !== null && _ref51 !== void 0 ? _ref51 : source.name) !== null && _ref50 !== void 0 ? _ref50 : params.customerName;
3925
+ var name = (_ref51 = (_ref52 = (_ref53 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref53 !== void 0 ? _ref53 : source.customerName) !== null && _ref52 !== void 0 ? _ref52 : source.customer_name) !== null && _ref51 !== void 0 ? _ref51 : params.customerName;
3926
+ var customerName = (_ref54 = (_ref55 = (_ref56 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref56 !== void 0 ? _ref56 : source.display_name) !== null && _ref55 !== void 0 ? _ref55 : source.name) !== null && _ref54 !== void 0 ? _ref54 : params.customerName;
3465
3927
  return _objectSpread(_objectSpread({}, source), {}, {
3466
3928
  id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
3467
3929
  customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
3468
3930
  name: String(name || ''),
3469
3931
  customer_name: String(customerName || ''),
3470
- country_calling_code: String((_ref53 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref53 !== void 0 ? _ref53 : params.countryCallingCode),
3932
+ country_calling_code: String((_ref57 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref57 !== void 0 ? _ref57 : params.countryCallingCode),
3471
3933
  phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
3472
3934
  email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
3473
3935
  });
@@ -3487,15 +3949,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3487
3949
  }, {
3488
3950
  key: "productHasCustomerBoundDiscount",
3489
3951
  value: function productHasCustomerBoundDiscount(product) {
3490
- var _this19 = this;
3952
+ var _this23 = this;
3491
3953
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3492
- return _this19.isCustomerBoundDiscount(discount);
3954
+ return _this23.isCustomerBoundDiscount(discount);
3493
3955
  })) {
3494
3956
  return true;
3495
3957
  }
3496
3958
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3497
3959
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3498
- return _this19.isCustomerBoundDiscount(discount);
3960
+ return _this23.isCustomerBoundDiscount(discount);
3499
3961
  });
3500
3962
  });
3501
3963
  }
@@ -3504,18 +3966,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3504
3966
  value: function shouldSkipDiscountCalculation(tempOrder) {
3505
3967
  var _this$store$discount20,
3506
3968
  _this$store$discount21,
3507
- _this20 = this;
3969
+ _this24 = this;
3508
3970
  if (this.hasActiveCustomerBoundDiscount) return false;
3509
3971
  var discountList = ((_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 || (_this$store$discount21 = _this$store$discount20.getDiscountList) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.call(_this$store$discount20)) || [];
3510
3972
  if (discountList.length > 0) return false;
3511
3973
  return !(tempOrder.products || []).some(function (product) {
3512
- return _this20.productHasCustomerBoundDiscount(product);
3974
+ return _this24.productHasCustomerBoundDiscount(product);
3513
3975
  });
3514
3976
  }
3515
3977
  }, {
3516
3978
  key: "clearCustomerBoundDiscounts",
3517
3979
  value: function clearCustomerBoundDiscounts(tempOrder) {
3518
- var _this21 = this,
3980
+ var _this25 = this,
3519
3981
  _discountModule$getDi,
3520
3982
  _discountModule$getOr,
3521
3983
  _discountModule$setDi,
@@ -3524,7 +3986,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3524
3986
  var filterDiscountList = function filterDiscountList(discountList) {
3525
3987
  if (!Array.isArray(discountList)) return [];
3526
3988
  return discountList.filter(function (discount) {
3527
- var shouldRemove = _this21.isCustomerBoundDiscount(discount);
3989
+ var shouldRemove = _this25.isCustomerBoundDiscount(discount);
3528
3990
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3529
3991
  return !shouldRemove;
3530
3992
  });
@@ -3551,12 +4013,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3551
4013
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3552
4014
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3553
4015
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3554
- if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3555
- return !_this21.isCustomerBoundDiscount(discount);
4016
+ if (_this25.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
4017
+ return !_this25.isCustomerBoundDiscount(discount);
3556
4018
  });
3557
4019
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3558
- if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3559
- return !_this21.isCustomerBoundDiscount(discount);
4020
+ if (_this25.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
4021
+ return !_this25.isCustomerBoundDiscount(discount);
3560
4022
  });
3561
4023
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3562
4024
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -3571,14 +4033,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3571
4033
  }, {
3572
4034
  key: "updateTempOrderCustomer",
3573
4035
  value: function updateTempOrderCustomer(customer) {
3574
- var _tempOrder$customer_i3, _ref54, _ref55, _customer$customer_id, _ref56, _ref57, _ref58, _customer$customer_na, _ref59, _customer$country_cal, _tempOrder$customer_i4;
4036
+ var _tempOrder$customer_i3, _ref58, _ref59, _customer$customer_id, _ref60, _ref61, _ref62, _customer$customer_na, _ref63, _customer$country_cal, _tempOrder$customer_i4;
3575
4037
  var tempOrder = this.ensureTempOrder();
3576
4038
  var previousCustomerId = (_tempOrder$customer_i3 = tempOrder.customer_id) !== null && _tempOrder$customer_i3 !== void 0 ? _tempOrder$customer_i3 : null;
3577
- var customerId = (_ref54 = (_ref55 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref55 !== void 0 ? _ref55 : customer.id) !== null && _ref54 !== void 0 ? _ref54 : null;
3578
- var customerName = (_ref56 = (_ref57 = (_ref58 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref58 !== void 0 ? _ref58 : customer.display_name) !== null && _ref57 !== void 0 ? _ref57 : customer.name) !== null && _ref56 !== void 0 ? _ref56 : '';
4039
+ var customerId = (_ref58 = (_ref59 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref59 !== void 0 ? _ref59 : customer.id) !== null && _ref58 !== void 0 ? _ref58 : null;
4040
+ var customerName = (_ref60 = (_ref61 = (_ref62 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref62 !== void 0 ? _ref62 : customer.display_name) !== null && _ref61 !== void 0 ? _ref61 : customer.name) !== null && _ref60 !== void 0 ? _ref60 : '';
3579
4041
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
3580
4042
  tempOrder.customer_name = String(customerName || '');
3581
- tempOrder.country_calling_code = String((_ref59 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref59 !== void 0 ? _ref59 : '');
4043
+ tempOrder.country_calling_code = String((_ref63 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref63 !== void 0 ? _ref63 : '');
3582
4044
  tempOrder.phone = String(customer.phone || '');
3583
4045
  tempOrder.email = String(customer.email || '');
3584
4046
  tempOrder.customer = this.buildTempOrderCustomer({
@@ -3591,8 +4053,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3591
4053
  });
3592
4054
  var nextCustomerId = (_tempOrder$customer_i4 = tempOrder.customer_id) !== null && _tempOrder$customer_i4 !== void 0 ? _tempOrder$customer_i4 : null;
3593
4055
  if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
3594
- this.store.availableWalletIds = [];
3595
- this.clearTempOrderPointCardSnapshot(tempOrder);
4056
+ this.clearCustomerWalletState(tempOrder);
3596
4057
  }
3597
4058
  this.persistTempOrder();
3598
4059
  return {
@@ -3631,9 +4092,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3631
4092
  }
3632
4093
  var nextCustomerId = (_tempOrder$customer_i6 = tempOrder.customer_id) !== null && _tempOrder$customer_i6 !== void 0 ? _tempOrder$customer_i6 : null;
3633
4094
  if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
3634
- this.store.availableWalletIds = [];
3635
- this.store.virtualCurrencyList = [];
3636
- this.clearTempOrderPointCardSnapshot(tempOrder);
4095
+ this.clearCustomerWalletState(tempOrder);
3637
4096
  clearTempOrderHolderAssignments(tempOrder);
3638
4097
  this.clearCustomerBoundDiscounts(tempOrder);
3639
4098
  this.applyDiscount();
@@ -3662,8 +4121,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3662
4121
  }, {
3663
4122
  key: "getOrderCustomerSnapshot",
3664
4123
  value: function getOrderCustomerSnapshot() {
3665
- var _this$store$tempOrder4;
3666
- var snapshot = (_this$store$tempOrder4 = this.store.tempOrder) === null || _this$store$tempOrder4 === void 0 || (_this$store$tempOrder4 = _this$store$tempOrder4._extend) === null || _this$store$tempOrder4 === void 0 ? void 0 : _this$store$tempOrder4.customerSnapshot;
4124
+ var _this$store$tempOrder5;
4125
+ var snapshot = (_this$store$tempOrder5 = this.store.tempOrder) === null || _this$store$tempOrder5 === void 0 || (_this$store$tempOrder5 = _this$store$tempOrder5._extend) === null || _this$store$tempOrder5 === void 0 ? void 0 : _this$store$tempOrder5.customerSnapshot;
3667
4126
  return snapshot ? cloneDeep(snapshot) : null;
3668
4127
  }
3669
4128
  }, {
@@ -3678,9 +4137,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3678
4137
  tempOrder.email = '';
3679
4138
  tempOrder.customer = null;
3680
4139
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
3681
- this.store.availableWalletIds = [];
3682
- this.store.virtualCurrencyList = [];
3683
- this.clearTempOrderPointCardSnapshot(tempOrder);
4140
+ this.clearCustomerWalletState(tempOrder);
3684
4141
  this.clearCustomerBoundDiscounts(tempOrder);
3685
4142
  this.applyDiscount();
3686
4143
  this.persistTempOrder();
@@ -3725,10 +4182,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3725
4182
  }, {
3726
4183
  key: "setOrderPayments",
3727
4184
  value: function setOrderPayments(payments) {
3728
- var _this22 = this;
4185
+ var _this26 = this;
3729
4186
  var tempOrder = this.ensureTempOrder();
3730
4187
  tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
3731
- return _this22.normalizePaymentSource(payment, {
4188
+ return _this26.normalizePaymentSource(payment, {
3732
4189
  defaultPaid: false
3733
4190
  });
3734
4191
  }));
@@ -3748,34 +4205,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3748
4205
  }, {
3749
4206
  key: "addOrderPaymentAsync",
3750
4207
  value: (function () {
3751
- var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(payment) {
4208
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(payment) {
3752
4209
  var hasPaymentNumber, devicePrefix;
3753
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3754
- while (1) switch (_context17.prev = _context17.next) {
4210
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
4211
+ while (1) switch (_context21.prev = _context21.next) {
3755
4212
  case 0:
3756
4213
  hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3757
4214
  if (!hasPaymentNumber) {
3758
- _context17.next = 5;
4215
+ _context21.next = 5;
3759
4216
  break;
3760
4217
  }
3761
- _context17.t0 = 'LOCAL';
3762
- _context17.next = 8;
4218
+ _context21.t0 = 'LOCAL';
4219
+ _context21.next = 8;
3763
4220
  break;
3764
4221
  case 5:
3765
- _context17.next = 7;
4222
+ _context21.next = 7;
3766
4223
  return this.getPaymentNumberDevicePrefixAsync();
3767
4224
  case 7:
3768
- _context17.t0 = _context17.sent;
4225
+ _context21.t0 = _context21.sent;
3769
4226
  case 8:
3770
- devicePrefix = _context17.t0;
3771
- return _context17.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
4227
+ devicePrefix = _context21.t0;
4228
+ return _context21.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3772
4229
  case 10:
3773
4230
  case "end":
3774
- return _context17.stop();
4231
+ return _context21.stop();
3775
4232
  }
3776
- }, _callee15, this);
4233
+ }, _callee19, this);
3777
4234
  }));
3778
- function addOrderPaymentAsync(_x14) {
4235
+ function addOrderPaymentAsync(_x16) {
3779
4236
  return _addOrderPaymentAsync.apply(this, arguments);
3780
4237
  }
3781
4238
  return addOrderPaymentAsync;
@@ -3783,7 +4240,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3783
4240
  }, {
3784
4241
  key: "addOrderPaymentWithDevicePrefix",
3785
4242
  value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3786
- var _this23 = this;
4243
+ var _this27 = this;
3787
4244
  this.logInfo('addOrderPayment', {
3788
4245
  payment: payment
3789
4246
  });
@@ -3801,7 +4258,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3801
4258
  void this.recalculateSummary({
3802
4259
  createIfMissing: true
3803
4260
  }).catch(function (error) {
3804
- _this23.logError('recalculate summary after addOrderPayment failed', {
4261
+ _this27.logError('recalculate summary after addOrderPayment failed', {
3805
4262
  error: error instanceof Error ? error.message : String(error)
3806
4263
  });
3807
4264
  });
@@ -3815,7 +4272,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3815
4272
  }, {
3816
4273
  key: "updateOrderPayment",
3817
4274
  value: (function () {
3818
- var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentIdentity, updates) {
4275
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(paymentIdentity, updates) {
3819
4276
  var options,
3820
4277
  tempOrder,
3821
4278
  identity,
@@ -3824,17 +4281,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3824
4281
  updatedPayment,
3825
4282
  summary,
3826
4283
  payments,
3827
- _args18 = arguments;
3828
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3829
- while (1) switch (_context18.prev = _context18.next) {
4284
+ _args22 = arguments;
4285
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4286
+ while (1) switch (_context22.prev = _context22.next) {
3830
4287
  case 0:
3831
- options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
4288
+ options = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {};
3832
4289
  tempOrder = this.ensureTempOrder();
3833
4290
  identity = String(paymentIdentity);
3834
4291
  matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3835
4292
  matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, matchMode);
3836
4293
  if (matchedPayment) {
3837
- _context18.next = 7;
4294
+ _context22.next = 7;
3838
4295
  break;
3839
4296
  }
3840
4297
  throw new Error("\u672A\u627E\u5230\u652F\u4ED8\u9879: ".concat(identity));
@@ -3849,15 +4306,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3849
4306
  return nextPayment;
3850
4307
  });
3851
4308
  this.persistTempOrder();
3852
- _context18.next = 12;
4309
+ _context22.next = 12;
3853
4310
  return this.recalculateSummary({
3854
4311
  createIfMissing: true
3855
4312
  });
3856
4313
  case 12:
3857
- summary = _context18.sent;
4314
+ summary = _context22.sent;
3858
4315
  this.persistTempOrder();
3859
4316
  payments = tempOrder.payments;
3860
- return _context18.abrupt("return", {
4317
+ return _context22.abrupt("return", {
3861
4318
  updated: true,
3862
4319
  payment: payments[matchedPayment.index] || updatedPayment,
3863
4320
  payments: payments,
@@ -3865,11 +4322,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3865
4322
  });
3866
4323
  case 16:
3867
4324
  case "end":
3868
- return _context18.stop();
4325
+ return _context22.stop();
3869
4326
  }
3870
- }, _callee16, this);
4327
+ }, _callee20, this);
3871
4328
  }));
3872
- function updateOrderPayment(_x15, _x16) {
4329
+ function updateOrderPayment(_x17, _x18) {
3873
4330
  return _updateOrderPayment.apply(this, arguments);
3874
4331
  }
3875
4332
  return updateOrderPayment;
@@ -3914,7 +4371,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3914
4371
  }, {
3915
4372
  key: "applyPaymentLifecycleChange",
3916
4373
  value: function applyPaymentLifecycleChange(tempOrder, options) {
3917
- var _this24 = this;
4374
+ var _this28 = this;
3918
4375
  this.updateTempOrderPaymentStatus(tempOrder);
3919
4376
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3920
4377
  this.persistTempOrder();
@@ -3924,7 +4381,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3924
4381
  void this.recalculateSummary({
3925
4382
  createIfMissing: true
3926
4383
  }).catch(function (error) {
3927
- _this24.logError("recalculate summary after ".concat(logContext, " failed"), {
4384
+ _this28.logError("recalculate summary after ".concat(logContext, " failed"), {
3928
4385
  error: error instanceof Error ? error.message : String(error)
3929
4386
  });
3930
4387
  });
@@ -3968,7 +4425,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3968
4425
  }, {
3969
4426
  key: "updateVoucherOrderPayments",
3970
4427
  value: function updateVoucherOrderPayments(payments, options) {
3971
- var _this25 = this;
4428
+ var _this29 = this;
3972
4429
  var tempOrder = this.ensureTempOrder();
3973
4430
  var isOrderPaymentType = function isOrderPaymentType(value) {
3974
4431
  return value === 'normal' || value === 'deposit';
@@ -4003,7 +4460,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4003
4460
  });
4004
4461
  };
4005
4462
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
4006
- return _this25.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
4463
+ return _this29.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
4007
4464
  defaultPaid: false,
4008
4465
  devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
4009
4466
  });
@@ -4056,7 +4513,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4056
4513
  void this.recalculateSummary({
4057
4514
  createIfMissing: true
4058
4515
  }).catch(function (error) {
4059
- _this25.logError('recalculate summary after updateVoucherOrderPayments failed', {
4516
+ _this29.logError('recalculate summary after updateVoucherOrderPayments failed', {
4060
4517
  error: error instanceof Error ? error.message : String(error)
4061
4518
  });
4062
4519
  });
@@ -4065,38 +4522,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4065
4522
  }, {
4066
4523
  key: "updateVoucherOrderPaymentsAsync",
4067
4524
  value: function () {
4068
- var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(payments, options) {
4525
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(payments, options) {
4069
4526
  var needsPaymentNumber, devicePrefix;
4070
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
4071
- while (1) switch (_context19.prev = _context19.next) {
4527
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4528
+ while (1) switch (_context23.prev = _context23.next) {
4072
4529
  case 0:
4073
4530
  needsPaymentNumber = (payments || []).some(function (payment) {
4074
4531
  return String(payment.payment_number || '').trim() === '';
4075
4532
  });
4076
4533
  if (!needsPaymentNumber) {
4077
- _context19.next = 7;
4534
+ _context23.next = 7;
4078
4535
  break;
4079
4536
  }
4080
- _context19.next = 4;
4537
+ _context23.next = 4;
4081
4538
  return this.getPaymentNumberDevicePrefixAsync();
4082
4539
  case 4:
4083
- _context19.t0 = _context19.sent;
4084
- _context19.next = 8;
4540
+ _context23.t0 = _context23.sent;
4541
+ _context23.next = 8;
4085
4542
  break;
4086
4543
  case 7:
4087
- _context19.t0 = 'LOCAL';
4544
+ _context23.t0 = 'LOCAL';
4088
4545
  case 8:
4089
- devicePrefix = _context19.t0;
4090
- return _context19.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
4546
+ devicePrefix = _context23.t0;
4547
+ return _context23.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
4091
4548
  devicePrefix: devicePrefix
4092
4549
  })));
4093
4550
  case 10:
4094
4551
  case "end":
4095
- return _context19.stop();
4552
+ return _context23.stop();
4096
4553
  }
4097
- }, _callee17, this);
4554
+ }, _callee21, this);
4098
4555
  }));
4099
- function updateVoucherOrderPaymentsAsync(_x17, _x18) {
4556
+ function updateVoucherOrderPaymentsAsync(_x19, _x20) {
4100
4557
  return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
4101
4558
  }
4102
4559
  return updateVoucherOrderPaymentsAsync;
@@ -4114,7 +4571,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4114
4571
  key: "shouldMergeProductToOrder",
4115
4572
  value: function shouldMergeProductToOrder(params) {
4116
4573
  var _this$orderHooks,
4117
- _this26 = this;
4574
+ _this30 = this;
4118
4575
  var onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
4119
4576
  if (!onBeforeMergeProductToOrder) return true;
4120
4577
  var result = onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
@@ -4122,7 +4579,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4122
4579
  }));
4123
4580
  if (result && _typeof(result) === 'object' && typeof result.then === 'function') {
4124
4581
  return Promise.resolve(result).then(function (resolved) {
4125
- return _this26.normalizeShouldMergeProductResult(resolved);
4582
+ return _this30.normalizeShouldMergeProductResult(resolved);
4126
4583
  });
4127
4584
  }
4128
4585
  return this.normalizeShouldMergeProductResult(result);
@@ -4142,8 +4599,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4142
4599
  }, {
4143
4600
  key: "hasLinkedBookingUid",
4144
4601
  value: function hasLinkedBookingUid(product) {
4145
- var _product$booking_uid, _product$metadata7;
4146
- var bookingUid = (_product$booking_uid = product === null || product === void 0 ? void 0 : product.booking_uid) !== null && _product$booking_uid !== void 0 ? _product$booking_uid : product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.booking_uid;
4602
+ var _product$booking_uid, _product$metadata9;
4603
+ var bookingUid = (_product$booking_uid = product === null || product === void 0 ? void 0 : product.booking_uid) !== null && _product$booking_uid !== void 0 ? _product$booking_uid : product === null || product === void 0 || (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.booking_uid;
4147
4604
  return bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '';
4148
4605
  }
4149
4606
  }, {
@@ -4171,7 +4628,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4171
4628
  }, {
4172
4629
  key: "assertAndLockProductSettlement",
4173
4630
  value: function assertAndLockProductSettlement(tempOrder, product) {
4174
- var _ref60, _ref61, _product$selling_pric;
4631
+ var _ref64, _ref65, _product$selling_pric;
4175
4632
  if (!this.isMultiCurrencySettlementEnabled()) return;
4176
4633
  var currentKey = getTempOrderSettlementKey(tempOrder);
4177
4634
  var incomingKey = getSettlementKey(getSelectedSettlementSnapshot(product)) || 'legal_currency';
@@ -4198,7 +4655,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4198
4655
  }
4199
4656
  applyTempOrderSettlementState(tempOrder, snapshot || {
4200
4657
  settlement_type: 'legal_currency',
4201
- price: (_ref60 = (_ref61 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.original_price) !== null && _ref61 !== void 0 ? _ref61 : product.payment_price) !== null && _ref60 !== void 0 ? _ref60 : 0,
4658
+ price: (_ref64 = (_ref65 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.original_price) !== null && _ref65 !== void 0 ? _ref65 : product.payment_price) !== null && _ref64 !== void 0 ? _ref64 : 0,
4202
4659
  unit_label: tempOrder.currency_code,
4203
4660
  symbol: tempOrder.currency_symbol,
4204
4661
  amount_format: tempOrder.currency_format
@@ -4251,45 +4708,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4251
4708
  }, {
4252
4709
  key: "finalizeProductOrderMutation",
4253
4710
  value: function () {
4254
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(tempOrder, options) {
4255
- var isVirtualSettlement;
4256
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
4257
- while (1) switch (_context20.prev = _context20.next) {
4711
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(tempOrder, options) {
4712
+ var isVirtualSettlement, promotionPayload;
4713
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4714
+ while (1) switch (_context24.prev = _context24.next) {
4258
4715
  case 0:
4259
4716
  this.syncTempOrderHolderFromBookings(tempOrder);
4260
4717
  this.prepareVirtualSettlementTempOrder(tempOrder);
4261
4718
  isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
4262
4719
  if (!(!(options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) && !isVirtualSettlement)) {
4263
- _context20.next = 6;
4720
+ _context24.next = 6;
4264
4721
  break;
4265
4722
  }
4266
- _context20.next = 6;
4723
+ _context24.next = 6;
4267
4724
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
4268
4725
  case 6:
4269
4726
  if (!(!(options !== null && options !== void 0 && options.skipDiscountRecalculation) && !isVirtualSettlement)) {
4270
- _context20.next = 9;
4727
+ _context24.next = 12;
4271
4728
  break;
4272
4729
  }
4273
- _context20.next = 9;
4274
- return this.applyPromotion();
4730
+ _context24.next = 9;
4731
+ return this.evaluatePromotion();
4275
4732
  case 9:
4733
+ _context24.t0 = _context24.sent;
4734
+ _context24.next = 13;
4735
+ break;
4736
+ case 12:
4737
+ _context24.t0 = null;
4738
+ case 13:
4739
+ promotionPayload = _context24.t0;
4276
4740
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation) && !isVirtualSettlement) {
4277
4741
  this.applyDiscount();
4278
4742
  }
4279
4743
  this.sanitizeTempOrderProducts(tempOrder);
4280
- _context20.next = 13;
4744
+ _context24.next = 18;
4281
4745
  return this.recalculateSummary({
4282
4746
  createIfMissing: true
4283
4747
  });
4284
- case 13:
4748
+ case 18:
4285
4749
  this.persistTempOrder();
4286
- case 14:
4750
+ this.emitPromotionApplied(promotionPayload);
4751
+ case 20:
4287
4752
  case "end":
4288
- return _context20.stop();
4753
+ return _context24.stop();
4289
4754
  }
4290
- }, _callee18, this);
4755
+ }, _callee22, this);
4291
4756
  }));
4292
- function finalizeProductOrderMutation(_x19, _x20) {
4757
+ function finalizeProductOrderMutation(_x21, _x22) {
4293
4758
  return _finalizeProductOrderMutation.apply(this, arguments);
4294
4759
  }
4295
4760
  return finalizeProductOrderMutation;
@@ -4315,7 +4780,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4315
4780
  _metadata,
4316
4781
  _productToAdd$metadat,
4317
4782
  _origin,
4318
- _this27 = this;
4783
+ _this31 = this;
4319
4784
  var linked = booking ? this.createLinkedProductAndBooking({
4320
4785
  product: product,
4321
4786
  booking: booking
@@ -4351,26 +4816,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4351
4816
  var isIncomingCustomItem = ((_productToAdd$metadat = productToAdd.metadata) === null || _productToAdd$metadat === void 0 || (_productToAdd$metadat = _productToAdd$metadat.origin) === null || _productToAdd$metadat === void 0 ? void 0 : _productToAdd$metadat.isCustomItem) === true || ((_origin = productToAdd._origin) === null || _origin === void 0 ? void 0 : _origin.isCustomItem) === true;
4352
4817
  var shouldForceNewLine = disableMerge || !!booking || hasIncomingGoodPass || isIncomingPersistedEntitlementPass || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4353
4818
  var matchedIndex = shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4354
- if (_this27.hasGoodPassDiscount(item)) return false;
4355
- var isRuntimeEntitlementPass = _this27.isRuntimeEntitlementAppend(item, tempOrder);
4819
+ if (_this31.hasGoodPassDiscount(item)) return false;
4820
+ var isRuntimeEntitlementPass = _this31.isRuntimeEntitlementAppend(item, tempOrder);
4356
4821
  if (isIncomingEntitlementAppend !== isRuntimeEntitlementPass) {
4357
4822
  return false;
4358
4823
  }
4359
- if (isIncomingEntitlementAppend && _this27.isPersistedProductLine(item)) {
4824
+ if (isIncomingEntitlementAppend && _this31.isPersistedProductLine(item)) {
4360
4825
  return false;
4361
4826
  }
4362
- var hasExistingProductNote = _this27.hasOrderProductLineNote(item);
4827
+ var hasExistingProductNote = _this31.hasOrderProductLineNote(item);
4363
4828
  if ((hasIncomingProductNote || hasExistingProductNote) && (!isRuntimeEntitlementPass || String(normalizedIncoming.note || '').trim() !== String(item.note || '').trim())) {
4364
4829
  return false;
4365
4830
  }
4366
4831
  var hasExistingManualProductDiscount = isManualProductDiscountProduct(item);
4367
- if (isRuntimeEntitlementPass && !_this27.hasSameEntitlementMergePriceConfig(normalizedIncoming, item)) {
4832
+ if (isRuntimeEntitlementPass && !_this31.hasSameEntitlementMergePriceConfig(normalizedIncoming, item)) {
4368
4833
  return false;
4369
4834
  }
4370
4835
  if ((hasIncomingManualProductDiscount || hasExistingManualProductDiscount) && !isRuntimeEntitlementPass) {
4371
4836
  return false;
4372
4837
  }
4373
- if (_this27.isPersistedProductLine(item)) return false;
4838
+ if (_this31.isPersistedProductLine(item)) return false;
4374
4839
  if (item.product_id !== productToAdd.product_id) return false;
4375
4840
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
4376
4841
  var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
@@ -4379,8 +4844,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4379
4844
  var matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
4380
4845
  var existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
4381
4846
  var commitProductLine = function commitProductLine(shouldMerge) {
4847
+ var committedProduct;
4382
4848
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
4383
- _this27.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4849
+ _this31.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4384
4850
  if (linked) {
4385
4851
  normalizedIncoming.booking_uid = linked.bookingUid;
4386
4852
  normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
@@ -4393,11 +4859,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4393
4859
  } else {
4394
4860
  tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
4395
4861
  }
4862
+ committedProduct = normalizedIncoming;
4396
4863
  } else {
4397
4864
  var _targetProduct$metada;
4398
4865
  var targetProduct = matchedProduct;
4399
4866
  var targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
4400
- var normalizedProduct = _this27.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4867
+ var normalizedProduct = _this31.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4401
4868
  metadata: _objectSpread(_objectSpread({}, productToAdd.metadata || {}), {}, {
4402
4869
  unique_identification_number: targetUid
4403
4870
  })
@@ -4420,7 +4887,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4420
4887
  order_detail_id: targetProduct.order_detail_id,
4421
4888
  num: nextNum
4422
4889
  });
4423
- _this27.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4890
+ _this31.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4891
+ committedProduct = tempOrder.products[matchedIndex];
4424
4892
  if (matchedIndex !== tempOrder.products.length - 1) {
4425
4893
  var mergedProduct = tempOrder.products[matchedIndex];
4426
4894
  tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, matchedIndex)), _toConsumableArray(tempOrder.products.slice(matchedIndex + 1)), [mergedProduct]);
@@ -4429,10 +4897,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4429
4897
  if (linked) {
4430
4898
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
4431
4899
  }
4900
+ return committedProduct;
4432
4901
  };
4433
4902
  if (!matchedProduct) {
4434
- commitProductLine(false);
4435
- return;
4903
+ return commitProductLine(false);
4436
4904
  }
4437
4905
  var shouldMerge = this.shouldMergeProductToOrder({
4438
4906
  incomingProduct: productToAdd,
@@ -4447,7 +4915,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4447
4915
  if (shouldMerge && _typeof(shouldMerge) === 'object' && typeof shouldMerge.then === 'function') {
4448
4916
  return Promise.resolve(shouldMerge).then(commitProductLine);
4449
4917
  }
4450
- commitProductLine(shouldMerge);
4918
+ return commitProductLine(shouldMerge);
4451
4919
  }
4452
4920
 
4453
4921
  /**
@@ -4457,14 +4925,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4457
4925
  }, {
4458
4926
  key: "createSplitBookingLine",
4459
4927
  value: function createSplitBookingLine(product, booking, index, splitCount) {
4460
- var _booking$metadata6, _ref62, _ref63, _bookingHolder$form_r, _booking$metadata7, _product$metadata8, _bookingHolder$name, _singleBooking$metada;
4928
+ var _booking$metadata6, _ref66, _ref67, _bookingHolder$form_r, _booking$metadata7, _product$metadata10, _bookingHolder$name, _singleBooking$metada;
4461
4929
  var singleLine = cloneDeep(product);
4462
4930
  singleLine.num = 1;
4463
4931
  delete singleLine.product_quantity;
4464
4932
  var singleBooking = cloneDeep(booking);
4465
4933
  var bookingHolder = booking !== null && booking !== void 0 && booking.holder && _typeof(booking.holder) === 'object' ? booking.holder : null;
4466
4934
  var metadataHolder = booking !== null && booking !== void 0 && (_booking$metadata6 = booking.metadata) !== null && _booking$metadata6 !== void 0 && _booking$metadata6.holder && _typeof(booking.metadata.holder) === 'object' ? booking.metadata.holder : null;
4467
- var rawHolderIds = (_ref62 = (_ref63 = (_bookingHolder$form_r = bookingHolder === null || bookingHolder === void 0 ? void 0 : bookingHolder.form_record) !== null && _bookingHolder$form_r !== void 0 ? _bookingHolder$form_r : booking === null || booking === void 0 || (_booking$metadata7 = booking.metadata) === null || _booking$metadata7 === void 0 ? void 0 : _booking$metadata7.holder_id) !== null && _ref63 !== void 0 ? _ref63 : metadataHolder === null || metadataHolder === void 0 ? void 0 : metadataHolder.form_record) !== null && _ref62 !== void 0 ? _ref62 : product === null || product === void 0 || (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.holder_id;
4935
+ var rawHolderIds = (_ref66 = (_ref67 = (_bookingHolder$form_r = bookingHolder === null || bookingHolder === void 0 ? void 0 : bookingHolder.form_record) !== null && _bookingHolder$form_r !== void 0 ? _bookingHolder$form_r : booking === null || booking === void 0 || (_booking$metadata7 = booking.metadata) === null || _booking$metadata7 === void 0 ? void 0 : _booking$metadata7.holder_id) !== null && _ref67 !== void 0 ? _ref67 : metadataHolder === null || metadataHolder === void 0 ? void 0 : metadataHolder.form_record) !== null && _ref66 !== void 0 ? _ref66 : product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.holder_id;
4468
4936
  var holderIds = (Array.isArray(rawHolderIds) ? rawHolderIds : [rawHolderIds]).map(function (holderId) {
4469
4937
  return holderId && _typeof(holderId) === 'object' ? holderId.form_record_id : holderId;
4470
4938
  }).filter(function (holderId) {
@@ -4528,12 +4996,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4528
4996
  }, {
4529
4997
  key: "addProductToOrder",
4530
4998
  value: (function () {
4531
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(product, booking, options) {
4532
- var tempOrder, insertAfterProductUid, anchorIndex, insertAtIndex, _ref64, _productRecord$num, productRecord, splitCount, i, splitLine, _appendResult, appendResult;
4533
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
4534
- while (1) switch (_context21.prev = _context21.next) {
4999
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(product, booking, options) {
5000
+ var _this32 = this;
5001
+ var tempOrder, salesNoteDrafts, mutationSnapshot, attachSalesNoteDrafts, rollbackProductAndNotesMutation, insertAfterProductUid, anchorIndex, insertAtIndex, _ref68, _productRecord$num, productRecord, splitCount, i, splitLine, committedProduct, _committedProduct, _committedProduct2;
5002
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
5003
+ while (1) switch (_context25.prev = _context25.next) {
4535
5004
  case 0:
4536
5005
  tempOrder = this.ensureTempOrder();
5006
+ salesNoteDrafts = ((options === null || options === void 0 ? void 0 : options.salesNotes) || []).map(function (draft) {
5007
+ return {
5008
+ note_type: String(draft.note_type || '').trim(),
5009
+ text: {
5010
+ kind: 'resolved',
5011
+ text: buildSalesNoteText(draft.text)
5012
+ }
5013
+ };
5014
+ });
5015
+ mutationSnapshot = salesNoteDrafts.length > 0 ? {
5016
+ products: cloneDeep(tempOrder.products || []),
5017
+ bookings: cloneDeep(tempOrder.bookings || []),
5018
+ notes: cloneDeep(tempOrder.notes || []),
5019
+ extend: cloneDeep(tempOrder._extend || {})
5020
+ } : null;
5021
+ attachSalesNoteDrafts = function attachSalesNoteDrafts(orderProduct) {
5022
+ var _orderProduct$metadat;
5023
+ if (!salesNoteDrafts.length) return;
5024
+ var productLineUid = ((_orderProduct$metadat = orderProduct.metadata) === null || _orderProduct$metadat === void 0 ? void 0 : _orderProduct$metadat.unique_identification_number) || orderProduct.unique_identification_number;
5025
+ if (!productLineUid) {
5026
+ throw new Error('[Order Notes] 商品行缺少 unique_identification_number');
5027
+ }
5028
+ salesNoteDrafts.forEach(function (draft) {
5029
+ _this32.setSalesNoteOnTempOrder(tempOrder, {
5030
+ note_type: draft.note_type,
5031
+ target: {
5032
+ target_type: 'order_detail',
5033
+ target_uuid: String(productLineUid)
5034
+ },
5035
+ text: draft.text
5036
+ });
5037
+ });
5038
+ };
5039
+ rollbackProductAndNotesMutation = function rollbackProductAndNotesMutation() {
5040
+ if (!mutationSnapshot) return;
5041
+ tempOrder.products = mutationSnapshot.products;
5042
+ tempOrder.bookings = mutationSnapshot.bookings;
5043
+ tempOrder.notes = mutationSnapshot.notes;
5044
+ tempOrder._extend = mutationSnapshot.extend;
5045
+ };
4537
5046
  insertAfterProductUid = options === null || options === void 0 ? void 0 : options.insertAfterProductUid;
4538
5047
  anchorIndex = booking && insertAfterProductUid ? tempOrder.products.findIndex(function (line) {
4539
5048
  var _line$metadata;
@@ -4541,71 +5050,99 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4541
5050
  return uid !== undefined && uid !== null && String(uid) === String(insertAfterProductUid);
4542
5051
  }) : -1;
4543
5052
  insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
5053
+ _context25.prev = 8;
4544
5054
  if (!booking) {
4545
- _context21.next = 22;
5055
+ _context25.next = 33;
4546
5056
  break;
4547
5057
  }
4548
5058
  productRecord = product;
4549
- splitCount = getSafeProductNum((_ref64 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref64 !== void 0 ? _ref64 : 1);
5059
+ splitCount = getSafeProductNum((_ref68 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref68 !== void 0 ? _ref68 : 1);
4550
5060
  if (!(splitCount > 1)) {
4551
- _context21.next = 22;
5061
+ _context25.next = 27;
4552
5062
  break;
4553
5063
  }
4554
5064
  i = 0;
4555
- case 9:
5065
+ case 14:
4556
5066
  if (!(i < splitCount)) {
4557
- _context21.next = 19;
5067
+ _context25.next = 25;
4558
5068
  break;
4559
5069
  }
4560
5070
  splitLine = this.createSplitBookingLine(productRecord, booking, i, splitCount);
4561
- _appendResult = this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking, {
5071
+ if (i > 0) {
5072
+ delete splitLine.product.unique_identification_number;
5073
+ delete splitLine.product.identity_key;
5074
+ if (splitLine.product.metadata) {
5075
+ splitLine.product.metadata = _objectSpread({}, splitLine.product.metadata);
5076
+ delete splitLine.product.metadata.unique_identification_number;
5077
+ delete splitLine.product.metadata.identity_key;
5078
+ }
5079
+ delete splitLine.booking.booking_uid;
5080
+ if (splitLine.booking.metadata) {
5081
+ splitLine.booking.metadata = _objectSpread({}, splitLine.booking.metadata);
5082
+ delete splitLine.booking.metadata.unique_identification_number;
5083
+ }
5084
+ }
5085
+ _context25.next = 19;
5086
+ return this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking, {
4562
5087
  insertAtIndex: insertAtIndex,
4563
5088
  disableMerge: options === null || options === void 0 ? void 0 : options.disableMerge
4564
5089
  });
4565
- if (!_appendResult) {
4566
- _context21.next = 15;
4567
- break;
4568
- }
4569
- _context21.next = 15;
4570
- return _appendResult;
4571
- case 15:
5090
+ case 19:
5091
+ committedProduct = _context25.sent;
5092
+ attachSalesNoteDrafts(committedProduct);
4572
5093
  if (insertAtIndex !== undefined) insertAtIndex += 1;
4573
- case 16:
5094
+ case 22:
4574
5095
  i += 1;
4575
- _context21.next = 9;
5096
+ _context25.next = 14;
4576
5097
  break;
4577
- case 19:
4578
- _context21.next = 21;
4579
- return this.finalizeProductOrderMutation(tempOrder);
4580
- case 21:
4581
- return _context21.abrupt("return", tempOrder.products);
4582
- case 22:
4583
- appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking, {
5098
+ case 25:
5099
+ _context25.next = 31;
5100
+ break;
5101
+ case 27:
5102
+ _context25.next = 29;
5103
+ return this.appendProductLineToTempOrder(tempOrder, product, cloneDeep(booking), {
4584
5104
  insertAtIndex: insertAtIndex,
4585
5105
  disableMerge: options === null || options === void 0 ? void 0 : options.disableMerge
4586
5106
  });
4587
- if (!appendResult) {
4588
- _context21.next = 26;
4589
- break;
4590
- }
4591
- _context21.next = 26;
4592
- return appendResult;
4593
- case 26:
4594
- _context21.next = 28;
5107
+ case 29:
5108
+ _committedProduct = _context25.sent;
5109
+ attachSalesNoteDrafts(_committedProduct);
5110
+ case 31:
5111
+ _context25.next = 37;
5112
+ break;
5113
+ case 33:
5114
+ _context25.next = 35;
5115
+ return this.appendProductLineToTempOrder(tempOrder, product, undefined, {
5116
+ insertAtIndex: insertAtIndex,
5117
+ disableMerge: options === null || options === void 0 ? void 0 : options.disableMerge
5118
+ });
5119
+ case 35:
5120
+ _committedProduct2 = _context25.sent;
5121
+ attachSalesNoteDrafts(_committedProduct2);
5122
+ case 37:
5123
+ _context25.next = 43;
5124
+ break;
5125
+ case 39:
5126
+ _context25.prev = 39;
5127
+ _context25.t0 = _context25["catch"](8);
5128
+ rollbackProductAndNotesMutation();
5129
+ throw _context25.t0;
5130
+ case 43:
5131
+ _context25.next = 45;
4595
5132
  return this.finalizeProductOrderMutation(tempOrder);
4596
- case 28:
5133
+ case 45:
4597
5134
  this.logInfo('addProductToOrder success', {
4598
5135
  product_id: product.product_id,
4599
5136
  with_booking: !!booking
4600
5137
  });
4601
- return _context21.abrupt("return", tempOrder.products);
4602
- case 30:
5138
+ return _context25.abrupt("return", tempOrder.products);
5139
+ case 47:
4603
5140
  case "end":
4604
- return _context21.stop();
5141
+ return _context25.stop();
4605
5142
  }
4606
- }, _callee19, this);
5143
+ }, _callee23, this, [[8, 39]]);
4607
5144
  }));
4608
- function addProductToOrder(_x21, _x22, _x23) {
5145
+ function addProductToOrder(_x23, _x24, _x25) {
4609
5146
  return _addProductToOrder.apply(this, arguments);
4610
5147
  }
4611
5148
  return addProductToOrder;
@@ -4623,101 +5160,101 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4623
5160
  }, {
4624
5161
  key: "addProductsToOrder",
4625
5162
  value: (function () {
4626
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(items, options) {
4627
- var tempOrder, _iterator20, _step20, item, product, booking, _ref65, _productRecord$num2, productRecord, splitCount, i, splitLine, _appendResult2, appendResult;
4628
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4629
- while (1) switch (_context22.prev = _context22.next) {
5163
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(items, options) {
5164
+ var tempOrder, _iterator20, _step20, item, product, booking, _ref69, _productRecord$num2, productRecord, splitCount, i, splitLine, _appendResult, appendResult;
5165
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
5166
+ while (1) switch (_context26.prev = _context26.next) {
4630
5167
  case 0:
4631
5168
  tempOrder = this.ensureTempOrder();
4632
5169
  if (!(!Array.isArray(items) || items.length === 0)) {
4633
- _context22.next = 3;
5170
+ _context26.next = 3;
4634
5171
  break;
4635
5172
  }
4636
- return _context22.abrupt("return", tempOrder.products);
5173
+ return _context26.abrupt("return", tempOrder.products);
4637
5174
  case 3:
4638
5175
  _iterator20 = _createForOfIteratorHelper(items || []);
4639
- _context22.prev = 4;
5176
+ _context26.prev = 4;
4640
5177
  _iterator20.s();
4641
5178
  case 6:
4642
5179
  if ((_step20 = _iterator20.n()).done) {
4643
- _context22.next = 32;
5180
+ _context26.next = 32;
4644
5181
  break;
4645
5182
  }
4646
5183
  item = _step20.value;
4647
5184
  product = item.product, booking = item.booking;
4648
5185
  if (product) {
4649
- _context22.next = 11;
5186
+ _context26.next = 11;
4650
5187
  break;
4651
5188
  }
4652
- return _context22.abrupt("continue", 30);
5189
+ return _context26.abrupt("continue", 30);
4653
5190
  case 11:
4654
5191
  if (!booking) {
4655
- _context22.next = 26;
5192
+ _context26.next = 26;
4656
5193
  break;
4657
5194
  }
4658
5195
  productRecord = product;
4659
- splitCount = getSafeProductNum((_ref65 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref65 !== void 0 ? _ref65 : 1);
5196
+ splitCount = getSafeProductNum((_ref69 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref69 !== void 0 ? _ref69 : 1);
4660
5197
  if (!(splitCount > 1)) {
4661
- _context22.next = 26;
5198
+ _context26.next = 26;
4662
5199
  break;
4663
5200
  }
4664
5201
  i = 0;
4665
5202
  case 16:
4666
5203
  if (!(i < splitCount)) {
4667
- _context22.next = 25;
5204
+ _context26.next = 25;
4668
5205
  break;
4669
5206
  }
4670
5207
  splitLine = this.createSplitBookingLine(productRecord, booking, i, splitCount);
4671
- _appendResult2 = this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking);
4672
- if (!_appendResult2) {
4673
- _context22.next = 22;
5208
+ _appendResult = this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking);
5209
+ if (!_appendResult) {
5210
+ _context26.next = 22;
4674
5211
  break;
4675
5212
  }
4676
- _context22.next = 22;
4677
- return _appendResult2;
5213
+ _context26.next = 22;
5214
+ return _appendResult;
4678
5215
  case 22:
4679
5216
  i += 1;
4680
- _context22.next = 16;
5217
+ _context26.next = 16;
4681
5218
  break;
4682
5219
  case 25:
4683
- return _context22.abrupt("continue", 30);
5220
+ return _context26.abrupt("continue", 30);
4684
5221
  case 26:
4685
5222
  appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking);
4686
5223
  if (!appendResult) {
4687
- _context22.next = 30;
5224
+ _context26.next = 30;
4688
5225
  break;
4689
5226
  }
4690
- _context22.next = 30;
5227
+ _context26.next = 30;
4691
5228
  return appendResult;
4692
5229
  case 30:
4693
- _context22.next = 6;
5230
+ _context26.next = 6;
4694
5231
  break;
4695
5232
  case 32:
4696
- _context22.next = 37;
5233
+ _context26.next = 37;
4697
5234
  break;
4698
5235
  case 34:
4699
- _context22.prev = 34;
4700
- _context22.t0 = _context22["catch"](4);
4701
- _iterator20.e(_context22.t0);
5236
+ _context26.prev = 34;
5237
+ _context26.t0 = _context26["catch"](4);
5238
+ _iterator20.e(_context26.t0);
4702
5239
  case 37:
4703
- _context22.prev = 37;
5240
+ _context26.prev = 37;
4704
5241
  _iterator20.f();
4705
- return _context22.finish(37);
5242
+ return _context26.finish(37);
4706
5243
  case 40:
4707
- _context22.next = 42;
5244
+ _context26.next = 42;
4708
5245
  return this.finalizeProductOrderMutation(tempOrder, options);
4709
5246
  case 42:
4710
5247
  this.logInfo('addProductsToOrder success', {
4711
5248
  itemsCount: items.length
4712
5249
  });
4713
- return _context22.abrupt("return", tempOrder.products);
5250
+ return _context26.abrupt("return", tempOrder.products);
4714
5251
  case 44:
4715
5252
  case "end":
4716
- return _context22.stop();
5253
+ return _context26.stop();
4717
5254
  }
4718
- }, _callee20, this, [[4, 34, 37, 40]]);
5255
+ }, _callee24, this, [[4, 34, 37, 40]]);
4719
5256
  }));
4720
- function addProductsToOrder(_x24, _x25) {
5257
+ function addProductsToOrder(_x26, _x27) {
4721
5258
  return _addProductsToOrder.apply(this, arguments);
4722
5259
  }
4723
5260
  return addProductsToOrder;
@@ -4754,41 +5291,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4754
5291
  }, {
4755
5292
  key: "isPersistedProductLine",
4756
5293
  value: function isPersistedProductLine(product) {
4757
- var _product$metadata9;
4758
- return product.order_detail_id !== undefined && product.order_detail_id !== null && product.order_detail_id !== '' || ((_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.is_edit_for_runtime) === true;
5294
+ var _product$metadata11;
5295
+ return product.order_detail_id !== undefined && product.order_detail_id !== null && product.order_detail_id !== '' || ((_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.is_edit_for_runtime) === true;
4759
5296
  }
4760
5297
  }, {
4761
5298
  key: "isRuntimeEntitlementAppend",
4762
5299
  value: function isRuntimeEntitlementAppend(product, tempOrder) {
4763
- var _product$metadata$uni, _product$metadata10, _tempOrder$_extend9, _product$_origin;
5300
+ var _product$metadata$uni, _product$metadata12, _tempOrder$_extend10, _product$_origin;
4764
5301
  if (this.isPersistedProductLine(product)) return false;
4765
- var uid = (_product$metadata$uni = (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number) !== null && _product$metadata$uni !== void 0 ? _product$metadata$uni : product.unique_identification_number;
4766
- var storedOrigin = uid !== undefined && uid !== null && uid !== '' ? (_tempOrder$_extend9 = tempOrder._extend) === null || _tempOrder$_extend9 === void 0 || (_tempOrder$_extend9 = _tempOrder$_extend9.productsByUid) === null || _tempOrder$_extend9 === void 0 || (_tempOrder$_extend9 = _tempOrder$_extend9[String(uid)]) === null || _tempOrder$_extend9 === void 0 ? void 0 : _tempOrder$_extend9.origin : undefined;
5302
+ var uid = (_product$metadata$uni = (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) !== null && _product$metadata$uni !== void 0 ? _product$metadata$uni : product.unique_identification_number;
5303
+ var storedOrigin = uid !== undefined && uid !== null && uid !== '' ? (_tempOrder$_extend10 = tempOrder._extend) === null || _tempOrder$_extend10 === void 0 || (_tempOrder$_extend10 = _tempOrder$_extend10.productsByUid) === null || _tempOrder$_extend10 === void 0 || (_tempOrder$_extend10 = _tempOrder$_extend10[String(uid)]) === null || _tempOrder$_extend10 === void 0 ? void 0 : _tempOrder$_extend10.origin : undefined;
4767
5304
  return Boolean((product === null || product === void 0 || (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.__entitlementPassRuntimeAppend) === true || (storedOrigin === null || storedOrigin === void 0 ? void 0 : storedOrigin.__entitlementPassRuntimeAppend) === true);
4768
5305
  }
4769
5306
  }, {
4770
5307
  key: "hasSameEntitlementMergePriceConfig",
4771
5308
  value: function hasSameEntitlementMergePriceConfig(incoming, existing) {
4772
- var _this28 = this;
5309
+ var _this33 = this;
4773
5310
  var buildPriceConfig = function buildPriceConfig(product) {
4774
5311
  var metadata = product.metadata || {};
4775
5312
  var bundle = (product.product_bundle || []).map(function (item) {
4776
- var _ref66, _item$bundle_id, _ref67, _ref68, _item$bundle_product_, _ref69, _item$bundle_variant_, _ref70, _item$price_type, _ref71, _item$price_type_ext;
5313
+ var _ref70, _item$bundle_id, _ref71, _ref72, _item$bundle_product_, _ref73, _item$bundle_variant_, _ref74, _item$price_type, _ref75, _item$price_type_ext;
4777
5314
  return {
4778
- bundle_id: (_ref66 = (_item$bundle_id = item.bundle_id) !== null && _item$bundle_id !== void 0 ? _item$bundle_id : item.id) !== null && _ref66 !== void 0 ? _ref66 : null,
4779
- bundle_product_id: (_ref67 = (_ref68 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref68 !== void 0 ? _ref68 : item.product_id) !== null && _ref67 !== void 0 ? _ref67 : null,
4780
- bundle_variant_id: (_ref69 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.product_variant_id) !== null && _ref69 !== void 0 ? _ref69 : 0,
4781
- price_type: (_ref70 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref70 !== void 0 ? _ref70 : '',
4782
- price_type_ext: (_ref71 = (_item$price_type_ext = item.price_type_ext) !== null && _item$price_type_ext !== void 0 ? _item$price_type_ext : item.custom_price_type_ext) !== null && _ref71 !== void 0 ? _ref71 : ''
5315
+ bundle_id: (_ref70 = (_item$bundle_id = item.bundle_id) !== null && _item$bundle_id !== void 0 ? _item$bundle_id : item.id) !== null && _ref70 !== void 0 ? _ref70 : null,
5316
+ bundle_product_id: (_ref71 = (_ref72 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref72 !== void 0 ? _ref72 : item.product_id) !== null && _ref71 !== void 0 ? _ref71 : null,
5317
+ bundle_variant_id: (_ref73 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.product_variant_id) !== null && _ref73 !== void 0 ? _ref73 : 0,
5318
+ price_type: (_ref74 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref74 !== void 0 ? _ref74 : '',
5319
+ price_type_ext: (_ref75 = (_item$price_type_ext = item.price_type_ext) !== null && _item$price_type_ext !== void 0 ? _item$price_type_ext : item.custom_price_type_ext) !== null && _ref75 !== void 0 ? _ref75 : ''
4783
5320
  };
4784
5321
  }).sort(function (left, right) {
4785
5322
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
4786
5323
  });
4787
5324
  return JSON.stringify({
4788
- original_price: _this28.normalizeFingerprintMoney(product.original_price),
4789
- source_product_price: _this28.normalizeFingerprintMoney(metadata.source_product_price),
4790
- main_product_original_price: _this28.normalizeFingerprintMoney(metadata.main_product_original_price),
4791
- price_override: _this28.normalizeFingerprintMoney(metadata.price_override),
5325
+ original_price: _this33.normalizeFingerprintMoney(product.original_price),
5326
+ source_product_price: _this33.normalizeFingerprintMoney(metadata.source_product_price),
5327
+ main_product_original_price: _this33.normalizeFingerprintMoney(metadata.main_product_original_price),
5328
+ price_override: _this33.normalizeFingerprintMoney(metadata.price_override),
4792
5329
  is_manual_discount: Boolean(metadata.is_manual_discount),
4793
5330
  bundle: bundle
4794
5331
  });
@@ -4798,24 +5335,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4798
5335
  }, {
4799
5336
  key: "getBundleRuntimeIdentity",
4800
5337
  value: function getBundleRuntimeIdentity(bundle) {
4801
- var _ref72, _bundle$bundle_id2, _ref73, _bundle$bundle_group_2, _ref74, _ref75, _bundle$bundle_produc3, _ref76, _bundle$bundle_varian3;
5338
+ var _ref76, _bundle$bundle_id2, _ref77, _bundle$bundle_group_2, _ref78, _ref79, _bundle$bundle_produc3, _ref80, _bundle$bundle_varian3;
4802
5339
  if (!bundle || _typeof(bundle) !== 'object') return '';
4803
- return [(_ref72 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref72 !== void 0 ? _ref72 : '', (_ref73 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref73 !== void 0 ? _ref73 : '', (_ref74 = (_ref75 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref75 !== void 0 ? _ref75 : bundle.product_id) !== null && _ref74 !== void 0 ? _ref74 : '', (_ref76 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref76 !== void 0 ? _ref76 : 0].join('|');
5340
+ return [(_ref76 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref76 !== void 0 ? _ref76 : '', (_ref77 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref77 !== void 0 ? _ref77 : '', (_ref78 = (_ref79 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref79 !== void 0 ? _ref79 : bundle.product_id) !== null && _ref78 !== void 0 ? _ref78 : '', (_ref80 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref80 !== void 0 ? _ref80 : 0].join('|');
4804
5341
  }
4805
5342
  }, {
4806
5343
  key: "preservePersistedBundlePriceFields",
4807
5344
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4808
- var _this29 = this;
5345
+ var _this34 = this;
4809
5346
  if (!Array.isArray(nextBundles)) return nextBundles;
4810
5347
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4811
5348
  var previousByIdentity = new Map();
4812
5349
  previousBundles.forEach(function (bundle) {
4813
- var identity = _this29.getBundleRuntimeIdentity(bundle);
5350
+ var identity = _this34.getBundleRuntimeIdentity(bundle);
4814
5351
  if (identity) previousByIdentity.set(identity, bundle);
4815
5352
  });
4816
5353
  return nextBundles.map(function (bundle, index) {
4817
5354
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4818
- var previous = previousByIdentity.get(_this29.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
5355
+ var previous = previousByIdentity.get(_this34.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4819
5356
  if (!previous || _typeof(previous) !== 'object') return bundle;
4820
5357
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4821
5358
  cover: previous.cover
@@ -4951,13 +5488,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4951
5488
  delete nextProduct.metadata.main_product_original_price;
4952
5489
  delete nextProduct.metadata.price_schema_version;
4953
5490
  } else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
4954
- var _ref77, _targetProduct$metada10, _targetProduct$metada11, _ref78, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
5491
+ var _ref81, _targetProduct$metada10, _targetProduct$metada11, _ref82, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
4955
5492
  // 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
4956
5493
  // 但必须让 original 与 selling 一起随新的 option 金额移动。
4957
5494
  var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
4958
5495
  var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
4959
- var _previousMainOriginal = new Decimal(Number((_ref77 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref77 !== void 0 ? _ref77 : 0) || 0);
4960
- var _previousMainSelling = new Decimal(Number((_ref78 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref78 !== void 0 ? _ref78 : _previousMainOriginal.toNumber()) || 0);
5496
+ var _previousMainOriginal = new Decimal(Number((_ref81 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref81 !== void 0 ? _ref81 : 0) || 0);
5497
+ var _previousMainSelling = new Decimal(Number((_ref82 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref82 !== void 0 ? _ref82 : _previousMainOriginal.toNumber()) || 0);
4961
5498
  var _preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
4962
5499
  var previousSource = ((_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal.minus(previousOptionSum);
4963
5500
  var _nextMainOriginal = previousSource.plus(nextOptionSum);
@@ -5016,37 +5553,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5016
5553
  }, {
5017
5554
  key: "updateOrderProduct",
5018
5555
  value: function () {
5019
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
5020
- var tempOrder, updatedProductUid;
5021
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
5022
- while (1) switch (_context23.prev = _context23.next) {
5556
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
5557
+ var tempOrder, updatedProductUid, promotionPayload;
5558
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
5559
+ while (1) switch (_context27.prev = _context27.next) {
5023
5560
  case 0:
5024
5561
  tempOrder = this.ensureTempOrder();
5025
5562
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
5026
- _context23.next = 4;
5027
- return this.applyPromotion();
5563
+ _context27.next = 4;
5564
+ return this.evaluatePromotion();
5028
5565
  case 4:
5566
+ promotionPayload = _context27.sent;
5029
5567
  this.applyDiscount({
5030
5568
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
5031
5569
  });
5032
5570
  this.sanitizeTempOrderProducts(tempOrder);
5033
- _context23.next = 8;
5571
+ _context27.next = 9;
5034
5572
  return this.recalculateSummary({
5035
5573
  createIfMissing: true
5036
5574
  });
5037
- case 8:
5575
+ case 9:
5038
5576
  this.persistTempOrder();
5577
+ this.emitPromotionApplied(promotionPayload);
5039
5578
  this.logInfo('updateOrderProduct success', {
5040
5579
  params: params
5041
5580
  });
5042
- return _context23.abrupt("return", tempOrder.products);
5043
- case 11:
5581
+ return _context27.abrupt("return", tempOrder.products);
5582
+ case 13:
5044
5583
  case "end":
5045
- return _context23.stop();
5584
+ return _context27.stop();
5046
5585
  }
5047
- }, _callee21, this);
5586
+ }, _callee25, this);
5048
5587
  }));
5049
- function updateOrderProduct(_x26) {
5588
+ function updateOrderProduct(_x28) {
5050
5589
  return _updateOrderProduct.apply(this, arguments);
5051
5590
  }
5052
5591
  return updateOrderProduct;
@@ -5054,28 +5593,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5054
5593
  }, {
5055
5594
  key: "updateOrderProducts",
5056
5595
  value: function () {
5057
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(paramsList) {
5058
- var _this30 = this;
5596
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(paramsList) {
5597
+ var _this35 = this;
5059
5598
  var tempOrder, reapplyBookingDiscountProductUids;
5060
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
5061
- while (1) switch (_context24.prev = _context24.next) {
5599
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
5600
+ while (1) switch (_context28.prev = _context28.next) {
5062
5601
  case 0:
5063
5602
  tempOrder = this.ensureTempOrder();
5064
5603
  if (paramsList.length) {
5065
- _context24.next = 3;
5604
+ _context28.next = 3;
5066
5605
  break;
5067
5606
  }
5068
- return _context24.abrupt("return", tempOrder.products);
5607
+ return _context28.abrupt("return", tempOrder.products);
5069
5608
  case 3:
5070
5609
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
5071
- var updatedProductUid = _this30.applyOrderProductUpdateToTempOrder(tempOrder, params);
5610
+ var updatedProductUid = _this35.applyOrderProductUpdateToTempOrder(tempOrder, params);
5072
5611
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
5073
5612
  if (params.allow_booking_discount_reapply && updatedProductUid) {
5074
5613
  acc.push(String(updatedProductUid));
5075
5614
  }
5076
5615
  return acc;
5077
5616
  }, []);
5078
- _context24.next = 6;
5617
+ _context28.next = 6;
5079
5618
  return this.finalizeAfterProductsMutation(tempOrder, {
5080
5619
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
5081
5620
  });
@@ -5083,14 +5622,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5083
5622
  this.logInfo('updateOrderProduct success', {
5084
5623
  paramsList: paramsList
5085
5624
  });
5086
- return _context24.abrupt("return", tempOrder.products);
5625
+ return _context28.abrupt("return", tempOrder.products);
5087
5626
  case 8:
5088
5627
  case "end":
5089
- return _context24.stop();
5628
+ return _context28.stop();
5090
5629
  }
5091
- }, _callee22, this);
5630
+ }, _callee26, this);
5092
5631
  }));
5093
- function updateOrderProducts(_x27) {
5632
+ function updateOrderProducts(_x29) {
5094
5633
  return _updateOrderProducts.apply(this, arguments);
5095
5634
  }
5096
5635
  return updateOrderProducts;
@@ -5098,11 +5637,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5098
5637
  }, {
5099
5638
  key: "updateOrderProductQuantity",
5100
5639
  value: function () {
5101
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
5640
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
5102
5641
  var _targetProduct$metada17;
5103
- var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, isPersistedOrderLine, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance;
5104
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
5105
- while (1) switch (_context25.prev = _context25.next) {
5642
+ var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, isPersistedOrderLine, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance, isVirtualSettlement, promotionPayload;
5643
+ return _regeneratorRuntime().wrap(function _callee27$(_context29) {
5644
+ while (1) switch (_context29.prev = _context29.next) {
5106
5645
  case 0:
5107
5646
  product_id = params.product_id, product_variant_id = params.product_variant_id, num = params.num, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_sku = params.product_sku, product_bundle = params.product_bundle;
5108
5647
  tempOrder = this.ensureTempOrder();
@@ -5132,7 +5671,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5132
5671
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
5133
5672
  }
5134
5673
  if (!(productIndex === -1)) {
5135
- _context25.next = 13;
5674
+ _context29.next = 13;
5136
5675
  break;
5137
5676
  }
5138
5677
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -5148,7 +5687,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5148
5687
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
5149
5688
  settlementSnapshot = getSelectedSettlementSnapshot(normalizedProduct);
5150
5689
  if (!(this.isMultiCurrencySettlementEnabled() && (settlementSnapshot === null || settlementSnapshot === void 0 ? void 0 : settlementSnapshot.settlement_type) === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1)) {
5151
- _context25.next = 27;
5690
+ _context29.next = 27;
5152
5691
  break;
5153
5692
  }
5154
5693
  currencyProductId = Number(settlementSnapshot.currency_product_id);
@@ -5156,7 +5695,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5156
5695
  return Number(item === null || item === void 0 ? void 0 : item.product_id) === currencyProductId;
5157
5696
  });
5158
5697
  if (asset) {
5159
- _context25.next = 23;
5698
+ _context29.next = 23;
5160
5699
  break;
5161
5700
  }
5162
5701
  throw new VirtualCurrencyAssetNotFoundError(currencyProductId);
@@ -5168,40 +5707,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5168
5707
  }, new Decimal(0));
5169
5708
  balance = new Decimal(asset.balance || 0);
5170
5709
  if (!balance.lt(requiredAmount)) {
5171
- _context25.next = 27;
5710
+ _context29.next = 27;
5172
5711
  break;
5173
5712
  }
5174
5713
  throw new VirtualCurrencyBalanceError(balance.toFixed(2), requiredAmount.toFixed(2));
5175
5714
  case 27:
5176
5715
  tempOrder.products[productIndex] = normalizedProduct;
5177
5716
  this.prepareVirtualSettlementTempOrder(tempOrder);
5178
- if (this.isActiveVirtualSettlementOrder(tempOrder)) {
5179
- _context25.next = 33;
5717
+ isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
5718
+ if (isVirtualSettlement) {
5719
+ _context29.next = 36;
5180
5720
  break;
5181
5721
  }
5182
- _context25.next = 32;
5183
- return this.applyPromotion();
5184
- case 32:
5185
- this.applyDiscount();
5722
+ _context29.next = 33;
5723
+ return this.evaluatePromotion();
5186
5724
  case 33:
5725
+ _context29.t0 = _context29.sent;
5726
+ _context29.next = 37;
5727
+ break;
5728
+ case 36:
5729
+ _context29.t0 = null;
5730
+ case 37:
5731
+ promotionPayload = _context29.t0;
5732
+ if (!isVirtualSettlement) {
5733
+ this.applyDiscount();
5734
+ }
5187
5735
  this.sanitizeTempOrderProducts(tempOrder);
5188
- _context25.next = 36;
5736
+ _context29.next = 42;
5189
5737
  return this.recalculateSummary({
5190
5738
  createIfMissing: true
5191
5739
  });
5192
- case 36:
5740
+ case 42:
5193
5741
  this.persistTempOrder();
5742
+ this.emitPromotionApplied(promotionPayload);
5194
5743
  this.logInfo('updateOrderProductQuantity success', {
5195
5744
  params: params
5196
5745
  });
5197
- return _context25.abrupt("return", tempOrder.products);
5198
- case 39:
5746
+ return _context29.abrupt("return", tempOrder.products);
5747
+ case 46:
5199
5748
  case "end":
5200
- return _context25.stop();
5749
+ return _context29.stop();
5201
5750
  }
5202
- }, _callee23, this);
5751
+ }, _callee27, this);
5203
5752
  }));
5204
- function updateOrderProductQuantity(_x28) {
5753
+ function updateOrderProductQuantity(_x30) {
5205
5754
  return _updateOrderProductQuantity.apply(this, arguments);
5206
5755
  }
5207
5756
  return updateOrderProductQuantity;
@@ -5242,31 +5791,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5242
5791
  }, {
5243
5792
  key: "finalizeAfterProductsMutation",
5244
5793
  value: (function () {
5245
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(tempOrder, options) {
5246
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
5247
- while (1) switch (_context26.prev = _context26.next) {
5794
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(tempOrder, options) {
5795
+ var promotionPayload;
5796
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
5797
+ while (1) switch (_context30.prev = _context30.next) {
5248
5798
  case 0:
5249
5799
  this.syncTempOrderHolderFromBookings(tempOrder);
5250
- _context26.next = 3;
5251
- return this.applyPromotion();
5800
+ _context30.next = 3;
5801
+ return this.evaluatePromotion();
5252
5802
  case 3:
5803
+ promotionPayload = _context30.sent;
5253
5804
  this.applyDiscount({
5254
5805
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
5255
5806
  });
5256
5807
  this.sanitizeTempOrderProducts(tempOrder);
5257
- _context26.next = 7;
5808
+ _context30.next = 8;
5258
5809
  return this.recalculateSummary({
5259
5810
  createIfMissing: true
5260
5811
  });
5261
- case 7:
5262
- this.persistTempOrder();
5263
5812
  case 8:
5813
+ this.persistTempOrder();
5814
+ this.emitPromotionApplied(promotionPayload);
5815
+ case 10:
5264
5816
  case "end":
5265
- return _context26.stop();
5817
+ return _context30.stop();
5266
5818
  }
5267
- }, _callee24, this);
5819
+ }, _callee28, this);
5268
5820
  }));
5269
- function finalizeAfterProductsMutation(_x29, _x30) {
5821
+ function finalizeAfterProductsMutation(_x31, _x32) {
5270
5822
  return _finalizeAfterProductsMutation.apply(this, arguments);
5271
5823
  }
5272
5824
  return finalizeAfterProductsMutation;
@@ -5281,20 +5833,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5281
5833
  }, {
5282
5834
  key: "removeProductsFromOrder",
5283
5835
  value: (function () {
5284
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identities, options) {
5285
- var _this31 = this;
5836
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(identities, options) {
5837
+ var _this36 = this;
5286
5838
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
5287
- return _regeneratorRuntime().wrap(function _callee25$(_context28) {
5288
- while (1) switch (_context28.prev = _context28.next) {
5839
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5840
+ while (1) switch (_context32.prev = _context32.next) {
5289
5841
  case 0:
5290
5842
  tempOrder = this.ensureTempOrder();
5291
- this.repairDuplicateProductLineIdentities(tempOrder);
5292
5843
  if (identities.length) {
5293
- _context28.next = 4;
5844
+ _context32.next = 3;
5294
5845
  break;
5295
5846
  }
5296
- return _context28.abrupt("return", tempOrder.products);
5297
- case 4:
5847
+ return _context32.abrupt("return", tempOrder.products);
5848
+ case 3:
5849
+ // 商品删除会同步删除以商品行为主关系的 Notes;快照不完整时禁止产生孤儿 Relation。
5850
+ this.ensureSalesNotesLoadedForMutation(tempOrder);
5851
+ this.repairDuplicateProductLineIdentities(tempOrder);
5298
5852
  productsBeforeRemove = tempOrder.products || [];
5299
5853
  bookingsBeforeRemove = tempOrder.bookings || [];
5300
5854
  preserveDisplayPosition = options === null || options === void 0 ? void 0 : options.preserveDisplayPosition;
@@ -5323,29 +5877,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5323
5877
  }
5324
5878
  linkedBookingUidsToRemove = new Set();
5325
5879
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
5326
- _context28.prev = 15;
5880
+ _context32.prev = 16;
5327
5881
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
5328
5882
  var _metadata11, _metadata12, _metadata13, _metadata14;
5329
5883
  var product, productUid, productBookingUid, isAddTimeProduct;
5330
- return _regeneratorRuntime().wrap(function _loop3$(_context27) {
5331
- while (1) switch (_context27.prev = _context27.next) {
5884
+ return _regeneratorRuntime().wrap(function _loop3$(_context31) {
5885
+ while (1) switch (_context31.prev = _context31.next) {
5332
5886
  case 0:
5333
5887
  product = _step21.value;
5334
5888
  productUid = (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5335
5889
  productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata12 = product.metadata) === null || _metadata12 === void 0 ? void 0 : _metadata12.booking_uid);
5336
5890
  isAddTimeProduct = (product === null || product === void 0 || (_metadata13 = product.metadata) === null || _metadata13 === void 0 ? void 0 : _metadata13.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata14 = product.metadata) === null || _metadata14 === void 0 ? void 0 : _metadata14.product_add_schedule_time) !== null;
5337
5891
  if (!isAddTimeProduct) {
5338
- _context27.next = 6;
5892
+ _context31.next = 6;
5339
5893
  break;
5340
5894
  }
5341
- return _context27.abrupt("return", 1);
5895
+ return _context31.abrupt("return", 1);
5342
5896
  case 6:
5343
5897
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
5344
5898
  linkedBookingUidsToRemove.add(String(productBookingUid));
5345
5899
  }
5346
5900
  if (productUid !== undefined && productUid !== null && productUid !== '') {
5347
5901
  bookingsBeforeRemove.forEach(function (booking) {
5348
- var bookingUid = _this31.getBookingUniqueIdentificationNumber(booking);
5902
+ var bookingUid = _this36.getBookingUniqueIdentificationNumber(booking);
5349
5903
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
5350
5904
  linkedBookingUidsToRemove.add(bookingUid);
5351
5905
  }
@@ -5353,38 +5907,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5353
5907
  }
5354
5908
  case 8:
5355
5909
  case "end":
5356
- return _context27.stop();
5910
+ return _context31.stop();
5357
5911
  }
5358
5912
  }, _loop3);
5359
5913
  });
5360
5914
  _iterator21.s();
5361
- case 18:
5915
+ case 19:
5362
5916
  if ((_step21 = _iterator21.n()).done) {
5363
- _context28.next = 24;
5917
+ _context32.next = 25;
5364
5918
  break;
5365
5919
  }
5366
- return _context28.delegateYield(_loop3(), "t0", 20);
5367
- case 20:
5368
- if (!_context28.t0) {
5369
- _context28.next = 22;
5920
+ return _context32.delegateYield(_loop3(), "t0", 21);
5921
+ case 21:
5922
+ if (!_context32.t0) {
5923
+ _context32.next = 23;
5370
5924
  break;
5371
5925
  }
5372
- return _context28.abrupt("continue", 22);
5373
- case 22:
5374
- _context28.next = 18;
5926
+ return _context32.abrupt("continue", 23);
5927
+ case 23:
5928
+ _context32.next = 19;
5375
5929
  break;
5376
- case 24:
5377
- _context28.next = 29;
5930
+ case 25:
5931
+ _context32.next = 30;
5378
5932
  break;
5379
- case 26:
5380
- _context28.prev = 26;
5381
- _context28.t1 = _context28["catch"](15);
5382
- _iterator21.e(_context28.t1);
5383
- case 29:
5384
- _context28.prev = 29;
5933
+ case 27:
5934
+ _context32.prev = 27;
5935
+ _context32.t1 = _context32["catch"](16);
5936
+ _iterator21.e(_context32.t1);
5937
+ case 30:
5938
+ _context32.prev = 30;
5385
5939
  _iterator21.f();
5386
- return _context28.finish(29);
5387
- case 32:
5940
+ return _context32.finish(30);
5941
+ case 33:
5388
5942
  if (linkedBookingUidsToRemove.size > 0) {
5389
5943
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
5390
5944
  tempOrder.products = (tempOrder.products || []).filter(function (line) {
@@ -5410,20 +5964,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5410
5964
  tempOrder.products = nextProductIndex >= 0 ? [].concat(_toConsumableArray(productsWithoutRemaining.slice(0, nextProductIndex)), [remainingProduct], _toConsumableArray(productsWithoutRemaining.slice(nextProductIndex))) : [].concat(_toConsumableArray(productsWithoutRemaining), [remainingProduct]);
5411
5965
  }
5412
5966
  }
5413
- _context28.next = 36;
5967
+ this.removeSalesNotesForMissingProductLines(tempOrder);
5968
+ _context32.next = 38;
5414
5969
  return this.finalizeAfterProductsMutation(tempOrder);
5415
- case 36:
5970
+ case 38:
5416
5971
  this.logInfo('removeProductsFromOrder success', {
5417
5972
  identities: identities
5418
5973
  });
5419
- return _context28.abrupt("return", tempOrder.products);
5420
- case 38:
5974
+ return _context32.abrupt("return", tempOrder.products);
5975
+ case 40:
5421
5976
  case "end":
5422
- return _context28.stop();
5977
+ return _context32.stop();
5423
5978
  }
5424
- }, _callee25, this, [[15, 26, 29, 32]]);
5979
+ }, _callee29, this, [[16, 27, 30, 33]]);
5425
5980
  }));
5426
- function removeProductsFromOrder(_x31, _x32) {
5981
+ function removeProductsFromOrder(_x33, _x34) {
5427
5982
  return _removeProductsFromOrder.apply(this, arguments);
5428
5983
  }
5429
5984
  return removeProductsFromOrder;
@@ -5431,62 +5986,66 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5431
5986
  }, {
5432
5987
  key: "removeProductFromOrder",
5433
5988
  value: function () {
5434
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(identity, options) {
5435
- return _regeneratorRuntime().wrap(function _callee26$(_context29) {
5436
- while (1) switch (_context29.prev = _context29.next) {
5989
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(identity, options) {
5990
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5991
+ while (1) switch (_context33.prev = _context33.next) {
5437
5992
  case 0:
5438
- return _context29.abrupt("return", this.removeProductsFromOrder([identity], options));
5993
+ return _context33.abrupt("return", this.removeProductsFromOrder([identity], options));
5439
5994
  case 1:
5440
5995
  case "end":
5441
- return _context29.stop();
5996
+ return _context33.stop();
5442
5997
  }
5443
- }, _callee26, this);
5998
+ }, _callee30, this);
5444
5999
  }));
5445
- function removeProductFromOrder(_x33, _x34) {
6000
+ function removeProductFromOrder(_x35, _x36) {
5446
6001
  return _removeProductFromOrder.apply(this, arguments);
5447
6002
  }
5448
6003
  return removeProductFromOrder;
5449
6004
  }()
5450
6005
  /**
5451
6006
  * 仅清空购物车行(products / bookings),不重置整单。
5452
- * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
6007
+ * 普通整单 note 保持不变;以商品行为主体的 Sales Notes 同步删除。
5453
6008
  */
5454
6009
  }, {
5455
6010
  key: "clearOrderCartLines",
5456
6011
  value: (function () {
5457
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
5458
- var tempOrder;
5459
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
5460
- while (1) switch (_context30.prev = _context30.next) {
6012
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
6013
+ var tempOrder, promotionPayload;
6014
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
6015
+ while (1) switch (_context34.prev = _context34.next) {
5461
6016
  case 0:
5462
6017
  tempOrder = this.ensureTempOrder();
6018
+ this.ensureSalesNotesLoadedForMutation(tempOrder);
5463
6019
  tempOrder.products = [];
5464
6020
  tempOrder.bookings = [];
5465
6021
  releaseTempOrderSettlementState(tempOrder);
6022
+ this.removeSalesNotesForMissingProductLines(tempOrder);
5466
6023
  this.syncTempOrderHolderFromBookings(tempOrder);
5467
6024
  if (tempOrder._extend && _typeof(tempOrder._extend) === 'object') {
5468
6025
  tempOrder._extend = _objectSpread(_objectSpread({}, tempOrder._extend), {}, {
5469
6026
  productsByUid: {}
5470
6027
  });
5471
6028
  }
5472
- _context30.next = 8;
5473
- return this.applyPromotion();
5474
- case 8:
6029
+ _context34.next = 10;
6030
+ return this.evaluatePromotion();
6031
+ case 10:
6032
+ promotionPayload = _context34.sent;
5475
6033
  this.applyDiscount();
5476
6034
  this.sanitizeTempOrderProducts(tempOrder);
5477
- _context30.next = 12;
6035
+ _context34.next = 15;
5478
6036
  return this.recalculateSummary({
5479
6037
  createIfMissing: true
5480
6038
  });
5481
- case 12:
6039
+ case 15:
5482
6040
  this.persistTempOrder();
6041
+ this.emitPromotionApplied(promotionPayload);
5483
6042
  this.logInfo('clearOrderCartLines success', {});
5484
- return _context30.abrupt("return", tempOrder);
5485
- case 15:
6043
+ return _context34.abrupt("return", tempOrder);
6044
+ case 19:
5486
6045
  case "end":
5487
- return _context30.stop();
6046
+ return _context34.stop();
5488
6047
  }
5489
- }, _callee27, this);
6048
+ }, _callee31, this);
5490
6049
  }));
5491
6050
  function clearOrderCartLines() {
5492
6051
  return _clearOrderCartLines.apply(this, arguments);
@@ -5500,15 +6059,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5500
6059
  }, {
5501
6060
  key: "clearOrderForSettlementSwitch",
5502
6061
  value: (function () {
5503
- var _clearOrderForSettlementSwitch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
6062
+ var _clearOrderForSettlementSwitch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
5504
6063
  var _this$store$discount22, _this$store$discount23;
5505
6064
  var tempOrder;
5506
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
5507
- while (1) switch (_context31.prev = _context31.next) {
6065
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
6066
+ while (1) switch (_context35.prev = _context35.next) {
5508
6067
  case 0:
5509
6068
  tempOrder = this.ensureTempOrder();
6069
+ this.ensureSalesNotesLoadedForMutation(tempOrder);
5510
6070
  tempOrder.products = [];
5511
6071
  tempOrder.bookings = [];
6072
+ this.removeSalesNotesForMissingProductLines(tempOrder);
5512
6073
  tempOrder.discount_list = [];
5513
6074
  tempOrder.payments = [];
5514
6075
  tempOrder.refunds = [];
@@ -5521,28 +6082,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5521
6082
  productsByUid: {}
5522
6083
  });
5523
6084
  }
5524
- _context31.next = 13;
6085
+ _context35.next = 15;
5525
6086
  return (_this$store$discount22 = this.store.discount) === null || _this$store$discount22 === void 0 ? void 0 : _this$store$discount22.setDiscountList([]);
5526
- case 13:
5527
- _context31.next = 15;
5528
- return (_this$store$discount23 = this.store.discount) === null || _this$store$discount23 === void 0 ? void 0 : _this$store$discount23.setOriginalDiscountList([]);
5529
6087
  case 15:
6088
+ _context35.next = 17;
6089
+ return (_this$store$discount23 = this.store.discount) === null || _this$store$discount23 === void 0 ? void 0 : _this$store$discount23.setOriginalDiscountList([]);
6090
+ case 17:
5530
6091
  this.hasActiveCustomerBoundDiscount = false;
5531
6092
  this.lastUnfulfilledPromotions = [];
5532
6093
  this.lastGiftActions = null;
5533
- _context31.next = 20;
6094
+ _context35.next = 22;
5534
6095
  return this.recalculateSummary({
5535
6096
  createIfMissing: true
5536
6097
  });
5537
- case 20:
6098
+ case 22:
5538
6099
  this.persistTempOrder();
5539
6100
  this.logInfo('clearOrderForSettlementSwitch success', {});
5540
- return _context31.abrupt("return", tempOrder);
5541
- case 23:
6101
+ return _context35.abrupt("return", tempOrder);
6102
+ case 25:
5542
6103
  case "end":
5543
- return _context31.stop();
6104
+ return _context35.stop();
5544
6105
  }
5545
- }, _callee28, this);
6106
+ }, _callee32, this);
5546
6107
  }));
5547
6108
  function clearOrderForSettlementSwitch() {
5548
6109
  return _clearOrderForSettlementSwitch.apply(this, arguments);
@@ -5553,23 +6114,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5553
6114
  }, {
5554
6115
  key: "buildCurrentSubmitPayloadForLocalPrint",
5555
6116
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
5556
- var _params$cacheId, _this$otherParams5, _ref79, _params$businessCode, _this$otherParams6, _this$otherParams7;
6117
+ var _params$cacheId, _this$otherParams5, _ref83, _params$businessCode, _this$otherParams6, _this$otherParams7;
5557
6118
  var tempOrder = this.ensureTempOrder();
5558
6119
  this.persistTempOrder();
5559
6120
  var payload = buildSubmitPayload({
5560
6121
  tempOrder: tempOrder,
5561
6122
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
5562
6123
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
5563
- businessCode: (_ref79 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref79 !== void 0 ? _ref79 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
6124
+ businessCode: (_ref83 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref83 !== void 0 ? _ref83 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
5564
6125
  channel: params === null || params === void 0 ? void 0 : params.channel,
5565
6126
  type: params === null || params === void 0 ? void 0 : params.type,
5566
6127
  summary: this.store.summary || createEmptySummary(),
5567
6128
  enhance: function enhance(nextPayload) {
5568
- var _ref80, _tempOrder$order_numb, _ref81, _tempOrder$shop_order, _ref82, _tempOrder$shop_full_;
6129
+ var _ref84, _tempOrder$order_numb, _ref85, _tempOrder$shop_order2, _ref86, _tempOrder$shop_full_;
5569
6130
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
5570
- order_number: (_ref80 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref80 !== void 0 ? _ref80 : null,
5571
- shop_order_number: (_ref81 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref81 !== void 0 ? _ref81 : null,
5572
- shop_full_order_number: (_ref82 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref82 !== void 0 ? _ref82 : null,
6131
+ order_number: (_ref84 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref84 !== void 0 ? _ref84 : null,
6132
+ shop_order_number: (_ref85 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref85 !== void 0 ? _ref85 : null,
6133
+ shop_full_order_number: (_ref86 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref86 !== void 0 ? _ref86 : null,
5573
6134
  small_ticket_data_flag: 1
5574
6135
  });
5575
6136
  }
@@ -5580,17 +6141,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5580
6141
  }, {
5581
6142
  key: "applyLocalPrintOrderNumbers",
5582
6143
  value: function () {
5583
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order) {
6144
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
5584
6145
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
5585
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5586
- while (1) switch (_context32.prev = _context32.next) {
6146
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
6147
+ while (1) switch (_context36.prev = _context36.next) {
5587
6148
  case 0:
5588
6149
  tempOrder = this.ensureTempOrder();
5589
6150
  if (!(!order || _typeof(order) !== 'object')) {
5590
- _context32.next = 3;
6151
+ _context36.next = 3;
5591
6152
  break;
5592
6153
  }
5593
- return _context32.abrupt("return", tempOrder);
6154
+ return _context36.abrupt("return", tempOrder);
5594
6155
  case 3:
5595
6156
  shopOrderNumber = order.shop_order_number;
5596
6157
  shopFullOrderNumber = order.shop_full_order_number;
@@ -5601,17 +6162,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5601
6162
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
5602
6163
  }
5603
6164
  this.persistTempOrder();
5604
- _context32.next = 10;
6165
+ _context36.next = 10;
5605
6166
  return this.saveDraft();
5606
6167
  case 10:
5607
- return _context32.abrupt("return", tempOrder);
6168
+ return _context36.abrupt("return", tempOrder);
5608
6169
  case 11:
5609
6170
  case "end":
5610
- return _context32.stop();
6171
+ return _context36.stop();
5611
6172
  }
5612
- }, _callee29, this);
6173
+ }, _callee33, this);
5613
6174
  }));
5614
- function applyLocalPrintOrderNumbers(_x35) {
6175
+ function applyLocalPrintOrderNumbers(_x37) {
5615
6176
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
5616
6177
  }
5617
6178
  return applyLocalPrintOrderNumbers;
@@ -5619,35 +6180,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5619
6180
  }, {
5620
6181
  key: "saveTempOrderAsDraft",
5621
6182
  value: function () {
5622
- var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
6183
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5623
6184
  var _params$cacheId2, _this$otherParams8, _this$otherParams9, _this$otherParams10, _params$type, _this$otherParams11, _payload$products;
5624
6185
  var tempOrder, latestSummary, payload;
5625
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5626
- while (1) switch (_context33.prev = _context33.next) {
6186
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
6187
+ while (1) switch (_context37.prev = _context37.next) {
5627
6188
  case 0:
5628
6189
  tempOrder = this.ensureTempOrder();
5629
6190
  this.ensureExternalSaleNumber(tempOrder);
5630
6191
  this.persistTempOrder();
5631
- _context33.next = 5;
6192
+ _context37.next = 5;
5632
6193
  return this.recalculateSummary({
5633
6194
  createIfMissing: true
5634
6195
  });
5635
6196
  case 5:
5636
- _context33.t1 = _context33.sent;
5637
- if (_context33.t1) {
5638
- _context33.next = 8;
6197
+ _context37.t1 = _context37.sent;
6198
+ if (_context37.t1) {
6199
+ _context37.next = 8;
5639
6200
  break;
5640
6201
  }
5641
- _context33.t1 = this.store.summary;
6202
+ _context37.t1 = this.store.summary;
5642
6203
  case 8:
5643
- _context33.t0 = _context33.t1;
5644
- if (_context33.t0) {
5645
- _context33.next = 11;
6204
+ _context37.t0 = _context37.t1;
6205
+ if (_context37.t0) {
6206
+ _context37.next = 11;
5646
6207
  break;
5647
6208
  }
5648
- _context33.t0 = createEmptySummary();
6209
+ _context37.t0 = createEmptySummary();
5649
6210
  case 11:
5650
- latestSummary = _context33.t0;
6211
+ latestSummary = _context37.t0;
5651
6212
  payload = buildSubmitPayload({
5652
6213
  tempOrder: tempOrder,
5653
6214
  cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
@@ -5668,17 +6229,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5668
6229
  externalSaleNumber: payload.external_sale_number,
5669
6230
  productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
5670
6231
  });
5671
- return _context33.abrupt("return", this.request.post('/order/sales/draft', payload, {
6232
+ return _context37.abrupt("return", this.request.post('/order/sales/draft', payload, {
5672
6233
  osServer: true,
5673
6234
  customToast: function customToast() {}
5674
6235
  }));
5675
6236
  case 18:
5676
6237
  case "end":
5677
- return _context33.stop();
6238
+ return _context37.stop();
5678
6239
  }
5679
- }, _callee30, this);
6240
+ }, _callee34, this);
5680
6241
  }));
5681
- function saveTempOrderAsDraft(_x36) {
6242
+ function saveTempOrderAsDraft(_x38) {
5682
6243
  return _saveTempOrderAsDraft.apply(this, arguments);
5683
6244
  }
5684
6245
  return saveTempOrderAsDraft;
@@ -5692,18 +6253,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5692
6253
  }, {
5693
6254
  key: "submitTempOrder",
5694
6255
  value: (function () {
5695
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
5696
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
5697
- while (1) switch (_context34.prev = _context34.next) {
6256
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
6257
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
6258
+ while (1) switch (_context38.prev = _context38.next) {
5698
6259
  case 0:
5699
- return _context34.abrupt("return", this.runSubmitTempOrder(params));
6260
+ return _context38.abrupt("return", this.runSubmitTempOrder(params));
5700
6261
  case 1:
5701
6262
  case "end":
5702
- return _context34.stop();
6263
+ return _context38.stop();
5703
6264
  }
5704
- }, _callee31, this);
6265
+ }, _callee35, this);
5705
6266
  }));
5706
- function submitTempOrder(_x37) {
6267
+ function submitTempOrder(_x39) {
5707
6268
  return _submitTempOrder.apply(this, arguments);
5708
6269
  }
5709
6270
  return submitTempOrder;
@@ -5711,20 +6272,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5711
6272
  }, {
5712
6273
  key: "submitTempOrderAsync",
5713
6274
  value: function () {
5714
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5715
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5716
- while (1) switch (_context35.prev = _context35.next) {
6275
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
6276
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
6277
+ while (1) switch (_context39.prev = _context39.next) {
5717
6278
  case 0:
5718
- return _context35.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
6279
+ return _context39.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5719
6280
  syncMode: true
5720
6281
  })));
5721
6282
  case 1:
5722
6283
  case "end":
5723
- return _context35.stop();
6284
+ return _context39.stop();
5724
6285
  }
5725
- }, _callee32, this);
6286
+ }, _callee36, this);
5726
6287
  }));
5727
- function submitTempOrderAsync(_x38) {
6288
+ function submitTempOrderAsync(_x40) {
5728
6289
  return _submitTempOrderAsync.apply(this, arguments);
5729
6290
  }
5730
6291
  return submitTempOrderAsync;
@@ -5732,11 +6293,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5732
6293
  }, {
5733
6294
  key: "runSubmitTempOrder",
5734
6295
  value: function () {
5735
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5736
- var _params$cacheId3, _this$otherParams12, _ref83, _ref84, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
5737
- var tempOrder, isOnlineStorePlatform, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
5738
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5739
- while (1) switch (_context36.prev = _context36.next) {
6296
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
6297
+ var _params$cacheId3, _this$otherParams12, _ref87, _ref88, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
6298
+ var tempOrder, isOnlineStorePlatform, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, shouldOverridePaymentStatus, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, isLocalPendingSubmit, salesNotesState, submittedOrderId, resultRecord;
6299
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
6300
+ while (1) switch (_context40.prev = _context40.next) {
5740
6301
  case 0:
5741
6302
  tempOrder = this.ensureTempOrder();
5742
6303
  this.prepareVirtualSettlementTempOrder(tempOrder);
@@ -5760,33 +6321,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5760
6321
  }
5761
6322
  }
5762
6323
  this.persistTempOrder();
5763
- _context36.next = 10;
6324
+ _context40.next = 10;
5764
6325
  return this.recalculateSummary({
5765
6326
  createIfMissing: true
5766
6327
  });
5767
6328
  case 10:
5768
- _context36.t1 = _context36.sent;
5769
- if (_context36.t1) {
5770
- _context36.next = 13;
6329
+ _context40.t1 = _context40.sent;
6330
+ if (_context40.t1) {
6331
+ _context40.next = 13;
5771
6332
  break;
5772
6333
  }
5773
- _context36.t1 = this.store.summary;
6334
+ _context40.t1 = this.store.summary;
5774
6335
  case 13:
5775
- _context36.t0 = _context36.t1;
5776
- if (_context36.t0) {
5777
- _context36.next = 16;
6336
+ _context40.t0 = _context40.t1;
6337
+ if (_context40.t0) {
6338
+ _context40.next = 16;
5778
6339
  break;
5779
6340
  }
5780
- _context36.t0 = createEmptySummary();
6341
+ _context40.t0 = createEmptySummary();
5781
6342
  case 16:
5782
- latestSummary = _context36.t0;
6343
+ latestSummary = _context40.t0;
5783
6344
  effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
5784
6345
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
6346
+ shouldOverridePaymentStatus = hasPaymentStatusOverride && !isOnlineStorePlatform && !shouldConfirmPendingVoucherPayments;
5785
6347
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
5786
6348
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
5787
6349
  var nextPayload = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, payload), hasPaymentOverride ? {
5788
6350
  payments: preparedPaymentOverride || []
5789
- } : {}), hasPaymentStatusOverride && !isOnlineStorePlatform && !shouldConfirmPendingVoucherPayments ? {
6351
+ } : {}), shouldOverridePaymentStatus ? {
5790
6352
  payment_status: params === null || params === void 0 ? void 0 : params.paymentStatus
5791
6353
  } : {}), hasSmallTicketDataFlagOverride ? {
5792
6354
  small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
@@ -5799,7 +6361,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5799
6361
  tempOrder: tempOrder,
5800
6362
  cacheId: effectiveCacheId,
5801
6363
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.platform),
5802
- businessCode: (_ref83 = (_ref84 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref84 !== void 0 ? _ref84 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref83 !== void 0 ? _ref83 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
6364
+ businessCode: (_ref87 = (_ref88 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref88 !== void 0 ? _ref88 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref87 !== void 0 ? _ref87 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
5803
6365
  channel: params === null || params === void 0 ? void 0 : params.channel,
5804
6366
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
5805
6367
  summary: latestSummary,
@@ -5814,10 +6376,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5814
6376
  if (!payload.created_at) {
5815
6377
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
5816
6378
  }
5817
- _context36.next = 27;
6379
+ _context40.next = 28;
5818
6380
  return this.saveDraft();
5819
- case 27:
5820
- _context36.prev = 27;
6381
+ case 28:
6382
+ _context40.prev = 28;
5821
6383
  this.logInfo('submitTempOrder calling sales checkout', {
5822
6384
  orderId: payload.order_id,
5823
6385
  externalSaleNumber: payload.external_sale_number,
@@ -5827,44 +6389,49 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5827
6389
  smallTicketDataFlag: payload.small_ticket_data_flag,
5828
6390
  syncMode: payload.sync_mode
5829
6391
  });
5830
- _context36.next = 31;
6392
+ _context40.next = 32;
5831
6393
  return this.submitSalesOrder({
5832
6394
  query: payload
5833
6395
  });
5834
- case 31:
5835
- result = _context36.sent;
5836
- _context36.next = 44;
6396
+ case 32:
6397
+ result = _context40.sent;
6398
+ _context40.next = 45;
5837
6399
  break;
5838
- case 34:
5839
- _context36.prev = 34;
5840
- _context36.t2 = _context36["catch"](27);
5841
- backendErrorResponse = this.extractSubmitErrorResponse(_context36.t2);
6400
+ case 35:
6401
+ _context40.prev = 35;
6402
+ _context40.t2 = _context40["catch"](28);
6403
+ backendErrorResponse = this.extractSubmitErrorResponse(_context40.t2);
5842
6404
  if (!backendErrorResponse) {
5843
- _context36.next = 41;
6405
+ _context40.next = 42;
5844
6406
  break;
5845
6407
  }
5846
6408
  this.store.syncState = 'failed';
5847
6409
  this.logSubmitBackendRejected(backendErrorResponse, payload);
5848
- return _context36.abrupt("return", backendErrorResponse);
5849
- case 41:
6410
+ return _context40.abrupt("return", backendErrorResponse);
6411
+ case 42:
5850
6412
  this.store.syncState = 'failed';
5851
6413
  this.logError('submitTempOrder failed', {
5852
- error: _context36.t2 instanceof Error ? _context36.t2.message : String(_context36.t2),
6414
+ error: _context40.t2 instanceof Error ? _context40.t2.message : String(_context40.t2),
5853
6415
  orderId: payload.order_id,
5854
6416
  externalSaleNumber: payload.external_sale_number,
5855
6417
  paymentStatus: payload.payment_status,
5856
6418
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
5857
6419
  });
5858
- throw _context36.t2;
5859
- case 44:
6420
+ throw _context40.t2;
6421
+ case 45:
5860
6422
  if (!this.isSubmitResponseRejected(result)) {
5861
- _context36.next = 48;
6423
+ _context40.next = 49;
5862
6424
  break;
5863
6425
  }
5864
6426
  this.store.syncState = 'failed';
5865
6427
  this.logSubmitBackendRejected(result, payload);
5866
- return _context36.abrupt("return", result);
5867
- case 48:
6428
+ return _context40.abrupt("return", result);
6429
+ case 49:
6430
+ isLocalPendingSubmit = this.isLocalPendingSubmitResult(result); // need_sync=1 仅表示已进入本地同步队列,不能视为远端已确认 Notes。
6431
+ if (Object.prototype.hasOwnProperty.call(payload, 'notes') && !isLocalPendingSubmit) {
6432
+ salesNotesState = this.ensureSalesNotesRuntimeState(tempOrder);
6433
+ salesNotesState.dirty = false;
6434
+ }
5868
6435
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
5869
6436
  this.logInfo('runSubmitTempOrder: 提交成功', {
5870
6437
  submittedOrderId: submittedOrderId,
@@ -5874,31 +6441,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5874
6441
  })
5875
6442
  });
5876
6443
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
5877
- _context36.next = 57;
6444
+ _context40.next = 58;
5878
6445
  break;
5879
6446
  }
5880
6447
  tempOrder.order_id = submittedOrderId;
5881
6448
  resultRecord = result;
5882
- _context36.next = 55;
6449
+ _context40.next = 58;
5883
6450
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
5884
- case 55:
5885
- _context36.next = 58;
5886
- break;
5887
- case 57:
5888
- if (this.isLocalPendingSubmitResult(result)) {
6451
+ case 58:
6452
+ if (isLocalPendingSubmit) {
5889
6453
  this.store.syncState = 'local';
5890
- } else {
6454
+ } else if (submittedOrderId === null || submittedOrderId === undefined) {
5891
6455
  this.store.syncState = 'submitted';
5892
6456
  }
5893
- case 58:
5894
- return _context36.abrupt("return", result);
5895
- case 59:
6457
+ return _context40.abrupt("return", result);
6458
+ case 60:
5896
6459
  case "end":
5897
- return _context36.stop();
6460
+ return _context40.stop();
5898
6461
  }
5899
- }, _callee33, this, [[27, 34]]);
6462
+ }, _callee37, this, [[28, 35]]);
5900
6463
  }));
5901
- function runSubmitTempOrder(_x39) {
6464
+ function runSubmitTempOrder(_x41) {
5902
6465
  return _runSubmitTempOrder.apply(this, arguments);
5903
6466
  }
5904
6467
  return runSubmitTempOrder;
@@ -5906,10 +6469,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5906
6469
  }, {
5907
6470
  key: "markLocalOrderSynced",
5908
6471
  value: function () {
5909
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(orderId, remoteOrder) {
6472
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(orderId, remoteOrder) {
5910
6473
  var tempOrder;
5911
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5912
- while (1) switch (_context37.prev = _context37.next) {
6474
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
6475
+ while (1) switch (_context41.prev = _context41.next) {
5913
6476
  case 0:
5914
6477
  tempOrder = this.ensureTempOrder();
5915
6478
  tempOrder.order_id = orderId;
@@ -5917,15 +6480,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5917
6480
  this.store.lastOrderInfo = remoteOrder;
5918
6481
  this.store.syncState = 'submitted';
5919
6482
  this.persistTempOrder();
5920
- _context37.next = 8;
6483
+ _context41.next = 8;
5921
6484
  return this.saveDraft();
5922
6485
  case 8:
5923
6486
  case "end":
5924
- return _context37.stop();
6487
+ return _context41.stop();
5925
6488
  }
5926
- }, _callee34, this);
6489
+ }, _callee38, this);
5927
6490
  }));
5928
- function markLocalOrderSynced(_x40, _x41) {
6491
+ function markLocalOrderSynced(_x42, _x43) {
5929
6492
  return _markLocalOrderSynced.apply(this, arguments);
5930
6493
  }
5931
6494
  return markLocalOrderSynced;
@@ -5968,10 +6531,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5968
6531
  value: function extractSubmitErrorResponse(error) {
5969
6532
  var _error$response,
5970
6533
  _error$response2,
5971
- _this32 = this;
6534
+ _this37 = this;
5972
6535
  var candidates = [error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.body, error === null || error === void 0 ? void 0 : error.body];
5973
6536
  return candidates.find(function (candidate) {
5974
- return _this32.isSubmitErrorResponse(candidate);
6537
+ return _this37.isSubmitErrorResponse(candidate);
5975
6538
  }) || null;
5976
6539
  }
5977
6540
  }, {
@@ -5998,33 +6561,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5998
6561
  }, {
5999
6562
  key: "syncPaymentsToOrder",
6000
6563
  value: function () {
6001
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
6002
- var _this33 = this,
6564
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
6565
+ var _this38 = this,
6003
6566
  _params$confirmPendin;
6004
6567
  var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, enhancePayload, submitParams, submitResult;
6005
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
6006
- while (1) switch (_context38.prev = _context38.next) {
6568
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
6569
+ while (1) switch (_context42.prev = _context42.next) {
6007
6570
  case 0:
6008
6571
  tempOrder = this.ensureTempOrder();
6009
6572
  needsPaymentNumber = (params.payments || []).some(function (payment) {
6010
6573
  return String(payment.payment_number || '').trim() === '';
6011
6574
  });
6012
6575
  if (!needsPaymentNumber) {
6013
- _context38.next = 8;
6576
+ _context42.next = 8;
6014
6577
  break;
6015
6578
  }
6016
- _context38.next = 5;
6579
+ _context42.next = 5;
6017
6580
  return this.getPaymentNumberDevicePrefixAsync();
6018
6581
  case 5:
6019
- _context38.t0 = _context38.sent;
6020
- _context38.next = 9;
6582
+ _context42.t0 = _context42.sent;
6583
+ _context42.next = 9;
6021
6584
  break;
6022
6585
  case 8:
6023
- _context38.t0 = 'LOCAL';
6586
+ _context42.t0 = 'LOCAL';
6024
6587
  case 9:
6025
- devicePrefix = _context38.t0;
6588
+ devicePrefix = _context42.t0;
6026
6589
  mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
6027
- return _this33.normalizePaymentSource(payment, {
6590
+ return _this38.normalizePaymentSource(payment, {
6028
6591
  defaultPaid: false,
6029
6592
  devicePrefix: devicePrefix
6030
6593
  });
@@ -6037,20 +6600,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6037
6600
  tempOrder.payments = effectivePayments;
6038
6601
  tempOrder.payment_status = paymentStatus;
6039
6602
  this.persistTempOrder();
6040
- _context38.next = 21;
6603
+ _context42.next = 21;
6041
6604
  return this.saveDraft();
6042
6605
  case 21:
6043
6606
  if (params.submitWhenPaid) {
6044
- _context38.next = 23;
6607
+ _context42.next = 23;
6045
6608
  break;
6046
6609
  }
6047
- return _context38.abrupt("return", completion);
6610
+ return _context42.abrupt("return", completion);
6048
6611
  case 23:
6049
6612
  if (!(this.store.syncState === 'submitting')) {
6050
- _context38.next = 25;
6613
+ _context42.next = 25;
6051
6614
  break;
6052
6615
  }
6053
- return _context38.abrupt("return", completion);
6616
+ return _context42.abrupt("return", completion);
6054
6617
  case 25:
6055
6618
  this.store.syncState = 'submitting';
6056
6619
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
@@ -6070,32 +6633,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6070
6633
  enhancePayload: enhancePayload
6071
6634
  };
6072
6635
  if (!(params.checkoutSyncTaskEnabled === false)) {
6073
- _context38.next = 35;
6636
+ _context42.next = 35;
6074
6637
  break;
6075
6638
  }
6076
- _context38.next = 32;
6639
+ _context42.next = 32;
6077
6640
  return this.submitTempOrderAsync(submitParams);
6078
6641
  case 32:
6079
- _context38.t1 = _context38.sent;
6080
- _context38.next = 38;
6642
+ _context42.t1 = _context42.sent;
6643
+ _context42.next = 38;
6081
6644
  break;
6082
6645
  case 35:
6083
- _context38.next = 37;
6646
+ _context42.next = 37;
6084
6647
  return this.submitTempOrder(submitParams);
6085
6648
  case 37:
6086
- _context38.t1 = _context38.sent;
6649
+ _context42.t1 = _context42.sent;
6087
6650
  case 38:
6088
- submitResult = _context38.t1;
6089
- return _context38.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
6651
+ submitResult = _context42.t1;
6652
+ return _context42.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
6090
6653
  submitResult: submitResult
6091
6654
  }));
6092
6655
  case 40:
6093
6656
  case "end":
6094
- return _context38.stop();
6657
+ return _context42.stop();
6095
6658
  }
6096
- }, _callee35, this);
6659
+ }, _callee39, this);
6097
6660
  }));
6098
- function syncPaymentsToOrder(_x42) {
6661
+ function syncPaymentsToOrder(_x44) {
6099
6662
  return _syncPaymentsToOrder.apply(this, arguments);
6100
6663
  }
6101
6664
  return syncPaymentsToOrder;
@@ -6103,7 +6666,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6103
6666
  }, {
6104
6667
  key: "createOrder",
6105
6668
  value: function createOrder(params) {
6106
- var _this34 = this;
6669
+ var _this39 = this;
6107
6670
  var order = _objectSpread({
6108
6671
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
6109
6672
  // 要从外面拿,virtual
@@ -6135,7 +6698,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6135
6698
 
6136
6699
  // 为预约补齐 holder 信息
6137
6700
  if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
6138
- ensureCartItemOriginHolder(item, _this34.window);
6701
+ ensureCartItemOriginHolder(item, _this39.window);
6139
6702
  }
6140
6703
 
6141
6704
  // 购物车是否为普通商品
@@ -6192,11 +6755,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6192
6755
  }, {
6193
6756
  key: "submitOrder",
6194
6757
  value: function () {
6195
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(order) {
6758
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(order) {
6196
6759
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
6197
6760
  var url, query, fetchUrl, params;
6198
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
6199
- while (1) switch (_context39.prev = _context39.next) {
6761
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
6762
+ while (1) switch (_context43.prev = _context43.next) {
6200
6763
  case 0:
6201
6764
  this.logInfo('submitOrder called', {
6202
6765
  url: order.url,
@@ -6216,14 +6779,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6216
6779
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
6217
6780
  scheduleDate: params.schedule_date
6218
6781
  });
6219
- return _context39.abrupt("return", this.request.post(fetchUrl, params));
6782
+ return _context43.abrupt("return", this.request.post(fetchUrl, params));
6220
6783
  case 6:
6221
6784
  case "end":
6222
- return _context39.stop();
6785
+ return _context43.stop();
6223
6786
  }
6224
- }, _callee36, this);
6787
+ }, _callee40, this);
6225
6788
  }));
6226
- function submitOrder(_x43) {
6789
+ function submitOrder(_x45) {
6227
6790
  return _submitOrder.apply(this, arguments);
6228
6791
  }
6229
6792
  return submitOrder;
@@ -6231,13 +6794,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6231
6794
  }, {
6232
6795
  key: "cancelOrder",
6233
6796
  value: function () {
6234
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
6797
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
6235
6798
  var payload;
6236
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
6237
- while (1) switch (_context40.prev = _context40.next) {
6799
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6800
+ while (1) switch (_context44.prev = _context44.next) {
6238
6801
  case 0:
6239
6802
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
6240
- _context40.next = 2;
6803
+ _context44.next = 2;
6241
6804
  break;
6242
6805
  }
6243
6806
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -6253,16 +6816,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6253
6816
  method: 'PUT',
6254
6817
  orderIdsCount: params.order_ids.length
6255
6818
  });
6256
- return _context40.abrupt("return", this.request.put('/order/update-status', payload, {
6819
+ return _context44.abrupt("return", this.request.put('/order/update-status', payload, {
6257
6820
  isShopApi: true
6258
6821
  }));
6259
6822
  case 5:
6260
6823
  case "end":
6261
- return _context40.stop();
6824
+ return _context44.stop();
6262
6825
  }
6263
- }, _callee37, this);
6826
+ }, _callee41, this);
6264
6827
  }));
6265
- function cancelOrder(_x44) {
6828
+ function cancelOrder(_x46) {
6266
6829
  return _cancelOrder.apply(this, arguments);
6267
6830
  }
6268
6831
  return cancelOrder;
@@ -6270,19 +6833,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6270
6833
  }, {
6271
6834
  key: "changeBookingStatus",
6272
6835
  value: function () {
6273
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
6836
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
6274
6837
  var url, payload;
6275
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
6276
- while (1) switch (_context41.prev = _context41.next) {
6838
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
6839
+ while (1) switch (_context45.prev = _context45.next) {
6277
6840
  case 0:
6278
6841
  if (params.booking_id) {
6279
- _context41.next = 2;
6842
+ _context45.next = 2;
6280
6843
  break;
6281
6844
  }
6282
6845
  throw new Error('变更预约状态失败:booking_id 不能为空');
6283
6846
  case 2:
6284
6847
  if (params.appointment_status) {
6285
- _context41.next = 4;
6848
+ _context45.next = 4;
6286
6849
  break;
6287
6850
  }
6288
6851
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -6297,16 +6860,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6297
6860
  bookingId: params.booking_id,
6298
6861
  appointmentStatus: params.appointment_status
6299
6862
  });
6300
- return _context41.abrupt("return", this.request.put(url, payload, {
6863
+ return _context45.abrupt("return", this.request.put(url, payload, {
6301
6864
  isShopApi: true
6302
6865
  }));
6303
6866
  case 8:
6304
6867
  case "end":
6305
- return _context41.stop();
6868
+ return _context45.stop();
6306
6869
  }
6307
- }, _callee38, this);
6870
+ }, _callee42, this);
6308
6871
  }));
6309
- function changeBookingStatus(_x45) {
6872
+ function changeBookingStatus(_x47) {
6310
6873
  return _changeBookingStatus.apply(this, arguments);
6311
6874
  }
6312
6875
  return changeBookingStatus;
@@ -6324,11 +6887,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6324
6887
  }, {
6325
6888
  key: "createOrderByCheckout",
6326
6889
  value: (function () {
6327
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
6890
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
6328
6891
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3;
6329
6892
  var onlineStorePaymentCodeList, _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, orderData, response;
6330
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
6331
- while (1) switch (_context42.prev = _context42.next) {
6893
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
6894
+ while (1) switch (_context46.prev = _context46.next) {
6332
6895
  case 0:
6333
6896
  // 过滤掉由在线店铺下单的 payment 支付数据
6334
6897
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -6353,7 +6916,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6353
6916
  return p.code;
6354
6917
  })) || []
6355
6918
  });
6356
- _context42.prev = 3;
6919
+ _context46.prev = 3;
6357
6920
  // 构建订单数据,设置默认值并允许 params 覆盖
6358
6921
  orderData = _objectSpread({
6359
6922
  sales_channel: 'my_pisel',
@@ -6401,32 +6964,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6401
6964
  hasOrderId: !!orderData.order_id,
6402
6965
  smallTicketDataFlag: orderData.small_ticket_data_flag
6403
6966
  });
6404
- _context42.next = 10;
6967
+ _context46.next = 10;
6405
6968
  return this.request.post('/order/checkout', orderData, {
6406
6969
  osServer: true,
6407
6970
  customToast: function customToast() {}
6408
6971
  });
6409
6972
  case 10:
6410
- response = _context42.sent;
6973
+ response = _context46.sent;
6411
6974
  this.logInfo('Order API called successfully', {
6412
6975
  response: response
6413
6976
  });
6414
- return _context42.abrupt("return", response);
6977
+ return _context46.abrupt("return", response);
6415
6978
  case 15:
6416
- _context42.prev = 15;
6417
- _context42.t0 = _context42["catch"](3);
6418
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context42.t0);
6979
+ _context46.prev = 15;
6980
+ _context46.t0 = _context46["catch"](3);
6981
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context46.t0);
6419
6982
  this.logInfo('Order API called failed', {
6420
- error: _context42.t0 instanceof Error ? _context42.t0.message : String(_context42.t0)
6983
+ error: _context46.t0 instanceof Error ? _context46.t0.message : String(_context46.t0)
6421
6984
  });
6422
- throw _context42.t0;
6985
+ throw _context46.t0;
6423
6986
  case 20:
6424
6987
  case "end":
6425
- return _context42.stop();
6988
+ return _context46.stop();
6426
6989
  }
6427
- }, _callee39, this, [[3, 15]]);
6990
+ }, _callee43, this, [[3, 15]]);
6428
6991
  }));
6429
- function createOrderByCheckout(_x46) {
6992
+ function createOrderByCheckout(_x48) {
6430
6993
  return _createOrderByCheckout.apply(this, arguments);
6431
6994
  }
6432
6995
  return createOrderByCheckout;
@@ -6434,25 +6997,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6434
6997
  }, {
6435
6998
  key: "submitSalesOrder",
6436
6999
  value: function () {
6437
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
7000
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
6438
7001
  var url, query, fetchUrl, requestQuery;
6439
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
6440
- while (1) switch (_context43.prev = _context43.next) {
7002
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
7003
+ while (1) switch (_context47.prev = _context47.next) {
6441
7004
  case 0:
6442
7005
  url = params.url, query = params.query;
6443
7006
  fetchUrl = url || '/order/sales/checkout';
6444
7007
  requestQuery = this.isSalesCheckoutHandledByOsServer(fetchUrl) ? query : stripOsPrivatePayloadFields(query);
6445
- return _context43.abrupt("return", this.request.post(fetchUrl, requestQuery, {
7008
+ return _context47.abrupt("return", this.request.post(fetchUrl, requestQuery, {
6446
7009
  osServer: true,
6447
7010
  customToast: function customToast() {}
6448
7011
  }));
6449
7012
  case 4:
6450
7013
  case "end":
6451
- return _context43.stop();
7014
+ return _context47.stop();
6452
7015
  }
6453
- }, _callee40, this);
7016
+ }, _callee44, this);
6454
7017
  }));
6455
- function submitSalesOrder(_x47) {
7018
+ function submitSalesOrder(_x49) {
6456
7019
  return _submitSalesOrder.apply(this, arguments);
6457
7020
  }
6458
7021
  return submitSalesOrder;
@@ -6479,37 +7042,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6479
7042
  }, {
6480
7043
  key: "sendCustomerPayLink",
6481
7044
  value: (function () {
6482
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
7045
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(params) {
6483
7046
  var _params$emails;
6484
7047
  var orderIds;
6485
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6486
- while (1) switch (_context44.prev = _context44.next) {
7048
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
7049
+ while (1) switch (_context48.prev = _context48.next) {
6487
7050
  case 0:
6488
7051
  orderIds = params.order_ids || params.orderIds || [];
6489
7052
  if (orderIds.length) {
6490
- _context44.next = 3;
7053
+ _context48.next = 3;
6491
7054
  break;
6492
7055
  }
6493
7056
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
6494
7057
  case 3:
6495
7058
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
6496
- _context44.next = 5;
7059
+ _context48.next = 5;
6497
7060
  break;
6498
7061
  }
6499
7062
  throw new Error('发送支付链接需要至少一个邮箱');
6500
7063
  case 5:
6501
- return _context44.abrupt("return", this.request.post('/order/batch-email', {
7064
+ return _context48.abrupt("return", this.request.post('/order/batch-email', {
6502
7065
  order_ids: orderIds,
6503
7066
  notify_action: params.notify_action || 'order_payment_reminder',
6504
7067
  emails: params.emails
6505
7068
  }));
6506
7069
  case 6:
6507
7070
  case "end":
6508
- return _context44.stop();
7071
+ return _context48.stop();
6509
7072
  }
6510
- }, _callee41, this);
7073
+ }, _callee45, this);
6511
7074
  }));
6512
- function sendCustomerPayLink(_x48) {
7075
+ function sendCustomerPayLink(_x50) {
6513
7076
  return _sendCustomerPayLink.apply(this, arguments);
6514
7077
  }
6515
7078
  return sendCustomerPayLink;
@@ -6517,14 +7080,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6517
7080
  }, {
6518
7081
  key: "getSalesOrderByLookup",
6519
7082
  value: function () {
6520
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
7083
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46(params) {
6521
7084
  var lookup, res;
6522
- return _regeneratorRuntime().wrap(function _callee42$(_context45) {
6523
- while (1) switch (_context45.prev = _context45.next) {
7085
+ return _regeneratorRuntime().wrap(function _callee46$(_context49) {
7086
+ while (1) switch (_context49.prev = _context49.next) {
6524
7087
  case 0:
6525
7088
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
6526
7089
  if (lookup) {
6527
- _context45.next = 3;
7090
+ _context49.next = 3;
6528
7091
  break;
6529
7092
  }
6530
7093
  throw new Error('加载销售详情需要 lookup');
@@ -6533,27 +7096,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6533
7096
  if (lookup.startsWith('LOCAL_')) {
6534
7097
  params.forceRemote = false;
6535
7098
  }
6536
- _context45.next = 6;
7099
+ _context49.next = 6;
6537
7100
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
6538
- with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'order_meta_list', 'refunds']
7101
+ with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'order_meta_list', 'refunds', 'notes']
6539
7102
  }, params.forceRemote ? {
6540
7103
  forceRemote: true
6541
7104
  } : {}), {
6542
7105
  osServer: true
6543
7106
  });
6544
7107
  case 6:
6545
- res = _context45.sent;
7108
+ res = _context49.sent;
6546
7109
  if (res.code === 200) {
6547
7110
  this.store.lastOrderInfo = res.data;
6548
7111
  }
6549
- return _context45.abrupt("return", res);
7112
+ return _context49.abrupt("return", res);
6550
7113
  case 9:
6551
7114
  case "end":
6552
- return _context45.stop();
7115
+ return _context49.stop();
6553
7116
  }
6554
- }, _callee42, this);
7117
+ }, _callee46, this);
6555
7118
  }));
6556
- function getSalesOrderByLookup(_x49) {
7119
+ function getSalesOrderByLookup(_x51) {
6557
7120
  return _getSalesOrderByLookup.apply(this, arguments);
6558
7121
  }
6559
7122
  return getSalesOrderByLookup;
@@ -6567,11 +7130,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6567
7130
  }, {
6568
7131
  key: "hydrateTempOrderFromRecord",
6569
7132
  value: (function () {
6570
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(record, options) {
7133
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47(record, options) {
6571
7134
  var _sourceRaw$_extend, _this$store$discount26;
6572
7135
  var sourceRaw, duplicateProductIdentityRepair, duplicateIdentityReadySource, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, isSessionStorageHydrate, isMergedSalesDetailHydrate, nextTempOrder, _this$store$discount24, _this$store$discount25, restoredSessionDiscounts, nextExtend, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, historicalDepositSnapshot, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount27, _this$store$discount28;
6573
- return _regeneratorRuntime().wrap(function _callee43$(_context46) {
6574
- while (1) switch (_context46.prev = _context46.next) {
7136
+ return _regeneratorRuntime().wrap(function _callee47$(_context50) {
7137
+ while (1) switch (_context50.prev = _context50.next) {
6575
7138
  case 0:
6576
7139
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
6577
7140
  duplicateProductIdentityRepair = repairDuplicateOrderProductLineIdentities(Array.isArray(sourceRaw.products) ? sourceRaw.products : [], (_sourceRaw$_extend = sourceRaw._extend) === null || _sourceRaw$_extend === void 0 ? void 0 : _sourceRaw$_extend.productsByUid);
@@ -6607,11 +7170,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6607
7170
  isMergedSalesDetailHydrate = (options === null || options === void 0 ? void 0 : options.source) === 'mergedSalesDetail';
6608
7171
  nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
6609
7172
  // merge 前已只给远端商品补标记;这里不能把本地未提交商品一并变成 saved item。
6610
- makeEditMark: !isSessionStorageHydrate && !isMergedSalesDetailHydrate
7173
+ makeEditMark: !isSessionStorageHydrate && !isMergedSalesDetailHydrate,
7174
+ allowUnresolvedSalesNotes: isSessionStorageHydrate
6611
7175
  });
6612
7176
  this.store.tempOrder = nextTempOrder;
7177
+ this.clearCustomerWalletRuntimeState();
6613
7178
  if (!isSessionStorageHydrate) {
6614
- _context46.next = 30;
7179
+ _context50.next = 31;
6615
7180
  break;
6616
7181
  }
6617
7182
  // 会话快照是未提交购物车,不应获得编辑订单的 saved/edit 标记与服务端基线。
@@ -6627,24 +7192,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6627
7192
  nextTempOrder.discount_list = restoredSessionDiscounts;
6628
7193
  this.store.summary = createEmptySummary();
6629
7194
  this.store.lastOrderInfo = undefined;
6630
- _context46.next = 23;
7195
+ _context50.next = 24;
6631
7196
  return (_this$store$discount24 = this.store.discount) === null || _this$store$discount24 === void 0 ? void 0 : _this$store$discount24.setOriginalDiscountList(cloneDeep(restoredSessionDiscounts));
6632
- case 23:
6633
- _context46.next = 25;
7197
+ case 24:
7198
+ _context50.next = 26;
6634
7199
  return (_this$store$discount25 = this.store.discount) === null || _this$store$discount25 === void 0 ? void 0 : _this$store$discount25.setDiscountList(cloneDeep(restoredSessionDiscounts));
6635
- case 25:
7200
+ case 26:
6636
7201
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6637
- _context46.next = 28;
7202
+ _context50.next = 29;
6638
7203
  break;
6639
7204
  }
6640
- _context46.next = 28;
7205
+ _context50.next = 29;
6641
7206
  return this.recalculateSummary({
6642
7207
  createIfMissing: false
6643
7208
  });
6644
- case 28:
7209
+ case 29:
6645
7210
  this.persistTempOrder();
6646
- return _context46.abrupt("return", nextTempOrder);
6647
- case 30:
7211
+ return _context50.abrupt("return", nextTempOrder);
7212
+ case 31:
6648
7213
  // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
6649
7214
  sourceLastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
6650
7215
  isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
@@ -6695,34 +7260,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6695
7260
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
6696
7261
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
6697
7262
  if (shouldSkipEmptyDiscountSync) {
6698
- _context46.next = 54;
7263
+ _context50.next = 55;
6699
7264
  break;
6700
7265
  }
6701
7266
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
6702
- _context46.next = 52;
7267
+ _context50.next = 53;
6703
7268
  return (_this$store$discount27 = this.store.discount) === null || _this$store$discount27 === void 0 ? void 0 : _this$store$discount27.setOriginalDiscountList(nextDiscounts);
6704
- case 52:
6705
- _context46.next = 54;
7269
+ case 53:
7270
+ _context50.next = 55;
6706
7271
  return (_this$store$discount28 = this.store.discount) === null || _this$store$discount28 === void 0 ? void 0 : _this$store$discount28.setDiscountList(nextDiscounts);
6707
- case 54:
7272
+ case 55:
6708
7273
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6709
- _context46.next = 57;
7274
+ _context50.next = 58;
6710
7275
  break;
6711
7276
  }
6712
- _context46.next = 57;
7277
+ _context50.next = 58;
6713
7278
  return this.recalculateSummary({
6714
7279
  createIfMissing: false
6715
7280
  });
6716
- case 57:
7281
+ case 58:
6717
7282
  this.persistTempOrder();
6718
- return _context46.abrupt("return", nextTempOrder);
6719
- case 59:
7283
+ return _context50.abrupt("return", nextTempOrder);
7284
+ case 60:
6720
7285
  case "end":
6721
- return _context46.stop();
7286
+ return _context50.stop();
6722
7287
  }
6723
- }, _callee43, this);
7288
+ }, _callee47, this);
6724
7289
  }));
6725
- function hydrateTempOrderFromRecord(_x50, _x51) {
7290
+ function hydrateTempOrderFromRecord(_x52, _x53) {
6726
7291
  return _hydrateTempOrderFromRecord.apply(this, arguments);
6727
7292
  }
6728
7293
  return hydrateTempOrderFromRecord;
@@ -6775,10 +7340,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6775
7340
  _step22;
6776
7341
  try {
6777
7342
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
6778
- var _product$metadata11;
7343
+ var _product$metadata13;
6779
7344
  var product = _step22.value;
6780
7345
  var productUid = getOrderCollectionUid('product', product);
6781
- var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.booking_uid);
7346
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.booking_uid);
6782
7347
  if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
6783
7348
  continue;
6784
7349
  }
@@ -6836,7 +7401,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6836
7401
  }, {
6837
7402
  key: "normalizeTempOrderForRuntime",
6838
7403
  value: function normalizeTempOrderForRuntime(raw, options) {
6839
- var _this35 = this;
7404
+ var _this40 = this,
7405
+ _raw$_extend;
6840
7406
  var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6841
7407
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
6842
7408
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
@@ -6860,12 +7426,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6860
7426
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
6861
7427
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
6862
7428
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
6863
- return _this35.normalizeHydratedOrderProduct(p, {
7429
+ return _this40.normalizeHydratedOrderProduct(p, {
6864
7430
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
6865
7431
  });
6866
7432
  }) : [];
6867
7433
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
6868
- var booking = _this35.normalizeHydratedBookingHolder(b || {});
7434
+ var booking = _this40.normalizeHydratedBookingHolder(b || {});
6869
7435
  return _objectSpread(_objectSpread({}, booking), {}, {
6870
7436
  is_all: normalizeBookingIsAll(booking),
6871
7437
  sub_type: normalizeBookingSubType(booking)
@@ -6874,6 +7440,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6874
7440
  nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(function (p) {
6875
7441
  return _objectSpread({}, p || {});
6876
7442
  }) : [];
7443
+ var rawHasSalesNotes = Object.prototype.hasOwnProperty.call(raw, 'notes');
7444
+ var restoredSalesNotesState = (_raw$_extend = raw._extend) === null || _raw$_extend === void 0 ? void 0 : _raw$_extend.salesNotesState;
7445
+ var allowUnresolvedSalesNotes = (options === null || options === void 0 ? void 0 : options.allowUnresolvedSalesNotes) === true || (restoredSalesNotesState === null || restoredSalesNotesState === void 0 ? void 0 : restoredSalesNotesState.dirty) === true || Number(raw.is_draft_order || 0) === 1;
7446
+ var decodedSalesNotes = rawHasSalesNotes ? decodeSalesNotesSnapshot(raw.notes, {
7447
+ allowUnresolvedOrderTarget: allowUnresolvedSalesNotes
7448
+ }) : {
7449
+ notes: [],
7450
+ complete: false
7451
+ };
7452
+ var hasUnresolvedSalesNoteOrderTarget = decodedSalesNotes.notes.some(function (note) {
7453
+ return note.note_relations.some(function (relation) {
7454
+ return relation.is_primary === 0 && relation.relation_type === 'related_to' && relation.target_type === 'order' && relation.target_uuid === '';
7455
+ });
7456
+ });
7457
+ nextTempOrder.notes = decodedSalesNotes.notes;
6877
7458
  nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(function (s) {
6878
7459
  return _objectSpread({}, s || {});
6879
7460
  }) : [];
@@ -6891,20 +7472,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6891
7472
  productsByUid: {}
6892
7473
  };
6893
7474
  var tempOrderExtend = nextTempOrder._extend;
7475
+ tempOrderExtend.salesNotesState = {
7476
+ loaded: rawHasSalesNotes ? decodedSalesNotes.complete : (restoredSalesNotesState === null || restoredSalesNotesState === void 0 ? void 0 : restoredSalesNotesState.loaded) === true,
7477
+ dirty: decodedSalesNotes.complete && ((restoredSalesNotesState === null || restoredSalesNotesState === void 0 ? void 0 : restoredSalesNotesState.dirty) === true || allowUnresolvedSalesNotes && hasUnresolvedSalesNoteOrderTarget)
7478
+ };
6894
7479
  var productsByUid = tempOrderExtend.productsByUid || {};
6895
7480
  var _iterator24 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
6896
7481
  _step24;
6897
7482
  try {
6898
7483
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
6899
- var _product$metadata12, _ref85, _ref86, _existed$origin, _rawProduct$metadata;
7484
+ var _product$metadata14, _ref89, _ref90, _existed$origin, _rawProduct$metadata;
6900
7485
  var _step24$value = _slicedToArray(_step24.value, 2),
6901
7486
  index = _step24$value[0],
6902
7487
  product = _step24$value[1];
6903
- var uid = (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number;
7488
+ var uid = (_product$metadata14 = product.metadata) === null || _product$metadata14 === void 0 ? void 0 : _product$metadata14.unique_identification_number;
6904
7489
  if (!uid) continue;
6905
7490
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
6906
7491
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
6907
- var origin = (_ref85 = (_ref86 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref86 !== void 0 ? _ref86 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref85 !== void 0 ? _ref85 : rawProduct;
7492
+ var origin = (_ref89 = (_ref90 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref90 !== void 0 ? _ref90 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref89 !== void 0 ? _ref89 : rawProduct;
6908
7493
  var originSnapshot = cloneDeep(origin);
6909
7494
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
6910
7495
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -6955,8 +7540,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6955
7540
  var bookingUidByProductUid = new Map();
6956
7541
  var productByUid = new Map();
6957
7542
  (tempOrder.products || []).forEach(function (product) {
6958
- var _product$metadata13;
6959
- var productUid = (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7543
+ var _product$metadata15;
7544
+ var productUid = (product === null || product === void 0 || (_product$metadata15 = product.metadata) === null || _product$metadata15 === void 0 ? void 0 : _product$metadata15.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6960
7545
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
6961
7546
  productByUid.set(String(productUid), product);
6962
7547
  }
@@ -6977,8 +7562,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6977
7562
  bookingUidByProductUid.set(String(productUid), bookingUid);
6978
7563
  });
6979
7564
  (tempOrder.products || []).forEach(function (product) {
6980
- var _product$metadata14;
6981
- var productUid = (product === null || product === void 0 || (_product$metadata14 = product.metadata) === null || _product$metadata14 === void 0 ? void 0 : _product$metadata14.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7565
+ var _product$metadata16;
7566
+ var productUid = (product === null || product === void 0 || (_product$metadata16 = product.metadata) === null || _product$metadata16 === void 0 ? void 0 : _product$metadata16.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6982
7567
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
6983
7568
  var bookingUid = bookingUidByProductUid.get(String(productUid));
6984
7569
  if (!bookingUid) return;
@@ -7033,10 +7618,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7033
7618
  }, {
7034
7619
  key: "normalizeHydratedProductOptionItem",
7035
7620
  value: function normalizeHydratedProductOptionItem(optionItem) {
7036
- var _ref87, _optionItem$num, _ref88, _optionItem$add_price;
7037
- var rawNum = (_ref87 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref87 !== void 0 ? _ref87 : 1;
7621
+ var _ref91, _optionItem$num, _ref92, _optionItem$add_price;
7622
+ var rawNum = (_ref91 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref91 !== void 0 ? _ref91 : 1;
7038
7623
  var parsedNum = Number(rawNum);
7039
- var rawPrice = (_ref88 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref88 !== void 0 ? _ref88 : 0;
7624
+ var rawPrice = (_ref92 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref92 !== void 0 ? _ref92 : 0;
7040
7625
  var parsedPrice = Number(rawPrice);
7041
7626
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
7042
7627
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -7053,7 +7638,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7053
7638
  }, {
7054
7639
  key: "normalizeHydratedOrderProduct",
7055
7640
  value: function normalizeHydratedOrderProduct(product, options) {
7056
- var _this36 = this;
7641
+ var _this41 = this;
7057
7642
  var row = _objectSpread({}, product || {});
7058
7643
  if (row.num === undefined && row.product_quantity !== undefined) {
7059
7644
  row.num = row.product_quantity;
@@ -7061,7 +7646,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7061
7646
  var productSku = ensureProductSku(row);
7062
7647
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
7063
7648
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
7064
- return _this36.normalizeHydratedProductOptionItem(optionItem || {});
7649
+ return _this41.normalizeHydratedProductOptionItem(optionItem || {});
7065
7650
  }))
7066
7651
  });
7067
7652
  delete row["product_".concat('option', "_item")];
@@ -7121,27 +7706,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7121
7706
  }, {
7122
7707
  key: "getOrderInfo",
7123
7708
  value: function () {
7124
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(order_id) {
7709
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(order_id) {
7125
7710
  var res;
7126
- return _regeneratorRuntime().wrap(function _callee44$(_context47) {
7127
- while (1) switch (_context47.prev = _context47.next) {
7711
+ return _regeneratorRuntime().wrap(function _callee48$(_context51) {
7712
+ while (1) switch (_context51.prev = _context51.next) {
7128
7713
  case 0:
7129
- _context47.next = 2;
7714
+ _context51.next = 2;
7130
7715
  return this.request.get("/order/sales/".concat(order_id), {
7131
- with: ['products', 'bookings']
7716
+ with: ['products', 'bookings', 'notes']
7132
7717
  }, {
7133
7718
  osServer: true
7134
7719
  });
7135
7720
  case 2:
7136
- res = _context47.sent;
7137
- return _context47.abrupt("return", res);
7721
+ res = _context51.sent;
7722
+ return _context51.abrupt("return", res);
7138
7723
  case 4:
7139
7724
  case "end":
7140
- return _context47.stop();
7725
+ return _context51.stop();
7141
7726
  }
7142
- }, _callee44, this);
7727
+ }, _callee48, this);
7143
7728
  }));
7144
- function getOrderInfo(_x52) {
7729
+ function getOrderInfo(_x54) {
7145
7730
  return _getOrderInfo.apply(this, arguments);
7146
7731
  }
7147
7732
  return getOrderInfo;
@@ -7149,8 +7734,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7149
7734
  }, {
7150
7735
  key: "getVouchers",
7151
7736
  value: function getVouchers() {
7152
- var _this$store$tempOrder5;
7153
- return ((_this$store$tempOrder5 = this.store.tempOrder) === null || _this$store$tempOrder5 === void 0 ? void 0 : _this$store$tempOrder5.vouchers) || [];
7737
+ var _this$store$tempOrder6;
7738
+ return ((_this$store$tempOrder6 = this.store.tempOrder) === null || _this$store$tempOrder6 === void 0 ? void 0 : _this$store$tempOrder6.vouchers) || [];
7154
7739
  }
7155
7740
  }], [{
7156
7741
  key: "populateSavedAmounts",