| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- <template>
- <div class="all-garden-page">
- <custom-header :name="t('agriFile.moreFarms')" />
- <div class="page-body">
- <div class="map-wrap">
- <div class="map-container" ref="mapContainer"></div>
- <div class="add-farm-btn" @click="handleAddFarm">
- <el-icon size="12"><Plus /></el-icon>
- <span>{{ t("garden.addFarm") }}</span>
- </div>
- </div>
- <div class="farm-filter">
- <el-input
- v-model="searchFarm"
- class="filter-search"
- :placeholder="t('weather.searchFarm')"
- :prefix-icon="Search"
- clearable
- />
- <div class="filter-select-wrap">
- <el-select
- v-model="regionVal"
- class="filter-select"
- :placeholder="t('weather.selectRegion')"
- clearable
- >
- <el-option
- v-for="item in regionOptions"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- <el-select
- v-model="typeVal"
- class="filter-select"
- :placeholder="t('weather.selectCategory')"
- clearable
- >
- <el-option
- v-for="item in typeOptions"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- </div>
- </div>
- <div class="farm-list">
- <div
- v-for="item in filteredFarmList"
- :key="item.id"
- class="farm-card"
- @click.stop="handleEnterFarm(item)"
- :class="{ 'is-current': item.isCurrent }"
- >
- <div class="farm-card__header">
- <div class="farm-card__main">
- <div class="farm-card__title-row">
- <span class="farm-name van-ellipsis">{{ item.name }}</span>
- <span v-if="item.categoryLabel" class="category-tag">{{ item.categoryLabel }}</span>
- </div>
- <div class="farm-address van-ellipsis">
- <el-icon><Location /></el-icon>
- {{ item.rawAddress || t("common.noAddress") }}
- </div>
- </div>
- <div
- v-if="item.isCurrent"
- class="action-btn action-btn-current"
- >
- {{ t("garden.currentFarm") }}
- </div>
- <div
- v-else
- class="action-btn action-btn-enter"
- @click.stop="handleEnterFarm(item)"
- >
- {{ t("garden.enterFarm") }}
- <el-icon color="rgba(255, 255, 255, 0.6)"><ArrowRightBold /></el-icon>
- </div>
- </div>
- <div class="phenology-box">
- {{ t("garden.currentPhenology") }}
- <span class="phenology-text">{{ item.phenologyText || t("garden.phenologyPlaceholder") }}</span>
- <div class="phenology-desc">
- 待完善待完善待完善预计 11 月上旬第二次秋梢叶色转绿、叶片逐步老熟
- </div>
- </div>
- <div class="task-bar" v-if="item.taskName">
- <div class="task-bar__left">
- <img class="task-icon" src="@/assets/img/home/task.png" alt="" />
- <span class="task-name van-ellipsis">{{ item.taskName || t("garden.taskNamePlaceholder") }}</span>
- <span class="task-status">{{ item.taskStatus || t("garden.pendingExecute") }}</span>
- </div>
- <div class="task-bar__forward" @click.stop="handleForward(item)">
- <Icon size="14" color="#FFD489" name="share" />
- <span>{{ t("garden.forward") }}</span>
- </div>
- </div>
- </div>
- <div v-if="!filteredFarmList.length" class="empty-tip">
- {{ t("garden.noFarm") }}
- </div>
- </div>
- </div>
- <div class="invite-bar">
- <div class="invite-btn secondary-btn" @click="handleInviteFarmer">
- <img class="invite-btn-icon" src="@/assets/img/home/user-icon.png" alt="">
- <span>{{ t("garden.inviteFarmer") }}</span>
- </div>
- <div class="invite-btn" @click="handleInviteService">
- <img class="invite-btn-icon" src="@/assets/img/home/user-icon.png" alt="">
- <span>{{ t("garden.inviteService") }}</span>
- </div>
- </div>
- </div>
- </template>
- <script setup>
- import { computed, nextTick, onActivated, onMounted, ref, watch } from "vue";
- import { useRouter } from "vue-router";
- import { useStore } from "vuex";
- import { ElMessage } from "element-plus";
- import { Plus, Search, Share, User, UserFilled } from "@element-plus/icons-vue";
- import { useI18n } from "@/i18n";
- import customHeader from "@/components/customHeader.vue";
- import IndexMap from "@/views/old_mini/work_execute/index.js";
- import { Icon } from 'vant';
- const { t } = useI18n();
- const router = useRouter();
- const store = useStore();
- const mapContainer = ref(null);
- const indexMap = new IndexMap();
- const farmList = ref([]);
- const searchFarm = ref("");
- const regionVal = ref("");
- const typeVal = ref("");
- const regionOptions = ref([]);
- const typeOptions = ref([]);
- let searchTimer = null;
- /** 列表由接口按 farm_name / region / crop 筛选 */
- const filteredFarmList = computed(() => farmList.value);
- function toSelectOptions(list) {
- return (Array.isArray(list) ? list : [])
- .filter(Boolean)
- .map((value) => ({ label: value, value }));
- }
- function getFilterOptions() {
- const id = getMiniUserId();
- if (!id) {
- regionOptions.value = [];
- typeOptions.value = [];
- return;
- }
- VE_API.questionnaire
- .getAreaAndCropType({ id })
- .then((res) => {
- const data = res?.data || {};
- regionOptions.value = toSelectOptions(data.regions);
- typeOptions.value = toSelectOptions(data.crops);
- })
- .catch(() => {
- regionOptions.value = [];
- typeOptions.value = [];
- });
- }
- function resolveFarmPointWkt(farm) {
- if (farm.geom_wkt && /^POINT\s*\(/i.test(String(farm.geom_wkt).trim())) {
- return farm.geom_wkt;
- }
- if (farm.farm_location && /^POINT\s*\(/i.test(String(farm.farm_location).trim())) {
- return farm.farm_location;
- }
- return farm.geom_wkt || "";
- }
- function getSelectedFarmId() {
- const stored = localStorage.getItem("selectedFarmId");
- if (stored != null && stored !== "") {
- return Number(stored);
- }
- try {
- const farm = JSON.parse(localStorage.getItem("selectedFarmData") || "{}");
- const id = farm.farm_id ?? farm.id;
- return id != null && id !== "" ? Number(id) : null;
- } catch {
- return null;
- }
- }
- function normalizeFarmList(data) {
- const selectedId = getSelectedFarmId();
- return (data || []).map((farm) => {
- const id = farm.farm_id;
- return {
- ...farm,
- id,
- name: farm.farm_name || "",
- wkt: resolveFarmPointWkt(farm),
- farmName: farm.farm_name || "",
- rawAddress: farm.farm_address || "",
- categoryLabel: farm.variety_name || "",
- phenologyText: farm.period_name || "",
- taskName: farm.fw_name || "",
- taskStatus: farm.work_status_name || farm.work_status || "",
- isCurrent: selectedId != null && Number(id) === selectedId,
- };
- });
- }
- function saveSelectedFarm(farm) {
- localStorage.setItem("selectedFarmId", farm.id);
- localStorage.setItem("selectedFarmName", farm.name || "");
- localStorage.setItem("selectedFarmPoint", farm.wkt || "");
- localStorage.setItem("selectedFarmData", JSON.stringify(farm));
- }
- function getDefaultMapPoint() {
- const withPoint = farmList.value.find((farm) => farm.wkt);
- return withPoint?.wkt || store.state.home.miniUserLocationPoint || "POINT(113.38 23.18)";
- }
- function refreshMapMarkers() {
- if (!indexMap.kmap) return;
- const points = filteredFarmList.value.filter((farm) => farm.wkt);
- indexMap.initData(points, "farm_name", "wkt", true);
- }
- function ensureMap() {
- if (!mapContainer.value) return;
- if (!indexMap.kmap) {
- // 农场列表跨省(如广东+湖北)时,默认 minZoom=6 在矮地图里 fit 后点全在视野外
- indexMap.initMap(getDefaultMapPoint(), mapContainer.value, true, { minZoom: 3 });
- }
- refreshMapMarkers();
- nextTick(() => {
- indexMap.kmap?.map?.updateSize?.();
- });
- }
- function getMiniUserId() {
- return store.state.home.miniUserId || localStorage.getItem("MINI_USER_ID");
- }
- function getFarmList() {
- const id = getMiniUserId();
- if (!id) {
- farmList.value = [];
- return;
- }
- const params = { id };
- const farmName = searchFarm.value.trim();
- if (farmName) params.farm_name = farmName;
- if (regionVal.value) params.region = regionVal.value;
- if (typeVal.value) params.crop = typeVal.value;
- VE_API.questionnaire
- .getFarms(params)
- .then((res) => {
- const list = Array.isArray(res?.data) ? res.data : [];
- farmList.value = normalizeFarmList(list);
- nextTick(() => {
- ensureMap();
- });
- })
- .catch(() => {
- farmList.value = [];
- });
- }
- function handleEnterFarm(item) {
- saveSelectedFarm(item);
- ElMessage({
- message: t("garden.enterFarmSuccess"),
- type: "success",
- customClass: "restore-planting-message",
- zIndex: 40000,
- });
- router.back();
- }
- function handleAddFarm() {
- router.push("/entry_information");
- }
- function handleForward() {
- ElMessage.info(t("garden.forwardTip"));
- }
- function handleInviteFarmer() {
- ElMessage.info(t("garden.inviteTip"));
- }
- function handleInviteService() {
- ElMessage.info(t("garden.inviteTip"));
- }
- watch(filteredFarmList, () => {
- if (indexMap.kmap) {
- refreshMapMarkers();
- }
- });
- watch([regionVal, typeVal], () => {
- getFarmList();
- });
- watch(searchFarm, () => {
- if (searchTimer) clearTimeout(searchTimer);
- searchTimer = setTimeout(() => {
- getFarmList();
- }, 300);
- });
- onMounted(() => {
- getFilterOptions();
- getFarmList();
- nextTick(() => {
- ensureMap();
- });
- });
- onActivated(() => {
- getFilterOptions();
- getFarmList();
- nextTick(() => {
- if (!indexMap.kmap) {
- ensureMap();
- return;
- }
- if (mapContainer.value && indexMap.kmap.map) {
- const checkAndUpdateSize = () => {
- const container = mapContainer.value;
- if (!container) return;
- const rect = container.getBoundingClientRect();
- if (rect.width > 0 && rect.height > 0) {
- indexMap.kmap.map.updateSize();
- refreshMapMarkers();
- } else {
- setTimeout(checkAndUpdateSize, 100);
- }
- };
- setTimeout(checkAndUpdateSize, 200);
- }
- });
- });
- </script>
- <style lang="scss" scoped>
- .all-garden-page {
- display: flex;
- flex-direction: column;
- height: 100vh;
- background: #141414;
- box-sizing: border-box;
- }
- .page-body {
- background: url('@/assets/img/agricultural/page-bg.png') no-repeat top center;
- background-size: 100% 250px;
- flex: 1;
- overflow: auto;
- padding: 10px 12px 22px;
- box-sizing: border-box;
- }
- .map-wrap {
- position: relative;
- border-radius: 10px;
- overflow: hidden;
- background: #1a191d;
- border: 1px solid rgba(255, 255, 255, 0.06);
- .map-container {
- width: 100%;
- height: 162px;
- clip-path: inset(0 round 10px);
- }
- .add-farm-btn {
- position: absolute;
- left: 8px;
- top: 5px;
- z-index: 2;
- display: inline-flex;
- align-items: center;
- gap: 2px;
- height: 30px;
- padding: 0 14px 0 10px;
- border-radius: 24px;
- background: rgba(7, 4, 0, 0.56);
- border: 1px solid rgba(255, 212, 137, 0.5);
- color: #FFD489;
- font-size: 12px;
- box-sizing: border-box;
- backdrop-filter: blur(4px);
- }
- }
- .farm-filter {
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 8px;
- margin-top: 12px;
- .filter-select-wrap {
- display: flex;
- align-items: center;
- gap: 8px;
- }
- .filter-search {
- min-width: 0;
- }
- .filter-select {
- width: 94px;
- flex-shrink: 0;
- }
- :deep(.el-input__wrapper),
- :deep(.el-select__wrapper) {
- min-height: 36px;
- line-height: 36px;
- height: 36px;
- padding: 0 10px;
- box-sizing: border-box;
- border-radius: 6px;
- background: rgba(255, 255, 255, 0.05);
- box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset !important;
- &:hover {
- box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2) inset !important;
- }
- &.is-focused {
- box-shadow: 0 0 0 1px rgba(255, 212, 137, 0.45) inset !important;
- }
- }
- :deep(.el-input__inner),
- :deep(.el-select__selected-item),
- :deep(.el-select__input) {
- color: rgba(255, 255, 255, 0.9);
- font-size: 12px;
- }
- :deep(.el-input__inner::placeholder),
- :deep(.el-select__placeholder) {
- color: rgba(255, 255, 255, 0.5);
- }
- :deep(.el-select__caret),
- :deep(.el-input__prefix),
- :deep(.el-input__suffix) {
- color: rgba(255, 255, 255, 0.45);
- }
- :deep(.el-input__clear),
- :deep(.el-select__clear) {
- color: rgba(255, 255, 255, 0.45);
- background: transparent;
- }
- }
- .farm-list {
- margin-top: 12px;
- }
- .farm-card {
- margin-bottom: 10px;
- padding: 12px;
- border-radius: 12px;
- background: linear-gradient(180deg, #1a191d 0%, #121216 100%);
- border: 1px solid rgba(255, 255, 255, 0.08);
- box-sizing: border-box;
- &.is-current {
- border-color: rgba(255, 212, 137, 0.3);
- .phenology-box .phenology-text {
- color: #ffd489;
- }
- .farm-name {
- color: #ffd489;
- }
- }
- }
- .farm-card__header {
- display: flex;
- align-items: flex-start;
- justify-content: space-between;
- gap: 8px;
- }
- .farm-card__main {
- flex: 1;
- min-width: 0;
- }
- .farm-card__title-row {
- display: flex;
- align-items: center;
- gap: 8px;
- min-width: 0;
- }
- .farm-name {
- max-width: 180px;
- font-size: 16px;
- color: #fff;
- }
- .category-tag {
- flex-shrink: 0;
- height: 18px;
- padding: 0 8px;
- border-radius: 4px;
- border: 1px solid rgba(255, 255, 255, 0.12);
- background: rgba(255, 255, 255, 0.05);
- color: rgba(255, 255, 255, 0.6);
- font-size: 12px;
- line-height: 18px;
- box-sizing: border-box;
- }
- .farm-address {
- display: flex;
- align-items: center;
- gap: 5px;
- margin-top: 4px;
- font-size: 12px;
- color: rgba(255, 255, 255, 0.4);
- }
- .action-btn {
- flex-shrink: 0;
- height: 26px;
- padding: 0 8px 0 11px;
- border-radius: 22px;
- font-size: 12px;
- color: rgba(255, 255, 255, 0.85);
- border: 1px solid rgba(255, 255, 255, 0.16);
- box-sizing: border-box;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 2px;
- }
- .action-btn-current {
- padding: 0 6px;
- border-radius: 4px;
- border-color: rgba(255, 212, 137, 0.16);
- color: #FFD489;
- background: rgba(255, 212, 137, 0.1);
- }
- .phenology-box {
- margin-top: 8px;
- padding: 9px 10px;
- border-radius: 8px;
- background: rgba(255, 255, 255, 0.05);
- font-size: 12px;
- color: rgba(255, 255, 255, 0.7);
- line-height: 18px;
- .phenology-desc {
- color: rgba(255, 255, 255, 0.7);
- }
- .phenology-text {
- padding-left: 2px;
- color: #FFFFFF;
- font-size: 14px;
- }
- }
- .task-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 8px;
- margin-top: 8px;
- padding: 8px 10px;
- border-radius: 10px;
- background: rgba(255, 255, 255, 0.05);
- }
- .task-bar__left {
- display: flex;
- align-items: center;
- gap: 8px;
- min-width: 0;
- flex: 1;
- }
- .task-icon {
- width: 16px;
- height: 16px;
- flex-shrink: 0;
- }
- .task-name {
- max-width: 120px;
- font-weight: 500;
- font-size: 14px;
- color: rgba(255, 255, 255, 0.9);
- }
- .task-status {
- flex-shrink: 0;
- height: 18px;
- padding: 0 6px;
- border-radius: 4px;
- background: rgba(255, 212, 137, 0.1);
- color: #FFD489;
- border: 1px solid rgba(255, 255, 255, 0.12);
- font-size: 12px;
- line-height: 18px;
- }
- .task-bar__forward {
- display: inline-flex;
- align-items: center;
- gap: 4px;
- flex-shrink: 0;
- color: #FFD489;
- font-size: 14px;
- }
- .empty-tip {
- padding: 40px 0;
- text-align: center;
- color: rgba(255, 255, 255, 0.4);
- font-size: 13px;
- }
- .invite-bar {
- display: flex;
- justify-content: center;
- gap: 12px;
- padding: 20px 10px calc(30px + env(safe-area-inset-bottom));
- width: 100%;
- box-sizing: border-box;
- }
- .invite-btn {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- box-sizing: border-box;
- gap: 6px;
- flex: 1;
- height: 44px;
- border-radius: 28px;
- background: linear-gradient(90deg, #FFEBC9 0%, #FFCA6D 100%);
- color: #1A1408;
- font-size: 16px;
- &.secondary-btn {
- background: #141416;
- border: 1px solid rgba(255, 212, 137, 0.4);
- color: #FFD489;
- }
- .invite-btn-icon {
- width: 16px;
- height: 16px;
- filter: brightness(0) saturate(100%);
- opacity: 0.85;
- }
- }
- </style>
|