growthTrack.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <template>
  2. <div class="growth-track-page">
  3. <custom-header
  4. :name="pageTitle"
  5. :isGoBack="!isFromShare"
  6. :isClose="isFromShare"
  7. :showClose="false"
  8. @goback="handleBack"
  9. />
  10. <div class="growth-track-body">
  11. <div class="growth-hero">
  12. <div class="growth-hero__top">
  13. <div class="growth-hero__main">
  14. <div class="growth-hero__title-row">
  15. <span class="growth-hero__title">{{ theme }}</span>
  16. <span class="growth-hero__tag growth-hero__tag--level">
  17. <el-icon>
  18. <BellFilled />
  19. </el-icon>
  20. {{ level }}
  21. </span>
  22. <span class="growth-hero__tag growth-hero__tag--zone">{{ zoneName }}</span>
  23. </div>
  24. <div class="growth-hero__reason">{{ reason }}</div>
  25. </div>
  26. <div class="growth-hero__share" @click="handleShare">
  27. <Icon name="share" />
  28. <span>{{ t("agriFile.forward") }}</span>
  29. </div>
  30. </div>
  31. </div>
  32. <div class="growth-content">
  33. <div class="growth-content__title">{{ t("agriFile.agriAssessment") }}</div>
  34. <div class="growth-content__desc">{{ assessmentDesc }}</div>
  35. </div>
  36. <div class="interact-card">
  37. <div class="interact-card__head">
  38. <div class="interact-card__tab">
  39. <img class="interact-card__star" src="@/assets/img/agricultural/start.png" alt="" />
  40. <span>{{ t("agriFile.interactQuestion") }}</span>
  41. </div>
  42. </div>
  43. <div class="interact-card__qa">
  44. <div class="interact-card__question">{{ interactProblem }}</div>
  45. <div class="interact-card__options">
  46. <div
  47. v-for="item in interactOptions"
  48. :key="item.id"
  49. class="interact-option"
  50. :class="{ selected: selectedOptionId === item.id }"
  51. @click="selectedOptionId = item.id"
  52. >
  53. <span class="interact-option__text">{{ item.name }}</span>
  54. </div>
  55. </div>
  56. <div class="interact-card__submit" @click="handleSubmit">{{ t("agriFile.submit") }}</div>
  57. </div>
  58. </div>
  59. <div class="guide-card">
  60. <div class="guide-title">{{ t("agriFile.patrolGuide") }}</div>
  61. <photo-provider :photo-closable="true">
  62. <photo-consumer :src="guideImage">
  63. <img class="guide-card__img" :src="guideImage" alt="" />
  64. </photo-consumer>
  65. </photo-provider>
  66. </div>
  67. </div>
  68. <div class="guide-card__upload" @click="handleUploadClick">
  69. <el-icon>
  70. <Plus />
  71. </el-icon>
  72. <span>{{ t("agriFile.uploadPhoto") }}</span>
  73. </div>
  74. <album-upload-popup v-model:show="showUploadPopup" @confirm="handleUploadConfirm" />
  75. <tip-popup
  76. v-model:show="showSuccessPopup"
  77. type="executeSuccess"
  78. text="您已上传成功"
  79. text2="请等待诊断报告生成"
  80. hideBtn
  81. >
  82. <template #footer>
  83. <div class="bottom-btn-container">
  84. <div class="bottom-btn primary-btn" @click="handleComplete">完成</div>
  85. </div>
  86. </template>
  87. </tip-popup>
  88. <leave-confirm-popup v-model:show="showLeavePopup" @confirm="confirmLeave" />
  89. </div>
  90. </template>
  91. <script setup>
  92. import { computed, nextTick, onActivated, ref } from "vue";
  93. import { useRoute, useRouter } from "vue-router";
  94. import { Icon } from "vant";
  95. import { ElMessage } from "element-plus";
  96. import customHeader from "@/components/customHeader.vue";
  97. import albumUploadPopup from "../components/albumUploadPopup.vue";
  98. import leaveConfirmPopup from "@/components/popup/leaveConfirmPopup.vue";
  99. import tipPopup from "@/components/popup/tipPopup.vue";
  100. import { useI18n } from "@/i18n";
  101. import { base_img_url2 } from "@/api/config";
  102. import wx from "weixin-js-sdk";
  103. const { t } = useI18n();
  104. const route = useRoute();
  105. const router = useRouter();
  106. // ---------- 常量 ----------
  107. const DEFAULT_GUIDE_IMAGE = require("@/assets/img/agricultural/patrol-guide.png");
  108. // ---------- 页面状态 ----------
  109. const interactTasks = ref([]);
  110. const currentTaskIndex = ref(0);
  111. const selectedOptionId = ref(null);
  112. const showUploadPopup = ref(false);
  113. const showSuccessPopup = ref(false);
  114. const showLeavePopup = ref(false);
  115. const needDraw = ref(true); // status≠1 时需先勾画种植范围
  116. // ---------- 计算属性 ----------
  117. const pageTitle = computed(() => route.query.pageName || t("agriFile.patrolGrowthTitle"));
  118. const id = computed(() => route.query.id);
  119. /** 通过分享进入:无返回箭头 */
  120. const isFromShare = computed(() => {
  121. if (isTruthyFlag(route.query.fromShare)) return true;
  122. const paramsPage = parseMaybeJson(route.query.paramsPage);
  123. if (isTruthyFlag(paramsPage?.fromShare)) return true;
  124. const miniJson = parseMaybeJson(route.query.miniJson);
  125. if (isTruthyFlag(miniJson?.fromShare)) return true;
  126. if (isTruthyFlag(parseMaybeJson(miniJson?.paramsPage)?.fromShare)) return true;
  127. return false;
  128. });
  129. const currentTask = computed(() => interactTasks.value[currentTaskIndex.value] || null);
  130. const currentContent = computed(() => currentTask.value?.interact_content || {});
  131. const theme = computed(
  132. () => currentContent.value.interact_title || t("agriFile.interactTheme")
  133. );
  134. const reason = computed(
  135. () => currentContent.value.interact_theme || t("agriFile.interactReason")
  136. );
  137. const level = computed(() => t("agriFile.riskLevel2"));
  138. const zoneName = computed(() => t("agriFile.zoneOne"));
  139. const assessmentDesc = computed(
  140. () => currentContent.value.interact_explain || t("agriFile.agriAssessmentDesc")
  141. );
  142. const interactProblem = computed(
  143. () => currentContent.value.interact_problem || t("agriFile.interactQuestionText")
  144. );
  145. const guideImage = computed(
  146. () => resolveImageUrl(currentContent.value.guide_url) || DEFAULT_GUIDE_IMAGE
  147. );
  148. const interactOptions = computed(() => {
  149. const options = currentContent.value.interact_options;
  150. if (!Array.isArray(options)) return [];
  151. return options.map((name, index) => ({
  152. id: index + 1,
  153. name: String(name),
  154. }));
  155. });
  156. // ---------- 工具函数 ----------
  157. function isTruthyFlag(value) {
  158. return value === 1 || value === "1" || value === true || value === "true";
  159. }
  160. function parseMaybeJson(value) {
  161. if (value == null || value === "") return null;
  162. if (typeof value === "object") return value;
  163. try {
  164. return JSON.parse(value);
  165. } catch {
  166. return null;
  167. }
  168. }
  169. function resolveImageUrl(path) {
  170. if (!path) return "";
  171. const text = String(path).trim();
  172. if (!text) return "";
  173. if (/^https?:\/\//i.test(text)) return text;
  174. return base_img_url2 + text.replace(/^\//, "");
  175. }
  176. function getSelectedFarm() {
  177. try {
  178. return JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
  179. } catch {
  180. return {};
  181. }
  182. }
  183. const hasAnswered = () => selectedOptionId.value != null;
  184. // ---------- 业务逻辑 ----------
  185. const applyTaskIndex = (index) => {
  186. currentTaskIndex.value = index;
  187. selectedOptionId.value = null;
  188. };
  189. const fetchInternalInteractTasks = async () => {
  190. try {
  191. const res = await VE_API.questionnaire.getInternalInteractTasks({ zone_id: id.value });
  192. const tasks = res?.data?.interact_tasks;
  193. interactTasks.value = Array.isArray(tasks) ? tasks : [];
  194. applyTaskIndex(0);
  195. } catch (e) {
  196. console.warn("[growthTrack] getInternalInteractTasks failed", e);
  197. interactTasks.value = [];
  198. }
  199. };
  200. /** status=1 有范围无需勾画;status=0 无范围需要勾画 */
  201. const fetchZoneRangeStatus = async () => {
  202. const farm = getSelectedFarm();
  203. const farmId = farm.farm_id ?? farm.id;
  204. const zoneId = id.value || farm.zone_id || farm.zoneId;
  205. if (farmId == null || farmId === "" || zoneId == null || zoneId === "") {
  206. needDraw.value = true;
  207. return;
  208. }
  209. try {
  210. const res = await VE_API.questionnaire.checkZoneRange({
  211. farm_id: farmId,
  212. zone_id: zoneId,
  213. });
  214. needDraw.value = Number(res?.data?.status) !== 1;
  215. } catch (e) {
  216. console.warn("[growthTrack] checkZoneRange failed", e);
  217. needDraw.value = true;
  218. }
  219. };
  220. // ---------- 事件处理 / 生命周期 ----------
  221. const handleShare = () => {
  222. const query = {
  223. askInfo: { title: "转发巡园要点", content: "是否分享给好友" },
  224. shareText: reason.value || "速长窗口不追肥?后期发育慢人一步,直接掉队!",
  225. targetUrl: "growth_track",
  226. paramsPage: JSON.stringify({
  227. id: id.value,
  228. fromShare: 1,
  229. ...(route.query.pageName ? { pageName: route.query.pageName } : {}),
  230. }),
  231. imageUrl: "https://birdseye-img.sysuimars.com/temp/field.png",
  232. };
  233. wx.miniProgram.navigateTo({
  234. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=sharePage`,
  235. });
  236. };
  237. const handleSubmit = () => {
  238. if (selectedOptionId.value == null) {
  239. ElMessage.warning(t("agriFile.pleaseSelectOption"));
  240. return;
  241. }
  242. // 选第二项:切换到下一条内部感知任务
  243. const isSecondOption = selectedOptionId.value === 2;
  244. if (isSecondOption && currentTaskIndex.value < interactTasks.value.length - 1) {
  245. applyTaskIndex(currentTaskIndex.value + 1);
  246. return;
  247. }
  248. ElMessage.success(t("agriFile.submitSuccess"));
  249. };
  250. /** 需勾画则先画范围;否则直接上传 */
  251. const handleUploadClick = () => {
  252. if (needDraw.value) {
  253. router.push({
  254. path: "/add_zone",
  255. query: {
  256. type: "farm",
  257. targetUrl: "/growth_track",
  258. ...(route.query.id ? { trackId: route.query.id } : {}),
  259. },
  260. });
  261. return;
  262. }
  263. showUploadPopup.value = true;
  264. };
  265. const handleUploadConfirm = async ({ images, date } = {}) => {
  266. const cloud_url = Array.isArray(images) ? images : [];
  267. if (!cloud_url.length) {
  268. ElMessage.warning("请先上传照片");
  269. return;
  270. }
  271. const farm = getSelectedFarm();
  272. try {
  273. const res = await VE_API.questionnaire.uploadImages({
  274. cloud_url,
  275. farm_id: farm.farm_id ?? farm.id ?? "",
  276. zone_id: id.value || "",
  277. category_code: farm.category_code || "",
  278. zone_name: farm.variety_name || "",
  279. create_time: date,
  280. });
  281. if (res?.code === 200) {
  282. showSuccessPopup.value = true;
  283. return;
  284. }
  285. ElMessage.error(res?.msg || "上传失败,请稍后再试");
  286. } catch {
  287. ElMessage.error("上传失败,请稍后再试");
  288. }
  289. };
  290. const handleComplete = () => {
  291. showSuccessPopup.value = false;
  292. router.replace("/agri_file");
  293. };
  294. const handleBack = () => {
  295. if (!hasAnswered()) {
  296. showLeavePopup.value = true;
  297. return;
  298. }
  299. router.back();
  300. };
  301. const confirmLeave = () => {
  302. router.back();
  303. };
  304. onActivated(() => {
  305. fetchZoneRangeStatus();
  306. fetchInternalInteractTasks();
  307. if (route.query.showUpload !== "1") return;
  308. nextTick(() => {
  309. showUploadPopup.value = true;
  310. const { showUpload, ...restQuery } = route.query;
  311. router.replace({ path: route.path, query: restQuery });
  312. });
  313. });
  314. </script>
  315. <style lang="scss" scoped>
  316. .growth-track-page {
  317. display: flex;
  318. flex-direction: column;
  319. width: 100%;
  320. height: 100vh;
  321. overflow: hidden;
  322. background: #f5f5f5;
  323. .growth-track-body {
  324. flex: 1;
  325. overflow-y: auto;
  326. -webkit-overflow-scrolling: touch;
  327. .growth-hero {
  328. padding: 18px 10px 38px;
  329. background: #2199f8;
  330. color: #fff;
  331. &__top {
  332. display: flex;
  333. align-items: center;
  334. justify-content: space-between;
  335. }
  336. &__title-row {
  337. display: flex;
  338. align-items: center;
  339. gap: 10px;
  340. }
  341. &__title {
  342. font-size: 28px;
  343. font-family: "PangMenZhengDao";
  344. margin-top: -5px;
  345. }
  346. &__reason {
  347. margin-top: 10px;
  348. padding: 4px 10px;
  349. border-radius: 4px;
  350. background: linear-gradient(90deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 100%);
  351. }
  352. &__tag {
  353. display: inline-flex;
  354. align-items: center;
  355. gap: 4px;
  356. padding: 1px 4px;
  357. border-radius: 2px;
  358. background: #fff;
  359. font-size: 12px;
  360. }
  361. &__tag--level {
  362. color: #ff6a6a;
  363. }
  364. &__tag--zone {
  365. color: #2199f8;
  366. }
  367. &__share {
  368. flex: none;
  369. display: flex;
  370. align-items: center;
  371. gap: 4px;
  372. padding: 4px 14px;
  373. border-radius: 25px;
  374. background: rgba(19, 125, 209, 0.5);
  375. color: #fff;
  376. }
  377. }
  378. }
  379. .growth-content {
  380. position: relative;
  381. z-index: 1;
  382. margin: -24px 10px 12px;
  383. padding: 10px;
  384. border-radius: 8px;
  385. background: #fff;
  386. &__title {
  387. color: #4f4f4f;
  388. font-size: 16px;
  389. font-family: "PangMenZhengDao";
  390. }
  391. &__desc {
  392. margin-top: 4px;
  393. color: #9c9c9c;
  394. font-size: 14px;
  395. }
  396. }
  397. .interact-card {
  398. margin: 0 10px 10px;
  399. overflow: hidden;
  400. border: 1px solid rgba(33, 153, 248, 0.5);
  401. border-radius: 12px;
  402. background: #fff;
  403. &__head {
  404. position: relative;
  405. background: linear-gradient(180deg, #e5f4ff 0%, #ffffff 72%);
  406. }
  407. &__tab {
  408. display: inline-flex;
  409. align-items: center;
  410. gap: 5px;
  411. height: 32px;
  412. padding: 0 32px 10px 8px;
  413. color: #fff;
  414. font-size: 16px;
  415. font-family: "PangMenZhengDao";
  416. background: url("@/assets/img/agricultural/title-bg.png") no-repeat center / 100% 100%;
  417. span {
  418. margin-top: -3px;
  419. }
  420. }
  421. &__star {
  422. width: 16px;
  423. height: 14px;
  424. }
  425. &__qa {
  426. margin: 10px;
  427. padding: 10px;
  428. border-radius: 8px;
  429. background: rgba(33, 153, 248, 0.1);
  430. }
  431. &__question {
  432. font-size: 14px;
  433. font-weight: 500;
  434. }
  435. &__options {
  436. display: flex;
  437. gap: 8px;
  438. margin-top: 10px;
  439. }
  440. &__submit {
  441. width: 120px;
  442. margin: 12px auto 0;
  443. padding: 8px 0;
  444. border-radius: 25px;
  445. background: #2199f8;
  446. color: #fff;
  447. font-size: 14px;
  448. text-align: center;
  449. }
  450. .interact-option {
  451. position: relative;
  452. flex: 1;
  453. min-width: 0;
  454. height: 36px;
  455. line-height: 36px;
  456. border-radius: 6px;
  457. background: #fff;
  458. border: 1px solid transparent;
  459. text-align: center;
  460. box-sizing: border-box;
  461. cursor: pointer;
  462. &__text {
  463. display: block;
  464. padding: 0 6px;
  465. overflow: hidden;
  466. text-overflow: ellipsis;
  467. white-space: nowrap;
  468. font-size: 14px;
  469. color: #666;
  470. }
  471. &.selected {
  472. border-color: #2199f8;
  473. .interact-option__text {
  474. color: #2199f8;
  475. }
  476. &::after {
  477. content: "";
  478. position: absolute;
  479. top: -1px;
  480. right: -1px;
  481. width: 18px;
  482. height: 14px;
  483. background: url("@/assets/img/home/checked-bg-top.png") no-repeat bottom right / 18px 13px;
  484. }
  485. }
  486. }
  487. }
  488. .guide-card__upload {
  489. position: fixed;
  490. right: 7px;
  491. bottom: 94px;
  492. z-index: 10;
  493. display: flex;
  494. flex-direction: column;
  495. align-items: center;
  496. justify-content: center;
  497. width: 58px;
  498. height: 58px;
  499. border-radius: 50%;
  500. background: #2199f8;
  501. color: #fff;
  502. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.1);
  503. font-size: 15px;
  504. }
  505. .guide-card__upload span {
  506. margin-top: 3px;
  507. font-size: 10px;
  508. }
  509. .guide-title {
  510. position: relative;
  511. z-index: 1;
  512. display: inline-block;
  513. font-size: 16px;
  514. font-weight: 500;
  515. &::after {
  516. content: "";
  517. position: absolute;
  518. left: 0;
  519. bottom: 2px;
  520. z-index: -1;
  521. width: 90px;
  522. height: 6px;
  523. border-radius: 25px;
  524. background: linear-gradient(90deg, #2199f8 0%, rgba(255, 255, 255, 0.37) 100%);
  525. opacity: 0.4;
  526. }
  527. }
  528. .guide-card {
  529. position: relative;
  530. margin: 10px;
  531. padding: 10px;
  532. border-radius: 8px;
  533. background: #fff;
  534. &__img {
  535. display: block;
  536. width: 100%;
  537. margin-top: 8px;
  538. }
  539. }
  540. }
  541. .bottom-btn-container {
  542. display: flex;
  543. justify-content: space-between;
  544. gap: 12px;
  545. width: 100%;
  546. .bottom-btn {
  547. padding: 0 25px;
  548. border-radius: 4px;
  549. font-size: 16px;
  550. height: 40px;
  551. line-height: 40px;
  552. box-sizing: border-box;
  553. font-weight: 500;
  554. text-align: center;
  555. &.primary-btn {
  556. flex: 1;
  557. background: #2199f8;
  558. color: #fff;
  559. }
  560. }
  561. }
  562. </style>