index.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. <template>
  2. <div class="growth-report-page" :style="{ height: `calc(100vh - ${tabBarHeight}px)` }">
  3. <div class="report-content">
  4. <div class="map-container" ref="mapContainer"></div>
  5. <!-- Overlay 宿主:无范围时挂到地图方框下方 -->
  6. <div ref="noRangeTipRef" class="no-range-tip" :style="{ display: noFarmRange ? 'inline-flex' : 'none' }"
  7. @click.stop="goAddZone('farm')">
  8. <span>勾画区域,获地块级长势报告</span>
  9. <el-icon class="no-range-tip__arrow">
  10. <ArrowRight />
  11. </el-icon>
  12. </div>
  13. </div>
  14. <!-- 左上角:位置切换 -->
  15. <div class="location-bar">
  16. <el-icon class="location-bar__icon">
  17. <LocationFilled />
  18. </el-icon>
  19. <span class="location-bar__name van-ellipsis">{{ locationName }}</span>
  20. <span v-if="hasSelectedFarm()" class="location-bar__action" @click="handleSwitchFarm">切换农场</span>
  21. </div>
  22. <div class="growth-top">
  23. <!-- 浮窗:长势互动(按 物候 → 异常 → 土壤根系 依次展示) -->
  24. <div v-if="currentCard" class="interact-float">
  25. <div class="interact-card" :class="`interact-card--${currentCard.kind}`">
  26. <el-icon class="interact-card__close" @click="dismissCurrentCard">
  27. <Close />
  28. </el-icon>
  29. <div class="interact-card__qa">
  30. <div class="interact-card__question">
  31. <div class="interact-card__question-icon">
  32. <img class="interact-card__question-icon-img" :src="currentCard.icon" alt="">
  33. </div>
  34. <span>{{ currentCard.title }}</span>
  35. </div>
  36. <!-- 物候 / 土壤根系:选项卡片 -->
  37. <div v-if="currentCard.kind === 'options'" class="interact-card__options">
  38. <div
  39. v-for="item in currentCard.options"
  40. :key="item.id"
  41. class="interact-option"
  42. :class="{
  43. selected: selectedOptionId === item.id,
  44. disabled: interactSubmitting,
  45. }"
  46. @click="handleInteractOptionClick(item)"
  47. >
  48. <span class="interact-option__text">{{ item.name }}</span>
  49. </div>
  50. </div>
  51. <!-- 异常:结论描述 + 立即巡园 -->
  52. <div v-else class="interact-card__abnormal">
  53. <div class="interact-card__desc">{{ currentCard.desc }}</div>
  54. <div class="interact-card__cta" @click="handlePatrolNow">
  55. 立即巡园
  56. <el-icon><ArrowRightBold /></el-icon>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="growth-top__content">
  63. <div class="invite-group">
  64. <div class="invite-btn" @click="handleLocateToCenter">
  65. <img class="current-icon" src="@/assets/img/home/current.png" alt="">
  66. </div>
  67. <div class="invite-btn" @click="handleInvite('service')">
  68. <img class="invite-icon" src="@/assets/img/home/user-icon.png" alt="">
  69. 邀请农服
  70. </div>
  71. <div class="invite-btn" @click="handleInvite('farmer')">
  72. <img class="invite-icon" src="@/assets/img/home/user-icon.png" alt="">
  73. 邀请农户
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. <crop-alert-panel :crop-name="currentCropName" :farm-id="selectedFarmId" :county-code="countyCode"
  79. @zone-change="handleZoneChange" @height-change="handlePanelHeightChange" />
  80. </div>
  81. <!-- 恢复种植弹窗 -->
  82. <restore-planting-popup />
  83. </template>
  84. <script setup>
  85. import { computed, nextTick, onActivated, onMounted, ref } from "vue";
  86. import { useRouter } from "vue-router";
  87. import { useStore } from "vuex";
  88. import { ElMessage } from "element-plus";
  89. import { ArrowRight, Close, LocationFilled } from "@element-plus/icons-vue";
  90. import { convertPointToArray } from "@/utils/index";
  91. import { fetchRegeo, toLocationParam } from "@/utils/tiandituLocation";
  92. import GrowthReportMap from "./growthReportMap.js";
  93. import CropAlertPanel from "./components/CropAlertPanel.vue";
  94. import wx from "weixin-js-sdk";
  95. import restorePlantingPopup from "@/components/popup/restorePlantingPopup.vue";
  96. const router = useRouter();
  97. const DEFAULT_MAP_POINT = "POINT(113.6142086995688 23.585836479509055)";
  98. const LOCATION_SESSION_KEY = "GROWTH_REPORT_LOCATION";
  99. const MAP_POINT_STORAGE_KEY = "GROWTH_REPORT_MAP_POINT";
  100. /** 无农场时逆地理得到的区县码,供点位预警使用 */
  101. const COUNTY_CODE_STORAGE_KEY = "GROWTH_REPORT_COUNTY_CODE";
  102. const periodIcon = require("@/assets/img/agricultural/period.png");
  103. const lightningIcon = require("@/assets/img/agricultural/lightning.png");
  104. const soilIcon = require("@/assets/img/agricultural/soil.png");
  105. const store = useStore();
  106. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  107. const mapContainer = ref(null);
  108. const noRangeTipRef = ref(null);
  109. const growthReportMap = new GrowthReportMap();
  110. const locationName = ref("");
  111. /** status≠1 时展示中心勾画引导 */
  112. const noFarmRange = ref(false);
  113. const selectedFarmId = ref(localStorage.getItem("selectedFarmId") || "");
  114. /** 无农场时区县码(逆地理 adcode) */
  115. const countyCode = ref(localStorage.getItem(COUNTY_CODE_STORAGE_KEY) || "");
  116. /** CropAlertPanel 当前选中分区 */
  117. const panelZoneId = ref(null);
  118. /** 面板叠在地图上的高度,中心点按「面板以上」可视区计算 */
  119. const panelOverlayHeight = ref(280);
  120. const currentCropName = computed(() => {
  121. // 依赖 selectedFarmId,切换农场后重新读缓存
  122. void selectedFarmId.value;
  123. const farm = getSelectedFarm();
  124. return (
  125. farm.variety_name ||
  126. farm.crop_name ||
  127. farm.farm_variety ||
  128. ""
  129. );
  130. });
  131. const getSelectedFarm = () => {
  132. try {
  133. return JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
  134. } catch {
  135. return {};
  136. }
  137. };
  138. /** 登录写入的用户定位:lng,lat */
  139. const getMiniUserLocationText = () => localStorage.getItem("MINI_USER_LOCATION") || "";
  140. /** 登录写入的用户定位 POINT;无 POINT 时用 lng,lat 拼 */
  141. const getMiniUserLocationPoint = () => {
  142. const point =
  143. localStorage.getItem("MINI_USER_LOCATION_POINT") ||
  144. store.state.home.miniUserLocationPoint ||
  145. "";
  146. if (typeof point === "string" && /^POINT\s*\(/i.test(point.trim())) {
  147. return point.trim();
  148. }
  149. const text = getMiniUserLocationText();
  150. if (text.includes(",")) {
  151. const [lng, lat] = text.split(",").map((s) => s.trim());
  152. if (lng && lat) return `POINT(${lng} ${lat})`;
  153. }
  154. return DEFAULT_MAP_POINT;
  155. };
  156. const hasSelectedFarm = () => {
  157. const farm = getSelectedFarm();
  158. const id =
  159. selectedFarmId.value ||
  160. localStorage.getItem("selectedFarmId") ||
  161. farm.farm_id ||
  162. farm.id;
  163. return id != null && id !== "";
  164. };
  165. /** 地图中心优先用农场 farm_location */
  166. const resolveFarmLocationWkt = (farm = getSelectedFarm()) => {
  167. const candidates = [farm.farm_location, farm.wkt, farm.geom_wkt, localStorage.getItem("selectedFarmPoint")];
  168. for (const item of candidates) {
  169. if (typeof item === "string" && /^POINT\s*\(/i.test(item.trim())) {
  170. return item.trim();
  171. }
  172. }
  173. return getMiniUserLocationPoint();
  174. };
  175. /** 有农场用农场点,无农场用登录用户点位 */
  176. const resolveMapCenterPoint = (farm = getSelectedFarm()) => {
  177. if (hasSelectedFarm()) return resolveFarmLocationWkt(farm);
  178. return getMiniUserLocationPoint();
  179. };
  180. const currentMapPoint = ref(resolveMapCenterPoint());
  181. const syncSelectedFarmId = () => {
  182. const next = String(
  183. localStorage.getItem("selectedFarmId") || getSelectedFarm().farm_id || getSelectedFarm().id || ""
  184. );
  185. // 切农场后旧 panelZoneId 属于上一农场,必须先清掉再等 CropAlertPanel 回传
  186. if (next !== selectedFarmId.value) {
  187. panelZoneId.value = null;
  188. }
  189. selectedFarmId.value = next;
  190. };
  191. /** status=1 有范围;否则展示勾画引导(无农场不展示) */
  192. async function fetchFarmRangeStatus() {
  193. const farm = getSelectedFarm();
  194. const farmId = selectedFarmId.value || farm.farm_id || farm.id;
  195. // 只信面板当前分区,禁止回退 selectedFarmData.zone_id(易与 farm_id 错配)
  196. const zoneId = panelZoneId.value;
  197. // 无农场不展示勾画引导
  198. if (farmId == null || farmId === "") {
  199. noFarmRange.value = false;
  200. await syncNoRangeGuide();
  201. return;
  202. }
  203. if (zoneId == null || zoneId === "") {
  204. noFarmRange.value = true;
  205. await syncNoRangeGuide();
  206. return;
  207. }
  208. try {
  209. const res = await VE_API.questionnaire.checkZoneRange({
  210. farm_id: farmId,
  211. zone_id: zoneId,
  212. });
  213. noFarmRange.value = Number(res?.data?.status) !== 1;
  214. } catch (e) {
  215. console.warn("[growth_report] checkZoneRange failed", e);
  216. noFarmRange.value = true;
  217. }
  218. await syncNoRangeGuide();
  219. }
  220. /** 无范围时在地图中心点画示意方框 + 下方提示 */
  221. async function syncNoRangeGuide() {
  222. await nextTick();
  223. if (!growthReportMap.kmap) return;
  224. if (!noFarmRange.value) {
  225. growthReportMap.clearNoRangeGuide();
  226. return;
  227. }
  228. const coordinate =
  229. growthReportMap.getCurrentCoordinate() ||
  230. convertPointToArray(currentMapPoint.value)?.map(Number);
  231. if (!coordinate?.length) return;
  232. growthReportMap.showNoRangeGuide(coordinate, noRangeTipRef.value);
  233. }
  234. const goAddZone = (type) => {
  235. router.push({
  236. path: "/add_zone",
  237. query: {
  238. type,
  239. isSuccessPopup: "1",
  240. },
  241. });
  242. };
  243. // ---------- 顶部巡园互动浮窗 ----------
  244. /** 卡片队列:物候(pheno) → 异常(abnormal) → 土壤根系(soil_root),缺失分块不入队 */
  245. const interactCards = ref([]);
  246. const currentCardIndex = ref(0);
  247. const interactDismissed = ref(false);
  248. const currentCard = computed(() =>
  249. interactDismissed.value ? null : interactCards.value[currentCardIndex.value] || null
  250. );
  251. const selectedOptionId = ref(null);
  252. const interactSubmitting = ref(false);
  253. /** 防止切换分区时旧请求回写 */
  254. let interactFetchToken = 0;
  255. function formatToday() {
  256. const d = new Date();
  257. const y = d.getFullYear();
  258. const m = String(d.getMonth() + 1).padStart(2, "0");
  259. const day = String(d.getDate()).padStart(2, "0");
  260. return `${y}-${m}-${day}`;
  261. }
  262. function getRequestErrorMessage(err) {
  263. const data = err?.response?.data;
  264. if (typeof data === "string" && data) return data;
  265. if (data?.msg) return data.msg;
  266. if (data?.message) return data.message;
  267. if (err?.message) return err.message;
  268. return "提交失败,请稍后再试";
  269. }
  270. /** interact_options / options 可能是 JSON 字符串、字符串数组或 {label,value} 数组 */
  271. function parseInteractOptions(raw) {
  272. let list = raw;
  273. if (typeof raw === "string") {
  274. try {
  275. list = JSON.parse(raw);
  276. } catch {
  277. return [];
  278. }
  279. }
  280. if (!Array.isArray(list)) return [];
  281. return list
  282. .map((item, index) => ({
  283. id: index + 1,
  284. name:
  285. item && typeof item === "object"
  286. ? String(item.label ?? item.value ?? "")
  287. : String(item),
  288. }))
  289. .filter((item) => item.name);
  290. }
  291. function resolveSectionOptions(section = {}) {
  292. return parseInteractOptions(section.interact_options ?? section.options);
  293. }
  294. /** getTypesTask 分块 → 按顺序的浮窗卡片(无对应分块则不显示) */
  295. function buildInteractCards(data = {}, ctx = {}) {
  296. const cards = [];
  297. const pushOptionsCard = (key, section, icon) => {
  298. if (!section) return;
  299. const title =
  300. section.interact_problem ||
  301. section.question ||
  302. section.interact_title ||
  303. section.interaction_title ||
  304. section.title ||
  305. "";
  306. const options = resolveSectionOptions(section);
  307. if (!title && !options.length) return;
  308. cards.push({ key, kind: "options", icon, title, options, raw: section, ...ctx });
  309. };
  310. // 1. 物候:问题 + 选项;status 有值(已提交)则不再展示(0/空 视为无值)
  311. const phenoStatus = data.pheno?.status;
  312. const phenoAnswered =
  313. phenoStatus != null && phenoStatus !== "" && Number(phenoStatus) !== 0;
  314. if (!phenoAnswered) {
  315. pushOptionsCard("pheno", data.pheno, periodIcon);
  316. }
  317. // 2. 异常:结论标题 + 描述 + 立即巡园
  318. if (data.abnormal) {
  319. const section = data.abnormal;
  320. const title = section.title || section.interaction_title || "";
  321. const desc =
  322. section.highlight ||
  323. section.interaction_theme ||
  324. section.interaction_reason ||
  325. section.inspection_guide ||
  326. "";
  327. if (title || desc) {
  328. cards.push({
  329. key: "abnormal",
  330. kind: "abnormal",
  331. icon: lightningIcon,
  332. title,
  333. desc,
  334. raw: section,
  335. ...ctx,
  336. });
  337. }
  338. }
  339. // 3. 土壤根系:问题 + 选项;is_answered=1 已答则不展示
  340. if (Number(data.soil_root?.is_answered) !== 1) {
  341. pushOptionsCard("soil_root", data.soil_root, soilIcon);
  342. }
  343. return cards;
  344. }
  345. function clearInteractCard() {
  346. interactCards.value = [];
  347. currentCardIndex.value = 0;
  348. interactDismissed.value = false;
  349. selectedOptionId.value = null;
  350. }
  351. function applyInteractCards(data = {}, ctx = {}) {
  352. interactCards.value = buildInteractCards(data, ctx);
  353. currentCardIndex.value = 0;
  354. interactDismissed.value = false;
  355. selectedOptionId.value = null;
  356. }
  357. /** 关闭当前卡 → 展示下一张;最后一张则整体收起 */
  358. function dismissCurrentCard() {
  359. selectedOptionId.value = null;
  360. if (currentCardIndex.value < interactCards.value.length - 1) {
  361. currentCardIndex.value += 1;
  362. } else {
  363. interactDismissed.value = true;
  364. }
  365. }
  366. /** 选项卡(物候/土壤)提交成功后才切下一张 */
  367. async function submitInteractOption(item) {
  368. const card = currentCard.value;
  369. if (!card || card.kind !== "options" || interactSubmitting.value) return;
  370. selectedOptionId.value = item.id;
  371. interactSubmitting.value = true;
  372. try {
  373. let res;
  374. if (card.key === "pheno") {
  375. // 物候感知结果沿用原有保存接口
  376. res = await VE_API.questionnaire.saveInteractResult({
  377. zone_id: Number(card.zoneId),
  378. date: formatToday(),
  379. period_code: card.raw?.period_code || "",
  380. });
  381. } else {
  382. // 土壤根系:与异常互动同接口,按 fw_code 提交选项
  383. res = await VE_API.questionnaire.confirmAbnormalInteract({
  384. farm_id: card.farmId,
  385. zone_id: card.zoneId,
  386. calc_date: card.calcDate,
  387. crop_type: card.cropType,
  388. fw_code: card.raw?.fw_code || "",
  389. options: item.name,
  390. });
  391. }
  392. if (res?.code === 200) {
  393. ElMessage.success(res?.msg || "提交成功");
  394. dismissCurrentCard();
  395. return;
  396. }
  397. ElMessage.error(res?.msg || "提交失败,请稍后再试");
  398. } catch (err) {
  399. ElMessage.error(getRequestErrorMessage(err));
  400. } finally {
  401. interactSubmitting.value = false;
  402. }
  403. }
  404. async function handleInteractOptionClick(item) {
  405. if (interactSubmitting.value || !item?.name || !currentCard.value) return;
  406. await submitInteractOption(item);
  407. }
  408. /** 异常卡「立即巡园」只跳转,不切到下一张(避免直接跳到土壤) */
  409. const handlePatrolNow = () => {
  410. const card = currentCard.value;
  411. if (!card) return;
  412. router.push({
  413. path: "/abnormal_track",
  414. query: {
  415. id: card.zoneId,
  416. ...(card.zoneId !== "" ? { zoneId: card.zoneId } : {}),
  417. },
  418. });
  419. };
  420. /** 首页巡园要点:getTypesTask 一次返回 pheno / abnormal / soil_root */
  421. async function fetchInteractTask() {
  422. const farm = getSelectedFarm();
  423. // 与 checkZoneRange 一致:只用面板选中分区,避免缓存旧 zone
  424. const zoneId = panelZoneId.value;
  425. const farmId = selectedFarmId.value || farm.farm_id || farm.id;
  426. const cropType = resolveCropCode(farm);
  427. if (
  428. zoneId == null ||
  429. zoneId === "" ||
  430. farmId == null ||
  431. farmId === "" ||
  432. !cropType
  433. ) {
  434. clearInteractCard();
  435. return;
  436. }
  437. const token = ++interactFetchToken;
  438. try {
  439. const res = await VE_API.pheno.getTypesTask({
  440. crop_type: cropType,
  441. farm_id: farmId,
  442. zone_id: zoneId,
  443. calc_date: formatToday(),
  444. });
  445. if (token !== interactFetchToken) return;
  446. if (res?.code !== 200) {
  447. clearInteractCard();
  448. return;
  449. }
  450. applyInteractCards(res?.data || {}, {
  451. zoneId,
  452. farmId,
  453. cropType,
  454. calcDate: formatToday(),
  455. });
  456. } catch (e) {
  457. if (token !== interactFetchToken) return;
  458. console.warn("[growth_report] getTypesTask failed", e);
  459. clearInteractCard();
  460. }
  461. }
  462. /** 农场品类编码:接口 crop_code / crop_type 对应缓存 category_code */
  463. function resolveCropCode(farm = getSelectedFarm()) {
  464. return farm.category_code || farm.categorycode || farm.crop_code || farm.crop_type || "";
  465. }
  466. const handleZoneChange = (zoneId) => {
  467. panelZoneId.value = zoneId != null && zoneId !== "" ? zoneId : null;
  468. fetchFarmRangeStatus();
  469. fetchInteractTask();
  470. };
  471. /** 面板高度变化:地图中心改到「面板以上」区域的几何中心 */
  472. const handlePanelHeightChange = (panelHeight) => {
  473. const next = Math.max(0, Number(panelHeight) || 0);
  474. panelOverlayHeight.value = next;
  475. growthReportMap.setBottomOverlayHeight(next);
  476. if (!growthReportMap.kmap) return;
  477. growthReportMap.syncVisibleCenter(
  478. convertPointToArray(currentMapPoint.value)?.map(Number)
  479. );
  480. };
  481. async function getLocationName(point = currentMapPoint.value) {
  482. // 已选农场且带 county_address:直接使用,不再请求逆地理
  483. const farm = getSelectedFarm();
  484. const farmCountyAddress = String(farm?.county_address ?? "").trim();
  485. if (hasSelectedFarm() && farmCountyAddress) {
  486. locationName.value = farmCountyAddress;
  487. return;
  488. }
  489. let locationParam = "";
  490. // 无农场:逆地理用登录点 MINI_USER_LOCATION(lng,lat)
  491. if (!hasSelectedFarm()) {
  492. locationParam = toLocationParam(getMiniUserLocationText());
  493. }
  494. if (!locationParam) {
  495. const locationPoint =
  496. point ||
  497. localStorage.getItem("selectedFarmPoint") ||
  498. getMiniUserLocationPoint();
  499. if (!locationPoint) return;
  500. const farmLocation = convertPointToArray(locationPoint);
  501. if (Array.isArray(farmLocation) && farmLocation.length >= 2) {
  502. locationParam = `${farmLocation[0]},${farmLocation[1]}`;
  503. } else if (typeof farmLocation === "string" && farmLocation.includes(",")) {
  504. locationParam = toLocationParam(farmLocation);
  505. } else {
  506. return;
  507. }
  508. }
  509. try {
  510. const { result } = await fetchRegeo({ location: locationParam });
  511. locationName.value = result?.address_component
  512. ? result.address_component.city + result.address_component.district
  513. : (result?.address || "") + "";
  514. // 无农场时用 adcode 同步给点位预警面板
  515. if (!hasSelectedFarm()) {
  516. const adcode = result?.ad_info?.adcode;
  517. if (adcode != null && adcode !== "") {
  518. const code = String(adcode);
  519. countyCode.value = code;
  520. localStorage.setItem(COUNTY_CODE_STORAGE_KEY, code);
  521. } else {
  522. countyCode.value = "";
  523. localStorage.removeItem(COUNTY_CODE_STORAGE_KEY);
  524. }
  525. }
  526. } catch (e) {
  527. console.warn("[growth_report] getLocationName failed", e);
  528. }
  529. }
  530. function saveCurrentMapPoint(point) {
  531. if (!point) return;
  532. currentMapPoint.value = point;
  533. localStorage.setItem(MAP_POINT_STORAGE_KEY, point);
  534. }
  535. const initMap = async () => {
  536. await nextTick();
  537. if (!mapContainer.value) return;
  538. growthReportMap.setBottomOverlayHeight(panelOverlayHeight.value);
  539. if (growthReportMap.kmap) {
  540. growthReportMap.kmap.map?.updateSize?.();
  541. const coordinate = convertPointToArray(currentMapPoint.value)?.map(Number);
  542. if (coordinate?.length === 2) {
  543. growthReportMap.setMapPosition(coordinate);
  544. }
  545. await syncNoRangeGuide();
  546. return;
  547. }
  548. const location = currentMapPoint.value || store.state.home.miniUserLocationPoint || DEFAULT_MAP_POINT;
  549. currentMapPoint.value = location;
  550. growthReportMap.initMap(location, mapContainer.value);
  551. await syncNoRangeGuide();
  552. };
  553. function applySelectedLocation() {
  554. const raw = sessionStorage.getItem(LOCATION_SESSION_KEY);
  555. if (!raw) return false;
  556. sessionStorage.removeItem(LOCATION_SESSION_KEY);
  557. let saved = null;
  558. try {
  559. saved = JSON.parse(raw);
  560. } catch {
  561. return false;
  562. }
  563. if (!saved?.point && !saved?.coordinate) return false;
  564. const point = saved.point || `POINT(${saved.coordinate[0]} ${saved.coordinate[1]})`;
  565. const coordinate = (saved.coordinate || convertPointToArray(point)).map(Number);
  566. saveCurrentMapPoint(point);
  567. if (growthReportMap.kmap && coordinate?.length === 2) {
  568. growthReportMap.setMapPosition(coordinate);
  569. }
  570. getLocationName(point);
  571. return true;
  572. }
  573. /** 有农场落到 farm_location;无农场落到登录用户点位 */
  574. function syncMapFromSelectedFarm() {
  575. const point = resolveMapCenterPoint();
  576. if (!point) return false;
  577. saveCurrentMapPoint(point);
  578. const coordinate = convertPointToArray(point)?.map(Number);
  579. if (growthReportMap.kmap && coordinate?.length === 2) {
  580. growthReportMap.setMapPosition(coordinate);
  581. }
  582. getLocationName(point);
  583. return true;
  584. }
  585. /** 定位按钮:地图回到农场 / 用户点位中心 */
  586. const handleLocateToCenter = () => {
  587. if (!growthReportMap.kmap) return;
  588. const point = resolveMapCenterPoint() || currentMapPoint.value;
  589. if (!point) return;
  590. saveCurrentMapPoint(point);
  591. const coordinate = convertPointToArray(point)?.map(Number);
  592. if (coordinate?.length === 2) {
  593. growthReportMap.setMapPosition(coordinate);
  594. }
  595. };
  596. const handleSwitchFarm = () => {
  597. router.push("/all_garden");
  598. };
  599. const handleSwitchLocation = () => {
  600. // 以已确认的 currentMapPoint 为准,避免地图临时中心覆盖已选位置
  601. const mapCenter =
  602. currentMapPoint.value ||
  603. store.state.home.miniUserLocationPoint ||
  604. DEFAULT_MAP_POINT;
  605. router.push({
  606. path: "/entry_select_location",
  607. query: {
  608. mapCenter,
  609. iconType: "current",
  610. from: "growth_report",
  611. },
  612. });
  613. };
  614. const handleInvite = (type) => {
  615. const isService = type === "service";
  616. let inviteName = "好友";
  617. try {
  618. const userInfo = JSON.parse(localStorage.getItem("localUserInfo") || "{}");
  619. inviteName = userInfo.nickName || userInfo.userName || userInfo.name || inviteName;
  620. } catch {
  621. // ignore
  622. }
  623. const inviteType = isService ? "service" : "farmer";
  624. const adminId = localStorage.getItem("MINI_USER_ID") || "";
  625. const query = {
  626. askInfo: { title: "邀请完善信息", content: "是否分享该邀请给好友" },
  627. shareText: isService ? "邀请您完善农服信息" : "邀请您完善地块种植信息",
  628. targetUrl: `invite_welcome`,
  629. paramsPage: JSON.stringify({ inviteName, inviteType, adminId }),
  630. imageUrl: 'https://birdseye-img.sysuimars.com/farm-h5/field.png',
  631. };
  632. wx.miniProgram.navigateTo({
  633. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=sharePage`,
  634. });
  635. }
  636. onMounted(() => {
  637. // syncSelectedFarmId();
  638. // syncMapFromSelectedFarm();
  639. getLocationName();
  640. // initMap();
  641. // fetchFarmRangeStatus();
  642. // fetchInteractTask();
  643. });
  644. onActivated(() => {
  645. syncSelectedFarmId();
  646. const applied = applySelectedLocation();
  647. if (!applied) syncMapFromSelectedFarm();
  648. initMap();
  649. // 范围校验 / 互动卡片等 CropAlertPanel 通过 zoneChange 回传后再拉,避免旧 zone 竞态
  650. });
  651. </script>
  652. <style lang="scss" scoped>
  653. .growth-report-page {
  654. width: 100%;
  655. height: 100%;
  656. background: #0A0A0A;
  657. box-sizing: border-box;
  658. .interact-float {
  659. margin-bottom: 6px;
  660. pointer-events: none;
  661. padding: 1px;
  662. background: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, rgba(153, 153, 153, 0.25) 100%);
  663. border-radius: 14px;
  664. backdrop-filter: blur(4px);
  665. .interact-card {
  666. position: relative;
  667. pointer-events: auto;
  668. overflow: hidden;
  669. border-radius: 14px;
  670. padding: 10px;
  671. background: linear-gradient(180deg, rgba(26, 25, 29, 0.6) 0%, rgba(18, 18, 22, 0.6) 100%);
  672. }
  673. .interact-card__head {
  674. position: relative;
  675. }
  676. .interact-card__tab {
  677. display: inline-flex;
  678. align-items: center;
  679. gap: 5px;
  680. height: 32px;
  681. padding: 0 32px 10px 8px;
  682. color: #fff;
  683. font-size: 16px;
  684. span {
  685. margin-top: -3px;
  686. }
  687. }
  688. .interact-card__star {
  689. width: 16px;
  690. height: 14px;
  691. }
  692. .interact-card__close {
  693. position: absolute;
  694. top: 12px;
  695. right: 10px;
  696. font-size: 16px;
  697. color: rgba(255, 255, 255, 0.5);
  698. cursor: pointer;
  699. }
  700. .interact-card__question {
  701. font-size: 16px;
  702. color: #fff;
  703. display: flex;
  704. align-items: center;
  705. gap: 12px;
  706. padding-right: 20px;
  707. > span {
  708. flex: 1;
  709. min-width: 0;
  710. }
  711. .interact-card__question-icon {
  712. flex-shrink: 0;
  713. display: flex;
  714. align-items: center;
  715. justify-content: center;
  716. width: 31px;
  717. height: 31px;
  718. background: rgba(255, 255, 255, 0.05);
  719. border: 1px solid rgba(255, 255, 255, 0.12);
  720. border-radius: 8px;
  721. .interact-card__question-icon-img {
  722. width: 15px;
  723. }
  724. }
  725. }
  726. .interact-card__options {
  727. display: flex;
  728. gap: 8px;
  729. margin-top: 10px;
  730. }
  731. /* 异常卡:结论描述 + 立即巡园 */
  732. .interact-card__abnormal {
  733. display: flex;
  734. align-items: center;
  735. gap: 12px;
  736. margin-top: 10px;
  737. }
  738. .interact-card__desc {
  739. flex: 1;
  740. min-width: 0;
  741. font-size: 14px;
  742. line-height: 21px;
  743. color: rgba(255, 255, 255, 0.6);
  744. overflow: hidden;
  745. word-break: break-all;
  746. }
  747. .interact-card__cta {
  748. flex-shrink: 0;
  749. display: inline-flex;
  750. align-items: center;
  751. justify-content: center;
  752. gap: 2px;
  753. height: 32px;
  754. padding: 0 10px 0 15px;
  755. border-radius: 24px;
  756. background: linear-gradient(90deg, #FFEBC9 0%, #FFCA6D 100%);
  757. color: #000000;
  758. font-size: 12px;
  759. white-space: nowrap;
  760. box-sizing: border-box;
  761. cursor: pointer;
  762. }
  763. .interact-option {
  764. position: relative;
  765. flex: 1;
  766. min-width: 0;
  767. height: 41px;
  768. line-height: 41px;
  769. border-radius: 6px;
  770. background: rgba(255, 255, 255, 0.05);
  771. border: 1px solid rgba(255, 255, 255, 0.12);
  772. text-align: center;
  773. box-sizing: border-box;
  774. cursor: pointer;
  775. &__text {
  776. display: block;
  777. padding: 0 6px;
  778. overflow: hidden;
  779. text-overflow: ellipsis;
  780. white-space: nowrap;
  781. font-size: 14px;
  782. color: rgba(255, 255, 255, 0.7);
  783. }
  784. &.selected {
  785. border-color: rgba(255, 255, 255, 0.5);
  786. background: rgba(255, 255, 255, 0.1);
  787. .interact-option__text {
  788. color: #fff;
  789. }
  790. // &::after {
  791. // content: "";
  792. // position: absolute;
  793. // top: -1px;
  794. // right: -1px;
  795. // width: 18px;
  796. // height: 14px;
  797. // background: url("@/assets/img/home/checked-bg-top.png") no-repeat bottom right / 18px 13px;
  798. // }
  799. }
  800. &.disabled {
  801. opacity: 0.65;
  802. pointer-events: none;
  803. }
  804. }
  805. }
  806. .location-bar {
  807. position: fixed;
  808. top: 12px;
  809. left: 12px;
  810. z-index: 16;
  811. display: inline-flex;
  812. align-items: center;
  813. gap: 4px;
  814. max-width: calc(100% - 24px);
  815. height: 32px;
  816. padding: 0 12px;
  817. border-radius: 16px;
  818. background: rgba(0, 0, 0, 0.4);
  819. backdrop-filter: blur(4px);
  820. color: #fff;
  821. font-size: 14px;
  822. box-sizing: border-box;
  823. &__icon {
  824. font-size: 16px;
  825. flex-shrink: 0;
  826. }
  827. &__name {
  828. max-width: calc(100vw - 80px);
  829. }
  830. &__action {
  831. flex-shrink: 0;
  832. color: #FFD489;
  833. }
  834. }
  835. .growth-top {
  836. width: 100%;
  837. position: fixed;
  838. top: 52px;
  839. z-index: 15;
  840. pointer-events: none;
  841. padding: 0 12px;
  842. box-sizing: border-box;
  843. .growth-top__content {
  844. display: flex;
  845. align-items: flex-start;
  846. justify-content: end;
  847. }
  848. }
  849. .invite-group {
  850. pointer-events: none;
  851. .invite-btn {
  852. pointer-events: auto;
  853. height: 48px;
  854. width: 48px;
  855. display: flex;
  856. align-items: center;
  857. justify-content: center;
  858. flex-direction: column;
  859. border-radius: 10px;
  860. border: 1px solid rgba(255, 255, 255, 0.2);
  861. background: rgba(20, 20, 22, 0.8);
  862. gap: 6px;
  863. color: rgba(255, 255, 255, 0.6);
  864. font-size: 10px;
  865. .invite-icon {
  866. width: 16px;
  867. }
  868. .current-icon {
  869. width: 20px;
  870. }
  871. }
  872. .invite-btn+.invite-btn {
  873. margin-top: 10px;
  874. }
  875. }
  876. .report-content {
  877. position: relative;
  878. height: 100%;
  879. box-sizing: border-box;
  880. .map-container {
  881. width: 100%;
  882. height: 100%;
  883. }
  884. }
  885. .no-range-tip {
  886. display: none;
  887. align-items: center;
  888. gap: 2px;
  889. max-width: calc(100vw - 48px);
  890. height: 36px;
  891. padding: 0 14px;
  892. border-radius: 18px;
  893. background: rgba(40, 48, 36, 0.72);
  894. backdrop-filter: blur(4px);
  895. color: #fff;
  896. font-size: 14px;
  897. white-space: nowrap;
  898. box-sizing: border-box;
  899. cursor: pointer;
  900. &__arrow {
  901. font-size: 14px;
  902. flex-shrink: 0;
  903. }
  904. }
  905. }
  906. </style>