lxf 2 týždňov pred
rodič
commit
19312a10d8

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

@@ -24,6 +24,7 @@ module.exports = {
     // 查看报告是否生成
     checkReportGenerated: {
         url: config.base_new_url + "report/check",
+        type: "get",
     },
     // 区县作物物候期(种植品类下拉)
     countyPhenophase: {

+ 63 - 19
src/components/popup/diagnosisReportPopup.vue

@@ -1,6 +1,6 @@
 <template>
     <popup
-        v-model:show="showValue"
+        v-model:show="visible"
         round
         teleport="body"
         class="diagnosis-report-popup"
@@ -18,30 +18,74 @@
 </template>
 
 <script setup>
-import { computed } from "vue";
+import { onMounted, ref, watch } from "vue";
+import { useRouter } from "vue-router";
 import { Popup } from "vant";
 import { useI18n } from "@/i18n";
 
 const { t } = useI18n();
+const router = useRouter();
 
-const props = defineProps({
-    show: {
-        type: Boolean,
-        default: false,
-    },
-});
+const ENTRY_FARM_DATA_KEY = "ENTRY_FARM_DATA";
+const SHOWN_CACHE_PREFIX = "DIAGNOSIS_REPORT_POPUP_SHOWN_";
 
-const emit = defineEmits(["update:show", "confirm"]);
+/** 弹窗显隐由组件内接口控制,默认不展示 */
+const visible = ref(false);
 
-const showValue = computed({
-    get: () => props.show,
-    set: (val) => emit("update:show", val),
-});
+const readEntryFarmPhone = () => {
+    try {
+        const data = JSON.parse(localStorage.getItem(ENTRY_FARM_DATA_KEY) || "null");
+        return data?.phone || "";
+    } catch {
+        return "";
+    }
+};
+
+const getShownCacheKey = (tel) => `${SHOWN_CACHE_PREFIX}${tel}`;
+
+const hasShownPopup = (tel) => !!localStorage.getItem(getShownCacheKey(tel));
+
+const markPopupShown = (tel) => {
+    if (!tel) return;
+    localStorage.setItem(getShownCacheKey(tel), "1");
+};
+
+/** exists=1 且本地未展示过时才弹窗 */
+const checkShouldShow = async () => {
+    const tel = readEntryFarmPhone();
+    if (!tel || hasShownPopup(tel)) {
+        visible.value = false;
+        return;
+    }
+    try {
+        const res = await VE_API.questionnaire.checkReportGenerated({ tel });
+        const shouldShow = res?.code === 200 && Number(res?.data?.exists) === 1;
+        visible.value = shouldShow;
+        if (shouldShow) markPopupShown(tel);
+    } catch {
+        visible.value = false;
+    }
+};
 
 const handleView = () => {
-    emit("confirm");
-    showValue.value = false;
+    const tel = readEntryFarmPhone();
+    markPopupShown(tel);
+    visible.value = false;
+    router.push("/diagnosis_report");
 };
+
+// 用户点遮罩关闭时也记为已展示,避免反复弹出
+watch(visible, (val, oldVal) => {
+    if (oldVal && !val) markPopupShown(readEntryFarmPhone());
+});
+
+onMounted(() => {
+    checkShouldShow();
+});
+
+defineExpose({
+    checkShouldShow,
+});
 </script>
 
 <style scoped lang="scss">
@@ -50,7 +94,7 @@ const handleView = () => {
     padding: 90px 20px 22px;
     text-align: center;
     overflow: visible;
-    background: linear-gradient(360deg, #FFFFFF 0%, #D3EBFF 100%);
+    background: linear-gradient(360deg, #ffffff 0%, #d3ebff 100%);
 
     &__image {
         display: block;
@@ -67,7 +111,7 @@ const handleView = () => {
         font-size: 30px;
         color: #010101;
         line-height: 32px;
-        div{
+        div {
             font-family: "pangmenzhengdao";
         }
     }
@@ -77,13 +121,13 @@ const handleView = () => {
         margin: 18px auto 10px;
         padding: 8px 0;
         border-radius: 25px;
-        background: linear-gradient(180deg, #96D1FF 0%, #2199F8 100%);
+        background: linear-gradient(180deg, #96d1ff 0%, #2199f8 100%);
         color: #fff;
         font-size: 16px;
     }
 
     &__hint {
-        color: #1D1919;
+        color: #1d1919;
     }
 }
 </style>

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

@@ -139,10 +139,8 @@
         <album-upload-popup v-model:show="showUploadPopup" />
         <complete-farm-info-popup v-model:show="showCompleteFarmPopup" @confirm="goCompleteFarmInfo" />
 
-        <!-- 诊断报告弹窗 -->
-        <diagnosis-report-popup 
-            v-model:show="showDiagnosisReportPopup"
-            @confirm="goDiagnosisReport" />
+        <!-- 诊断报告弹窗:组件内请求接口判断是否展示并跳转 -->
+        <diagnosis-report-popup />
 
         <!-- 恢复种植弹窗 -->
         <restore-planting-popup />
@@ -275,7 +273,6 @@ const reportList = ref([
 
 const showUploadPopup = ref(false);
 const showCompleteFarmPopup = ref(false);
-const showDiagnosisReportPopup = ref(false);
 // 后续由接口控制是否展示代管授权弹窗
 const showProxyAuthPopup = ref(false);
 const proxyServiceName = ref("农服名称");
@@ -551,10 +548,6 @@ const goCompleteFarmInfo = () => {
     router.push("/entry_information");
 };
 
-const goDiagnosisReport = () => {
-    router.push("/diagnosis_report");
-};
-
 const goAlbumDetail = (item) => {
     router.push({
         path: "/region_albums",

+ 2 - 4
src/views/old_mini/agri_file/pages/diagnosisReport.vue

@@ -283,10 +283,8 @@ const fetchReport = async () => {
     loading.value = true;
     reportData.value = null;
     try {
-        const res = await VE_API.questionnaire.generateReport({
-            region: entryFarmData.region,
-            crop: entryFarmData.crop,
-            phone: entryFarmData.phone,
+        const res = await VE_API.questionnaire.checkReportGenerated({
+            tel: entryFarmData.phone,
         });
         if (res?.code === 200 && res.data?.report) {
             reportData.value = parseReportMarkdown(res.data.report);