Selaa lähdekoodia

fix: 对接详情

lxf 2 päivää sitten
vanhempi
commit
38f4d3e6e8

+ 124 - 25
src/views/old_mini/agri_file/pages/abnormalTrack.vue

@@ -36,7 +36,7 @@
                             {{ t("agriFile.agriAssessment") }}
                         </div>
                         <div class="analysis-card__desc">{{ assessmentDesc }}</div>
-                        <div class="analysis-card__stats">
+                        <!-- <div class="analysis-card__stats">
                             <div v-for="(item, index) in analysisStats" :key="index" class="analysis-card__stat">
                                 <div class="analysis-card__stat-value" :class="{ highlight: item.highlight }">
                                     <template v-if="item.unit">
@@ -47,7 +47,7 @@
                                 </div>
                                 <div class="analysis-card__stat-label">{{ item.label }}</div>
                             </div>
-                        </div>
+                        </div> -->
                     </div>
                 </div>
 
@@ -66,35 +66,52 @@
 
                         <div class="stage-card interact-card">
                             <div class="work-info">
-                                <div class="interact-card__head">
-                                    <div class="section-title interact-card__title">
-                                        <span class="title-bar"></span>
-                                        {{ t("agriFile.interactQuestion") }}
+                                <!-- 已答:问题 + 答案一句 + 修改;点修改后回到选项态 -->
+                                <div v-if="isAnsweredView(item, index)" class="interact-card__answered">
+                                    <div class="interact-card__answered-text">
+                                        <span class="interact-card__answered-problem">{{
+                                            item.interact_problem
+                                        }}:</span>
+                                        <span class="interact-card__answered-value">{{
+                                            resolveAnswerText(item)
+                                        }}</span>
                                     </div>
-                                    <div
-                                        class="interact-card__submit"
-                                        :class="{ disabled: selectedMap[item.fw_code || index] == null }"
-                                        @click="handleSubmit(item, index)"
-                                    >
-                                        确认提交
+                                    <div class="interact-card__edit" @click="startEdit(item, index)">
+                                        修改
+                                        <el-icon class="interact-card__edit-icon"><Edit /></el-icon>
                                     </div>
                                 </div>
-                                <div class="interact-card__qa">
-                                    <div class="interact-card__question">{{ item.interact_problem }}</div>
-                                    <div class="interact-card__options">
+                                <template v-else>
+                                    <div class="interact-card__head">
+                                        <div class="section-title interact-card__title">
+                                            <span class="title-bar"></span>
+                                            {{ t("agriFile.interactQuestion") }}
+                                        </div>
                                         <div
-                                            v-for="(opt, optIndex) in item.options"
-                                            :key="`${item.fw_code || index}-${optIndex}`"
-                                            class="interact-option"
-                                            :class="{
-                                                selected: selectedMap[item.fw_code || index] === optIndex,
-                                            }"
-                                            @click="selectedMap[item.fw_code || index] = optIndex"
+                                            class="interact-card__submit"
+                                            :class="{ disabled: selectedMap[item.fw_code || index] == null }"
+                                            @click="handleSubmit(item, index)"
                                         >
-                                            <span class="interact-option__text">{{ opt }}</span>
+                                            确认提交
                                         </div>
                                     </div>
-                                </div>
+                                    <div class="interact-card__qa">
+                                        <div class="interact-card__question">{{ item.interact_problem }}</div>
+                                        <div class="interact-card__options">
+                                            <div
+                                                v-for="(opt, optIndex) in item.options"
+                                                :key="`${item.fw_code || index}-${optIndex}`"
+                                                class="interact-option"
+                                                :class="{
+                                                    selected: selectedMap[item.fw_code || index] === optIndex,
+                                                }"
+                                                @click="selectedMap[item.fw_code || index] = optIndex"
+                                            >
+                                                <span class="interact-option__text">{{ opt }}</span>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </template>
                             </div>
                         </div>
                         <!-- 巡园向导 -->
