From 99e37eb1e5ba8636b6a5994861dec31278d312c2 Mon Sep 17 00:00:00 2001
From: 石广澎 <shiguangpeng@163.com>
Date: 星期二, 21 十一月 2023 15:08:32 +0800
Subject: [PATCH] 列表搜索项支持级联

---
 admin-web/src/components/mySearch/SearchItem.vue |  107 +++++++++++++++++++++++++++++------------------------
 1 files changed, 59 insertions(+), 48 deletions(-)

diff --git a/admin-web/src/components/mySearch/SearchItem.vue b/admin-web/src/components/mySearch/SearchItem.vue
index 4da675b..cefc365 100644
--- a/admin-web/src/components/mySearch/SearchItem.vue
+++ b/admin-web/src/components/mySearch/SearchItem.vue
@@ -132,54 +132,7 @@
     item: Object,
   },
   created() {
-    if (this.item.type === 'select' && this.item.optionsConfig) {
-      if (this.$axios === undefined) {
-        console.error('璇峰厛閰嶇疆this.$axios');
-        return;
-      }
-      request({
-        url: this.item.optionsConfig.url,
-        method: 'get',
-      }).then((res) => {
-        const data = res || [];
-        this.item.options = [];
-        data.forEach((v) => {
-          this.item.options.push({
-            label: v[this.item.optionsConfig.label || 'label'],
-            value: v[this.item.optionsConfig.value || 'value'],
-          });
-        });
-      });
-    }
-    if (this.item.type === 'cascader' && this.item.optionsConfig) {
-      if (this.$axios === undefined) {
-        console.error('璇峰厛閰嶇疆this.$axios');
-        return;
-      }
-      request({
-        url: this.item.optionsConfig.url,
-        method: 'get',
-      }).then((res) => {
-        const data = res || [];
-        this.item.options = [];
-        this.item.options = data;
-      });
-    }
-    if (this.item.type === 'tree-select' && this.item.optionsConfig) {
-      if (this.$axios === undefined) {
-        console.error('璇峰厛閰嶇疆this.$axios');
-        return;
-      }
-      if (this.item.asyncLoad) {
-        this.asyncLoad({value: 0}).then((res) => {
-          this.treeData = res;
-        });
-      } else {
-        this.asyncLoad({}).then((res) => {
-          this.treeData = res;
-        });
-      }
-    }
+    this.initData({})
   },
   watch: {
     value(v) {
@@ -230,6 +183,64 @@
     };
   },
   methods: {
+    clearData() {
+      this.item.options = []
+      this.treeData = []
+    },
+    initData(params) {
+      this.val = this.item.defaultValue
+      if (this.item.type === 'select' && this.item.optionsConfig) {
+        if (this.$axios === undefined) {
+          console.error('璇峰厛閰嶇疆this.$axios');
+          return;
+        }
+        request({
+          url: this.item.optionsConfig.url,
+          method: 'get',
+          params
+        }).then((res) => {
+          const data = res || [];
+          this.item.options = [];
+          data.forEach((v) => {
+            this.item.options.push({
+              label: v[this.item.optionsConfig.label || 'label'],
+              value: v[this.item.optionsConfig.value || 'value'],
+            });
+          });
+        });
+      }
+      if (this.item.type === 'cascader' && this.item.optionsConfig) {
+        if (this.$axios === undefined) {
+          console.error('璇峰厛閰嶇疆this.$axios');
+          return;
+        }
+        request({
+          url: this.item.optionsConfig.url,
+          method: 'get',
+          params
+        }).then((res) => {
+          const data = res || [];
+          this.item.options = [];
+          this.item.options = data;
+        });
+      }
+      if (this.item.type === 'tree-select' && this.item.optionsConfig) {
+        if (this.$axios === undefined) {
+          console.error('璇峰厛閰嶇疆this.$axios');
+          return;
+        }
+        if (this.item.asyncLoad) {
+          params.value = 0
+          this.asyncLoad(params).then((res) => {
+            this.treeData = res;
+          });
+        } else {
+          this.asyncLoad(params).then((res) => {
+            this.treeData = res;
+          });
+        }
+      }
+    },
     panelChange(v, type) {
       var info = null
       if (v && this.item.type !== 'date-time-picker') {

--
Gitblit v1.9.1