|
@@ -28,7 +28,7 @@ const placeholder = {
|
|
|
setTeachers: "请选择老师",
|
|
|
setEducations: "请选乐团主管",
|
|
|
};
|
|
|
-import { throttle, slice } from "lodash";
|
|
|
+import { throttle, slice, uniqBy } from "lodash";
|
|
|
import selects from "@/store/modules/selects";
|
|
|
export default {
|
|
|
name: "remote-search",
|
|
@@ -37,6 +37,7 @@ export default {
|
|
|
return {
|
|
|
options: [],
|
|
|
list: [],
|
|
|
+ listById: {},
|
|
|
loading: false,
|
|
|
constant: this.number || 50,
|
|
|
placeholder: placeholder[this.commit],
|
|
@@ -52,7 +53,11 @@ export default {
|
|
|
async getList() {
|
|
|
await this.$store.dispatch(this.commit);
|
|
|
this.list = this.selects[this.enumer[this.commit]];
|
|
|
-
|
|
|
+ const data = {}
|
|
|
+ for (const item of this.list) {
|
|
|
+ data[item.userId] = item
|
|
|
+ }
|
|
|
+ this.listById = data
|
|
|
this.options =
|
|
|
this.list.length <= this.constant
|
|
|
? this.list
|
|
@@ -63,7 +68,7 @@ export default {
|
|
|
// throttle
|
|
|
throttle(this.getOptions, 800)(query);
|
|
|
},
|
|
|
- getOptions(query) {
|
|
|
+ async getOptions(query) {
|
|
|
if (query) {
|
|
|
let flag;
|
|
|
this.options = this.list.filter((item) => {
|
|
@@ -77,7 +82,13 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
- this.getList();
|
|
|
+ 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')
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
changeValue(val) {
|