@pisell/pisellos 2.2.292 → 2.2.294

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 (174) hide show
  1. package/dist/core/index.d.ts +7 -0
  2. package/dist/core/index.js +108 -65
  3. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  4. package/dist/model/strategy/adapter/itemRule/adapter.js +135 -35
  5. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  6. package/dist/model/strategy/adapter/itemRule/evaluator.js +25 -1
  7. package/dist/model/strategy/adapter/itemRule/type.d.ts +44 -0
  8. package/dist/model/strategy/adapter/itemRule/type.js +19 -1
  9. package/dist/modules/BookingContext/index.d.ts +3 -0
  10. package/dist/modules/BookingContext/index.js +42 -13
  11. package/dist/modules/BookingContext/types.d.ts +4 -4
  12. package/dist/modules/BookingContext/types.js +3 -3
  13. package/dist/modules/OpenData/types.d.ts +1 -0
  14. package/dist/modules/Order/index.d.ts +19 -4
  15. package/dist/modules/Order/index.js +885 -485
  16. package/dist/modules/Order/salesNotes.d.ts +31 -0
  17. package/dist/modules/Order/salesNotes.js +492 -0
  18. package/dist/modules/Order/types.d.ts +93 -5
  19. package/dist/modules/Order/types.js +5 -0
  20. package/dist/modules/Order/utils.d.ts +12 -0
  21. package/dist/modules/Order/utils.js +96 -31
  22. package/dist/modules/Product/types.d.ts +2 -0
  23. package/dist/modules/ProductList/clientDataVariants.d.ts +50 -0
  24. package/dist/modules/ProductList/clientDataVariants.js +216 -0
  25. package/dist/modules/ProductList/index.d.ts +18 -3
  26. package/dist/modules/ProductList/index.js +220 -38
  27. package/dist/modules/ProductList/types.d.ts +10 -0
  28. package/dist/modules/Quotation/index.d.ts +22 -0
  29. package/dist/modules/Quotation/index.js +293 -28
  30. package/dist/modules/ResourcePlanner/index.d.ts +0 -22
  31. package/dist/modules/ResourcePlanner/index.js +1 -180
  32. package/dist/modules/ResourcePlanner/localClock.d.ts +33 -0
  33. package/dist/modules/ResourcePlanner/localClock.js +183 -0
  34. package/dist/modules/ResourcePlanner/planner.d.ts +5 -14
  35. package/dist/modules/ResourcePlanner/planner.js +2111 -958
  36. package/dist/modules/ResourcePlanner/types.d.ts +359 -187
  37. package/dist/modules/ResourcePlanner/types.js +33 -1
  38. package/dist/plugins/request.d.ts +1 -0
  39. package/dist/server/index.d.ts +17 -2
  40. package/dist/server/index.js +1134 -932
  41. package/dist/server/modules/floor-plan/index.d.ts +4 -0
  42. package/dist/server/modules/floor-plan/index.js +240 -98
  43. package/dist/server/modules/menu/index.js +48 -23
  44. package/dist/server/modules/order/index.d.ts +17 -7
  45. package/dist/server/modules/order/index.js +419 -207
  46. package/dist/server/modules/products/index.d.ts +10 -4
  47. package/dist/server/modules/products/index.js +177 -84
  48. package/dist/server/modules/resource/index.js +21 -13
  49. package/dist/server/utils/product.d.ts +1 -1
  50. package/dist/server/utils/product.js +186 -22
  51. package/dist/server/utils/small-ticket.d.ts +9 -1
  52. package/dist/server/utils/small-ticket.js +136 -41
  53. package/dist/solution/BaseSales/index.d.ts +26 -3
  54. package/dist/solution/BaseSales/index.js +1384 -905
  55. package/dist/solution/BaseSales/types.d.ts +2 -0
  56. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +3 -0
  57. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +10 -3
  58. package/dist/solution/BaseSales/utils.js +6 -3
  59. package/dist/solution/BookingByStep/index.d.ts +4 -4
  60. package/dist/solution/BookingTicket/index.d.ts +1 -1
  61. package/dist/solution/BookingTicket/index.js +4 -2
  62. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  63. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -3
  64. package/dist/solution/BookingTicket/utils/orderCustomer.js +3 -2
  65. package/dist/solution/RegisterAndLogin/config.d.ts +9 -3
  66. package/dist/solution/RegisterAndLogin/config.js +95 -40
  67. package/dist/solution/RegisterAndLogin/index.js +4 -1
  68. package/dist/solution/ScanOrder/index.d.ts +1 -0
  69. package/dist/solution/ScanOrder/index.js +31 -27
  70. package/dist/solution/ScanOrder/types.d.ts +2 -0
  71. package/dist/solution/ScanOrder/utils.d.ts +1 -0
  72. package/dist/solution/ScanOrder/utils.js +8 -3
  73. package/dist/solution/UnifiedBookingSales/index.d.ts +130 -76
  74. package/dist/solution/UnifiedBookingSales/index.js +3882 -966
  75. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +49 -0
  76. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +430 -0
  77. package/dist/solution/UnifiedBookingSales/types.d.ts +161 -77
  78. package/dist/solution/UnifiedBookingSales/types.js +4 -9
  79. package/dist/solution/VenueBooking/index.d.ts +3 -0
  80. package/dist/solution/VenueBooking/index.js +549 -497
  81. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  82. package/dist/solution/VenueBooking/utils/dateSummary.js +3 -1
  83. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +2 -0
  84. package/dist/solution/VenueBooking/utils/slotMerge.js +3 -1
  85. package/dist/utils/platform.d.ts +8 -0
  86. package/dist/utils/platform.js +15 -0
  87. package/lib/core/index.d.ts +7 -0
  88. package/lib/core/index.js +20 -2
  89. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  90. package/lib/model/strategy/adapter/itemRule/adapter.js +73 -4
  91. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  92. package/lib/model/strategy/adapter/itemRule/evaluator.js +23 -1
  93. package/lib/model/strategy/adapter/itemRule/type.d.ts +44 -0
  94. package/lib/model/strategy/adapter/itemRule/type.js +19 -1
  95. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  96. package/lib/modules/BookingContext/index.d.ts +3 -0
  97. package/lib/modules/BookingContext/index.js +35 -8
  98. package/lib/modules/BookingContext/types.d.ts +4 -4
  99. package/lib/modules/BookingContext/types.js +3 -3
  100. package/lib/modules/OpenData/types.d.ts +1 -0
  101. package/lib/modules/Order/index.d.ts +19 -4
  102. package/lib/modules/Order/index.js +325 -28
  103. package/lib/modules/Order/salesNotes.d.ts +31 -0
  104. package/lib/modules/Order/salesNotes.js +382 -0
  105. package/lib/modules/Order/types.d.ts +93 -5
  106. package/lib/modules/Order/types.js +4 -0
  107. package/lib/modules/Order/utils.d.ts +12 -0
  108. package/lib/modules/Order/utils.js +85 -16
  109. package/lib/modules/Product/types.d.ts +2 -0
  110. package/lib/modules/ProductList/clientDataVariants.d.ts +50 -0
  111. package/lib/modules/ProductList/clientDataVariants.js +204 -0
  112. package/lib/modules/ProductList/index.d.ts +18 -3
  113. package/lib/modules/ProductList/index.js +137 -8
  114. package/lib/modules/ProductList/types.d.ts +10 -0
  115. package/lib/modules/Quotation/index.d.ts +22 -0
  116. package/lib/modules/Quotation/index.js +158 -11
  117. package/lib/modules/ResourcePlanner/index.d.ts +0 -22
  118. package/lib/modules/ResourcePlanner/index.js +9 -129
  119. package/lib/modules/ResourcePlanner/localClock.d.ts +33 -0
  120. package/lib/modules/ResourcePlanner/localClock.js +205 -0
  121. package/lib/modules/ResourcePlanner/planner.d.ts +5 -14
  122. package/lib/modules/ResourcePlanner/planner.js +1807 -783
  123. package/lib/modules/ResourcePlanner/types.d.ts +359 -187
  124. package/lib/modules/ResourcePlanner/types.js +13 -1
  125. package/lib/plugins/request.d.ts +1 -0
  126. package/lib/server/index.d.ts +17 -2
  127. package/lib/server/index.js +149 -21
  128. package/lib/server/modules/floor-plan/index.d.ts +4 -0
  129. package/lib/server/modules/floor-plan/index.js +60 -7
  130. package/lib/server/modules/menu/index.js +26 -4
  131. package/lib/server/modules/order/index.d.ts +17 -7
  132. package/lib/server/modules/order/index.js +194 -57
  133. package/lib/server/modules/products/index.d.ts +10 -4
  134. package/lib/server/modules/products/index.js +93 -23
  135. package/lib/server/modules/resource/index.js +12 -2
  136. package/lib/server/utils/product.d.ts +1 -1
  137. package/lib/server/utils/product.js +163 -3
  138. package/lib/server/utils/small-ticket.d.ts +9 -1
  139. package/lib/server/utils/small-ticket.js +126 -33
  140. package/lib/solution/BaseSales/index.d.ts +26 -3
  141. package/lib/solution/BaseSales/index.js +396 -70
  142. package/lib/solution/BaseSales/types.d.ts +2 -0
  143. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +3 -0
  144. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +9 -2
  145. package/lib/solution/BaseSales/utils.js +3 -0
  146. package/lib/solution/BookingByStep/index.d.ts +4 -4
  147. package/lib/solution/BookingTicket/index.d.ts +1 -1
  148. package/lib/solution/BookingTicket/index.js +2 -1
  149. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  150. package/lib/solution/BookingTicket/utils/addProductDecision.js +5 -2
  151. package/lib/solution/BookingTicket/utils/orderCustomer.js +2 -1
  152. package/lib/solution/RegisterAndLogin/config.d.ts +9 -3
  153. package/lib/solution/RegisterAndLogin/config.js +49 -8
  154. package/lib/solution/RegisterAndLogin/index.js +4 -1
  155. package/lib/solution/ScanOrder/index.d.ts +1 -0
  156. package/lib/solution/ScanOrder/index.js +5 -1
  157. package/lib/solution/ScanOrder/types.d.ts +2 -0
  158. package/lib/solution/ScanOrder/utils.d.ts +1 -0
  159. package/lib/solution/ScanOrder/utils.js +4 -0
  160. package/lib/solution/UnifiedBookingSales/index.d.ts +130 -76
  161. package/lib/solution/UnifiedBookingSales/index.js +2597 -427
  162. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +49 -0
  163. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +316 -0
  164. package/lib/solution/UnifiedBookingSales/types.d.ts +161 -77
  165. package/lib/solution/UnifiedBookingSales/types.js +4 -6
  166. package/lib/solution/VenueBooking/index.d.ts +3 -0
  167. package/lib/solution/VenueBooking/index.js +33 -9
  168. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  169. package/lib/solution/VenueBooking/utils/dateSummary.js +3 -1
  170. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +2 -0
  171. package/lib/solution/VenueBooking/utils/slotMerge.js +3 -1
  172. package/lib/utils/platform.d.ts +8 -0
  173. package/lib/utils/platform.js +22 -0
  174. package/package.json +1 -1
@@ -35,6 +35,7 @@ import { OrderHooks } from "./types";
35
35
  import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, mergeOrderProductDisplayFields, resolveIsFormSubject } from "./utils";
36
36
  import { isNormalProduct } from "../Product/utils";
37
37
  import dayjs from 'dayjs';
38
+ import { buildSalesNoteText, decodeSalesNotesSnapshot, getSalesNotePolicy } from "./salesNotes";
38
39
  import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
39
40
  import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
40
41
  import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid, PRODUCT_LINE_MERGE_DISABLED_METADATA_KEY } from "../../solution/BaseSales/utils/cartPromotion";
@@ -1373,6 +1374,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1373
1374
  if (!this.store.tempOrder) return;
1374
1375
  this.store.tempOrder = _objectSpread(_objectSpread({}, this.store.tempOrder), {}, {
1375
1376
  products: _toConsumableArray(this.store.tempOrder.products),
1377
+ notes: _toConsumableArray(this.store.tempOrder.notes || []),
1376
1378
  bookings: this.store.tempOrder.bookings ? _toConsumableArray(this.store.tempOrder.bookings) : []
1377
1379
  });
1378
1380
  this.persistTempOrder();
@@ -3227,6 +3229,277 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3227
3229
  var _this$store$tempOrder3;
3228
3230
  return ((_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.note) || '';
3229
3231
  }
