Pārlūkot izejas kodu

feat:对接农资农事方案接口

wangsisi 2 dienas atpakaļ
vecāks
revīzija
dc2c81e2bf

+ 10 - 0
src/api/modules/home.js

@@ -42,5 +42,15 @@ module.exports = {
     listMySchemes:{
         url: config.base_dev_url + "container_farm_work_scheme/listMySchemes",
         type: "get",
+    },
+    //批量初始化农事方案(多个容器)
+    batchInitSchemes:{
+        url: config.base_dev_url + "container_farm_work_scheme/batchInitScheme",
+        type: "post",
+    },
+    //根据方案ID查询农事列表(按物候期分组)
+    listBySchemeId:{
+        url: config.base_dev_url + "z_farm_work_lib/listBySchemeId",
+        type: "get",
     }
 }

+ 33 - 5
src/components/pageComponents/PlanList.vue

@@ -3,7 +3,7 @@
         <div class="plan-menu">
             <el-anchor :container="containerRef" direction="vertical" type="default" @click="handleClick">
                 <el-menu :default-active="defaultActive" class="el-menu-vertical-demo">
-                    <el-sub-menu v-for="(menu, index) in menuData" :key="index" :index="String(menu.id)">
+                    <el-sub-menu v-for="(menu, index) in menuData" :key="index" :index="String(menu.phenologyId)">
                         <template #title>
                             <img class="menu-icon" :src="require(`@/assets/img/gallery/icon-${index}.png`)" />
                             <span class="menu-text">{{ menu.phenologyName }}</span>
@@ -31,7 +31,7 @@
                         :key="index + '-' + subI"
                     >
                         <div class="section-id" :id="section.phenologyName + sub.name"></div>
-                        <record-item :record-item-data="sub">
+                        <record-item :record-item-data="sub" @click="handleEdit(sub)">
                             <template #title>
                                 <div class="box-title">
                                     <div class="title-l">
@@ -52,13 +52,16 @@
 </template>
 
 <script setup>
-import { ref, onMounted } from "vue";
+import { ref, onMounted, watch } from "vue";
 import recordItem from "@/components/recordItem.vue";
+import { useRouter } from "vue-router";
+
+const router = useRouter();
 
 const props = defineProps({
     farmId: {
         type: [Number, String],
-        required: true,
+        default: null,
     },
     isEdit: {
         type: Boolean,
@@ -68,6 +71,10 @@ const props = defineProps({
         type: String,
         default: "1-1",
     },
+    schemeId : {
+        type: [Number, String],
+        default: null,
+    },
 });
 
 const curRole = localStorage.getItem("SET_USER_CUR_ROLE")
@@ -90,10 +97,30 @@ const getFarmTypeText = (type) => {
     return "";
 };
 
+const handleEdit = (sub) => {
+    if(curRole == 2){
+        router.push(`/edit_plan?id=${sub.id}`);
+    }
+};
+
 onMounted(() => {
-    getPlanWorkList();
+    if(props.farmId){
+        getPlanWorkList();
+    }
+});
+
+watch(() => props.schemeId, (newVal) => {
+    if(newVal){
+        getListBySchemeId();
+    }
 });
 
+const getListBySchemeId = () => {
+    VE_API.home.listBySchemeId({ schemeId: props.schemeId }).then(({ data }) => {
+        menuData.value = data;
+    });
+};
+
 const handleClick = (e) => {
     e.preventDefault();
 };
@@ -207,6 +234,7 @@ const handleClick = (e) => {
         .box-title {
             display: flex;
             align-items: center;
+            justify-content: space-between;
             padding-bottom: 8px;
             border-bottom: 1px solid #f5f5f5;
             margin-bottom: 8px;

+ 7 - 3
src/components/pageComponents/TabList.vue

@@ -34,13 +34,13 @@ const emit = defineEmits(['update:modelValue', 'change']);
 
 // 判断是否为对象格式的 tab
 const isObjectTab = (tab) => {
-    return typeof tab === 'object' && tab !== null && (tab.title !== undefined || tab.label !== undefined);
+    return typeof tab === 'object' && tab !== null && (tab.title !== undefined || tab.label !== undefined || tab.name !== undefined);
 };
 
 // 获取 tab 的标题
 const getTabTitle = (tab) => {
     if (isObjectTab(tab)) {
-        return tab.title || tab.label || '';
+        return tab.title || tab.label || tab.name || '';
     }
     return tab;
 };
@@ -49,7 +49,11 @@ const getTabTitle = (tab) => {
 const isActive = (index, tab) => {
     if (isObjectTab(tab)) {
         // 对象格式:比较 value
-        return props.modelValue === tab.value;
+        if(tab.value){
+            return props.modelValue === tab.value;
+        }else{
+            return props.modelValue === tab.id;
+        }
     }
     // 字符串/简单格式:比较索引
     return props.modelValue === index;

+ 35 - 17
src/views/old_mini/plan/index.vue

@@ -7,9 +7,10 @@
                 type="light"
                 v-model="active"
                 :tabs="tabs"
-                @change="handleFarmServiceTabChange"
+                @change="handleTabChange"
+                class="tabs-list"
             />
-            <plan-list :farm-id="route.query.farmId" :default-active="defaultActive" isEdit> </plan-list>
+            <plan-list :farm-id="route.query.farmId" :schemeId="active" isEdit> </plan-list>
         </div>
     </div>
 </template>
@@ -22,25 +23,39 @@ import tabList from "@/components/pageComponents/TabList.vue";
 import PlanList from "@/components/pageComponents/PlanList.vue";
 
 const route = useRoute();
-// 菜单
-const defaultActive = ref("1-1");
+const curRole = localStorage.getItem("SET_USER_CUR_ROLE");
 
-const curRole = localStorage.getItem('SET_USER_CUR_ROLE')
+const tabs = ref([]);
+const active = ref(null);
 
-const tabs = [];
-const active = ref(0);
+const handleTabChange = (index) => {
+    console.log(index);
+};
 
-const handleFarmServiceTabChange = (index) => {};
-
-onMounted(()=>{
-    if(curRole == 2){
-        VE_API.home.listMySchemes().then(({data,code}) => {
-            if(code == 0){
-                tabs.value = data || []
-            }
-        })
+onMounted(() => {
+    if (curRole == 2) {
+        getListMySchemes();
     }
-})
+});
+
+const getListMySchemes = () => {
+    VE_API.home.listMySchemes().then(({ data }) => {
+        if (data.length) {
+            tabs.value = data || [];
+            active.value = data[0].id;
+        } else {
+            getSchemes();
+        }
+    });
+};
+
+const getSchemes = () => {
+    VE_API.home.batchInitSchemes({ containerIds: [3], schemeName: "农资荔枝方案" }).then(({ code }) => {
+        if (code == 0) {
+            getListMySchemes();
+        }
+    });
+};
 </script>
 
 <style scoped lang="scss">
@@ -52,6 +67,9 @@ onMounted(()=>{
         width: 100%;
         height: calc(100vh - 40px);
         padding-top: 10px;
+        .tabs-list {
+            margin: 0 0 10px 10px;
+        }
     }
 }
 </style>