فهرست منبع

fix:修改bug

wangsisi 3 هفته پیش
والد
کامیت
4dc0360238

+ 36 - 6
src/components/popup/diagnosisReportPopup.vue

@@ -62,20 +62,54 @@ const markPopupShown = (tel) => {
     localStorage.setItem(getShownCacheKey(tel), "1");
 };
 
+/** 当前选中农场;接口必传 farm_id / zone_id */
+const readSelectedFarm = () => {
+    try {
+        return JSON.parse(localStorage.getItem("selectedFarmData") || "null") || {};
+    } catch {
+        return {};
+    }
+};
+
+const readFarmId = () => {
+    const farm = readSelectedFarm();
+    const id = farm.farm_id ?? farm.id;
+    if (id != null && id !== "") return id;
+    return localStorage.getItem("selectedFarmId") || "";
+};
+
+const readZoneId = () => {
+    const farm = readSelectedFarm();
+    const id = farm.zone_id ?? farm.zoneId;
+    return id != null && id !== "" ? id : "";
+};
+
+let checking = false;
+
 /** exists=2 且本地未展示过时弹窗(不依赖物候确认) */
 const checkShouldShow = async () => {
     const tel = readEntryFarmPhone();
-    if (!tel || hasShownPopup(tel)) {
+    const farmId = readFarmId();
+    const zoneId = readZoneId();
+    if (checking) return;
+    if (!tel || !farmId || !zoneId || hasShownPopup(tel)) {
         visible.value = false;
         return;
     }
+    checking = true;
     try {
-        const res = await VE_API.questionnaire.checkReportGenerated({ tel });
+        const res = await VE_API.questionnaire.checkReportGenerated({
+            tel,
+            farm_id: farmId,
+            zone_id: zoneId,
+        });
         const shouldShow = res?.code === 200 && Number(res?.data?.exists) === 2;
         visible.value = shouldShow;
         if (shouldShow) markPopupShown(tel);
     } catch {
         visible.value = false;
+    } finally {
+        checking = false;
     }
 };
 
@@ -91,10 +125,6 @@ watch(visible, (val, oldVal) => {
     if (oldVal && !val) markPopupShown(readEntryFarmPhone());
 });
 
-onMounted(() => {
-    checkShouldShow();
-});
-
 onActivated(() => {
     checkShouldShow();
 });

+ 1 - 1
src/i18n/messages.js

@@ -355,7 +355,7 @@ export default {
             before: "前",
             after: "后",
             fromFarm: "来自某某农场农场",
-            noData: "近期暂无农事",
+            noData: "近期暂无待做农事",
             all: "全部",
             highRisk: "高风险",
             executeAreaLabel: "执行区域:",

+ 38 - 6
src/views/old_mini/agri_file/pages/diagnosisReport.vue

@@ -80,17 +80,20 @@
             @switchGrowing="handleSwitchGrowing"
         />
         <editPlantPointPopup ref="editPlantPointPopupRef" @confirm="handlePlantPointConfirm" />
+        <complete-farm-info-popup v-model:show="showCompleteFarmPopup" @confirm="goCompleteFarmInfo" />
     </div>
 </template>
 
 <script setup>
-import { computed, onActivated, onMounted, ref } from "vue";
+import { computed, onActivated, ref } from "vue";
 import { useRouter } from "vue-router";
+import { useStore } from "vuex";
 import { ElMessage } from "element-plus";
 import { Plus, Edit } from "@element-plus/icons-vue";
 import adjustPhenologyPopup from "../components/adjustPhenologyPopup.vue";
 import restingDatePopup from "../components/restingDatePopup.vue";
 import editPlantPointPopup from "../components/editPlantPointPopup.vue";
+import completeFarmInfoPopup from "@/components/popup/completeFarmInfoPopup.vue";
 import tab1Icon from "@/assets/img/report/tab-1.png";
 import tab2Icon from "@/assets/img/report/tab-2.png";
 import tab3Icon from "@/assets/img/report/tab-3.png";
@@ -101,6 +104,7 @@ import tab5Icon from "@/assets/img/report/tab-5.png";
 // Props / Emits — 无
 // ---------------------------------------------------------------------------
 const router = useRouter();
+const store = useStore();
 
 // ---------------------------------------------------------------------------
 // 常量
@@ -146,6 +150,7 @@ const activeReportTab = ref("weather");
 const adjustPhenologyPopupRef = ref(null);
 const restingDatePopupRef = ref(null);
 const editPlantPointPopupRef = ref(null);
+const showCompleteFarmPopup = ref(false); // 无农场时展示「完善农场信息」
 
 // ---------------------------------------------------------------------------
 // 计算属性
@@ -163,6 +168,10 @@ const activeReportHtml = computed(() => {
 // ---------------------------------------------------------------------------
 // 工具函数
 // ---------------------------------------------------------------------------
+function getMiniUserId() {
+    return store.state.home.miniUserId || localStorage.getItem("MINI_USER_ID");
+}
+
 function getSelectedFarm() {
     try {
         return JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
@@ -320,8 +329,25 @@ function resetReportView(farm = {}) {
 }
 
 // ---------------------------------------------------------------------------
-// 业务逻辑:加载报告
+// 业务逻辑:无农场弹窗 / 加载报告
 // ---------------------------------------------------------------------------
+/** 无果园信息时展示「完善农场信息」弹窗 */
+async function checkCompleteFarmPopup() {
+    const id = getMiniUserId();
+    if (!id) {
+        showCompleteFarmPopup.value = false;
+        return;
+    }
+    try {
+        const res = await VE_API.questionnaire.getFarms({ id });
+        const list = Array.isArray(res?.data) ? res.data : [];
+        showCompleteFarmPopup.value = list.length === 0;
+    } catch (e) {
+        console.warn("[diagnosisReport] getFarms failed", e);
+        showCompleteFarmPopup.value = false;
+    }
+}
+
 async function fetchDiagnosisReport() {
     const farm = getSelectedFarm();
     const farmId = farm.farm_id ?? farm.id;
@@ -345,7 +371,7 @@ async function fetchDiagnosisReport() {
             return;
         }
         resetReportView(farm);
-        ElMessage.warning(res?.msg || res?.message || "暂无诊断报告");
+        ElMessage.warning(res?.msg || res?.message || "报告正在生成中...");
     } catch (error) {
         console.error("fetchDiagnosisReport failed", error);
         resetReportView(farm);
@@ -390,9 +416,15 @@ const handlePlantPointConfirm = (payload) => {
     console.log("plant point confirm:", payload);
 };
 
-// onMounted(fetchDiagnosisReport);
-// tabbar 切换时组件被 keep-alive 缓存,需在激活时重新拉报告
-onActivated(fetchDiagnosisReport);
+const goCompleteFarmInfo = () => {
+    router.push("/entry_information");
+};
+
+// tabbar 切换时组件被 keep-alive 缓存,需在激活时重新拉报告 / 校验农场
+onActivated(() => {
+    checkCompleteFarmPopup();
+    fetchDiagnosisReport();
+});
 </script>
 
 <style lang="scss" scoped>

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

@@ -35,6 +35,8 @@
                             maxlength="11"
                             clearable
                             type="tel"
+                            inputmode="numeric"
+                            @input="onPhoneInput"
                         />
                     </el-form-item>
                     <el-form-item label="常驻点位" prop="location" class="location-form-item">
@@ -111,6 +113,11 @@ function readJson(key) {
     }
 }
 
+/** 手机号仅保留数字,最多 11 位(type=number 时 maxlength 不生效) */
+function onPhoneInput(val) {
+    form.phone = String(val ?? "").replace(/\D/g, "").slice(0, 11);
+}
+
 function saveFormDraft() {
     sessionStorage.setItem(
         FORM_KEY,
@@ -122,7 +129,7 @@ function restoreFormDraft() {
     const draft = readJson(FORM_KEY);
     if (!draft) return;
     if (draft.name != null) form.name = draft.name;
-    if (draft.phone != null) form.phone = draft.phone;
+    if (draft.phone != null) form.phone = String(draft.phone).replace(/\D/g, "").slice(0, 11);
 }
 
 function utilWktToCoordinate(point) {

+ 1 - 0
src/views/old_mini/entry_information/components/selectEquipment.vue

@@ -75,6 +75,7 @@
             :text="isService ? '您的信息已提交成功' : '您的信息已上传'"
             :text2="isService ? '' : '请等待诊断报告生成'"
             buttonText="完成"
+            :close-on-click-overlay="false"
             @confirm="handleComplete"
         />