import Dialog from "@mui/material/Dialog"; import DialogActions from "@mui/material/DialogActions"; import DialogContent from "@mui/material/DialogContent"; import DialogTitle from "@mui/material/DialogTitle"; import TextField from "@mui/material/TextField"; import { useState } from "react"; import { Button } from "@/shared/ui/Button.jsx"; import { formatNumber } from "../format.js"; export function LuckyGiftPoolAdjustmentDialog({ adjustmentId, direction, onClose, onSubmit, pool, submitting }) { const [amount, setAmount] = useState(""); const [reason, setReason] = useState(""); const [errors, setErrors] = useState({}); const debit = direction === "out"; const appCode = pool.app_code; const poolID = pool.pool_id; const strategyVersion = pool.strategy_version; const availableBalance = Number(pool.available_balance || 0); const title = debit ? "扣减奖池水位" : "添加奖池水位"; const submit = (event) => { event.preventDefault(); const nextErrors = validateAdjustment({ amount, availableBalance, debit, reason }); setErrors(nextErrors); if (Object.keys(nextErrors).length) { return; } // adjustmentId 在打开弹窗时创建,此处只原样透传。请求失败后组件不会卸载,因此用户修正或直接重试时 // 仍使用同一幂等键,网络超时场景不会把已成功的资金动作重复执行。 onSubmit({ adjustmentId, amountCoins: Number(amount), appCode, direction, poolId: poolID, reason: reason.trim(), strategyVersion, }); }; return (
{title}
{pool.materialized === false ? (
当前为默认水位,提交后将物化为独立策略奖池。
) : null} { setAmount(event.target.value); setErrors((current) => ({ ...current, amount: "" })); }} /> { setReason(event.target.value); setErrors((current) => ({ ...current, reason: "" })); }} />
); } function PoolMetric({ label, value }) { return (
{label} {value || "-"}
); } function validateAdjustment({ amount, availableBalance, debit, reason }) { const errors = {}; const rawAmount = String(amount || "").trim(); if (!/^[1-9]\d*$/.test(rawAmount) || !Number.isSafeInteger(Number(rawAmount))) { errors.amount = "请输入大于 0 的整数金币数量"; } else if (debit && Number(rawAmount) > availableBalance) { errors.amount = `扣减不能超过可用余额 ${formatNumber(availableBalance)}`; } if (!String(reason || "").trim()) { errors.reason = "请输入调整原因"; } return errors; }