From e1535c267711c7c8d560e8916437167bbcd3156b Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 02 二月 2026 17:54:31 +0800
Subject: [PATCH] feat: 进销质量类分析接口对接

---
 src/views/reportAnalysis/qualityAnalysis/components/center-center.vue |  101 +++++++++++++++++++++++++++-----------------------
 1 files changed, 55 insertions(+), 46 deletions(-)

diff --git a/src/views/reportAnalysis/qualityAnalysis/components/center-center.vue b/src/views/reportAnalysis/qualityAnalysis/components/center-center.vue
index 8024092..8d28f7a 100644
--- a/src/views/reportAnalysis/qualityAnalysis/components/center-center.vue
+++ b/src/views/reportAnalysis/qualityAnalysis/components/center-center.vue
@@ -12,7 +12,8 @@
       <div class="warn-body">
         <div class="warn-list" role="list">
           <div v-for="item in warnings" :key="item.id" class="warn-item" role="listitem" @click="openWarning(item)">
-            <div class="warn-tag" :class="tagClass(item.type)">{{ item.typeText }}</div>
+            <div class="warn-tag" :class="tagClass(item.type)">{{ item.parentProductTitle }}-{{ item.productTitle }}
+            </div>
             <div class="warn-text" :title="item.title">{{ item.title }}</div>
             <div class="warn-action" @click.stop="openWarning(item)">鏌ョ湅</div>
             <div class="warn-date">{{ item.date }}</div>
@@ -26,18 +27,18 @@
 <script setup>
 import { computed, getCurrentInstance, ref, onMounted } from 'vue'
 import Echarts from '@/components/Echarts/echarts.vue'
-import { qualityUnqualifiedListPage } from '@/api/qualityManagement/nonconformingManagement.js'
+import { nonComplianceWarning } from '@/api/viewIndex.js'
 
 const { proxy } = getCurrentInstance() || {}
 
-const warnings = ref([
-  { id: '1', type: 'raw', typeText: '鍘熸潗鏂�', title: '鍏充簬浼佷笟鍘熸潗鏂欒皟鏁撮�氱煡', date: '2024.08.24' },
-  { id: '2', type: 'raw', typeText: '鍘熸潗鏂�', title: '鍏充簬鍘熸潗鏂欐秷鑰楁柟妗堝缓璁剧殑閫氱煡', date: '2024.08.24' },
-  { id: '3', type: 'final', typeText: '鎴愬搧', title: '鎴愬搧宸ヤ綔鍙扮郴缁熺淮鎶よ鍒掑畨鎺�', date: '2024.08.24' },
-  { id: '4', type: 'final', typeText: '鎴愬搧', title: '鎴愬搧宸ヤ綔鍙扮郴缁熺淮鎶よ鍒掑畨鎺�', date: '2024.08.24' },
-  { id: '5', type: 'semi', typeText: '鍗婃垚鍝�', title: 'HRM绯荤粺瀹夊叏鍗囩骇鍏憡锛氬姞寮鸿闂帶鍒垛��', date: '2024.08.24' },
-  { id: '6', type: 'semi', typeText: '鍗婃垚鍝�', title: 'HRM绯荤粺瀹夊叏鍗囩骇鍏憡锛氬姞寮鸿闂帶鍒垛��', date: '2024.08.24' },
-])
+const warnings = ref([])
+
+// 鍗犳瘮鏁版嵁
+const ratios = ref({
+  rawMaterialRatio: 0,
+  semiFinishedProductRatio: 0,
+  finishedProductRatio: 0,
+})
 
 const TAG_COLORS = {
   raw: '#7C4DFF',
@@ -51,6 +52,14 @@
   return 'tag-semi'
 }
 
