@pisell/pisellos 2.2.276 → 2.2.277

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.
@@ -45,6 +45,29 @@ function normalizeWalletAssetCode(code) {
45
45
  function getWalletAssetCodeKeys(asset) {
46
46
  return [asset === null || asset === void 0 ? void 0 : asset.code, asset === null || asset === void 0 ? void 0 : asset.encoded].map(normalizeWalletAssetCode).filter(Boolean);
47
47
  }
48
+
49
+ /**
50
+ * 保存货币类扫码资产自身的可用余额,供后续前端策略重新计算。
51
+ * 搜索接口的 recommended_usage_amount 已扣除了搜索时的已选券,不能作为
52
+ * 取消勾选后的永久上限。积分卡的 balance_par_value 是积分值,不能直接
53
+ * 当作货币金额,因此继续沿用接口推荐金额。
54
+ */
55
+ function withWalletAssetRecalculationBaseAmount(asset) {
56
+ var existingBaseAmount = Number(asset === null || asset === void 0 ? void 0 : asset._wallet_asset_recalculation_base_amount);
57
+ if (Number.isFinite(existingBaseAmount) && existingBaseAmount >= 0) {
58
+ return asset;
59
+ }
60
+ if (!['product_voucher', 'gift_card'].includes(asset === null || asset === void 0 ? void 0 : asset.tag)) {
61
+ return asset;
62
+ }
63
+ var balanceParValue = Number(asset === null || asset === void 0 ? void 0 : asset.balance_par_value);
64
+ if (!Number.isFinite(balanceParValue) || balanceParValue < 0) {
65
+ return asset;
66
+ }
67
+ return _objectSpread(_objectSpread({}, asset), {}, {
68
+ _wallet_asset_recalculation_base_amount: balanceParValue
69
+ });
70
+ }
48
71
  function isWalletAssetAvailable(asset) {
49
72
  if (!asset) return false;
50
73
  if (asset.unified_available_status !== undefined && Number(asset.unified_available_status) !== 1) {
@@ -228,6 +251,36 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
228
251
  });
229
252
  }
230
253
 
254
+ /**
255
+ * 搜索接口只返回后端 Wallet Pass 数据,不包含前端策略 config。
256
+ * 在资产进入共享选择状态前补齐策略结果,避免增量重算回退到接口状态。
257
+ */
258
+ }, {
259
+ key: "formatSearchedWalletPaymentAssets",
260
+ value: function formatSearchedWalletPaymentAssets(assets) {
261
+ var _this$paymentModule$w3, _this$paymentModule$w4, _this$walletParams, _this$walletParams2;
262
+ if (!assets.length) return assets;
263
+ var assetsWithRecalculationBase = assets.map(withWalletAssetRecalculationBaseAmount);
264
+ var evaluator = (_this$paymentModule$w3 = this.paymentModule.window) === null || _this$paymentModule$w3 === void 0 || (_this$paymentModule$w4 = _this$paymentModule$w3.getWalletPassEvaluator) === null || _this$paymentModule$w4 === void 0 ? void 0 : _this$paymentModule$w4.call(_this$paymentModule$w3);
265
+ if (!(evaluator !== null && evaluator !== void 0 && evaluator.searchVoucherFormat)) return assetsWithRecalculationBase;
266
+ var hasCalculationProducts = this.walletAssetsCalculationContext.products.length > 0;
267
+ var products = hasCalculationProducts ? this.walletAssetsCalculationContext.products : ((_this$walletParams = this.walletParams) === null || _this$walletParams === void 0 ? void 0 : _this$walletParams.products) || [];
268
+ var orderTotalAmount = Number(hasCalculationProducts ? this.walletAssetsCalculationContext.orderTotalAmount : ((_this$walletParams2 = this.walletParams) === null || _this$walletParams2 === void 0 ? void 0 : _this$walletParams2.order_wait_pay_amount) || 0);
269
+ try {
270
+ var formattedAssets = evaluator.searchVoucherFormat({
271
+ orderTotalAmount: orderTotalAmount,
272
+ products: products,
273
+ vouchers: assetsWithRecalculationBase
274
+ });
275
+ return formattedAssets;
276
+ } catch (error) {
277
+ this.paymentModule.logWarning('[WalletPass] 搜索资产策略格式化失败,保留接口结果', {
278
+ error: error instanceof Error ? error.message : String(error)
279
+ });
280
+ return assetsWithRecalculationBase;
281
+ }
282
+ }
283
+
231
284
  /** 获取当前缓存中所有支付类 Wallet 资产的扫码 code。 */
232
285
  }, {
233
286
  key: "getSearchedWalletAssetCodes",
@@ -256,8 +309,19 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
256
309
  return code.toUpperCase();
257
310
  }));
