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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
|
'use client'
import * as React from 'react'
import { UseFormReturn } from 'react-hook-form'
import { ChevronRight, Upload, FileText, Eye, User, Building, Calendar, DollarSign, Plus } from 'lucide-react'
import { toast } from 'sonner'
import { Button } from '@/components/ui/button'
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '@/components/ui/form'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import { Input } from '@/components/ui/input'
import { Textarea } from '@/components/ui/textarea'
import { Switch } from '@/components/ui/switch'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
import type { CreateBiddingSchema } from '@/lib/bidding/validation'
import { contractTypeLabels, biddingTypeLabels, awardCountLabels, biddingNoticeTypeLabels } from '@/db/schema'
import {
getIncotermsForSelection,
getPaymentTermsForSelection,
getPlaceOfShippingForSelection,
getPlaceOfDestinationForSelection,
} from '@/lib/procurement-select/service'
import { TAX_CONDITIONS } from '@/lib/tax-conditions/types'
import { getBiddingNoticeTemplate } from '@/lib/bidding/service'
import TiptapEditor from '@/components/qna/tiptap-editor'
import { PurchaseGroupCodeSelector } from '@/components/common/selectors/purchase-group-code'
import { ProcurementManagerSelector } from '@/components/common/selectors/procurement-manager'
import type { PurchaseGroupCodeWithUser } from '@/components/common/selectors/purchase-group-code/purchase-group-code-service'
import type { ProcurementManagerWithUser } from '@/components/common/selectors/procurement-manager/procurement-manager-service'
import { createBidding } from '@/lib/bidding/service'
interface BiddingCreateDialogProps {
form: UseFormReturn<CreateBiddingSchema>
onSuccess?: () => void
}
export function BiddingCreateDialog({ form, onSuccess }: BiddingCreateDialogProps) {
const [isOpen, setIsOpen] = React.useState(false)
const [isSubmitting, setIsSubmitting] = React.useState(false)
const [paymentTermsOptions, setPaymentTermsOptions] = React.useState<Array<{ code: string; description: string }>>([])
const [incotermsOptions, setIncotermsOptions] = React.useState<Array<{ code: string; description: string }>>([])
const [shippingPlaces, setShippingPlaces] = React.useState<Array<{ code: string; description: string }>>([])
const [destinationPlaces, setDestinationPlaces] = React.useState<Array<{ code: string; description: string }>>([])
const [biddingConditions, setBiddingConditions] = React.useState({
paymentTerms: '',
taxConditions: 'V1',
incoterms: 'DAP',
incotermsOption: '',
contractDeliveryDate: '',
shippingPort: '',
destinationPort: '',
isPriceAdjustmentApplicable: false,
sparePartOptions: '',
})
// 구매요청자 정보 (현재 사용자)
// React.useEffect(() => {
// // 실제로는 현재 로그인한 사용자의 정보를 가져와야 함
// // 임시로 기본값 설정
// form.setValue('requesterName', '김두진') // 실제로는 API에서 가져와야 함
// }, [form])
const [shiAttachmentFiles, setShiAttachmentFiles] = React.useState<File[]>([])
const [vendorAttachmentFiles, setVendorAttachmentFiles] = React.useState<File[]>([])
// 담당자 selector 상태
const [selectedBidPic, setSelectedBidPic] = React.useState<PurchaseGroupCodeWithUser | undefined>(undefined)
const [selectedSupplyPic, setSelectedSupplyPic] = React.useState<ProcurementManagerWithUser | undefined>(undefined)
// 입찰공고 템플릿 관련 상태
const [noticeTemplate, setNoticeTemplate] = React.useState<string>('')
const [isLoadingTemplate, setIsLoadingTemplate] = React.useState(false)
// -- 데이터 로딩 및 상태 동기화 로직
const loadPaymentTerms = React.useCallback(async () => {
try {
const data = await getPaymentTermsForSelection()
setPaymentTermsOptions(data)
const p008Exists = data.some((item) => item.code === 'P008')
if (p008Exists) {
setBiddingConditions((prev) => ({ ...prev, paymentTerms: 'P008' }))
form.setValue('biddingConditions.paymentTerms', 'P008')
}
} catch (error) {
console.error('Failed to load payment terms:', error)
toast.error('결제조건 목록을 불러오는데 실패했습니다.')
}
}, [form])
const loadIncoterms = React.useCallback(async () => {
try {
const data = await getIncotermsForSelection()
setIncotermsOptions(data)
const dapExists = data.some((item) => item.code === 'DAP')
if (dapExists) {
setBiddingConditions((prev) => ({ ...prev, incoterms: 'DAP' }))
form.setValue('biddingConditions.incoterms', 'DAP')
}
} catch (error) {
console.error('Failed to load incoterms:', error)
toast.error('운송조건 목록을 불러오는데 실패했습니다.')
}
}, [form])
const loadShippingPlaces = React.useCallback(async () => {
try {
const data = await getPlaceOfShippingForSelection()
setShippingPlaces(data)
} catch (error) {
console.error('Failed to load shipping places:', error)
toast.error('선적지 목록을 불러오는데 실패했습니다.')
}
}, [])
const loadDestinationPlaces = React.useCallback(async () => {
try {
const data = await getPlaceOfDestinationForSelection()
setDestinationPlaces(data)
} catch (error) {
console.error('Failed to load destination places:', error)
toast.error('하역지 목록을 불러오는데 실패했습니다.')
}
}, [])
React.useEffect(() => {
if (isOpen) {
loadPaymentTerms()
loadIncoterms()
loadShippingPlaces()
loadDestinationPlaces()
const v1Exists = TAX_CONDITIONS.some((item) => item.code === 'V1')
if (v1Exists) {
setBiddingConditions((prev) => ({ ...prev, taxConditions: 'V1' }))
form.setValue('biddingConditions.taxConditions', 'V1')
}
// 초기 표준 템플릿 로드
const loadInitialTemplate = async () => {
try {
const standardTemplate = await getBiddingNoticeTemplate('standard')
if (standardTemplate) {
console.log('standardTemplate', standardTemplate)
setNoticeTemplate(standardTemplate.content)
form.setValue('content', standardTemplate.content)
}
} catch (error) {
console.error('Failed to load initial template:', error)
toast.error('기본 템플릿을 불러오는데 실패했습니다.')
}
}
loadInitialTemplate()
}
}, [isOpen, loadPaymentTerms, loadIncoterms, loadShippingPlaces, loadDestinationPlaces, form])
// 입찰공고 템플릿 로딩
const noticeTypeValue = form.watch('noticeType')
const selectedNoticeType = React.useMemo(() => noticeTypeValue, [noticeTypeValue])
React.useEffect(() => {
const loadNoticeTemplate = async () => {
if (selectedNoticeType) {
setIsLoadingTemplate(true)
try {
const template = await getBiddingNoticeTemplate(selectedNoticeType)
if (template) {
setNoticeTemplate(template.content)
// 폼의 content 필드도 업데이트
form.setValue('content', template.content)
} else {
// 템플릿이 없으면 표준 템플릿 사용
const defaultTemplate = await getBiddingNoticeTemplate('standard')
if (defaultTemplate) {
setNoticeTemplate(defaultTemplate.content)
form.setValue('content', defaultTemplate.content)
}
}
} catch (error) {
console.error('Failed to load notice template:', error)
toast.error('입찰공고 템플릿을 불러오는데 실패했습니다.')
} finally {
setIsLoadingTemplate(false)
}
}
}
loadNoticeTemplate()
}, [selectedNoticeType, form])
// SHI용 파일 첨부 핸들러
const handleShiFileUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
const files = Array.from(event.target.files || [])
setShiAttachmentFiles(prev => [...prev, ...files])
}
const removeShiFile = (index: number) => {
setShiAttachmentFiles(prev => prev.filter((_, i) => i !== index))
}
// 협력업체용 파일 첨부 핸들러
const handleVendorFileUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
const files = Array.from(event.target.files || [])
setVendorAttachmentFiles(prev => [...prev, ...files])
}
const removeVendorFile = (index: number) => {
setVendorAttachmentFiles(prev => prev.filter((_, i) => i !== index))
}
// 입찰담당자 선택 핸들러
const handleBidPicSelect = (code: PurchaseGroupCodeWithUser) => {
setSelectedBidPic(code)
form.setValue('bidPicName', code.DISPLAY_NAME || '')
form.setValue('bidPicCode', code.PURCHASE_GROUP_CODE || '')
// ID도 저장 (실제로는 사용자 ID가 필요)
if (code.user) {
form.setValue('bidPicId', code.user.id || undefined)
}
}
// 조달담당자 선택 핸들러
const handleSupplyPicSelect = (manager: ProcurementManagerWithUser) => {
setSelectedSupplyPic(manager)
form.setValue('supplyPicName', manager.DISPLAY_NAME || '')
form.setValue('supplyPicCode', manager.PROCUREMENT_MANAGER_CODE || '')
// ID도 저장 (실제로는 사용자 ID가 필요)
if (manager.user) {
form.setValue('supplyPicId', manager.user.id || undefined)
}
}
const handleSubmit = async (data: CreateBiddingSchema) => {
setIsSubmitting(true)
try {
// 폼 validation 실행
const isFormValid = await form.trigger()
if (!isFormValid) {
toast.error('필수 정보를 모두 입력해주세요.')
return
}
// 첨부파일 정보 설정 (실제로는 파일 업로드 후 저장해야 함)
const attachments = shiAttachmentFiles.map((file, index) => ({
id: `shi_${Date.now()}_${index}`,
fileName: file.name,
fileSize: file.size,
filePath: '', // 실제 업로드 후 경로
uploadedAt: new Date().toISOString(),
type: 'shi' as const,
}))
const vendorAttachments = vendorAttachmentFiles.map((file, index) => ({
id: `vendor_${Date.now()}_${index}`,
fileName: file.name,
fileSize: file.size,
filePath: '', // 실제 업로드 후 경로
uploadedAt: new Date().toISOString(),
type: 'vendor' as const,
}))
// sparePartOptions가 undefined인 경우 빈 문자열로 설정
const biddingData: CreateBiddingInput = {
...data,
attachments,
vendorAttachments,
biddingConditions: {
...data.biddingConditions,
sparePartOptions: data.biddingConditions.sparePartOptions || '',
incotermsOption: data.biddingConditions.incotermsOption || '',
contractDeliveryDate: data.biddingConditions.contractDeliveryDate || '',
shippingPort: data.biddingConditions.shippingPort || '',
destinationPort: data.biddingConditions.destinationPort || '',
},
}
const result = await createBidding(biddingData, '1') // 실제로는 현재 사용자 ID
if (result.success) {
toast.success("입찰이 성공적으로 생성되었습니다.")
setIsOpen(false)
form.reset()
setShiAttachmentFiles([])
setVendorAttachmentFiles([])
setSelectedBidPic(undefined)
setSelectedSupplyPic(undefined)
setNoticeTemplate('')
if (onSuccess) {
onSuccess()
}
} else {
toast.error((result as { success: false; error: string }).error || "입찰 생성에 실패했습니다.")
}
} catch (error) {
console.error("Failed to create bidding:", error)
toast.error("입찰 생성 중 오류가 발생했습니다.")
} finally {
setIsSubmitting(false)
}
}
const handleOpenChange = (open: boolean) => {
setIsOpen(open)
if (!open) {
// 다이얼로그 닫을 때 폼 초기화
form.reset()
setShiAttachmentFiles([])
setVendorAttachmentFiles([])
setSelectedBidPic(undefined)
setSelectedSupplyPic(undefined)
setNoticeTemplate('')
setBiddingConditions({
paymentTerms: '',
taxConditions: 'V1',
incoterms: 'DAP',
incotermsOption: '',
contractDeliveryDate: '',
shippingPort: '',
destinationPort: '',
isPriceAdjustmentApplicable: false,
sparePartOptions: '',
})
}
}
return (
<Dialog open={isOpen} onOpenChange={handleOpenChange}>
<DialogTrigger asChild>
<Button>
<Plus className="mr-2 h-4 w-4" />
입찰 신규생성
</Button>
</DialogTrigger>
<DialogContent className="max-w-6xl max-h-[90vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>입찰 신규생성</DialogTitle>
<DialogDescription>
새로운 입찰을 생성합니다. 기본 정보와 입찰 조건을 설정하세요.
</DialogDescription>
</DialogHeader>
<div className="space-y-6">
<Form {...form}>
<form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-6">
{/* 통합된 기본 정보 및 입찰 조건 카드 */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<FileText className="h-5 w-5" />
기본 정보 및 입찰 조건
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
{/* 1행: 입찰명, 낙찰수, 입찰유형, 계약구분 */}
<div className="grid grid-cols-4 gap-4">
<FormField
control={form.control}
name="title"
render={({ field }) => (
<FormItem>
<FormLabel>입찰명 <span className="text-red-500">*</span></FormLabel>
<FormControl>
<Input placeholder="입찰명을 입력하세요" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="awardCount"
render={({ field }) => (
<FormItem>
<FormLabel>낙찰수 <span className="text-red-500">*</span></FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="낙찰수 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
{Object.entries(awardCountLabels).map(([value, label]) => (
<SelectItem key={value} value={value}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="biddingType"
render={({ field }) => (
<FormItem>
<FormLabel>입찰유형 <span className="text-red-500">*</span></FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="입찰유형 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
{Object.entries(biddingTypeLabels).map(([value, label]) => (
<SelectItem key={value} value={value}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="contractType"
render={({ field }) => (
<FormItem>
<FormLabel>계약구분 <span className="text-red-500">*</span></FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="계약구분 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
{Object.entries(contractTypeLabels).map(([value, label]) => (
<SelectItem key={value} value={value}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 기타 입찰유형 선택 시 직접입력 필드 */}
{form.watch('biddingType') === 'other' && (
<div className="grid grid-cols-4 gap-4">
<div></div>
<div></div>
<FormField
control={form.control}
name="biddingTypeCustom"
render={({ field }) => (
<FormItem>
<FormLabel>기타 입찰유형 <span className="text-red-500">*</span></FormLabel>
<FormControl>
<Input placeholder="직접 입력하세요" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div></div>
</div>
)}
{/* 2행: 예산, 실적가, 내정가, P/R번호 (조회용) */}
<div className="grid grid-cols-4 gap-4">
<FormField
control={form.control}
name="budget"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<DollarSign className="h-3 w-3" />
예산
</FormLabel>
<FormControl>
<Input placeholder="예산 입력" {...field} readOnly className="bg-muted" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="finalBidPrice"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<DollarSign className="h-3 w-3" />
실적가
</FormLabel>
<FormControl>
<Input placeholder="실적가" {...field} readOnly className="bg-muted" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="targetPrice"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<Eye className="h-3 w-3" />
내정가
</FormLabel>
<FormControl>
<Input placeholder="내정가" {...field} readOnly className="bg-muted" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="prNumber"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<Eye className="h-3 w-3" />
P/R번호
</FormLabel>
<FormControl>
<Input placeholder="P/R번호" {...field} readOnly className="bg-muted" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 3행: 입찰담당자, 조달담당자 */}
<div className="grid grid-cols-2 gap-4">
<FormField
control={form.control}
name="bidPicName"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<User className="h-3 w-3" />
입찰담당자 <span className="text-red-500">*</span>
</FormLabel>
<FormControl>
<PurchaseGroupCodeSelector
selectedCode={selectedBidPic}
onCodeSelect={(code) => {
handleBidPicSelect(code)
field.onChange(code.DISPLAY_NAME || '')
}}
placeholder="입찰담당자 선택"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="supplyPicName"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<User className="h-3 w-3" />
조달담당자
</FormLabel>
<FormControl>
<ProcurementManagerSelector
selectedManager={selectedSupplyPic}
onManagerSelect={(manager) => {
handleSupplyPicSelect(manager)
field.onChange(manager.DISPLAY_NAME || '')
}}
placeholder="조달담당자 선택"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 4행: 하도급법적용여부, SHI 지급조건 */}
<div className="grid grid-cols-2 gap-4">
<FormField
control={form.control}
name="biddingConditions.isPriceAdjustmentApplicable"
render={({ field }) => (
<FormItem>
<FormLabel>하도급법적용여부</FormLabel>
<div className="flex items-center space-x-2">
<Switch
id="price-adjustment"
checked={biddingConditions.isPriceAdjustmentApplicable}
onCheckedChange={(checked) => {
setBiddingConditions(prev => ({
...prev,
isPriceAdjustmentApplicable: checked
}))
field.onChange(checked)
}}
/>
<FormLabel htmlFor="price-adjustment" className="text-sm">
연동제 적용 요건
</FormLabel>
</div>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="biddingConditions.paymentTerms"
render={({ field }) => (
<FormItem>
<FormLabel>SHI 지급조건 <span className="text-red-500">*</span></FormLabel>
<FormControl>
<Select
value={biddingConditions.paymentTerms}
onValueChange={(value) => {
setBiddingConditions(prev => ({
...prev,
paymentTerms: value
}))
field.onChange(value)
}}
>
<SelectTrigger>
<SelectValue placeholder="지급조건 선택" />
</SelectTrigger>
<SelectContent>
{paymentTermsOptions.length > 0 ? (
paymentTermsOptions.map((option) => (
<SelectItem key={option.code} value={option.code}>
{option.code} {option.description && `(${option.description})`}
</SelectItem>
))
) : (
<SelectItem value="loading" disabled>
데이터를 불러오는 중...
</SelectItem>
)}
</SelectContent>
</Select>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 5행: SHI 인도조건, SHI 인도조건2 */}
<div className="grid grid-cols-2 gap-4">
<FormField
control={form.control}
name="biddingConditions.incoterms"
render={({ field }) => (
<FormItem>
<FormLabel>SHI 인도조건 <span className="text-red-500">*</span></FormLabel>
<Select
value={biddingConditions.incoterms}
onValueChange={(value) => {
setBiddingConditions(prev => ({
...prev,
incoterms: value
}))
field.onChange(value)
}}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="인코텀즈 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
{incotermsOptions.length > 0 ? (
incotermsOptions.map((option) => (
<SelectItem key={option.code} value={option.code}>
{option.code} {option.description && `(${option.description})`}
</SelectItem>
))
) : (
<SelectItem value="loading" disabled>
데이터를 불러오는 중...
</SelectItem>
)}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="biddingConditions.incotermsOption"
render={({ field }) => (
<FormItem>
<FormLabel>SHI 인도조건2</FormLabel>
<FormControl>
<Input
placeholder="인도조건 추가 정보"
value={biddingConditions.incotermsOption}
onChange={(e) => {
setBiddingConditions(prev => ({
...prev,
incotermsOption: e.target.value
}))
field.onChange(e.target.value)
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 6행: SHI 매입부가가치세, SHI 선적지 */}
<div className="grid grid-cols-2 gap-4">
<FormField
control={form.control}
name="biddingConditions.taxConditions"
render={({ field }) => (
<FormItem>
<FormLabel>SHI 매입부가가치세 <span className="text-red-500">*</span></FormLabel>
<FormControl>
<Select
value={biddingConditions.taxConditions}
onValueChange={(value) => {
setBiddingConditions(prev => ({
...prev,
taxConditions: value
}))
field.onChange(value)
}}
>
<SelectTrigger>
<SelectValue placeholder="세금조건 선택" />
</SelectTrigger>
<SelectContent>
{TAX_CONDITIONS.map((condition) => (
<SelectItem key={condition.code} value={condition.code}>
{condition.name}
</SelectItem>
))}
</SelectContent>
</Select>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="biddingConditions.shippingPort"
render={({ field }) => (
<FormItem>
<FormLabel>SHI 선적지</FormLabel>
<Select
value={biddingConditions.shippingPort}
onValueChange={(value) => {
setBiddingConditions(prev => ({
...prev,
shippingPort: value
}))
field.onChange(value)
}}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="선적지 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
{shippingPlaces.length > 0 ? (
shippingPlaces.map((place) => (
<SelectItem key={place.code} value={place.code}>
{place.code} {place.description && `(${place.description})`}
</SelectItem>
))
) : (
<SelectItem value="loading" disabled>
데이터를 불러오는 중...
</SelectItem>
)}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 7행: SHI 하역지, 계약 납품일 */}
<div className="grid grid-cols-2 gap-4">
<FormField
control={form.control}
name="biddingConditions.destinationPort"
render={({ field }) => (
<FormItem>
<FormLabel>SHI 하역지</FormLabel>
<Select
value={biddingConditions.destinationPort}
onValueChange={(value) => {
setBiddingConditions(prev => ({
...prev,
destinationPort: value
}))
field.onChange(value)
}}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="하역지 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
{destinationPlaces.length > 0 ? (
destinationPlaces.map((place) => (
<SelectItem key={place.code} value={place.code}>
{place.code} {place.description && `(${place.description})`}
</SelectItem>
))
) : (
<SelectItem value="loading" disabled>
데이터를 불러오는 중...
</SelectItem>
)}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="biddingConditions.contractDeliveryDate"
render={({ field }) => (
<FormItem>
<FormLabel>계약 납품일</FormLabel>
<FormControl>
<Input
type="date"
value={biddingConditions.contractDeliveryDate}
onChange={(e) => {
setBiddingConditions(prev => ({
...prev,
contractDeliveryDate: e.target.value
}))
field.onChange(e.target.value)
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 8행: 계약기간 시작/종료, 진행상태, 구매조직 */}
<div className="grid grid-cols-4 gap-4">
<FormField
control={form.control}
name="contractStartDate"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<Calendar className="h-3 w-3" />
계약기간 시작
</FormLabel>
<FormControl>
<Input type="date" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="contractEndDate"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<Calendar className="h-3 w-3" />
계약기간 종료
</FormLabel>
<FormControl>
<Input type="date" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="status"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<Eye className="h-3 w-3" />
진행상태
</FormLabel>
<FormControl>
<Input placeholder="진행상태" {...field} readOnly className="bg-muted" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="purchasingOrganization"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<Building className="h-3 w-3" />
구매조직
</FormLabel>
<Select onValueChange={field.onChange} value={field.value || ''}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="구매조직 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="조선">조선</SelectItem>
<SelectItem value="해양">해양</SelectItem>
<SelectItem value="기타">기타</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 9행: 구매요청자, 구매유형, 통화, 스페어파트 옵션 */}
<div className="grid grid-cols-4 gap-4">
<FormField
control={form.control}
name="requesterName"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-1">
<User className="h-3 w-3" />
구매요청자
</FormLabel>
<FormControl>
<Input placeholder="구매요청자" {...field} readOnly className="bg-muted" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="noticeType"
render={({ field }) => (
<FormItem>
<FormLabel>구매유형 <span className="text-red-500">*</span></FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="구매유형 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
{Object.entries(biddingNoticeTypeLabels).map(([value, label]) => (
<SelectItem key={value} value={value}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="currency"
render={({ field }) => (
<FormItem>
<FormLabel>통화 <span className="text-red-500">*</span></FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="통화 선택" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="KRW">KRW (원)</SelectItem>
<SelectItem value="USD">USD (달러)</SelectItem>
<SelectItem value="EUR">EUR (유로)</SelectItem>
<SelectItem value="JPY">JPY (엔)</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="biddingConditions.sparePartOptions"
render={({ field }) => (
<FormItem>
<FormLabel>스페어파트 옵션</FormLabel>
<FormControl>
<Textarea
placeholder="스페어파트 관련 옵션을 입력하세요"
value={biddingConditions.sparePartOptions}
onChange={(e) => {
setBiddingConditions(prev => ({
...prev,
sparePartOptions: e.target.value
}))
field.onChange(e.target.value)
}}
rows={3}
className="min-h-[40px]"
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 입찰개요 추가 */}
<div className="mt-6 pt-4 border-t">
<FormField
control={form.control}
name="description"
render={({ field }) => (
<FormItem>
<FormLabel>입찰개요</FormLabel>
<FormControl>
<Textarea placeholder="입찰에 대한 설명을 입력하세요" rows={3} {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
</CardContent>
</Card>
{/* 입찰공고 내용 */}
<Card>
<CardHeader>
<CardTitle>입찰공고 내용</CardTitle>
<p className="text-sm text-muted-foreground">
선택한 입찰공고 타입의 템플릿이 자동으로 로드됩니다. 필요에 따라 수정하세요.
</p>
</CardHeader>
<CardContent className="space-y-4">
<FormField
control={form.control}
name="content"
render={({ field }) => (
<FormItem>
<FormControl>
<div className="border rounded-lg">
<TiptapEditor
content={field.value || noticeTemplate}
setContent={(content) => {
field.onChange(content)
}}
disabled={isLoadingTemplate}
height="300px"
/>
</div>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{isLoadingTemplate && (
<div className="flex items-center justify-center p-4 text-sm text-muted-foreground">
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-gray-900 mr-2"></div>
입찰공고 템플릿을 불러오는 중...
</div>
)}
</CardContent>
</Card>
{/* SHI용 첨부파일 */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Upload className="h-5 w-5" />
SHI용 첨부파일
</CardTitle>
<p className="text-sm text-muted-foreground">
SHI에서 제공하는 문서나 파일을 업로드하세요
</p>
</CardHeader>
<CardContent className="space-y-4">
<div className="border-2 border-dashed border-gray-300 rounded-lg p-6">
<div className="text-center">
<Upload className="h-12 w-12 text-gray-400 mx-auto mb-4" />
<div className="space-y-2">
<p className="text-sm text-gray-600">
파일을 드래그 앤 드롭하거나{' '}
<label className="text-blue-600 hover:text-blue-500 cursor-pointer">
<input
type="file"
multiple
className="hidden"
onChange={handleShiFileUpload}
accept=".pdf,.doc,.docx,.xls,.xlsx,.png,.jpg,.jpeg"
/>
찾아보세요
</label>
</p>
<p className="text-xs text-gray-500">
PDF, DOC, DOCX, XLS, XLSX, PNG, JPG, JPEG 파일을 업로드할 수 있습니다
</p>
</div>
</div>
</div>
{shiAttachmentFiles.length > 0 && (
<div className="space-y-2">
<h4 className="text-sm font-medium">업로드된 파일</h4>
<div className="space-y-2">
{shiAttachmentFiles.map((file, index) => (
<div
key={index}
className="flex items-center justify-between p-3 bg-muted rounded-lg"
>
<div className="flex items-center gap-3">
<FileText className="h-4 w-4 text-muted-foreground" />
<div>
<p className="text-sm font-medium">{file.name}</p>
<p className="text-xs text-muted-foreground">
{(file.size / 1024 / 1024).toFixed(2)} MB
</p>
</div>
</div>
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => removeShiFile(index)}
>
제거
</Button>
</div>
))}
</div>
</div>
)}
</CardContent>
</Card>
{/* 협력업체용 첨부파일 */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Upload className="h-5 w-5" />
협력업체용 첨부파일
</CardTitle>
<p className="text-sm text-muted-foreground">
협력업체에서 제공하는 문서나 파일을 업로드하세요
</p>
</CardHeader>
<CardContent className="space-y-4">
<div className="border-2 border-dashed border-gray-300 rounded-lg p-6">
<div className="text-center">
<Upload className="h-12 w-12 text-gray-400 mx-auto mb-4" />
<div className="space-y-2">
<p className="text-sm text-gray-600">
파일을 드래그 앤 드롭하거나{' '}
<label className="text-blue-600 hover:text-blue-500 cursor-pointer">
<input
type="file"
multiple
className="hidden"
onChange={handleVendorFileUpload}
accept=".pdf,.doc,.docx,.xls,.xlsx,.png,.jpg,.jpeg"
/>
찾아보세요
</label>
</p>
<p className="text-xs text-gray-500">
PDF, DOC, DOCX, XLS, XLSX, PNG, JPG, JPEG 파일을 업로드할 수 있습니다
</p>
</div>
</div>
</div>
{vendorAttachmentFiles.length > 0 && (
<div className="space-y-2">
<h4 className="text-sm font-medium">업로드된 파일</h4>
<div className="space-y-2">
{vendorAttachmentFiles.map((file, index) => (
<div
key={index}
className="flex items-center justify-between p-3 bg-muted rounded-lg"
>
<div className="flex items-center gap-3">
<FileText className="h-4 w-4 text-muted-foreground" />
<div>
<p className="text-sm font-medium">{file.name}</p>
<p className="text-xs text-muted-foreground">
{(file.size / 1024 / 1024).toFixed(2)} MB
</p>
</div>
</div>
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => removeVendorFile(index)}
>
제거
</Button>
</div>
))}
</div>
</div>
)}
</CardContent>
</Card>
{/* 네비게이션 버튼 */}
<div className="flex justify-between">
<div></div>
<div className="flex gap-2">
<Button
type="submit"
disabled={isSubmitting}
className="flex items-center gap-2"
>
{isSubmitting ? '저장 중...' : '저장'}
<ChevronRight className="h-4 w-4" />
</Button>
</div>
</div>
</form>
</Form>
</div>
</DialogContent>
</Dialog>
)
}
|