index.vue 13 KB

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