3232
+ }, {
3233
+ key: "ensureSalesNotesRuntimeState",
3234
+ value: function ensureSalesNotesRuntimeState(tempOrder) {
3235
+ var hadNotesSnapshot = Array.isArray(tempOrder.notes);
3236
+ if (!Array.isArray(tempOrder.notes)) tempOrder.notes = [];
3237
+ if (!tempOrder._extend || _typeof(tempOrder._extend) !== 'object') {
3238
+ tempOrder._extend = {
3239
+ productsByUid: {}
3240
+ };
3241
+ }
3242
+ if (!tempOrder._extend.salesNotesState) {
3243
+ tempOrder._extend.salesNotesState = {
3244
+ loaded: hadNotesSnapshot,
3245
+ dirty: false
3246
+ };
3247
+ }
3248
+ return tempOrder._extend.salesNotesState;
3249
+ }
3250
+ }, {
3251
+ key: "ensureSalesNotesLoadedForMutation",
3252
+ value: function ensureSalesNotesLoadedForMutation(tempOrder) {
3253
+ var state = this.ensureSalesNotesRuntimeState(tempOrder);
3254
+ if (state.loaded) return;
3255
+ if (tempOrder.order_id === null || tempOrder.order_id === undefined) {
3256
+ state.loaded = true;
3257
+ tempOrder.notes = [];
3258
+ return;
3259
+ }
3260
+ throw new Error('[Order Notes] 当前订单 Notes 尚未完整加载,禁止提交部分快照');
3261
+ }
3262
+ }, {
3263
+ key: "normalizeSalesNoteUuid",
3264
+ value: function normalizeSalesNoteUuid(value, field) {
3265
+ var uuid = String(value !== null && value !== void 0 ? value : '').trim();
3266
+ if (!uuid) throw new Error("[Order Notes] ".concat(field, " \u4E0D\u80FD\u4E3A\u7A7A"));
3267
+ if (uuid.length > 255) {
3268
+ throw new Error("[Order Notes] ".concat(field, " \u4E0D\u80FD\u8D85\u8FC7 255 \u4E2A\u5B57\u7B26"));
3269
+ }
3270
+ return uuid;
3271
+ }
3272
+ }, {
3273
+ key: "getSalesNotePrimaryRelation",
3274
+ value: function getSalesNotePrimaryRelation(note) {
3275
+ return note.note_relations.find(function (relation) {
3276
+ return relation.is_primary === 1;
3277
+ }) || null;
3278
+ }
3279
+ }, {
3280
+ key: "removeSalesNotesForMissingProductLines",
3281
+ value: function removeSalesNotesForMissingProductLines(tempOrder) {
3282
+ var _this19 = this;
3283
+ var state = this.ensureSalesNotesRuntimeState(tempOrder);
3284
+ if (!state.loaded || !Array.isArray(tempOrder.notes) || tempOrder.notes.length === 0) {
3285
+ return;
3286
+ }
3287
+ var remainingProductUids = new Set((tempOrder.products || []).map(function (product) {
3288
+ var _product$metadata7;
3289
+ return ((_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number) || product.unique_identification_number;
3290
+ }).filter(function (uid) {
3291
+ return typeof uid === 'string' && uid.length > 0;
3292
+ }));
3293
+ var nextNotes = tempOrder.notes.filter(function (note) {
3294
+ var primary = _this19.getSalesNotePrimaryRelation(note);
3295
+ if (!primary || primary.target_type !== 'order_detail') return true;
3296
+ return remainingProductUids.has(primary.target_uuid);
3297
+ });
3298
+ if (nextNotes.length === tempOrder.notes.length) return;
3299
+ tempOrder.notes = nextNotes;
3300
+ state.dirty = true;
3301
+ }
3302
+ }, {
3303
+ key: "setSalesNoteOnTempOrder",
3304
+ value: function setSalesNoteOnTempOrder(tempOrder, input) {
3305
+ var _input$target,
3306
+ _this20 = this,
3307
+ _tempOrder$shop_order;
3308
+ this.ensureSalesNotesLoadedForMutation(tempOrder);
3309
+ var note_type = String(input.note_type || '').trim();
3310
+ var policy = getSalesNotePolicy(note_type);
3311
+ if (!policy) {
3312
+ throw new Error("[Order Notes] \u5F53\u524D\u672A\u6CE8\u518C\u5907\u6CE8\u7C7B\u578B: ".concat(note_type || '(empty)'));
3313
+ }
3314
+ if (((_input$target = input.target) === null || _input$target === void 0 ? void 0 : _input$target.target_type) !== 'order_detail') {
3315
+ throw new Error('[Order Notes] 本期只支持 order_detail 作为主体');
3316
+ }
3317
+ var target_uuid = this.normalizeSalesNoteUuid(input.target.target_uuid, 'target_uuid');
3318
+ var targetProductExists = (tempOrder.products || []).some(function (product) {
3319
+ var _product$metadata8;
3320
+ var productLineUid = ((_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.unique_identification_number) || product.unique_identification_number;
3321
+ return String(productLineUid !== null && productLineUid !== void 0 ? productLineUid : '') === target_uuid;
3322
+ });
3323
+ if (!targetProductExists) {
3324
+ throw new Error('[Order Notes] 目标商品行不存在');
3325
+ }
3326
+ var text = buildSalesNoteText(input.text);
3327
+ var notes = tempOrder.notes || [];
3328
+ // 当前 allergy policy 固定同一商品行只保留一条;业务调用方不参与去重规则。
3329
+ var existingIndex = policy.uniquePerPrimaryTarget ? notes.findIndex(function (note) {
3330
+ var primary = _this20.getSalesNotePrimaryRelation(note);
3331
+ return note.note_type === note_type && (primary === null || primary === void 0 ? void 0 : primary.target_type) === 'order_detail' && primary.target_uuid === target_uuid;
3332
+ }) : -1;
3333
+ var existing = existingIndex >= 0 ? notes[existingIndex] : null;
3334
+ var existingPrimary = existing === null || existing === void 0 ? void 0 : existing.note_relations.find(function (relation) {
3335
+ return relation.is_primary === 1 && relation.target_type === 'order_detail';
3336
+ });
3337
+ var existingOrderRelation = existing === null || existing === void 0 ? void 0 : existing.note_relations.find(function (relation) {
3338
+ return relation.is_primary === 0 && relation.target_type === 'order';
3339
+ });
3340
+ var note = {
3341
+ uuid: (existing === null || existing === void 0 ? void 0 : existing.uuid) || createUuidV4(),
3342
+ note_type: policy.note_type,
3343
+ content: {
3344
+ text: text
3345
+ },
3346
+ importance: policy.importance,
3347
+ note_relations: [{
3348
+ uuid: (existingPrimary === null || existingPrimary === void 0 ? void 0 : existingPrimary.uuid) || createUuidV4(),
3349
+ relation_type: policy.primary_relation_type,
3350
+ target_type: 'order_detail',
3351
+ target_uuid: target_uuid,
3352
+ is_primary: 1
3353
+ }, {
3354
+ uuid: (existingOrderRelation === null || existingOrderRelation === void 0 ? void 0 : existingOrderRelation.uuid) || createUuidV4(),
3355
+ relation_type: policy.secondary_order_relation_type,
3356
+ target_type: 'order',
3357
+ target_uuid: String((_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : ''),
3358
+ is_primary: 0
3359
+ }]
3360
+ };
3361
+ var duplicateIndex = notes.findIndex(function (item, index) {
3362
+ return item.uuid === note.uuid && index !== existingIndex;
3363
+ });
3364
+ if (duplicateIndex >= 0) {
3365
+ throw new Error('[Order Notes] uuid 已被其他 Note 使用');
3366
+ }
3367
+ tempOrder.notes = existingIndex >= 0 ? notes.map(function (item, index) {
3368
+ return index === existingIndex ? note : item;
3369
+ }) : [].concat(_toConsumableArray(notes), [note]);
3370
+ var state = this.ensureSalesNotesRuntimeState(tempOrder);
3371
+ state.loaded = true;
3372
+ state.dirty = true;
3373
+ return note;
3374
+ }
3375
+ }, {
3376
+ key: "getSalesNotes",
3377
+ value: function getSalesNotes() {
3378
+ var tempOrder = this.ensureTempOrder();
3379
+ this.ensureSalesNotesRuntimeState(tempOrder);
3380
+ return cloneDeep(tempOrder.notes || []);
3381
+ }
3382
+ }, {
3383
+ key: "createSalesNotesMutationSnapshot",
3384
+ value: function createSalesNotesMutationSnapshot() {
3385
+ var _tempOrder$order_id2;
3386
+ var tempOrder = this.ensureTempOrder();
3387
+ var state = this.ensureSalesNotesRuntimeState(tempOrder);
3388
+ return {
3389
+ orderIdentity: {
3390
+ orderId: (_tempOrder$order_id2 = tempOrder.order_id) !== null && _tempOrder$order_id2 !== void 0 ? _tempOrder$order_id2 : null,
3391
+ externalSaleNumber: String(tempOrder.external_sale_number || '')
3392
+ },
3393
+ notes: cloneDeep(tempOrder.notes || []),
3394
+ state: cloneDeep(state)
3395
+ };
3396
+ }
3397
+ }, {
3398
+ key: "restoreSalesNotesMutationSnapshot",
3399
+ value: function restoreSalesNotesMutationSnapshot(snapshot) {
3400
+ var _snapshot$state, _snapshot$state2;
3401
+ 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') {
3402
+ throw new Error('[Order Notes] 无效的 mutation snapshot');
3403
+ }
3404
+ var tempOrder = this.store.tempOrder;
3405
+ if (!tempOrder) throw new Error('[Order Notes] 当前订单不存在');
3406
+ var snapshotOrderId = snapshot.orderIdentity.orderId;
3407
+ var currentOrderId = tempOrder.order_id;
3408
+ var hasSnapshotOrderId = snapshotOrderId !== null && snapshotOrderId !== undefined && String(snapshotOrderId).trim().length > 0;
3409
+ var hasCurrentOrderId = currentOrderId !== null && currentOrderId !== undefined && String(currentOrderId).trim().length > 0;
3410
+ var isSameOrder = hasSnapshotOrderId && hasCurrentOrderId ? String(snapshotOrderId) === String(currentOrderId) : Boolean(snapshot.orderIdentity.externalSaleNumber) && snapshot.orderIdentity.externalSaleNumber === String(tempOrder.external_sale_number || '');
3411
+ if (!isSameOrder) {
3412
+ throw new Error('[Order Notes] 当前订单已切换,拒绝恢复旧订单快照');
3413
+ }
3414
+ this.ensureSalesNotesRuntimeState(tempOrder);
3415
+ tempOrder.notes = cloneDeep(snapshot.notes);
3416
+ tempOrder._extend.salesNotesState = cloneDeep(snapshot.state);
3417
+ this.notifyTempOrderChanged();
3418
+ }
3419
+ }, {
3420
+ key: "setSalesNote",
3421
+ value: function () {
3422
+ var _setSalesNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(input) {
3423
+ var tempOrder, note;
3424
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3425
+ while (1) switch (_context17.prev = _context17.next) {
3426
+ case 0:
3427
+ tempOrder = this.ensureTempOrder();
3428
+ note = this.setSalesNoteOnTempOrder(tempOrder, input);
3429
+ this.notifyTempOrderChanged();
3430
+ return _context17.abrupt("return", cloneDeep(note));
3431
+ case 4:
3432
+ case "end":
3433
+ return _context17.stop();
3434
+ }
3435
+ }, _callee15, this);
3436
+ }));
3437
+ function setSalesNote(_x14) {
3438
+ return _setSalesNote.apply(this, arguments);
3439
+ }
3440
+ return setSalesNote;
3441
+ }()
3442
+ }, {
3443
+ key: "removeSalesNote",
3444
+ value: function () {
3445
+ var _removeSalesNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(uuid) {
3446
+ var tempOrder, normalizedUuid, notes, nextNotes, state;
3447
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3448
+ while (1) switch (_context18.prev = _context18.next) {
3449
+ case 0:
3450
+ tempOrder = this.ensureTempOrder();
3451
+ this.ensureSalesNotesLoadedForMutation(tempOrder);
3452
+ normalizedUuid = this.normalizeSalesNoteUuid(uuid, 'uuid');
3453
+ notes = tempOrder.notes || [];
3454
+ nextNotes = notes.filter(function (note) {
3455
+ return note.uuid !== normalizedUuid;
3456
+ });
3457
+ if (!(nextNotes.length === notes.length)) {
3458
+ _context18.next = 7;
3459
+ break;
3460
+ }
3461
+ return _context18.abrupt("return");
3462
+ case 7:
3463
+ tempOrder.notes = nextNotes;
3464
+ state = this.ensureSalesNotesRuntimeState(tempOrder);
3465
+ state.dirty = true;
3466
+ this.notifyTempOrderChanged();
3467
+ case 11:
3468
+ case "end":
3469
+ return _context18.stop();
3470
+ }
3471
+ }, _callee16, this);
3472
+ }));
3473
+ function removeSalesNote(_x15) {
3474
+ return _removeSalesNote.apply(this, arguments);
3475
+ }
3476
+ return removeSalesNote;
3477
+ }()
3478
+ }, {
3479
+ key: "clearSalesNotes",
3480
+ value: function () {
3481
+ var _clearSalesNotes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
3482
+ var tempOrder, state;
3483
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3484
+ while (1) switch (_context19.prev = _context19.next) {
3485
+ case 0:
3486
+ tempOrder = this.ensureTempOrder();
3487
+ tempOrder.notes = [];
3488
+ state = this.ensureSalesNotesRuntimeState(tempOrder);
3489
+ state.loaded = true;
3490
+ state.dirty = true;
3491
+ this.notifyTempOrderChanged();
3492
+ case 6:
3493
+ case "end":
3494
+ return _context19.stop();
3495
+ }
3496
+ }, _callee17, this);
3497
+ }));
3498
+ function clearSalesNotes() {
3499
+ return _clearSalesNotes.apply(this, arguments);
3500
+ }
3501
+ return clearSalesNotes;
3502
+ }()
3230
3503
  }, {
3231
3504
  key: "updateTempOrderShopDiscount",
3232
3505
  value: function updateTempOrderShopDiscount(amount) {
@@ -3268,6 +3541,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3268
3541
  this.persistTempOrder();
3269
3542
  return tempOrder.buzzer;
3270
3543
  }
3544
+ }, {
3545
+ key: "updateTempOrderShopServiceData",
3546
+ value: function updateTempOrderShopServiceData(patch) {
3547
+ var tempOrder = this.ensureTempOrder();
3548
+ var metadata = tempOrder.metadata && _typeof(tempOrder.metadata) === 'object' && !Array.isArray(tempOrder.metadata) ? tempOrder.metadata : {};
3549
+ var currentShopServiceData = metadata.shop_service_data && _typeof(metadata.shop_service_data) === 'object' && !Array.isArray(metadata.shop_service_data) ? metadata.shop_service_data : {};
3550
+ var shopServiceData = _objectSpread(_objectSpread({}, currentShopServiceData), patch);
3551
+ tempOrder.metadata = _objectSpread(_objectSpread({}, metadata), {}, {
3552
+ shop_service_data: shopServiceData
3553
+ });
3554
+ this.persistTempOrder();
3555
+ return shopServiceData;
3556
+ }
3557
+ }, {
3558
+ key: "updateTempOrderPickupReferenceMode",
3559
+ value: function updateTempOrderPickupReferenceMode(mode) {
3560
+ return this.updateTempOrderShopServiceData({
3561
+ pickup_reference_mode: mode
3562
+ });
3563
+ }
3564
+ }, {
3565
+ key: "updateTempOrderServiceType",
3566
+ value: function updateTempOrderServiceType(serviceType) {
3567
+ return this.updateTempOrderShopServiceData({
3568
+ service_type: serviceType
3569
+ });
3570
+ }
3271
3571
  }, {
3272
3572
  key: "updateTempOrderContactsInfo",
3273
3573
  value: function updateTempOrderContactsInfo(contactsInfo) {
@@ -3309,15 +3609,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3309
3609
  }, {
3310
3610
  key: "productHasCustomerBoundDiscount",
3311
3611
  value: function productHasCustomerBoundDiscount(product) {
3312
- var _this19 = this;
3612
+ var _this21 = this;
3313
3613
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3314
- return _this19.isCustomerBoundDiscount(discount);
3614
+ return _this21.isCustomerBoundDiscount(discount);
3315
3615
  })) {
3316
3616
  return true;
3317
3617
  }
3318
3618
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3319
3619
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3320
- return _this19.isCustomerBoundDiscount(discount);
3620
+ return _this21.isCustomerBoundDiscount(discount);
3321
3621
  });
3322
3622
  });
3323
3623
  }
@@ -3326,18 +3626,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3326
3626
  value: function shouldSkipDiscountCalculation(tempOrder) {
3327
3627
  var _this$store$discount18,
3328
3628
  _this$store$discount19,
3329
- _this20 = this;
3629
+ _this22 = this;
3330
3630
  if (this.hasActiveCustomerBoundDiscount) return false;
3331
3631
  var discountList = ((_this$store$discount18 = this.store.discount) === null || _this$store$discount18 === void 0 || (_this$store$discount19 = _this$store$discount18.getDiscountList) === null || _this$store$discount19 === void 0 ? void 0 : _this$store$discount19.call(_this$store$discount18)) || [];
3332
3632
  if (discountList.length > 0) return false;
3333
3633
  return !(tempOrder.products || []).some(function (product) {
3334
- return _this20.productHasCustomerBoundDiscount(product);
3634
+ return _this22.productHasCustomerBoundDiscount(product);
3335
3635
  });
3336
3636
  }
3337
3637
  }, {
3338
3638
  key: "clearCustomerBoundDiscounts",
3339
3639
  value: function clearCustomerBoundDiscounts(tempOrder) {
3340
- var _this21 = this,
3640
+ var _this23 = this,
3341
3641
  _discountModule$getDi,
3342
3642
  _discountModule$getOr,
3343
3643
  _discountModule$setDi,
@@ -3346,7 +3646,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3346
3646
  var filterDiscountList = function filterDiscountList(discountList) {
3347
3647
  if (!Array.isArray(discountList)) return [];
3348
3648
  return discountList.filter(function (discount) {
3349
- var shouldRemove = _this21.isCustomerBoundDiscount(discount);
3649
+ var shouldRemove = _this23.isCustomerBoundDiscount(discount);
3350
3650
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3351
3651
  return !shouldRemove;
3352
3652
  });
@@ -3373,12 +3673,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3373
3673
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3374
3674
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3375
3675
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3376
- if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3377
- return !_this21.isCustomerBoundDiscount(discount);
3676
+ if (_this23.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3677
+ return !_this23.isCustomerBoundDiscount(discount);
3378
3678
  });
3379
3679
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3380
- if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3381
- return !_this21.isCustomerBoundDiscount(discount);
3680
+ if (_this23.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3681
+ return !_this23.isCustomerBoundDiscount(discount);
3382
3682
  });
3383
3683
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3384
3684
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -3539,10 +3839,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3539
3839
  }, {
3540
3840
  key: "setOrderPayments",
3541
3841
  value: function setOrderPayments(payments) {
3542
- var _this22 = this;
3842
+ var _this24 = this;
3543
3843
  var tempOrder = this.ensureTempOrder();
3544
3844
  tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
3545
- return _this22.normalizePaymentSource(payment, {
3845
+ return _this24.normalizePaymentSource(payment, {
3546
3846
  defaultPaid: false
3547
3847
  });
3548
3848
  }));
@@ -3562,34 +3862,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3562
3862
  }, {
3563
3863
  key: "addOrderPaymentAsync",
3564
3864
  value: (function () {
3565
- var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(payment) {
3865
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(payment) {
3566
3866
  var hasPaymentNumber, devicePrefix;
3567
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3568
- while (1) switch (_context17.prev = _context17.next) {
3867
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3868
+ while (1) switch (_context20.prev = _context20.next) {
3569
3869
  case 0:
3570
3870
  hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3571
3871
  if (!hasPaymentNumber) {
3572
- _context17.next = 5;
3872
+ _context20.next = 5;
3573
3873
  break;
3574
3874
  }
3575
- _context17.t0 = 'LOCAL';
3576
- _context17.next = 8;
3875
+ _context20.t0 = 'LOCAL';
3876
+ _context20.next = 8;
3577
3877
  break;
3578
3878
  case 5:
3579
- _context17.next = 7;
3879
+ _context20.next = 7;
3580
3880
  return this.getPaymentNumberDevicePrefixAsync();
3581
3881
  case 7:
3582
- _context17.t0 = _context17.sent;
3882
+ _context20.t0 = _context20.sent;
3583
3883
  case 8:
3584
- devicePrefix = _context17.t0;
3585
- return _context17.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3884
+ devicePrefix = _context20.t0;
3885
+ return _context20.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3586
3886
  case 10:
3587
3887
  case "end":
3588
- return _context17.stop();
3888
+ return _context20.stop();
3589
3889
  }
3590
- }, _callee15, this);
3890
+ }, _callee18, this);
3591
3891
  }));
