"use client" import { useState, useEffect } from "react" import { X, Settings, CheckCircle, AlertCircle, Zap } from "lucide-react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Switch } from "@/components/ui/switch" import { useStore } from "@/lib/store" interface AutoWithdrawModalProps { isOpen: boolean onClose: () => void } interface AutoWithdrawConfig { enabled: boolean minAmount: number method: 'wechat' | 'alipay' account: string name: string } export function AutoWithdrawModal({ isOpen, onClose }: AutoWithdrawModalProps) { const { user } = useStore() const [config, setConfig] = useState({ enabled: false, minAmount: 100, method: 'wechat', account: '', name: '', }) const [isLoading, setIsLoading] = useState(false) const [isSuccess, setIsSuccess] = useState(false) const [error, setError] = useState(null) // 加载已保存的配置 useEffect(() => { if (isOpen && user?.id) { const savedConfig = localStorage.getItem(`auto_withdraw_config_${user.id}`) if (savedConfig) { try { setConfig(JSON.parse(savedConfig)) } catch { // 忽略解析错误 } } } }, [isOpen, user?.id]) if (!isOpen) return null const handleSave = async () => { if (!user?.id) return // 验证 if (config.enabled) { if (config.minAmount < 10) { setError('最低提现金额不能少于10元') return } if (!config.account) { setError('请填写提现账号') return } if (!config.name) { setError('请填写真实姓名') return } } setIsLoading(true) setError(null) try { // 保存配置到本地存储 localStorage.setItem(`auto_withdraw_config_${user.id}`, JSON.stringify(config)) // 如果启用了自动提现,也发送到服务器 if (config.enabled) { await fetch('/api/distribution/auto-withdraw-config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ userId: user.id, ...config, }), }) } setIsSuccess(true) } catch (err) { setError('保存失败,请重试') console.error('保存自动提现配置失败:', err) } finally { setIsLoading(false) } } const handleClose = () => { setIsSuccess(false) setError(null) onClose() } return (
{/* 遮罩 */}
{/* 弹窗内容 */}
{/* 关闭按钮 */} {isSuccess ? ( /* 成功状态 */

设置保存成功

{config.enabled ? `当可提现金额达到 ¥${config.minAmount} 时,将自动打款到您的${config.method === 'wechat' ? '微信' : '支付宝'}账户` : '自动提现已关闭' }

) : ( /* 设置表单 */
{/* 标题 */}

自动提现设置

达到金额自动打款到账户

{/* 错误提示 */} {error && (
{error}
)}
{/* 启用开关 */}
启用自动提现
setConfig({ ...config, enabled: checked })} />
{config.enabled && ( <> {/* 最低金额 */}
¥ setConfig({ ...config, minAmount: Number(e.target.value) })} className="pl-8 bg-white/5 border-white/10 text-white h-12" placeholder="100" />

最低提现金额为10元

{/* 提现方式 */}
{/* 收款账号 */}
setConfig({ ...config, account: e.target.value })} className="bg-white/5 border-white/10 text-white h-12" placeholder={config.method === 'wechat' ? '请输入微信openid' : '请输入支付宝账号'} /> {config.method === 'wechat' && (

需要用户授权获取的openid,而非微信号

)}
{/* 真实姓名 */}
setConfig({ ...config, name: e.target.value })} className="bg-white/5 border-white/10 text-white h-12" placeholder="请输入收款人真实姓名" />

必须与收款账户实名一致

)}
{/* 保存按钮 */} {/* 提示 */}

💡 提示:启用自动提现后,当您的可提现金额达到设定值时,系统将自动发起打款。 微信打款需要用户openid(通过公众号授权获取),支付宝打款需要实名认证的账号。

)}
) }