|
|
@@ -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>
|