3592
- function addOrderPaymentAsync(_x14) {
3892
+ function addOrderPaymentAsync(_x16) {
3593
3893
  return _addOrderPaymentAsync.apply(this, arguments);
3594
3894
  }
3595
3895
  return addOrderPaymentAsync;
@@ -3597,7 +3897,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3597
3897
  }, {
3598
3898
  key: "addOrderPaymentWithDevicePrefix",
3599
3899
  value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3600
- var _this23 = this;
3900
+ var _this25 = this;
3601
3901
  this.logInfo('addOrderPayment', {
3602
3902
  payment: payment
3603
3903
  });
@@ -3615,7 +3915,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3615
3915
  void this.recalculateSummary({
3616
3916
  createIfMissing: true
3617
3917
  }).catch(function (error) {
3618
- _this23.logError('recalculate summary after addOrderPayment failed', {
3918
+ _this25.logError('recalculate summary after addOrderPayment failed', {
3619
3919
  error: error instanceof Error ? error.message : String(error)
3620
3920
  });
3621
3921
  });
@@ -3629,7 +3929,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3629
3929
  }, {
3630
3930
  key: "updateOrderPayment",
3631
3931
  value: (function () {
3632
- var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentIdentity, updates) {
3932
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(paymentIdentity, updates) {
3633
3933
  var options,
3634
3934
  tempOrder,
3635
3935
  identity,
@@ -3638,17 +3938,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3638
3938
  updatedPayment,
3639
3939
  summary,
3640
3940
  payments,
3641
- _args18 = arguments;
3642
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3643
- while (1) switch (_context18.prev = _context18.next) {
3941
+ _args21 = arguments;
3942
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3943
+ while (1) switch (_context21.prev = _context21.next) {
3644
3944
  case 0:
3645
- options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
3945
+ options = _args21.length > 2 && _args21[2] !== undefined ? _args21[2] : {};
3646
3946
  tempOrder = this.ensureTempOrder();
3647
3947
  identity = String(paymentIdentity);
3648
3948
  matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3649
3949
  matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, matchMode);
3650
3950
  if (matchedPayment) {
3651
- _context18.next = 7;
3951
+ _context21.next = 7;
3652
3952
  break;
3653
3953
  }
3654
3954
  throw new Error("\u672A\u627E\u5230\u652F\u4ED8\u9879: ".concat(identity));
@@ -3663,15 +3963,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3663
3963
  return nextPayment;
3664
3964
  });
3665
3965
  this.persistTempOrder();
3666
- _context18.next = 12;
3966
+ _context21.next = 12;
3667
3967
  return this.recalculateSummary({
3668
3968
  createIfMissing: true
3669
3969
  });
3670
3970
  case 12:
3671
- summary = _context18.sent;
3971
+ summary = _context21.sent;
3672
3972
  this.persistTempOrder();
3673
3973
  payments = tempOrder.payments;
3674
- return _context18.abrupt("return", {
3974
+ return _context21.abrupt("return", {
3675
3975
  updated: true,
3676
3976
  payment: payments[matchedPayment.index] || updatedPayment,
3677
3977
  payments: payments,
@@ -3679,11 +3979,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3679
3979
  });
3680
3980
  case 16:
3681
3981
  case "end":
3682
- return _context18.stop();
3982
+ return _context21.stop();
3683
3983
  }
3684
- }, _callee16, this);
3984
+ }, _callee19, this);
3685
3985
  }));
3686
- function updateOrderPayment(_x15, _x16) {
3986
+ function updateOrderPayment(_x17, _x18) {
3687
3987
  return _updateOrderPayment.apply(this, arguments);
3688
3988
  }
3689
3989
  return updateOrderPayment;
@@ -3728,7 +4028,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3728
4028
  }, {
3729
4029
  key: "applyPaymentLifecycleChange",
3730
4030
  value: function applyPaymentLifecycleChange(tempOrder, options) {
3731
- var _this24 = this;
4031
+ var _this26 = this;
3732
4032
  this.updateTempOrderPaymentStatus(tempOrder);
3733
4033
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3734
4034
  this.persistTempOrder();
@@ -3738,7 +4038,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3738
4038
  void this.recalculateSummary({
3739
4039
  createIfMissing: true
3740
4040
  }).catch(function (error) {
3741
- _this24.logError("recalculate summary after ".concat(logContext, " failed"), {
4041
+ _this26.logError("recalculate summary after ".concat(logContext, " failed"), {
3742
4042
  error: error instanceof Error ? error.message : String(error)
3743
4043
  });
3744
4044
  });
@@ -3782,7 +4082,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3782
4082
  }, {
3783
4083
  key: "updateVoucherOrderPayments",
3784
4084
  value: function updateVoucherOrderPayments(payments, options) {
3785
- var _this25 = this;
4085
+ var _this27 = this;
3786
4086
  var tempOrder = this.ensureTempOrder();
3787
4087
  var isOrderPaymentType = function isOrderPaymentType(value) {
3788
4088
  return value === 'normal' || value === 'deposit';
@@ -3817,7 +4117,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3817
4117
  });
3818
4118
  };
3819
4119
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3820
- return _this25.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
4120
+ return _this27.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3821
4121
  defaultPaid: false,
3822
4122
  devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
3823
4123
  });
@@ -3870,7 +4170,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3870
4170
  void this.recalculateSummary({
3871
4171
  createIfMissing: true
3872
4172
  }).catch(function (error) {
3873
- _this25.logError('recalculate summary after updateVoucherOrderPayments failed', {
4173
+ _this27.logError('recalculate summary after updateVoucherOrderPayments failed', {
3874
4174
  error: error instanceof Error ? error.message : String(error)
3875
4175
  });
3876
4176
  });
@@ -3879,38 +4179,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3879
4179
  }, {
3880
4180
  key: "updateVoucherOrderPaymentsAsync",
3881
4181
  value: function () {
3882
- var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(payments, options) {
4182
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(payments, options) {
3883
4183
  var needsPaymentNumber, devicePrefix;
3884
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3885
- while (1) switch (_context19.prev = _context19.next) {
4184
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4185
+ while (1) switch (_context22.prev = _context22.next) {
3886
4186
  case 0:
3887
4187
  needsPaymentNumber = (payments || []).some(function (payment) {
3888
4188
  return String(payment.payment_number || '').trim() === '';
3889
4189
  });
3890
4190
  if (!needsPaymentNumber) {
3891
- _context19.next = 7;
4191
+ _context22.next = 7;
3892
4192
  break;
3893
4193
  }
3894
- _context19.next = 4;
4194
+ _context22.next = 4;
3895
4195
  return this.getPaymentNumberDevicePrefixAsync();
3896
4196
  case 4:
3897
- _context19.t0 = _context19.sent;
3898
- _context19.next = 8;
4197
+ _context22.t0 = _context22.sent;
4198
+ _context22.next = 8;
3899
4199
  break;
3900
4200
  case 7:
3901
- _context19.t0 = 'LOCAL';
4201
+ _context22.t0 = 'LOCAL';
3902
4202
  case 8:
3903
- devicePrefix = _context19.t0;
3904
- return _context19.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
4203
+ devicePrefix = _context22.t0;
4204
+ return _context22.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
3905
4205
  devicePrefix: devicePrefix
3906
4206
  })));
3907
4207
  case 10:
3908
4208
  case "end":
3909
- return _context19.stop();
4209
+ return _context22.stop();
3910
4210
  }
3911
- }, _callee17, this);
4211
+ }, _callee20, this);
3912
4212
  }));
3913
- function updateVoucherOrderPaymentsAsync(_x17, _x18) {
4213
+ function updateVoucherOrderPaymentsAsync(_x19, _x20) {
3914
4214
  return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3915
4215
  }
3916
4216
  return updateVoucherOrderPaymentsAsync;
@@ -3928,7 +4228,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3928
4228
  key: "shouldMergeProductToOrder",
3929
4229
  value: function shouldMergeProductToOrder(params) {
3930
4230
  var _this$orderHooks,
3931
- _this26 = this;
4231
+ _this28 = this;
3932
4232
  var onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3933
4233
  if (!onBeforeMergeProductToOrder) return true;
3934
4234
  var result = onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
@@ -3936,7 +4236,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3936
4236
  }));
3937
4237
  if (result && _typeof(result) === 'object' && typeof result.then === 'function') {
3938
4238
  return Promise.resolve(result).then(function (resolved) {
3939
- return _this26.normalizeShouldMergeProductResult(resolved);
4239
+ return _this28.normalizeShouldMergeProductResult(resolved);
3940
4240
  });
3941
4241
  }
3942
4242
  return this.normalizeShouldMergeProductResult(result);
@@ -3956,8 +4256,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3956
4256
  }, {
3957
4257
  key: "hasLinkedBookingUid",
3958
4258
  value: function hasLinkedBookingUid(product) {
3959
- var _product$booking_uid, _product$metadata7;
3960
- 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;
4259
+ var _product$booking_uid, _product$metadata9;
4260
+ 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;
3961
4261
  return bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '';
3962
4262
  }
3963
4263
 
@@ -3972,30 +4272,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3972
4272
  }, {
3973
4273
  key: "finalizeProductOrderMutation",
3974
4274
  value: function () {
3975
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(tempOrder, options) {
3976
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3977
- while (1) switch (_context20.prev = _context20.next) {
4275
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(tempOrder, options) {
4276
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4277
+ while (1) switch (_context23.prev = _context23.next) {
3978
4278
  case 0:
3979
4279
  this.syncTempOrderHolderFromBookings(tempOrder);
3980
4280
  if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3981
- _context20.next = 4;
4281
+ _context23.next = 4;
3982
4282
  break;
3983
4283
  }
3984
- _context20.next = 4;
4284
+ _context23.next = 4;
3985
4285
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3986
4286
  case 4:
3987
4287
  if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3988
- _context20.next = 7;
4288
+ _context23.next = 7;
3989
4289
  break;
3990
4290
  }
3991
- _context20.next = 7;
4291
+ _context23.next = 7;
3992
4292
  return this.applyPromotion();
3993
4293
  case 7:
3994
4294
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
3995
4295
  this.applyDiscount();
3996
4296
  }
3997
4297
  this.sanitizeTempOrderProducts(tempOrder);
3998
- _context20.next = 11;
4298
+ _context23.next = 11;
3999
4299
  return this.recalculateSummary({
4000
4300
  createIfMissing: true
4001
4301
  });
@@ -4003,11 +4303,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4003
4303
  this.persistTempOrder();
4004
4304
  case 12:
4005
4305
  case "end":
4006
- return _context20.stop();
4306
+ return _context23.stop();
4007
4307
  }
4008
- }, _callee18, this);
4308
+ }, _callee21, this);
4009
4309
  }));
4010
- function finalizeProductOrderMutation(_x19, _x20) {
4310
+ function finalizeProductOrderMutation(_x21, _x22) {
4011
4311
  return _finalizeProductOrderMutation.apply(this, arguments);
4012
4312
  }
4013
4313
  return finalizeProductOrderMutation;
@@ -4033,7 +4333,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4033
4333
  _metadata,
4034
4334
  _productToAdd$metadat,
4035
4335
  _origin,
4036
- _this27 = this;
4336
+ _this29 = this;
4037
4337
  var linked = booking ? this.createLinkedProductAndBooking({
4038
4338
  product: product,
4039
4339
  booking: booking
@@ -4066,8 +4366,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4066
4366
  var shouldForceNewLine = disableMerge || !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4067
4367
  var matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4068
4368
  var _item$metadata3;
4069
- if (_this27.hasGoodPassDiscount(item)) return false;
4070
- if (_this27.hasOrderProductLineNote(item)) return false;
4369
+ if (_this29.hasGoodPassDiscount(item)) return false;
4370
+ if (_this29.hasOrderProductLineNote(item)) return false;
4071
4371
  if (isManualProductDiscountProduct(item)) return false;
4072
4372
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
4073
4373
  if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
@@ -4079,8 +4379,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4079
4379
  var matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
4080
4380
  var existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
4081
4381
  var commitProductLine = function commitProductLine(shouldMerge) {
4382
+ var committedProduct;
4082
4383
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
4083
- _this27.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4384
+ _this29.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4084
4385
  if (linked) {
4085
4386
  normalizedIncoming.booking_uid = linked.bookingUid;
4086
4387
  normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
@@ -4093,6 +4394,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4093
4394
  } else {
4094
4395
  tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
4095
4396
  }
4397
+ committedProduct = normalizedIncoming;
4096
4398
  } else {
4097
4399
  var _targetProduct$metada;
4098
4400
  var targetProduct = matchedProduct;
@@ -4120,7 +4422,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4120
4422
  order_detail_id: targetProduct.order_detail_id,
4121
4423
  num: nextNum
4122
4424
  });
4123
- _this27.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4425
+ _this29.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4426
+ committedProduct = tempOrder.products[matchedIndex];
4124
4427
  if (matchedIndex !== tempOrder.products.length - 1) {
4125
4428
  var mergedProduct = tempOrder.products[matchedIndex];
4126
4429
  tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, matchedIndex)), _toConsumableArray(tempOrder.products.slice(matchedIndex + 1)), [mergedProduct]);
@@ -4129,10 +4432,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4129
4432
  if (linked) {
4130
4433
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
4131
4434
  }
4435
+ return committedProduct;
4132
4436
  };
4133
4437
  if (!matchedProduct) {
4134
- commitProductLine(false);
4135
- return;
4438
+ return commitProductLine(false);
4136
4439
  }