258
311
  if (searchedCodeKeys.size === 0) return cachedAssets;
312
+ var cachedAssetByCode = new Map();
313
+ cachedAssets.forEach(function (item) {
314
+ getWalletAssetCodeKeys(item).forEach(function (code) {
315
+ cachedAssetByCode.set(code, item);
316
+ });
317
+ });
259
318
  var refreshedAssets = refreshedCandidates.filter(function (item) {
260
319
  return isWalletPaymentAsset(item) && searchedCodeKeys.has(String((item === null || item === void 0 ? void 0 : item.code) || '').trim().toUpperCase());
320
+ }).map(function (item) {
321
+ var cachedAsset = getWalletAssetCodeKeys(item).map(function (code) {
322
+ return cachedAssetByCode.get(code);
323
+ }).find(Boolean);
324
+ return withWalletAssetRecalculationBaseAmount(_objectSpread(_objectSpread({}, cachedAsset), item));
261
325
  });
262
326
  if (refreshedAssets.length > 0) {
263
327
  var replacedCodes = new Set(refreshedAssets.map(function (item) {
@@ -333,8 +397,14 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
333
397
  payment_order_id: payment_order_id
334
398
  };
335
399
 
336
- // 存储生成的参数到模块中
400
+ // 扫码可能早于异步 Wallet 初始化完成。walletParams 与前端增量重算
401
+ // 必须使用同一份当前购物车上下文,避免搜索按真实金额判断可用,
402
+ // 随后的 recalculateVouchers 却仍读取初始的 0 元/空商品上下文。
337
403
  this.walletParams = walletParams;
404
+ this.walletAssetsCalculationContext = {
405
+ orderTotalAmount: Number(walletParams.order_wait_pay_amount || 0),
406
+ products: Array.isArray(walletParams.products) ? walletParams.products : []
407
+ };
338
408
  this.paymentModule.logInfo('[WalletPass] 钱包默认参数已生成并存储', {
339
409
  customer_id: walletParams.customer_id,
340
410
  holder_id: walletParams.holder_id,
@@ -511,7 +581,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
511
581
  key: "initializeWalletDataAsync",
512
582
  value: (function () {
513
583
  var _initializeWalletDataAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(baseParams) {
514
- var _this$paymentModule$w3, _this$paymentModule$w4, identificationParams, _yield$Promise$all, _yield$Promise$all2, allList, orderBasicDetail, walletPassEvaluator, products, res, recommended, transformList, noApplicableVoucher, recommendedAmount;
584
+ var _this$paymentModule$w5, _this$paymentModule$w6, identificationParams, _yield$Promise$all, _yield$Promise$all2, allList, orderBasicDetail, walletPassEvaluator, products, res, recommended, transformList, noApplicableVoucher, recommendedAmount;
515
585
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
516
586
  while (1) switch (_context3.prev = _context3.next) {
517
587
  case 0:
@@ -530,7 +600,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
530
600
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
531
601
  allList = _yield$Promise$all2[0];
532
602
  orderBasicDetail = _yield$Promise$all2[1];
533
- walletPassEvaluator = (_this$paymentModule$w3 = this.paymentModule.window) === null || _this$paymentModule$w3 === void 0 || (_this$paymentModule$w4 = _this$paymentModule$w3.getWalletPassEvaluator) === null || _this$paymentModule$w4 === void 0 ? void 0 : _this$paymentModule$w4.call(_this$paymentModule$w3);
603
+ walletPassEvaluator = (_this$paymentModule$w5 = this.paymentModule.window) === null || _this$paymentModule$w5 === void 0 || (_this$paymentModule$w6 = _this$paymentModule$w5.getWalletPassEvaluator) === null || _this$paymentModule$w6 === void 0 ? void 0 : _this$paymentModule$w6.call(_this$paymentModule$w5);
534
604
  if (walletPassEvaluator) {
535
605
  _context3.next = 11;
536
606
  break;
@@ -550,7 +620,6 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
550
620
  vouchers: allList
551
621
  });
552
622
  recommended = res.recommended, transformList = res.transformList, noApplicableVoucher = res.noApplicableVoucher, recommendedAmount = res.recommendedAmount;
553
- console.log(res, 'resres12');
554
623
  this.walletRecommendList = recommended;
555
624
 
556
625
  // 存储初始化数据到内存中,供 useWalletPass 使用
@@ -570,19 +639,19 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
570
639
  noApplicableVoucher: noApplicableVoucher,
571
640
  products: products || []
572
641
  });
573
- case 20:
574
- _context3.prev = 20;
642
+ case 19:
643
+ _context3.prev = 19;
575
644
  _context3.t0 = _context3["catch"](0);
576
645
  this.paymentModule.logError('[WalletPass] 初始化钱包数据失败', _context3.t0, {
577
646
  customer_id: baseParams.customer_id,
578
647
  order_expect_amount: baseParams.order_expect_amount
579
648
  });
580
649
  throw _context3.t0;
581
- case 24:
650
+ case 23:
582
651
  case "end":
583
652
  return _context3.stop();
584
653
  }
585
- }, _callee3, this, [[0, 20]]);
654
+ }, _callee3, this, [[0, 19]]);
586
655
  }));
