@pisell/private-materials 6.4.22 → 6.4.23

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.
@@ -1613,7 +1613,7 @@ var PaymentModal = function PaymentModal(_ref17) {
1613
1613
  // 获取 checkout 模块并处理订单数据
1614
1614
  checkout = pisellos === null || pisellos === void 0 ? void 0 : pisellos.getModule('checkout');
1615
1615
  if (!(checkout && data && !isLocalOrderCreated.current)) {
1616
- _context17.next = 19;
1616
+ _context17.next = 20;
1617
1617
  break;
1618
1618
  }
1619
1619
  isLocalOrderCreated.current = true;
@@ -1661,27 +1661,130 @@ var PaymentModal = function PaymentModal(_ref17) {
1661
1661
  unsubscribeRef.current();
1662
1662
  unsubscribeRef.current = undefined;
1663
1663
  }
1664
- _context17.next = 30;
1664
+ // 监听订单同步完成,同步完成后显示订单完成 toast,关闭当前弹窗
1665
+ unsubscribeRef.current = checkout.core.effects.on('checkout:onOrderSynced', function (data) {
1666
+ var _data$response, _responseData$payment2;
1667
+ // 获取支付状态和相关信息
1668
+ var responseData = (_data$response = data.response) === null || _data$response === void 0 ? void 0 : _data$response.data;
1669
+ // 获取支付状态
1670
+ var paymentStatus = responseData === null || responseData === void 0 ? void 0 : responseData.payment_status;
1671
+ if (data.isManual) return;
1672
+ handlePaymentComplete(data);
1673
+ // 如果正在显示现金支付 toast,跳过自动关闭逻辑
1674
+ if (showingCashToastRef.current) {
1675
+ return;
1676
+ }
1677
+
1678
+ // 获取订单总金额
1679
+ var orderTotalAmount = Number((responseData === null || responseData === void 0 ? void 0 : responseData.total_amount) || 0);
1680
+ var gapAmount = Number((responseData === null || responseData === void 0 ? void 0 : responseData.amount_gap) || 0);
1681
+ var currentChangeGivenAmount = Number((responseData === null || responseData === void 0 || (_responseData$payment2 = responseData.payment_info) === null || _responseData$payment2 === void 0 ? void 0 : _responseData$payment2.current_change_given_amount) || 0);
1682
+ // const changeDue = Number(responseData?.amount_gap || 0);
1683
+ // 获取失败原因
1684
+ var failureReason = responseData === null || responseData === void 0 ? void 0 : responseData.failure_reason;
1685
+
1686
+ // 根据支付状态弹出对应的支付结果toast
1687
+ if (paymentStatus) {
1688
+ // 打印订单完整信息
1689
+ console.log('print_order_onOrderSynced>>>>', responseData);
1690
+ logger === null || logger === void 0 || logger.addLog({
1691
+ type: 'info',
1692
+ title: 'print_order_onOrderSynced',
1693
+ metadata: {
1694
+ responseData: responseData
1695
+ }
1696
+ });
1697
+ try {
1698
+ var _responseData$payment3;
1699
+ var params = {
1700
+ type: '99',
1701
+ // 打印订单全部信息
1702
+ data: {
1703
+ order_id: responseData.order_id,
1704
+ machine_code_print_info: responseData === null || responseData === void 0 ? void 0 : responseData.machine_code_print_info,
1705
+ small_ticket_data: responseData === null || responseData === void 0 || (_responseData$payment3 = responseData.payment_info) === null || _responseData$payment3 === void 0 ? void 0 : _responseData$payment3.small_ticket_data
1706
+ }
1707
+ };
1708
+ console.log('print_order_onOrderSynced_params>>>>', params);
1709
+ logger === null || logger === void 0 || logger.addLog({
1710
+ type: 'info',
1711
+ title: 'print_order_onOrderSynced_params',
1712
+ metadata: {
1713
+ params: params
1714
+ }
1715
+ });
1716
+ webPrint(params, function (res) {
1717
+ console.log('print_order_onOrderSynced_res>>>>', res);
1718
+ logger === null || logger === void 0 || logger.addLog({
1719
+ type: 'info',
1720
+ title: 'print_order_onOrderSynced_res',
1721
+ metadata: {
1722
+ res: res
1723
+ }
1724
+ });
1725
+ });
1726
+ } catch (error) {
1727
+ console.error('print_order_onOrderSynced_error>>>>', error);
1728
+ logger === null || logger === void 0 || logger.addLog({
1729
+ type: 'info',
1730
+ title: 'print_order_onOrderSynced_error',
1731
+ metadata: {
1732
+ error: error
1733
+ }
1734
+ });
1735
+ }
1736
+
1737
+ // 确定支付状态
1738
+ var statusClassName = calculateStatusClassName(paymentStatus);
1739
+ var autoCloseConfig = calculateAutoCloseConfig(paymentStatus, !!currentChangeGivenAmount);
1740
+
1741
+ // 根据支付状态展示不同的 toast
1742
+ displayPaymentResultToast({
1743
+ paymentStatus: paymentStatus,
1744
+ orderTotalAmount: orderTotalAmount,
1745
+ gapAmount: paymentStatus === 'partially_paid' ? gapAmount : currentChangeGivenAmount,
1746
+ failureReason: failureReason,
1747
+ autoCloseConfig: autoCloseConfig,
1748
+ actionButtons: generateActionButtons(paymentStatus)
1749
+ }, paymentResultToastConfig);
1750
+
1751
+ // 将支付结果信息传递给回调处理
1752
+ var paymentResult = _objectSpread(_objectSpread({}, data), {}, {
1753
+ toastInfo: {
1754
+ status: paymentStatus,
1755
+ amount: orderTotalAmount,
1756
+ gapAmount: currentChangeGivenAmount,
1757
+ failureReason: failureReason
1758
+ }
1759
+ });
1760
+ handlePaymentComplete(paymentResult);
1761
+ } else {
1762
+ handlePaymentComplete(data);
1763
+ }
1764
+ // 可以在这里执行同步完成后的业务逻辑
1765
+ // 比如:通知其他系统、更新UI状态等
1766
+ });
1767
+ _context17.next = 31;
1665
1768
  break;
1666
- case 19:
1769
+ case 20:
1667
1770
  if (!isLocalOrderCreated.current) {
1668
- _context17.next = 30;
1771
+ _context17.next = 31;
1669
1772
  break;
1670
1773
  }
1671
1774
  // // 如果本地订单已创建,这时候还更新了 data,则需要销毁当前的订单数据,然后更新新的订单数据了
1672
1775
  console.log('🔄 PaymentModal: data changed, updating checkout data...');
1673
1776
  isLocalOrderCreated.current = false;
1674
- _context17.next = 24;
1777
+ _context17.next = 25;
1675
1778
  return checkout.cancelCurrentOrderAsync();
1676
- case 24:
1677
- _context17.next = 26;
1779
+ case 25:
1780
+ _context17.next = 27;
1678
1781
  return checkout.createLocalOrderAsync({
1679
1782
  orderData: data === null || data === void 0 ? void 0 : data.order_info,
1680
1783
  cartSummary: data === null || data === void 0 || (_data$subtotal_info = data.subtotal_info) === null || _data$subtotal_info === void 0 ? void 0 : _data$subtotal_info.subTotalList,
1681
1784
  autoPayment: true,
1682
1785
  totalInfo: data === null || data === void 0 ? void 0 : data.subtotal_info
1683
1786
  });
1684
- case 26:
1787
+ case 27:
1685
1788
  // 获取订单总金额
1686
1789
  _orderInfo3 = checkout.getCurrentOrderInfo();
1687
1790
  if (_orderInfo3 && _orderInfo3.totalAmount) {
@@ -1689,11 +1792,11 @@ var PaymentModal = function PaymentModal(_ref17) {
1689
1792
  }
1690
1793
  setOrderInfo(_orderInfo3);
1691
1794
  isLocalOrderCreated.current = true;
1692
- case 30:
1693
- _context17.next = 36;
1795
+ case 31:
1796
+ _context17.next = 37;
1694
1797
  break;
1695
- case 32:
1696
- _context17.prev = 32;
1798
+ case 33:
1799
+ _context17.prev = 33;
1697
1800
  _context17.t0 = _context17["catch"](0);
1698
1801
  console.error('Failed to initialize checkout data:', _context17.t0);
1699
1802
  logger === null || logger === void 0 || logger.addLog({
@@ -1703,11 +1806,11 @@ var PaymentModal = function PaymentModal(_ref17) {
1703
1806
  error: _context17.t0
1704
1807
  }
1705
1808
  });
1706
- case 36:
1809
+ case 37:
1707
1810
  case "end":
1708
1811
  return _context17.stop();
1709
1812
  }
1710
- }, _callee17, null, [[0, 32]]);
1813
+ }, _callee17, null, [[0, 33]]);
1711
1814
  }));
