1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
"use client"
import * as React from "react"
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { Package, FileText, X } from "lucide-react"
import { getTechSalesRfqItems } from "../service"
interface RfqItem {
id: number;
rfqId: number;
itemType: "SHIP" | "TOP" | "HULL";
itemCode: string;
itemList: string;
workType: string;
shipType?: string; // 조선용
subItemName?: string; // 해양용
}
interface RfqItemsViewDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
rfq: {
id: number;
rfqCode?: string;
status?: string;
description?: string;
rfqType?: "SHIP" | "TOP" | "HULL";
} | null;
}
export function RfqItemsViewDialog({
open,
onOpenChange,
rfq,
}: RfqItemsViewDialogProps) {
const [items, setItems] = React.useState<RfqItem[]>([]);
const [loading, setLoading] = React.useState(false);
console.log("RfqItemsViewDialog render:", { open, rfq });
React.useEffect(() => {
console.log("RfqItemsViewDialog useEffect:", { open, rfqId: rfq?.id });
if (open && rfq?.id) {
loadItems();
}
}, [open, rfq?.id]);
const loadItems = async () => {
if (!rfq?.id) return;
console.log("Loading items for RFQ:", rfq.id);
setLoading(true);
try {
const result = await getTechSalesRfqItems(rfq.id);
console.log("Items loaded:", result);
if (result.data) {
setItems(result.data);
}
} catch (error) {
console.error("Failed to load items:", error);
} finally {
setLoading(false);
}
};
const getTypeLabel = (type: string) => {
switch (type) {
case "SHIP":
return "조선";
case "TOP":
return "해양TOP";
case "HULL":
return "해양HULL";
default:
return type;
}
};
const getTypeColor = (type: string) => {
switch (type) {
case "SHIP":
return "bg-blue-100 text-blue-800";
case "TOP":
return "bg-green-100 text-green-800";
case "HULL":
return "bg-purple-100 text-purple-800";
default:
return "bg-gray-100 text-gray-800";
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-none w-[1200px]">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
RFQ 아이템 조회
<Badge variant="outline" className="ml-2">
{rfq?.rfqCode || `RFQ #${rfq?.id}`}
</Badge>
</DialogTitle>
<DialogDescription>
RFQ에 등록된 아이템 목록을 확인할 수 있습니다.
</DialogDescription>
</DialogHeader>
<div className="overflow-x-auto w-full">
<div className="space-y-4">
{loading ? (
<div className="flex items-center justify-center py-8">
<div className="text-center space-y-2">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"></div>
<p className="text-sm text-muted-foreground">아이템을 불러오는 중...</p>
</div>
</div>
) : items.length === 0 ? (
<div className="flex flex-col items-center justify-center py-12 text-center">
<FileText className="h-12 w-12 text-muted-foreground mb-3" />
<h3 className="text-lg font-medium mb-1">아이템이 없습니다</h3>
<p className="text-sm text-muted-foreground">
이 RFQ에 등록된 아이템이 없습니다.
</p>
</div>
) : (
<>
{/* 헤더 행 (라벨) */}
<div className="flex items-center gap-2 border-b pb-2 font-medium text-sm">
<div className="w-[50px] text-center">No.</div>
<div className="w-[120px] pl-2">타입</div>
<div className="w-[200px] ">자재 그룹</div>
<div className="w-[150px] ">공종</div>
<div className="w-[300px] ">자재명</div>
<div className="w-[150px] ">선종/자재명(상세)</div>
</div>
{/* 아이템 행들 */}
<div className="max-h-[50vh] overflow-y-auto pr-1 space-y-2">
{items.map((item, index) => (
<div
key={item.id}
className="flex items-center gap-2 group hover:bg-gray-50 p-2 rounded-md transition-colors border"
>
<div className="w-[50px] text-center text-sm font-medium text-muted-foreground">
{index + 1}
</div>
<div className="w-[120px] pl-2">
<Badge variant="secondary" className={`text-xs ${getTypeColor(item.itemType)}`}>
{getTypeLabel(item.itemType)}
</Badge>
</div>
<div className="w-[200px] pl-2 font-mono text-sm">
{item.itemCode}
</div>
<div className="w-[150px] pl-2 text-sm">
{item.workType}
</div>
<div className="w-[300px] pl-2 font-medium">
{item.itemList}
</div>
<div className="w-[150px] pl-2 text-sm">
{item.itemType === 'SHIP' ? item.shipType : item.subItemName}
</div>
</div>
))}
</div>
<div className="flex justify-between items-center pt-2 border-t">
<div className="flex items-center gap-2">
<Package className="h-4 w-4 text-muted-foreground" />
<span className="text-sm text-muted-foreground">
총 {items.length}개 아이템
</span>
</div>
</div>
</>
)}
</div>
</div>
<DialogFooter className="mt-6">
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
<X className="mr-2 h-4 w-4" />
닫기
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
|