4137
4440
  var shouldMerge = this.shouldMergeProductToOrder({
4138
4441
  incomingProduct: productToAdd,
@@ -4147,7 +4450,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4147
4450
  if (shouldMerge && _typeof(shouldMerge) === 'object' && typeof shouldMerge.then === 'function') {
4148
4451
  return Promise.resolve(shouldMerge).then(commitProductLine);
4149
4452
  }
4150
- commitProductLine(shouldMerge);
4453
+ return commitProductLine(shouldMerge);
4151
4454
  }
4152
4455
 
4153
4456
  /**
@@ -4160,12 +4463,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4160
4463
  }, {
4161
4464
  key: "addProductToOrder",
4162
4465
  value: (function () {
4163
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(product, booking, options) {
4164
- var tempOrder, insertAfterProductUid, anchorIndex, insertAtIndex, _ref60, _productRecord$num, productRecord, splitCount, i, singleLine, _appendResult, appendResult;
4165
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
4166
- while (1) switch (_context21.prev = _context21.next) {
4466
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(product, booking, options) {
4467
+ var _this30 = this;
4468
+ var tempOrder, salesNoteDrafts, mutationSnapshot, attachSalesNoteDrafts, rollbackProductAndNotesMutation, insertAfterProductUid, anchorIndex, insertAtIndex, _ref60, _productRecord$num, productRecord, splitCount, i, singleLine, singleBooking, committedProduct, _committedProduct, _committedProduct2;
4469
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4470
+ while (1) switch (_context24.prev = _context24.next) {
4167
4471
  case 0:
4168
4472
  tempOrder = this.ensureTempOrder();
4473
+ salesNoteDrafts = ((options === null || options === void 0 ? void 0 : options.salesNotes) || []).map(function (draft) {
4474
+ return {
4475
+ note_type: String(draft.note_type || '').trim(),
4476
+ text: {
4477
+ kind: 'resolved',
4478
+ text: buildSalesNoteText(draft.text)
4479
+ }
4480
+ };
4481
+ });
4482
+ mutationSnapshot = salesNoteDrafts.length > 0 ? {
4483
+ products: cloneDeep(tempOrder.products || []),
4484
+ bookings: cloneDeep(tempOrder.bookings || []),
4485
+ notes: cloneDeep(tempOrder.notes || []),
4486
+ extend: cloneDeep(tempOrder._extend || {})
4487
+ } : null;
4488
+ attachSalesNoteDrafts = function attachSalesNoteDrafts(orderProduct) {
4489
+ var _orderProduct$metadat;
4490
+ if (!salesNoteDrafts.length) return;
4491
+ var productLineUid = ((_orderProduct$metadat = orderProduct.metadata) === null || _orderProduct$metadat === void 0 ? void 0 : _orderProduct$metadat.unique_identification_number) || orderProduct.unique_identification_number;
4492
+ if (!productLineUid) {
4493
+ throw new Error('[Order Notes] 商品行缺少 unique_identification_number');
4494
+ }
4495
+ salesNoteDrafts.forEach(function (draft) {
4496
+ _this30.setSalesNoteOnTempOrder(tempOrder, {
4497
+ note_type: draft.note_type,
4498
+ target: {
4499
+ target_type: 'order_detail',
4500
+ target_uuid: String(productLineUid)
4501
+ },
4502
+ text: draft.text
4503
+ });
4504
+ });
4505
+ };
4506
+ rollbackProductAndNotesMutation = function rollbackProductAndNotesMutation() {
4507
+ if (!mutationSnapshot) return;
4508
+ tempOrder.products = mutationSnapshot.products;
4509
+ tempOrder.bookings = mutationSnapshot.bookings;
4510
+ tempOrder.notes = mutationSnapshot.notes;
4511
+ tempOrder._extend = mutationSnapshot.extend;
4512
+ };
4169
4513
  insertAfterProductUid = options === null || options === void 0 ? void 0 : options.insertAfterProductUid;
4170
4514
  anchorIndex = booking && insertAfterProductUid ? tempOrder.products.findIndex(function (line) {
4171
4515
  var _line$metadata;
@@ -4173,73 +4517,102 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4173
4517
  return uid !== undefined && uid !== null && String(uid) === String(insertAfterProductUid);
4174
4518
  }) : -1;
4175
4519
  insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
4520
+ _context24.prev = 8;
4176
4521
  if (!booking) {
4177
- _context21.next = 24;
4522
+ _context24.next = 36;
4178
4523
  break;
4179
4524
  }
4180
4525
  productRecord = product;
4181
4526
  splitCount = getSafeProductNum((_ref60 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref60 !== void 0 ? _ref60 : 1);
4182
4527
  if (!(splitCount > 1)) {
4183
- _context21.next = 24;
4528
+ _context24.next = 30;
4184
4529
  break;
4185
4530
  }
4186
4531
  i = 0;
4187
- case 9:
4532
+ case 14:
4188
4533
  if (!(i < splitCount)) {
4189
- _context21.next = 21;
4534
+ _context24.next = 28;
4190
4535
  break;
4191
4536
  }
4192
4537
  singleLine = cloneDeep(productRecord);
4538
+ singleBooking = cloneDeep(booking);
4193
4539
  singleLine.num = 1;
4194
4540
  delete singleLine.product_quantity;
4195
- _appendResult = this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking), {
4541
+ if (i > 0) {
4542
+ delete singleLine.unique_identification_number;
4543
+ delete singleLine.identity_key;
4544
+ if (singleLine.metadata) {
4545
+ singleLine.metadata = _objectSpread({}, singleLine.metadata);
4546
+ delete singleLine.metadata.unique_identification_number;
4547
+ delete singleLine.metadata.identity_key;
4548
+ }
4549
+ delete singleBooking.booking_uid;
4550
+ if (singleBooking.metadata) {
4551
+ singleBooking.metadata = _objectSpread({}, singleBooking.metadata);
4552
+ delete singleBooking.metadata.unique_identification_number;
4553
+ }
4554
+ }
4555
+ _context24.next = 22;
4556
+ return this.appendProductLineToTempOrder(tempOrder, singleLine, singleBooking, {
4196
4557
  insertAtIndex: insertAtIndex,
4197
4558
  disableMerge: options === null || options === void 0 ? void 0 : options.disableMerge
4198
4559
  });
4199
- if (!_appendResult) {
4200
- _context21.next = 17;
4201
- break;
4202
- }
4203
- _context21.next = 17;
4204
- return _appendResult;
4205
- case 17:
4560
+ case 22:
4561
+ committedProduct = _context24.sent;
4562
+ attachSalesNoteDrafts(committedProduct);
4206
4563
  if (insertAtIndex !== undefined) insertAtIndex += 1;
4207
- case 18:
4564
+ case 25:
4208
4565
  i += 1;
4209
- _context21.next = 9;
4566
+ _context24.next = 14;
4210
4567
  break;
4211
- case 21:
4212
- _context21.next = 23;
4213
- return this.finalizeProductOrderMutation(tempOrder);
4214
- case 23:
4215
- return _context21.abrupt("return", tempOrder.products);
4216
- case 24:
4217
- appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking, {
4568
+ case 28:
4569
+ _context24.next = 34;
4570
+ break;
4571
+ case 30:
4572
+ _context24.next = 32;
4573
+ return this.appendProductLineToTempOrder(tempOrder, product, cloneDeep(booking), {
4218
4574
  insertAtIndex: insertAtIndex,
4219
4575
  disableMerge: options === null || options === void 0 ? void 0 : options.disableMerge
4220
4576
  });
4221
- if (!appendResult) {
4222
- _context21.next = 28;
4223
- break;
4224
- }
4225
- _context21.next = 28;
4226
- return appendResult;
4227
- case 28:
4228
- _context21.next = 30;
4577
+ case 32:
4578
+ _committedProduct = _context24.sent;
4579
+ attachSalesNoteDrafts(_committedProduct);
4580
+ case 34:
4581
+ _context24.next = 40;
4582
+ break;
4583
+ case 36:
4584
+ _context24.next = 38;
4585
+ return this.appendProductLineToTempOrder(tempOrder, product, undefined, {
4586
+ insertAtIndex: insertAtIndex,
4587
+ disableMerge: options === null || options === void 0 ? void 0 : options.disableMerge
4588
+ });
4589
+ case 38:
4590
+ _committedProduct2 = _context24.sent;
4591
+ attachSalesNoteDrafts(_committedProduct2);
4592
+ case 40:
4593
+ _context24.next = 46;
4594
+ break;
4595
+ case 42:
4596
+ _context24.prev = 42;
4597
+ _context24.t0 = _context24["catch"](8);
4598
+ rollbackProductAndNotesMutation();
4599
+ throw _context24.t0;
4600
+ case 46:
4601
+ _context24.next = 48;
4229
4602
  return this.finalizeProductOrderMutation(tempOrder);
4230
- case 30:
4603
+ case 48:
4231
4604
  this.logInfo('addProductToOrder success', {
4232
4605
  product_id: product.product_id,
4233
4606
  with_booking: !!booking
4234
4607
  });
4235
- return _context21.abrupt("return", tempOrder.products);
4236
- case 32:
4608
+ return _context24.abrupt("return", tempOrder.products);
4609
+ case 50:
4237
4610
  case "end":
4238
- return _context21.stop();
4611
+ return _context24.stop();
4239
4612
  }
4240
- }, _callee19, this);
4613
+ }, _callee22, this, [[8, 42]]);
4241
4614
  }));
4242
- function addProductToOrder(_x21, _x22, _x23) {
4615
+ function addProductToOrder(_x23, _x24, _x25) {
4243
4616
  return _addProductToOrder.apply(this, arguments);
4244
4617
  }
4245
4618
  return addProductToOrder;
@@ -4257,103 +4630,103 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4257
4630
  }, {
4258
4631
  key: "addProductsToOrder",
4259
4632
  value: (function () {
4260
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(items, options) {
4261
- var tempOrder, _iterator20, _step20, item, product, booking, _ref61, _productRecord$num2, productRecord, splitCount, i, singleLine, _appendResult2, appendResult;
4262
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4263
- while (1) switch (_context22.prev = _context22.next) {
4633
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(items, options) {
4634
+ var tempOrder, _iterator20, _step20, item, product, booking, _ref61, _productRecord$num2, productRecord, splitCount, i, singleLine, _appendResult, appendResult;
4635
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4636
+ while (1) switch (_context25.prev = _context25.next) {
4264
4637
  case 0:
4265
4638
  tempOrder = this.ensureTempOrder();
4266
4639
  if (!(!Array.isArray(items) || items.length === 0)) {
4267
- _context22.next = 3;
4640
+ _context25.next = 3;
4268
4641
  break;
4269
4642
  }
4270
- return _context22.abrupt("return", tempOrder.products);
4643
+ return _context25.abrupt("return", tempOrder.products);
4271
4644
  case 3:
4272
4645
  _iterator20 = _createForOfIteratorHelper(items || []);
4273
- _context22.prev = 4;
4646
+ _context25.prev = 4;
4274
4647
  _iterator20.s();
4275
4648
  case 6:
4276
4649
  if ((_step20 = _iterator20.n()).done) {
4277
- _context22.next = 34;
4650
+ _context25.next = 34;
4278
4651
  break;
4279
4652
  }
4280
4653
  item = _step20.value;
4281
4654
  product = item.product, booking = item.booking;
4282
4655
  if (product) {
4283
- _context22.next = 11;
4656
+ _context25.next = 11;
4284
4657
  break;
4285
4658
  }
4286
- return _context22.abrupt("continue", 32);
4659
+ return _context25.abrupt("continue", 32);
4287
4660
  case 11:
4288
4661
  if (!booking) {
4289
- _context22.next = 28;
4662
+ _context25.next = 28;
4290
4663
  break;
4291
4664
  }
4292
4665
  productRecord = product;
4293
4666
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
4294
4667
  if (!(splitCount > 1)) {
4295
- _context22.next = 28;
4668
+ _context25.next = 28;
4296
4669
  break;
4297
4670
  }
4298
4671
  i = 0;
4299
4672
  case 16:
4300
4673
  if (!(i < splitCount)) {
4301
- _context22.next = 27;
4674
+ _context25.next = 27;
4302
4675
  break;
4303
4676
  }
4304
4677
  singleLine = cloneDeep(productRecord);
4305
4678
  singleLine.num = 1;
4306
4679
  delete singleLine.product_quantity;
4307
- _appendResult2 = this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
4308
- if (!_appendResult2) {
4309
- _context22.next = 24;
4680
+ _appendResult = this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
4681
+ if (!_appendResult) {
4682
+ _context25.next = 24;
4310
4683
  break;
4311
4684
  }
4312
- _context22.next = 24;
4313
- return _appendResult2;
4685
+ _context25.next = 24;
4686
+ return _appendResult;
4314
4687
  case 24:
4315
4688
  i += 1;
4316
- _context22.next = 16;
4689
+ _context25.next = 16;
4317
4690
  break;
4318
4691
  case 27:
4319
- return _context22.abrupt("continue", 32);
4692
+ return _context25.abrupt("continue", 32);
4320
4693
  case 28:
4321
4694
  appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking);
4322
4695
  if (!appendResult) {
4323
- _context22.next = 32;
4696
+ _context25.next = 32;
4324
4697
  break;
4325
4698
  }
4326
- _context22.next = 32;
4699
+ _context25.next = 32;
4327
4700
  return appendResult;
4328
4701
  case 32:
4329
- _context22.next = 6;
4702
+ _context25.next = 6;
4330
4703
  break;
4331
4704
  case 34:
4332
- _context22.next = 39;
4705
+ _context25.next = 39;
4333
4706
  break;
4334
4707
  case 36:
4335
- _context22.prev = 36;
4336
- _context22.t0 = _context22["catch"](4);
4337
- _iterator20.e(_context22.t0);
4708
+ _context25.prev = 36;
4709
+ _context25.t0 = _context25["catch"](4);
4710
+ _iterator20.e(_context25.t0);
4338
4711
  case 39:
4339
- _context22.prev = 39;
4712
+ _context25.prev = 39;
4340
4713
  _iterator20.f();
4341
- return _context22.finish(39);
4714
+ return _context25.finish(39);
4342
4715
  case 42:
4343
- _context22.next = 44;
4716
+ _context25.next = 44;
4344
4717
  return this.finalizeProductOrderMutation(tempOrder, options);
4345
4718
  case 44:
4346
4719
  this.logInfo('addProductsToOrder success', {
4347
4720
  itemsCount: items.length
4348
4721
  });
4349
- return _context22.abrupt("return", tempOrder.products);
4722
+ return _context25.abrupt("return", tempOrder.products);
4350
4723
  case 46:
4351
4724
  case "end":
4352
- return _context22.stop();
4725
+ return _context25.stop();
4353
4726
  }
4354
- }, _callee20, this, [[4, 36, 39, 42]]);
4727
+ }, _callee23, this, [[4, 36, 39, 42]]);
4355
4728
  }));
4356
- function addProductsToOrder(_x24, _x25) {
4729
+ function addProductsToOrder(_x26, _x27) {
4357
4730
  return _addProductsToOrder.apply(this, arguments);
4358
4731
  }
4359
4732
  return addProductsToOrder;
@@ -4387,17 +4760,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4387
4760
  }, {
4388
4761
  key: "preservePersistedBundlePriceFields",
4389
4762
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4390
- var _this28 = this;
4763
+ var _this31 = this;
4391
4764
  if (!Array.isArray(nextBundles)) return nextBundles;
4392
4765
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4393
4766
  var previousByIdentity = new Map();
4394
4767
  previousBundles.forEach(function (bundle) {
4395
- var identity = _this28.getBundleRuntimeIdentity(bundle);
4768
+ var identity = _this31.getBundleRuntimeIdentity(bundle);
4396
4769
  if (identity) previousByIdentity.set(identity, bundle);
4397
4770
  });
4398
4771
  return nextBundles.map(function (bundle, index) {
4399
4772
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4400
- var previous = previousByIdentity.get(_this28.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4773
+ var previous = previousByIdentity.get(_this31.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4401
4774
  if (!previous || _typeof(previous) !== 'object') return bundle;
4402
4775
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4403
4776
  cover: previous.cover
@@ -4598,21 +4971,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4598
4971
  }, {
4599
4972
  key: "updateOrderProduct",
4600
4973
  value: function () {
4601
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
4974
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
4602
4975
  var tempOrder, updatedProductUid;
4603
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4604
- while (1) switch (_context23.prev = _context23.next) {
4976
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4977
+ while (1) switch (_context26.prev = _context26.next) {
4605
4978
  case 0:
4606
4979
  tempOrder = this.ensureTempOrder();
4607
4980
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4608
- _context23.next = 4;
4981
+ _context26.next = 4;
4609
4982
  return this.applyPromotion();
4610
4983
  case 4:
4611
4984
  this.applyDiscount({
4612
4985
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4613
4986
  });
4614
4987
  this.sanitizeTempOrderProducts(tempOrder);
4615
- _context23.next = 8;
4988
+ _context26.next = 8;
4616
4989
  return this.recalculateSummary({
4617
4990
  createIfMissing: true
4618
4991
  });
@@ -4621,14 +4994,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4621
4994
  this.logInfo('updateOrderProduct success', {
4622
4995
  params: params
4623
4996
  });
4624
- return _context23.abrupt("return", tempOrder.products);
4997
+ return _context26.abrupt("return", tempOrder.products);
4625
4998
  case 11:
4626
4999
  case "end":
4627
- return _context23.stop();
5000
+ return _context26.stop();
4628
5001
  }
4629
- }, _callee21, this);
5002
+ }, _callee24, this);
4630
5003
  }));
4631
- function updateOrderProduct(_x26) {
5004
+ function updateOrderProduct(_x28) {
4632
5005
  return _updateOrderProduct.apply(this, arguments);
4633
5006
  }
4634
5007
  return updateOrderProduct;
@@ -4636,28 +5009,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4636
5009
  }, {
4637
5010
  key: "updateOrderProducts",
4638
5011
  value: function () {
4639
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(paramsList) {
4640
- var _this29 = this;
5012
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(paramsList) {
5013
+ var _this32 = this;
4641
5014
  var tempOrder, reapplyBookingDiscountProductUids;
4642
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4643
- while (1) switch (_context24.prev = _context24.next) {
5015
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
5016
+ while (1) switch (_context27.prev = _context27.next) {
4644
5017
  case 0:
4645
5018
  tempOrder = this.ensureTempOrder();
4646
5019
  if (paramsList.length) {
4647
- _context24.next = 3;
5020
+ _context27.next = 3;
4648
5021
  break;
4649
5022
  }
4650
- return _context24.abrupt("return", tempOrder.products);
5023
+ return _context27.abrupt("return", tempOrder.products);
4651
5024
  case 3:
4652
5025
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4653
- var updatedProductUid = _this29.applyOrderProductUpdateToTempOrder(tempOrder, params);
5026
+ var updatedProductUid = _this32.applyOrderProductUpdateToTempOrder(tempOrder, params);
4654
5027
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4655
5028
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4656
5029
  acc.push(String(updatedProductUid));
4657
5030
  }
4658
5031
  return acc;
4659
5032
  }, []);
4660
- _context24.next = 6;
5033
+ _context27.next = 6;
4661
5034
  return this.finalizeAfterProductsMutation(tempOrder, {
4662
5035
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4663
5036
  });
@@ -4665,14 +5038,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4665
5038
  this.logInfo('updateOrderProduct success', {
4666
5039
  paramsList: paramsList
4667
5040
  });
4668
- return _context24.abrupt("return", tempOrder.products);
5041
+ return _context27.abrupt("return", tempOrder.products);
4669
5042
  case 8:
4670
5043
  case "end":
4671
- return _context24.stop();
5044
+ return _context27.stop();
4672
5045
  }
4673
- }, _callee22, this);
5046
+ }, _callee25, this);
4674
5047
  }));
4675
- function updateOrderProducts(_x27) {
5048
+ function updateOrderProducts(_x29) {
4676
5049
  return _updateOrderProducts.apply(this, arguments);
4677
5050
  }
4678
5051
  return updateOrderProducts;
@@ -4680,11 +5053,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4680
5053
  }, {
4681
5054
  key: "updateOrderProductQuantity",
4682
5055
  value: function () {
4683
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
5056
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
4684
5057
  var _targetProduct$metada17;
4685
5058
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4686
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4687
- while (1) switch (_context25.prev = _context25.next) {
5059
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
5060
+ while (1) switch (_context28.prev = _context28.next) {
4688
5061
  case 0:
4689
5062
  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;
4690
5063
  tempOrder = this.ensureTempOrder();
@@ -4714,7 +5087,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4714
5087
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4715
5088
  }
4716
5089
  if (!(productIndex === -1)) {
4717
- _context25.next = 13;
5090
+ _context28.next = 13;
4718
5091
  break;
4719
5092
  }
4720
5093
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -4728,12 +5101,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4728
5101
  }));
4729
5102
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4730
5103
  tempOrder.products[productIndex] = normalizedProduct;
4731
- _context25.next = 19;
5104
+ _context28.next = 19;
4732
5105
  return this.applyPromotion();
4733
5106
  case 19:
4734
5107
  this.applyDiscount();
4735
5108
  this.sanitizeTempOrderProducts(tempOrder);
4736
- _context25.next = 23;
5109
+ _context28.next = 23;
4737
5110
  return this.recalculateSummary({
4738
5111
  createIfMissing: true
4739
5112
  });
@@ -4742,14 +5115,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4742
5115
  this.logInfo('updateOrderProductQuantity success', {
4743
5116
  params: params
4744
5117
  });
4745
- return _context25.abrupt("return", tempOrder.products);
5118
+ return _context28.abrupt("return", tempOrder.products);
4746
5119
  case 26:
4747
5120
  case "end":
4748
- return _context25.stop();
5121
+ return _context28.stop();
4749
5122
  }
4750
- }, _callee23, this);
5123
+ }, _callee26, this);
4751
5124
  }));
4752
- function updateOrderProductQuantity(_x28) {
5125
+ function updateOrderProductQuantity(_x30) {
4753
5126
  return _updateOrderProductQuantity.apply(this, arguments);
4754
5127
  }
4755
5128
  return updateOrderProductQuantity;
@@ -4790,19 +5163,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4790
5163
  }, {
4791
5164
  key: "finalizeAfterProductsMutation",
4792
5165
  value: (function () {
4793
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(tempOrder, options) {
4794
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4795
- while (1) switch (_context26.prev = _context26.next) {
5166
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(tempOrder, options) {
5167
+ return _regeneratorRuntime().wrap(function _callee27$(_context29) {
5168
+ while (1) switch (_context29.prev = _context29.next) {
4796
5169
  case 0:
4797
5170
  this.syncTempOrderHolderFromBookings(tempOrder);
4798
- _context26.next = 3;
5171
+ _context29.next = 3;
4799
5172
  return this.applyPromotion();
4800
5173
  case 3:
4801
5174
  this.applyDiscount({
4802
5175
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4803
5176
  });
4804
5177
  this.sanitizeTempOrderProducts(tempOrder);
4805
- _context26.next = 7;
5178
+ _context29.next = 7;
4806
5179
  return this.recalculateSummary({
4807
5180
  createIfMissing: true
4808
5181
  });
@@ -4810,11 +5183,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4810
5183
  this.persistTempOrder();
4811
5184
  case 8:
4812
5185
  case "end":
4813
- return _context26.stop();
5186
+ return _context29.stop();
4814
5187
  }
4815
- }, _callee24, this);
5188
+ }, _callee27, this);
4816
5189
  }));
4817
- function finalizeAfterProductsMutation(_x29, _x30) {
5190
+ function finalizeAfterProductsMutation(_x31, _x32) {
4818
5191
  return _finalizeAfterProductsMutation.apply(this, arguments);
4819
5192
  }
4820
5193
  return finalizeAfterProductsMutation;
@@ -4829,20 +5202,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4829
5202
  }, {
4830
5203
  key: "removeProductsFromOrder",
4831
5204
  value: (function () {
4832
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identities, options) {
4833
- var _this30 = this;
5205
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identities, options) {
5206
+ var _this33 = this;
4834
5207
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
4835
- return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4836
- while (1) switch (_context28.prev = _context28.next) {
5208
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
5209
+ while (1) switch (_context31.prev = _context31.next) {
4837
5210
  case 0:
4838
5211
  tempOrder = this.ensureTempOrder();
4839
- this.repairDuplicateProductLineIdentities(tempOrder);
4840
5212
  if (identities.length) {
4841
- _context28.next = 4;
5213
+ _context31.next = 3;
4842
5214
  break;
4843
5215
  }
4844
- return _context28.abrupt("return", tempOrder.products);
4845
- case 4:
5216
+ return _context31.abrupt("return", tempOrder.products);
5217
+ case 3:
5218
+ // 商品删除会同步删除以商品行为主关系的 Notes;快照不完整时禁止产生孤儿 Relation。
5219
+ this.ensureSalesNotesLoadedForMutation(tempOrder);
5220
+ this.repairDuplicateProductLineIdentities(tempOrder);
4846
5221
  productsBeforeRemove = tempOrder.products || [];
4847
5222
  bookingsBeforeRemove = tempOrder.bookings || [];
4848
5223
  preserveDisplayPosition = options === null || options === void 0 ? void 0 : options.preserveDisplayPosition;
@@ -4871,29 +5246,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4871
5246
  }
4872
5247
  linkedBookingUidsToRemove = new Set();
4873
5248
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4874
- _context28.prev = 15;
5249
+ _context31.prev = 16;
4875
5250
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4876
5251
  var _metadata11, _metadata12, _metadata13, _metadata14;
4877
5252
  var product, productUid, productBookingUid, isAddTimeProduct;
4878
- return _regeneratorRuntime().wrap(function _loop3$(_context27) {
4879
- while (1) switch (_context27.prev = _context27.next) {
5253
+ return _regeneratorRuntime().wrap(function _loop3$(_context30) {
5254
+ while (1) switch (_context30.prev = _context30.next) {
4880
5255
  case 0:
4881
5256
  product = _step21.value;
4882
5257
  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);
4883
5258
  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);
4884
5259
  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;
4885
5260
  if (!isAddTimeProduct) {
4886
- _context27.next = 6;
5261
+ _context30.next = 6;
4887
5262
  break;
4888
5263
  }
4889
- return _context27.abrupt("return", 1);
5264
+ return _context30.abrupt("return", 1);
4890
5265
  case 6:
4891
5266
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4892
5267
  linkedBookingUidsToRemove.add(String(productBookingUid));
4893
5268
  }
4894
5269
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4895
5270
  bookingsBeforeRemove.forEach(function (booking) {
4896
- var bookingUid = _this30.getBookingUniqueIdentificationNumber(booking);
5271
+ var bookingUid = _this33.getBookingUniqueIdentificationNumber(booking);
4897
5272
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4898
5273
  linkedBookingUidsToRemove.add(bookingUid);
4899
5274
  }
@@ -4901,38 +5276,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4901
5276
  }
4902
5277
  case 8:
4903
5278
  case "end":
4904
- return _context27.stop();
5279
+ return _context30.stop();
4905
5280
  }
4906
5281
  }, _loop3);
4907
5282
  });
4908
5283
  _iterator21.s();
4909
- case 18:
5284
+ case 19:
4910
5285
  if ((_step21 = _iterator21.n()).done) {
4911
- _context28.next = 24;
5286
+ _context31.next = 25;
4912
5287
  break;
4913
5288
  }
4914
- return _context28.delegateYield(_loop3(), "t0", 20);
4915
- case 20:
4916
- if (!_context28.t0) {
4917
- _context28.next = 22;
5289
+ return _context31.delegateYield(_loop3(), "t0", 21);
5290
+ case 21:
5291
+ if (!_context31.t0) {
5292
+ _context31.next = 23;
4918
5293
  break;
4919
5294
  }
4920
- return _context28.abrupt("continue", 22);
4921
- case 22:
4922
- _context28.next = 18;
5295
+ return _context31.abrupt("continue", 23);
5296
+ case 23:
5297
+ _context31.next = 19;
4923
5298
  break;
4924
- case 24:
4925
- _context28.next = 29;
5299
+ case 25:
5300
+ _context31.next = 30;
4926
5301
  break;
4927
- case 26:
4928
- _context28.prev = 26;
4929
- _context28.t1 = _context28["catch"](15);
4930
- _iterator21.e(_context28.t1);
4931
- case 29:
4932
- _context28.prev = 29;
5302
+ case 27:
5303
+ _context31.prev = 27;
5304
+ _context31.t1 = _context31["catch"](16);
5305
+ _iterator21.e(_context31.t1);
5306
+ case 30:
5307
+ _context31.prev = 30;
4933
5308
  _iterator21.f();
4934
- return _context28.finish(29);
4935
- case 32:
5309
+ return _context31.finish(30);
5310
+ case 33:
4936
5311
  if (linkedBookingUidsToRemove.size > 0) {
4937
5312
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
4938
5313
  tempOrder.products = (tempOrder.products || []).filter(function (line) {
@@ -4958,20 +5333,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4958
5333
  tempOrder.products = nextProductIndex >= 0 ? [].concat(_toConsumableArray(productsWithoutRemaining.slice(0, nextProductIndex)), [remainingProduct], _toConsumableArray(productsWithoutRemaining.slice(nextProductIndex))) : [].concat(_toConsumableArray(productsWithoutRemaining), [remainingProduct]);
4959
5334
  }
4960
5335
  }
4961
- _context28.next = 36;
5336
+ this.removeSalesNotesForMissingProductLines(tempOrder);
5337
+ _context31.next = 38;
4962
5338
  return this.finalizeAfterProductsMutation(tempOrder);
4963
- case 36:
5339
+ case 38:
4964
5340
  this.logInfo('removeProductsFromOrder success', {
4965
5341
  identities: identities
4966
5342
  });
4967
- return _context28.abrupt("return", tempOrder.products);
4968
- case 38:
5343
+ return _context31.abrupt("return", tempOrder.products);
5344
+ case 40:
4969
5345
  case "end":
4970
- return _context28.stop();
5346
+ return _context31.stop();
4971
5347
  }
4972
- }, _callee25, this, [[15, 26, 29, 32]]);
5348
+ }, _callee28, this, [[16, 27, 30, 33]]);
4973
5349
  }));
4974
- function removeProductsFromOrder(_x31, _x32) {
5350
+ function removeProductsFromOrder(_x33, _x34) {
4975
5351
  return _removeProductsFromOrder.apply(this, arguments);
4976
5352
  }
4977
5353
  return removeProductsFromOrder;
@@ -4979,61 +5355,63 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4979
5355
  }, {
4980
5356
  key: "removeProductFromOrder",
4981
5357
  value: function () {
4982
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(identity, options) {
4983
- return _regeneratorRuntime().wrap(function _callee26$(_context29) {
4984
- while (1) switch (_context29.prev = _context29.next) {
5358
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(identity, options) {
5359
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5360
+ while (1) switch (_context32.prev = _context32.next) {
4985
5361
  case 0:
4986
- return _context29.abrupt("return", this.removeProductsFromOrder([identity], options));
5362
+ return _context32.abrupt("return", this.removeProductsFromOrder([identity], options));
4987
5363
  case 1:
4988
5364
  case "end":
4989
- return _context29.stop();
5365
+ return _context32.stop();
4990
5366
  }
4991
- }, _callee26, this);
5367
+ }, _callee29, this);
4992
5368
  }));
4993
- function removeProductFromOrder(_x33, _x34) {
5369
+ function removeProductFromOrder(_x35, _x36) {
4994
5370
  return _removeProductFromOrder.apply(this, arguments);
4995
5371
  }
4996
5372
  return removeProductFromOrder;
4997
5373
  }()
4998
5374
  /**
4999
5375
  * 仅清空购物车行(products / bookings),不重置整单。
5000
- * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
5376
+ * 普通整单 note 保持不变;以商品行为主体的 Sales Notes 同步删除。
5001
5377
  */
5002
5378
  }, {
5003
5379
  key: "clearOrderCartLines",
5004
5380
  value: (function () {
5005
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
5381
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
5006
5382
  var tempOrder;
5007
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
5008
- while (1) switch (_context30.prev = _context30.next) {
5383
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5384
+ while (1) switch (_context33.prev = _context33.next) {
5009
5385
  case 0:
5010
5386
  tempOrder = this.ensureTempOrder();
5387
+ this.ensureSalesNotesLoadedForMutation(tempOrder);
5011
5388
  tempOrder.products = [];
5012
5389
  tempOrder.bookings = [];
5390
+ this.removeSalesNotesForMissingProductLines(tempOrder);
5013
5391
  this.syncTempOrderHolderFromBookings(tempOrder);
5014
5392
  if (tempOrder._extend && _typeof(tempOrder._extend) === 'object') {
5015
5393
  tempOrder._extend = _objectSpread(_objectSpread({}, tempOrder._extend), {}, {
5016
5394
  productsByUid: {}
5017
5395
  });
5018
5396
  }
5019
- _context30.next = 7;
5397
+ _context33.next = 9;
5020
5398
  return this.applyPromotion();
5021
- case 7:
5399
+ case 9:
5022
5400
  this.applyDiscount();
5023
5401
  this.sanitizeTempOrderProducts(tempOrder);
5024
- _context30.next = 11;
5402
+ _context33.next = 13;
5025
5403
  return this.recalculateSummary({
5026
5404
  createIfMissing: true
5027
5405
  });
5028
- case 11:
5406
+ case 13:
5029
5407
  this.persistTempOrder();
5030
5408
  this.logInfo('clearOrderCartLines success', {});
5031
- return _context30.abrupt("return", tempOrder);
5032
- case 14:
5409
+ return _context33.abrupt("return", tempOrder);
5410
+ case 16:
5033
5411
  case "end":
5034
- return _context30.stop();
5412
+ return _context33.stop();
5035
5413
  }
5036
- }, _callee27, this);
5414
+ }, _callee30, this);
5037
5415
  }));
