更新採購單跟商品資料一些bug
This commit is contained in:
@@ -21,6 +21,13 @@ import {
|
||||
import { useForm } from "@inertiajs/react";
|
||||
import { toast } from "sonner";
|
||||
import type { Product, Category } from "@/Pages/Product/Index";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/Components/ui/dropdown-menu";
|
||||
import { ChevronDown } from "lucide-react";
|
||||
|
||||
interface ProductDialogProps {
|
||||
open: boolean;
|
||||
@@ -41,7 +48,7 @@ export default function ProductDialog({
|
||||
category_id: "",
|
||||
brand: "",
|
||||
specification: "",
|
||||
base_unit: "kg",
|
||||
base_unit: "公斤",
|
||||
large_unit: "",
|
||||
conversion_rate: "",
|
||||
purchase_unit: "",
|
||||
@@ -184,32 +191,34 @@ export default function ProductDialog({
|
||||
<Label htmlFor="base_unit">
|
||||
基本庫存單位 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={data.base_unit}
|
||||
onValueChange={(value) => setData("base_unit", value)}
|
||||
>
|
||||
<SelectTrigger id="base_unit" className={errors.base_unit ? "border-red-500" : ""}>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="kg">公斤 (kg)</SelectItem>
|
||||
<SelectItem value="g">公克 (g)</SelectItem>
|
||||
<SelectItem value="l">公升 (l)</SelectItem>
|
||||
<SelectItem value="ml">毫升 (ml)</SelectItem>
|
||||
<SelectItem value="個">個</SelectItem>
|
||||
<SelectItem value="支">支</SelectItem>
|
||||
<SelectItem value="包">包</SelectItem>
|
||||
<SelectItem value="罐">罐</SelectItem>
|
||||
<SelectItem value="瓶">瓶</SelectItem>
|
||||
<SelectItem value="箱">箱</SelectItem>
|
||||
<SelectItem value="袋">袋</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
id="base_unit"
|
||||
value={data.base_unit}
|
||||
onChange={(e) => setData("base_unit", e.target.value)}
|
||||
placeholder="可輸入或選擇..."
|
||||
className={errors.base_unit ? "border-red-500 flex-1" : "flex-1"}
|
||||
/>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="icon" className="shrink-0">
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{["公斤", "公克", "公升", "毫升", "個", "支", "包", "罐", "瓶", "箱", "袋"].map((u) => (
|
||||
<DropdownMenuItem key={u} onClick={() => setData("base_unit", u)}>
|
||||
{u}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
{errors.base_unit && <p className="text-sm text-red-500">{errors.base_unit}</p>}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="large_unit">大單位 (進貨單位)</Label>
|
||||
<Label htmlFor="large_unit">大單位</Label>
|
||||
<Input
|
||||
id="large_unit"
|
||||
value={data.large_unit}
|
||||
@@ -270,6 +279,6 @@ export default function ProductDialog({
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</Dialog >
|
||||
);
|
||||
}
|
||||
@@ -46,11 +46,12 @@ export function PurchaseOrderItemsTable({
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="bg-gray-50 hover:bg-gray-50">
|
||||
<TableHead className="w-[30%] text-left">商品名稱</TableHead>
|
||||
<TableHead className="w-[15%] text-left">數量</TableHead>
|
||||
<TableHead className="w-[10%] text-left">單位</TableHead>
|
||||
<TableHead className="w-[20%] text-left">預估單價</TableHead>
|
||||
<TableHead className="w-[20%] text-left">小計</TableHead>
|
||||
<TableHead className="w-[25%] text-left">商品名稱</TableHead>
|
||||
<TableHead className="w-[10%] text-left">數量</TableHead>
|
||||
<TableHead className="w-[10%] text-left">採購單位</TableHead>
|
||||
<TableHead className="w-[15%] text-left">換算基本單位</TableHead>
|
||||
<TableHead className="w-[15%] text-left">預估單價</TableHead>
|
||||
<TableHead className="w-[15%] text-left">小計</TableHead>
|
||||
{!isReadOnly && <TableHead className="w-[5%]"></TableHead>}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
@@ -58,7 +59,7 @@ export function PurchaseOrderItemsTable({
|
||||
{items.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={isReadOnly ? 5 : 6}
|
||||
colSpan={isReadOnly ? 6 : 7}
|
||||
className="text-center text-gray-400 py-12 italic"
|
||||
>
|
||||
{isDisabled ? "請先選擇供應商後才能新增商品" : "尚未新增任何商品項"}
|
||||
@@ -115,11 +116,20 @@ export function PurchaseOrderItemsTable({
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
{/* 單位 */}
|
||||
{/* 採購單位 */}
|
||||
<TableCell>
|
||||
<span className="text-gray-500 font-medium">{item.unit || "-"}</span>
|
||||
</TableCell>
|
||||
|
||||
{/* 換算基本單位 */}
|
||||
<TableCell>
|
||||
<span className="text-gray-500 font-medium">
|
||||
{item.conversion_rate && item.base_unit
|
||||
? `${parseFloat((item.quantity * item.conversion_rate).toFixed(2))} ${item.base_unit}`
|
||||
: "-"}
|
||||
</span>
|
||||
</TableCell>
|
||||
|
||||
{/* 單價 */}
|
||||
<TableCell className="text-left">
|
||||
{isReadOnly ? (
|
||||
@@ -135,12 +145,23 @@ export function PurchaseOrderItemsTable({
|
||||
onItemChange?.(index, "unitPrice", Number(e.target.value))
|
||||
}
|
||||
disabled={isDisabled}
|
||||
className={`h-10 text-left w-32 ${isPriceAlert(item.unitPrice, item.previousPrice)
|
||||
? "border-amber-400 bg-amber-50 focus-visible:ring-amber-500"
|
||||
: "border-gray-200"
|
||||
className={`h-10 text-left w-32 ${
|
||||
// 如果有數量但沒有單價,顯示錯誤樣式
|
||||
item.quantity > 0 && (!item.unitPrice || item.unitPrice <= 0)
|
||||
? "border-red-400 bg-red-50 focus-visible:ring-red-500"
|
||||
: isPriceAlert(item.unitPrice, item.previousPrice)
|
||||
? "border-amber-400 bg-amber-50 focus-visible:ring-amber-500"
|
||||
: "border-gray-200"
|
||||
}`}
|
||||
/>
|
||||
{isPriceAlert(item.unitPrice, item.previousPrice) && (
|
||||
{/* 錯誤提示:有數量但沒有單價 */}
|
||||
{item.quantity > 0 && (!item.unitPrice || item.unitPrice <= 0) && (
|
||||
<p className="text-[10px] text-red-600 font-medium">
|
||||
❌ 請填寫預估單價
|
||||
</p>
|
||||
)}
|
||||
{/* 價格警示:單價高於上次 */}
|
||||
{item.unitPrice > 0 && isPriceAlert(item.unitPrice, item.previousPrice) && (
|
||||
<p className="text-[10px] text-amber-600 font-medium animate-pulse">
|
||||
⚠️ 高於上次: {formatCurrency(item.previousPrice || 0)}
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user