index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <div class="agri-file-page" :style="{ height: `calc(100vh - ${tabBarHeight}px)` }">
  3. <!-- <div class="agri-file-page__header" /> -->
  4. <farm-header />
  5. <div class="nav-cards">
  6. <div
  7. v-for="item in navCards"
  8. :key="item.key"
  9. class="nav-card-wrap"
  10. :class="{ 'nav-card-wrap--report': item.key === 'report' }"
  11. >
  12. <div
  13. class="nav-card"
  14. :class="{ 'is-active': activeNav === item.key }"
  15. @click="handleNavClick(item)"
  16. >
  17. <span class="nav-card__label">{{ t(item.labelKey) }}</span>
  18. <img v-show="activeNav !== item.key" class="nav-card__icon" :src="item.icon" alt="" />
  19. <img v-show="activeNav === item.key" class="nav-card__icon" :src="item.activeIcon" alt="" />
  20. </div>
  21. <div v-if="item.key === 'report' && guideVisible && !noFarms" class="report-guide-bubble">
  22. <span class="report-guide-bubble__arrow"></span>
  23. <div class="report-guide-bubble__content">
  24. {{ t("agriFile.diagnosisReportGuidePrefix") }}
  25. <span class="report-guide-bubble__link">
  26. {{ t("agriFile.uploadPhoto") }}
  27. </span>
  28. {{ t("agriFile.diagnosisReportGuideSuffix") }}
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="content-panel">
  34. <patrol-panel ref="patrolPanelRef" v-show="activeNav === 'patrol'" @open-upload="openUploadPopup" />
  35. <album-panel
  36. v-show="activeNav === 'album'"
  37. :active="activeNav === 'album'"
  38. @open-upload="openUploadPopup"
  39. />
  40. <report-panel v-show="activeNav === 'report'" :active="activeNav === 'report'" />
  41. </div>
  42. <album-upload-popup v-model:show="showUploadPopup" @confirm="handleUploadConfirm" />
  43. <tip-popup v-model:show="showSuccessPopup" type="executeSuccess" text="您已上传成功" text2="诊断报告正在生成,请稍后..." hideBtn>
  44. <template #footer>
  45. <div class="bottom-btn-container">
  46. <div class="bottom-btn primary-btn" @click="handleComplete">完成</div>
  47. </div>
  48. </template>
  49. </tip-popup>
  50. <!-- 恢复种植弹窗 -->
  51. <restore-planting-popup @success="handleRestorePlantingSuccess" />
  52. <!-- 代管弹窗:后续由接口控制是否展示 -->
  53. <proxy-auth-popup
  54. v-model:show="showProxyAuthPopup"
  55. :service-name="proxyServiceName"
  56. @reject="handleProxyReject"
  57. @allow="handleProxyAllow"
  58. />
  59. <!-- 申请更换物候期弹窗:后续由接口控制是否展示 -->
  60. <phenology-update-popup
  61. v-model:show="showPhenologyUpdatePopup"
  62. :service-name="phenologyUpdateInfo.serviceName"
  63. :current-stage="phenologyUpdateInfo.currentStage"
  64. :target-stage="phenologyUpdateInfo.targetStage"
  65. :current-image="phenologyUpdateInfo.currentImage"
  66. :farm-location="phenologyUpdateInfo.farmLocation"
  67. @reject="handlePhenologyUpdateReject"
  68. @confirm="handlePhenologyUpdateConfirm"
  69. />
  70. <!-- 种植全析报告弹窗:组件内接口判断 exists 且本地未展示过;结束后再出诊断报告弹窗 -->
  71. <diagnosis-report-popup @finished="onDiagnosisReportFinished" />
  72. <!-- 诊断报告:等种植全析弹窗 finished 后再检查展示,避免同时弹出 -->
  73. <patrol-diagnosis-popup ref="patrolDiagnosisPopupRef" :auto-check="false" />
  74. </div>
  75. </template>
  76. <script setup>
  77. import { computed, nextTick, onActivated, onBeforeUnmount, onMounted, ref } from "vue";
  78. import { useStore } from "vuex";
  79. import { useRouter } from "vue-router";
  80. import { ElMessage } from "element-plus";
  81. import { useI18n } from "@/i18n";
  82. import farmHeader from "@/components/farmHeader.vue";
  83. import albumUploadPopup from "./components/albumUploadPopup.vue";
  84. import tipPopup from "@/components/popup/tipPopup.vue";
  85. import diagnosisReportPopup from "@/components/popup/diagnosisReportPopup.vue";
  86. import { hasFarms } from "@/utils/farmPresence";
  87. import restorePlantingPopup from "@/components/popup/restorePlantingPopup.vue";
  88. import proxyAuthPopup from "@/components/popup/proxyAuthPopup.vue";
  89. import phenologyUpdatePopup from "@/components/popup/phenologyUpdatePopup.vue";
  90. import patrolPanel from "./components/patrolPanel.vue";
  91. import albumPanel from "./components/albumPanel.vue";
  92. import reportPanel from "./components/reportPanel.vue";
  93. import patrolDiagnosisPopup from "@/components/popup/patrolDiagnosisPopup.vue";
  94. const { t } = useI18n();
  95. const store = useStore();
  96. const router = useRouter();
  97. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  98. // ---------- 常量 ----------
  99. const DIAGNOSIS_GUIDE_STORAGE_KEY = "AGRI_FILE_DIAGNOSIS_REPORT_GUIDE";
  100. /** 勾画范围提交成功后,回农事档案继续上传的标记 */
  101. const CONTINUE_UPLOAD_KEY = "AGRI_FILE_CONTINUE_UPLOAD";
  102. const navCards = [
  103. {
  104. key: "patrol",
  105. labelKey: "agriFile.patrolRecord",
  106. icon: require("@/assets/img/agricultural/pen.png"),
  107. activeIcon: require("@/assets/img/agricultural/pen-active.png"),
  108. },
  109. {
  110. key: "album",
  111. labelKey: "agriFile.agriAlbum",
  112. icon: require("@/assets/img/agricultural/pic.png"),
  113. activeIcon: require("@/assets/img/agricultural/pic-active.png"),
  114. },
  115. {
  116. key: "report",
  117. labelKey: "agriFile.diagnosisReport",
  118. icon: require("@/assets/img/agricultural/file.png"),
  119. activeIcon: require("@/assets/img/agricultural/file-active.png"),
  120. },
  121. ];
  122. // ---------- 页面状态 ----------
  123. const activeNav = ref("patrol");
  124. const guideVisible = ref(false);
  125. const showUploadPopup = ref(false);
  126. const showSuccessPopup = ref(false);
  127. const patrolPanelRef = ref(null);
  128. const patrolDiagnosisPopupRef = ref(null);
  129. /** 后续由接口控制是否展示代管授权弹窗 */
  130. const showProxyAuthPopup = ref(false);
  131. const proxyServiceName = ref("农服名称");
  132. /** 后续由接口控制是否展示申请更换物候期弹窗 */
  133. const showPhenologyUpdatePopup = ref(false);
  134. const phenologyUpdateInfo = ref({
  135. serviceName: "某某农服",
  136. currentStage: "花穗期",
  137. targetStage: "小果期",
  138. varietyName: "荔枝-桂味",
  139. farmLocation: "--",
  140. });
  141. // ---------- 工具函数 ----------
  142. /** 列表未返回或为空时不展示诊断引导;弹窗由应用层 noFarmPopupHost 负责 */
  143. const noFarms = computed(() => hasFarms.value !== true);
  144. const dismissGuide = () => {
  145. if (!guideVisible.value) return;
  146. guideVisible.value = false;
  147. localStorage.setItem(DIAGNOSIS_GUIDE_STORAGE_KEY, "1");
  148. };
  149. const tryShowGuide = () => {
  150. if (localStorage.getItem(DIAGNOSIS_GUIDE_STORAGE_KEY)) return;
  151. guideVisible.value = true;
  152. };
  153. const uploadZoneId = ref(null);
  154. const getSelectedFarm = () => {
  155. try {
  156. return JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
  157. } catch {
  158. return {};
  159. }
  160. };
  161. // ---------- 事件处理 ----------
  162. const openUploadPopup = (zoneId, needDraw) => {
  163. if (!zoneId) return;
  164. if (needDraw) {
  165. // 勾画完成后带 continueUpload 返回,继续打开上传弹窗
  166. router.push({
  167. path: "/add_zone",
  168. query: {
  169. type: "region",
  170. zoneId,
  171. continueUpload: "1",
  172. },
  173. });
  174. return;
  175. }
  176. uploadZoneId.value = zoneId;
  177. showUploadPopup.value = true;
  178. };
  179. /** 从勾画范围页提交成功后返回:继续打开上传弹窗 */
  180. const tryContinueUpload = () => {
  181. const raw = sessionStorage.getItem(CONTINUE_UPLOAD_KEY);
  182. if (!raw) return;
  183. sessionStorage.removeItem(CONTINUE_UPLOAD_KEY);
  184. let zoneId = "";
  185. try {
  186. zoneId = JSON.parse(raw)?.zoneId || "";
  187. } catch {
  188. return;
  189. }
  190. if (!zoneId) return;
  191. uploadZoneId.value = zoneId;
  192. nextTick(() => {
  193. showUploadPopup.value = true;
  194. });
  195. };
  196. const handleUploadConfirm = async ({ images, date } = {}) => {
  197. const cloud_url = Array.isArray(images) ? images : [];
  198. if (!cloud_url.length) {
  199. ElMessage.warning("请先上传照片");
  200. return;
  201. }
  202. const farm = getSelectedFarm();
  203. try {
  204. const res = await VE_API.questionnaire.uploadImages({
  205. cloud_url,
  206. farm_id: farm.farm_id ?? farm.id ?? "",
  207. zone_id: uploadZoneId.value || farm.zone_id || "",
  208. category_code: farm.category_code || "",
  209. zone_name: farm.variety_name || "",
  210. create_time: date,
  211. });
  212. if (res?.code === 200) {
  213. showSuccessPopup.value = true;
  214. return;
  215. }
  216. ElMessage.error(res?.msg || "上传失败,请稍后再试");
  217. } catch {
  218. ElMessage.error("上传失败,请稍后再试");
  219. }
  220. };
  221. const handleComplete = () => {
  222. showSuccessPopup.value = false;
  223. };
  224. /** 恢复种植提交成功后刷新巡园卡片与作物档案 */
  225. const handleRestorePlantingSuccess = () => {
  226. patrolPanelRef.value?.loadPatrolData?.();
  227. };
  228. const handleNavClick = (item) => {
  229. if (item.key === "report") dismissGuide();
  230. activeNav.value = item.key;
  231. };
  232. const handleOutsideClick = (event) => {
  233. if (!guideVisible.value) return;
  234. const target = event.target;
  235. if (
  236. target?.closest?.(".report-guide-bubble") ||
  237. target?.closest?.(".nav-card-wrap--report .nav-card")
  238. ) {
  239. return;
  240. }
  241. dismissGuide();
  242. };
  243. const handleProxyReject = () => {
  244. // TODO: 调用拒绝代管接口
  245. };
  246. const handleProxyAllow = () => {
  247. // TODO: 调用允许代管接口
  248. };
  249. const handlePhenologyUpdateReject = () => {
  250. // TODO: 调用暂不更新接口
  251. };
  252. const handlePhenologyUpdateConfirm = () => {
  253. // TODO: 调用确认更新接口
  254. };
  255. /** 种植全析弹窗回合结束(未展示 / 遮罩关闭)后再检查诊断报告弹窗 */
  256. const onDiagnosisReportFinished = () => {
  257. patrolDiagnosisPopupRef.value?.checkShouldShow?.();
  258. };
  259. // ---------- 生命周期 ----------
  260. onMounted(() => {
  261. document.addEventListener("click", handleOutsideClick, true);
  262. });
  263. onActivated(() => {
  264. tryShowGuide();
  265. tryContinueUpload();
  266. });
  267. onBeforeUnmount(() => {
  268. document.removeEventListener("click", handleOutsideClick, true);
  269. });
  270. </script>
  271. <style lang="scss" scoped>
  272. .agri-file-page {
  273. position: relative;
  274. display: flex;
  275. flex-direction: column;
  276. width: 100%;
  277. height: 100%;
  278. overflow: hidden;
  279. background: url('@/assets/img/agricultural/page-bg.png') no-repeat top center;
  280. background-size: 100% 250px;
  281. .agri-file-page__header {
  282. position: absolute;
  283. z-index: -1;
  284. top: 0;
  285. background: url('@/assets/img/agricultural/page-bg.png') no-repeat center center;
  286. background-size: 100% 100%;
  287. width: 100%;
  288. height: 250px;
  289. }
  290. .nav-cards {
  291. position: relative;
  292. z-index: 2;
  293. display: flex;
  294. justify-content: space-around;
  295. gap: 8px;
  296. padding: 10px 10px;
  297. // margin-bottom: 10px;
  298. .nav-card-wrap {
  299. position: relative;
  300. flex: 1;
  301. &--report {
  302. z-index: 5;
  303. }
  304. }
  305. .nav-card {
  306. position: relative;
  307. display: flex;
  308. align-items: center;
  309. border-radius: 8px;
  310. background: linear-gradient(180deg, #1A191D 0%, #121216 100%);
  311. border: 1px solid rgba(255, 255, 255, 0.1);
  312. height: 43px;
  313. font-size: 14px;
  314. font-weight: 500;
  315. box-sizing: border-box;
  316. .nav-card__icon {
  317. width: 38px;
  318. // height: 29px;
  319. border-radius: 0 0 8px 0;
  320. position: absolute;
  321. bottom: 0;
  322. right: 0;
  323. }
  324. .nav-card__label {
  325. color: #A4A4A4;
  326. padding-left: 12px;
  327. }
  328. &.is-active {
  329. background: linear-gradient(180deg, #FFEBC9 0%, #FFCA6D 100%);
  330. .nav-card__label {
  331. color: #292929;
  332. }
  333. &::after {
  334. content: "";
  335. position: absolute;
  336. left: 50%;
  337. bottom: -5px;
  338. transform: translateX(-50%);
  339. border-left: 6px solid transparent;
  340. border-right: 6px solid transparent;
  341. border-top: 6px solid #FFCA6D;
  342. z-index: 3;
  343. }
  344. }
  345. }
  346. .report-guide-bubble {
  347. position: absolute;
  348. top: calc(100% + 10px);
  349. right: 22px;
  350. width: 216px;
  351. padding: 6px 10px;
  352. border-radius: 6px;
  353. background: rgba(0, 0, 0, 0.8);
  354. backdrop-filter: blur(4px);
  355. box-sizing: border-box;
  356. border: 1px solid rgba(255, 255, 255, 0.2);
  357. z-index: 20;
  358. pointer-events: auto;
  359. &__arrow {
  360. position: absolute;
  361. top: -4.5px;
  362. right: 16px;
  363. width: 6px;
  364. height: 6px;
  365. transform: rotate(45deg);
  366. background: rgba(0, 0, 0, 0.8);
  367. border: 1px solid rgba(255, 255, 255, 0.2);
  368. border-bottom-color: transparent;
  369. border-right-color: transparent;
  370. }
  371. &__content {
  372. font-size: 14px;
  373. line-height: 22px;
  374. color: #fff;
  375. word-break: break-all;
  376. text-align: justify;
  377. }
  378. &__link {
  379. padding: 0 2px;
  380. color: #FFD489;
  381. cursor: pointer;
  382. }
  383. }
  384. }
  385. .content-panel {
  386. flex: 1;
  387. overflow-y: auto;
  388. background: #141414;
  389. padding: 8px 12px 12px;
  390. &::-webkit-scrollbar {
  391. display: none;
  392. }
  393. }
  394. }
  395. .bottom-btn-container {
  396. display: flex;
  397. justify-content: space-between;
  398. gap: 12px;
  399. width: 100%;
  400. .bottom-btn {
  401. padding: 0 25px;
  402. border-radius: 4px;
  403. font-size: 16px;
  404. height: 40px;
  405. line-height: 40px;
  406. box-sizing: border-box;
  407. font-weight: 500;
  408. text-align: center;
  409. &.primary-btn {
  410. flex: 1;
  411. background: linear-gradient(90deg, #FFEBC9 0%, #FFCA6D 100%);
  412. color: #1A1408;
  413. }
  414. }
  415. }
  416. </style>