5038
5416
  function clearOrderCartLines() {
5039
5417
  return _clearOrderCartLines.apply(this, arguments);
@@ -5056,10 +5434,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5056
5434
  type: params === null || params === void 0 ? void 0 : params.type,
5057
5435
  summary: this.store.summary || createEmptySummary(),
5058
5436
  enhance: function enhance(nextPayload) {
5059
- var _ref70, _tempOrder$order_numb, _ref71, _tempOrder$shop_order, _ref72, _tempOrder$shop_full_;
5437
+ var _ref70, _tempOrder$order_numb, _ref71, _tempOrder$shop_order2, _ref72, _tempOrder$shop_full_;
5060
5438
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
5061
5439
  order_number: (_ref70 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref70 !== void 0 ? _ref70 : null,
5062
- shop_order_number: (_ref71 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref71 !== void 0 ? _ref71 : null,
5440
+ shop_order_number: (_ref71 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref71 !== void 0 ? _ref71 : null,
5063
5441
  shop_full_order_number: (_ref72 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref72 !== void 0 ? _ref72 : null,
5064
5442
  small_ticket_data_flag: 1
5065
5443
  });
@@ -5071,17 +5449,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5071
5449
  }, {
5072
5450
  key: "applyLocalPrintOrderNumbers",
5073
5451
  value: function () {
5074
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(order) {
5452
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(order) {
5075
5453
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
5076
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
5077
- while (1) switch (_context31.prev = _context31.next) {
5454
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
5455
+ while (1) switch (_context34.prev = _context34.next) {
5078
5456
  case 0:
5079
5457
  tempOrder = this.ensureTempOrder();
5080
5458
  if (!(!order || _typeof(order) !== 'object')) {
5081
- _context31.next = 3;
5459
+ _context34.next = 3;
5082
5460
  break;
5083
5461
  }
5084
- return _context31.abrupt("return", tempOrder);
5462
+ return _context34.abrupt("return", tempOrder);
5085
5463
  case 3:
5086
5464
  shopOrderNumber = order.shop_order_number;
5087
5465
  shopFullOrderNumber = order.shop_full_order_number;
@@ -5092,17 +5470,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5092
5470
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
5093
5471
  }
5094
5472
  this.persistTempOrder();
5095
- _context31.next = 10;
5473
+ _context34.next = 10;
5096
5474
  return this.saveDraft();
5097
5475
  case 10:
5098
- return _context31.abrupt("return", tempOrder);
5476
+ return _context34.abrupt("return", tempOrder);
5099
5477
  case 11:
5100
5478
  case "end":
5101
- return _context31.stop();
5479
+ return _context34.stop();
5102
5480
  }
5103
- }, _callee28, this);
5481
+ }, _callee31, this);
5104
5482
  }));
