allGarden.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <template>
  2. <div class="all-garden-page">
  3. <custom-header :name="t('agriFile.moreFarms')" />
  4. <div class="page-body">
  5. <div class="map-wrap">
  6. <div class="map-container" ref="mapContainer"></div>
  7. <div class="add-farm-btn" @click="handleAddFarm">
  8. <el-icon size="12"><Plus /></el-icon>
  9. <span>{{ t("garden.addFarm") }}</span>
  10. </div>
  11. </div>
  12. <div class="farm-filter">
  13. <el-input
  14. v-model="searchFarm"
  15. class="filter-search"
  16. :placeholder="t('weather.searchFarm')"
  17. :prefix-icon="Search"
  18. clearable
  19. />
  20. <div class="filter-select-wrap">
  21. <el-select
  22. v-model="regionVal"
  23. class="filter-select"
  24. :placeholder="t('weather.selectRegion')"
  25. clearable
  26. >
  27. <el-option
  28. v-for="item in regionOptions"
  29. :key="item.value"
  30. :label="item.label"
  31. :value="item.value"
  32. />
  33. </el-select>
  34. <el-select
  35. v-model="typeVal"
  36. class="filter-select"
  37. :placeholder="t('weather.selectCategory')"
  38. clearable
  39. >
  40. <el-option
  41. v-for="item in typeOptions"
  42. :key="item.value"
  43. :label="item.label"
  44. :value="item.value"
  45. />
  46. </el-select>
  47. </div>
  48. </div>
  49. <div class="farm-list">
  50. <div
  51. v-for="item in filteredFarmList"
  52. :key="item.id"
  53. class="farm-card"
  54. @click.stop="handleEnterFarm(item)"
  55. :class="{ 'is-current': item.isCurrent }"
  56. >
  57. <div class="farm-card__header">
  58. <div class="farm-card__main">
  59. <div class="farm-card__title-row">
  60. <span class="farm-name van-ellipsis">{{ item.name }}</span>
  61. <span v-if="item.categoryLabel" class="category-tag">{{ item.categoryLabel }}</span>
  62. </div>
  63. <div class="farm-address van-ellipsis">
  64. <el-icon><Location /></el-icon>
  65. {{ item.rawAddress || t("common.noAddress") }}
  66. </div>
  67. </div>
  68. <div
  69. v-if="item.isCurrent"
  70. class="action-btn action-btn-current"
  71. >
  72. {{ t("garden.currentFarm") }}
  73. </div>
  74. <div
  75. v-else
  76. class="action-btn action-btn-enter"
  77. @click.stop="handleEnterFarm(item)"
  78. >
  79. {{ t("garden.enterFarm") }}
  80. <el-icon color="rgba(255, 255, 255, 0.6)"><ArrowRightBold /></el-icon>
  81. </div>
  82. </div>
  83. <div class="phenology-box">
  84. {{ t("garden.currentPhenology") }}
  85. <span class="phenology-text">{{ item.phenologyText || t("garden.phenologyPlaceholder") }}</span>
  86. <div class="phenology-desc">
  87. 待完善待完善待完善预计 11 月上旬第二次秋梢叶色转绿、叶片逐步老熟
  88. </div>
  89. </div>
  90. <div class="task-bar" v-if="item.taskName">
  91. <div class="task-bar__left">
  92. <img class="task-icon" src="@/assets/img/home/task.png" alt="" />
  93. <span class="task-name van-ellipsis">{{ item.taskName || t("garden.taskNamePlaceholder") }}</span>
  94. <span class="task-status">{{ item.taskStatus || t("garden.pendingExecute") }}</span>
  95. </div>
  96. <div class="task-bar__forward" @click.stop="handleForward(item)">
  97. <Icon size="14" color="#FFD489" name="share" />
  98. <span>{{ t("garden.forward") }}</span>
  99. </div>
  100. </div>
  101. </div>
  102. <div v-if="!filteredFarmList.length" class="empty-tip">
  103. {{ t("garden.noFarm") }}
  104. </div>
  105. </div>
  106. </div>
  107. <div class="invite-bar">
  108. <div class="invite-btn secondary-btn" @click="handleInviteFarmer">
  109. <img class="invite-btn-icon" src="@/assets/img/home/user-icon.png" alt="">
  110. <span>{{ t("garden.inviteFarmer") }}</span>
  111. </div>
  112. <div class="invite-btn" @click="handleInviteService">
  113. <img class="invite-btn-icon" src="@/assets/img/home/user-icon.png" alt="">
  114. <span>{{ t("garden.inviteService") }}</span>
  115. </div>
  116. </div>
  117. </div>
  118. </template>
  119. <script setup>
  120. import { computed, nextTick, onActivated, onMounted, ref, watch } from "vue";
  121. import { useRouter } from "vue-router";
  122. import { useStore } from "vuex";
  123. import { ElMessage } from "element-plus";
  124. import { Plus, Search, Share, User, UserFilled } from "@element-plus/icons-vue";
  125. import { useI18n } from "@/i18n";
  126. import customHeader from "@/components/customHeader.vue";
  127. import IndexMap from "@/views/old_mini/work_execute/index.js";
  128. import { Icon } from 'vant';
  129. const { t } = useI18n();
  130. const router = useRouter();
  131. const store = useStore();
  132. const mapContainer = ref(null);
  133. const indexMap = new IndexMap();
  134. const farmList = ref([]);
  135. const searchFarm = ref("");
  136. const regionVal = ref("");
  137. const typeVal = ref("");
  138. const regionOptions = ref([]);
  139. const typeOptions = ref([]);
  140. let searchTimer = null;
  141. /** 列表由接口按 farm_name / region / crop 筛选 */
  142. const filteredFarmList = computed(() => farmList.value);
  143. function toSelectOptions(list) {
  144. return (Array.isArray(list) ? list : [])
  145. .filter(Boolean)
  146. .map((value) => ({ label: value, value }));
  147. }
  148. function getFilterOptions() {
  149. const id = getMiniUserId();
  150. if (!id) {
  151. regionOptions.value = [];
  152. typeOptions.value = [];
  153. return;
  154. }
  155. VE_API.questionnaire
  156. .getAreaAndCropType({ id })
  157. .then((res) => {
  158. const data = res?.data || {};
  159. regionOptions.value = toSelectOptions(data.regions);
  160. typeOptions.value = toSelectOptions(data.crops);
  161. })
  162. .catch(() => {
  163. regionOptions.value = [];
  164. typeOptions.value = [];
  165. });
  166. }
  167. function resolveFarmPointWkt(farm) {
  168. if (farm.geom_wkt && /^POINT\s*\(/i.test(String(farm.geom_wkt).trim())) {
  169. return farm.geom_wkt;
  170. }
  171. if (farm.farm_location && /^POINT\s*\(/i.test(String(farm.farm_location).trim())) {
  172. return farm.farm_location;
  173. }
  174. return farm.geom_wkt || "";
  175. }
  176. function getSelectedFarmId() {
  177. const stored = localStorage.getItem("selectedFarmId");
  178. if (stored != null && stored !== "") {
  179. return Number(stored);
  180. }
  181. try {
  182. const farm = JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
  183. const id = farm.farm_id ?? farm.id;
  184. return id != null && id !== "" ? Number(id) : null;
  185. } catch {
  186. return null;
  187. }
  188. }
  189. function normalizeFarmList(data) {
  190. const selectedId = getSelectedFarmId();
  191. return (data || []).map((farm) => {
  192. const id = farm.farm_id;
  193. return {
  194. ...farm,
  195. id,
  196. name: farm.farm_name || "",
  197. wkt: resolveFarmPointWkt(farm),
  198. farmName: farm.farm_name || "",
  199. rawAddress: farm.farm_address || "",
  200. categoryLabel: farm.variety_name || "",
  201. phenologyText: farm.period_name || "",
  202. taskName: farm.fw_name || "",
  203. taskStatus: farm.work_status_name || farm.work_status || "",
  204. isCurrent: selectedId != null && Number(id) === selectedId,
  205. };
  206. });
  207. }
  208. function saveSelectedFarm(farm) {
  209. localStorage.setItem("selectedFarmId", farm.id);
  210. localStorage.setItem("selectedFarmName", farm.name || "");
  211. localStorage.setItem("selectedFarmPoint", farm.wkt || "");
  212. localStorage.setItem("selectedFarmData", JSON.stringify(farm));
  213. }
  214. function getDefaultMapPoint() {
  215. const withPoint = farmList.value.find((farm) => farm.wkt);
  216. return withPoint?.wkt || store.state.home.miniUserLocationPoint || "POINT(113.38 23.18)";
  217. }
  218. function refreshMapMarkers() {
  219. if (!indexMap.kmap) return;
  220. const points = filteredFarmList.value.filter((farm) => farm.wkt);
  221. indexMap.initData(points, "farm_name", "wkt", true);
  222. }
  223. function ensureMap() {
  224. if (!mapContainer.value) return;
  225. if (!indexMap.kmap) {
  226. // 农场列表跨省(如广东+湖北)时,默认 minZoom=6 在矮地图里 fit 后点全在视野外
  227. indexMap.initMap(getDefaultMapPoint(), mapContainer.value, true, { minZoom: 3 });
  228. }
  229. refreshMapMarkers();
  230. nextTick(() => {
  231. indexMap.kmap?.map?.updateSize?.();
  232. });
  233. }
  234. function getMiniUserId() {
  235. return store.state.home.miniUserId || localStorage.getItem("MINI_USER_ID");
  236. }
  237. function getFarmList() {
  238. const id = getMiniUserId();
  239. if (!id) {
  240. farmList.value = [];
  241. return;
  242. }
  243. const params = { id };
  244. const farmName = searchFarm.value.trim();
  245. if (farmName) params.farm_name = farmName;
  246. if (regionVal.value) params.region = regionVal.value;
  247. if (typeVal.value) params.crop = typeVal.value;
  248. VE_API.questionnaire
  249. .getFarms(params)
  250. .then((res) => {
  251. const list = Array.isArray(res?.data) ? res.data : [];
  252. farmList.value = normalizeFarmList(list);
  253. nextTick(() => {
  254. ensureMap();
  255. });
  256. })
  257. .catch(() => {
  258. farmList.value = [];
  259. });
  260. }
  261. function handleEnterFarm(item) {
  262. saveSelectedFarm(item);
  263. ElMessage({
  264. message: t("garden.enterFarmSuccess"),
  265. type: "success",
  266. customClass: "restore-planting-message",
  267. zIndex: 40000,
  268. });
  269. router.back();
  270. }
  271. function handleAddFarm() {
  272. router.push("/entry_information");
  273. }
  274. function handleForward() {
  275. ElMessage.info(t("garden.forwardTip"));
  276. }
  277. function handleInviteFarmer() {
  278. ElMessage.info(t("garden.inviteTip"));
  279. }
  280. function handleInviteService() {
  281. ElMessage.info(t("garden.inviteTip"));
  282. }
  283. watch(filteredFarmList, () => {
  284. if (indexMap.kmap) {
  285. refreshMapMarkers();
  286. }
  287. });
  288. watch([regionVal, typeVal], () => {
  289. getFarmList();
  290. });
  291. watch(searchFarm, () => {
  292. if (searchTimer) clearTimeout(searchTimer);
  293. searchTimer = setTimeout(() => {
  294. getFarmList();
  295. }, 300);
  296. });
  297. onMounted(() => {
  298. getFilterOptions();
  299. getFarmList();
  300. nextTick(() => {
  301. ensureMap();
  302. });
  303. });
  304. onActivated(() => {
  305. getFilterOptions();
  306. getFarmList();
  307. nextTick(() => {
  308. if (!indexMap.kmap) {
  309. ensureMap();
  310. return;
  311. }
  312. if (mapContainer.value && indexMap.kmap.map) {
  313. const checkAndUpdateSize = () => {
  314. const container = mapContainer.value;
  315. if (!container) return;
  316. const rect = container.getBoundingClientRect();
  317. if (rect.width > 0 && rect.height > 0) {
  318. indexMap.kmap.map.updateSize();
  319. refreshMapMarkers();
  320. } else {
  321. setTimeout(checkAndUpdateSize, 100);
  322. }
  323. };
  324. setTimeout(checkAndUpdateSize, 200);
  325. }
  326. });
  327. });
  328. </script>
  329. <style lang="scss" scoped>
  330. .all-garden-page {
  331. display: flex;
  332. flex-direction: column;
  333. height: 100vh;
  334. background: #141414;
  335. box-sizing: border-box;
  336. }
  337. .page-body {
  338. background: url('@/assets/img/agricultural/page-bg.png') no-repeat top center;
  339. background-size: 100% 250px;
  340. flex: 1;
  341. overflow: auto;
  342. padding: 10px 12px 22px;
  343. box-sizing: border-box;
  344. }
  345. .map-wrap {
  346. position: relative;
  347. border-radius: 10px;
  348. overflow: hidden;
  349. background: #1a191d;
  350. border: 1px solid rgba(255, 255, 255, 0.06);
  351. .map-container {
  352. width: 100%;
  353. height: 162px;
  354. clip-path: inset(0 round 10px);
  355. }
  356. .add-farm-btn {
  357. position: absolute;
  358. left: 8px;
  359. top: 5px;
  360. z-index: 2;
  361. display: inline-flex;
  362. align-items: center;
  363. gap: 2px;
  364. height: 30px;
  365. padding: 0 14px 0 10px;
  366. border-radius: 24px;
  367. background: rgba(7, 4, 0, 0.56);
  368. border: 1px solid rgba(255, 212, 137, 0.5);
  369. color: #FFD489;
  370. font-size: 12px;
  371. box-sizing: border-box;
  372. backdrop-filter: blur(4px);
  373. }
  374. }
  375. .farm-filter {
  376. display: flex;
  377. align-items: center;
  378. justify-content: space-between;
  379. gap: 8px;
  380. margin-top: 12px;
  381. .filter-select-wrap {
  382. display: flex;
  383. align-items: center;
  384. gap: 8px;
  385. }
  386. .filter-search {
  387. min-width: 0;
  388. }
  389. .filter-select {
  390. width: 94px;
  391. flex-shrink: 0;
  392. }
  393. :deep(.el-input__wrapper),
  394. :deep(.el-select__wrapper) {
  395. min-height: 36px;
  396. line-height: 36px;
  397. height: 36px;
  398. padding: 0 10px;
  399. box-sizing: border-box;
  400. border-radius: 6px;
  401. background: rgba(255, 255, 255, 0.05);
  402. box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset !important;
  403. &:hover {
  404. box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2) inset !important;
  405. }
  406. &.is-focused {
  407. box-shadow: 0 0 0 1px rgba(255, 212, 137, 0.45) inset !important;
  408. }
  409. }
  410. :deep(.el-input__inner),
  411. :deep(.el-select__selected-item),
  412. :deep(.el-select__input) {
  413. color: rgba(255, 255, 255, 0.9);
  414. font-size: 12px;
  415. }
  416. :deep(.el-input__inner::placeholder),
  417. :deep(.el-select__placeholder) {
  418. color: rgba(255, 255, 255, 0.5);
  419. }
  420. :deep(.el-select__caret),
  421. :deep(.el-input__prefix),
  422. :deep(.el-input__suffix) {
  423. color: rgba(255, 255, 255, 0.45);
  424. }
  425. :deep(.el-input__clear),
  426. :deep(.el-select__clear) {
  427. color: rgba(255, 255, 255, 0.45);
  428. background: transparent;
  429. }
  430. }
  431. .farm-list {
  432. margin-top: 12px;
  433. }
  434. .farm-card {
  435. margin-bottom: 10px;
  436. padding: 12px;
  437. border-radius: 12px;
  438. background: linear-gradient(180deg, #1a191d 0%, #121216 100%);
  439. border: 1px solid rgba(255, 255, 255, 0.08);
  440. box-sizing: border-box;
  441. &.is-current {
  442. border-color: rgba(255, 212, 137, 0.3);
  443. .phenology-box .phenology-text {
  444. color: #ffd489;
  445. }
  446. .farm-name {
  447. color: #ffd489;
  448. }
  449. }
  450. }
  451. .farm-card__header {
  452. display: flex;
  453. align-items: flex-start;
  454. justify-content: space-between;
  455. gap: 8px;
  456. }
  457. .farm-card__main {
  458. flex: 1;
  459. min-width: 0;
  460. }
  461. .farm-card__title-row {
  462. display: flex;
  463. align-items: center;
  464. gap: 8px;
  465. min-width: 0;
  466. }
  467. .farm-name {
  468. max-width: 180px;
  469. font-size: 16px;
  470. color: #fff;
  471. }
  472. .category-tag {
  473. flex-shrink: 0;
  474. height: 18px;
  475. padding: 0 8px;
  476. border-radius: 4px;
  477. border: 1px solid rgba(255, 255, 255, 0.12);
  478. background: rgba(255, 255, 255, 0.05);
  479. color: rgba(255, 255, 255, 0.6);
  480. font-size: 12px;
  481. line-height: 18px;
  482. box-sizing: border-box;
  483. }
  484. .farm-address {
  485. display: flex;
  486. align-items: center;
  487. gap: 5px;
  488. margin-top: 4px;
  489. font-size: 12px;
  490. color: rgba(255, 255, 255, 0.4);
  491. }
  492. .action-btn {
  493. flex-shrink: 0;
  494. height: 26px;
  495. padding: 0 8px 0 11px;
  496. border-radius: 22px;
  497. font-size: 12px;
  498. color: rgba(255, 255, 255, 0.85);
  499. border: 1px solid rgba(255, 255, 255, 0.16);
  500. box-sizing: border-box;
  501. display: flex;
  502. align-items: center;
  503. justify-content: center;
  504. gap: 2px;
  505. }
  506. .action-btn-current {
  507. padding: 0 6px;
  508. border-radius: 4px;
  509. border-color: rgba(255, 212, 137, 0.16);
  510. color: #FFD489;
  511. background: rgba(255, 212, 137, 0.1);
  512. }
  513. .phenology-box {
  514. margin-top: 8px;
  515. padding: 9px 10px;
  516. border-radius: 8px;
  517. background: rgba(255, 255, 255, 0.05);
  518. font-size: 12px;
  519. color: rgba(255, 255, 255, 0.7);
  520. line-height: 18px;
  521. .phenology-desc {
  522. color: rgba(255, 255, 255, 0.7);
  523. }
  524. .phenology-text {
  525. padding-left: 2px;
  526. color: #FFFFFF;
  527. font-size: 14px;
  528. }
  529. }
  530. .task-bar {
  531. display: flex;
  532. align-items: center;
  533. justify-content: space-between;
  534. gap: 8px;
  535. margin-top: 8px;
  536. padding: 8px 10px;
  537. border-radius: 10px;
  538. background: rgba(255, 255, 255, 0.05);
  539. }
  540. .task-bar__left {
  541. display: flex;
  542. align-items: center;
  543. gap: 8px;
  544. min-width: 0;
  545. flex: 1;
  546. }
  547. .task-icon {
  548. width: 16px;
  549. height: 16px;
  550. flex-shrink: 0;
  551. }
  552. .task-name {
  553. max-width: 120px;
  554. font-weight: 500;
  555. font-size: 14px;
  556. color: rgba(255, 255, 255, 0.9);
  557. }
  558. .task-status {
  559. flex-shrink: 0;
  560. height: 18px;
  561. padding: 0 6px;
  562. border-radius: 4px;
  563. background: rgba(255, 212, 137, 0.1);
  564. color: #FFD489;
  565. border: 1px solid rgba(255, 255, 255, 0.12);
  566. font-size: 12px;
  567. line-height: 18px;
  568. }
  569. .task-bar__forward {
  570. display: inline-flex;
  571. align-items: center;
  572. gap: 4px;
  573. flex-shrink: 0;
  574. color: #FFD489;
  575. font-size: 14px;
  576. }
  577. .empty-tip {
  578. padding: 40px 0;
  579. text-align: center;
  580. color: rgba(255, 255, 255, 0.4);
  581. font-size: 13px;
  582. }
  583. .invite-bar {
  584. display: flex;
  585. justify-content: center;
  586. gap: 12px;
  587. padding: 20px 10px calc(30px + env(safe-area-inset-bottom));
  588. width: 100%;
  589. box-sizing: border-box;
  590. }
  591. .invite-btn {
  592. display: inline-flex;
  593. align-items: center;
  594. justify-content: center;
  595. box-sizing: border-box;
  596. gap: 6px;
  597. flex: 1;
  598. height: 44px;
  599. border-radius: 28px;
  600. background: linear-gradient(90deg, #FFEBC9 0%, #FFCA6D 100%);
  601. color: #1A1408;
  602. font-size: 16px;
  603. &.secondary-btn {
  604. background: #141416;
  605. border: 1px solid rgba(255, 212, 137, 0.4);
  606. color: #FFD489;
  607. }
  608. .invite-btn-icon {
  609. width: 16px;
  610. height: 16px;
  611. filter: brightness(0) saturate(100%);
  612. opacity: 0.85;
  613. }
  614. }
  615. </style>