index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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 && !noFarms" 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. const noFarms = ref(true);
  136. // ---------- 业务逻辑 ----------
  137. /** 无果园信息时展示「完善农场信息」弹窗 */
  138. async function checkCompleteFarmPopup() {
  139. const id = getMiniUserId();
  140. if (!id) {
  141. showCompleteFarmPopup.value = false;
  142. return;
  143. }
  144. try {
  145. const res = await VE_API.questionnaire.getFarms({ id });
  146. const list = Array.isArray(res?.data) ? res.data : [];
  147. noFarms.value = list.length === 0;
  148. showCompleteFarmPopup.value = list.length === 0;
  149. } catch (e) {
  150. console.warn("[agri_file] getFarms failed", e);
  151. showCompleteFarmPopup.value = false;
  152. }
  153. }
  154. const dismissGuide = () => {
  155. if (!guideVisible.value) return;
  156. guideVisible.value = false;
  157. localStorage.setItem(DIAGNOSIS_GUIDE_STORAGE_KEY, "1");
  158. };
  159. const tryShowGuide = () => {
  160. if (localStorage.getItem(DIAGNOSIS_GUIDE_STORAGE_KEY)) return;
  161. guideVisible.value = true;
  162. };
  163. const uploadZoneId = ref(null);
  164. const getSelectedFarm = () => {
  165. try {
  166. return JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
  167. } catch {
  168. return {};
  169. }
  170. };
  171. // ---------- 事件处理 ----------
  172. const openUploadPopup = (zoneId) => {
  173. if (!zoneId) return;
  174. uploadZoneId.value = zoneId;
  175. showUploadPopup.value = true;
  176. };
  177. const handleUploadConfirm = async ({ images, date } = {}) => {
  178. const cloud_url = Array.isArray(images) ? images : [];
  179. if (!cloud_url.length) {
  180. ElMessage.warning("请先上传照片");
  181. return;
  182. }
  183. const farm = getSelectedFarm();
  184. try {
  185. const res = await VE_API.questionnaire.uploadImages({
  186. cloud_url,
  187. farm_id: farm.farm_id ?? farm.id ?? "",
  188. zone_id: uploadZoneId.value || farm.zone_id || "",
  189. category_code: farm.category_code || "",
  190. zone_name: farm.variety_name || "",
  191. create_time: date,
  192. });
  193. if (res?.code === 200) {
  194. showSuccessPopup.value = true;
  195. return;
  196. }
  197. ElMessage.error(res?.msg || "上传失败,请稍后再试");
  198. } catch {
  199. ElMessage.error("上传失败,请稍后再试");
  200. }
  201. };
  202. const handleComplete = () => {
  203. showSuccessPopup.value = false;
  204. };
  205. const handleNavClick = (item) => {
  206. if (item.key === "report") dismissGuide();
  207. activeNav.value = item.key;
  208. };
  209. const handleOutsideClick = (event) => {
  210. if (!guideVisible.value) return;
  211. const target = event.target;
  212. if (
  213. target?.closest?.(".report-guide-bubble") ||
  214. target?.closest?.(".nav-card-wrap--report .nav-card")
  215. ) {
  216. return;
  217. }
  218. dismissGuide();
  219. };
  220. const goCompleteFarmInfo = () => {
  221. router.push("/entry_information");
  222. };
  223. const handleProxyReject = () => {
  224. // TODO: 调用拒绝代管接口
  225. };
  226. const handleProxyAllow = () => {
  227. // TODO: 调用允许代管接口
  228. };
  229. const handlePhenologyUpdateReject = () => {
  230. // TODO: 调用暂不更新接口
  231. };
  232. const handlePhenologyUpdateConfirm = () => {
  233. // TODO: 调用确认更新接口
  234. };
  235. // ---------- 生命周期 ----------
  236. onMounted(() => {
  237. checkCompleteFarmPopup();
  238. tryShowGuide();
  239. document.addEventListener("click", handleOutsideClick, true);
  240. });
  241. onActivated(() => {
  242. checkCompleteFarmPopup();
  243. tryShowGuide();
  244. });
  245. onBeforeUnmount(() => {
  246. document.removeEventListener("click", handleOutsideClick, true);
  247. });
  248. </script>
  249. <style lang="scss" scoped>
  250. .agri-file-page {
  251. position: relative;
  252. display: flex;
  253. flex-direction: column;
  254. width: 100%;
  255. height: 100%;
  256. overflow: hidden;
  257. background: linear-gradient(180deg, #d1ebff 0%, #ffffff 100%);
  258. .nav-cards {
  259. position: relative;
  260. z-index: 2;
  261. display: flex;
  262. justify-content: space-around;
  263. padding: 10px 10px;
  264. margin-bottom: 10px;
  265. .nav-card-wrap {
  266. position: relative;
  267. &--report {
  268. z-index: 5;
  269. }
  270. }
  271. .nav-card {
  272. position: relative;
  273. display: flex;
  274. flex-direction: column;
  275. align-items: center;
  276. justify-content: center;
  277. border-radius: 8px;
  278. background: #fff;
  279. width: 90px;
  280. height: 64px;
  281. box-shadow: 0px 4px 4px 0px #0000000d;
  282. .nav-card__icon {
  283. width: 26px;
  284. height: 26px;
  285. margin-bottom: 4px;
  286. }
  287. &.is-active {
  288. background: linear-gradient(180deg, #5bb8ff 0%, #2199f8 100%);
  289. box-shadow: 0 4px 10px rgba(33, 153, 248, 0.28);
  290. .nav-card__icon {
  291. filter: brightness(0) invert(1);
  292. }
  293. .nav-card__label {
  294. color: #fff;
  295. }
  296. &::after {
  297. content: "";
  298. position: absolute;
  299. left: 50%;
  300. bottom: -5px;
  301. transform: translateX(-50%);
  302. border-left: 6px solid transparent;
  303. border-right: 6px solid transparent;
  304. border-top: 6px solid #2199f8;
  305. z-index: 3;
  306. }
  307. }
  308. }
  309. .report-guide-bubble {
  310. position: absolute;
  311. top: calc(100% + 10px);
  312. right: 22px;
  313. width: 216px;
  314. padding: 6px 10px;
  315. border-radius: 6px;
  316. background: rgba(0, 0, 0, 0.8);
  317. backdrop-filter: blur(4px);
  318. box-sizing: border-box;
  319. z-index: 20;
  320. pointer-events: auto;
  321. &__arrow {
  322. position: absolute;
  323. top: -5px;
  324. right: 16px;
  325. width: 0;
  326. height: 0;
  327. border-left: 6px solid transparent;
  328. border-right: 6px solid transparent;
  329. border-bottom: 6px solid rgba(0, 0, 0, 0.8);
  330. }
  331. &__content {
  332. font-size: 14px;
  333. line-height: 22px;
  334. color: #fff;
  335. word-break: break-all;
  336. text-align: justify;
  337. }
  338. &__link {
  339. padding: 0 2px;
  340. color: #2199f8;
  341. cursor: pointer;
  342. }
  343. }
  344. }
  345. .content-panel {
  346. flex: 1;
  347. overflow-y: auto;
  348. background: linear-gradient(360deg, rgba(229, 243, 255, 0.55) 0%, rgba(255, 255, 255, 0.55) 100%);
  349. border-radius: 20px 20px 0 0;
  350. border: 1px solid #ffffff;
  351. padding: 18px 10px;
  352. &::-webkit-scrollbar {
  353. display: none;
  354. }
  355. }
  356. }
  357. .bottom-btn-container {
  358. display: flex;
  359. justify-content: space-between;
  360. gap: 12px;
  361. width: 100%;
  362. .bottom-btn {
  363. padding: 0 25px;
  364. border-radius: 4px;
  365. font-size: 16px;
  366. height: 40px;
  367. line-height: 40px;
  368. box-sizing: border-box;
  369. font-weight: 500;
  370. text-align: center;
  371. &.primary-btn {
  372. flex: 1;
  373. background: #2199f8;
  374. color: #fff;
  375. }
  376. }
  377. }
  378. </style>