Kaynağa Gözat

feat:首页果园和方案接口对接

wangsisi 1 gün önce
ebeveyn
işleme
7afcb3b18a
1 değiştirilmiş dosya ile 41 ekleme ve 33 silme
  1. 41 33
      src/components/weatherInfo.vue

+ 41 - 33
src/components/weatherInfo.vue

@@ -9,25 +9,25 @@
                 <div class="address-select flex-center">
                     <el-dropdown class="select-garden" trigger="click" popper-class="select-garden-popper">
                         <div class="el-dropdown-link flex-center">
-                            <span :class="value2 === '从化荔博园' ? 'ellipsis-l1' : ''">{{ value2 }}</span>
-                            <div class="default-text" v-show="value2 === '从化荔博园'">默认</div>
+                            <span :class="farmName === '从化荔博园' ? 'ellipsis-l1' : ''">{{ farmName }}</span>
+                            <div class="default-text" v-show="farmName === '从化荔博园'">默认</div>
                             <el-icon class="el-icon--right"><arrow-down /></el-icon>
                         </div>
                         <template #dropdown>
                             <el-dropdown-menu>
                                 <el-dropdown-item
-                                    @click="handleCommand(item.label)"
-                                    v-for="item in options2"
-                                    :key="item.value"
-                                    :class="{ 'selected-active-garden': value2 === item.label }"
+                                    @click="handleCommand(item.name)"
+                                    v-for="item in farmList"
+                                    :key="item.organId"
+                                    :class="{ 'selected-active-garden': farmName === item.name }"
                                 >
-                                    {{ item.label }}
+                                    {{ item.name }}
                                 </el-dropdown-item>
                             </el-dropdown-menu>
                         </template>
                     </el-dropdown>
-                    <el-select class="select-plan" v-model="value" size="small">
-                        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
+                    <el-select class="select-plan" v-model="planValue" size="small">
+                        <el-option v-for="item in planList" :key="item.id" :label="item.name" :value="item.id" />
                     </el-select>
                 </div>
                 <div class="temperature flex-center">
@@ -58,35 +58,15 @@
 <script setup>
 import { onMounted, ref } from "vue";
 import weatherChart from "./weatherChart.vue";
-
+import { useStore } from "vuex";
+const store = useStore();
 // 定义emit事件
 const emit = defineEmits(['weatherExpanded']);
 
-const value2 = ref("从化荔博园");
-const options2 = [
-    {
-        value: "Option1",
-        label: "从化荔博园",
-    },
-    {
-        value: "Option2",
-        label: "从化荔博园2",
-    },
-];
-
 const handleCommand = (command) => {
-    value2.value = command;
-    console.log("选中了:", command);
+    farmName.value = command;
 };
 
-const value = ref("Option1");
-const options = [
-    {
-        value: "Option1",
-        label: "选择方案1",
-    },
-];
-
 const isExpanded = ref(false);
 
 const toggleExpand = () => {
@@ -94,7 +74,35 @@ const toggleExpand = () => {
     emit('weatherExpanded',isExpanded.value);
 };
 
-onMounted(() => {});
+const miniUserId = store.state.home.miniUserId;
+
+onMounted(() => {
+    getFarmList()
+});
+
+const farmId = ref(null);
+const containerId = ref(null);
+const farmName = ref("");
+const farmList = ref([]);
+// 获取农场列表
+function getFarmList() {
+    VE_API.farm.fetchFarmList({userId: miniUserId, show3dFarm: false}).then(({data}) => {
+        farmList.value = data || []
+        farmName.value = data[0].name
+        farmId.value = data[0].organId
+        containerId.value = data[0].containerId
+        getPlanList()
+    })
+}
+
+// 获取方案列表
+const planValue = ref("");
+const planList = ref([]);
+function getPlanList() {
+    VE_API.home.listByFarmIdAndContainerId({farmId: farmId.value, containerId: containerId.value}).then(({data}) => {
+        planList.value = data || []
+    })
+}
 </script>
 
 <style lang="scss" scoped>