import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription } from "@/Components/ui/dialog"; import { Button } from "@/Components/ui/button"; import { Input } from "@/Components/ui/input"; import { Label } from "@/Components/ui/label"; import { Upload, Download, FileSpreadsheet, AlertCircle, Info } from "lucide-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/Components/ui/accordion"; import { useForm } from "@inertiajs/react"; import { Alert, AlertDescription } from "@/Components/ui/alert"; interface ProductImportDialogProps { open: boolean; onOpenChange: (open: boolean) => void; } export default function ProductImportDialog({ open, onOpenChange }: ProductImportDialogProps) { const { data, setData, post, processing, errors, reset, clearErrors } = useForm<{ file: File | null; }>({ file: null, }); const handleFileChange = (e: React.ChangeEvent) => { if (e.target.files && e.target.files[0]) { setData("file", e.target.files[0]); clearErrors("file"); } }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); post(route("products.import"), { onSuccess: () => { reset(); onOpenChange(false); }, }); }; const handleDownloadTemplate = () => { window.location.href = route('products.template'); }; return ( 匯入商品資料 請先下載範本,填寫後上傳。系統將自動建立商品資料。
{/* 步驟 1: 下載範本 */}
下載標準範本以確保資料格式正確。請勿修改欄位名稱。
{/* 步驟 2: 上傳檔案 */}
{errors.file && ( {errors.file} )}
{/* 欄位說明 */}
欄位填寫規則
  • 必填欄位:商品代號 (2-8 碼)、條碼、商品名稱、類別名稱、基本單位。
  • 唯一性:商品代號與條碼不可與現有資料重複。
  • 自動關聯:類別與單位請填寫系統當前存在的「名稱」(如:飲品、瓶)。
  • 大單位:若填寫大單位,則「換算率」為必填(需大於 0)。
); }