浏览代码

feat:对接作物档案接口和农事页面跳转

wangsisi 2 周之前
父节点
当前提交
07165f6fb9
共有 3 个文件被更改,包括 76 次插入 和 16 次删除
  1. 5 0
      src/api/modules/questionnaire.js
  2. 68 14
      src/views/old_mini/agri_file/index.vue
  3. 3 2
      src/views/old_mini/work_detail/index.vue

+ 5 - 0
src/api/modules/questionnaire.js

@@ -76,6 +76,11 @@ module.exports = {
         url: config.base_new_url + "report/get_phenophase",
         type: "get",
     },
+    // 作物档案:物候期信息列表
+    getPhenophaseInfo: {
+        url: config.base_new_url + "report/get_phenophase_info",
+        type: "get",
+    },
     // 气象风险报告
     riskReport: {
         url: config.base_new_url + "report/risk_report",

+ 68 - 14
src/views/old_mini/agri_file/index.vue

@@ -371,13 +371,56 @@ const patrolIcon = require("@/assets/img/report/wh-icon.png");
 /** 巡园要点列表:接口 data 原样 push,字段在模板自行对接 */
 const patrolList = ref([]);
 
-const MOCK_CROP_ARCHIVE = [
-    { id: "mock-2", date: "2025-04-18", contentKey: "agriFile.cropArchiveAbnormal" },
-    { id: "mock-3", date: "2025-04-10", contentKey: "agriFile.cropArchiveMetric" },
-];
-
 const cropArchiveList = ref([]);
 
+function resolveUserTel() {
+    try {
+        const entry = JSON.parse(localStorage.getItem(ENTRY_FARM_DATA_KEY) || "null");
+        if (entry?.phone) return String(entry.phone).trim();
+    } catch {
+        // ignore
+    }
+    try {
+        const userInfo = JSON.parse(localStorage.getItem("localUserInfo") || "{}");
+        return String(userInfo.tel || userInfo.phone || userInfo.mobile || "").trim();
+    } catch {
+        return "";
+    }
+}
+
+function formatPhenophaseDate(value) {
+    if (!value) return "";
+    const text = String(value).trim();
+    const iso = text.match(/(\d{4})-(\d{2})-(\d{2})/);
+    if (iso) return `${iso[1]}-${iso[2]}-${iso[3]}`;
+    const d = new Date(text);
+    if (Number.isNaN(d.getTime())) return "";
+    return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
+}
+
+/** get_phenophase_info → 作物档案时间轴 */
+function mapPhenophaseInfoToArchive(list) {
+    const cropName = resolveSelectedCropName();
+    const rows = Array.isArray(list) ? list : [];
+    const filtered = cropName
+        ? rows.filter((item) => !item?.crop_category_name || item.crop_category_name === cropName)
+        : rows;
+    const source = filtered.length ? filtered : rows;
+    return source
+        .map((item, index) => ({
+            id: item?.phenophase_code
+                ? `${item.phenophase_code}-${item.start_time || index}`
+                : `pheno-${index}`,
+            date: formatPhenophaseDate(item?.start_time) || formatPhenophaseDate(item?.sentence),
+            zone_name: item?.crop_category_name || cropName || "",
+            content: item?.sentence || item?.phenophase_name || "",
+            phenophase_code: item?.phenophase_code,
+            phenophase_name: item?.phenophase_name,
+        }))
+        .filter((item) => item.date && item.content)
+        .sort((a, b) => String(b.date).localeCompare(String(a.date)));
+}
+
 function readCropArchiveAnswers() {
     try {
         const list = JSON.parse(localStorage.getItem(CROP_ARCHIVE_KEY) || "[]");
@@ -387,6 +430,25 @@ function readCropArchiveAnswers() {
     }
 }
 
+async function fetchCropArchiveList() {
+    const tel = resolveUserTel();
+    if (!tel) {
+        cropArchiveList.value = readCropArchiveAnswers();
+        return;
+    }
+    try {
+        const res = await VE_API.questionnaire.getPhenophaseInfo({ tel });
+        if (res?.code !== 200) {
+            cropArchiveList.value = readCropArchiveAnswers();
+            return;
+        }
+        const apiList = mapPhenophaseInfoToArchive(res.data);
+        cropArchiveList.value = [...readCropArchiveAnswers(), ...apiList];
+    } catch {
+        cropArchiveList.value = readCropArchiveAnswers();
+    }
+}
+
 const setMarkerEl = (id, el) => {
     if (el) markerEls[id] = el;
     else delete markerEls[id];
@@ -472,15 +534,6 @@ const fillMockLabels = () => {
         desc: t("agriFile.reportDesc"),
         date: t("agriFile.reportDate"),
     }));
-    cropArchiveList.value = [
-        ...readCropArchiveAnswers(),
-        ...MOCK_CROP_ARCHIVE.map((item) => ({
-            id: item.id,
-            date: item.date,
-            zone_name: cropName,
-            content: t(item.contentKey),
-        })),
-    ];
 };
 
 /**
@@ -554,6 +607,7 @@ async function loadPatrolContent() {
     await fetchPatrolGrowthInteract();
     await fetchPatrolAbnormalInteract();
     await fetchCropQuestionAlbumPic();
+    await fetchCropArchiveList();
 }
 
 const goAddZone = (type) => {

+ 3 - 2
src/views/old_mini/work_detail/index.vue

@@ -193,7 +193,7 @@ import WKT from "ol/format/WKT.js";
 import { time } from "echarts";
 
 const route = useRoute();
-const { locale } = useI18n();
+const { locale, t } = useI18n();
 const showUploadTipsPopup = ref(false);
 const router = useRouter();
 // const info = JSON.parse(localStorage.getItem("localUserInfo") || "{}");
@@ -771,7 +771,8 @@ const goGrowthTrack = () => {
         path: "/growth_track",
         query: {
             id: farmData.value?.id || workId.value || route.query.id,
-            type: farmData.value?.type || "growth",
+            type: "abnormal",
+            pageName: t("agriFile.patrolAbnormalTitle"),
         },
     });
 };