From 8abb605a626104db83463fd30eb46547fa2ca6a2 Mon Sep 17 00:00:00 2001 From: danshihao Date: Tue, 16 Jan 2024 16:40:37 +0800 Subject: [PATCH] fix 80839 --- src/components/company/SelectContacts.vue | 37 ++++++++++++++++----- src/views/draftTeam/SignUpDraftTeamPage.vue | 2 +- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/components/company/SelectContacts.vue b/src/components/company/SelectContacts.vue index 0c5585d..d756388 100644 --- a/src/components/company/SelectContacts.vue +++ b/src/components/company/SelectContacts.vue @@ -12,7 +12,6 @@ allowClear option-filter-prop="children" :filterOption="false" - :not-found-content="null" @search="lazySearch" @popupScroll="lazyPopupScroll" @dropdownVisibleChange="handleDropdownOpen"> @@ -102,12 +101,19 @@ export default { type: Number, require: false, default: 50 + }, + // 没有企业id(companyId)就不进行搜索 + notCompanyIdCancelSearch: { + type: Boolean, + require: false, + default: false } }, data() { return { contactsList: [], // 该企业下联系人列表 lazyContactsList: [], // 该企业下联系人列表 (懒加载) + searchContactsList: [], // 搜索的全下拉 (懒加载) isFirstOpen: true, // 编辑状态下是否为第一次打开 contactId: this.value } @@ -116,6 +122,7 @@ export default { // this.initContacts = null this.contactsList = [] this.lazyContactsList = [] + this.searchContactsList = [] // 编辑 第一次不回显的问题 this.getContactsList() }, @@ -149,8 +156,14 @@ export default { methods: { // 懒加载搜索 lazySearch (val) { - this.lazyContactsList = [] - this.lazyContactsList = this.contactsList.filter(item => item.name.includes(val)).slice(0, this.lazySize) + // 搜索后就只需要一直从searchContactsList里取懒加载的部分数据 + if (val) { + this.searchContactsList = this.contactsList.filter(item => item.name.includes(val)) + } else { + this.searchContactsList = this.contactsList + } + // 显示部分搜索结果 + this.lazyContactsList = this.searchContactsList.slice(0, this.lazySize) }, // 懒加载滚动 lazyPopupScroll: debounce(function (e) { @@ -165,11 +178,11 @@ export default { // 当下拉框滚动条到达底部的时候 if (scrollHeight < clientHeight + 5) { console.log('scroll end') - const allLen = this.contactsList.length + const allLen = this.searchContactsList.length const showLen = this.lazyContactsList.length // 如果总长度大于显示长度,那就添加 if (allLen > showLen) { - this.lazyContactsList = this.contactsList.slice(0, showLen + this.lazySize) + this.lazyContactsList = this.searchContactsList.slice(0, showLen + this.lazySize) } } } @@ -184,6 +197,8 @@ export default { } else { params.companyId = null } + // 如果没有id就不调用接口 + if (this.notCompanyIdCancelSearch && !params.companyId) return // 是否调用无权限接口 if (this.isLimit) { // 调用无权限接口 @@ -191,9 +206,12 @@ export default { getContactsByCompanyNoLimit(params).then(res => { this.contactsList = res.result if (this.lazy) { - // 回显的用户显示再最前面 + // 完整的所有下拉,回显的用户显示再最前面 const findIndex = this.contactsList.findIndex(item => item.id === this.value) this.contactsList.unshift(this.contactsList.splice(findIndex, 1)[0]) + // 搜索的所有下拉 + this.searchContactsList = this.contactsList + // 显示的所有下拉 this.lazyContactsList = this.contactsList.slice(0, this.lazySize) } if (this.initContacts && this.initContacts.id) { @@ -207,9 +225,12 @@ export default { getContactsByCompany(params).then(res => { this.contactsList = res.result || [] if (this.lazy) { - // 回显的用户显示再最前面 + // 完整的所有下拉,回显的用户显示再最前面 const findIndex = this.contactsList.findIndex(item => item.id === this.value) - this.contactsList.unshift(this.contactsList.splice(findIndex, 1)) + this.contactsList.unshift(this.contactsList.splice(findIndex, 1)[0]) + // 搜索的所有下拉 + this.searchContactsList = this.contactsList + // 显示的所有下拉 this.lazyContactsList = this.contactsList.slice(0, this.lazySize) } if (this.initContacts && this.initContacts.id) { diff --git a/src/views/draftTeam/SignUpDraftTeamPage.vue b/src/views/draftTeam/SignUpDraftTeamPage.vue index bec0b93..f78b701 100644 --- a/src/views/draftTeam/SignUpDraftTeamPage.vue +++ b/src/views/draftTeam/SignUpDraftTeamPage.vue @@ -87,7 +87,7 @@ v-decorator="[`payDraftingGroupSubItemContactsList[${index}].contactsId`, {rules: [{ required: index === 0, validator: index === 0 ? validateContactRequired : validateContact }],validateTrigger: 'change'}]" :maxLength='50' isLimit - lazy + not-company-id-cancel-search :ref="`selectContacts${index}`">