587
656
  function initializeWalletDataAsync(_x3) {
588
657
  return _initializeWalletDataAsync.apply(this, arguments);
@@ -598,7 +667,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
598
667
  key: "aggregateRecalculateWalletAssetsAsync",
599
668
  value: (function () {
600
669
  var _aggregateRecalculateWalletAssetsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(businessData, selectedIds) {
601
- var _this$paymentModule$w5, _this$paymentModule$w6;
670
+ var _this$paymentModule$w7, _this$paymentModule$w8;
602
671
  var walletParams, customerId, requestParams, response, responseData, hasAggregateLists, recalculateList, customerWalletPassList, allList, walletPassEvaluator, evaluated, returnedSelectedKeys, authoritativeSelectedIds;
603
672
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
604
673
  while (1) switch (_context4.prev = _context4.next) {
@@ -636,7 +705,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
636
705
  recalculateList = Array.isArray(responseData === null || responseData === void 0 ? void 0 : responseData.recalculate_list) ? responseData.recalculate_list : [];
637
706
  customerWalletPassList = Array.isArray(responseData === null || responseData === void 0 ? void 0 : responseData.customer_wallet_pass_list) ? responseData.customer_wallet_pass_list : [];
638
707
  allList = mergeWalletAssets(recalculateList, customerWalletPassList);
639
- walletPassEvaluator = (_this$paymentModule$w5 = this.paymentModule.window) === null || _this$paymentModule$w5 === void 0 || (_this$paymentModule$w6 = _this$paymentModule$w5.getWalletPassEvaluator) === null || _this$paymentModule$w6 === void 0 ? void 0 : _this$paymentModule$w6.call(_this$paymentModule$w5);
708
+ walletPassEvaluator = (_this$paymentModule$w7 = this.paymentModule.window) === null || _this$paymentModule$w7 === void 0 || (_this$paymentModule$w8 = _this$paymentModule$w7.getWalletPassEvaluator) === null || _this$paymentModule$w8 === void 0 ? void 0 : _this$paymentModule$w8.call(_this$paymentModule$w7);
640
709
  evaluated = walletPassEvaluator !== null && walletPassEvaluator !== void 0 && walletPassEvaluator.getRecommendedVouchers ? walletPassEvaluator.getRecommendedVouchers({
641
710
  orderTotalAmount: walletParams.order_wait_pay_amount,
642
711
  products: walletParams.products,
@@ -647,8 +716,10 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
647
716
  noApplicableVoucher: allList.filter(function (item) {
648
717
  return !isWalletAssetAvailable(item);
649
718
  })
650
- };
651
- returnedSelectedKeys = new Set(recalculateList.filter(isWalletAssetAvailable).map(function (item) {
719
+ }; // 聚合接口只负责刷新资产数据;选中资格最终由前端 evaluator 重算。
720
+ // 这里仅移除接口完全未返回的资产,不能把 recalculate_list 当作
721
+ // 策略选中结果,否则 customer_wallet_pass_list 中的可用券会被误取消。
722
+ returnedSelectedKeys = new Set(allList.map(function (item) {
652
723
  return getWalletAssetKey(item);
653
724
  }));
654
725
  authoritativeSelectedIds = selectedIds.filter(function (id) {
@@ -692,7 +763,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
692
763
  key: "getWalletPassRecommendListAsync",
693
764
  value: function () {
694
765
  var _getWalletPassRecommendListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
695
- var _this$walletParams, response;
766
+ var _this$walletParams3, response;
696
767
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
697
768
  while (1) switch (_context5.prev = _context5.next) {
698
769
  case 0:
@@ -701,7 +772,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
701
772
  customer_id: params.customer_id,
702
773
  order_expect_amount: params.order_expect_amount,
703
774
  sale_channel: params.sale_channel,
704
- payment_order_id: (_this$walletParams = this.walletParams) === null || _this$walletParams === void 0 ? void 0 : _this$walletParams.payment_order_id
775
+ payment_order_id: (_this$walletParams3 = this.walletParams) === null || _this$walletParams3 === void 0 ? void 0 : _this$walletParams3.payment_order_id
705
776
  });
706
777
  if (typeof params.payment_order_id === 'string' && params.payment_order_id.startsWith('LOCAL_')) {
707
778
  params.payment_order_id = undefined;
@@ -759,7 +830,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
759
830
  key: "getUserIdentificationCodeListAsync",
760
831
  value: function () {
761
832
  var _getUserIdentificationCodeListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
762
- var _newParams$products, _newParams$prepare_pa, _this$walletParams2, newParams, response, sortedData;
833
+ var _newParams$products, _newParams$prepare_pa, _this$walletParams4, newParams, response, sortedData;
763
834
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
764
835
  while (1) switch (_context6.prev = _context6.next) {
765
836
  case 0:
@@ -780,7 +851,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
780
851
  available: newParams.available,
781
852
  prepare_payments_count: ((_newParams$prepare_pa = newParams.prepare_payments) === null || _newParams$prepare_pa === void 0 ? void 0 : _newParams$prepare_pa.length) || 0,
782
853
  filter_prepare_wallet_pass: newParams.filter_prepare_wallet_pass,
783
- payment_order_id: (_this$walletParams2 = this.walletParams) === null || _this$walletParams2 === void 0 ? void 0 : _this$walletParams2.payment_order_id
854
+ payment_order_id: (_this$walletParams4 = this.walletParams) === null || _this$walletParams4 === void 0 ? void 0 : _this$walletParams4.payment_order_id
784
855
  });
785
856
  _context6.next = 9;
786
857
  return this.paymentModule.request.post('/machinecode/prepare/deduction', newParams);
@@ -1019,6 +1090,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1019
1090
  selectedIds,
1020
1091
  selectionSources,
1021
1092
  scanSelectedAssets,
1093
+ manualEditAmountByKey,
1022
1094
  restoredSearchedAssets,
1023
1095
  searchedWalletAssetCodes,
1024
1096
  useAggregateRecalculate,
@@ -1061,11 +1133,20 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1061
1133
  scanSelectedAssets = preserveSelection ? this.walletAssetsState.selectedItems.filter(function (asset) {
1062
1134
  var assetId = getWalletAssetId(asset);
1063
1135
  return assetId !== undefined && assetId !== null && selectionSources[String(assetId)] === 'scan';
1064
- }) : []; // aggregate-recalculate 不接受空商品列表。
1136
+ }) : [];
1137
+ manualEditAmountByKey = new Map();
1138
+ if (preserveSelection) {
1139
+ this.walletAssetsState.selectedItems.forEach(function (asset) {
1140
+ if (typeof (asset === null || asset === void 0 ? void 0 : asset.edit_current_amount) !== 'number') return;
1141
+ manualEditAmountByKey.set(getWalletAssetKey(asset), asset.edit_current_amount);
1142
+ });
1143
+ }
1144
+
1145
+ // aggregate-recalculate 不接受空商品列表。
1065
1146
  // 清空购物车时保留扫码资产供后续加购恢复;只有手动 Remove/Clear
1066
1147
  // 会取消自动应用资格,商品变化导致的自动失效需要重新进入待选队列。
1067
1148
  if ((_businessData$product2 = businessData.products) !== null && _businessData$product2 !== void 0 && _businessData$product2.length) {
1068
- _context8.next = 22;
1149
+ _context8.next = 24;
1069
1150
  break;
1070
1151
  }
1071
1152
  this.queuePendingAutoSelectForAssets(scanSelectedAssets);
@@ -1103,7 +1184,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1103
1184
  totalSelectedAmount: 0,
1104
1185
  error: null
1105
1186
  }));
1106
- case 22:
1187
+ case 24:
1107
1188
  this.publishWalletAssetsState({
1108
1189
  status: 'loading',
1109
1190
  customerId: nextCustomerId,
@@ -1114,40 +1195,40 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1114
1195
  totalSelectedAmount: preserveSelection ? this.walletAssetsState.totalSelectedAmount : 0,
1115
1196
  error: null
1116
1197
  });
1117
- _context8.prev = 23;
1198
+ _context8.prev = 25;
1118
1199
  searchedWalletAssetCodes = preserveSelection ? this.getSearchedWalletAssetCodes() : [];
1119
1200
  useAggregateRecalculate = preserveSelection && (selectedIds.length > 0 || searchedWalletAssetCodes.length > 0);
1120
1201
  if (!useAggregateRecalculate) {
1121
- _context8.next = 32;
1202
+ _context8.next = 34;
1122
1203
  break;
1123
1204
  }
1124
- _context8.next = 29;
1205
+ _context8.next = 31;
1125
1206
  return this.aggregateRecalculateWalletAssetsAsync(businessData, selectedIds);
1126
- case 29:
1207
+ case 31:
1127
1208
  _context8.t0 = _context8.sent;
1128
- _context8.next = 33;
1209
+ _context8.next = 35;
1129
1210
  break;
1130
- case 32:
1211
+ case 34:
1131
1212
  _context8.t0 = null;
1132
- case 33:
1213
+ case 35:
1133
1214
  aggregateResult = _context8.t0;
1134
1215
  _context8.t1 = aggregateResult;
1135
1216
  if (_context8.t1) {
1136
- _context8.next = 39;
1217
+ _context8.next = 41;
1137
1218
  break;
1138
1219
  }
1139
- _context8.next = 38;
1220
+ _context8.next = 40;
1140
1221
  return this.initializeWalletDataFromBusinessAsync(businessData);
1141
- case 38:
1222
+ case 40:
1142
1223
  _context8.t1 = _context8.sent;
1143
- case 39:
1224
+ case 41:
1144
1225
  result = _context8.t1;
1145
1226
  if (!(requestSequence !== this.walletAssetsRequestSequence)) {
1146
- _context8.next = 42;
1227
+ _context8.next = 44;
1147
1228
  break;
1148
1229
  }
1149
1230
  return _context8.abrupt("return", this.getWalletAssetsState());
1150
- case 42:
1231
+ case 44:
1151
1232
  this.walletAssetsCalculationContext = {
1152
1233
  orderTotalAmount: Number(businessData.order_wait_pay_amount || 0),
1153
1234
  products: result.products || businessData.products || []
@@ -1170,17 +1251,20 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1170
1251
  }
1171
1252
  searchedWalletAssets = preserveSelection ? this.syncSearchedWalletAssets([].concat(_toConsumableArray(result.transformList || []), _toConsumableArray(result.noApplicableVoucher || []))) : [];
1172
1253
  if (!(requestSequence !== this.walletAssetsRequestSequence)) {
1173
- _context8.next = 48;
1254
+ _context8.next = 50;
1174
1255
  break;
1175
1256
  }
1176
1257
  return _context8.abrupt("return", this.getWalletAssetsState());
1177
- case 48:
1258
+ case 50:
1178
1259
  recommendedKeys = new Set((result.walletRecommendList || []).map(function (asset) {
1179
1260
  return getWalletAssetKey(asset);
1180
1261
  }));
1181
1262
  items = mergeWalletAssets(preserveSelection && !aggregateResult ? this.walletAssetsState.selectedItems : [], searchedWalletAssets, result.transformList || [], result.noApplicableVoucher || []).map(function (asset) {
1182
- return _objectSpread(_objectSpread({}, asset), {}, {
1183
- _wallet_asset_recommended: recommendedKeys.has(getWalletAssetKey(asset))
1263
+ var assetKey = getWalletAssetKey(asset);
1264
+ return _objectSpread(_objectSpread(_objectSpread({}, asset), manualEditAmountByKey.has(assetKey) ? {
1265
+ edit_current_amount: manualEditAmountByKey.get(assetKey)
1266
+ } : {}), {}, {
1267
+ _wallet_asset_recommended: recommendedKeys.has(assetKey)
1184
1268
  });
1185
1269
  });
1186
1270
  latestSelectedIds = preserveSelection ? authoritativeSelectedIds : [];
@@ -1217,15 +1301,15 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1217
1301
  });
1218
1302
  this.queuePendingAutoSelectForAssets(droppedScanSelectedAssets);
1219
1303
  return _context8.abrupt("return", nextState);
1220
- case 63:
1221
- _context8.prev = 63;
1222
- _context8.t2 = _context8["catch"](23);
1304
+ case 65:
1305
+ _context8.prev = 65;
1306
+ _context8.t2 = _context8["catch"](25);
1223
1307
  if (!(requestSequence !== this.walletAssetsRequestSequence)) {
1224
- _context8.next = 67;
1308
+ _context8.next = 69;
1225
1309
  break;
1226
1310
  }
1227
1311
  return _context8.abrupt("return", this.getWalletAssetsState());
1228
- case 67:
1312
+ case 69:
1229
1313
  this.paymentModule.logError('[WalletPass] 刷新共享钱包资产失败,保留刷新前状态', _context8.t2, {
1230
1314
  customer_id: businessData.customer_id,
1231
1315
  selected_ids: selectedIds,
@@ -1241,11 +1325,11 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1241
1325
  customerId: nextCustomerId,
1242
1326
  error: _context8.t2 instanceof Error ? _context8.t2.message : String(_context8.t2)
1243
1327
  }));
1244
- case 69:
1328
+ case 71:
1245
1329
  case "end":
1246
1330
  return _context8.stop();
1247
1331
  }
1248
- }, _callee8, this, [[23, 63]]);
1332
+ }, _callee8, this, [[25, 65]]);
1249
1333
  }));