5105
- function applyLocalPrintOrderNumbers(_x35) {
5483
+ function applyLocalPrintOrderNumbers(_x37) {
5106
5484
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
5107
5485
  }
5108
5486
  return applyLocalPrintOrderNumbers;
@@ -5110,35 +5488,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5110
5488
  }, {
5111
5489
  key: "saveTempOrderAsDraft",
5112
5490
  value: function () {
5113
- var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
5491
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5114
5492
  var _params$cacheId2, _this$otherParams6, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
5115
5493
  var tempOrder, latestSummary, payload;
5116
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5117
- while (1) switch (_context32.prev = _context32.next) {
5494
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5495
+ while (1) switch (_context35.prev = _context35.next) {
5118
5496
  case 0:
5119
5497
  tempOrder = this.ensureTempOrder();
5120
5498
  this.ensureExternalSaleNumber(tempOrder);
5121
5499
  this.persistTempOrder();
5122
- _context32.next = 5;
5500
+ _context35.next = 5;
5123
5501
  return this.recalculateSummary({
5124
5502
  createIfMissing: true
5125
5503
  });
5126
5504
  case 5:
5127
- _context32.t1 = _context32.sent;
5128
- if (_context32.t1) {
5129
- _context32.next = 8;
5505
+ _context35.t1 = _context35.sent;
5506
+ if (_context35.t1) {
5507
+ _context35.next = 8;
5130
5508
  break;
5131
5509
  }
5132
- _context32.t1 = this.store.summary;
5510
+ _context35.t1 = this.store.summary;
5133
5511
  case 8:
5134
- _context32.t0 = _context32.t1;
5135
- if (_context32.t0) {
5136
- _context32.next = 11;
5512
+ _context35.t0 = _context35.t1;
5513
+ if (_context35.t0) {
5514
+ _context35.next = 11;
5137
5515
  break;
5138
5516
  }
5139
- _context32.t0 = createEmptySummary();
5517
+ _context35.t0 = createEmptySummary();
5140
5518
  case 11:
5141
- latestSummary = _context32.t0;
5519
+ latestSummary = _context35.t0;
5142
5520
  payload = buildSubmitPayload({
5143
5521
  tempOrder: tempOrder,
5144
5522
  cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
@@ -5159,17 +5537,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5159
5537
  externalSaleNumber: payload.external_sale_number,
5160
5538
  productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
5161
5539
  });
5162
- return _context32.abrupt("return", this.request.post('/order/sales/draft', payload, {
5540
+ return _context35.abrupt("return", this.request.post('/order/sales/draft', payload, {
5163
5541
  osServer: true,
5164
5542
  customToast: function customToast() {}
5165
5543
  }));
5166
5544
  case 18:
5167
5545
  case "end":
5168
- return _context32.stop();
5546
+ return _context35.stop();
5169
5547
  }
5170
- }, _callee29, this);
5548
+ }, _callee32, this);
5171
5549
  }));
5172
- function saveTempOrderAsDraft(_x36) {
5550
+ function saveTempOrderAsDraft(_x38) {
5173
5551
  return _saveTempOrderAsDraft.apply(this, arguments);
5174
5552
  }
5175
5553
  return saveTempOrderAsDraft;
@@ -5183,18 +5561,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5183
5561
  }, {
5184
5562
  key: "submitTempOrder",
5185
5563
  value: (function () {
5186
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
5187
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5188
- while (1) switch (_context33.prev = _context33.next) {
5564
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5565
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5566
+ while (1) switch (_context36.prev = _context36.next) {
5189
5567
  case 0:
5190
- return _context33.abrupt("return", this.runSubmitTempOrder(params));
5568
+ return _context36.abrupt("return", this.runSubmitTempOrder(params));
5191
5569
  case 1:
5192
5570
  case "end":
5193
- return _context33.stop();
5571
+ return _context36.stop();
5194
5572
  }
5195
- }, _callee30, this);
5573
+ }, _callee33, this);
5196
5574
  }));
5197
- function submitTempOrder(_x37) {
5575
+ function submitTempOrder(_x39) {
5198
5576
  return _submitTempOrder.apply(this, arguments);
5199
5577
  }
5200
5578
  return submitTempOrder;
@@ -5202,20 +5580,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5202
5580
  }, {
5203
5581
  key: "submitTempOrderAsync",
5204
5582
  value: function () {
5205
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
5206
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
5207
- while (1) switch (_context34.prev = _context34.next) {
5583
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5584
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5585
+ while (1) switch (_context37.prev = _context37.next) {
5208
5586
  case 0:
5209
- return _context34.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5587
+ return _context37.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5210
5588
  syncMode: true
5211
5589
  })));
5212
5590
  case 1:
5213
5591
  case "end":
5214
- return _context34.stop();
5592
+ return _context37.stop();
5215
5593
  }
5216
- }, _callee31, this);
5594
+ }, _callee34, this);
5217
5595
  }));
5218
- function submitTempOrderAsync(_x38) {
5596
+ function submitTempOrderAsync(_x40) {
5219
5597
  return _submitTempOrderAsync.apply(this, arguments);
5220
5598
  }
5221
5599
  return submitTempOrderAsync;
@@ -5223,11 +5601,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5223
5601
  }, {
5224
5602
  key: "runSubmitTempOrder",
5225
5603
  value: function () {
5226
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5604
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5227
5605
  var _params$cacheId3, _this$otherParams10, _ref73, _ref74, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
5228
- var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
5229
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5230
- while (1) switch (_context35.prev = _context35.next) {
5606
+ var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, isLocalPendingSubmit, salesNotesState, submittedOrderId, resultRecord;
5607
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5608
+ while (1) switch (_context38.prev = _context38.next) {
5231
5609
  case 0:
5232
5610
  tempOrder = this.ensureTempOrder();
5233
5611
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
@@ -5247,26 +5625,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5247
5625
  }
5248
5626
  }
5249
5627
  this.persistTempOrder();
5250
- _context35.next = 8;
5628
+ _context38.next = 8;
5251
5629
  return this.recalculateSummary({
5252
5630
  createIfMissing: true
5253
5631
  });
5254
5632
  case 8:
5255
- _context35.t1 = _context35.sent;
5256
- if (_context35.t1) {
5257
- _context35.next = 11;
5633
+ _context38.t1 = _context38.sent;
5634
+ if (_context38.t1) {
5635
+ _context38.next = 11;
5258
5636
  break;
5259
5637
  }
5260
- _context35.t1 = this.store.summary;
5638
+ _context38.t1 = this.store.summary;
5261
5639
  case 11:
5262
- _context35.t0 = _context35.t1;
5263
- if (_context35.t0) {
5264
- _context35.next = 14;
5640
+ _context38.t0 = _context38.t1;
5641
+ if (_context38.t0) {
5642
+ _context38.next = 14;
5265
5643
  break;
5266
5644
  }
5267
- _context35.t0 = createEmptySummary();
5645
+ _context38.t0 = createEmptySummary();
5268
5646
  case 14:
5269
- latestSummary = _context35.t0;
5647
+ latestSummary = _context38.t0;
5270
5648
  effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
5271
5649
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
5272
5650
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
@@ -5300,10 +5678,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5300
5678
  if (!payload.created_at) {
5301
5679
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
5302
5680
  }
5303
- _context35.next = 25;
5681
+ _context38.next = 25;
5304
5682
  return this.saveDraft();
5305
5683
  case 25:
5306
- _context35.prev = 25;
5684
+ _context38.prev = 25;
5307
5685
  this.logInfo('submitTempOrder calling sales checkout', {
5308
5686
  orderId: payload.order_id,
5309
5687
  externalSaleNumber: payload.external_sale_number,
@@ -5313,44 +5691,49 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5313
5691
  smallTicketDataFlag: payload.small_ticket_data_flag,
5314
5692
  syncMode: payload.sync_mode
5315
5693
  });
5316
- _context35.next = 29;
5694
+ _context38.next = 29;
5317
5695
  return this.submitSalesOrder({
5318
5696
  query: payload
5319
5697
  });
5320
5698
  case 29:
5321
- result = _context35.sent;
5322
- _context35.next = 42;
5699
+ result = _context38.sent;
5700
+ _context38.next = 42;
5323
5701
  break;
5324
5702
  case 32:
5325
- _context35.prev = 32;
5326
- _context35.t2 = _context35["catch"](25);
5327
- backendErrorResponse = this.extractSubmitErrorResponse(_context35.t2);
5703
+ _context38.prev = 32;
5704
+ _context38.t2 = _context38["catch"](25);
5705
+ backendErrorResponse = this.extractSubmitErrorResponse(_context38.t2);
5328
5706
  if (!backendErrorResponse) {
5329
- _context35.next = 39;
5707
+ _context38.next = 39;
5330
5708
  break;
5331
5709
  }
5332
5710
  this.store.syncState = 'failed';
5333
5711
  this.logSubmitBackendRejected(backendErrorResponse, payload);
5334
- return _context35.abrupt("return", backendErrorResponse);
5712
+ return _context38.abrupt("return", backendErrorResponse);
5335
5713
  case 39:
5336
5714
  this.store.syncState = 'failed';
5337
5715
  this.logError('submitTempOrder failed', {
5338
- error: _context35.t2 instanceof Error ? _context35.t2.message : String(_context35.t2),
5716
+ error: _context38.t2 instanceof Error ? _context38.t2.message : String(_context38.t2),
5339
5717
  orderId: payload.order_id,
5340
5718
  externalSaleNumber: payload.external_sale_number,
5341
5719
  paymentStatus: payload.payment_status,
5342
5720
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
5343
5721
  });
5344
- throw _context35.t2;
5722
+ throw _context38.t2;
5345
5723
  case 42:
5346
5724
  if (!this.isSubmitResponseRejected(result)) {
5347
- _context35.next = 46;
5725
+ _context38.next = 46;
5348
5726
  break;
5349
5727
  }
5350
5728
  this.store.syncState = 'failed';
5351
5729
  this.logSubmitBackendRejected(result, payload);
5352
- return _context35.abrupt("return", result);
5730
+ return _context38.abrupt("return", result);
5353
5731
  case 46:
5732
+ isLocalPendingSubmit = this.isLocalPendingSubmitResult(result); // need_sync=1 仅表示已进入本地同步队列,不能视为远端已确认 Notes。
5733
+ if (Object.prototype.hasOwnProperty.call(payload, 'notes') && !isLocalPendingSubmit) {
5734
+ salesNotesState = this.ensureSalesNotesRuntimeState(tempOrder);
5735
+ salesNotesState.dirty = false;
5736
+ }
5354
5737
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
5355
5738
  this.logInfo('runSubmitTempOrder: 提交成功', {
5356
5739
  submittedOrderId: submittedOrderId,
@@ -5360,31 +5743,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5360
5743
  })
5361
5744
  });
5362
5745
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
5363
- _context35.next = 55;
5746
+ _context38.next = 55;
5364
5747
  break;
5365
5748
  }
5366
5749
  tempOrder.order_id = submittedOrderId;
5367
5750
  resultRecord = result;
5368
- _context35.next = 53;
5751
+ _context38.next = 55;
5369
5752
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
5370
- case 53:
5371
- _context35.next = 56;
5372
- break;
5373
5753
  case 55:
5374
- if (this.isLocalPendingSubmitResult(result)) {
5754
+ if (isLocalPendingSubmit) {
5375
5755
  this.store.syncState = 'local';
5376
- } else {
5756
+ } else if (submittedOrderId === null || submittedOrderId === undefined) {
5377
5757
  this.store.syncState = 'submitted';
5378
5758
  }
5379
- case 56:
5380
- return _context35.abrupt("return", result);
5759
+ return _context38.abrupt("return", result);
5381
5760
  case 57:
5382
5761
  case "end":
5383
- return _context35.stop();
5762
+ return _context38.stop();
5384
5763
  }
5385
- }, _callee32, this, [[25, 32]]);
5764
+ }, _callee35, this, [[25, 32]]);
5386
5765
  }));
