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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
|
'use client'
import * as React from 'react'
import { createColumnHelper } from '@tanstack/react-table'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import {
CheckCircle,
XCircle,
FileText,
MoreHorizontal,
Calendar,
User,
Paperclip,
AlertTriangle
} from 'lucide-react'
import { format } from 'date-fns'
import { biddingStatusLabels, contractTypeLabels } from '@/db/schema'
import { PartnersBiddingListItem } from '../detail/service'
import { Checkbox } from '@/components/ui/checkbox'
import { toast } from 'sonner'
const columnHelper = createColumnHelper<PartnersBiddingListItem>()
interface PartnersBiddingListColumnsProps {
setRowAction?: (action: { type: string; row: { original: PartnersBiddingListItem } }) => void
}
export function getPartnersBiddingListColumns({ setRowAction }: PartnersBiddingListColumnsProps = {}) {
return [
// select 버튼
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={table.getIsAllPageRowsSelected() || (table.getIsSomePageRowsSelected() && "indeterminate")}
onCheckedChange={(v) => table.toggleAllPageRowsSelected(!!v)}
aria-label="select all"
className="translate-y-0.5"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(v) => row.toggleSelected(!!v)}
aria-label="select row"
className="translate-y-0.5"
/>
),
size: 40,
enableSorting: false,
enableHiding: false,
},
// 입찰 No.
columnHelper.accessor('biddingNumber', {
header: '입찰 No.',
cell: ({ row }) => {
const biddingNumber = row.original.biddingNumber
const originalBiddingNumber = row.original.originalBiddingNumber
const revision = row.original.revision
return (
<div className="font-mono text-sm">
<div>{biddingNumber}</div>
{/* <div className="text-muted-foreground text-xs">Rev. {revision ?? 0}</div> */}
{originalBiddingNumber && (
<div className="text-xs text-muted-foreground">원: {originalBiddingNumber}</div>
)}
</div>
)
},
}),
// 입찰상태
columnHelper.accessor('status', {
header: '입찰상태',
cell: ({ row }) => {
const status = row.original.status
return (
<Badge variant={
status === 'bidding_disposal' ? 'destructive' :
status === 'vendor_selected' ? 'default' :
status === 'bidding_generated' ? 'secondary' :
'outline'
}>
{biddingStatusLabels[status] || status}
</Badge>
)
},
}),
// 긴급여부
columnHelper.accessor('isUrgent', {
header: '긴급여부',
cell: ({ row }) => {
const isUrgent = row.original.isUrgent
return isUrgent ? (
<div className="flex items-center gap-1">
<AlertTriangle className="h-4 w-4 text-red-600" />
<Badge variant="destructive" className="text-xs">
긴급
</Badge>
</div>
) : (
<div className="flex items-center gap-1">
<CheckCircle className="h-4 w-4 text-green-600" />
<span className="text-xs text-muted-foreground">일반</span>
</div>
)
},
}),
// 첨부파일
columnHelper.display({
id: 'attachments',
header: '첨부파일',
cell: ({ row }) => {
const handleViewDocumentsClick = (e: React.MouseEvent) => {
e.stopPropagation()
if (setRowAction) {
setRowAction({
type: 'view-documents',
row: { original: row.original }
})
}
}
return (
<Button
variant="ghost"
size="sm"
className="p-1 h-8 w-8"
onClick={handleViewDocumentsClick}
title="첨부파일 보기"
>
<Paperclip className="h-4 w-4 text-blue-600" />
</Button>
)
},
size: 80,
enableSorting: false,
}),
// 액션 (드롭다운 메뉴)
columnHelper.display({
id: 'actions',
header: '액션',
cell: ({ row }) => {
// 사양설명회 참석여부 체크 함수
const checkSpecificationMeeting = () => {
const hasSpecMeeting = row.original.hasSpecificationMeeting
const isAttending = row.original.isAttendingMeeting
// 사양설명회가 있고, 참석여부가 아직 설정되지 않은 경우
if (hasSpecMeeting && isAttending === null) {
toast.warning('사양설명회 참석여부 필요', {
description: '사전견적 또는 입찰을 진행하기 전에 사양설명회 참석여부를 먼저 설정해주세요.',
duration: 5000,
})
return false
}
return true
}
const handleView = () => {
// 입찰기간 체크 (현 시간 기준으로 입찰기간 시작 전이면 접근 불가)
const now = new Date()
const startDate = row.original.submissionStartDate ? new Date(row.original.submissionStartDate).toISOString().slice(0, 16) : null
const endDate = row.original.submissionEndDate ? new Date(row.original.submissionEndDate).toISOString().slice(0, 16) : null
console.log(startDate, endDate, "startDate, endDate")
if (startDate && now < startDate) {
toast.warning('입찰기간 전 접근 제한', {
description: `입찰기간이 아직 시작되지 않았습니다`,
duration: 5000,
})
return
}
// 사양설명회 체크
if (!checkSpecificationMeeting()) {
return
}
if (setRowAction) {
setRowAction({
type: 'view',
row: { original: row.original }
})
}
}
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
className="flex h-8 w-8 p-0 data-[state=open]:bg-muted"
>
<MoreHorizontal className="h-4 w-4" />
<span className="sr-only">메뉴 열기</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-[160px]">
<DropdownMenuItem onClick={handleView}>
<FileText className="mr-2 h-4 w-4" />
입찰 상세보기
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
},
}),
// // 품목명
// columnHelper.accessor('itemName', {
// header: '품목명',
// cell: ({ row }) => (
// <div className="max-w-32 truncate" title={row.original.itemName}>
// {row.original.itemName}
// </div>
// ),
// }),
// 입찰명
columnHelper.accessor('title', {
header: '입찰명',
cell: ({ row }) => {
const handleTitleClick = (e: React.MouseEvent) => {
e.stopPropagation()
// 사양설명회 참석여부 체크
const hasSpecMeeting = row.original.hasSpecificationMeeting
const isAttending = row.original.isAttendingMeeting
// 사양설명회가 있고, 참석여부가 아직 설정되지 않은 경우
if (hasSpecMeeting && isAttending === null) {
toast.warning('사양설명회 참석여부 필요', {
description: '사전견적 또는 입찰을 진행하기 전에 사양설명회 참석여부를 먼저 설정해주세요.',
duration: 5000,
})
return
}
// 입찰기간 체크 (현 시간 기준으로 입찰기간 시작 전이면 접근 불가)
const now = new Date()
const startDate = row.original.submissionStartDate ? new Date(row.original.submissionStartDate) : null
if (startDate && now < startDate) {
toast.warning('입찰기간 전 접근 제한', {
description: `입찰기간이 아직 시작되지 않았습니다`,
duration: 5000,
})
return
}
if (setRowAction) {
setRowAction({
type: 'view',
row: { original: row.original }
})
}
}
return (
<div
className="max-w-48 truncate cursor-pointer underline font-bold hover:text-blue-600"
title={row.original.title}
onClick={handleTitleClick}
>
{row.original.title}
</div>
)
},
}),
// 사양설명회
columnHelper.accessor('isAttendingMeeting', {
header: '사양설명회',
cell: ({ row }) => {
const isAttending = row.original.isAttendingMeeting
if (isAttending === null) {
return <div className="text-muted-foreground text-center">-</div>
}
return isAttending ? (
<CheckCircle className="h-5 w-5 text-green-600 mx-auto" />
) : (
<XCircle className="h-5 w-5 text-red-600 mx-auto" />
)
},
}),
// 입찰 참여의사
columnHelper.accessor('isBiddingParticipated', {
header: '입찰 참여의사',
cell: ({ row }) => {
const participated = row.original.isBiddingParticipated
if (participated === null) {
return <Badge variant="outline">미결정</Badge>
}
return (
<Badge variant={participated ? 'default' : 'destructive'}>
{participated ? '참여' : '불참'}
</Badge>
)
},
}),
// 입찰 제출여부
columnHelper.display({
id: 'biddingSubmissionStatus',
header: '입찰 제출여부',
cell: ({ row }) => {
const finalQuoteAmount = row.original.finalQuoteAmount
const isFinalSubmission = row.original.isFinalSubmission
if (!finalQuoteAmount) {
return <Badge variant="outline">미제출</Badge>
}
if (isFinalSubmission) {
return <Badge variant="default">최종제출</Badge>
}
return <Badge variant="secondary">제출</Badge>
},
}),
// 계약구분
columnHelper.accessor('contractType', {
header: '계약구분',
cell: ({ row }) => (
<div>{contractTypeLabels[row.original.contractType] || row.original.contractType}</div>
),
}),
// 입찰기간
columnHelper.accessor('submissionStartDate', {
header: '입찰기간',
cell: ({ row }) => {
const startDate = row.original.submissionStartDate
const endDate = row.original.submissionEndDate
if (!startDate || !endDate) {
return <div className="text-muted-foreground">-</div>
}
const startObj = new Date(startDate)
const endObj = new Date(endDate)
// UI 표시용 KST 변환
const formatKst = (d: Date) => new Date(d.getTime() + 9 * 60 * 60 * 1000).toISOString().slice(0, 16).replace('T', ' ')
return (
<div className="text-sm">
<div>{formatKst(startObj)}</div>
<div className="text-muted-foreground">~</div>
<div>{formatKst(endObj)}</div>
</div>
)
},
}),
// 사전견적 마감일
columnHelper.accessor('preQuoteDeadline', {
header: '사전견적 마감일',
cell: ({ row }) => {
const deadline = row.original.preQuoteDeadline
if (!deadline) {
return <div className="text-muted-foreground">-</div>
}
const now = new Date()
const deadlineDate = new Date(deadline)
const isExpired = deadlineDate < now
return (
<div className={`text-sm flex items-center gap-1 ${isExpired ? 'text-red-600' : ''}`}>
<Calendar className="w-4 h-4" />
<span>{format(new Date(deadline), "yyyy-MM-dd HH:mm")}</span>
{isExpired && (
<Badge variant="destructive" className="text-xs">
마감
</Badge>
)}
</div>
)
},
}),
// 계약기간
columnHelper.accessor('contractStartDate', {
header: '계약기간',
cell: ({ row }) => {
const startDate = row.original.contractStartDate
const endDate = row.original.contractEndDate
if (!startDate || !endDate) {
return <div className="text-muted-foreground text-center">-</div>
}
return (
<div className="text-sm">
<div>{format(new Date(startDate), "yyyy-MM-dd")}</div>
<div className="text-muted-foreground">~</div>
<div>{format(new Date(endDate), "yyyy-MM-dd")}</div>
</div>
)
},
}),
// 입찰담당자
columnHelper.display({
id: 'bidPicName',
header: '입찰담당자',
cell: ({ row }) => {
const name = row.original.bidPicName
if (!name) {
return <div className="text-muted-foreground text-center">-</div>
}
return (
<div className="flex items-center gap-1">
<User className="h-4 w-4" />
<div className="text-sm">{name}</div>
</div>
)
},
}),
// 조달담당자
columnHelper.display({
id: 'supplyPicName',
header: '조달담당자',
cell: ({ row }) => {
const name = row.original.supplyPicName
if (!name) {
return <div className="text-muted-foreground text-center">-</div>
}
return (
<div className="flex items-center gap-1">
<User className="h-4 w-4" />
<div className="text-sm">{name}</div>
</div>
)
},
}),
// 최종수정일
columnHelper.accessor('updatedAt', {
header: '최종수정일',
cell: ({ row }) => (
<div className="text-sm">{format(new Date(row.original.updatedAt), "yyyy-MM-dd HH:mm")}</div>
),
}),
]
}
|