From 5e059c9c17a6d63b6c017d2d2beb25ae227071d1 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 11 四月 2025 17:33:59 +0800
Subject: [PATCH] 走航融合优化中

---
 src/components/search/OptionDevice.vue |   50 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/src/components/search/OptionDevice.vue b/src/components/search/OptionDevice.vue
index d63fe7c..093e7b8 100644
--- a/src/components/search/OptionDevice.vue
+++ b/src/components/search/OptionDevice.vue
@@ -2,13 +2,13 @@
   <el-form-item label="璁惧">
     <el-select
       :model-value="modelValue"
-      @change="handleChange"
+      @update:model-value="handleChange"
       placeholder="璁惧"
       size="small"
       class="w-120"
     >
       <el-option
-        v-for="(s, i) in deviceList"
+        v-for="(s, i) in deviceOptions"
         :key="i"
         :label="s.label"
         :value="s.value"
@@ -18,41 +18,67 @@
 </template>
 
 <script>
+// import { deviceList } from '@/constant/device-type';
+import { mapStores } from 'pinia';
+import { useDeviceStore } from '@/stores/device';
+
 export default {
   props: {
     type: String,
     modelValue: String
   },
-  emits: ['update:modelValue'],
+  emits: ['update:modelValue', 'initOver'],
   data() {
     return {};
   },
   computed: {
-    deviceList() {
-      const t = this.type ? this.type : '0a';
-      return [1, 2, 3].map((v) => {
-        const text = `${t}000000000${v}`;
+    ...mapStores(useDeviceStore),
+    deviceOptions() {
+      return this.deviceStore.getDevice(this.type).map((v) => {
         return {
-          label: text,
-          value: text
+          label: v.deviceName,
+          value: v.deviceCode
         };
       });
     }
   },
   watch: {
-    deviceList(nV, oV) {
+    // type(nV, oV) {
+    //   if (nV != oV) {
+    //     this.refreshOptions();
+    //   }
+    // }
+    deviceOptions(nV, oV) {
       if (nV != oV) {
-        this.handleChange(nV[0].value);
+        if (nV.length > 0) {
+          this.handleChange(nV[0].value);
+        }
       }
     }
   },
   methods: {
+    fetchDevice() {
+      this.deviceStore.fetchDevice().then((res) => {
+        if (res.success && res.data.length > 0) {
+          this.handleChange(this.deviceOptions[0].value);
+          this.$emit('initOver');
+        }
+      });
+    },
+    // refreshOptions() {
+    //   this.deviceOptions =
+    // },
     handleChange(value) {
       this.$emit('update:modelValue', value);
     }
   },
   mounted() {
-    this.handleChange(this.deviceList[0].value);
+    if (this.deviceStore.deviceList.length == 0) {
+      this.fetchDevice();
+    } else {
+      this.handleChange(this.deviceOptions[0].value);
+      this.$emit('initOver');
+    }
   }
 };
 </script>

--
Gitblit v1.9.3