'use client'; import { useState, useEffect } from 'react'; import { X, Loader2, Save, ArrowRight } from 'lucide-react'; import { toast } from 'react-hot-toast'; import { orderService } from '@/lib/services'; import { OrderDetail } from '@/types'; interface OrderPriceAdjustModalProps { isOpen: boolean; onClose: () => void; order: OrderDetail | null; onSuccess: () => void; } export default function OrderPriceAdjustModal({ isOpen, onClose, order, onSuccess, }: OrderPriceAdjustModalProps) { const [loading, setLoading] = useState(false); const [formData, setFormData] = useState({ adjustment_delta: '', reason: '管理员手动调价', }); useEffect(() => { if (isOpen) { setFormData({ adjustment_delta: '', reason: '管理员手动调价', }); } }, [isOpen, order]); if (!isOpen || !order) return null; const baseAmount = order ? (order.base_amount ?? order.total_amount ?? order.amount ?? 0) : 0; const currency = order.base_currency || 'CNY'; const symbol = currency === 'CNY' ? '¥' : currency === 'USD' ? '$' : `${currency} `; const deltaValue = parseFloat(formData.adjustment_delta) || 0; const deltaCents = Math.round(deltaValue * 100); const estimatedFinalAmount = Math.max(0, baseAmount + deltaCents); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!order?.id) return; if (isNaN(deltaValue)) { toast.error('请输入有效的金额'); return; } if (deltaValue === 0) { toast.error('调整金额不能为 0'); return; } setLoading(true); try { await orderService.adjustPrice(order.id, { adjustment_delta: deltaCents, reason: formData.reason, }); toast.success('价格调整成功'); onSuccess(); onClose(); } catch (error: any) { toast.error('调整失败: ' + (error.response?.data?.message || '未知错误')); } finally { setLoading(false); } }; return (