Browse Source

feat:对接农事档案外面长势的接口

wangsisi 2 tuần trước cách đây
mục cha
commit
b513388eb3

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

@@ -41,6 +41,11 @@ module.exports = {
         url: config.base_new_url + "report/crop_question",
         type: "get",
     },
+    // 巡园互动解析(长势跟踪要点)
+    parseInteract: {
+        url: config.base_new_url + "report/parse_interact",
+        type: "get",
+    },
     // 暂未到达物候
     adjustPhenology: {
         url: config.base_new_url + "report/adjust_phenophase",

+ 86 - 50
src/views/old_mini/agri_file/index.vue

@@ -30,40 +30,50 @@
         </div>
         <div class="content-panel">
             <div v-show="activeNav === 'patrol'">
-                <div v-for="item in patrolList" :key="item.id" class="tracking-item"
-                    :class="`tracking-item--${item.theme}`" @click="goGrowthTrack(item)">
+                <div
+                    v-for="(item, index) in patrolList"
+                    :key="index"
+                    class="tracking-item tracking-item--blue"
+                    @click="goGrowthTrack(item)"
+                >
                     <div class="tracking-item__header">
                         <div class="tracking-item__header-row">
                             <div class="tracking-item__header-left">
                                 <span class="tracking-item__level">
                                     <el-icon><BellFilled /></el-icon>
-                                    {{ item.level }}
+                                    {{ t("agriFile.riskLevel2") }}
                                 </span>
                                 <span class="tracking-item__title van-ellipsis">
-                                    {{ item.title }}<span v-if="item.zone" class="tracking-item__zone"> ({{ item.zone }})</span>
+                                    {{
+                                        item.type === "abnormal"
+                                            ? t("agriFile.patrolAbnormalTitle")
+                                            : t("agriFile.patrolGrowthTitle")
+                                    }}
+                                    <span
+                                        v-if="item.crop_category_name"
+                                        class="tracking-item__zone"
+                                    >
+                                        ({{ item.crop_category_name }})
+                                    </span>
+                                    <span
+                                        v-else-if="item.zone"
+                                        class="tracking-item__zone"
+                                    >
+                                        ({{ item.zone }})
+                                    </span>
                                 </span>
                             </div>
-                            <!-- <div class="tracking-item__share" @click.stop="handleShare(item)">
-                                <Icon size="14" color="#2199F8" name="share" />
-                                <span>{{ t("agriFile.forward") }}</span>
-                            </div> -->
                         </div>
                     </div>
                     <div class="tracking-item__body">
                         <div class="tracking-item__action">
                             <div class="tracking-item__action-main">
                                 <div class="tracking-item__icon">
-                                    <img :src="item.icon" alt="" />
-                                    <span class="tracking-item__reason">{{ item.subject }}</span>
+                                    <img :src="patrolIcon" alt="" />
+                                    <span class="tracking-item__reason">{{ item.interaction_problem }}</span>
                                 </div>
-                                <div class="tracking-item__issue">{{ item.issue }}</div>
+                                <div class="tracking-item__issue">{{ item.interaction_reason }}</div>
                             </div>
-                            <!-- <div class="tracking-item__btn" @click.stop="handleUploadClick(item)">
-                                <el-icon>
-                                    <Plus />
-                                </el-icon>
-                                <span>{{ t("agriFile.uploadPhoto") }}</span>
-                            </div> -->
                         </div>
                     </div>
                 </div>
@@ -245,6 +255,14 @@ function readEntryFarmCoordinate() {
     return null;
 }
 
+function readEntryFarmData() {
+    try {
+        return JSON.parse(localStorage.getItem(ENTRY_FARM_DATA_KEY) || "null");
+    } catch {
+        return null;
+    }
+}
+
 function buildZoneList(coordinate = readEntryFarmCoordinate() || DEFAULT_CENTER) {
     return [
         {
@@ -302,28 +320,9 @@ const handlePhenologyUpdateReject = () => {
 const handlePhenologyUpdateConfirm = () => {
     // TODO: 调用确认更新接口
 };
-const patrolList = ref([
-    {
-        id: 1,
-        type: "growth",
-        theme: "blue",
-        level: "",
-        title: "",
-        subject: "",
-        issue: "",
-        icon: require("@/assets/img/report/wh-icon.png"),
-    },
-    {
-        id: 2,
-        type: "abnormal",
-        theme: "blue",
-        level: "",
-        title: "",
-        subject: "",
-        issue: "",
-        icon: require("@/assets/img/report/wh-icon.png"),
-    },
-]);
+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" },
@@ -423,14 +422,6 @@ const fillMockLabels = () => {
         desc: t("agriFile.reportDesc"),
         date: t("agriFile.reportDate"),
     }));
-    patrolList.value = patrolList.value.map((item, index) => ({
-        ...item,
-        level: t("agriFile.riskLevel2"),
-        title: t(index === 0 ? "agriFile.patrolGrowthTitle" : "agriFile.patrolAbnormalTitle"),
-        zone: albumName,
-        subject: t("agriFile.patrolSubject"),
-        issue: t("agriFile.patrolIssue"),
-    }));
     cropArchiveList.value = [
         ...readCropArchiveAnswers(),
         ...MOCK_CROP_ARCHIVE.map((item) => ({
@@ -442,6 +433,52 @@ const fillMockLabels = () => {
     ];
 };
 
+/**
+ * 长势跟踪巡园要点:parse_interact
+ */
+async function fetchPatrolGrowthInteract() {
+    const entry = readEntryFarmData();
+    const cropCategoryName = entry?.crop;
+    const phenophaseCode = entry?.cropCode;
+    const riskName = entry?.weatherRisk;
+    if (!cropCategoryName || !phenophaseCode || !riskName) return;
+
+    try {
+        const res = await VE_API.questionnaire.parseInteract({
+            crop_category_name: cropCategoryName,
+            phenophase_code: String(phenophaseCode),
+            risk_name: riskName,
+        });
+        if (res.code !== 200) return;
+        const data = res.data;
+        if (Array.isArray(data)) {
+            patrolList.value.push(...data);
+        } else if (data) {
+            patrolList.value.push(data);
+        }
+    } catch {
+        // ignore
+    }
+}
+
+/** 异常态势暂未接接口,保留本地展示 */
+function buildAbnormalPatrolMock() {
+    return {
+        type: "abnormal",
+        zone: t("agriFile.zoneOne"),
+        interaction_problem: t("agriFile.patrolSubject"),
+        interaction_reason: t("agriFile.patrolIssue"),
+    };
+}
+
+async function loadPatrolContent() {
+    fillMockLabels();
+    patrolList.value = [];
+    await fetchPatrolGrowthInteract();
+    // 物候接口只负责长势项;异常项仍展示
+    patrolList.value.push(buildAbnormalPatrolMock());
+}
+
 const goAddZone = (type) => {
     router.push(
         {
@@ -461,7 +498,7 @@ const goAlbumMap = () => {
 const goGrowthTrack = (item) => {
     router.push({
         path: "/growth_track",
-        query: { id: item?.id, type: item?.type || "growth" },
+        query: { type: item?.type || "growth" },
     });
 };
 
@@ -560,13 +597,12 @@ const goAlbumDetail = (item) => {
 };
 
 onMounted(() => {
-    fillMockLabels();
     initAlbumMap();
     tryShowGuide();
     document.addEventListener("click", handleOutsideClick, true);
 });
 onActivated(() => {
-    fillMockLabels();
+    loadPatrolContent();
     initAlbumMap();
     tryShowGuide();
 });

+ 1 - 1
src/views/old_mini/entry_information/components/baInformation.vue

@@ -443,7 +443,7 @@ const handleNext = async () => {
         localStorage.setItem(HAS_FARM_KEY, "1");
         VE_API.questionnaire.generateReport({ region, crop, tel:form.phone }).catch(() => {});
         clearFormDraft();
-        ElMessage.success(res?.message || res?.msg || "上传成功,报告正在生成中...");
+        ElMessage.success("上传成功,报告正在生成中...");
         router.replace("/growth_report");
     } catch (e) {
         console.error("addPlotInfo failed", e);