Jelajahi Sumber

修复多选框

1
mo 4 tahun lalu
induk
melakukan
ab43dcda2c
1 mengubah file dengan 8 tambahan dan 41 penghapusan
  1. 8 41
      src/components/remote-search/index.vue

+ 8 - 41
src/components/remote-search/index.vue

@@ -1,6 +1,6 @@
 <template>
   <div>
-    <el-select v-if='!multiple'
+    <el-select
       v-bind="{...$attrs}"
       :value="value"
       filterable
@@ -15,31 +15,8 @@
       :style="{ width: this.selectWidt + 'px!important' }"
     >
       <el-option
-        v-for="(item, index) in options"
-        :key="index"
-        :label="item.userName"
-        :value="item.userId"
-      >
-      </el-option>
-    </el-select>
-
-
-        <el-select v-else
-      v-bind="{...$attrs}"
-      :value="value"
-      filterable
-      remote
-      reserve-keyword
-      clearable
-      :multiple="multiple"
-      :placeholder="placeholder"
-      :loading="loading"
-      @change="changeValue"
-      :style="{ width: this.selectWidt + 'px!important' }"
-    >
-      <el-option
-        v-for="(item, index) in options"
-        :key="index"
+        v-for="(item) in options"
+        :key="item.userId"
         :label="item.userName"
         :value="item.userId"
       >
@@ -73,7 +50,6 @@ export default {
     // this.getList();
     // console.log(this.value)
     this.getOptions(this.value|| '' )
-    // console.log(this.multiple)
 
 
   },
@@ -86,27 +62,20 @@ export default {
         data[item.userId] = item
       }
       this.listById = data
-    if(this.multiple){
-       this.options =this.list
-    }else{
-       this.options =
+
+      this.options =
         this.list.length <= this.constant
           ? this.list
           : slice(this.list, 0, this.constant);
-    }
-     
 
             //  console.log(this.options)
     },
     remoteMethod(query) {
       // throttle
-      if(!this.multiple){
-         throttle(this.getOptions, 800)(query);
-      }
-     
+      throttle(this.getOptions, 800)(query);
     },
     async getOptions(query) {
-
+      console.log(query)
       if (query&&query.length>0) {
         let flag;
         this.options = this.list.filter((item) => {
@@ -114,18 +83,17 @@ export default {
             item.userName.toLowerCase().indexOf(query.toString().toLowerCase()) > -1 ||
             item.userId == query;
           if (this.multiple) {
-            console.log(this.value,this.value.includes(item.userId),item.userId)
             return flag || this.value.includes(item.userId);
           } else {
             // console.log(query,this.value)
             return flag || item.userId == this.value;
           }
         });
-  
       } else {
           try{
              await this.getList()
           const optionids = this.options.map(item => item.userId)
+
           const valueItem = this.listById[this.value]
           if (!optionids.includes(this.value) && valueItem) {
             this.options.push(valueItem)
@@ -159,7 +127,6 @@ export default {
 
         if (this.multiple) {
           if (val?.length > 0 && this.isFirst) {
-
            this.getOptions()
           }
         } else {