1250
1334
  function refreshWalletAssetsFromBusinessAsync(_x9) {
1251
1335
  return _refreshWalletAssetsFromBusinessAsync.apply(this, arguments);
@@ -1298,6 +1382,17 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1298
1382
  selectionSources: snapshot.state.selectionSources || {}
1299
1383
  }));
1300
1384
  }
1385
+ }, {
1386
+ key: "updateWalletAssetEditAmountInCaches",
1387
+ value: function updateWalletAssetEditAmountInCaches(assetKey, amount) {
1388
+ var updateAsset = function updateAsset(asset) {
1389
+ return getWalletAssetKey(asset) === assetKey ? _objectSpread(_objectSpread({}, asset), {}, {
1390
+ edit_current_amount: amount
1391
+ }) : asset;
1392
+ };
1393
+ this.searchResults = this.searchResults.map(updateAsset);
1394
+ return this.walletAssetsState.items.map(updateAsset);
1395
+ }
1301
1396
  }, {
1302
1397
  key: "selectWalletAsset",
1303
1398
  value: function selectWalletAsset(assetId, options) {
@@ -1314,6 +1409,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1314
1409
  });
1315
1410
  var selectionSources = _objectSpread({}, this.walletAssetsState.selectionSources);
1316
1411
  delete selectionSources[assetKey];