5387
- function runSubmitTempOrder(_x39) {
5766
+ function runSubmitTempOrder(_x41) {
5388
5767
  return _runSubmitTempOrder.apply(this, arguments);
5389
5768
  }
5390
5769
  return runSubmitTempOrder;
@@ -5392,10 +5771,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5392
5771
  }, {
5393
5772
  key: "markLocalOrderSynced",
5394
5773
  value: function () {
5395
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(orderId, remoteOrder) {
5774
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(orderId, remoteOrder) {
5396
5775
  var tempOrder;
5397
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5398
- while (1) switch (_context36.prev = _context36.next) {
5776
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5777
+ while (1) switch (_context39.prev = _context39.next) {
5399
5778
  case 0:
5400
5779
  tempOrder = this.ensureTempOrder();
5401
5780
  tempOrder.order_id = orderId;
@@ -5403,15 +5782,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5403
5782
  this.store.lastOrderInfo = remoteOrder;
5404
5783
  this.store.syncState = 'submitted';
5405
5784
  this.persistTempOrder();
5406
- _context36.next = 8;
5785
+ _context39.next = 8;
5407
5786
  return this.saveDraft();
5408
5787
  case 8:
5409
5788
  case "end":
5410
- return _context36.stop();
5789
+ return _context39.stop();
5411
5790
  }
5412
- }, _callee33, this);
5791
+ }, _callee36, this);
5413
5792
  }));
5414
- function markLocalOrderSynced(_x40, _x41) {
5793
+ function markLocalOrderSynced(_x42, _x43) {
5415
5794
  return _markLocalOrderSynced.apply(this, arguments);
5416
5795
  }
5417
5796
  return markLocalOrderSynced;
@@ -5454,10 +5833,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5454
5833
  value: function extractSubmitErrorResponse(error) {
5455
5834
  var _error$response,
5456
5835
  _error$response2,
5457
- _this31 = this;
5836
+ _this34 = this;
5458
5837
  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];
5459
5838
  return candidates.find(function (candidate) {
5460
- return _this31.isSubmitErrorResponse(candidate);
5839
+ return _this34.isSubmitErrorResponse(candidate);
5461
5840
  }) || null;
5462
5841
  }
5463
5842
  }, {
@@ -5484,33 +5863,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5484
5863
  }, {
5485
5864
  key: "syncPaymentsToOrder",
5486
5865
  value: function () {
5487
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5488
- var _this32 = this,
5866
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5867
+ var _this35 = this,
5489
5868
  _params$confirmPendin;
5490
5869
  var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, enhancePayload, submitParams, submitResult;
5491
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5492
- while (1) switch (_context37.prev = _context37.next) {
5870
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5871
+ while (1) switch (_context40.prev = _context40.next) {
5493
5872
  case 0:
5494
5873
  tempOrder = this.ensureTempOrder();
5495
5874
  needsPaymentNumber = (params.payments || []).some(function (payment) {
5496
5875
  return String(payment.payment_number || '').trim() === '';
5497
5876
  });
5498
5877
  if (!needsPaymentNumber) {
5499
- _context37.next = 8;
5878
+ _context40.next = 8;
5500
5879
  break;
5501
5880
  }
5502
- _context37.next = 5;
5881
+ _context40.next = 5;
5503
5882
  return this.getPaymentNumberDevicePrefixAsync();
5504
5883
  case 5:
5505
- _context37.t0 = _context37.sent;
5506
- _context37.next = 9;
5884
+ _context40.t0 = _context40.sent;
5885
+ _context40.next = 9;
5507
5886
  break;
5508
5887
  case 8:
5509
- _context37.t0 = 'LOCAL';
5888
+ _context40.t0 = 'LOCAL';
5510
5889
  case 9:
5511
- devicePrefix = _context37.t0;
5890
+ devicePrefix = _context40.t0;
5512
5891
  mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5513
- return _this32.normalizePaymentSource(payment, {
5892
+ return _this35.normalizePaymentSource(payment, {
5514
5893
  defaultPaid: false,
5515
5894
  devicePrefix: devicePrefix
5516
5895
  });
@@ -5523,20 +5902,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5523
5902
  tempOrder.payments = effectivePayments;
5524
5903
  tempOrder.payment_status = paymentStatus;
5525
5904
  this.persistTempOrder();
5526
- _context37.next = 21;
5905
+ _context40.next = 21;
5527
5906
  return this.saveDraft();
5528
5907
  case 21:
5529
5908
  if (params.submitWhenPaid) {
5530
- _context37.next = 23;
5909
+ _context40.next = 23;
5531
5910
  break;
5532
5911
  }
5533
- return _context37.abrupt("return", completion);
5912
+ return _context40.abrupt("return", completion);
5534
5913
  case 23:
5535
5914
  if (!(this.store.syncState === 'submitting')) {
5536
- _context37.next = 25;
5915
+ _context40.next = 25;
5537
5916
  break;
5538
5917
  }
5539
- return _context37.abrupt("return", completion);
5918
+ return _context40.abrupt("return", completion);
5540
5919
  case 25:
5541
5920
  this.store.syncState = 'submitting';
5542
5921
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
@@ -5556,32 +5935,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5556
5935
  enhancePayload: enhancePayload
5557
5936
  };
5558
5937
  if (!(params.checkoutSyncTaskEnabled === false)) {
5559
- _context37.next = 35;
5938
+ _context40.next = 35;
5560
5939
  break;
5561
5940
  }
5562
- _context37.next = 32;
5941
+ _context40.next = 32;
5563
5942
  return this.submitTempOrderAsync(submitParams);
5564
5943
  case 32:
5565
- _context37.t1 = _context37.sent;
5566
- _context37.next = 38;
5944
+ _context40.t1 = _context40.sent;
5945
+ _context40.next = 38;
5567
5946
  break;
5568
5947
  case 35:
5569
- _context37.next = 37;
5948
+ _context40.next = 37;
5570
5949
  return this.submitTempOrder(submitParams);
5571
5950
  case 37:
5572
- _context37.t1 = _context37.sent;
5951
+ _context40.t1 = _context40.sent;
5573
5952
  case 38:
5574
- submitResult = _context37.t1;
5575
- return _context37.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5953
+ submitResult = _context40.t1;
5954
+ return _context40.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5576
5955
  submitResult: submitResult
5577
5956
  }));
5578
5957
  case 40:
5579
5958
  case "end":
5580
- return _context37.stop();
5959
+ return _context40.stop();
5581
5960
  }
5582
- }, _callee34, this);
5961
+ }, _callee37, this);
5583
5962
  }));
5584
- function syncPaymentsToOrder(_x42) {
5963
+ function syncPaymentsToOrder(_x44) {
5585
5964
  return _syncPaymentsToOrder.apply(this, arguments);
5586
5965
  }
5587
5966
  return syncPaymentsToOrder;
@@ -5589,7 +5968,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5589
5968
  }, {
5590
5969
  key: "createOrder",
5591
5970
  value: function createOrder(params) {
5592
- var _this33 = this;
5971
+ var _this36 = this;
5593
5972
  var order = _objectSpread({
5594
5973
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
5595
5974
  // 要从外面拿,virtual
@@ -5621,7 +6000,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5621
6000
 
5622
6001
  // 为预约补齐 holder 信息
5623
6002
  if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
5624
- ensureCartItemOriginHolder(item, _this33.window);
6003
+ ensureCartItemOriginHolder(item, _this36.window);
5625
6004
  }
5626
6005
 
5627
6006
  // 购物车是否为普通商品
@@ -5678,11 +6057,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5678
6057
  }, {
5679
6058
  key: "submitOrder",
5680
6059
  value: function () {
5681
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(order) {
6060
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(order) {
5682
6061
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5683
6062
  var url, query, fetchUrl, params;
5684
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5685
- while (1) switch (_context38.prev = _context38.next) {
6063
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
6064
+ while (1) switch (_context41.prev = _context41.next) {
5686
6065
  case 0:
5687
6066
  this.logInfo('submitOrder called', {
5688
6067
  url: order.url,
@@ -5702,14 +6081,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5702
6081
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5703
6082
  scheduleDate: params.schedule_date
5704
6083
  });
5705
- return _context38.abrupt("return", this.request.post(fetchUrl, params));
6084
+ return _context41.abrupt("return", this.request.post(fetchUrl, params));
5706
6085
  case 6:
5707
6086
  case "end":
5708
- return _context38.stop();
6087
+ return _context41.stop();
5709
6088
  }
5710
- }, _callee35, this);
6089
+ }, _callee38, this);
5711
6090
  }));
5712
- function submitOrder(_x43) {
6091
+ function submitOrder(_x45) {
5713
6092
  return _submitOrder.apply(this, arguments);
5714
6093
  }
5715
6094
  return submitOrder;
@@ -5717,13 +6096,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5717
6096
  }, {
5718
6097
  key: "cancelOrder",
5719
6098
  value: function () {
5720
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
6099
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5721
6100
  var payload;
5722
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5723
- while (1) switch (_context39.prev = _context39.next) {
6101
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
6102
+ while (1) switch (_context42.prev = _context42.next) {
5724
6103
  case 0:
5725
6104
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5726
- _context39.next = 2;
6105
+ _context42.next = 2;
5727
6106
  break;
5728
6107
  }
5729
6108
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5739,16 +6118,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5739
6118
  method: 'PUT',
5740
6119
  orderIdsCount: params.order_ids.length
5741
6120
  });
5742
- return _context39.abrupt("return", this.request.put('/order/update-status', payload, {
6121
+ return _context42.abrupt("return", this.request.put('/order/update-status', payload, {
5743
6122
  isShopApi: true
5744
6123
  }));
5745
6124
  case 5:
5746
6125
  case "end":
5747
- return _context39.stop();
6126
+ return _context42.stop();
5748
6127
  }
5749
- }, _callee36, this);
6128
+ }, _callee39, this);
5750
6129
  }));
5751
- function cancelOrder(_x44) {
6130
+ function cancelOrder(_x46) {
5752
6131
  return _cancelOrder.apply(this, arguments);
5753
6132
  }
5754
6133
  return cancelOrder;
@@ -5756,19 +6135,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5756
6135
  }, {
5757
6136
  key: "changeBookingStatus",
5758
6137
  value: function () {
5759
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
6138
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5760
6139
  var url, payload;
5761
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5762
- while (1) switch (_context40.prev = _context40.next) {
6140
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
6141
+ while (1) switch (_context43.prev = _context43.next) {
5763
6142
  case 0:
5764
6143
  if (params.booking_id) {
5765
- _context40.next = 2;
6144
+ _context43.next = 2;
5766
6145
  break;
5767
6146
  }
5768
6147
  throw new Error('变更预约状态失败:booking_id 不能为空');
5769
6148
  case 2:
5770
6149
  if (params.appointment_status) {
5771
- _context40.next = 4;
6150
+ _context43.next = 4;
5772
6151
  break;
5773
6152
  }
5774
6153
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5783,16 +6162,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5783
6162
  bookingId: params.booking_id,
5784
6163
  appointmentStatus: params.appointment_status
5785
6164
  });
5786
- return _context40.abrupt("return", this.request.put(url, payload, {
6165
+ return _context43.abrupt("return", this.request.put(url, payload, {
5787
6166
  isShopApi: true
5788
6167
  }));
5789
6168
  case 8:
5790
6169
  case "end":
5791
- return _context40.stop();
6170
+ return _context43.stop();
5792
6171
  }
5793
- }, _callee37, this);
6172
+ }, _callee40, this);
5794
6173
  }));
5795
- function changeBookingStatus(_x45) {
6174
+ function changeBookingStatus(_x47) {
5796
6175
  return _changeBookingStatus.apply(this, arguments);
5797
6176
  }
5798
6177
  return changeBookingStatus;
@@ -5810,11 +6189,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5810
6189
  }, {
5811
6190
  key: "createOrderByCheckout",
5812
6191
  value: (function () {
5813
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
6192
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5814
6193
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3;
5815
6194
  var onlineStorePaymentCodeList, _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, orderData, response;
5816
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5817
- while (1) switch (_context41.prev = _context41.next) {
6195
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6196
+ while (1) switch (_context44.prev = _context44.next) {
5818
6197
  case 0:
5819
6198
  // 过滤掉由在线店铺下单的 payment 支付数据
5820
6199
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5839,7 +6218,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5839
6218
  return p.code;
5840
6219
  })) || []
5841
6220
  });
5842
- _context41.prev = 3;
6221
+ _context44.prev = 3;
5843
6222
  // 构建订单数据,设置默认值并允许 params 覆盖
5844
6223
  orderData = _objectSpread({
5845
6224
  sales_channel: 'my_pisel',
@@ -5887,32 +6266,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5887
6266
  hasOrderId: !!orderData.order_id,
5888
6267
  smallTicketDataFlag: orderData.small_ticket_data_flag
5889
6268
  });
5890
- _context41.next = 10;
6269
+ _context44.next = 10;
5891
6270
  return this.request.post('/order/checkout', orderData, {
5892
6271
  osServer: true,
5893
6272
  customToast: function customToast() {}
5894
6273
  });
5895
6274
  case 10:
5896
- response = _context41.sent;
6275
+ response = _context44.sent;
5897
6276
  this.logInfo('Order API called successfully', {
5898
6277
  response: response
5899
6278
  });
5900
- return _context41.abrupt("return", response);
6279
+ return _context44.abrupt("return", response);
5901
6280
  case 15:
5902
- _context41.prev = 15;
5903
- _context41.t0 = _context41["catch"](3);
5904
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context41.t0);
6281
+ _context44.prev = 15;
6282
+ _context44.t0 = _context44["catch"](3);
6283
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context44.t0);
5905
6284
  this.logInfo('Order API called failed', {
5906
- error: _context41.t0 instanceof Error ? _context41.t0.message : String(_context41.t0)
6285
+ error: _context44.t0 instanceof Error ? _context44.t0.message : String(_context44.t0)
5907
6286
  });
5908
- throw _context41.t0;
6287
+ throw _context44.t0;
5909
6288
  case 20:
5910
6289
  case "end":
5911
- return _context41.stop();
6290
+ return _context44.stop();
5912
6291
  }
5913
- }, _callee38, this, [[3, 15]]);
6292
+ }, _callee41, this, [[3, 15]]);
5914
6293
  }));
5915
- function createOrderByCheckout(_x46) {
6294
+ function createOrderByCheckout(_x48) {
5916
6295
  return _createOrderByCheckout.apply(this, arguments);
5917
6296
  }
5918
6297
  return createOrderByCheckout;
@@ -5920,24 +6299,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5920
6299
  }, {
5921
6300
  key: "submitSalesOrder",
5922
6301
  value: function () {
5923
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
6302
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5924
6303
  var url, query, fetchUrl;
5925
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5926
- while (1) switch (_context42.prev = _context42.next) {
6304
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
6305
+ while (1) switch (_context45.prev = _context45.next) {
5927
6306
  case 0:
5928
6307
  url = params.url, query = params.query;
5929
6308
  fetchUrl = url || '/order/sales/checkout';
5930
- return _context42.abrupt("return", this.request.post(fetchUrl, query, {
6309
+ return _context45.abrupt("return", this.request.post(fetchUrl, query, {
5931
6310
  osServer: true,
5932
6311
  customToast: function customToast() {}
5933
6312
  }));
5934
6313
  case 3:
5935
6314
  case "end":
5936
- return _context42.stop();
6315
+ return _context45.stop();
5937
6316
  }
5938
- }, _callee39, this);
6317
+ }, _callee42, this);
5939
6318
  }));
