1.需求
表單項需具有搜索功能,並以下拉選的形式展現
2.實現
<template>
<div class="medicalRecord">
<div class="main-content" v-if="!taskDetail">
<div class="content-top">
<el-form style="width: 100%" :inline="true" :model="formResult" ref="formResult" hide-required-asterisk class="form-box" :rules="formRules">
<ul class="flex-space-between" style="width: 100%">
<li style="width: 322px; margin-left: 3px !important;">
<el-form-item label="管理機構:" label-width="82px">
<el-select
v-model="formResult.branchCom"
filterable
remote
clearable
reserve-keyword
placeholder="請輸入關鍵詞"
:remote-method="remoteMethod"
:loading="remoteLoading"
:disabled="isRemote"
@focus="repeatList"
@change="handleSelectBranchCom"
>
<el-option
v-for="item in remoteOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</li>
</ul>
</el-form>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'taskManage',
data () {
return {
formResult: {
branchCom: '', // 管理機構
branchComCode: '' // 管理機構編碼
},
formRules: {
// grpContNo: [{required: true, message: '請輸入團體保單號', trigger: 'blur'}] // 團體保單號必填
},
remoteOptions: [], // 遠程搜索列表
remoteList: [], // 返回的遠程搜索列表
remoteLoading: false, // 是否正在從遠程獲取數據
isRemote: false // 是否爲遠程搜索
}
},
created () {
// 獲取當前登錄人的中支
// this.formResult.branchComCode = this.$cookies.get('branchCom')
// console.log(this.formResult.branchComCode)
this.getBranchCom() // 獲取管理機構列表
},
methods: {
// 獲取管理機構列表
getBranchCom () {
console.log('獲取管理機構,入參;;;this.branchComCode', this.formResult.branchComCode)
// let bcode = this.formResult.branchComCode
this.$axios({
url: 'survey-app-service/rest/survey/branchcom/query',
method: 'post',
data: {
'tradeMap': {
'manageCom': '',
'branchCom': '%'
}
}
}).then(res => {
console.log(res)
let data = res.data
if (data.tradeMap.resultCode === '00') {
this.remoteList = data.tradeMap.comCode.map(item => {
// return { value: item, label: item }
return {
value: item,
label: item.split(',')[1]
}
})
console.log('this.remoteList')
console.log(this.remoteList)
}
}).catch(() => {
this.$message.error('系統異常')
})
},
// 清空選擇項
repeatList () {
this.remoteOptions = this.remoteList.filter(item => {
return item.label
})
},
// 選中管理機構時觸發
handleSelectBranchCom (item) {
console.log('遠程搜索選中後返回的item:::::即value的值')
console.log(item)
this.formResult.branchComCode = item.split(',')[0]
},
// 管理機構觸發的遠程搜索方法
remoteMethod (query) {
console.log(this.remoteList)
if (query !== '') {
this.remoteLoading = true
setTimeout(() => {
this.remoteLoading = false
this.remoteOptions = this.remoteList.filter(item => {
return item.value
.indexOf(query) > -1
})
console.log('this.remoteOptions')
console.log(this.remoteOptions)
}, 200)
} else {
this.remoteOptions = []
}
}
}
}
</script>
3.後端返回結果示例
{errorList:[]
serviceNode:""
shardFlag:false
storageMap:{}
tradeMap:{
message:"查詢成功"
resultCode:"00"
comCode:["01,北京分公司", "02,湖北分公司", "0201,湖北分公司宜昌中心"]
}}
4.效果展示