|
@@ -77,6 +77,7 @@ export default {
|
|
|
watch: {
|
|
|
value: {
|
|
|
handler(newV, oldV) {
|
|
|
+ // console.log({ newV, oldV })
|
|
|
if (this.searchValue === newV) {
|
|
|
return
|
|
|
}
|
|
@@ -87,7 +88,7 @@ export default {
|
|
|
}
|
|
|
const type = Object.prototype.toString.call(this.searchValue)
|
|
|
if (type.indexOf('Array') < 0) {
|
|
|
- this.searchPeople(this.searchValue)
|
|
|
+ this.searchPeople(this.searchValue, true)
|
|
|
} else if (type.indexOf('Array') > 0 && this.searchValue.length > 0 && this.firstGetArr) {
|
|
|
this.initMore(this.searchValue)
|
|
|
this.firstGetArr = false
|
|
@@ -100,12 +101,12 @@ export default {
|
|
|
this.initMore(this.searchValue)
|
|
|
},
|
|
|
methods: {
|
|
|
- remoteMethod: _.debounce(function(query) {
|
|
|
- query !== '' ? this.getMember(query) : this.options = []
|
|
|
- }, 2000),
|
|
|
- searchPeople(query) {
|
|
|
+ remoteMethod: _.debounce(function(query, initMore = false) {
|
|
|
+ query !== '' ? this.getMember(query, initMore) : this.options = []
|
|
|
+ }, 700),
|
|
|
+ searchPeople(query, initMore = false) {
|
|
|
this.loading = true
|
|
|
- this.remoteMethod(query)
|
|
|
+ this.remoteMethod(query, initMore)
|
|
|
},
|
|
|
initMore(arr) { // 当多人时候,对数组每一个人员进行搜索
|
|
|
if (this.multiple) {
|
|
@@ -128,23 +129,34 @@ export default {
|
|
|
return
|
|
|
}
|
|
|
this.loading = false
|
|
|
- const weakMap = new Map()
|
|
|
- for (const item of res.data) {
|
|
|
- if (!weakMap.has(item.idap)) {
|
|
|
- weakMap.set(item.idap, item)
|
|
|
- }
|
|
|
- }
|
|
|
// 去重
|
|
|
- let op = null
|
|
|
- const hash = {}
|
|
|
- const item = []
|
|
|
- initMore ? op = [...this.options, ...weakMap.values()] : op = [...weakMap.values()]
|
|
|
- op.map(t => {
|
|
|
- if (!hash[t.deptid]) {
|
|
|
- hash[t.deptid] = true && item.push(t)
|
|
|
- }
|
|
|
- })
|
|
|
- this.options = item
|
|
|
+ this.arrayNonRepeatfy(res.data, initMore)
|
|
|
+ // this.options = res.data
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 去重
|
|
|
+ * @param data 每次查询返回的结果
|
|
|
+ * @param initMore 搜索时,当有原始数据存在时,必然需要去重,否则会导致,数据重复
|
|
|
+ */
|
|
|
+ arrayNonRepeatfy(data, initMore = false) {
|
|
|
+ this.options = initMore ? data.map(e => e) : Array.from(new Set([...this.options, ...data]))
|
|
|
+ // console.log(this.options, data, 139)
|
|
|
+ // const weakMap = new Map()
|
|
|
+ // for (const item of data) {
|
|
|
+ // if (!weakMap.has(item.idap)) {
|
|
|
+ // weakMap.set(item.idap, item)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // let op = null
|
|
|
+ // const hash = {}
|
|
|
+ // const item = []
|
|
|
+ // initMore ? op = [...this.options, ...weakMap.values()] : op = [...weakMap.values()]
|
|
|
+ // op.map(t => {
|
|
|
+ // if (!hash[t.deptid]) {
|
|
|
+ // hash[t.deptid] = true && item.push(t)
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // this.options = item
|
|
|
},
|
|
|
changeSelect(e) {
|
|
|
if (this.searchValue === [] || this.searchValue === '') {
|