soilRootTrack.vue 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. <template>
  2. <div class="soil-root-track-page">
  3. <custom-header
  4. :name="pageTitle"
  5. :isGoBack="!isFromShare"
  6. :isClose="isFromShare"
  7. :showClose="false"
  8. @goback="handleBack"
  9. />
  10. <div class="soil-root-track-body" v-loading="loading" element-loading-background="rgba(15, 15, 15, 0.55)" element-loading-text="加载中...">
  11. <div class="soil-root-hero">
  12. <div class="soil-root-hero__share" @click="handleShare">
  13. <Icon name="share" color="rgba(255,255,255,0.85)" />
  14. <span>{{ t("agriFile.forward") }}</span>
  15. </div>
  16. <div class="soil-root-mask"></div>
  17. <div class="soil-root-top">
  18. <div class="soil-root-hero__tags">
  19. <span class="soil-root-hero__tag soil-root-hero__tag--level">
  20. <el-icon><WarningFilled /></el-icon>
  21. {{ level }}
  22. </span>
  23. <span class="soil-root-hero__tag soil-root-hero__tag--zone">{{ zoneName }}</span>
  24. </div>
  25. <div class="soil-root-hero__title">{{ theme }}</div>
  26. <div class="soil-root-hero__reason">{{ reason }}</div>
  27. </div>
  28. </div>
  29. <div class="soil-root-main">
  30. <!-- 农情研判 -->
  31. <div class="box-wrap stage-card analysis-card">
  32. <div class="work-info">
  33. <div class="section-title">
  34. <span class="title-bar"></span>
  35. {{ t("agriFile.agriAssessment") }}
  36. </div>
  37. <div class="analysis-card__desc">{{ assessmentDesc }}</div>
  38. <!-- <div class="analysis-card__stats">
  39. <div v-for="(item, index) in analysisStats" :key="index" class="analysis-card__stat">
  40. <div class="analysis-card__stat-value" :class="{ highlight: item.highlight }">
  41. <template v-if="item.unit">
  42. <span class="num">{{ item.value }}</span>
  43. <span class="unit">{{ item.unit }}</span>
  44. </template>
  45. <template v-else>{{ item.value }}</template>
  46. </div>
  47. <div class="analysis-card__stat-label">{{ item.label }}</div>
  48. </div>
  49. </div> -->
  50. </div>
  51. </div>
  52. <!-- 根系排查互动 -->
  53. <!-- <div class="interact-section-head">
  54. <span class="interact-section-head__text"> 根系排查互动 · 共 {{ interactList.length }} 项 </span>
  55. <span class="interact-section-head__line"></span>
  56. </div> -->
  57. <div v-for="(item, index) in interactList" :key="item.fw_code || index" class="soil-root-item">
  58. <div class="soil-root-item__wrap">
  59. <div class="soil-root-item__title">
  60. <img class="soil-root-item__icon" src="@/assets/img/agricultural/gaojin.png" alt="" />
  61. <span>{{ item.abnormal_type || t("agriFile.rootAbnormal") }}</span>
  62. </div>
  63. <div class="stage-card interact-card">
  64. <div class="work-info">
  65. <!-- 已答:问题 + 答案一句 + 修改;点修改后回到选项态 -->
  66. <div v-if="isAnsweredView(item, index)" class="interact-card__answered">
  67. <div class="interact-card__answered-text">
  68. <span class="interact-card__answered-problem">{{
  69. item.interact_problem
  70. }}:</span>
  71. <span class="interact-card__answered-value">{{
  72. resolveAnswerText(item)
  73. }}</span>
  74. </div>
  75. <div class="interact-card__edit" @click="startEdit(item, index)">
  76. 修改
  77. <el-icon class="interact-card__edit-icon"><Edit /></el-icon>
  78. </div>
  79. </div>
  80. <template v-else>
  81. <div class="interact-card__head">
  82. <div class="section-title interact-card__title">
  83. <span class="title-bar"></span>
  84. {{ t("agriFile.interactQuestion") }}
  85. </div>
  86. <div
  87. class="interact-card__submit"
  88. :class="{ disabled: selectedMap[item.fw_code || index] == null }"
  89. @click="handleSubmit(item, index)"
  90. >
  91. 确认提交
  92. </div>
  93. </div>
  94. <div class="interact-card__qa">
  95. <div class="interact-card__question">{{ item.interact_problem }}</div>
  96. <div class="interact-card__options">
  97. <div
  98. v-for="(opt, optIndex) in item.options"
  99. :key="`${item.fw_code || index}-${optIndex}`"
  100. class="interact-option"
  101. :class="{
  102. selected: selectedMap[item.fw_code || index] === optIndex,
  103. }"
  104. @click="selectedMap[item.fw_code || index] = optIndex"
  105. >
  106. <span class="interact-option__text">{{ opt }}</span>
  107. </div>
  108. </div>
  109. </div>
  110. </template>
  111. </div>
  112. </div>
  113. <!-- 巡园向导 -->
  114. <div class="guide-card">
  115. <div class="work-info">
  116. <div class="section-title">
  117. <img class="guide-icon" src="@/assets/img/farm/guide.png" alt="" />
  118. {{ t("agriFile.patrolGuide") }}
  119. </div>
  120. <div class="guide-card__img-box">
  121. <photo-provider :photo-closable="true">
  122. <photo-consumer :src="resolveGuideImage(item.pic_url)">
  123. <img :src="resolveGuideImage(item.pic_url)" alt="" />
  124. </photo-consumer>
  125. </photo-provider>
  126. </div>
  127. </div>
  128. <div class="guide-card__upload-wrap">
  129. <div class="guide-card__upload" @click="handleUploadClick">
  130. <img class="guide-card__upload-icon" src="@/assets/img/common/camera.png" alt="" />
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. <!-- 土壤条件判断 -->
  137. <!-- <div class="interact-section-head">
  138. <span class="interact-section-head__text"> 土壤条件判断 · 共 {{ soilSections.length }} 项 </span>
  139. <span class="interact-section-head__line"></span>
  140. </div> -->
  141. <!-- <div v-for="section in soilSections" :key="section.key" class="soil-section-card">
  142. <div class="soil-section-card__wrap">
  143. <div class="soil-section-card__title">
  144. <img class="soil-section-card__icon" src="@/assets/img/agricultural/gaojin.png" alt="" />
  145. <span>{{ section.title }}</span>
  146. </div>
  147. <div class="soil-section-card__question">{{ section.question }}</div>
  148. <div class="soil-section-card__options">
  149. <div
  150. v-for="opt in section.options"
  151. :key="`${section.key}-${opt.value}`"
  152. class="interact-option"
  153. :class="{ selected: isSectionSelected(section, opt.value) }"
  154. @click="toggleSectionOption(section, opt.value)"
  155. >
  156. <span class="interact-option__text">{{ opt.label }}</span>
  157. </div>
  158. </div>
  159. <div v-if="section.guide && section.guide.desc" class="soil-section-card__guide">
  160. <div class="section-title">
  161. <img class="guide-icon" src="@/assets/img/farm/guide.png" alt="" />
  162. {{ t("agriFile.patrolGuide") }}
  163. </div>
  164. <div class="soil-section-card__guide-desc">{{ section.guide.desc }}</div>
  165. </div>
  166. </div>
  167. </div> -->
  168. <div v-for="(section, index) in soilSections" :key="index" class="soil-root-item">
  169. <div class="soil-root-item__wrap">
  170. <div class="soil-root-item__title">
  171. <img class="soil-root-item__icon" src="@/assets/img/agricultural/gaojin.png" alt="" />
  172. <span>{{ section.title || t("agriFile.rootAbnormal") }}</span>
  173. </div>
  174. <div class="stage-card interact-card">
  175. <div class="work-info">
  176. <div class="interact-card__head">
  177. <div class="section-title interact-card__title">
  178. <span class="title-bar"></span>
  179. {{ t("agriFile.interactQuestion") }}
  180. </div>
  181. <div
  182. class="interact-card__submit"
  183. @click="handleSubmit(section, index)"
  184. >
  185. <!-- :class="{ disabled: selectedMap[item.fw_code || index] == null }" -->
  186. 确认提交
  187. </div>
  188. </div>
  189. <div class="interact-card__qa">
  190. <div class="interact-card__question">{{ section.question }}</div>
  191. <div class="interact-card__options soil-section-card__options">
  192. <div
  193. v-for="opt in section.options"
  194. :key="`${section.key}-${opt.value}`"
  195. class="interact-option"
  196. :class="{ selected: isSectionSelected(section, opt.value) }"
  197. @click="toggleSectionOption(section, opt.value)"
  198. >
  199. <span class="interact-option__text">{{ opt.label }}</span>
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. </div>
  205. <!-- 巡园向导 -->
  206. <div class="guide-card">
  207. <div class="work-info">
  208. <div class="section-title">
  209. <img class="guide-icon" src="@/assets/img/farm/guide.png" alt="" />
  210. {{ t("agriFile.patrolGuide") }}
  211. </div>
  212. <div class="soil-section-card__guide-desc">{{ section.guide.desc }}</div>
  213. <div class="guide-card__img-box" v-if="section.image_url">
  214. <photo-provider :photo-closable="true">
  215. <photo-consumer :src="base_img_url3+section.image_url">
  216. <img :src="base_img_url3 + section.image_url" alt="" />
  217. </photo-consumer>
  218. </photo-provider>
  219. </div>
  220. </div>
  221. <div class="guide-card__upload-wrap">
  222. <div class="guide-card__upload" @click="handleUploadClick">
  223. <img class="guide-card__upload-icon" src="@/assets/img/common/camera.png" alt="" />
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. </div>
  230. </div>
  231. <album-upload-popup v-model:show="showUploadPopup" @confirm="handleUploadConfirm" />
  232. <tip-popup
  233. v-model:show="showSuccessPopup"
  234. type="executeSuccess"
  235. text="您已上传成功"
  236. text2="诊断报告正在生成,请稍后..."
  237. hideBtn
  238. >
  239. <template #footer>
  240. <div class="bottom-btn-container">
  241. <div class="bottom-btn primary-btn" @click="handleComplete">完成</div>
  242. </div>
  243. </template>
  244. </tip-popup>
  245. </div>
  246. </template>
  247. <script setup>
  248. import { computed, nextTick, onActivated, reactive, ref } from "vue";
  249. import { useRoute, useRouter } from "vue-router";
  250. import { Icon } from "vant";
  251. import { ElMessage } from "element-plus";
  252. import { Edit } from "@element-plus/icons-vue";
  253. import customHeader from "@/components/customHeader.vue";
  254. import albumUploadPopup from "../components/albumUploadPopup.vue";
  255. import tipPopup from "@/components/popup/tipPopup.vue";
  256. import { useI18n } from "@/i18n";
  257. import { resolvePairedFarmZone } from "@/utils/selectedFarm";
  258. import { base_img_url2, base_img_url3 } from "@/api/config";
  259. import wx from "weixin-js-sdk";
  260. const { t } = useI18n();
  261. const route = useRoute();
  262. const router = useRouter();
  263. // ---------- 常量 ----------
  264. const DEFAULT_GUIDE_IMAGE = require("@/assets/img/agricultural/patrol-guide.png");
  265. /** 农情研判底部指标:接口未接好前写死(土壤根系相关) */
  266. const analysisStats = [
  267. { value: "126", unit: "mm", label: "累计降雨", highlight: false },
  268. { value: "92", unit: "%", label: "土壤含水率", highlight: false },
  269. { value: "52", unit: "h", label: "根部积水", highlight: true },
  270. ];
  271. // ---------- 页面状态 ----------
  272. const loading = ref(false);
  273. const submitting = ref(false);
  274. const showUploadPopup = ref(false);
  275. const showSuccessPopup = ref(false);
  276. const needDraw = ref(true); // status≠1 时需先勾画种植范围
  277. const interactList = ref([]); // root 根系排查互动项(取 data.root)
  278. const soilSections = ref([]); // 土壤条件判断(质地/酸碱/墒情/氮磷钾/持水)
  279. const sectionSelected = reactive({}); // section.key → 选中值(多选为数组)
  280. const stressInfo = ref({}); // 胁迫等级等公共信息
  281. const selectedMap = reactive({}); // fw_code/index → 选项下标
  282. const editingMap = reactive({}); // fw_code/index → 已答后点「修改」进入选项态
  283. /** 与查询共用的提交上下文,保证 fw 答案与列表同源 */
  284. const queryContext = ref({
  285. farm_id: null,
  286. zone_id: null,
  287. calc_date: "",
  288. crop_type: "",
  289. });
  290. // ---------- 计算属性 ----------
  291. const pageTitle = computed(() => route.query.pageName || t("agriFile.patrolSoilTitle"));
  292. const zoneId = computed(() => route.query.zoneId || route.query.id);
  293. const firstInteract = computed(() => interactList.value[0] || null);
  294. /** interaction_theme */
  295. const theme = computed(() => firstInteract.value?.interaction_title || t("agriFile.soilRootTheme"));
  296. /** interaction_title */
  297. const reason = computed(() => firstInteract.value?.interaction_theme || t("agriFile.soilRootReason"));
  298. /** 农情研判说明 */
  299. const assessmentDesc = computed(() => firstInteract.value?.interaction_reason || t("agriFile.soilRootAssessment"));
  300. const guideImage = computed(() => resolveGuideImage(firstInteract.value?.pic_url));
  301. /** stress_info.level */
  302. const level = computed(() => {
  303. const lv = stressInfo.value?.level;
  304. if (lv == null || lv === "") return t("agriFile.riskLevel2");
  305. return `${lv}级`;
  306. });
  307. const zoneName = computed(() => {
  308. const farm = getSelectedFarm();
  309. return farm.variety_name || farm.zone_name || t("agriFile.zoneOne");
  310. });
  311. /** 通过分享进入:无返回箭头 */
  312. const isFromShare = computed(() => {
  313. if (isTruthyFlag(route.query.fromShare)) return true;
  314. const paramsPage = parseMaybeJson(route.query.paramsPage);
  315. if (isTruthyFlag(paramsPage?.fromShare)) return true;
  316. const miniJson = parseMaybeJson(route.query.miniJson);
  317. if (isTruthyFlag(miniJson?.fromShare)) return true;
  318. if (isTruthyFlag(parseMaybeJson(miniJson?.paramsPage)?.fromShare)) return true;
  319. return false;
  320. });
  321. // ---------- 工具函数 ----------
  322. function isTruthyFlag(value) {
  323. return value === 1 || value === "1" || value === true || value === "true";
  324. }
  325. function parseMaybeJson(value) {
  326. if (value == null || value === "") return null;
  327. if (typeof value === "object") return value;
  328. try {
  329. return JSON.parse(value);
  330. } catch {
  331. return null;
  332. }
  333. }
  334. function getSelectedFarm() {
  335. try {
  336. return JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
  337. } catch {
  338. return {};
  339. }
  340. }
  341. function getSelectedFarmId() {
  342. const stored = localStorage.getItem("selectedFarmId");
  343. if (stored != null && stored !== "") return Number(stored);
  344. const farm = getSelectedFarm();
  345. const id = farm.farm_id ?? farm.id;
  346. return id != null && id !== "" ? Number(id) : null;
  347. }
  348. /** 农场品类编码,接口 crop_type */
  349. const resolveCropType = (farm = getSelectedFarm()) =>
  350. farm.category_code || farm.categorycode || farm.crop_code || farm.crop_type || "";
  351. function resolveImageUrl(path) {
  352. if (!path) return "";
  353. const text = String(path).trim();
  354. if (!text) return "";
  355. if (/^https?:\/\//i.test(text)) return text;
  356. return base_img_url2 + text.replace(/^\//, "");
  357. }
  358. function resolveGuideImage(picUrl) {
  359. return resolveImageUrl(picUrl) || DEFAULT_GUIDE_IMAGE;
  360. }
  361. /** interact_options 可能是 JSON 字符串 */
  362. function parseInteractOptions(value) {
  363. if (Array.isArray(value)) return value.map((name) => String(name));
  364. const parsed = parseMaybeJson(value);
  365. if (Array.isArray(parsed)) return parsed.map((name) => String(name));
  366. return [];
  367. }
  368. /** 已答文案:提交字段为 options,回显兼容 answer / interact_answer / 字符串 options */
  369. function resolveAnswerText(item) {
  370. const raw =
  371. item?.answerText ||
  372. item?.answer ||
  373. item?.interact_answer ||
  374. item?.fw_answer ||
  375. (typeof item?.options === "string" ? item.options : "");
  376. return raw != null && raw !== "" ? String(raw) : "";
  377. }
  378. function mapInteractItem(raw) {
  379. const optionsStr =
  380. typeof raw?.options === "string" && raw.options.trim() && !raw.options.trim().startsWith("[")
  381. ? raw.options
  382. : "";
  383. return {
  384. ...raw,
  385. options: parseInteractOptions(raw?.interact_options),
  386. answerText: String(raw?.answer ?? raw?.interact_answer ?? raw?.fw_answer ?? optionsStr ?? ""),
  387. };
  388. }
  389. function interactKey(item, index) {
  390. return item?.fw_code || index;
  391. }
  392. /** 已答且未进入修改态 */
  393. function isAnsweredView(item, index) {
  394. return Number(item?.is_answered) === 1 && !editingMap[interactKey(item, index)];
  395. }
  396. /** 点修改:回到选项,并尽量回填当前答案 */
  397. function startEdit(item, index) {
  398. const key = interactKey(item, index);
  399. editingMap[key] = true;
  400. const answer = resolveAnswerText(item);
  401. if (!answer || !Array.isArray(item?.options)) return;
  402. const optIndex = item.options.findIndex((opt) => opt === answer);
  403. if (optIndex >= 0) selectedMap[key] = optIndex;
  404. }
  405. const formatLocalDate = (date) => {
  406. const y = date.getFullYear();
  407. const m = String(date.getMonth() + 1).padStart(2, "0");
  408. const d = String(date.getDate()).padStart(2, "0");
  409. return `${y}-${m}-${d}`;
  410. };
  411. // ---------- 业务逻辑 ----------
  412. // 土壤根系感知:GET VE_API.pheno.getSoilTasks({ zone_id }),返回 data.root(根系排查互动)
  413. // 与 data.sections(土壤条件判断:质地/酸碱/墒情/氮磷钾/持水)
  414. const fetchSoilRootInteract = async () => {
  415. const farm = getSelectedFarm();
  416. const { farmId, zoneId: zId } = await resolvePairedFarmZone(zoneId.value);
  417. if (farmId == null || zId == null || zId === "") {
  418. interactList.value = [];
  419. stressInfo.value = {};
  420. soilSections.value = [];
  421. return;
  422. }
  423. // 提交上下文:confirmAbnormalInteract 需完整参数,取本地农场信息补全
  424. queryContext.value = {
  425. farm_id: farmId,
  426. zone_id: zId,
  427. calc_date: formatLocalDate(new Date()),
  428. crop_type: resolveCropType(farm),
  429. };
  430. loading.value = true;
  431. try {
  432. const res = await VE_API.pheno.getSoilTasks({ zone_id: zId });
  433. if (res?.code !== 200) {
  434. interactList.value = [];
  435. stressInfo.value = {};
  436. soilSections.value = [];
  437. return;
  438. }
  439. const data = res?.data || {};
  440. const root = data.root || {};
  441. interactList.value = Object.keys(root).length ? [mapInteractItem(root)] : [];
  442. // hero 等级取 root.level_num(如 2),level 计算属性会拼成「2级」
  443. stressInfo.value = { level: root.level_num ?? null };
  444. soilSections.value = Array.isArray(data.sections) ? data.sections : [];
  445. } catch (e) {
  446. console.warn("[soilRootTrack] getSoilTasks failed", e);
  447. interactList.value = [];
  448. stressInfo.value = {};
  449. soilSections.value = [];
  450. } finally {
  451. loading.value = false;
  452. }
  453. };
  454. /** status=1 有范围无需勾画;status=0 无范围需要勾画 */
  455. const fetchZoneRangeStatus = async () => {
  456. const { farmId, zoneId: zId } = await resolvePairedFarmZone(zoneId.value);
  457. if (farmId == null || farmId === "" || zId == null || zId === "") {
  458. needDraw.value = true;
  459. return;
  460. }
  461. try {
  462. const res = await VE_API.questionnaire.checkZoneRange({
  463. farm_id: farmId,
  464. zone_id: zId,
  465. });
  466. needDraw.value = Number(res?.data?.status) !== 1;
  467. } catch (e) {
  468. console.warn("[soilRootTrack] checkZoneRange failed", e);
  469. needDraw.value = true;
  470. }
  471. };
  472. // ---------- 事件处理 / 生命周期 ----------
  473. const handleShare = () => {
  474. const query = {
  475. askInfo: { title: "转发巡园要点", content: "是否分享给好友" },
  476. shareText: theme.value || "土壤根系巡园要点",
  477. targetUrl: "soil_root_track",
  478. paramsPage: JSON.stringify({
  479. id: route.query.id,
  480. zoneId: zoneId.value,
  481. fromShare: 1,
  482. ...(route.query.pageName ? { pageName: route.query.pageName } : {}),
  483. }),
  484. imageUrl: "https://birdseye-img.sysuimars.com/farm-h5/growth_cover.png",
  485. };
  486. wx.miniProgram.navigateTo({
  487. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=sharePage`,
  488. });
  489. };
  490. /** 需勾画则先画范围;否则直接上传(同 abnormalTrack) */
  491. const handleUploadClick = () => {
  492. if (needDraw.value) {
  493. router.push({
  494. path: "/add_zone",
  495. query: {
  496. type: "farm",
  497. targetUrl: "/soil_root_track",
  498. ...(zoneId.value ? { trackId: zoneId.value } : {}),
  499. },
  500. });
  501. return;
  502. }
  503. showUploadPopup.value = true;
  504. };
  505. const handleUploadConfirm = async ({ images, date } = {}) => {
  506. const cloud_url = Array.isArray(images) ? images : [];
  507. if (!cloud_url.length) {
  508. ElMessage.warning("请先上传照片");
  509. return;
  510. }
  511. const farm = getSelectedFarm();
  512. const { farmId, zoneId: pairedZoneId } = await resolvePairedFarmZone(zoneId.value);
  513. if (farmId == null || pairedZoneId == null || pairedZoneId === "") {
  514. ElMessage.warning("当前农场与分区不匹配,请返回后重试");
  515. return;
  516. }
  517. try {
  518. const res = await VE_API.questionnaire.uploadImages({
  519. cloud_url,
  520. farm_id: farmId,
  521. zone_id: pairedZoneId,
  522. category_code: farm.category_code || "",
  523. zone_name: farm.variety_name || "",
  524. create_time: date,
  525. });
  526. if (res?.code === 200) {
  527. showSuccessPopup.value = true;
  528. return;
  529. }
  530. ElMessage.error(res?.msg || "上传失败,请稍后再试");
  531. } catch {
  532. ElMessage.error("上传失败,请稍后再试");
  533. }
  534. };
  535. const handleComplete = () => {
  536. showSuccessPopup.value = false;
  537. router.replace("/agri_file");
  538. };
  539. const handleSubmit = async (item, index) => {
  540. const key = interactKey(item, index);
  541. const optIndex = selectedMap[key];
  542. if (optIndex == null) {
  543. ElMessage.warning(t("agriFile.pleaseSelectOption"));
  544. return;
  545. }
  546. const optionText = item?.options?.[optIndex];
  547. if (!optionText || !item?.fw_code) {
  548. ElMessage.warning(t("agriFile.pleaseSelectOption"));
  549. return;
  550. }
  551. if (submitting.value) return;
  552. submitting.value = true;
  553. try {
  554. const res = await VE_API.questionnaire.confirmAbnormalInteract({
  555. ...queryContext.value,
  556. fw_code: item.fw_code,
  557. options: String(optionText),
  558. });
  559. if (res?.code === 200) {
  560. ElMessage.success(t("agriFile.submitSuccess"));
  561. editingMap[key] = false;
  562. await fetchSoilRootInteract();
  563. return;
  564. }
  565. ElMessage.error(res?.msg || "提交失败,请稍后再试");
  566. } catch (e) {
  567. console.warn("[soilRootTrack] confirmAbnormalInteract failed", e);
  568. ElMessage.error("提交失败,请稍后再试");
  569. } finally {
  570. submitting.value = false;
  571. }
  572. };
  573. const handleBack = () => {
  574. router.back();
  575. };
  576. // 土壤条件判断:单选 / 多选选项切换
  577. const isSectionSelected = (section, value) => {
  578. const sel = sectionSelected[section.key];
  579. if (section.multiple) return Array.isArray(sel) && sel.includes(value);
  580. return sel === value;
  581. };
  582. const toggleSectionOption = (section, value) => {
  583. if (section.multiple) {
  584. const cur = Array.isArray(sectionSelected[section.key])
  585. ? sectionSelected[section.key]
  586. : [];
  587. sectionSelected[section.key] = cur.includes(value)
  588. ? cur.filter((v) => v !== value)
  589. : [...cur, value];
  590. } else {
  591. sectionSelected[section.key] =
  592. sectionSelected[section.key] === value ? null : value;
  593. }
  594. };
  595. /** keep-alive 离开再进:清掉「修改」态,按接口已答态回到「已答 + 修改」 */
  596. function resetEditingState() {
  597. Object.keys(editingMap).forEach((k) => delete editingMap[k]);
  598. }
  599. onActivated(() => {
  600. resetEditingState();
  601. fetchZoneRangeStatus();
  602. fetchSoilRootInteract();
  603. if (route.query.showUpload !== "1") return;
  604. nextTick(() => {
  605. showUploadPopup.value = true;
  606. const { showUpload, ...restQuery } = route.query;
  607. router.replace({ path: route.path, query: restQuery });
  608. });
  609. });
  610. </script>
  611. <style lang="scss" scoped>
  612. .soil-root-track-page {
  613. display: flex;
  614. flex-direction: column;
  615. width: 100%;
  616. height: 100vh;
  617. overflow: hidden;
  618. background: #0b0b0b;
  619. color: #fff;
  620. .soil-root-track-body {
  621. flex: 1;
  622. overflow-y: auto;
  623. -webkit-overflow-scrolling: touch;
  624. padding-bottom: 10px;
  625. box-sizing: border-box;
  626. }
  627. .soil-root-hero {
  628. position: relative;
  629. padding: 106px 70px 16px 12px;
  630. box-sizing: border-box;
  631. z-index: 2;
  632. // min-height: 240px;
  633. background: linear-gradient(
  634. 180deg,
  635. rgba(11, 11, 11, 0) 8.51%,
  636. rgba(11, 11, 11, 0.416) 42.95%,
  637. rgba(11, 11, 11, 0.468) 56.49%,
  638. rgba(11, 11, 11, 0.52) 80.47%
  639. ),
  640. url("@/assets/img/agricultural/soil-detail-bg.png") right bottom / cover no-repeat;
  641. .soil-root-mask {
  642. position: absolute;
  643. bottom: 0;
  644. left: 0;
  645. width: 100%;
  646. height: 107px;
  647. background: linear-gradient(
  648. 180deg,
  649. rgba(11, 11, 11, 0) 8.47%,
  650. rgba(11, 11, 11, 0.8) 26.93%,
  651. rgba(11, 11, 11, 0.9) 37.74%,
  652. #0b0b0b 56.89%
  653. );
  654. }
  655. .soil-root-top {
  656. position: relative;
  657. z-index: 2;
  658. // padding-bottom: 40px;
  659. }
  660. &__share {
  661. position: absolute;
  662. top: 16px;
  663. right: 16px;
  664. z-index: 2;
  665. display: inline-flex;
  666. align-items: center;
  667. gap: 4px;
  668. height: 28px;
  669. padding: 0 12px;
  670. border-radius: 14px;
  671. background: rgba(0, 0, 0, 0.45);
  672. border: 1px solid rgba(255, 255, 255, 0.12);
  673. color: rgba(255, 255, 255, 0.85);
  674. font-size: 12px;
  675. }
  676. &__tags {
  677. display: flex;
  678. align-items: center;
  679. flex-wrap: wrap;
  680. gap: 8px;
  681. margin-bottom: 12px;
  682. padding-right: 88px;
  683. }
  684. &__tag {
  685. display: inline-flex;
  686. align-items: center;
  687. gap: 3px;
  688. height: 20px;
  689. padding: 0 7px;
  690. border-radius: 24px;
  691. font-size: 12px;
  692. line-height: 20px;
  693. box-sizing: border-box;
  694. border: 1px solid rgba(138, 106, 46, 1);
  695. }
  696. &__tag--level {
  697. background: linear-gradient(90deg, #7e2321 0%, #350302 100%);
  698. color: #ff7d7b;
  699. border-color: rgba(201, 53, 50, 0.41);
  700. }
  701. &__tag--zone {
  702. color: #e8c27a;
  703. background: #2a2418;
  704. }
  705. &__title {
  706. font-family: "PangMenZhengDao", sans-serif;
  707. font-size: 26px;
  708. line-height: 34px;
  709. background: linear-gradient(180deg, #ffffff 0%, #fecd76 100%);
  710. -webkit-background-clip: text;
  711. background-clip: text;
  712. color: transparent;
  713. margin-bottom: 6px;
  714. }
  715. &__reason {
  716. font-size: 12px;
  717. line-height: 22px;
  718. padding: 4px;
  719. border-radius: 4px;
  720. background: linear-gradient(90deg, rgba(255, 212, 137, 0.1) 0%, rgba(255, 212, 137, 0) 100%);
  721. color: rgba(255, 255, 255, 1);
  722. }
  723. }
  724. .soil-root-main {
  725. position: relative;
  726. z-index: 3;
  727. // margin-top: -38px;
  728. padding: 0 12px 12px;
  729. box-sizing: border-box;
  730. }
  731. .box-wrap {
  732. padding: 1px;
  733. border-radius: 12px;
  734. background: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 72.15%);
  735. .work-info {
  736. background: linear-gradient(180deg, #1a191d 0%, #121216 100%);
  737. border-radius: 12px;
  738. padding: 12px 13px;
  739. box-sizing: border-box;
  740. }
  741. }
  742. .stage-card + .stage-card {
  743. margin-top: 12px;
  744. }
  745. .section-title {
  746. display: flex;
  747. align-items: center;
  748. gap: 10px;
  749. font-size: 16px;
  750. font-weight: 500;
  751. color: #f2e9d8;
  752. margin-bottom: 10px;
  753. &.interact-card__title {
  754. font-size: 14px;
  755. }
  756. .title-bar {
  757. width: 4px;
  758. height: 16px;
  759. border-radius: 2px;
  760. background: #ffd489;
  761. flex-shrink: 0;
  762. }
  763. }
  764. .analysis-card {
  765. .analysis-card__desc {
  766. font-size: 14px;
  767. line-height: 22px;
  768. color: rgba(255, 255, 255, 0.6);
  769. margin-bottom: 10px;
  770. }
  771. .analysis-card__stats {
  772. display: flex;
  773. align-items: stretch;
  774. background: rgba(255, 255, 255, 0.05);
  775. border-radius: 10px;
  776. padding: 8px 0 6px;
  777. }
  778. .analysis-card__stat {
  779. flex: 1;
  780. min-width: 0;
  781. text-align: center;
  782. position: relative;
  783. & + .analysis-card__stat::before {
  784. content: "";
  785. position: absolute;
  786. left: 0;
  787. top: 50%;
  788. transform: translateY(-50%);
  789. width: 1px;
  790. height: 32px;
  791. background: rgba(255, 255, 255, 0.06);
  792. }
  793. }
  794. .analysis-card__stat-value {
  795. font-size: 22px;
  796. line-height: 27px;
  797. color: #fff;
  798. margin-bottom: 2px;
  799. height: 27px;
  800. &.highlight {
  801. color: #ff9f5a;
  802. }
  803. .num {
  804. font-size: 22px;
  805. font-weight: 600;
  806. }
  807. .unit {
  808. color: rgba(255, 255, 255, 0.5);
  809. margin-left: 1px;
  810. font-size: 12px;
  811. }
  812. }
  813. .analysis-card__stat-label {
  814. font-size: 12px;
  815. line-height: 18px;
  816. color: rgba(255, 255, 255, 0.5);
  817. }
  818. }
  819. .interact-section-head {
  820. display: flex;
  821. align-items: center;
  822. gap: 10px;
  823. margin: 16px 0 12px;
  824. &__text {
  825. flex-shrink: 0;
  826. font-size: 12px;
  827. line-height: 18px;
  828. color: #727272;
  829. }
  830. &__line {
  831. flex: 1;
  832. height: 1px;
  833. background: rgba(255, 255, 255, 0.08);
  834. }
  835. }
  836. .soil-root-item {
  837. margin-top: 12px;
  838. padding: 1px;
  839. border-radius: 12px;
  840. background: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 25%),
  841. linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 25%);
  842. &__wrap {
  843. padding: 11px 13px;
  844. border-radius: 12px;
  845. background: linear-gradient(180deg, #1A191D 0%, #121216 100%);
  846. }
  847. & + .soil-root-item {
  848. margin-top: 16px;
  849. }
  850. &__title {
  851. display: flex;
  852. align-items: center;
  853. gap: 10px;
  854. margin-bottom: 12px;
  855. font-size: 16px;
  856. font-weight: 500;
  857. color: #FFD489;
  858. }
  859. &__icon {
  860. width: 18px;
  861. height: 23px;
  862. object-fit: contain;
  863. }
  864. }
  865. .soil-section-card {
  866. padding: 1px;
  867. margin-top: 12px;
  868. border-radius: 12px;
  869. background: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 25%),
  870. linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 25%);
  871. &__wrap {
  872. padding: 11px 13px;
  873. border-radius: 12px;
  874. background: linear-gradient(180deg, #1A191D 0%, #121216 100%);
  875. }
  876. &__title {
  877. display: flex;
  878. align-items: center;
  879. gap: 10px;
  880. margin-bottom: 12px;
  881. font-size: 16px;
  882. font-weight: 500;
  883. color: #FFD489;
  884. }
  885. &__icon {
  886. width: 18px;
  887. height: 23px;
  888. object-fit: contain;
  889. }
  890. &__question {
  891. font-size: 16px;
  892. font-family: "PangMenZhengDao";
  893. line-height: 20px;
  894. color: #FFD489;
  895. margin-bottom: 12px;
  896. }
  897. &__options {
  898. display: flex;
  899. flex-wrap: wrap;
  900. gap: 12px;
  901. &.soil-section-card__options {
  902. display: grid;
  903. grid-template-columns: repeat(3, 1fr);
  904. }
  905. }
  906. &__guide {
  907. margin-top: 12px;
  908. background: rgba(75, 74, 70, 0.2);
  909. border-radius: 10px;
  910. padding: 10px;
  911. .section-title {
  912. gap: 6px;
  913. font-size: 14px;
  914. color: rgba(255, 255, 255, 0.6);
  915. }
  916. .guide-icon {
  917. width: 14px;
  918. height: 14px;
  919. object-fit: contain;
  920. filter: grayscale(100%);
  921. -webkit-filter: grayscale(100%);
  922. }
  923. &-desc {
  924. margin: 8px 0;
  925. font-size: 13px;
  926. line-height: 20px;
  927. color: rgba(255, 255, 255, 0.55);
  928. }
  929. }
  930. }
  931. .interact-card {
  932. padding: 10px 12px;
  933. border-radius: 12px;
  934. border: 1px solid rgba(255, 241, 217, 0.2);
  935. background: linear-gradient(180deg, #1A191D 0%, #121216 100%);
  936. &__head {
  937. display: flex;
  938. align-items: center;
  939. justify-content: space-between;
  940. gap: 8px;
  941. margin-bottom: 12px;
  942. .section-title {
  943. margin-bottom: 0;
  944. }
  945. }
  946. &__submit {
  947. flex-shrink: 0;
  948. height: 27px;
  949. padding: 0 15px;
  950. border-radius: 24px;
  951. background: rgba(255, 212, 137, 0.1);
  952. border: 1px solid rgba(255, 212, 137, 0.4);
  953. color: #FFD489;
  954. font-size: 12px;
  955. line-height: 27px;
  956. text-align: center;
  957. box-sizing: border-box;
  958. &.disabled {
  959. opacity: 0.35;
  960. }
  961. }
  962. &__question {
  963. font-size: 16px;
  964. font-family: "PangMenZhengDao";
  965. line-height: 20px;
  966. color: #FFD489;
  967. margin-bottom: 12px;
  968. }
  969. &__answered {
  970. display: flex;
  971. align-items: center;
  972. justify-content: space-between;
  973. gap: 6px;
  974. }
  975. &__answered-text {
  976. flex: 1;
  977. min-width: 0;
  978. font-size: 14px;
  979. line-height: 22px;
  980. word-break: break-all;
  981. }
  982. &__answered-problem {
  983. color: rgba(255, 255, 255, 0.85);
  984. }
  985. &__answered-value {
  986. padding-left: 4px;
  987. color: #ffd489;
  988. }
  989. &__edit {
  990. flex-shrink: 0;
  991. display: inline-flex;
  992. align-items: center;
  993. gap: 4px;
  994. height: 22px;
  995. padding: 0 10px;
  996. border-radius: 12px;
  997. background: rgba(255, 212, 137, 0.1);
  998. color: #ffd489;
  999. font-size: 12px;
  1000. line-height: 22px;
  1001. box-sizing: border-box;
  1002. }
  1003. &__edit-icon {
  1004. font-size: 12px;
  1005. color: #ffd489;
  1006. }
  1007. &__options {
  1008. display: flex;
  1009. gap: 12px;
  1010. flex-wrap: wrap;
  1011. }
  1012. .interact-option {
  1013. position: relative;
  1014. flex: auto;
  1015. min-width: 0;
  1016. min-height: 41px;
  1017. display: flex;
  1018. align-items: center;
  1019. justify-content: center;
  1020. border-radius: 8px;
  1021. background: rgba(255, 255, 255, 0.05);
  1022. border: 1px solid rgba(255, 255, 255, 0.12);
  1023. box-sizing: border-box;
  1024. cursor: pointer;
  1025. &__text {
  1026. display: block;
  1027. padding: 0 6px;
  1028. overflow: hidden;
  1029. text-overflow: ellipsis;
  1030. white-space: nowrap;
  1031. font-size: 14px;
  1032. color: rgba(255, 255, 255, 0.7);
  1033. }
  1034. &.selected {
  1035. border-color: rgba(255, 255, 255, 0.5);
  1036. background: rgba(255, 255, 255, 0.1);
  1037. .interact-option__text {
  1038. color: #fff;
  1039. }
  1040. }
  1041. }
  1042. }
  1043. .guide-card {
  1044. position: relative;
  1045. margin-top: 12px;
  1046. background: rgba(75, 74, 70, 0.2);
  1047. border-radius: 10px;
  1048. padding: 10px;
  1049. &__img {
  1050. display: block;
  1051. width: 100%;
  1052. border-radius: 8px;
  1053. }
  1054. .guide-card__img-box {
  1055. img {
  1056. display: block;
  1057. width: 100%;
  1058. }
  1059. }
  1060. .section-title {
  1061. gap: 6px;
  1062. font-size: 14px;
  1063. color: rgba(255, 255, 255, 0.6);
  1064. }
  1065. .guide-icon {
  1066. width: 14px;
  1067. height: 14px;
  1068. object-fit: contain;
  1069. filter: grayscale(100%);
  1070. -webkit-filter: grayscale(100%);
  1071. }
  1072. }
  1073. .guide-card__upload-wrap {
  1074. position: absolute;
  1075. right: 25px;
  1076. bottom: 27px;
  1077. z-index: 10;
  1078. }
  1079. .guide-card__upload {
  1080. display: flex;
  1081. align-items: center;
  1082. justify-content: center;
  1083. width: 52px;
  1084. height: 52px;
  1085. border-radius: 50%;
  1086. background: linear-gradient(90deg, #ffebc9 0%, #ffca6d 100%);
  1087. }
  1088. .guide-card__upload-icon {
  1089. width: 18px;
  1090. height: 16px;
  1091. object-fit: contain;
  1092. }
  1093. }
  1094. .bottom-btn-container {
  1095. display: flex;
  1096. justify-content: space-between;
  1097. gap: 12px;
  1098. width: 100%;
  1099. .bottom-btn {
  1100. padding: 0 25px;
  1101. border-radius: 8px;
  1102. font-size: 16px;
  1103. height: 40px;
  1104. line-height: 40px;
  1105. box-sizing: border-box;
  1106. font-weight: 500;
  1107. text-align: center;
  1108. &.primary-btn {
  1109. flex: 1;
  1110. background: linear-gradient(90deg, #ffebc9 0%, #ffca6d 100%);
  1111. color: #1a1408;
  1112. }
  1113. }
  1114. }
  1115. </style>