封装人员组件并运用

被运用页面

 <input-person v-model="form.remark01" style="width: 220px"
                    placeholder="请输入" />
 import inputPerson from "@/components/inputPerson.vue";
 export default {
  components: {
    inputPerson, 
  },
   data() {
    return {
      form:{
        remark01:""
      },
      }
      }

inputPerson页面

<template>
  <div>
    <el-autocomplete
      v-model="value1"
      value-key="userName"
      :fetch-suggestions="querySearch"
      placeholder="请输入"
      :trigger-on-focus="false"
      style="width: 100%"
    >
      <i slot="suffix" class="el-input__icon el-icon-user-solid pointer" @click="choose" />
    </el-autocomplete>
    <el-dialog title="人员选择" :visible.sync="dialogTableVisible">
      <choose-person @person-select="personSelect" />
    </el-dialog>
  </div>
</template>
<script>
import choosePerson from './choosePerson'
import { GetAllUserInfos } from '@/api/insofworks'
import PinyinMatch from 'pinyin-match'

export default {  
  components: { choosePerson },
  props: {
    value: {
      type: String,
      default: ''
    },
  },
  data() {
    return {
      suggestions: null,
      dialogTableVisible: false,
    }
  },
  computed: {
    value1: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
        this.$emit('change', val)
      }
    }
  },
  
  methods: {
    choose() {
      this.dialogTableVisible = true
    },
    personSelect(id, name) {
      this.value1 = name
      this.dialogTableVisible = false
    },
    querySearch(queryString, cb) {
      if (this.suggestions) {
        var results = queryString ? this.suggestions.filter(this.createFilter(queryString, 'userName')) : this.suggestions
        // 调用 callback 返回建议列表的数据
        cb(results)
      } else {
        GetAllUserInfos().then(
          res => {
            this.suggestions = res.data
            var results = queryString ? this.suggestions.filter(this.createFilter(queryString, 'userName')) : this.suggestions
            // 调用 callback 返回建议列表的数据
            cb(results)
          }
        ).catch(err => {
          console.log(err)
          cb([])
        })
      }
    },
    createFilter(queryString, key) {
      return (item) => {
        // return (item[key].toLowerCase().includes(queryString.toLowerCase()))
        return (PinyinMatch.match(item[key], queryString))
      }
    }
  }
}
</script>
<style scoped>

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值