|
@@ -1,6 +1,6 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
- <el-select
|
|
|
+ <el-select v-if='!multiple'
|
|
|
v-bind="{...$attrs}"
|
|
|
:value="value"
|
|
|
filterable
|
|
@@ -22,6 +22,29 @@
|
|
|
>
|
|
|
</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"
|
|
|
+ :label="item.userName"
|
|
|
+ :value="item.userId"
|
|
|
+ >
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
@@ -63,17 +86,24 @@ export default {
|
|
|
data[item.userId] = item
|
|
|
}
|
|
|
this.listById = data
|
|
|
-
|
|
|
- this.options =
|
|
|
+ if(this.multiple){
|
|
|
+ this.options =this.list
|
|
|
+ }else{
|
|
|
+ this.options =
|
|
|
this.list.length <= this.constant
|
|
|
? this.list
|
|
|
: slice(this.list, 0, this.constant);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// console.log(this.options)
|
|
|
},
|
|
|
remoteMethod(query) {
|
|
|
// throttle
|
|
|
- throttle(this.getOptions, 800)(query);
|
|
|
+ if(!this.multiple){
|
|
|
+ throttle(this.getOptions, 800)(query);
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
async getOptions(query) {
|
|
|
|
|
@@ -84,26 +114,23 @@ 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)
|
|
|
this.options = uniqBy(this.options, 'userId')
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}catch(e){
|
|
|
// console.log(e)
|
|
|
}
|