Просмотр исходного кода

feat:对接农户新增果园接口

wangsisi 1 неделя назад
Родитель
Сommit
e18acb491f
2 измененных файлов с 55 добавлено и 47 удалено
  1. 38 24
      src/components/popup/farmInfoPopup.vue
  2. 17 23
      src/views/old_mini/interactionList/index.vue

+ 38 - 24
src/components/popup/farmInfoPopup.vue

@@ -35,9 +35,9 @@
                 </el-form-item>
 
                 <!-- 农场品类 -->
-                <el-form-item label="农场品类" prop="typeId">
+                <el-form-item label="农场品类" prop="typeIds">
                     <el-select
-                        v-model="formData.typeId"
+                        v-model="formData.typeIds"
                         multiple
                         collapse-tags
                         placeholder="请选择"
@@ -80,7 +80,7 @@
             <div class="popup-title">为了精准匹配种植方案,完善物候信息</div>
 
             <!-- 物候期表单 -->
-            <el-form ref="phenologyFormRef" :model="phenologyData" :rules="phenologyRules" class="farm-form">
+            <el-form ref="phenologyFormRef" :model="phenologyData" label-width="92px" :rules="phenologyRules" class="farm-form">
                 <!-- 物候期选择器 -->
                 <el-form-item
                     label="当下物候期"
@@ -187,7 +187,7 @@ function getFruitsList(parentId) {
     });
 }
 
