人员联想模糊匹配

这个博客展示了如何在前端应用中使用`el-autocomplete`和`el-select`组件实现用户和群组的搜索选择。组件支持单选和多选,并具备清空、禁用、远程数据加载等功能。用户输入时会触发异步数据请求,从后端获取匹配的用户信息。当用户选择项目负责人时,会更新表单并触发相关处理函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

单选
<el-autocomplete size="mini" v-model="form.projectLeader" :fetch-suggestions="userAutoSearch" @select="val => userAutoSelect(1, val)" clearable @clear="handleProjectNumberOfPeople" :disabled="currentPhase == '项目已完成'" placeholder="请输入项目负责人">
  <template slot-scope="{ item }">
    {{ item.pinyin + ' ' + item.userCode }}
  </template>
</el-autocomplete>
userAutoSearch(queryString, cb) {
  if (queryString.trim() == '') {
    cb([])
  }
  else {
    let that = this
    let _data = {
      searchParam: queryString,
      returnDataType: 1 //1:只返回用户,2:只返回群组,3:全部返回
    }
    that.$store.dispatch('peopleAccosiation', _data).then((res) => {
      cb(res.data)
    }, (err) => {
      console.log(err.message)
    })
  }
},
userAutoSelect(_no, val) {
  let _user = val.pinyin + ' ' + val.userCode
  if (_no == 1) {
    this.form.projectLeader = _user
    this.handleProjectNumberOfPeople()
  }
  else {
  }
}
多选
<el-select size="mini" v-model="form.TC" :disabled="currentPhase == '项目已完成'" multiple filterable clearable remote :remote-method="userSearch" @change="handleReportTo" placeholder="请输入TC" :loading="userLoading">
  <el-option v-for="(user, index) in userSearchData" :key="index" :value="user.pinyin + ' ' + user.userCode"></el-option>
</el-select>
userSearch(val) {
  let that = this
  if (val.trim() == '') {
    that.userSearchData = []
  }
  else {
    that.userLoading = true
    let _data = {
      searchParam: val,
      returnDataType: 1 //1:只返回用户,2:只返回群组,3:全部返回
    }
    that.$store.dispatch('peopleAccosiation', _data).then((res) => {
      that.userSearchData = res.data
      that.userLoading = false
    }, (err) => {
      console.log(err.message)
      that.userLoading = false
    })
  }
},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值