lty/qy-lty-admin/components/food/add-print-batch-dialog.tsx
2026-03-17 13:17:02 +08:00

153 lines
5.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Checkbox } from "@/components/ui/checkbox"
import { Plus, Loader2 } from "lucide-react"
interface AddPrintBatchDialogProps {
foodId: string
isPublished: boolean
}
export function AddPrintBatchDialog({ foodId, isPublished }: AddPrintBatchDialogProps) {
const [open, setOpen] = useState(false)
const [quantity, setQuantity] = useState(1000)
const [batchName, setBatchName] = useState("")
const [printMethod, setPrintMethod] = useState("standard")
const [autoActivate, setAutoActivate] = useState(false)
const [isSubmitting, setIsSubmitting] = useState(false)
const handleSubmit = async () => {
setIsSubmitting(true)
// 模拟API请求
await new Promise((resolve) => setTimeout(resolve, 1500))
setIsSubmitting(false)
setOpen(false)
}
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button className="bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600 transition-all duration-300 shadow-md hover:shadow-lg">
<Plus className="mr-2 h-4 w-4" />
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
<DialogTitle className="text-xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-purple-600 to-pink-600">
</DialogTitle>
<DialogDescription>
<span className="font-medium">{foodId}</span> ID
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="space-y-2">
<Label htmlFor="batchName"></Label>
<Input
id="batchName"
placeholder="例如2024年春季批次"
value={batchName}
onChange={(e) => setBatchName(e.target.value)}
className="border-gray-300 focus-visible:ring-purple-500"
/>
</div>
<div className="space-y-2">
<Label htmlFor="printMethod"></Label>
<Select value={printMethod} onValueChange={setPrintMethod}>
<SelectTrigger id="printMethod">
<SelectValue placeholder="选择印刷方式" />
</SelectTrigger>
<SelectContent>
<SelectItem value="standard"></SelectItem>
<SelectItem value="premium"></SelectItem>
<SelectItem value="limited"></SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="quantity"></Label>
<Input
id="quantity"
type="number"
min="1"
value={quantity}
onChange={(e) => setQuantity(Number.parseInt(e.target.value))}
className="border-gray-300 focus-visible:ring-purple-500"
/>
<p className="text-sm text-gray-500"> {quantity} ID</p>
</div>
<div className="flex items-center space-x-2 pt-2">
<Checkbox
id="autoActivate"
checked={autoActivate}
onCheckedChange={(checked) => setAutoActivate(!!checked)}
/>
<Label htmlFor="autoActivate" className="text-sm font-normal cursor-pointer">
</Label>
</div>
<div className="space-y-2">
<Label className="text-right"></Label>
<div className="p-3 bg-gray-50 rounded-md">
<p className="text-sm text-gray-700">
ID:{" "}
<span className="font-mono">
B
{Math.floor(Math.random() * 1000)
.toString()
.padStart(3, "0")}
</span>
</p>
<p className="text-sm text-gray-700">
ID: <span className="font-mono">{foodId}-XXXX</span>
</p>
<p className="text-sm text-gray-700">
ID: <span className="font-mono">{foodId}-YYYY</span>
</p>
</div>
<p className="text-xs text-gray-500">ID将在创建批次时生成</p>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setOpen(false)} disabled={isSubmitting}>
</Button>
<Button
className="bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600"
onClick={handleSubmit}
disabled={isSubmitting}
>
{isSubmitting ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
...
</>
) : (
"创建批次"
)}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}