-const emit = defineEmits(["update:show", "confirm"]);
+const emit = defineEmits(["update:show"]);
 
 // 处理v-model双向绑定
 const showValue = computed({
@@ -208,7 +208,7 @@ const isNameEdited = ref(false);
 const formData = ref({
     address: "",
     speciesId: "",
-    typeId: [],
+    typeIds: [],
     mu: "",
     name: "",
 });
@@ -229,24 +229,33 @@ const normalizeTypeId = (value) => {
     return [value];
 };
 
-// 自定义验证器:验证农场品种
-const validateVariety = (rule, value, callback) => {
-    const hasType =
-        Array.isArray(formData.value.typeId)
-            ? formData.value.typeId.length > 0
-            : !!formData.value.typeId;
-    if (!formData.value.speciesId || !hasType) {
+// 自定义验证器:验证农场品种(只校验 speciesId)
+const validateSpeciesId = (rule, value, callback) => {
+    if (!value) {
         callback(new Error("请选择农场品种"));
     } else {
         callback();
     }
 };
 
+// 自定义验证器:验证农场品类(只校验 typeIds)
+const validateTypeIds = (rule, value, callback) => {
+    const hasType =
+        Array.isArray(value)
+            ? value.length > 0
+            : !!value;
+    if (!hasType) {
+        callback(new Error("请选择农场品类"));
+    } else {
+        callback();
+    }
+};
+
 // 表单验证规则
 const rules = {
     address: [{ required: true, message: "请输入农场位置", trigger: "blur" }],
-    speciesId: [{ required: true, validator: validateVariety, trigger: "change" }],
-    typeId: [{ required: true, validator: validateVariety, trigger: "change" }],
+    speciesId: [{ required: true, validator: validateSpeciesId, trigger: "change" }],
+    typeIds: [{ required: true, validator: validateTypeIds, trigger: "change" }],
     mu: [
         { required: true, message: "请输入农场亩数", trigger: "blur" },
         { pattern: /^\d+(\.\d+)?$/, message: "请输入有效的数字", trigger: "blur" },
@@ -266,7 +275,7 @@ watch(
     (newData) => {
         if (newData && Object.keys(newData).length > 0) {
             Object.assign(formData.value, newData);
-            formData.value.typeId = normalizeTypeId(formData.value.typeId);
+            formData.value.typeIds = normalizeTypeId(formData.value.typeIds);
         }
     },
     { immediate: true, deep: true }
@@ -287,12 +296,12 @@ watch(
             // 弹窗打开时,如果有初始数据则使用,否则使用默认值
             if (props.initialData && Object.keys(props.initialData).length > 0) {
                 Object.assign(formData.value, props.initialData);
-                formData.value.typeId = normalizeTypeId(formData.value.typeId);
+                formData.value.typeIds = normalizeTypeId(formData.value.typeIds);
             } else {
                 formData.value = {
                     address: "",
                     speciesId: "",
-                    typeId: [],
+                    typeIds: [],
                     mu: "",
                     name: "",
                 };
@@ -308,7 +317,7 @@ watch(
 
 // 品种1变化时,重置品种2并触发验证
 const handleSpecieChange = (val) => {
-    formData.value.typeId = [];
+    formData.value.typeIds = [];
     const specie = specieList.value.find(item => item.id === val);
     // 只有在用户没有手动修改名称时,才自动带出默认名称
     if (specie && !isNameEdited.value) {
@@ -324,9 +333,8 @@ const handleSpecieChange = (val) => {
 // 品种2变化时,触发验证
 const handleFruitsChange = () => {
     nextTick(() => {
-        // 校验农场品种(包含大类和品种)
-        formRef.value?.validateField("speciesId");
-        formRef.value?.validateField("typeId");
+        // 只校验当前字段(农场品类)
+        formRef.value?.validateField("typeIds");
     });
 };
 
@@ -356,14 +364,20 @@ const handleConfirm = async () => {
         try {
             await phenologyFormRef.value.validate();
             // 验证通过,提交所有数据并关闭弹窗
-            emit("confirm", { 
+            const params = {
                 ...formData.value,
                 ...phenologyData.value,
                 wkt: store.state.home.miniUserLocationPoint,
                 expertMiniUserId: props.expertMiniUserId,
                 containerId: specieList.value.find(item => item.id === formData.value.speciesId)?.defaultContainerId,
-            });
-            emit("update:show", false);
+            }
+            const { code, msg } = await VE_API.farm.saveFarm(params);
+            if (code === 0) {
+                ElMessage.success("农场信息确认成功");
+                emit("update:show", false);
+            } else {
+                ElMessage.error(msg || '农场信息确认失败');
+            }
         } catch (error) {
             console.log("物候期表单验证失败", error);
         }

+ 17 - 23
src/views/old_mini/interactionList/index.vue

@@ -75,7 +75,7 @@
             <!-- 比例信息(已上传状态显示) -->
             <div class="proportion-info" v-show="item.isConfirmed != null">
                 <span class="proportion-text" v-if="item.replyText">当前果园{{ item.phenologyName }}占比: {{ item.replyText
-                }}%</span>
+                    }}%</span>
                 <span class="proportion-text" v-else>暂无数据</span>
                 <div class="toggle-btn" @click="toggleExpand(item)">
                     <span>{{ item.expanded ? "收起" : "展开" }}</span>
@@ -89,8 +89,7 @@
         <div class="empty-data" v-if="!loading && listData.length === 0">暂无数据</div>
     </div>
     <!-- 农场信息完善弹窗 -->
-    <farm-info-popup :expertMiniUserId="query.expertMiniUserId" v-model:show="showFarmInfoPopup"
-        @confirm="handleFarmInfoConfirm" />
+    <farm-info-popup :expertMiniUserId="query.expertMiniUserId" v-model:show="showFarmInfoPopup" />
 
     <!-- 示例照片 -->
     <popup v-model:show="showExamplePopup" class="example-popup" :overlay-style="{ backdropFilter: 'blur(4px)' }">
@@ -105,7 +104,7 @@
     <popup v-model:show="showUploadProgressPopup" round class="upload-progress-popup">
         <div class="upload-progress-title">
             <span>照片上传进度</span>
-            <el-progress class="upload-progress" :percentage="50" stroke-width="10" :format="format"/>
+            <el-progress class="upload-progress" :percentage="50" stroke-width="10" :format="format" />
         </div>
         <div class="upload-wrap">
             <upload :maxCount="10" @handleUpload="handleUploadSuccess">
@@ -245,17 +244,6 @@ const toggleExpand = (item) => {
     item.expanded = !item.expanded;
 };
 
-// 确认农场信息
-const handleFarmInfoConfirm = async (data) => {
-    // 这里可以处理提交逻辑
-    const { code, msg } = await VE_API.farm.saveFarm(data);
-    if (code === 0) {
-        ElMessage.success("农场信息确认成功");
-    } else {
-        ElMessage.error(msg || '农场信息确认失败');
-    }
-};
-
 const handleDrawRegion = (item) => {
     console.log("勾画发生区域", item);
     router.push(`/draw_region`)
@@ -279,7 +267,6 @@ const getFarmList = async () => {
     if (data && data.length === 0) {
         showFarmInfoPopup.value = true;
     }
-    // showFarmInfoPopup.value = true;
 }
 
 </script>
@@ -584,21 +571,25 @@ const getFarmList = async () => {
 .upload-progress-popup {
     width: 100%;
     padding: 20px 16px;
-    .upload-progress-title{
+
+    .upload-progress-title {
         font-size: 16px;
         color: #121212;
         margin-bottom: 12px;
         display: flex;
         align-items: center;
         justify-content: space-between;
-        .upload-progress{
+
+        .upload-progress {
             width: 55%;
         }
     }
-    .upload-wrap{
+
+    .upload-wrap {
         margin-bottom: 12px;
     }
-    .region-tips{
+
+    .region-tips {
         color: #2199F8;
         padding: 5px;
         background: rgba(33, 153, 248, 0.1);
@@ -606,7 +597,8 @@ const getFarmList = async () => {
         margin: 16px 0 12px 0;
         text-align: center;
     }
-    .region-map{
+
+    .region-map {
         width: 100%;
         height: 168px;
         background: red;
@@ -614,14 +606,16 @@ const getFarmList = async () => {
         display: flex;
         align-items: center;
         justify-content: center;
-        .region-map-text{
+
+        .region-map-text {
             color: #FFFFFF;
             padding: 5px 20px;
             border-radius: 5px;
             background: rgba(0, 0, 0, 0.6);
         }
     }
-    .confirm-btn{
+
+    .confirm-btn {
         background: #2199f8;
         color: #ffffff;
         border-radius: 4px;