+// 鏍规嵁productTitle鏄犲皠绫诲瀷
+const mapProductTitleToType = (productTitle) => {
+  if (productTitle === '鍘熸潗鏂�') return 'raw'
+  if (productTitle === '鍗婃垚鍝�') return 'semi'
+  if (productTitle === '鎴愬搧') return 'final'
+  return 'raw' // 榛樿鍊�
+}
+
 const pieChartStyle = { width: '100%', height: '100%' }
 
 const pieOptions = {
@@ -60,19 +69,14 @@
 
 const pieTooltip = {
   trigger: 'item',
-  formatter: (p) => `${p.name}锛�${p.value}`,
+  formatter: (p) => `${p.name}锛�${p.value}%`,
 }
 
 const pieData = computed(() => {
-  const counts = { raw: 0, final: 0, semi: 0 }
-  warnings.value.forEach((w) => {
-    const key = w.type in counts ? w.type : 'raw'
-    counts[key] += 1
-  })
   return [
-    { name: '鍘熸潗鏂�', value: counts.raw, itemStyle: { color: TAG_COLORS.raw } },
-    { name: '鍗婃垚鍝�', value: counts.semi, itemStyle: { color: TAG_COLORS.semi } },
-    { name: '鎴愬搧', value: counts.final, itemStyle: { color: TAG_COLORS.final } },
+    { name: '鍘熸潗鏂�', value: ratios.value.rawMaterialRatio, itemStyle: { color: TAG_COLORS.raw } },
+    { name: '鍗婃垚鍝�', value: ratios.value.semiFinishedProductRatio, itemStyle: { color: TAG_COLORS.semi } },
+    { name: '鎴愬搧', value: ratios.value.finishedProductRatio, itemStyle: { color: TAG_COLORS.final } },
   ]
 })
 
@@ -111,34 +115,42 @@
 
 const fetchWarnings = async () => {
   try {
-    const res = await qualityUnqualifiedListPage({ pageNum: 1, pageSize: 6 })
-    const rows = res?.rows || res?.data?.rows || res?.data || []
-    if (!Array.isArray(rows) || rows.length === 0) return
+    const res = await nonComplianceWarning()
+    if (res?.code === 200 && res?.data) {
+      const data = res.data
 
-    warnings.value = rows.slice(0, 6).map((r, idx) => {
-      const typeCode = r.inspectType ?? r.modelType ?? r.type
-      const mappedType = typeCode === 0 || typeCode === '0' ? 'raw' : typeCode === 1 || typeCode === '1' ? 'semi' : 'final'
-      const title = r.title || r.unqualifiedTitle || r.remark || r.unqualifiedReason || '涓嶅悎鏍奸璀�'
-      const date = (r.warningTime || r.createTime || r.updateTime || '').slice(0, 10).replace(/-/g, '.') || '2024.08.24'
-      return {
-        id: r.id ?? r.unqualifiedId ?? `${idx}`,
-        type: mappedType,
-        typeText: mappedType === 'raw' ? '鍘熸潗鏂�' : mappedType === 'semi' ? '鍗婃垚鍝�' : '鎴愬搧',
-        title,
-        date,
+      // 鏇存柊鍗犳瘮鏁版嵁
+      ratios.value = {
+        rawMaterialRatio: data.rawMaterialRatio ?? 0,
+        semiFinishedProductRatio: data.semiFinishedProductRatio ?? 0,
+        finishedProductRatio: data.finishedProductRatio ?? 0,
       }
-    })
+
+      // 鏇存柊璀﹀憡鍒楄〃
+      const children = data.children || []
+      warnings.value = children.map((item, idx) => {
+        const type = mapProductTitleToType(item.parentProductTitle)
+        const date = item.date ? item.date.replace(/-/g, '.') : ''
+        return {
+          id: item.id ?? `warning-${idx}`,
+          type,
+          parentProductTitle: item.parentProductTitle || '鍘熸潗鏂�',
+          productTitle: item.productTitle || '鍘熸潗鏂�',
+          title: item.description || '涓嶅悎鏍奸璀�',
+          date,
+        }
+      })
+    }
   } catch (e) {
-    // 鎺ュ彛澶辫触鍒欎繚鎸� mock
+    // 鎺ュ彛澶辫触鍒欎繚鎸佺┖鏁版嵁
     console.error('鑾峰彇涓嶅悎鏍奸璀﹀け璐�:', e)
   }
 }
 
 const openWarning = (item) => {
-  const title = `銆�${item.typeText}銆�${item.title}`
-  const content = `${title}鏃堕棿锛�${item.date}`
+  const title = `銆�${item.parentProductTitle}-${item.productTitle}銆�${item.title}`
   if (proxy?.$modal?.alert) {
-    proxy.$modal.alert(content)
+    proxy.$modal.alert(title)
     return
   }
   // 鍏滃簳锛氭病鏈夊叏灞� modal 鏃剁敤 console
@@ -170,14 +182,11 @@
   align-items: center;
   justify-content: space-between;
   border-bottom: 1px solid;
-  border-image: linear-gradient(
-      270deg,
+  border-image: linear-gradient(270deg,
       rgba(0, 126, 255, 0) 0%,
       rgba(0, 126, 255, 0.4549) 35%,
       #007eff 78%,
-      #007eff 100%
-    )
-    1;
+      #007eff 100%) 1;
   padding: 10px 0 6px;
 }
 
@@ -235,13 +244,13 @@
 
 .warn-item {
   display: grid;
-  grid-template-columns: 88px 1fr auto 110px;
+  grid-template-columns: 130px 1fr auto 110px;
   align-items: center;
   gap: 12px;
   color: #b8c8e0;
   font-size: 14px;
-  line-height: 1;
-  padding: 6px 0;
+  line-height: 1.2;
+  padding: 8px 0;
   border-radius: 4px;
   transition: background-color 0.2s, color 0.2s;
 }

--
Gitblit v1.9.3