@pisell/private-materials 6.11.178 → 6.11.180

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.
@@ -732,7 +732,6 @@ var PaymentContent = /*#__PURE__*/forwardRef(function (_ref, ref) {
732
732
  // const orderSyncFailedUnsubscribe = core.effects.on(
733
733
  // CheckoutHooks.OnOrderSyncFailed,
734
734
  // () => {
735
- // debugger
736
735
  // Toast?.fail(locales.getText('pisell2.checkout.order-sync-failed') || 'Order sync failed');
737
736
  // }
738
737
  // );
@@ -8,7 +8,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
8
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import React, { useState, useEffect } from 'react';
11
+ import React, { useState, useEffect, useMemo } from 'react';
12
12
  import useEngineContext from "../../../../hooks/useEngineContext";
13
13
  // @ts-ignore
14
14
  import { locales, formatAmount } from '@pisell/utils';
@@ -66,16 +66,16 @@ export function CashPaymentModule(_ref) {
66
66
  // 回退到全局语言包
67
67
  return locales.getText(key) || fallback;
68
68
  };
69
-
70
- // 检查是否应该禁用按钮:原本disabled为true 或者 订单金额为0
71
- var isAmountButtonsDisabled = disabled || Number(customAmount || 0) === 0;
72
-
73
- // 检查是否应该禁用输入框:原本disabled为true 或者 订单金额为0
74
- var isInputDisabled = disabled || Number(customAmount || 0) === 0;
75
- var getOrderBaseAmount = function getOrderBaseAmount() {
69
+ var orderBaseAmount = useMemo(function () {
76
70
  var baseAmount = parseFloat(orderInfo !== null && orderInfo !== void 0 && orderInfo.isDeposit ? balanceDueTotalAmount || '0' : balanceDueAmount || '0');
77
71
  return Number.isFinite(baseAmount) ? baseAmount : 0;
78
- };
72
+ }, [orderInfo === null || orderInfo === void 0 ? void 0 : orderInfo.isDeposit, balanceDueAmount, balanceDueTotalAmount]);
73
+
74
+ // 检查是否应该禁用按钮:原本disabled为true 或者 订单待付金额为0
75
+ var isAmountButtonsDisabled = disabled || orderBaseAmount <= 0;
76
+
77
+ // 检查是否应该禁用输入框:原本disabled为true 或者 订单待付金额为0
78
+ var isInputDisabled = disabled || orderBaseAmount <= 0;
79
79
  var shouldKeepOrderRounding = function shouldKeepOrderRounding(inputAmount, baseInfo) {
80
80
  var targetBaseInfo = baseInfo || roundingBaseInfo;
81
81
  if (Math.abs(targetBaseInfo.orderRoundingAmount) === 0) return false;
@@ -144,52 +144,61 @@ export function CashPaymentModule(_ref) {
144
144
  var isCancelled = false;
145
145
  var syncRoundingBaseInfo = /*#__PURE__*/function () {
146
146
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
147
- var orderBaseAmount, roundedBaseAmount, orderRoundingAmount, _result$roundedAmount, _result$roundingDiffe, _result, nextBaseInfo;
147
+ var roundedBaseAmount, orderRoundingAmount, _result$roundedAmount, _result$roundingDiffe, _result, nextBaseInfo, nextInputAmount;
148
148
  return _regeneratorRuntime().wrap(function _callee$(_context) {
149
149
  while (1) switch (_context.prev = _context.next) {
150
150
  case 0:
151
- orderBaseAmount = getOrderBaseAmount();
152
151
  roundedBaseAmount = orderBaseAmount;
153
152
  orderRoundingAmount = 0;
154
153
  if (!(roundingFunction && orderBaseAmount > 0)) {
155
- _context.next = 9;
154
+ _context.next = 16;
156
155
  break;
157
156
  }
157
+ _context.prev = 3;
158
158
  _context.next = 6;
159
159
  return roundingFunction(orderBaseAmount);
160
160
  case 6:
161
161
  _result = _context.sent;
162
162
  roundedBaseAmount = (_result$roundedAmount = _result === null || _result === void 0 ? void 0 : _result.roundedAmount) !== null && _result$roundedAmount !== void 0 ? _result$roundedAmount : orderBaseAmount;
163
163
  orderRoundingAmount = (_result$roundingDiffe = _result === null || _result === void 0 ? void 0 : _result.roundingDifference) !== null && _result$roundingDiffe !== void 0 ? _result$roundingDiffe : 0;
164
- case 9:
164
+ _context.next = 16;
165
+ break;
166
+ case 11:
167
+ _context.prev = 11;
168
+ _context.t0 = _context["catch"](3);
169
+ console.warn('Failed to calculate cash rounding amount:', _context.t0);
170
+ roundedBaseAmount = orderBaseAmount;
171
+ orderRoundingAmount = 0;
172
+ case 16:
165
173
  nextBaseInfo = {
166
174
  orderBaseAmount: orderBaseAmount,
167
175
  roundedBaseAmount: roundedBaseAmount,
168
176
  orderRoundingAmount: orderRoundingAmount
169
177
  };
170
178
  if (!isCancelled) {
171
- _context.next = 12;
179
+ _context.next = 19;
172
180
  break;
173
181
  }
174
182
  return _context.abrupt("return");
175
- case 12:
183
+ case 19:
176
184
  setRoundingBaseInfo(nextBaseInfo);
177
185
  if (!isInputDisabled) {
178
- _context.next = 17;
186
+ _context.next = 24;
179
187
  break;
180
188
  }
181
189
  setAmount('0.00');
182
190
  setRoundingAmount(0);
183
191
  return _context.abrupt("return");
184
- case 17:
185
- applyInputAmount(customAmount || '', {
192
+ case 24:
193
+ nextInputAmount = Number(customAmount || 0) > 0 ? customAmount !== null && customAmount !== void 0 ? customAmount : '' : String(nextBaseInfo.roundedBaseAmount || nextBaseInfo.orderBaseAmount || '');
194
+ applyInputAmount(nextInputAmount, {
186
195
  baseInfo: nextBaseInfo
187
196
  });
188
- case 18:
197
+ case 26:
189
198
  case "end":
190
199
  return _context.stop();
191
200
  }
192
- }, _callee);
201
+ }, _callee, null, [[3, 11]]);
193
202
  }));
194
203
  return function syncRoundingBaseInfo() {
195
204
  return _ref3.apply(this, arguments);
@@ -199,7 +208,7 @@ export function CashPaymentModule(_ref) {
199
208
  return function () {
200
209
  isCancelled = true;
201
210
  };
202
- }, [customAmount, balanceDueAmount, balanceDueTotalAmount, orderInfo === null || orderInfo === void 0 ? void 0 : orderInfo.isDeposit, roundingFunction, isInputDisabled]);
211
+ }, [customAmount, balanceDueAmount, balanceDueTotalAmount, orderInfo === null || orderInfo === void 0 ? void 0 : orderInfo.isDeposit, roundingFunction, isInputDisabled, orderBaseAmount]);
203
212
  var handleAmountClick = function handleAmountClick(clickedAmount) {
204
213
  if (isAmountButtonsDisabled) return;
205
214
  var amountStr = clickedAmount.toString();
@@ -154,6 +154,7 @@ function buildServiceItemFromRuleProduct(product, resource) {
154
154
  return _objectSpread(_objectSpread({}, product), {}, {
155
155
  _id: "pre_".concat((_product$id = product === null || product === void 0 ? void 0 : product.id) !== null && _product$id !== void 0 ? _product$id : 'unknown', "_").concat(Date.now()),
156
156
  id: product === null || product === void 0 ? void 0 : product.id,
157
+ product_id: product === null || product === void 0 ? void 0 : product.id,
157
158
  title: title,
158
159
  quantity: 1,
159
160
  price: price,
@@ -78,14 +78,14 @@ function CashPaymentModule({
78
78
  }
79
79
  return import_utils.locales.getText(key) || fallback;
80
80
  };
81
- const isAmountButtonsDisabled = disabled || Number(customAmount || 0) === 0;
82
- const isInputDisabled = disabled || Number(customAmount || 0) === 0;
83
- const getOrderBaseAmount = () => {
81
+ const orderBaseAmount = (0, import_react.useMemo)(() => {
84
82
  const baseAmount = parseFloat(
85
83
  (orderInfo == null ? void 0 : orderInfo.isDeposit) ? balanceDueTotalAmount || "0" : balanceDueAmount || "0"
86
84
  );
87
85
  return Number.isFinite(baseAmount) ? baseAmount : 0;
88
- };
86
+ }, [orderInfo == null ? void 0 : orderInfo.isDeposit, balanceDueAmount, balanceDueTotalAmount]);
87
+ const isAmountButtonsDisabled = disabled || orderBaseAmount <= 0;
88
+ const isInputDisabled = disabled || orderBaseAmount <= 0;
89
89
  const shouldKeepOrderRounding = (inputAmount, baseInfo) => {
90
90
  const targetBaseInfo = baseInfo || roundingBaseInfo;
91
91
  if (Math.abs(targetBaseInfo.orderRoundingAmount) === 0) return false;
@@ -155,13 +155,18 @@ function CashPaymentModule({
155
155
  (0, import_react.useEffect)(() => {
156
156
  let isCancelled = false;
157
157
  const syncRoundingBaseInfo = async () => {
158
- const orderBaseAmount = getOrderBaseAmount();
159
158
  let roundedBaseAmount = orderBaseAmount;
160
159
  let orderRoundingAmount = 0;
161
160
  if (roundingFunction && orderBaseAmount > 0) {
162
- const result = await roundingFunction(orderBaseAmount);
163
- roundedBaseAmount = (result == null ? void 0 : result.roundedAmount) ?? orderBaseAmount;
164
- orderRoundingAmount = (result == null ? void 0 : result.roundingDifference) ?? 0;
161
+ try {
162
+ const result = await roundingFunction(orderBaseAmount);
163
+ roundedBaseAmount = (result == null ? void 0 : result.roundedAmount) ?? orderBaseAmount;
164
+ orderRoundingAmount = (result == null ? void 0 : result.roundingDifference) ?? 0;
165
+ } catch (error) {
166
+ console.warn("Failed to calculate cash rounding amount:", error);
167
+ roundedBaseAmount = orderBaseAmount;
168
+ orderRoundingAmount = 0;
169
+ }
165
170
  }
166
171
  const nextBaseInfo = {
167
172
  orderBaseAmount,
@@ -175,7 +180,8 @@ function CashPaymentModule({
175
180
  setRoundingAmount(0);
176
181
  return;
177
182
  }
178
- applyInputAmount(customAmount || "", { baseInfo: nextBaseInfo });
183
+ const nextInputAmount = Number(customAmount || 0) > 0 ? customAmount ?? "" : String(nextBaseInfo.roundedBaseAmount || nextBaseInfo.orderBaseAmount || "");
184
+ applyInputAmount(nextInputAmount, { baseInfo: nextBaseInfo });
179
185
  };
180
186
  syncRoundingBaseInfo();
181
187
  return () => {
@@ -187,7 +193,8 @@ function CashPaymentModule({
187
193
  balanceDueTotalAmount,
188
194
  orderInfo == null ? void 0 : orderInfo.isDeposit,
189
195
  roundingFunction,
190
- isInputDisabled
196
+ isInputDisabled,
197
+ orderBaseAmount
191
198
  ]);
192
199
  const handleAmountClick = (clickedAmount) => {
193
200
  if (isAmountButtonsDisabled) return;
@@ -164,6 +164,7 @@ function buildServiceItemFromRuleProduct(product, resource) {
164
164
  ...product,
165
165
  _id: `pre_${(product == null ? void 0 : product.id) ?? "unknown"}_${Date.now()}`,
166
166
  id: product == null ? void 0 : product.id,
167
+ product_id: product == null ? void 0 : product.id,
167
168
  title,
168
169
  quantity: 1,
169
170
  price,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.11.178",
3
+ "version": "6.11.180",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -69,8 +69,8 @@
69
69
  "styled-components": "^6.0.0-rc.3",
70
70
  "@pisell/utils": "3.0.2",
71
71
  "@pisell/materials": "6.11.57",
72
- "@pisell/date-picker": "3.0.8",
73
- "@pisell/icon": "0.0.11"
72
+ "@pisell/icon": "0.0.11",
73
+ "@pisell/date-picker": "3.0.8"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "react": "^18.0.0",
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { type TicketBookingSecondaryDisplayConfig } from './useTicketBookingSecondaryScreen';
3
- import './index.less';
4
- import { ProductDisplayConfig, ProductDisplayPresetKey } from '../ProductDisplayAdapter/types';
5
- import { BaseResponsiveProps } from '../../../../responsive/type';
6
- export declare const _formatBookingDetail: (data: any, modalState: any) => any;
7
- interface TicketBookingProps {
8
- onPrerenderComplete?: () => void;
9
- productDisplayConfig?: ProductDisplayPresetKey | ProductDisplayConfig;
10
- isShowTimeBar?: boolean;
11
- isShowFloatButtons?: boolean;
12
- /** 副屏展示:购物车列数、是否显示客户信息等 */
13
- secondaryScreenDisplay?: TicketBookingSecondaryDisplayConfig;
14
- }
15
- declare const _default: React.ForwardRefExoticComponent<TicketBookingProps & BaseResponsiveProps & React.RefAttributes<unknown>>;
16
- export default _default;
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { type TicketBookingSecondaryDisplayConfig } from './useTicketBookingSecondaryScreen';
3
- import './index.less';
4
- import { ProductDisplayConfig, ProductDisplayPresetKey } from '../ProductDisplayAdapter/types';
5
- import { BaseResponsiveProps } from '../../../../responsive/type';
6
- export declare const _formatBookingDetail: (data: any, modalState: any) => any;
7
- interface TicketBookingProps {
8
- onPrerenderComplete?: () => void;
9
- productDisplayConfig?: ProductDisplayPresetKey | ProductDisplayConfig;
10
- isShowTimeBar?: boolean;
11
- isShowFloatButtons?: boolean;
12
- /** 副屏展示:购物车列数、是否显示客户信息等 */
13
- secondaryScreenDisplay?: TicketBookingSecondaryDisplayConfig;
14
- }
15
- declare const _default: React.ForwardRefExoticComponent<TicketBookingProps & BaseResponsiveProps & React.RefAttributes<unknown>>;
16
- export default _default;