Explorar o código

fix: 对接报告

lxf hai 2 semanas
pai
achega
974759af58

+ 119 - 12
src/views/old_mini/agri_file/index.vue

@@ -116,7 +116,7 @@
                 </div>
             </div>
             <div v-show="activeNav === 'report'">
-                <div v-for="item in reportList" :key="item.id" class="report-card">
+                <div v-for="item in reportList" :key="item.id" class="report-card" @click="goReportDetail(item)">
                     <div class="report-card__cover">
                         <img :src="item.cover" alt="" />
                         <span class="report-card__date">{{ item.date }}</span>
@@ -330,11 +330,107 @@ async function fetchCropQuestionAlbumPic() {
 }
 
 const reportCover = require("@/assets/img/common/sd-1.jpg");
-const reportList = ref([
-    { id: 1, title: "", desc: "", date: "", cover: reportCover },
-    { id: 2, title: "", desc: "", date: "", cover: require("@/assets/img/common/sd-2.jpg") },
-    { id: 3, title: "", desc: "", date: "", cover: require("@/assets/img/common/sd-3.jpg") },
-]);
+/** 诊断报告列表:1 风险报告 / 2 胁迫报告 / 3 种植诊断报告 */
+const reportList = ref([]);
+
+function resolveReportCover() {
+    return readStoredCropQuestionPic() || reportCover;
+}
+
+function resolveUserTel() {
+    const entry = readEntryFarmData();
+    if (entry?.phone) return String(entry.phone).trim();
+    try {
+        const userInfo = JSON.parse(localStorage.getItem("localUserInfo") || "{}");
+        return String(userInfo.tel || userInfo.phone || userInfo.mobile || "").trim();
+    } catch {
+        return "";
+    }
+}
+
+function unwrapApiData(raw) {
+    const res = Array.isArray(raw) ? raw[0] : raw;
+    if (Number(res?.code) !== 200 || !res.data) return null;
+    return Array.isArray(res.data) ? res.data[0] : res.data;
+}
+
+function pickReportDate(data) {
+    return data?.create_time || data?.update_time || data?.date || data?.report_date || "";
+}
+
+/** 从诊断报告 markdown 取标题与首段简介 */
+function pickDiagnosisCard(data) {
+    const md = data?.report;
+    if (!md || typeof md !== "string") return null;
+    const titleMatch = md.match(/^#\s+(.+)$/m);
+    const title = (titleMatch?.[1] || "").trim() || t("agriFile.plantingDiagnosisReport");
+    const intro = md
+        .split(/\n+/)
+        .map((line) => line.trim())
+        .find((line) => line && !line.startsWith("#")) || "";
+    return {
+        title,
+        desc: intro,
+        date: pickReportDate(data),
+    };
+}
+
+/** 拼装诊断报告 tab:risk_report / stress_report / report.check */
+async function fetchReportList() {
+    const tel = resolveUserTel();
+    const cover = resolveReportCover();
+    const entry = readEntryFarmData();
+    const empty = (id) => ({ id, title: "", desc: "", date: "", cover });
+
+    if (!tel) {
+        reportList.value = [empty(1), empty(2), empty(3)];
+        return;
+    }
+
+    const [riskRaw, stressRaw, diagnosisRaw] = await Promise.all([
+        VE_API.questionnaire.riskReport({ tel }).catch(() => null),
+        VE_API.questionnaire.stressReport({ tel }).catch(() => null),
+        VE_API.questionnaire.checkReportGenerated({ tel }).catch(() => null),
+    ]);
+
+    const riskData = unwrapApiData(riskRaw);
+    const stressData = unwrapApiData(stressRaw);
+    const diagnosisRes = Array.isArray(diagnosisRaw) ? diagnosisRaw[0] : diagnosisRaw;
+    const diagnosisData =
+        Number(diagnosisRes?.code) === 200 && diagnosisRes?.data ? diagnosisRes.data : null;
+    const diagnosisCard = pickDiagnosisCard(diagnosisData);
+
+    reportList.value = [
+        {
+            id: 1,
+            type: "risk",
+            title: riskData
+                ? `未来预警: ${entry?.weatherRisk || riskData.risk_name || "预警"}`
+                : "",
+            desc: riskData?.explain_simple || riskData?.interact_explain || "",
+            date: pickReportDate(riskData),
+            cover,
+        },
+        {
+            id: 2,
+            type: "stress",
+            title: stressData
+                ? `当下胁迫: ${entry?.weatherStress || stressData.stress_name || "胁迫"}`
+                : "",
+            desc: stressData?.explain_simple || stressData?.interact_explain || "",
+            date: pickReportDate(stressData),
+            cover,
+        },
+        {
+            id: 3,
+            type: "diagnosis",
+            title: diagnosisCard?.title || "",
+            desc: diagnosisCard?.desc || "",
+            date: diagnosisCard?.date || "",
+            cover,
+        },
+    ].filter((item) => item.title || item.desc);
+}
 
 const showUploadPopup = ref(false);
 const showCompleteFarmPopup = ref(false);
@@ -466,12 +562,6 @@ const fillMockLabels = () => {
     const cropName = resolveSelectedCropName();
     zoneList.value = zoneList.value.map((item) => ({ ...item, name: cropName }));
     albumList.value = albumList.value.map((item) => ({ ...item, name: cropName }));
-    reportList.value = reportList.value.map((item) => ({
-        ...item,
-        title: t("agriFile.reportTitle"),
-        desc: t("agriFile.reportDesc"),
-        date: t("agriFile.reportDate"),
-    }));
     cropArchiveList.value = [
         ...readCropArchiveAnswers(),
         ...MOCK_CROP_ARCHIVE.map((item) => ({
@@ -554,6 +644,7 @@ async function loadPatrolContent() {
     await fetchPatrolGrowthInteract();
     await fetchPatrolAbnormalInteract();
     await fetchCropQuestionAlbumPic();
+    await fetchReportList();
 }
 
 const goAddZone = (type) => {
@@ -584,6 +675,22 @@ const goGrowthTrack = (item) => {
     });
 };
 
+/** 诊断报告:风险/胁迫进详情页,种植诊断报告进报告页 */
+const goReportDetail = (item) => {
+    if (!item) return;
+    if (item.type === "diagnosis") {
+        router.push("/diagnosis_report");
+        return;
+    }
+    router.push({
+        path: "/alert_detail",
+        query: {
+            title: item.title || "具体预警",
+            detailType: item.type || "",
+        },
+    });
+};
+
 const handleShare = (item) => {
     const query = {
         askInfo: { title: "转发巡园要点", content: "是否分享给好友" },

+ 2 - 2
src/views/old_mini/growth_report/index.vue

@@ -153,7 +153,7 @@ function resolveUserTel() {
 /** 未来预警卡片:risk_report → explain_simple */
 async function fetchRiskReport() {
     // TODO: 接口有正式数据后改回 resolveUserTel()
-    const tel = "13232323233";
+    const tel = resolveUserTel();
     if (!tel) {
         weatherRiskExplain.value = "";
         return;
@@ -177,7 +177,7 @@ async function fetchRiskReport() {
 /** 当下胁迫卡片:stress_report → explain_simple */
 async function fetchStressReport() {
     // TODO: 接口有正式数据后改回 resolveUserTel()
-    const tel = "13232323233";
+    const tel = resolveUserTel();
     if (!tel) {
         weatherStressExplain.value = "";
         return;