5940
- function submitSalesOrder(_x47) {
6319
+ function submitSalesOrder(_x49) {
5941
6320
  return _submitSalesOrder.apply(this, arguments);
5942
6321
  }
5943
6322
  return submitSalesOrder;
@@ -5951,37 +6330,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5951
6330
  }, {
5952
6331
  key: "sendCustomerPayLink",
5953
6332
  value: (function () {
5954
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
6333
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
5955
6334
  var _params$emails;
5956
6335
  var orderIds;
5957
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5958
- while (1) switch (_context43.prev = _context43.next) {
6336
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
6337
+ while (1) switch (_context46.prev = _context46.next) {
5959
6338
  case 0:
5960
6339
  orderIds = params.order_ids || params.orderIds || [];
5961
6340
  if (orderIds.length) {
5962
- _context43.next = 3;
6341
+ _context46.next = 3;
5963
6342
  break;
5964
6343
  }
5965
6344
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5966
6345
  case 3:
5967
6346
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5968
- _context43.next = 5;
6347
+ _context46.next = 5;
5969
6348
  break;
5970
6349
  }
5971
6350
  throw new Error('发送支付链接需要至少一个邮箱');
5972
6351
  case 5:
5973
- return _context43.abrupt("return", this.request.post('/order/batch-email', {
6352
+ return _context46.abrupt("return", this.request.post('/order/batch-email', {
5974
6353
  order_ids: orderIds,
5975
6354
  notify_action: params.notify_action || 'order_payment_reminder',
5976
6355
  emails: params.emails
5977
6356
  }));
5978
6357
  case 6:
5979
6358
  case "end":
5980
- return _context43.stop();
6359
+ return _context46.stop();
5981
6360
  }
5982
- }, _callee40, this);
6361
+ }, _callee43, this);
5983
6362
  }));
5984
- function sendCustomerPayLink(_x48) {
6363
+ function sendCustomerPayLink(_x50) {
5985
6364
  return _sendCustomerPayLink.apply(this, arguments);
5986
6365
  }
5987
6366
  return sendCustomerPayLink;
@@ -5989,14 +6368,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5989
6368
  }, {
5990
6369
  key: "getSalesOrderByLookup",
5991
6370
  value: function () {
5992
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
6371
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
5993
6372
  var lookup, res;
5994
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5995
- while (1) switch (_context44.prev = _context44.next) {
6373
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
6374
+ while (1) switch (_context47.prev = _context47.next) {
5996
6375
  case 0:
5997
6376
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5998
6377
  if (lookup) {
5999
- _context44.next = 3;
6378
+ _context47.next = 3;
6000
6379
  break;
6001
6380
  }
6002
6381
  throw new Error('加载销售详情需要 lookup');
@@ -6005,27 +6384,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6005
6384
  if (lookup.startsWith('LOCAL_')) {
6006
6385
  params.forceRemote = false;
6007
6386
  }
6008
- _context44.next = 6;
6387
+ _context47.next = 6;
6009
6388
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
6010
- with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds']
6389
+ with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds', 'notes']
6011
6390
  }, params.forceRemote ? {
6012
6391
  forceRemote: true
6013
6392
  } : {}), {
6014
6393
  osServer: true
6015
6394
  });
6016
6395
  case 6:
6017
- res = _context44.sent;
6396
+ res = _context47.sent;
6018
6397
  if (res.code === 200) {
6019
6398
  this.store.lastOrderInfo = res.data;
6020
6399
  }
6021
- return _context44.abrupt("return", res);
6400
+ return _context47.abrupt("return", res);
6022
6401
  case 9:
6023
6402
  case "end":
6024
- return _context44.stop();
6403
+ return _context47.stop();
6025
6404
  }
6026
- }, _callee41, this);
6405
+ }, _callee44, this);
6027
6406
  }));
6028
- function getSalesOrderByLookup(_x49) {
6407
+ function getSalesOrderByLookup(_x51) {
6029
6408
  return _getSalesOrderByLookup.apply(this, arguments);
6030
6409
  }
6031
6410
  return getSalesOrderByLookup;
@@ -6039,11 +6418,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6039
6418
  }, {
6040
6419
  key: "hydrateTempOrderFromRecord",
6041
6420
  value: (function () {
6042
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(record, options) {
6421
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(record, options) {
6043
6422
  var _sourceRaw$_extend, _this$store$discount22;
6044
6423
  var sourceRaw, duplicateProductIdentityRepair, duplicateIdentityReadySource, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, isSessionStorageHydrate, isMergedSalesDetailHydrate, nextTempOrder, _this$store$discount20, _this$store$discount21, restoredSessionDiscounts, nextExtend, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, historicalDepositSnapshot, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount23, _this$store$discount24;
6045
- return _regeneratorRuntime().wrap(function _callee42$(_context45) {
6046
- while (1) switch (_context45.prev = _context45.next) {
6424
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6425
+ while (1) switch (_context48.prev = _context48.next) {
6047
6426
  case 0:
6048
6427
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
6049
6428
  duplicateProductIdentityRepair = repairDuplicateOrderProductLineIdentities(Array.isArray(sourceRaw.products) ? sourceRaw.products : [], (_sourceRaw$_extend = sourceRaw._extend) === null || _sourceRaw$_extend === void 0 ? void 0 : _sourceRaw$_extend.productsByUid);
@@ -6079,11 +6458,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6079
6458
  isMergedSalesDetailHydrate = (options === null || options === void 0 ? void 0 : options.source) === 'mergedSalesDetail';
6080
6459
  nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
6081
6460
  // merge 前已只给远端商品补标记;这里不能把本地未提交商品一并变成 saved item。
6082
- makeEditMark: !isSessionStorageHydrate && !isMergedSalesDetailHydrate
6461
+ makeEditMark: !isSessionStorageHydrate && !isMergedSalesDetailHydrate,
6462
+ allowUnresolvedSalesNotes: isSessionStorageHydrate
6083
6463
  });
6084
6464
  this.store.tempOrder = nextTempOrder;
6085
6465
  if (!isSessionStorageHydrate) {
6086
- _context45.next = 30;
6466
+ _context48.next = 30;
6087
6467
  break;
6088
6468
  }
6089
6469
  // 会话快照是未提交购物车,不应获得编辑订单的 saved/edit 标记与服务端基线。
@@ -6099,23 +6479,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6099
6479
  nextTempOrder.discount_list = restoredSessionDiscounts;
6100
6480
  this.store.summary = createEmptySummary();
6101
6481
  this.store.lastOrderInfo = undefined;
6102
- _context45.next = 23;
6482
+ _context48.next = 23;
6103
6483
  return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(cloneDeep(restoredSessionDiscounts));
6104
6484
  case 23:
6105
- _context45.next = 25;
6485
+ _context48.next = 25;
6106
6486
  return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(cloneDeep(restoredSessionDiscounts));
6107
6487
  case 25:
6108
6488
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6109
- _context45.next = 28;
6489
+ _context48.next = 28;
6110
6490
  break;
6111
6491
  }
6112
- _context45.next = 28;
6492
+ _context48.next = 28;
6113
6493
  return this.recalculateSummary({
6114
6494
  createIfMissing: false
6115
6495
  });
6116
6496
  case 28:
6117
6497
  this.persistTempOrder();
6118
- return _context45.abrupt("return", nextTempOrder);
6498
+ return _context48.abrupt("return", nextTempOrder);
6119
6499
  case 30:
6120
6500
  // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
6121
6501
  sourceLastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
@@ -6167,34 +6547,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6167
6547
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
6168
6548
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
6169
6549
  if (shouldSkipEmptyDiscountSync) {
6170
- _context45.next = 54;
6550
+ _context48.next = 54;
6171
6551
  break;
6172
6552
  }
6173
6553
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
6174
- _context45.next = 52;
6554
+ _context48.next = 52;
6175
6555
  return (_this$store$discount23 = this.store.discount) === null || _this$store$discount23 === void 0 ? void 0 : _this$store$discount23.setOriginalDiscountList(nextDiscounts);
6176
6556
  case 52:
6177
- _context45.next = 54;
6557
+ _context48.next = 54;
6178
6558
  return (_this$store$discount24 = this.store.discount) === null || _this$store$discount24 === void 0 ? void 0 : _this$store$discount24.setDiscountList(nextDiscounts);
6179
6559
  case 54:
6180
6560
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6181
- _context45.next = 57;
6561
+ _context48.next = 57;
6182
6562
  break;
6183
6563
  }
6184
- _context45.next = 57;
6564
+ _context48.next = 57;
6185
6565
  return this.recalculateSummary({
6186
6566
  createIfMissing: false
6187
6567
  });
6188
6568
  case 57:
6189
6569
  this.persistTempOrder();
6190
- return _context45.abrupt("return", nextTempOrder);
6570
+ return _context48.abrupt("return", nextTempOrder);
6191
6571
  case 59:
6192
6572
  case "end":
6193
- return _context45.stop();
6573
+ return _context48.stop();
6194
6574
  }
6195
- }, _callee42, this);
6575
+ }, _callee45, this);
6196
6576
  }));
6197
- function hydrateTempOrderFromRecord(_x50, _x51) {
6577
+ function hydrateTempOrderFromRecord(_x52, _x53) {
6198
6578
  return _hydrateTempOrderFromRecord.apply(this, arguments);
6199
6579
  }
6200
6580
  return hydrateTempOrderFromRecord;
@@ -6247,10 +6627,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6247
6627
  _step22;
6248
6628
  try {
6249
6629
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
6250
- var _product$metadata8;
6630
+ var _product$metadata10;
6251
6631
  var product = _step22.value;
6252
6632
  var productUid = getOrderCollectionUid('product', product);
6253
- var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.booking_uid);
6633
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.booking_uid);
6254
6634
  if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
6255
6635
  continue;
6256
6636
  }
@@ -6308,7 +6688,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6308
6688
  }, {
6309
6689
  key: "normalizeTempOrderForRuntime",
6310
6690
  value: function normalizeTempOrderForRuntime(raw, options) {
6311
- var _this34 = this;
6691
+ var _this37 = this,
6692
+ _raw$_extend;
6312
6693
  var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6313
6694
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
6314
6695
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
@@ -6332,12 +6713,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6332
6713
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
6333
6714
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
6334
6715
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
6335
- return _this34.normalizeHydratedOrderProduct(p, {
6716
+ return _this37.normalizeHydratedOrderProduct(p, {
6336
6717
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
6337
6718
  });
6338
6719
  }) : [];
6339
6720
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
6340
- var booking = _this34.normalizeHydratedBookingHolder(b || {});
6721
+ var booking = _this37.normalizeHydratedBookingHolder(b || {});
6341
6722
  return _objectSpread(_objectSpread({}, booking), {}, {
6342
6723
  is_all: normalizeBookingIsAll(booking),
6343
6724
  sub_type: normalizeBookingSubType(booking)
@@ -6346,6 +6727,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6346
6727
  nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(function (p) {
6347
6728
  return _objectSpread({}, p || {});
6348
6729
  }) : [];
6730
+ var rawHasSalesNotes = Object.prototype.hasOwnProperty.call(raw, 'notes');
6731
+ var restoredSalesNotesState = (_raw$_extend = raw._extend) === null || _raw$_extend === void 0 ? void 0 : _raw$_extend.salesNotesState;
6732
+ 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;
6733
+ var decodedSalesNotes = rawHasSalesNotes ? decodeSalesNotesSnapshot(raw.notes, {
6734
+ allowUnresolvedOrderTarget: allowUnresolvedSalesNotes
6735
+ }) : {
6736
+ notes: [],
6737
+ complete: false
6738
+ };
6739
+ var hasUnresolvedSalesNoteOrderTarget = decodedSalesNotes.notes.some(function (note) {
6740
+ return note.note_relations.some(function (relation) {
6741
+ return relation.is_primary === 0 && relation.relation_type === 'related_to' && relation.target_type === 'order' && relation.target_uuid === '';
6742
+ });
6743
+ });
6744
+ nextTempOrder.notes = decodedSalesNotes.notes;
6349
6745
  nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(function (s) {
6350
6746
  return _objectSpread({}, s || {});
6351
6747
  }) : [];
@@ -6362,16 +6758,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6362
6758
  productsByUid: {}
6363
6759
  };
6364
6760
  var tempOrderExtend = nextTempOrder._extend;
6761
+ tempOrderExtend.salesNotesState = {
6762
+ loaded: rawHasSalesNotes ? decodedSalesNotes.complete : (restoredSalesNotesState === null || restoredSalesNotesState === void 0 ? void 0 : restoredSalesNotesState.loaded) === true,
6763
+ dirty: decodedSalesNotes.complete && ((restoredSalesNotesState === null || restoredSalesNotesState === void 0 ? void 0 : restoredSalesNotesState.dirty) === true || allowUnresolvedSalesNotes && hasUnresolvedSalesNoteOrderTarget)
6764
+ };
6365
6765
  var productsByUid = tempOrderExtend.productsByUid || {};
6366
6766
  var _iterator24 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
6367
6767
  _step24;
6368
6768
  try {
6369
6769
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
6370
- var _product$metadata9, _ref75, _ref76, _existed$origin, _rawProduct$metadata;
6770
+ var _product$metadata11, _ref75, _ref76, _existed$origin, _rawProduct$metadata;
6371
6771
  var _step24$value = _slicedToArray(_step24.value, 2),
6372
6772
  index = _step24$value[0],
6373
6773
  product = _step24$value[1];
6374
- var uid = (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.unique_identification_number;
6774
+ var uid = (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number;
6375
6775
  if (!uid) continue;
6376
6776
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
6377
6777
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
@@ -6426,8 +6826,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6426
6826
  var bookingUidByProductUid = new Map();
6427
6827
  var productByUid = new Map();
6428
6828
  (tempOrder.products || []).forEach(function (product) {
6429
- var _product$metadata10;
6430
- var productUid = (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6829
+ var _product$metadata12;
6830
+ var productUid = (product === null || product === void 0 || (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6431
6831
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
6432
6832
  productByUid.set(String(productUid), product);
6433
6833
  }
@@ -6448,8 +6848,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6448
6848
  bookingUidByProductUid.set(String(productUid), bookingUid);
6449
6849
  });
6450
6850
  (tempOrder.products || []).forEach(function (product) {
6451
- var _product$metadata11;
6452
- var productUid = (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6851
+ var _product$metadata13;
6852
+ 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);
6453
6853
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
6454
6854
  var bookingUid = bookingUidByProductUid.get(String(productUid));
6455
6855
  if (!bookingUid) return;
@@ -6524,7 +6924,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6524
6924
  }, {
6525
6925
  key: "normalizeHydratedOrderProduct",
6526
6926
  value: function normalizeHydratedOrderProduct(product, options) {
6527
- var _this35 = this;
6927
+ var _this38 = this;
6528
6928
  var row = _objectSpread({}, product || {});
6529
6929
  if (row.num === undefined && row.product_quantity !== undefined) {
6530
6930
  row.num = row.product_quantity;
@@ -6532,7 +6932,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6532
6932
  var productSku = ensureProductSku(row);
6533
6933
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
6534
6934
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
6535
- return _this35.normalizeHydratedProductOptionItem(optionItem || {});
6935
+ return _this38.normalizeHydratedProductOptionItem(optionItem || {});
6536
6936
  }))
6537
6937
  });
6538
6938
  delete row["product_".concat('option', "_item")];
@@ -6572,27 +6972,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6572
6972
  }, {
6573
6973
  key: "getOrderInfo",
6574
6974
  value: function () {
6575
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(order_id) {
6975
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46(order_id) {
6576
6976
  var res;
6577
- return _regeneratorRuntime().wrap(function _callee43$(_context46) {
6578
- while (1) switch (_context46.prev = _context46.next) {
6977
+ return _regeneratorRuntime().wrap(function _callee46$(_context49) {
6978
+ while (1) switch (_context49.prev = _context49.next) {
6579
6979
  case 0:
6580
- _context46.next = 2;
6980
+ _context49.next = 2;
6581
6981
  return this.request.get("/order/sales/".concat(order_id), {
6582
- with: ['products', 'bookings']
6982
+ with: ['products', 'bookings', 'notes']
6583
6983
  }, {
6584
6984
  osServer: true
6585
6985
  });
6586
6986
  case 2:
6587
- res = _context46.sent;
6588
- return _context46.abrupt("return", res);
6987
+ res = _context49.sent;
6988
+ return _context49.abrupt("return", res);
6589
6989
  case 4:
6590
6990
  case "end":
6591
- return _context46.stop();
6991
+ return _context49.stop();
6592
6992
  }
6593
- }, _callee43, this);
6993
+ }, _callee46, this);
6594
6994
  }));
6595
- function getOrderInfo(_x52) {
6995
+ function getOrderInfo(_x54) {
6596
6996
  return _getOrderInfo.apply(this, arguments);
6597
6997
  }
6598
6998
  return getOrderInfo;