@@ -145,6 +162,7 @@ import { computed, nextTick, onActivated, reactive, ref } from "vue";
 import { useRoute, useRouter } from "vue-router";
 import { Icon } from "vant";
 import { ElMessage } from "element-plus";
+import { EditPen } from "@element-plus/icons-vue";
 import customHeader from "@/components/customHeader.vue";
 import albumUploadPopup from "../components/albumUploadPopup.vue";
 import tipPopup from "@/components/popup/tipPopup.vue";
@@ -176,6 +194,7 @@ const needDraw = ref(true); // status≠1 时需先勾画种植范围
 const interactList = ref([]); // ab_it_info.interact_Info 映射后的列表
 const stressInfo = ref({}); // 胁迫等级等公共信息
 const selectedMap = reactive({}); // fw_code/index → 选项下标
+const editingMap = reactive({}); // fw_code/index → 已答后点「修改」进入选项态
 /** 与查询共用的提交上下文,保证 fw 答案与列表同源 */
 const queryContext = ref({
     farm_id: null,
@@ -273,13 +292,48 @@ function parseInteractOptions(value) {
     return [];
 }
 
+/** 已答文案:提交字段为 options,回显兼容 answer / interact_answer / 字符串 options */
+function resolveAnswerText(item) {
+    const raw =
+        item?.answerText ||
+        item?.answer ||
+        item?.interact_answer ||
+        item?.fw_answer ||
+        (typeof item?.options === "string" ? item.options : "");
+    return raw != null && raw !== "" ? String(raw) : "";
+}
+
 function mapInteractItem(raw) {
+    const optionsStr =
+        typeof raw?.options === "string" && raw.options.trim() && !raw.options.trim().startsWith("[")
+            ? raw.options
+            : "";
     return {
         ...raw,
         options: parseInteractOptions(raw?.interact_options),
+        answerText: String(raw?.answer ?? raw?.interact_answer ?? raw?.fw_answer ?? optionsStr ?? ""),
     };
 }
 
+function interactKey(item, index) {
+    return item?.fw_code || index;
+}
+
+/** 已答且未进入修改态 */
+function isAnsweredView(item, index) {
+    return Number(item?.is_answered) === 1 && !editingMap[interactKey(item, index)];
+}
+
+/** 点修改:回到选项,并尽量回填当前答案 */
+function startEdit(item, index) {
+    const key = interactKey(item, index);
+    editingMap[key] = true;
+    const answer = resolveAnswerText(item);
+    if (!answer || !Array.isArray(item?.options)) return;
+    const optIndex = item.options.findIndex((opt) => opt === answer);
+    if (optIndex >= 0) selectedMap[key] = optIndex;
+}
+
 const formatLocalDate = (date) => {
     const y = date.getFullYear();
     const m = String(date.getMonth() + 1).padStart(2, "0");
@@ -417,7 +471,7 @@ const handleComplete = () => {
 };
 
 const handleSubmit = async (item, index) => {
-    const key = item?.fw_code || index;
+    const key = interactKey(item, index);
     const optIndex = selectedMap[key];
     if (optIndex == null) {
         ElMessage.warning(t("agriFile.pleaseSelectOption"));
@@ -438,6 +492,7 @@ const handleSubmit = async (item, index) => {
         });
         if (res?.code === 200) {
             ElMessage.success(t("agriFile.submitSuccess"));
+            editingMap[key] = false;
             await fetchAbnormalInteract();
             return;
         }
@@ -799,6 +854,50 @@ onActivated(() => {
             margin-bottom: 12px;
         }
 
+        &__answered {
+            display: flex;
+            align-items: center;
+            justify-content: space-between;
+            gap: 6px;
+        }
+
+        &__answered-text {
+            flex: 1;
+            min-width: 0;
+            font-size: 14px;
+            line-height: 22px;
+            word-break: break-all;
+        }
+
+        &__answered-problem {
+            color: rgba(255, 255, 255, 0.85);
+        }
+
+        &__answered-value {
+            padding-left: 4px;
+            color: #ffd489;
+        }
+
+        &__edit {
+            flex-shrink: 0;
+            display: inline-flex;
+            align-items: center;
+            gap: 4px;
+            height: 22px;
+            padding: 0 10px;
+            border-radius: 12px;
+            background: rgba(255, 212, 137, 0.1);
+            color: #ffd489;
+            font-size: 12px;
+            line-height: 22px;
+            box-sizing: border-box;
+        }
+
+        &__edit-icon {
+            font-size: 12px;
+            color: #ffd489;
+        }
+
         &__options {
             display: flex;
             gap: 12px;

+ 3 - 3
src/views/old_mini/agri_file/pages/growthTrack.vue

@@ -35,7 +35,7 @@
                             {{ t("agriFile.agriAssessment") }}
                         </div>
                         <div class="analysis-card__desc">{{ assessmentDesc }}</div>
-                        <div class="analysis-card__stats">
+                        <!-- <div class="analysis-card__stats">
                             <div
                                 v-for="(item, index) in analysisStats"
                                 :key="index"
@@ -50,7 +50,7 @@
                                 </div>
                                 <div class="analysis-card__stat-label">{{ item.label }}</div>
                             </div>
-                        </div>
+                        </div> -->
                     </div>
                 </div>
 
@@ -445,7 +445,7 @@ onActivated(() => {
         flex: 1;
         overflow-y: auto;
         -webkit-overflow-scrolling: touch;
-        padding-bottom: 100px;
+        padding-bottom: 20px;
         box-sizing: border-box;
     }
 

+ 124 - 25
src/views/old_mini/agri_file/pages/soilRootTrack.vue

@@ -36,7 +36,7 @@
                             {{ t("agriFile.agriAssessment") }}
                         </div>
                         <div class="analysis-card__desc">{{ assessmentDesc }}</div>
-                        <div class="analysis-card__stats">
+                        <!-- <div class="analysis-card__stats">
                             <div v-for="(item, index) in analysisStats" :key="index" class="analysis-card__stat">
                                 <div class="analysis-card__stat-value" :class="{ highlight: item.highlight }">
                                     <template v-if="item.unit">
@@ -47,7 +47,7 @@
                                 </div>
                                 <div class="analysis-card__stat-label">{{ item.label }}</div>
                             </div>
-                        </div>
+                        </div> -->
                     </div>
                 </div>
 
@@ -66,35 +66,52 @@
 
                         <div class="stage-card interact-card">
                             <div class="work-info">
-                                <div class="interact-card__head">
-                                    <div class="section-title interact-card__title">
-                                        <span class="title-bar"></span>
-                                        {{ t("agriFile.interactQuestion") }}
+                                <!-- 已答:问题 + 答案一句 + 修改;点修改后回到选项态 -->
+                                <div v-if="isAnsweredView(item, index)" class="interact-card__answered">
+                                    <div class="interact-card__answered-text">
+                                        <span class="interact-card__answered-problem">{{
+                                            item.interact_problem
+                                        }}:</span>
+                                        <span class="interact-card__answered-value">{{
+                                            resolveAnswerText(item)
+                                        }}</span>
                                     </div>
-                                    <div
-                                        class="interact-card__submit"
-                                        :class="{ disabled: selectedMap[item.fw_code || index] == null }"
-                                        @click="handleSubmit(item, index)"
-                                    >
-                                        确认提交
+                                    <div class="interact-card__edit" @click="startEdit(item, index)">
+                                        修改
+                                        <el-icon class="interact-card__edit-icon"><Edit /></el-icon>
                                     </div>
                                 </div>
-                                <div class="interact-card__qa">
-                                    <div class="interact-card__question">{{ item.interact_problem }}</div>
-                                    <div class="interact-card__options">
+                                <template v-else>
+                                    <div class="interact-card__head">
+                                        <div class="section-title interact-card__title">
+                                            <span class="title-bar"></span>
+                                            {{ t("agriFile.interactQuestion") }}
+                                        </div>
                                         <div
-                                            v-for="(opt, optIndex) in item.options"
-                                            :key="`${item.fw_code || index}-${optIndex}`"
-                                            class="interact-option"
-                                            :class="{
-                                                selected: selectedMap[item.fw_code || index] === optIndex,
-                                            }"
-                                            @click="selectedMap[item.fw_code || index] = optIndex"
+                                            class="interact-card__submit"
+                                            :class="{ disabled: selectedMap[item.fw_code || index] == null }"
+                                            @click="handleSubmit(item, index)"
                                         >
-                                            <span class="interact-option__text">{{ opt }}</span>
+                                            确认提交
                                         </div>
                                     </div>
-                                </div>
+                                    <div class="interact-card__qa">
+                                        <div class="interact-card__question">{{ item.interact_problem }}</div>
+                                        <div class="interact-card__options">
+                                            <div
+                                                v-for="(opt, optIndex) in item.options"
+                                                :key="`${item.fw_code || index}-${optIndex}`"
+                                                class="interact-option"
+                                                :class="{
+                                                    selected: selectedMap[item.fw_code || index] === optIndex,
+                                                }"
+                                                @click="selectedMap[item.fw_code || index] = optIndex"
+                                            >
+                                                <span class="interact-option__text">{{ opt }}</span>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </template>
                             </div>
                         </div>
                         <!-- 巡园向导 -->
@@ -243,6 +260,7 @@ import { computed, nextTick, onActivated, reactive, ref } from "vue";
 import { useRoute, useRouter } from "vue-router";
 import { Icon } from "vant";
 import { ElMessage } from "element-plus";
+import { Edit } from "@element-plus/icons-vue";
 import customHeader from "@/components/customHeader.vue";
 import albumUploadPopup from "../components/albumUploadPopup.vue";
 import tipPopup from "@/components/popup/tipPopup.vue";
@@ -276,6 +294,7 @@ const soilSections = ref([]); // 土壤条件判断(质地/酸碱/墒情/氮
 const sectionSelected = reactive({}); // section.key → 选中值(多选为数组)
 const stressInfo = ref({}); // 胁迫等级等公共信息
 const selectedMap = reactive({}); // fw_code/index → 选项下标
+const editingMap = reactive({}); // fw_code/index → 已答后点「修改」进入选项态
 /** 与查询共用的提交上下文,保证 fw 答案与列表同源 */
 const queryContext = ref({
     farm_id: null,
@@ -373,13 +392,48 @@ function parseInteractOptions(value) {
     return [];
 }
 
+/** 已答文案:提交字段为 options,回显兼容 answer / interact_answer / 字符串 options */
+function resolveAnswerText(item) {
+    const raw =
+        item?.answerText ||
+        item?.answer ||
+        item?.interact_answer ||
+        item?.fw_answer ||
+        (typeof item?.options === "string" ? item.options : "");
+    return raw != null && raw !== "" ? String(raw) : "";
+}
+
 function mapInteractItem(raw) {
+    const optionsStr =
+        typeof raw?.options === "string" && raw.options.trim() && !raw.options.trim().startsWith("[")
+            ? raw.options
+            : "";
     return {
         ...raw,
         options: parseInteractOptions(raw?.interact_options),
+        answerText: String(raw?.answer ?? raw?.interact_answer ?? raw?.fw_answer ?? optionsStr ?? ""),
     };
 }
 
+function interactKey(item, index) {
+    return item?.fw_code || index;
+}
+
+/** 已答且未进入修改态 */
+function isAnsweredView(item, index) {
+    return Number(item?.is_answered) === 1 && !editingMap[interactKey(item, index)];
+}
+
+/** 点修改:回到选项,并尽量回填当前答案 */
+function startEdit(item, index) {
+    const key = interactKey(item, index);
+    editingMap[key] = true;
+    const answer = resolveAnswerText(item);
+    if (!answer || !Array.isArray(item?.options)) return;
+    const optIndex = item.options.findIndex((opt) => opt === answer);
+    if (optIndex >= 0) selectedMap[key] = optIndex;
+}
+
 const formatLocalDate = (date) => {
     const y = date.getFullYear();
     const m = String(date.getMonth() + 1).padStart(2, "0");
@@ -522,7 +576,7 @@ const handleComplete = () => {
 };
 
 const handleSubmit = async (item, index) => {
-    const key = item?.fw_code || index;
+    const key = interactKey(item, index);
     const optIndex = selectedMap[key];
     if (optIndex == null) {
         ElMessage.warning(t("agriFile.pleaseSelectOption"));
@@ -543,6 +597,7 @@ const handleSubmit = async (item, index) => {
         });
         if (res?.code === 200) {
             ElMessage.success(t("agriFile.submitSuccess"));
+            editingMap[key] = false;
             await fetchSoilRootInteract();
             return;
         }
@@ -1001,6 +1056,50 @@ onActivated(() => {
             margin-bottom: 12px;
         }
 
+        &__answered {
+            display: flex;
+            align-items: center;
+            justify-content: space-between;
+            gap: 6px;
+        }
+
+        &__answered-text {
+            flex: 1;
+            min-width: 0;
+            font-size: 14px;
+            line-height: 22px;
+            word-break: break-all;
+        }
+
+        &__answered-problem {
+            color: rgba(255, 255, 255, 0.85);
+        }
+
+        &__answered-value {
+            padding-left: 4px;
+            color: #ffd489;
+        }
+
+        &__edit {
+            flex-shrink: 0;
+            display: inline-flex;
+            align-items: center;
+            gap: 4px;
+            height: 22px;
+            padding: 0 10px;
+            border-radius: 12px;
+            background: rgba(255, 212, 137, 0.1);
+            color: #ffd489;
+            font-size: 12px;
+            line-height: 22px;
+            box-sizing: border-box;
+        }
+
+        &__edit-icon {
+            font-size: 12px;
+            color: #ffd489;
+        }
+
         &__options {
             display: flex;
             gap: 12px;

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

@@ -367,8 +367,10 @@ function buildInteractCards(data = {}, ctx = {}) {
         }
     }
 
-    // 3. 土壤根系:问题 + 选项
-    pushOptionsCard("soil_root", data.soil_root, soilIcon);
+    // 3. 土壤根系:问题 + 选项;is_answered=1 已答则不展示
+    if (Number(data.soil_root?.is_answered) !== 1) {
+        pushOptionsCard("soil_root", data.soil_root, soilIcon);
+    }
     return cards;
 }
 

+ 43 - 15
src/views/old_mini/work_detail/index.vue

@@ -8,7 +8,7 @@
             :showClose="false"
             @goback="handleBack"
         />
-        <div class="work-detail-content" v-loading="detailLoading">
+        <div class="work-detail-content" v-loading="detailLoading" element-loading-text="加载中..." element-loading-background="rgba(15, 15, 15, 0.55)">
             <!-- 顶部状态:标准 / 气象 / 异常 / 已完成 -->
             <div class="content-status" :class="`is-${statusCardMode}`">
                 <div class="status-tags">
@@ -95,7 +95,7 @@
                             农情研判
                         </div>
                         <div class="analysis-card__desc">{{ displayExplain }}</div>
-                        <div class="analysis-card__stats">
+                        <!-- <div class="analysis-card__stats">
                             <div
                                 v-for="(item, index) in analysisStats"
                                 :key="index"
@@ -110,7 +110,7 @@
                                 </div>
                                 <div class="analysis-card__stat-label">{{ item.label }}</div>
                             </div>
-                        </div>
+                        </div> -->
                     </div>
                 </div>
 
@@ -332,12 +332,33 @@ const detailLoading = ref(false);
 const wktFmt = new WKT();
 const MAP_CENTER_FALLBACK = "POINT(113.1093017627431 22.57454083668)";
 
+/** 接口 zone → AreaMap 结构(读 zone_geometry;新接口字段为 polygon) */
+function mapZoneForAreaMap(zone) {
+    if (!zone || typeof zone !== "object") return null;
+    const wkt =
+        (typeof zone.polygon === "string" && zone.polygon.trim()) ||
+        (typeof zone.zone_geometry === "string" && zone.zone_geometry.trim()) ||
+        "";
+    if (!wkt) return null;
+    return {
+        zone_geometry: wkt,
+        zone_name: zone.zone_name || "",
+    };
+}
+
 const farmZones = computed(() => {
     const zones = farmData.value?.zones;
     if (!Array.isArray(zones)) return [];
-    return zones.filter(
-        (z) => z && typeof z.zone_geometry === "string" && z.zone_geometry.trim()
-    );
+    return zones.map(mapZoneForAreaMap).filter(Boolean);
+});
+
+/** fw 任务详情 data.zone;旧监控详情仍用 farmData.zones */
+const detailMapZones = computed(() => {
+    if (isFwTaskMode.value) {
+        const mapped = mapZoneForAreaMap(taskDetail.value?.zone);
+        return mapped ? [mapped] : [];
+    }
+    return farmZones.value;
 });
 
 /** 从地块 WKT 取首坐标作为初始中心,initZones 会 fit 到全部地块 */
@@ -360,8 +381,12 @@ function destroyWorkDetailMap() {
     areaMap.destroyMap();
 }
 
-/** 详情接口无经纬度时:优先选中农场点位 */
+/** 详情接口无经纬度时:优先 zone 点位,再选中农场点位 */
 function resolveFwMapPoint() {
+    const zone = taskDetail.value?.zone;
+    if (zone?.longitude != null && zone?.latitude != null) {
+        return `POINT(${zone.longitude} ${zone.latitude})`;
+    }
     const farm = getSelectedFarm();
     const candidates = [
         farm.farm_location,
@@ -381,13 +406,16 @@ function initWorkDetailMap() {
     nextTick(() => {
         if (!mapContainer.value) return;
         areaMap.destroyMap();
-        if (isFwTaskMode.value) {
-            areaMap.initMap(resolveFwMapPoint(), mapContainer.value);
+        const zones = detailMapZones.value;
+        if (zones.length) {
+            areaMap.initMap(wktCenterPointFromZones(zones), mapContainer.value);
+            areaMap.initZones(zones);
             return;
         }
-        const zones = farmZones.value;
-        areaMap.initMap(wktCenterPointFromZones(zones), mapContainer.value);
-        areaMap.initZones(zones);
+        areaMap.initMap(
+            isFwTaskMode.value ? resolveFwMapPoint() : MAP_CENTER_FALLBACK,
+            mapContainer.value
+        );
     });
 }
 
@@ -677,12 +705,12 @@ const displayNotes = computed(
         farmData.value?.precautions ||
         "注意事项注意事项注意事项注意事项注意事项注意事项"
 );
+/** 执行区域标题旁:分区名称(data.zone.zone_name) */
 const displayAreaCode = computed(() => {
     if (isFwTaskMode.value) {
-        const zoneId = fwTaskQuery.value.zone_id;
-        return zoneId != null ? `分区 ${zoneId}` : "编码";
+        return taskDetail.value?.zone?.zone_name || "编码";
     }
-    return "ws0gefwg9tdn";
+    return farmZones.value[0]?.zone_name || farmData.value?.zone_name || "编码";
 });
 
 /** 农资表格:接口未返回 materials,写死 */

+ 1 - 0
src/views/old_mini/work_execute/index.vue

@@ -93,6 +93,7 @@
                                     派发工人
                                 </div>
                                 <div
+                                    v-if="item.status !== 'completed'"
                                     class="card-btn card-btn--primary"
                                     :class="{ disabled: completeSubmittingId === item.id }"
                                     @click.stop="handleMarkComplete(item)"

+ 2 - 2
vue.config.js

@@ -45,8 +45,8 @@ module.exports = {
             }
         },
         //这里的ip和端口是前端项目的;下面为需要跨域访问后端项目
-        host:"127.0.0.1",
-        port: '8081',
+        host:"0.0.0.0",
+        port: '8080',
         https: false,
         open: false // 配置自动启动浏览器
     },