1712
1815
  return function initCheckoutData() {
1713
1816
  return _ref22.apply(this, arguments);
@@ -1718,110 +1821,6 @@ var PaymentModal = function PaymentModal(_ref17) {
1718
1821
  }
1719
1822
  }, [data]);
1720
1823
  useEffect(function () {
1721
- var checkout = pisellos === null || pisellos === void 0 ? void 0 : pisellos.getModule('checkout');
1722
- // 监听订单同步完成,同步完成后显示订单完成 toast,关闭当前弹窗
1723
- unsubscribeRef.current = checkout.core.effects.on('checkout:onOrderSynced', function (data) {
1724
- var _data$response, _responseData$payment2;
1725
- // 获取支付状态和相关信息
1726
- var responseData = (_data$response = data.response) === null || _data$response === void 0 ? void 0 : _data$response.data;
1727
- // 获取支付状态
1728
- var paymentStatus = responseData === null || responseData === void 0 ? void 0 : responseData.payment_status;
1729
- if (data.isManual) return;
1730
- handlePaymentComplete(data);
1731
- // 如果正在显示现金支付 toast,跳过自动关闭逻辑
1732
- if (showingCashToastRef.current) {
1733
- return;
1734
- }
1735
-
1736
- // 获取订单总金额
1737
- var orderTotalAmount = Number((responseData === null || responseData === void 0 ? void 0 : responseData.total_amount) || 0);
1738
- var gapAmount = Number((responseData === null || responseData === void 0 ? void 0 : responseData.amount_gap) || 0);
1739
- var currentChangeGivenAmount = Number((responseData === null || responseData === void 0 || (_responseData$payment2 = responseData.payment_info) === null || _responseData$payment2 === void 0 ? void 0 : _responseData$payment2.current_change_given_amount) || 0);
1740
- // const changeDue = Number(responseData?.amount_gap || 0);
1741
- // 获取失败原因
1742
- var failureReason = responseData === null || responseData === void 0 ? void 0 : responseData.failure_reason;
1743
-
1744
- // 根据支付状态弹出对应的支付结果toast
1745
- if (paymentStatus) {
1746
- // 打印订单完整信息
1747
- console.log('print_order_onOrderSynced>>>>', responseData);
1748
- logger === null || logger === void 0 || logger.addLog({
1749
- type: 'info',
1750
- title: 'print_order_onOrderSynced',
1751
- metadata: {
1752
- responseData: responseData
1753
- }
1754
- });
1755
- try {
1756
- var _responseData$payment3;
1757
- var params = {
1758
- type: '99',
1759
- // 打印订单全部信息
1760
- data: {
1761
- order_id: responseData.order_id,
1762
- machine_code_print_info: responseData === null || responseData === void 0 ? void 0 : responseData.machine_code_print_info,
1763
- small_ticket_data: responseData === null || responseData === void 0 || (_responseData$payment3 = responseData.payment_info) === null || _responseData$payment3 === void 0 ? void 0 : _responseData$payment3.small_ticket_data
1764
- }
1765
- };
1766
- console.log('print_order_onOrderSynced_params>>>>', params);
1767
- logger === null || logger === void 0 || logger.addLog({
1768
- type: 'info',
1769
- title: 'print_order_onOrderSynced_params',
1770
- metadata: {
1771
- params: params
1772
- }
1773
- });
1774
- webPrint(params, function (res) {
1775
- console.log('print_order_onOrderSynced_res>>>>', res);
1776
- logger === null || logger === void 0 || logger.addLog({
1777
- type: 'info',
1778
- title: 'print_order_onOrderSynced_res',
1779
- metadata: {
1780
- res: res
1781
- }
1782
- });
1783
- });
1784
- } catch (error) {
1785
- console.error('print_order_onOrderSynced_error>>>>', error);
1786
- logger === null || logger === void 0 || logger.addLog({
1787
- type: 'info',
1788
- title: 'print_order_onOrderSynced_error',
1789
- metadata: {
1790
- error: error
1791
- }
1792
- });
1793
- }
1794
-
1795
- // 确定支付状态
1796
- var statusClassName = calculateStatusClassName(paymentStatus);
1797
- var autoCloseConfig = calculateAutoCloseConfig(paymentStatus, !!currentChangeGivenAmount);
1798
-
1799
- // 根据支付状态展示不同的 toast
1800
- displayPaymentResultToast({
1801
- paymentStatus: paymentStatus,
1802
- orderTotalAmount: orderTotalAmount,
1803
- gapAmount: paymentStatus === 'partially_paid' ? gapAmount : currentChangeGivenAmount,
1804
- failureReason: failureReason,
1805
- autoCloseConfig: autoCloseConfig,
1806
- actionButtons: generateActionButtons(paymentStatus)
1807
- }, paymentResultToastConfig);
1808
-
1809
- // 将支付结果信息传递给回调处理
1810
- var paymentResult = _objectSpread(_objectSpread({}, data), {}, {
1811
- toastInfo: {
1812
- status: paymentStatus,
1813
- amount: orderTotalAmount,
1814
- gapAmount: currentChangeGivenAmount,
1815
- failureReason: failureReason
1816
- }
1817
- });
1818
- handlePaymentComplete(paymentResult);
1819
- } else {
1820
- handlePaymentComplete(data);
1821
- }
1822
- // 可以在这里执行同步完成后的业务逻辑
1823
- // 比如:通知其他系统、更新UI状态等
1824
- });
1825
1824
  return function () {
1826
1825
  if (typeof unsubscribeRef.current === 'function') {
1827
1826
  var _unsubscribeRef$curre;
@@ -1239,6 +1239,101 @@ var PaymentModal = ({
1239
1239
  unsubscribeRef.current();
1240
1240
  unsubscribeRef.current = void 0;
1241
1241
  }
1242
+ unsubscribeRef.current = checkout.core.effects.on(
1243
+ "checkout:onOrderSynced",
1244
+ (data2) => {
1245
+ var _a3, _b3, _c2;
1246
+ const responseData = (_a3 = data2.response) == null ? void 0 : _a3.data;
1247
+ const paymentStatus = responseData == null ? void 0 : responseData.payment_status;
1248
+ if (data2.isManual) return;
1249
+ handlePaymentComplete(data2);
1250
+ if (showingCashToastRef.current) {
1251
+ return;
1252
+ }
1253
+ const orderTotalAmount = Number((responseData == null ? void 0 : responseData.total_amount) || 0);
1254
+ const gapAmount = Number((responseData == null ? void 0 : responseData.amount_gap) || 0);
1255
+ const currentChangeGivenAmount = Number(
1256
+ ((_b3 = responseData == null ? void 0 : responseData.payment_info) == null ? void 0 : _b3.current_change_given_amount) || 0
1257
+ );
1258
+ const failureReason = responseData == null ? void 0 : responseData.failure_reason;
1259
+ if (paymentStatus) {
1260
+ console.log("print_order_onOrderSynced>>>>", responseData);
1261
+ logger == null ? void 0 : logger.addLog({
1262
+ type: "info",
1263
+ title: "print_order_onOrderSynced",
1264
+ metadata: {
1265
+ responseData
1266
+ }
1267
+ });
1268
+ try {
1269
+ const params = {
1270
+ type: "99",
1271
+ // 打印订单全部信息
1272
+ data: {
1273
+ order_id: responseData.order_id,
1274
+ machine_code_print_info: responseData == null ? void 0 : responseData.machine_code_print_info,
1275
+ small_ticket_data: (_c2 = responseData == null ? void 0 : responseData.payment_info) == null ? void 0 : _c2.small_ticket_data
1276
+ }
1277
+ };
1278
+ console.log("print_order_onOrderSynced_params>>>>", params);
1279
+ logger == null ? void 0 : logger.addLog({
1280
+ type: "info",
1281
+ title: "print_order_onOrderSynced_params",
1282
+ metadata: {
1283
+ params
1284
+ }
1285
+ });
1286
+ (0, import_utils.webPrint)(params, (res) => {
1287
+ console.log("print_order_onOrderSynced_res>>>>", res);
1288
+ logger == null ? void 0 : logger.addLog({
1289
+ type: "info",
1290
+ title: "print_order_onOrderSynced_res",
1291
+ metadata: {
1292
+ res
1293
+ }
1294
+ });
1295
+ });
1296
+ } catch (error) {
1297
+ console.error("print_order_onOrderSynced_error>>>>", error);
1298
+ logger == null ? void 0 : logger.addLog({
1299
+ type: "info",
1300
+ title: "print_order_onOrderSynced_error",
1301
+ metadata: {
1302
+ error
1303
+ }
1304
+ });
1305
+ }
1306
+ const statusClassName = (0, import_PaymentResultToastUtils.calculateStatusClassName)(paymentStatus);
1307
+ const autoCloseConfig = (0, import_PaymentResultToastUtils.calculateAutoCloseConfig)(
1308
+ paymentStatus,
1309
+ !!currentChangeGivenAmount
1310
+ );
1311
+ (0, import_PaymentResultToastUtils.displayPaymentResultToast)(
1312
+ {
1313
+ paymentStatus,
1314
+ orderTotalAmount,
1315
+ gapAmount: paymentStatus === "partially_paid" ? gapAmount : currentChangeGivenAmount,
1316
+ failureReason,
1317
+ autoCloseConfig,
1318
+ actionButtons: generateActionButtons(paymentStatus)
1319
+ },
1320
+ paymentResultToastConfig
1321
+ );
1322
+ const paymentResult = {
1323
+ ...data2,
1324
+ toastInfo: {
1325
+ status: paymentStatus,
1326
+ amount: orderTotalAmount,
1327
+ gapAmount: currentChangeGivenAmount,
1328
+ failureReason
1329
+ }
1330
+ };
1331
+ handlePaymentComplete(paymentResult);
1332
+ } else {
1333
+ handlePaymentComplete(data2);
1334
+ }
1335
+ }
1336
+ );
1242
1337
  } else if (isLocalOrderCreated.current) {
1243
1338
  console.log(
1244
1339
  "🔄 PaymentModal: data changed, updating checkout data..."
@@ -1274,102 +1369,6 @@ var PaymentModal = ({
1274
1369
  }
1275
1370
  }, [data]);
1276
1371
  (0, import_react.useEffect)(() => {
1277
- const checkout = pisellos == null ? void 0 : pisellos.getModule("checkout");
1278
- unsubscribeRef.current = checkout.core.effects.on(
1279
- "checkout:onOrderSynced",
1280
- (data2) => {
1281
- var _a2, _b2, _c2;
1282
- const responseData = (_a2 = data2.response) == null ? void 0 : _a2.data;
1283
- const paymentStatus = responseData == null ? void 0 : responseData.payment_status;
1284
- if (data2.isManual) return;
1285
- handlePaymentComplete(data2);
1286
- if (showingCashToastRef.current) {
1287
- return;
1288
- }
1289
- const orderTotalAmount = Number((responseData == null ? void 0 : responseData.total_amount) || 0);
1290
- const gapAmount = Number((responseData == null ? void 0 : responseData.amount_gap) || 0);
1291
- const currentChangeGivenAmount = Number(
1292
- ((_b2 = responseData == null ? void 0 : responseData.payment_info) == null ? void 0 : _b2.current_change_given_amount) || 0
1293
- );
1294
- const failureReason = responseData == null ? void 0 : responseData.failure_reason;
1295
- if (paymentStatus) {
1296
- console.log("print_order_onOrderSynced>>>>", responseData);
1297
- logger == null ? void 0 : logger.addLog({
1298
- type: "info",
1299
- title: "print_order_onOrderSynced",
1300
- metadata: {
1301
- responseData
1302
- }
1303
- });
1304
- try {
1305
- const params = {
1306
- type: "99",
1307
- // 打印订单全部信息
1308
- data: {
1309
- order_id: responseData.order_id,
1310
- machine_code_print_info: responseData == null ? void 0 : responseData.machine_code_print_info,
1311
- small_ticket_data: (_c2 = responseData == null ? void 0 : responseData.payment_info) == null ? void 0 : _c2.small_ticket_data
1312
- }
1313
- };
1314
- console.log("print_order_onOrderSynced_params>>>>", params);
1315
- logger == null ? void 0 : logger.addLog({
1316
- type: "info",
1317
- title: "print_order_onOrderSynced_params",
1318
- metadata: {
1319
- params
1320
- }
1321
- });
1322
- (0, import_utils.webPrint)(params, (res) => {
1323
- console.log("print_order_onOrderSynced_res>>>>", res);
1324
- logger == null ? void 0 : logger.addLog({
1325
- type: "info",
1326
- title: "print_order_onOrderSynced_res",
1327
- metadata: {
1328
- res
1329
- }
1330
- });
1331
- });
1332
- } catch (error) {
1333
- console.error("print_order_onOrderSynced_error>>>>", error);
1334
- logger == null ? void 0 : logger.addLog({
1335
- type: "info",
1336
- title: "print_order_onOrderSynced_error",
1337
- metadata: {
1338
- error
1339
- }
1340
- });
1341
- }
1342
- const statusClassName = (0, import_PaymentResultToastUtils.calculateStatusClassName)(paymentStatus);
1343
- const autoCloseConfig = (0, import_PaymentResultToastUtils.calculateAutoCloseConfig)(
1344
- paymentStatus,
1345
- !!currentChangeGivenAmount
1346
- );
1347
- (0, import_PaymentResultToastUtils.displayPaymentResultToast)(
1348
- {
1349
- paymentStatus,
1350
- orderTotalAmount,
1351
- gapAmount: paymentStatus === "partially_paid" ? gapAmount : currentChangeGivenAmount,
1352
- failureReason,
1353
- autoCloseConfig,
1354
- actionButtons: generateActionButtons(paymentStatus)
1355
- },
1356
- paymentResultToastConfig
1357
- );
1358
- const paymentResult = {
1359
- ...data2,
1360
- toastInfo: {
1361
- status: paymentStatus,
1362
- amount: orderTotalAmount,
1363
- gapAmount: currentChangeGivenAmount,
1364
- failureReason
1365
- }
1366
- };
1367
- handlePaymentComplete(paymentResult);
1368
- } else {
1369
- handlePaymentComplete(data2);
1370
- }
1371
- }
1372
- );
1373
1372
  return () => {
1374
1373
  var _a2;
1375
1374
  if (typeof unsubscribeRef.current === "function") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.4.22",
3
+ "version": "6.4.23",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -59,10 +59,10 @@
59
59
  "react-infinite-scroll-component": "^6.1.0",
60
60
  "react-resizable": "^3.0.5",
61
61
  "styled-components": "^6.0.0-rc.3",
62
- "@pisell/materials": "6.4.3",
63
- "@pisell/utils": "3.0.2",
64
62
  "@pisell/date-picker": "3.0.7",
65
- "@pisell/icon": "0.0.11"
63
+ "@pisell/icon": "0.0.11",
64
+ "@pisell/materials": "6.4.3",
65
+ "@pisell/utils": "3.0.2"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "react": "^18.0.0",