Kaynağa Gözat

fix: 初始化弹窗

lxf 2 hafta önce
ebeveyn
işleme
bb844a9f4b

+ 1 - 1
src/api/modules/questionnaire.js

@@ -41,7 +41,7 @@ module.exports = {
         url: config.base_new_url + "report/crop_question",
         type: "get",
     },
-    // 暂未到达物候
+    // 物候调整确认
     adjustPhenology: {
         url: config.base_new_url + "report/adjust_phenophase",
         type: "get",

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

@@ -28,6 +28,8 @@ const router = useRouter();
 
 const ENTRY_FARM_DATA_KEY = "ENTRY_FARM_DATA";
 const SHOWN_CACHE_PREFIX = "DIAGNOSIS_REPORT_POPUP_SHOWN_";
+/** 恢复种植弹窗确认「已到达」后写入,诊断报告弹窗依赖此缓存 */
+const PHENOLOGY_REACHED_PREFIX = "PHENOLOGY_REACHED_";
 
 /** 弹窗显隐由组件内接口控制,默认不展示 */
 const visible = ref(false);
@@ -42,18 +44,20 @@ const readEntryFarmPhone = () => {
 };
 
 const getShownCacheKey = (tel) => `${SHOWN_CACHE_PREFIX}${tel}`;
+const getPhenologyReachedKey = (tel) => `${PHENOLOGY_REACHED_PREFIX}${tel}`;
 
 const hasShownPopup = (tel) => !!localStorage.getItem(getShownCacheKey(tel));
+const hasPhenologyReached = (tel) => !!localStorage.getItem(getPhenologyReachedKey(tel));
 
 const markPopupShown = (tel) => {
     if (!tel) return;
     localStorage.setItem(getShownCacheKey(tel), "1");
 };
 
-/** exists=1 且本地未展示过时才弹窗 */
+/** 需先确认物候已到达,且 exists=1、本地未展示过时才弹窗 */
 const checkShouldShow = async () => {
     const tel = readEntryFarmPhone();
-    if (!tel || hasShownPopup(tel)) {
+    if (!tel || !hasPhenologyReached(tel) || hasShownPopup(tel)) {
         visible.value = false;
         return;
     }

+ 52 - 13
src/components/popup/restorePlantingPopup.vue

@@ -123,8 +123,9 @@ const PATROL_GUIDE_IMAGE_PATH =
     "e84a8f1b-9842-434c-951f-068ff6963f31/6c8b7135-95b7-4c04-82ef-a2daeb674d0c/DJI_202608190758_001_6c8b7135-95b7-4c04-82ef-a2daeb674d0c/DJI_20260819080818_0085_V_code-ws0fsmg8zg8u.jpeg";
 const patrolGuideImage = base_img_url2 + PATROL_GUIDE_IMAGE_PATH;
 
-/** adjustPhenology:暂未到达 / 已过 */
+/** adjustPhenology:已到达 / 暂未到达 / 已过 */
 const ADJUST_ACTION = {
+    reached: 0,
     not_reached: 1,
     passed: 2,
 };
@@ -142,6 +143,7 @@ const submitting = ref(false);
 /** 当前物候期编码,调整后用接口返回值替换 */
 const currentPhenophaseCode = ref("");
 const cropType = ref("");
+const userTel = ref("");
 
 const questionText = ref("");
 const highlightWord = ref("");
@@ -247,20 +249,31 @@ const fetchPhenologyProblem = async (phenophaseCode) => {
     return res.data;
 };
 
-/** 请求接口判断是否展示,并填充问题内容 */
+/** 先查报告状态,exists=2 不展示;否则拉取物候问题 */
 const checkShouldShow = async () => {
     const farm = readEntryFarmData();
     const crop = farm?.crop || "";
     const code = farm?.cropCode || "";
-    if (!crop || !code) {
+    const tel = farm?.phone || "";
+    if (!tel) {
         visible.value = false;
         return;
     }
 
     cropType.value = crop;
-    currentPhenophaseCode.value = String(code);
+    currentPhenophaseCode.value = String(code || "");
+    userTel.value = tel;
 
     try {
+        const checkRes = await VE_API.questionnaire.checkReportGenerated({ tel });
+        if (checkRes?.code !== 200 || Number(checkRes?.data?.exists) === 2) {
+            visible.value = false;
+            return;
+        }
+        if (!crop || !code) {
+            visible.value = false;
+            return;
+        }
         const data = await fetchPhenologyProblem(currentPhenophaseCode.value);
         applyQuestionData(data);
         visible.value = !!(data.phenophase_question_time || data.phenophase_question);
@@ -271,7 +284,7 @@ const checkShouldShow = async () => {
 
 /**
  * 暂未到达 / 已过:调 adjustPhenology,再用新 code 刷新问题二
- * @param {0|1} action 0=已过,1=暂未到达
+ * @param {0|1|2} action
  */
 const adjustAndRefreshQuestion = async (action) => {
     if (submitting.value) return;
@@ -280,6 +293,7 @@ const adjustAndRefreshQuestion = async (action) => {
         const adjustRes = await VE_API.questionnaire.adjustPhenology({
             phenophase_code: currentPhenophaseCode.value,
             action,
+            tel: userTel.value,
         });
         if (adjustRes?.code !== 200) {
             showMessage(adjustRes?.msg || "调整物候期失败", "error");
@@ -307,6 +321,36 @@ const adjustAndRefreshQuestion = async (action) => {
     }
 };
 
+/** 已到达:确认当前物候期 */
+const confirmReachedPhenology = async () => {
+    if (submitting.value) return false;
+    submitting.value = true;
+    try {
+        const res = await VE_API.questionnaire.adjustPhenology({
+            phenophase_code: currentPhenophaseCode.value,
+            action: ADJUST_ACTION.reached,
+            tel: userTel.value,
+        });
+        if (res?.code !== 200) {
+            showMessage(res?.msg || "提交失败,请稍后再试", "error");
+            return false;
+        }
+        // 供诊断报告弹窗判断:已确认物候后才可弹出
+        if (userTel.value) {
+            localStorage.setItem(`PHENOLOGY_REACHED_${userTel.value}`, "1");
+        }
+        showMessage(res.msg || "提交成功", "success");
+        visible.value = false;
+        resetForm();
+        return true;
+    } catch (err) {
+        showMessage(err?.response?.data?.msg || err?.message || "提交失败,请稍后再试", "error");
+        return false;
+    } finally {
+        submitting.value = false;
+    }
+};
+
 // ---------------------------------------------------------------------------
 // 事件处理 / 生命周期
 // ---------------------------------------------------------------------------
@@ -316,7 +360,7 @@ onMounted(() => {
 
 /**
  * 暂未到达 / 已过:调接口刷新问题;
- * 已到达:仅提示
+ * 已到达:仅选中,提交时再调接口
  */
 const handlePhenologySelect = async (value) => {
     if (value === "not_reached") {
@@ -330,9 +374,6 @@ const handlePhenologySelect = async (value) => {
         return;
     }
     phenologyAnswer.value = "reached";
-    showMessage("提交成功", "success");
-    visible.value = false;
-    resetForm();
 };
 
 const handleConfirm = async () => {
@@ -354,14 +395,12 @@ const handleConfirm = async () => {
         return;
     }
 
-    // 问题二:需选择「已到达」
+    // 问题二:需选择「已到达」后提交
     if (phenologyAnswer.value !== "reached") {
         showWarning("请确认当前物候期是否已到达");
         return;
     }
-    showMessage("已确认当前物候期", "success");
-    visible.value = false;
-    resetForm();
+    await confirmReachedPhenology();
 };
 
 defineExpose({

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

@@ -994,7 +994,8 @@ watch(activeNav, (key) => {
             width: 100%;
             margin-bottom: 16px;
             box-shadow: 0px 4px 4px 0px rgba(33, 153, 248, 0.1);
-
+            background: linear-gradient(180deg, #86CAFF 0%, #2199F8 49%);
+            border-radius: 10px;
 
             &:last-of-type {
                 margin-bottom: 0;
@@ -1004,7 +1005,7 @@ watch(activeNav, (key) => {
                 position: relative;
                 padding: 10px 10px 20px;
                 border-radius: 10px 10px 0 0;
-                background: linear-gradient(180deg, #86CAFF 0%, #2199F8 48.5%);
+                // background: linear-gradient(180deg, #86CAFF 0%, #2199F8 48.5%);
             }
 
             &__header-row {