瀏覽代碼

feat:对接创建农场接口

wangsisi 22 小時之前
父節點
當前提交
6c4434091b

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

@@ -17,6 +17,11 @@ module.exports = {
         url: config.base_dev_url + "v2/farm/selfCreateFarmByExpert",
         type: "post",
     },
+    // 自己创建农场基于专家
+    saveBasicFarmInfoByExpertV3: {
+        url: config.base_dev_url + "v3/farm/selfCreateFarmByExpert",
+        type: "post",
+    },
     // 保存草稿
     saveDraft: {
         url: url + "/saveDraft",

+ 16 - 11
src/views/old_mini/create_farm/index.vue

@@ -481,14 +481,16 @@ const submitForm = (formEl) => {
     if (!formEl) return;
     formEl.validate((valid) => {
         if (valid) {
-            const mainSpecies = Array.isArray(ruleForm.speciesItem)
-                ? ruleForm.speciesItem[0]
-                : ruleForm.speciesItem;
+            const speciesList = Array.isArray(ruleForm.speciesItem) ? ruleForm.speciesItem : (ruleForm.speciesItem ? [ruleForm.speciesItem] : []);
+            const mainSpecies = speciesList[0];
+            const speciesContainer = speciesList.map((item) => ({
+                speciesId: item?.id ?? null,
+                containerId: item?.defaultContainerId ?? null,
+            }));
             const params = {
                 ...ruleForm,
                 wkt: centerPoint.value,
-                speciesId: mainSpecies?.id,
-                containerId: mainSpecies?.defaultContainerId,
+                speciesContainer,
                 agriculturalCreate: route.query.type === "client" ? 1 : 0,
                 // 编辑时geom不是数组,新增时是数组
                 geom:
@@ -520,6 +522,10 @@ const submitForm = (formEl) => {
                 if (Array.isArray(queryParams.geom)) {
                     queryParams.geom = JSON.stringify(queryParams.geom);
                 }
+                // speciesContainer 为对象时需序列化,否则 query 传递后无法正确解析
+                if (queryParams.speciesContainer && typeof queryParams.speciesContainer === 'object') {
+                    queryParams.speciesContainer = JSON.stringify(queryParams.speciesContainer);
+                }
                 delete queryParams.speciesItem;
                 queryParams.speciesName = mainSpecies?.name;
                 
@@ -681,18 +687,17 @@ function getSpecieList() {
     return VE_API.farm.fetchSpecieList({ point: centerPoint.value }).then(({ data }) => {
         const list = Array.isArray(data) ? data : [];
         // 只保留名称包含“荔枝”的品类
-        const litchiList = list.filter((item) => item?.name && item.name.includes("荔枝"));
-        specieList.value = litchiList;
+        specieList.value = list;
         // 非编辑模式且当前未选择品类时,默认选中第一项
         const noSpeciesSelected =
             !Array.isArray(ruleForm.speciesItem) || ruleForm.speciesItem.length === 0;
-        if (route.query.type !== "edit" && noSpeciesSelected && litchiList.length > 0) {
-            const first = { value: litchiList[0].id, ...litchiList[0] };
+        if (route.query.type !== "edit" && noSpeciesSelected && list.length > 0) {
+            const first = { value: list[0].id, ...list[0] };
             ruleForm.speciesItem = [first];
             // 同步触发品类变更逻辑(加载品种、自动生成农场名等)
             changeSpecie(first);
         }
-        return litchiList;
+        return list;
     });
 }
 
@@ -1149,7 +1154,7 @@ function handleMianjiInput(value) {
                     }
 
                     .select-item {
-                        min-width: 76px;
+                        min-width: 100px;
                     }
                 }
 

+ 1 - 1
src/views/old_mini/home/index.vue

@@ -103,7 +103,7 @@ const router = useRouter();
 const showAddClient = ref(false);
 const handleAddClientSelf = () => {
     showAddClient.value = false;
-    router.push("/create_farm?type=add");
+    router.push("/create_farm?from=home&type=add");
 };
 const handleAddClientInvite = () => {
     showAddClient.value = false;

+ 22 - 4
src/views/old_mini/home/subPages/prescriptionPage.vue

@@ -578,19 +578,23 @@ async function submit() {
         //     expertMiniUserId: '81881',
         // }
         // const res = await VE_API.basic_farm.saveBasicFarmInfoByExpert(params);
-        const res = await VE_API.farm.saveFarm(route.query);
+        const param = {
+            ...route.query,
+            expertMiniUserId: '81881',
+            speciesContainer: JSON.parse(route.query.speciesContainer),
+        }
+        const res = await VE_API.basic_farm.saveBasicFarmInfoByExpertV3(param);
         if (res.code === 0) {
             // showSuccessPopup.value = true;
 
             // 设置选中当前新增的农场
             localStorage.setItem("selectedFarmId", res.data.id);
             localStorage.setItem("selectedFarmName", res.data.name);
-            console.log('route.query.invite', route.query);
             if(route.query.invite){
                 qrCodePopupRef.value.showPopup();
                 return;
             }
-            // router.replace('/home');
+            router.replace('/home');
             // return true;
         } else {
             ElMessage.error(res.msg || '提交失败,请重试');
@@ -685,12 +689,26 @@ const getTodayDate = () => {
 
 const firstPhenology = ref({});
 const phenologyData = ref({});
+// 从 query 中解析 containerId(支持 speciesContainer 数组/对象或 JSON 字符串)
+const getContainerIdFromQuery = () => {
+    const sc = route.query.speciesContainer;
+    if (sc != null) {
+        const parsed = typeof sc === 'string' ? (tryParse(sc) || []) : sc;
+        const first = Array.isArray(parsed) ? parsed[0] : parsed;
+        return first?.containerId ?? route.query.containerId;
+    }
+    return route.query.containerId;
+};
+const tryParse = (str) => {
+    try { return JSON.parse(str); } catch { return null; }
+};
+
 // 获取当前和下一个物候期
 const getCurrentAndNextPhenology = async () => {
     try {
         const { data } = await VE_API.home.getCurrentAndNextPhenology({ 
             expertMiniUserId: '81881',
-            containerId: route.query.containerId,
+            containerId: getContainerIdFromQuery(),
         });
         if (data && Array.isArray(data)) {
             // 初始化物候期表单数据,日期使用第一个物候期的 startDate