1412
+ var nextItems = this.walletAssetsState.items;
1317
1413
  if (options.selected) {
1318
1414
  if (!asset || !isWalletAssetAvailable(asset)) {
1319
1415
  return this.getWalletAssetsState();
@@ -1322,8 +1418,9 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1322
1418
  selectionSources[assetKey] = options.source || 'manual';
1323
1419
  } else if (asset) {
1324
1420
  this.clearPendingAutoSelectForAsset(asset);
1421
+ nextItems = this.updateWalletAssetEditAmountInCaches(assetKey, undefined);
1325
1422
  }
1326
- var nextState = this.recalculateWalletAssets(this.walletAssetsState.items, selectedIds, selectionSources);
1423
+ var nextState = this.recalculateWalletAssets(nextItems, selectedIds, selectionSources);
1327
1424
  if (options.selected && asset && nextState.selectedIds.some(function (id) {
1328
1425
  return String(id) === assetKey;
1329
1426
  })) {
@@ -1331,11 +1428,49 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1331
1428
  }
1332
1429
  return nextState;
1333
1430
  }
1431
+
1432
+ /**
1433
+ * 更新已选资产的手动金额。只允许在当前实际抵扣额内向下调整,
1434
+ * 金额为 0 时沿用 legacy 行为取消选择。
1435
+ */
1436
+ }, {
1437
+ key: "updateWalletAssetAmount",
1438
+ value: function updateWalletAssetAmount(assetId, amount) {
1439
+ var assetKey = String(assetId);
1440
+ var committedKeys = new Set(this.walletAssetsState.committedIds.map(function (id) {
1441
+ return String(id);
1442
+ }));
1443
+ var selectedKeys = new Set(this.walletAssetsState.selectedIds.map(function (id) {
1444
+ return String(id);
1445
+ }));
1446
+ var asset = this.walletAssetsState.items.find(function (item) {
1447
+ return getWalletAssetKey(item) === assetKey;
1448
+ });
1449
+ var requestedAmount = Number(amount);
1450
+ if (!asset || committedKeys.has(assetKey) || !selectedKeys.has(assetKey) || !Number.isFinite(requestedAmount) || requestedAmount < 0) {
1451
+ return this.getWalletAssetsState();
1452
+ }
1453
+ var selectedIds = _toConsumableArray(this.walletAssetsState.selectedIds);
1454
+ var selectionSources = _objectSpread({}, this.walletAssetsState.selectionSources);
1455
+ if (requestedAmount === 0) {
1456
+ var _nextItems = this.updateWalletAssetEditAmountInCaches(assetKey, undefined);
1457
+ delete selectionSources[assetKey];
1458
+ this.clearPendingAutoSelectForAsset(asset);
1459
+ return this.recalculateWalletAssets(_nextItems, selectedIds.filter(function (id) {
1460
+ return String(id) !== assetKey;
1461
+ }), selectionSources);
1462
+ }
1463
+ var currentDeductionAmount = getWalletAssetDeductionAmount(asset);
1464
+ var editAmount = Math.min(requestedAmount, currentDeductionAmount);
1465
+ if (editAmount <= 0) return this.getWalletAssetsState();
1466
+ var nextItems = this.updateWalletAssetEditAmountInCaches(assetKey, editAmount);
1467
+ return this.recalculateWalletAssets(nextItems, selectedIds, selectionSources);
1468
+ }
1334
1469
  }, {
1335
1470
  key: "scanWalletAssetAsync",
1336
1471
  value: function () {
1337
1472
  var _scanWalletAssetAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(code) {
1338
- var normalizedCode, selectedAsset, result, paymentAssets, asset, items, recalculatedState, assetId, selected, isSelected;
1473
+ var normalizedCode, selectedAsset, result, paymentAssets, asset, items, recalculatedState, assetId, recalculatedAsset, selected, isSelected, selectedStateAsset, resolvedAsset;
1339
1474
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1340
1475
  while (1) switch (_context9.prev = _context9.next) {
1341
1476
  case 0:
@@ -1372,12 +1507,15 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1372
1507
  }));
1373
1508
  case 9:
1374
1509
  result = _context9.sent;
1375
- paymentAssets = result.data.filter(isWalletPaymentAsset);
1510
+ paymentAssets = this.formatSearchedWalletPaymentAssets(result.data.filter(isWalletPaymentAsset));
1511
+ if (paymentAssets.length > 0) {
1512
+ this.searchResults = mergeWalletAssets(this.searchResults, paymentAssets);
1513
+ }
1376
1514
  asset = paymentAssets.find(function (item) {
1377
1515
  return String((item === null || item === void 0 ? void 0 : item.code) || '') === normalizedCode;
1378
1516
  }) || paymentAssets[0];
1379
1517
  if (!(!asset || result.type === 'walletCode')) {
1380
- _context9.next = 14;
1518
+ _context9.next = 15;
1381
1519
  break;
1382
1520
  }
1383
1521
  return _context9.abrupt("return", {
@@ -1386,30 +1524,37 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1386
1524
  selected: false,
1387
1525
  state: this.getWalletAssetsState()
1388
1526
  });
1389
- case 14:
1527
+ case 15:
1390
1528
  items = mergeWalletAssets(this.walletAssetsState.items, [asset]);
1391
1529
  recalculatedState = this.recalculateWalletAssets(items, this.walletAssetsState.selectedIds, this.walletAssetsState.selectionSources);
1392
1530
  assetId = getWalletAssetId(asset);
1393
- selected = this.walletAssetsBehavior.autoSelectAfterSearch && assetId !== undefined && isWalletAssetAvailable(asset) ? this.selectWalletAsset(assetId, {
1531
+ recalculatedAsset = assetId === undefined ? undefined : recalculatedState.items.find(function (item) {
1532
+ return getWalletAssetKey(item) === String(assetId);
1533
+ });
1534
+ selected = this.walletAssetsBehavior.autoSelectAfterSearch && assetId !== undefined && isWalletAssetAvailable(recalculatedAsset) ? this.selectWalletAsset(assetId, {
1394
1535
  selected: true,
1395
1536
  source: 'scan'
1396
1537
  }) : recalculatedState;
1397
1538
  isSelected = assetId !== undefined && selected.selectedIds.some(function (id) {
1398
1539
  return String(id) === String(assetId);
1399
1540
  });
1541
+ selectedStateAsset = assetId === undefined ? undefined : selected.items.find(function (item) {
1542
+ return getWalletAssetKey(item) === String(assetId);
1543
+ });
1544
+ resolvedAsset = selectedStateAsset || recalculatedAsset || asset;
1400
1545
  if (isSelected) {
1401
- this.clearPendingAutoSelectForAsset(asset);
1546
+ this.clearPendingAutoSelectForAsset(resolvedAsset);
1402
1547
  } else if (this.walletAssetsBehavior.autoSelectAfterSearch) {
1403
1548
  this.pendingAutoSelectSearchCodes.add(normalizeWalletAssetCode(normalizedCode));
1404
- this.queuePendingAutoSelectForAssets([asset]);
1549
+ this.queuePendingAutoSelectForAssets([resolvedAsset]);
1405
1550
  }
1406
1551
  return _context9.abrupt("return", {
1407
1552
  type: result.type,
1408
- asset: asset,
1553
+ asset: resolvedAsset,
1409
1554
  selected: isSelected,
1410
1555
  state: selected
1411
1556
  });
1412
- case 21:
1557
+ case 25:
1413
1558
  case "end":
1414
1559
  return _context9.stop();
1415
1560
  }
@@ -1424,7 +1569,16 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1424
1569
  key: "clearWalletAssetSelection",
1425
1570
  value: function clearWalletAssetSelection() {
1426
1571
  this.pendingAutoSelectSearchCodes.clear();
1427
- return this.recalculateWalletAssets(this.walletAssetsState.items, [], {});
1572
+ var selectedKeys = new Set(this.walletAssetsState.selectedIds.map(function (id) {
1573
+ return String(id);
1574
+ }));
1575
+ var clearSelectedEditAmount = function clearSelectedEditAmount(asset) {
1576
+ return selectedKeys.has(getWalletAssetKey(asset)) ? _objectSpread(_objectSpread({}, asset), {}, {
1577
+ edit_current_amount: undefined
1578
+ }) : asset;
1579
+ };
1580
+ this.searchResults = this.searchResults.map(clearSelectedEditAmount);
1581
+ return this.recalculateWalletAssets(this.walletAssetsState.items.map(clearSelectedEditAmount), [], {});
1428
1582
  }
1429
1583
  }, {
1430
1584
  key: "setCommittedWalletAssets",
@@ -355,6 +355,11 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
355
355
  selected: boolean;
356
356
  source?: WalletAssetSelectionSource;
357
357
  }): Promise<WalletAssetsState>;
358
+ /** 更新已选钱包资产的手动使用金额,并同步 pending payment。 */
359
+ updateWalletAssetAmount(params: {
360
+ assetId: WalletAssetId;
361
+ amount: number;
362
+ }): Promise<WalletAssetsState>;
358
363
  /** 扫码精确查券;仅可用资产会被自动选中。 */
359
364
  scanWalletAsset(code: string): Promise<ScanWalletAssetResult>;
360
365
  /** 清空全部未确认钱包选择,已支付钱包项由 Order 模块继续保留。 */