patrolPanel.vue 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. <template>
  2. <div class="patrol-panel">
  3. <!-- 品种切换 -->
  4. <div class="variety-bar">
  5. <div class="variety-bar__tags">
  6. <div v-for="item in zoneList" :key="item.zone_id" class="variety-bar__tag"
  7. :class="{ active: item.zone_id === selectedZoneId }" @click="handleSelectZone(item)">
  8. {{ item.zone_name }}
  9. </div>
  10. </div>
  11. <div class="variety-bar__add" @click="goAddVariety">
  12. <el-icon size="10">
  13. <Plus />
  14. </el-icon>
  15. <span>新增品种</span>
  16. </div>
  17. </div>
  18. <!-- <div v-if="loading" class="patrol-loading">
  19. <span class="patrol-loading__spinner"></span>
  20. <span class="patrol-loading__text">加载中...</span>
  21. </div> -->
  22. <div v-loading="loading" element-loading-background="rgba(15, 15, 15, 0.55)" element-loading-text="加载中...">
  23. <div v-for="item in patrolList" :key="item.id" class="tracking-item" @click="goGrowthTrack(item)">
  24. <div class="tracking-item__header">
  25. <div class="tracking-item__header-left">
  26. <img class="tracking-item__header-icon" :src="item.headerIcon || periodIcon" alt="" />
  27. <span class="tracking-item__title van-ellipsis">
  28. {{ item.title }}
  29. </span>
  30. </div>
  31. <div v-if="item.level" class="tracking-item__level" :class="'level-' + item.level_num">
  32. <el-icon>
  33. <WarningFilled />
  34. </el-icon>
  35. <span>{{ item.level }}</span>
  36. </div>
  37. </div>
  38. <div class="tracking-item__body">
  39. <img class="tracking-item__thumb" :src="item.icon" alt="" />
  40. <div class="tracking-item__content">
  41. <div class="tracking-item__subject van-ellipsis">{{ item.subject }}</div>
  42. <div class="tracking-item__issue">{{ item.issue || item.desc }}</div>
  43. <div class="tracking-item__urgency"
  44. :class="`tracking-item__urgency--${item.urgencyTone || 'danger'}`">
  45. <img v-if="item.urgencyIcon" class="tracking-item__urgency-icon" :src="item.urgencyIcon"
  46. alt="" />
  47. <el-icon v-else>
  48. <Clock />
  49. </el-icon>
  50. <span>{{ item.urgencyText || "建议 24 小时内处理" }}</span>
  51. </div>
  52. </div>
  53. </div>
  54. <div class="tracking-item__footer">
  55. <div class="tracking-item__actions">
  56. <div class="tracking-item__action" @click.stop="handleShare(item)">
  57. <Icon size="14" color="rgba(255,255,255,0.75)" name="share" />
  58. <span>{{ t("agriFile.forward") }}</span>
  59. </div>
  60. <span class="tracking-item__divider"></span>
  61. <div class="tracking-item__action" @click.stop="handleUploadClick(item)">
  62. <el-icon>
  63. <Camera />
  64. </el-icon>
  65. <span>上传巡园照片</span>
  66. </div>
  67. </div>
  68. <div class="tracking-item__detail-btn" @click.stop="goGrowthTrack(item)">
  69. 进入详情 <el-icon>
  70. <ArrowRightBold />
  71. </el-icon>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="no-data-text" v-if="patrolList.length == 0">
  76. <div>不在作物的种植周期内</div>
  77. <div>暂无巡园记录</div>
  78. </div>
  79. </div>
  80. <div class="crop-archive">
  81. <!-- <div class="crop-archive__title">{{ t("agriFile.cropArchive") }}</div> -->
  82. <PhenologyTrackTimelineItem theme="dark" :list="cropArchiveList" />
  83. </div>
  84. <album-upload-popup v-model:show="showUploadPopup" @confirm="handleUploadConfirm" />
  85. <tip-popup class="restore-planting-success-popup" :zIndex="20000" v-model:show="showSuccessPopup" type="executeSuccess" text="您已上传成功" text2="诊断报告正在生成,请稍后..." hideBtn>
  86. <template #footer>
  87. <div class="bottom-btn-container">
  88. <div class="bottom-btn primary-btn" @click="handleComplete">完成</div>
  89. </div>
  90. </template>
  91. </tip-popup>
  92. </div>
  93. </template>
  94. <script setup>
  95. import { nextTick, onActivated, onMounted, ref } from "vue";
  96. import { useRoute, useRouter } from "vue-router";
  97. import { Icon } from "vant";
  98. import { ElMessage } from "element-plus";
  99. import { Camera, Clock, Plus, WarningFilled } from "@element-plus/icons-vue";
  100. import { useI18n } from "@/i18n";
  101. import { base_img_url2 } from "@/api/config";
  102. import { resolvePairedFarmZone } from "@/utils/selectedFarm";
  103. import PhenologyTrackTimelineItem from "@/components/pageComponents/PhenologyTrackTimelineItem.vue";
  104. import albumUploadPopup from "./albumUploadPopup.vue";
  105. import tipPopup from "@/components/popup/tipPopup.vue";
  106. import wx from "weixin-js-sdk";
  107. const { t } = useI18n();
  108. const route = useRoute();
  109. const router = useRouter();
  110. const PATROL_ICON = require("@/assets/img/common/empty-bg.png");
  111. const periodIcon = require("@/assets/img/agricultural/period.png");
  112. const lightningIcon = require("@/assets/img/agricultural/lightning.png");
  113. const soilIcon = require("@/assets/img/agricultural/soil.png");
  114. /** 长势:最佳窗口(资源文件名 clock,实际为日历) */
  115. const calendarUrgencyIcon = require("@/assets/img/agricultural/clock.png");
  116. /** 土壤:含水率提示 */
  117. const waterUrgencyIcon = require("@/assets/img/agricultural/water.png");
  118. /** 接口返回的图片可能是 CDN 相对路径 */
  119. const resolveTaskImage = (url) => {
  120. if (!url) return "";
  121. const text = String(url).trim();
  122. if (!text) return "";
  123. if (/^https?:\/\//i.test(text)) return text;
  124. return base_img_url2 + text.replace(/^\//, "");
  125. };
  126. // ---------- 页面状态 ----------
  127. const zoneList = ref([]);
  128. const selectedZoneId = ref(null);
  129. const selectedZoneName = ref("");
  130. /** 物候卡片占位(接口无数据 / 请求失败时兜底展示) */
  131. const buildGrowthPatrolMock = () => ({
  132. id: "growth-mock",
  133. type: "growth",
  134. theme: "blue",
  135. level: null,
  136. title: t("agriFile.patrolGrowthTitle"),
  137. zone: selectedZoneName.value || t("agriFile.zoneOne"),
  138. subject: t("agriFile.patrolSubject"),
  139. issue: t("agriFile.patrolIssue"),
  140. desc: "",
  141. urgencyText: "最佳窗口 --",
  142. urgencyTone: "success",
  143. urgencyIcon: calendarUrgencyIcon,
  144. headerIcon: periodIcon,
  145. icon: PATROL_ICON,
  146. });
  147. /** 默认组成:仅物候占位;异常 / 土壤根系卡由接口数据决定,无数据不占位 */
  148. const buildDefaultPatrolList = () => [buildGrowthPatrolMock()];
  149. const patrolList = ref(buildDefaultPatrolList());
  150. /** 巡园接口返回前的加载态 */
  151. const loading = ref(false);
  152. const cropArchiveList = ref([]);
  153. const showUploadPopup = ref(false);
  154. const showSuccessPopup = ref(false);
  155. const uploadZoneId = ref("");
  156. /** 当前上传来源卡片类型:growth 走相册接口;abnormal / soil 走巡检接口 */
  157. const uploadCardType = ref("");
  158. /** 范围校验进行中,避免重复点击触发多次跳转 */
  159. const uploadChecking = ref(false);
  160. /** 新增品种前校验范围,避免重复跳转 */
  161. const addVarietyChecking = ref(false);
  162. // ---------- 工具函数 ----------
  163. function formatToday() {
  164. const d = new Date();
  165. const y = d.getFullYear();
  166. const m = String(d.getMonth() + 1).padStart(2, "0");
  167. const day = String(d.getDate()).padStart(2, "0");
  168. return `${y}-${m}-${day}`;
  169. }
  170. /** 农场品类编码,接口 crop_type */
  171. const resolveCropType = (farm = getSelectedFarm()) =>
  172. farm.category_code || farm.categorycode || farm.crop_code || farm.crop_type || "";
  173. /**
  174. * 新接口按分块下发的单条巡园任务(pheno / abnormal / soil_root)→ 巡园卡片
  175. * 字段直接来自 data.pheno / data.abnormal / data.soil_root;无对应分块则不展示该项
  176. */
  177. const mapSectionToPatrol = (section = {}, type, ctx = {}) => {
  178. const isAbnormal = type === "abnormal";
  179. const isSoil = type === "soil";
  180. const isGrowth = type === "growth";
  181. const title = isSoil
  182. ? "土壤根系感知"
  183. : isGrowth
  184. ? t("agriFile.patrolGrowthTitle")
  185. : t("agriFile.patrolAbnormalTitle");
  186. const subject =
  187. section.title ||
  188. section.interact_title ||
  189. section.interaction_title ||
  190. section.pheno_name ||
  191. "";
  192. const issue =
  193. section.interact_theme ||
  194. section.interaction_theme ||
  195. section.interaction_reason
  196. "";
  197. const level = section.level || (isSoil ? "一级" : "");
  198. const urgencyText =
  199. section.action_hint ||
  200. (isSoil
  201. ? "土壤含水率偏高 · 已持续 5 天"
  202. : isGrowth
  203. ? "最佳窗口待确认"
  204. : "建议 24 小时内处理");
  205. const urgencyTone = isSoil ? "warn" : isGrowth ? "success" : "danger";
  206. const urgencyIcon = isSoil ? waterUrgencyIcon : isGrowth ? calendarUrgencyIcon : "";
  207. const headerIcon = isSoil ? soilIcon : isGrowth ? periodIcon : lightningIcon;
  208. const icon = resolveTaskImage(section.image_url || section.pic_url || section.guide_url) || PATROL_ICON;
  209. const zoneId = section.zone_id ?? ctx.zoneId ?? selectedZoneId.value;
  210. return {
  211. id: section.type_code ? `${section.type_code}:${zoneId}` : `${type}:${zoneId}`,
  212. type,
  213. theme: "blue",
  214. level,
  215. level_num: section.level_num,
  216. title,
  217. subject,
  218. issue,
  219. desc: "",
  220. urgencyText,
  221. urgencyTone,
  222. urgencyIcon,
  223. headerIcon,
  224. icon,
  225. zone: ctx.zone || selectedZoneName.value || "",
  226. zoneId,
  227. interactCode: section.interact_code || "",
  228. fwCode: section.fw_code || "",
  229. taskKey: section.type_code || type,
  230. status: section.status || "",
  231. raw: section,
  232. };
  233. };
  234. /**
  235. * 一次接口返回 → 巡园卡片:物候(pheno) → 异常(abnormal) → 土壤根系(soil_root)
  236. * pheno / abnormal 有数据才展示对应卡片;soil_root 缺失时兜底写死占位
  237. */
  238. const buildPatrolList = (data = {}) => {
  239. const zoneId = data.zone_id ?? selectedZoneId.value;
  240. const zone = selectedZoneName.value || "";
  241. const ctx = { zoneId, zone, data };
  242. const list = [];
  243. if (data.pheno) list.push(mapSectionToPatrol(data.pheno, "growth", ctx));
  244. if (data.abnormal) list.push(mapSectionToPatrol(data.abnormal, "abnormal", ctx));
  245. // 土壤根系:接口字段为 soil_root(type_code=soil_root),缺失则不显示
  246. if (data.soil_root) list.push(mapSectionToPatrol(data.soil_root, "soil", ctx));
  247. return list;
  248. };
  249. const mapPhenoRecordToArchive = (item, index, zoneName) => {
  250. // 物候记录用 enter_date,异常记录只有 trigger_date
  251. const date = item.enter_date || item.trigger_date || "";
  252. return {
  253. id: [item.zone_id, item.type, date, item.period_code || item.fw_code, index]
  254. .filter((v) => v != null && v !== "")
  255. .join("_"),
  256. date,
  257. zone_name: item.zone_name || zoneName || "",
  258. content: item.sentence || (item.period_name ? `到达 ${item.period_name}` : ""),
  259. period_code: item.period_code,
  260. period_name: item.period_name,
  261. shoot_type: item.shoot_type,
  262. zone_id: item.zone_id,
  263. crop_code: item.crop_code,
  264. fw_code: item.fw_code,
  265. type: item.type,
  266. };
  267. };
  268. const getSelectedFarm = () => {
  269. try {
  270. return JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
  271. } catch {
  272. return {};
  273. }
  274. };
  275. const getSelectedFarmId = () => {
  276. const stored = localStorage.getItem("selectedFarmId");
  277. if (stored != null && stored !== "") {
  278. return Number(stored);
  279. }
  280. const farm = getSelectedFarm();
  281. const id = farm.farm_id ?? farm.id;
  282. return id != null && id !== "" ? Number(id) : null;
  283. };
  284. /** 切换农场 / 分区、请求失败时清空接口数据,回退为占位卡片 */
  285. const resetPatrolList = () => {
  286. patrolList.value = buildDefaultPatrolList();
  287. };
  288. // ---------- 业务逻辑:加载 ----------
  289. const applySelectedZone = (zone) => {
  290. selectedZoneId.value = zone?.zone_id ?? null;
  291. selectedZoneName.value = zone?.zone_name || "";
  292. };
  293. /** 记录上次拉分区的农场,切农场时丢弃旧 selectedZoneId */
  294. let lastZonesFarmId = null;
  295. const fetchZones = async () => {
  296. const farmId = getSelectedFarmId();
  297. if (farmId == null) {
  298. lastZonesFarmId = null;
  299. zoneList.value = [];
  300. applySelectedZone(null);
  301. return;
  302. }
  303. // 切农场后旧 zone 不属于新农场,先清空再拉,避免上传校验错配
  304. if (lastZonesFarmId !== farmId) {
  305. applySelectedZone(null);
  306. lastZonesFarmId = farmId;
  307. }
  308. try {
  309. const res = await VE_API.questionnaire.getZones({ farm_id: farmId });
  310. const zones = Array.isArray(res?.data?.zones) ? res.data.zones : [];
  311. // zoneList.value = zones.reverse();
  312. zoneList.value = zones;
  313. // 同农场内优先沿用当前选中;否则默认第一个
  314. const matched = zones.find((z) => z.zone_id === selectedZoneId.value);
  315. applySelectedZone(matched || zoneList.value[0] || null);
  316. } catch (e) {
  317. console.warn("[patrolPanel] getZones failed", e);
  318. zoneList.value = [];
  319. applySelectedZone(null);
  320. }
  321. };
  322. /** 首页巡园要点:物候 / 异常 / 土壤由 getTypesTask 一次返回 */
  323. const fetchTypesTask = async () => {
  324. const farm = getSelectedFarm();
  325. const farmId = getSelectedFarmId();
  326. const zoneId = selectedZoneId.value;
  327. const cropType = resolveCropType(farm);
  328. if (farmId == null || zoneId == null || zoneId === "" || !cropType) {
  329. resetPatrolList();
  330. return;
  331. }
  332. loading.value = true;
  333. try {
  334. const res = await VE_API.pheno.getTypesTask({
  335. crop_type: cropType,
  336. farm_id: farmId,
  337. zone_id: zoneId,
  338. calc_date: formatToday(),
  339. });
  340. if (res?.code !== 200) {
  341. resetPatrolList();
  342. loading.value = false;
  343. return;
  344. }
  345. patrolList.value = buildPatrolList(res?.data || {});
  346. loading.value = false;
  347. } catch (e) {
  348. console.warn("[patrolPanel] getTypesTask failed", e);
  349. resetPatrolList();
  350. loading.value = false;
  351. }
  352. };
  353. const fetchCropArchive = async () => {
  354. const farm = getSelectedFarm();
  355. const query = {
  356. farm_id: farm.farm_id ?? farm.id,
  357. crop_code: farm.category_code,
  358. };
  359. if (!farm.farm_id) return
  360. try {
  361. const res = await VE_API.entry.getPhenoRecord(query);
  362. if (res?.code !== 200) {
  363. cropArchiveList.value = [];
  364. return;
  365. }
  366. const data = res?.data || {};
  367. const zones = Array.isArray(data.zones) ? data.zones : [];
  368. // 新结构:data.zones[].records 为各分区的物候 / 异常记录
  369. let cursor = 0;
  370. const list = [];
  371. for (const zone of zones) {
  372. const records = Array.isArray(zone.records) ? zone.records : [];
  373. const zoneName = zone.zone_name || zone.crop_variety || String(zone.zone_id ?? "");
  374. for (const item of records) {
  375. list.push(mapPhenoRecordToArchive(item, cursor, zoneName));
  376. cursor += 1;
  377. }
  378. }
  379. cropArchiveList.value = list.sort((a, b) =>
  380. String(b.date).localeCompare(String(a.date))
  381. );
  382. } catch (e) {
  383. console.warn("[patrolPanel] getPhenoRecord failed", e);
  384. cropArchiveList.value = [];
  385. }
  386. };
  387. /** 按当前选中品种刷新巡园卡片(作物档案按农场维度,切品种不重拉) */
  388. const reloadBySelectedZone = () => {
  389. resetPatrolList();
  390. fetchTypesTask();
  391. };
  392. const loadPatrolData = async () => {
  393. // 先清掉上一农场的任务数据,避免切换时残留
  394. // resetPatrolList();
  395. await fetchZones();
  396. fetchTypesTask();
  397. fetchCropArchive();
  398. };
  399. // ---------- 事件处理 ----------
  400. const handleSelectZone = (zone) => {
  401. if (!zone || zone.zone_id === selectedZoneId.value) return;
  402. applySelectedZone(zone);
  403. reloadBySelectedZone();
  404. };
  405. /**
  406. * 新增品种前校验当前选中品种是否已勾画范围(同 albumPanel checkZoneRange):
  407. * 已勾画 → 直接进新增分区;未勾画 → 先 type=farm 画范围,
  408. * 画完后 addZone 会 ElMessage「勾画完成」并继续进 type=region&isSuccessPopup=1
  409. */
  410. const goAddVariety = async () => {
  411. if (addVarietyChecking.value) return;
  412. const goRegionAdd = () => {
  413. router.push({
  414. path: "/add_zone",
  415. query: { type: "region", isSuccessPopup: "1" },
  416. });
  417. };
  418. const zoneId = selectedZoneId.value;
  419. if (zoneId == null || zoneId === "") {
  420. goRegionAdd();
  421. return;
  422. }
  423. addVarietyChecking.value = true;
  424. try {
  425. if (await hasZoneRange(zoneId)) {
  426. goRegionAdd();
  427. return;
  428. }
  429. const varietyName = selectedZoneName.value || "当前品类";
  430. // ElMessage.warning(`请先勾画「${varietyName}」的种植范围,完成后再新增分区`);
  431. ElMessage({
  432. message: `请先勾画「${varietyName}」的种植范围,\n完成后再新增品种`,
  433. type: "warning",
  434. customClass: "restore-planting-message",
  435. zIndex: 40000,
  436. });
  437. setTimeout(() => {
  438. router.push({
  439. path: "/add_zone",
  440. query: {
  441. type: "farm",
  442. continueAddVariety: "1",
  443. zoneId,
  444. },
  445. });
  446. }, 800);
  447. } finally {
  448. addVarietyChecking.value = false;
  449. }
  450. };
  451. /** 卡片 id 为任务标识,详情 / 上传 / 分享统一使用分区 id */
  452. const resolveCardZoneId = (item) => item?.zoneId ?? selectedZoneId.value ?? item?.id ?? "";
  453. const goGrowthTrack = (item) => {
  454. const type = item?.type;
  455. const zoneId = resolveCardZoneId(item);
  456. const path =
  457. type === "soil"
  458. ? "/soil_root_track"
  459. : type === "abnormal"
  460. ? "/abnormal_track"
  461. : "/growth_track";
  462. router.push({
  463. path,
  464. query: {
  465. id: zoneId,
  466. ...(zoneId !== "" ? { zoneId } : {}),
  467. pageName: item.title || "详情",
  468. },
  469. });
  470. };
  471. const handleShare = (item) => {
  472. const type = item?.type;
  473. const zoneId = resolveCardZoneId(item);
  474. let targetUrl;
  475. let pageName;
  476. let coverImg;
  477. if (type === "soil") {
  478. targetUrl = "soil_root_track";
  479. pageName = t("agriFile.patrolSoilTitle");
  480. coverImg = "https://birdseye-img.sysuimars.com/farm-h5/growth_cover.png";
  481. } else if (type === "abnormal") {
  482. targetUrl = "abnormal_track";
  483. pageName = t("agriFile.patrolAbnormalTitle");
  484. coverImg = "https://birdseye-img.sysuimars.com/farm-h5/abnormal_cover.png";
  485. } else {
  486. targetUrl = "growth_track";
  487. pageName = t("agriFile.patrolGrowthTitle");
  488. coverImg = "https://birdseye-img.sysuimars.com/farm-h5/growth_cover.png";
  489. }
  490. const shareFarmId = getSelectedFarmId();
  491. const query = {
  492. askInfo: { title: "转发巡园要点", content: "是否分享给好友" },
  493. shareText: item?.issue || "巡园要点",
  494. targetUrl,
  495. paramsPage: JSON.stringify({
  496. id: zoneId,
  497. fromShare: 1,
  498. ...(zoneId !== "" ? { zoneId } : {}),
  499. ...(shareFarmId != null && shareFarmId !== "" ? { farmId: shareFarmId } : {}),
  500. pageName,
  501. }),
  502. imageUrl: coverImg,
  503. };
  504. wx.miniProgram.navigateTo({
  505. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=sharePage`,
  506. });
  507. };
  508. /** status=1 表示已勾画种植范围;信息不全 / 校验异常时不拦截上传 */
  509. const hasZoneRange = async (zoneId) => {
  510. const farmId = getSelectedFarmId();
  511. if (farmId == null || farmId === "" || zoneId == null || zoneId === "") return true;
  512. // 分区必须落在当前农场分区列表内,防止卡片残留旧 zoneId
  513. const belongsToFarm = zoneList.value.some((z) => String(z.zone_id) === String(zoneId));
  514. if (!belongsToFarm) return false;
  515. try {
  516. const res = await VE_API.questionnaire.checkZoneRange({
  517. farm_id: farmId,
  518. zone_id: zoneId,
  519. });
  520. return Number(res?.data?.status) === 1;
  521. } catch (e) {
  522. console.warn("[patrolPanel] checkZoneRange failed", e);
  523. return true;
  524. }
  525. };
  526. /**
  527. * 上传前校验地块范围:
  528. * 已勾画 → 直接弹上传;未勾画 → 先去 /add_zone 画范围,
  529. * 画好后 addZone 带 showUpload=1 回跳 /agri_file,由 tryContinueUpload 恢复上传弹窗
  530. */
  531. const handleUploadClick = async (item) => {
  532. if (uploadChecking.value) return;
  533. const zoneId = resolveCardZoneId(item);
  534. uploadZoneId.value = zoneId;
  535. uploadCardType.value = item?.type || "";
  536. uploadChecking.value = true;
  537. try {
  538. if (await hasZoneRange(zoneId)) {
  539. showUploadPopup.value = true;
  540. return;
  541. }
  542. router.push({
  543. path: "/add_zone",
  544. query: {
  545. type: "farm",
  546. targetUrl: "/agri_file",
  547. ...(zoneId !== "" && zoneId != null
  548. ? { zoneId, trackId: zoneId }
  549. : {}),
  550. },
  551. });
  552. } finally {
  553. uploadChecking.value = false;
  554. }
  555. };
  556. /** 勾画完成返回(showUpload=1):恢复上传弹窗并清掉标记 */
  557. const tryContinueUpload = () => {
  558. if (route.query.showUpload !== "1") return;
  559. uploadZoneId.value =
  560. route.query.id || uploadZoneId.value || selectedZoneId.value || "";
  561. nextTick(() => {
  562. showUploadPopup.value = true;
  563. });
  564. const { showUpload, ...restQuery } = route.query;
  565. router.replace({ path: route.path, query: restQuery });
  566. };
  567. /** 异常态势 / 土壤根系:与 abnormalTrack 相同,走巡检上传 */
  568. const isInspectUploadType = (type) => type === "abnormal" || type === "soil";
  569. const handleUploadConfirm = async ({ images, date } = {}) => {
  570. if (isInspectUploadType(uploadCardType.value)) {
  571. const imageList = (Array.isArray(images) ? images : [])
  572. .filter(Boolean)
  573. .map((url) => resolveTaskImage(url));
  574. if (!imageList.length) {
  575. ElMessage.warning("请先上传照片");
  576. return;
  577. }
  578. const zoneId = uploadZoneId.value || selectedZoneId.value;
  579. const { farmId, zoneId: pairedZoneId } = await resolvePairedFarmZone(zoneId);
  580. if (farmId == null || pairedZoneId == null || pairedZoneId === "") {
  581. ElMessage.warning("当前农场与分区不匹配,请返回后重试");
  582. return;
  583. }
  584. try {
  585. const res = await VE_API.pheno.uploadAbnormalPhoto({
  586. farm_id: farmId,
  587. zone_id: pairedZoneId,
  588. images: imageList,
  589. });
  590. if (res?.code === 200) {
  591. showSuccessPopup.value = true;
  592. return;
  593. }
  594. ElMessage.error(res?.msg || "上传失败,请稍后再试");
  595. } catch {
  596. ElMessage.error("上传失败,请稍后再试");
  597. }
  598. return;
  599. }
  600. const cloud_url = Array.isArray(images) ? images : [];
  601. if (!cloud_url.length) {
  602. ElMessage.warning("请先上传照片");
  603. return;
  604. }
  605. const farm = getSelectedFarm();
  606. try {
  607. const res = await VE_API.questionnaire.uploadImages({
  608. cloud_url,
  609. farm_id: farm.farm_id ?? farm.id ?? "",
  610. zone_id: uploadZoneId.value || selectedZoneId.value || "",
  611. category_code: farm.category_code || "",
  612. zone_name: selectedZoneName.value || farm.variety_name || "",
  613. create_time: date,
  614. });
  615. if (res?.code === 200) {
  616. showSuccessPopup.value = true;
  617. return;
  618. }
  619. ElMessage.error(res?.msg || "上传失败,请稍后再试");
  620. } catch {
  621. ElMessage.error("上传失败,请稍后再试");
  622. }
  623. };
  624. const handleComplete = () => {
  625. showSuccessPopup.value = false;
  626. };
  627. // ---------- 生命周期 ----------
  628. onMounted(loadPatrolData);
  629. onActivated(() => {
  630. loadPatrolData();
  631. tryContinueUpload();
  632. });
  633. defineExpose({
  634. fetchTypesTask,
  635. fetchCropArchive,
  636. loadPatrolData,
  637. });
  638. </script>
  639. <style lang="scss" scoped>
  640. .patrol-panel {
  641. // padding-top: 8px;
  642. .no-data-text {
  643. text-align: center;
  644. padding-top: 40px;
  645. font-size: 14px;
  646. color: #A8A094;
  647. display: flex;
  648. flex-direction: column;
  649. gap: 4px;
  650. }
  651. .crop-archive {
  652. margin-top: 16px;
  653. }
  654. .variety-bar {
  655. display: flex;
  656. align-items: center;
  657. justify-content: space-between;
  658. gap: 12px;
  659. margin-bottom: 12px;
  660. &__tags {
  661. display: flex;
  662. align-items: center;
  663. flex-wrap: nowrap;
  664. gap: 16px;
  665. flex: 1;
  666. min-width: 0;
  667. overflow-x: auto;
  668. -webkit-overflow-scrolling: touch;
  669. scrollbar-width: none;
  670. &::-webkit-scrollbar {
  671. display: none;
  672. }
  673. }
  674. &__tag {
  675. position: relative;
  676. flex: none;
  677. white-space: nowrap;
  678. padding: 4px 0 8px;
  679. color: rgba(255, 255, 255, 0.35);
  680. font-size: 14px;
  681. line-height: 20px;
  682. &.active {
  683. color: #ffd489;
  684. font-weight: 500;
  685. &::after {
  686. content: "";
  687. position: absolute;
  688. left: 50%;
  689. bottom: 0;
  690. transform: translateX(-50%);
  691. width: 100%;
  692. height: 2px;
  693. border-radius: 2px;
  694. background: #ffd489;
  695. }
  696. }
  697. }
  698. &__add {
  699. flex: none;
  700. display: flex;
  701. align-items: center;
  702. gap: 2px;
  703. height: 28px;
  704. padding: 0 10px;
  705. border-radius: 14px;
  706. border: 1px solid rgba(255, 255, 255, 0.1);
  707. background: rgba(255, 255, 255, 0.06);
  708. color: rgba(255, 255, 255, 0.8);
  709. font-size: 12px;
  710. box-sizing: border-box;
  711. }
  712. }
  713. .patrol-loading {
  714. display: flex;
  715. flex-direction: column;
  716. align-items: center;
  717. justify-content: center;
  718. gap: 12px;
  719. padding: 64px 0;
  720. color: rgba(255, 255, 255, 0.6);
  721. font-size: 13px;
  722. letter-spacing: 1px;
  723. &__spinner {
  724. width: 28px;
  725. height: 28px;
  726. border-radius: 50%;
  727. border: 3px solid rgba(255, 255, 255, 0.15);
  728. border-top-color: #ffd489;
  729. animation: patrol-spin 0.8s linear infinite;
  730. }
  731. }
  732. .tracking-item {
  733. width: 100%;
  734. margin-bottom: 12px;
  735. padding: 10px 8px 8px 12px;
  736. border-radius: 12px;
  737. border: 1px solid rgba(255, 255, 255, 0.1);
  738. background: linear-gradient(180deg, #1A191D 0%, #121216 100%);
  739. box-sizing: border-box;
  740. &:last-of-type {
  741. margin-bottom: 0;
  742. }
  743. &__header {
  744. display: flex;
  745. align-items: center;
  746. justify-content: space-between;
  747. gap: 8px;
  748. padding-bottom: 10px;
  749. border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  750. }
  751. &__header-left {
  752. display: flex;
  753. align-items: center;
  754. gap: 6px;
  755. min-width: 0;
  756. }
  757. &__header-icon {
  758. width: 16px;
  759. height: 16px;
  760. flex-shrink: 0;
  761. object-fit: contain;
  762. }
  763. &__title {
  764. color: rgba(255, 255, 255, 0.9);
  765. font-size: 14px;
  766. font-weight: 500;
  767. line-height: 20px;
  768. }
  769. &__level {
  770. flex-shrink: 0;
  771. display: flex;
  772. align-items: center;
  773. gap: 3px;
  774. height: 22px;
  775. padding: 0 8px;
  776. border-radius: 11px;
  777. background: rgba(126, 35, 33, 0.2);
  778. border: 1px solid rgba(201, 53, 50, 0.41);
  779. color: #FFA1A0;
  780. font-size: 12px;
  781. box-sizing: border-box;
  782. &.level-1 {
  783. border-color: rgba(255, 212, 137, 0.41);
  784. background-color: rgba(255, 212, 137, 0.16);
  785. color: #FFD489;
  786. }
  787. &.level-2 {
  788. border-color: rgba(255, 127, 20, 0.4);
  789. background-color: rgba(255, 127, 20, 0.18);
  790. color: #FF9B47;
  791. }
  792. &.level-3 {
  793. border-color: rgba(126, 35, 33, 0.2);
  794. background-color: rgba(126, 35, 33, 0.2);
  795. color: #FF7D7B;
  796. }
  797. .el-icon {
  798. font-size: 12px;
  799. }
  800. }
  801. &__body {
  802. display: flex;
  803. gap: 10px;
  804. padding: 12px 0;
  805. }
  806. &__thumb {
  807. width: 96px;
  808. height: 96px;
  809. flex-shrink: 0;
  810. border-radius: 8px;
  811. object-fit: cover;
  812. background: rgba(255, 255, 255, 0.06);
  813. }
  814. &__content {
  815. flex: 1;
  816. min-width: 0;
  817. display: flex;
  818. flex-direction: column;
  819. justify-content: space-around;
  820. gap: 4px;
  821. }
  822. &__subject {
  823. color: #fff;
  824. font-size: 16px;
  825. line-height: 24px;
  826. }
  827. &__issue {
  828. color: rgba(255, 255, 255, 0.6);
  829. font-size: 12px;
  830. line-height: 18px;
  831. display: -webkit-box;
  832. -webkit-box-orient: vertical;
  833. -webkit-line-clamp: 2;
  834. overflow: hidden;
  835. word-break: break-all;
  836. }
  837. &__urgency {
  838. display: flex;
  839. align-items: center;
  840. gap: 4px;
  841. margin-top: 2px;
  842. font-size: 12px;
  843. .el-icon {
  844. font-size: 13px;
  845. }
  846. &--success {
  847. color: #85a53e;
  848. }
  849. &--danger {
  850. color: #ff8f8f;
  851. }
  852. &--warn {
  853. color: #ffd489;
  854. }
  855. }
  856. &__urgency-icon {
  857. width: 14px;
  858. height: 14px;
  859. flex-shrink: 0;
  860. object-fit: contain;
  861. }
  862. &__footer {
  863. display: flex;
  864. align-items: center;
  865. justify-content: space-between;
  866. gap: 8px;
  867. }
  868. &__actions {
  869. display: flex;
  870. align-items: center;
  871. gap: 10px;
  872. min-width: 0;
  873. }
  874. &__action {
  875. display: flex;
  876. align-items: center;
  877. gap: 4px;
  878. color: rgba(255, 255, 255, 0.75);
  879. font-size: 12px;
  880. line-height: 16px;
  881. white-space: nowrap;
  882. .el-icon {
  883. font-size: 14px;
  884. }
  885. }
  886. &__divider {
  887. width: 1px;
  888. height: 12px;
  889. background: rgba(255, 255, 255, 0.16);
  890. flex-shrink: 0;
  891. }
  892. &__detail-btn {
  893. flex-shrink: 0;
  894. // height: 32px;
  895. // line-height: 32px;
  896. padding: 7px 10px 8px 10px;
  897. display: flex;
  898. align-items: center;
  899. justify-content: center;
  900. border-radius: 24px;
  901. background: linear-gradient(90deg, #FFEBC9 0%, #FFCA6D 100%);
  902. color: #000;
  903. font-size: 12px;
  904. font-weight: 500;
  905. }
  906. }
  907. }
  908. .bottom-btn-container {
  909. display: flex;
  910. justify-content: space-between;
  911. gap: 12px;
  912. width: 100%;
  913. .bottom-btn {
  914. padding: 0 25px;
  915. border-radius: 4px;
  916. font-size: 16px;
  917. height: 40px;
  918. line-height: 40px;
  919. box-sizing: border-box;
  920. font-weight: 500;
  921. text-align: center;
  922. &.primary-btn {
  923. flex: 1;
  924. background: linear-gradient(135deg, #FFEBC9 0%, #FFCA6D 100%);
  925. color: #1A1408;
  926. }
  927. }
  928. }
  929. @keyframes patrol-spin {
  930. to {
  931. transform: rotate(360deg);
  932. }
  933. }
  934. </style>
  935. <style lang="scss">
  936. .restore-planting-success-popup {
  937. &.tip-popup {
  938. z-index: 20000 !important;
  939. }
  940. }
  941. .el-message.restore-planting-message {
  942. z-index: 40000 !important;
  943. white-space: pre-line;
  944. &.el-message--warning .el-message__content {
  945. width: max-content;
  946. line-height: 19px;
  947. }
  948. }
  949. </style>