lxf 3 недель назад
Родитель
Сommit
1e8f730fd4
2 измененных файлов с 33 добавлено и 22 удалено
  1. 5 0
      src/api/modules/questionnaire.js
  2. 28 22
      src/components/allGarden.vue

+ 5 - 0
src/api/modules/questionnaire.js

@@ -148,4 +148,9 @@ module.exports = {
         url: config.base_new_url + "report/weather_risk_report_latlon",
         type: "get",
     },
+    // 查询地区和品类
+    getAreaAndCropType: {
+        url: config.base_new_url + "questionnaire/find_farm_information_options",
+        type: "get",
+    },
 }

+ 28 - 22
src/components/allGarden.vue

@@ -141,32 +141,37 @@ const farmList = ref([]);
 const searchFarm = ref("");
 const regionVal = ref("");
 const typeVal = ref("");
-/** 筛选项从历次接口结果累计,避免筛选后下拉变空 */
-const regionOptionSet = ref(new Set());
-const typeOptionSet = ref(new Set());
+const regionOptions = ref([]);
+const typeOptions = ref([]);
 let searchTimer = null;
 
-const regionOptions = computed(() =>
-    Array.from(regionOptionSet.value).map((value) => ({ label: value, value }))
-);
-
-const typeOptions = computed(() =>
-    Array.from(typeOptionSet.value).map((value) => ({ label: value, value }))
-);
-
 /** 列表由接口按 farm_name / region / crop 筛选 */
 const filteredFarmList = computed(() => farmList.value);
 
-function collectFilterOptions(list) {
-    const nextRegions = new Set(regionOptionSet.value);
-    const nextTypes = new Set(typeOptionSet.value);
-    (list || []).forEach((farm) => {
-        const region = farm.city || farm.farm_city || "";
-        if (region) nextRegions.add(region);
-        if (farm.categoryLabel) nextTypes.add(farm.categoryLabel);
-    });
-    regionOptionSet.value = nextRegions;
-    typeOptionSet.value = nextTypes;
+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) {
@@ -263,7 +268,6 @@ function getFarmList() {
         .then((res) => {
             const list = Array.isArray(res?.data) ? res.data : [];
             farmList.value = normalizeFarmList(list);
-            collectFilterOptions(farmList.value);
             nextTick(() => {
                 ensureMap();
             });
@@ -313,6 +317,7 @@ watch(searchFarm, () => {
 });
 
 onMounted(() => {
+    getFilterOptions();
     getFarmList();
     nextTick(() => {
         ensureMap();
@@ -320,6 +325,7 @@ onMounted(() => {
 });
 
 onActivated(() => {
+    getFilterOptions();
     getFarmList();
     nextTick(() => {
         if (!indexMap.kmap) {