Browse Source

单位选择组件封装。

zhengqiang 5 years ago
parent
commit
d22c8344a1

+ 28 - 3
src/components/SelectTree/index.vue

@@ -1,7 +1,7 @@
 <template>
- <el-select size="mini" :value="valueTitle" :clearable="clearable" @clear="clearHandle">
+ <el-select :size="size" :value="valueTitle" :clearable="clearable" @clear="clearHandle">
     <el-input
-      size="mini"
+      :size="size"
       class="selectInput"
       :placeholder="placeholder"
       v-model="filterText">
@@ -10,7 +10,7 @@
       <el-tree  id="tree-option"
         ref="selectTree"
         :accordion="accordion"
-        :data="options"
+        :data="optionData"
         :props="props"
         :node-key="props.value"    
         :default-expanded-keys="defaultExpandedKey"
@@ -45,6 +45,11 @@ export default {
       type: String,
       default: ()=>{ return null }
     },
+    /* 初始值 */
+    size:{
+      type: String,
+      default: ()=>{ return 'small' }
+    },
     /* 可清空选项 */
     clearable:{
       type:Boolean,
@@ -60,6 +65,26 @@ export default {
       default:()=>{return "检索关键字"}
     }
   },
+  computed: {
+    /* 转树形数据 */
+    optionData() {
+      //第一个节点为根节点
+      if(this.options.length>0){
+        var rootId = this.options[0].id;
+
+        let cloneData = JSON.parse(JSON.stringify(this.options)); // 对源数据深度克隆
+        return cloneData.filter(father => {
+          // 循环所有项,并添加children属性
+          let branchArr = cloneData.filter(child => father.id == child.parentId); // 返回每一项的子级数组
+          branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性,并赋值
+          return father.id == rootId || father.parentId == null; //返回第一层
+        });
+      }
+      else{
+        return [];
+      }
+    }
+  },
   data() {
     return {
       filterText: '',

+ 1 - 13
src/views/base/companyInfo-detail.vue

@@ -45,7 +45,7 @@
               </el-select>-->
               <el-select-tree
                 :props="props"
-                :options="optionData"
+                :options="companyResult"
                 :value="formModel.parentId"
                 @getValue="getSelectedValue($event)"
                 height="200"
@@ -185,18 +185,6 @@ export default {
       }
     };
   },
-  computed: {
-    /* 转树形数据 */
-    optionData() {
-      let cloneData = JSON.parse(JSON.stringify(this.companyResult)); // 对源数据深度克隆
-      return cloneData.filter(father => {
-        // 循环所有项,并添加children属性
-        let branchArr = cloneData.filter(child => father.id == child.parentId); // 返回每一项的子级数组
-        branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性,并赋值
-        return father.parentId == null; //返回第一层
-      });
-    }
-  },
   created() {
     var self = this;
     companyInfoApi.list().then(function(response) {

+ 2 - 13
src/views/base/companyInfo-list.vue

@@ -30,8 +30,9 @@
           ></el-option>
         </el-select> -->
         <el-select-tree
+          size="mini"
           :props="props"
-          :options="optionData"
+          :options="companyResult"
           :value="queryModel.parentId"
           @getValue="getSelectedValue($event)"
           height="200"
@@ -179,18 +180,6 @@ export default {
       }
     }
   },
-  computed: {
-    /* 转树形数据 */
-    optionData() {
-      let cloneData = JSON.parse(JSON.stringify(this.companyResult)); // 对源数据深度克隆
-      return cloneData.filter(father => {
-        // 循环所有项,并添加children属性
-        let branchArr = cloneData.filter(child => father.id == child.parentId); // 返回每一项的子级数组
-        branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性,并赋值
-        return father.parentId == null; //返回第一层
-      });
-    }
-  },
   created() {
     this.tableHeight = window.innerHeight - 320;
     this.treeHeight = window.innerHeight - 200;

+ 3 - 14
src/views/base/personInfo-list.vue

@@ -57,8 +57,9 @@
             ></el-option>
           </el-select>-->
           <el-select-tree
+            size="mini"
             :props="props"
-            :options="optionData"
+            :options="companyResult"
             :value="queryModel.parentId"
             @getValue="getSelectedValue($event)"
             height="200"
@@ -506,7 +507,7 @@ export default {
       showModal: false,
       modalTitle: "",
       businessKey: "",
-      companyResult: "",
+      companyResult: [],
       uploadCompanyId: "",
       batchImportVisible: false,
       batchImportFileList: [],
@@ -549,18 +550,6 @@ export default {
       }
     };
   },
-  computed: {
-    /* 转树形数据 */
-    optionData() {
-      let cloneData = JSON.parse(JSON.stringify(this.companyResult)); // 对源数据深度克隆
-      return cloneData.filter(father => {
-        // 循环所有项,并添加children属性
-        let branchArr = cloneData.filter(child => father.id == child.parentId); // 返回每一项的子级数组
-        branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性,并赋值
-        return father.parentId == null; //返回第一层
-      });
-    }
-  },
   created() {
     var self = this;