From 8a19a6fa336768d8b6712752c9d713360067ecb0 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 8 Dec 2025 08:45:20 +0000
Subject: (최겸) 구매 피드백 수정, 안전담당자, pq항목 내 첨부, 내외자 구분,
 도로명주소 api 반영(운영기준)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/pq-input/pq-review-wrapper.tsx | 78 +++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 3 deletions(-)

(limited to 'components/pq-input/pq-review-wrapper.tsx')

diff --git a/components/pq-input/pq-review-wrapper.tsx b/components/pq-input/pq-review-wrapper.tsx
index 1e172744..efb078e0 100644
--- a/components/pq-input/pq-review-wrapper.tsx
+++ b/components/pq-input/pq-review-wrapper.tsx
@@ -21,9 +21,10 @@ import {
   DialogTitle
 } from "@/components/ui/dialog"
 import { useToast } from "@/hooks/use-toast"
-import { CheckCircle, AlertCircle, Paperclip, Square } from "lucide-react"
+import { CheckCircle, AlertCircle, Paperclip, Square, Download } from "lucide-react"
 import { PQGroupData } from "@/lib/pq/service"
 import { approvePQAction, rejectPQAction, updateSHICommentAction, approveQMReviewAction, rejectQMReviewAction, requestPqSupplementAction } from "@/lib/pq/service"
+import { FileList, FileListHeader, FileListInfo, FileListItem, FileListName, FileListDescription, FileListAction, FileListIcon } from "@/components/ui/file-list"
 // import * as ExcelJS from 'exceljs';
 // import { saveAs } from "file-saver";
 
@@ -49,13 +50,15 @@ interface PQReviewWrapperProps {
   vendorId: number
   pqSubmission: PQSubmission
   vendorInfo?: any // 협력업체 정보 (선택사항)
+  vendorCountry?: string | null
 }
 
 export function PQReviewWrapper({
   pqData,
   vendorId,
   pqSubmission,
-  vendorInfo
+  vendorInfo,
+  vendorCountry,
 }: PQReviewWrapperProps) {
   const router = useRouter()
   const { toast } = useToast()
@@ -96,6 +99,32 @@ export function PQReviewWrapper({
       return 0
     })
   }
+
+  // 벤더 내자/외자 판별 (국가 코드 기반)
+  const isDomesticVendor = React.useMemo(() => {
+    if (!vendorCountry) return null; // 정보 없으면 필터 미적용
+    return vendorCountry === "KR" || vendorCountry === "한국";
+  }, [vendorCountry]);
+
+  // 벤더 유형에 따라 PQ 항목 필터링
+  const filteredData: PQGroupData[] = React.useMemo(() => {
+    if (isDomesticVendor === null) return pqData;
+
+    const filterItemByType = (item: any) => {
+      const itemType = item.type || "내외자";
+      if (itemType === "내외자") return true;
+      if (itemType === "내자") return isDomesticVendor === true;
+      if (itemType === "외자") return isDomesticVendor === false;
+      return true;
+    };
+
+    return pqData
+      .map((group) => ({
+        ...group,
+        items: group.items.filter(filterItemByType),
+      }))
+      .filter((group) => group.items.length > 0);
+  }, [pqData, isDomesticVendor]);
   
 
   // 기존 SHI 코멘트를 로컬 상태에 초기화
@@ -482,8 +511,14 @@ export function PQReviewWrapper({
   
   return (
     <div className="space-y-6">
+      {filteredData.length === 0 && (
+        <div className="rounded-md border border-dashed p-4 text-sm text-muted-foreground">
+          표시할 PQ 항목이 없습니다. (벤더 내/외자 구분 필터 적용)
+        </div>
+      )}
+
       {/* 그룹별 PQ 항목 표시 */}
-      {pqData.map((group) => (
+      {filteredData.map((group) => (
         <div key={group.groupName} className="space-y-4">
           <h3 className="text-lg font-medium">{group.groupName}</h3>
           
@@ -530,6 +565,43 @@ export function PQReviewWrapper({
                   </div>
                 </CardHeader>
                 <CardContent className="space-y-4">
+                  {item.criteriaAttachments && item.criteriaAttachments.length > 0 && (
+                    <div className="space-y-2">
+                      <p className="text-sm font-medium">기준 첨부파일</p>
+                      <FileList>
+                        {item.criteriaAttachments.map((file) => (
+                          <FileListItem key={file.attachId}>
+                            <FileListHeader>
+                              <FileListIcon />
+                              <FileListInfo>
+                                <FileListName>{file.fileName}</FileListName>
+                                {file.fileSize && (
+                                  <FileListDescription>{file.fileSize} bytes</FileListDescription>
+                                )}
+                              </FileListInfo>
+                              <FileListAction
+                                onClick={async () => {
+                                  try {
+                                    const { downloadFile } = await import('@/lib/file-download')
+                                    await downloadFile(file.filePath, file.fileName, { showToast: true })
+                                  } catch (error) {
+                                    toast({
+                                      title: "다운로드 실패",
+                                      description: "파일 다운로드 중 오류가 발생했습니다.",
+                                      variant: "destructive"
+                                    })
+                                  }
+                                }}
+                              >
+                                <Download className="h-4 w-4" />
+                                <span className="sr-only">Download</span>
+                              </FileListAction>
+                            </FileListHeader>
+                          </FileListItem>
+                        ))}
+                      </FileList>
+                    </div>
+                  )}
                   {/* 프로젝트별 추가 정보 */}
                   {pqSubmission.projectId && item.contractInfo && (
                     <div className="space-y-1">
-- 
cgit v1.2.3

