소스 검색

fix:修改接口请求参数

wangsisi 2 주 전
부모
커밋
39524cd5fd
2개의 변경된 파일과 62개의 추가작업 그리고 7개의 파일을 삭제
  1. 5 0
      src/api/modules/questionnaire.js
  2. 57 7
      src/views/old_mini/entry_information/components/baInformation.vue

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

@@ -21,4 +21,9 @@ module.exports = {
         url: config.base_new_url + "report/generate",
         type: "get",
     },
+    // 区县作物物候期(种植品类下拉)
+    countyPhenophase: {
+        url: config.base_new_url + "report/county_phenophase",
+        type: "get",
+    },
 }

+ 57 - 7
src/views/old_mini/entry_information/components/baInformation.vue

@@ -45,12 +45,13 @@
                             placement="bottom-end"
                             popper-class="crop-select-popper"
                             teleported
+                            :loading="cropLoading"
                         >
                             <el-option
-                                v-for="item in CROP_OPTIONS"
-                                :key="item"
-                                :label="item"
-                                :value="item"
+                                v-for="item in cropOptions"
+                                :key="item.name"
+                                :label="item.name"
+                                :value="item.name"
                             />
                         </el-select>
                     </el-form-item>
@@ -87,15 +88,17 @@ const HAS_FARM_KEY = "HAS_ENTRY_FARM";
 const ENTRY_FARM_DATA_KEY = "ENTRY_FARM_DATA";
 /** 默认定位:河北宁晋县 */
 const DEFAULT_POINT = "POINT(114.91863572509733 37.67702031436258)";
+/** 默认区县:河北宁晋县 */
+const DEFAULT_COUNTY_CODE = "130528";
 const MAP_KEY = "CZLBZ-LJICQ-R4A5J-BN62X-YXCRJ-GNBUT";
-/** 河北主要作物(固定下拉选项) */
-const CROP_OPTIONS = ["玉米", "冬小麦", "水稻", "马铃薯", "大豆", "谷子", "高粱", "莜麦"];
 
 const router = useRouter();
 
 const formRef = ref(null);
 const previewMapRef = ref(null);
 let previewMap = null;
+const cropOptions = ref([]);
+const cropLoading = ref(false);
 const form = reactive({
     name: "",
     phone: "",
@@ -196,6 +199,49 @@ function syncLocationFromSession() {
     nextTick(() => initPreviewMap(getDefaultPoint(), false));
 }
 
+/** 解析当前区县 code:优先选点 adcode,否则默认宁晋县 */
+function resolveCountyCode() {
+    const saved = readJson(LOCATION_KEY);
+    if (saved?.adcode) return String(saved.adcode);
+    return DEFAULT_COUNTY_CODE;
+}
+
+async function fetchCropOptions() {
+    const countyCode = resolveCountyCode();
+    cropLoading.value = true;
+    try {
+        const res = await VE_API.questionnaire.countyPhenophase({
+            county_code: countyCode,
+        });
+        if (res?.code != null && res.code !== 200) {
+            cropOptions.value = [];
+            ElMessage.error(res.msg || "获取种植品类失败");
+            return;
+        }
+        const list = Array.isArray(res?.data?.phenophases) ? res.data.phenophases : [];
+        const options = [];
+        const seen = new Set();
+        list.forEach((item) => {
+            const name = item?.crop_category_name;
+            if (typeof name !== "string" || !name.trim() || seen.has(name)) return;
+            seen.add(name);
+            options.push({
+                name,
+                code: item?.phenophase_code != null ? String(item.phenophase_code) : "",
+            });
+        });
+        cropOptions.value = options;
+        if (form.crop && !seen.has(form.crop)) {
+            form.crop = undefined;
+        }
+    } catch {
+        cropOptions.value = [];
+        ElMessage.error("获取种植品类失败,请稍后再试");
+    } finally {
+        cropLoading.value = false;
+    }
+}
+
 const goSelectLocation = () => {
     saveFormDraft();
     const mapCenter = form.location || getDefaultPoint();
@@ -255,11 +301,14 @@ const handleNext = async () => {
     }
 
     const crop = form.crop;
+    const selectedCrop = cropOptions.value.find((item) => item.name === crop);
+    const cropCode = selectedCrop?.code || "";
     const point = form.location || saved?.point || "";
     const farmData = {
         name: form.name,
         phone: form.phone,
         crop,
+        cropCode,
         point,
         coordinate: saved?.coordinate || null,
         region,
@@ -270,7 +319,7 @@ const handleNext = async () => {
         localStorage.setItem("GROWTH_REPORT_MAP_POINT", point);
         localStorage.setItem("selectedFarmPoint", point);
     }
-    VE_API.questionnaire.generateReport({ region, crop }).catch(() => {});
+    VE_API.questionnaire.generateReport({ region, crop, tel: form.phone }).catch(() => {});
     localStorage.setItem(HAS_FARM_KEY, "1");
     clearFormDraft();
     router.replace("/growth_report");
@@ -285,6 +334,7 @@ onMounted(() => {
 onActivated(() => {
     restoreFormDraft();
     syncLocationFromSession();
+    fetchCropOptions();
 });
 
 onBeforeUnmount(() => {