<template>
  <el-select
    v-model="selected"
    filterable
    remote
    reserve-keyword
    placeholder="请输入关键字"
    :remote-method="remoteMethod"
    :loading="loading"
    v-bind="$attrs"
    @change="change"
  >
    <el-option
      v-for="item in options"
      :key="item.id"
      :label="item.nickname"
      :value="item.nickname"
    >
      {{ item.nickname }}
    </el-option>

  </el-select>
</template>

<script>
import { getUserList } from '@/api/wms/base/stock'
export default {
  props: {
    value: {
      type: [String, Number, Array],
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      options: []
    }
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  methods: {
    remoteMethod(keyWold) {
      this.loading = true
      const params = {
        keyWold
      }
      getUserList(params).then(response => {
        this.options = response.data || []
      }).finally(() => {
        this.loading = false
      })
    },
    change(v) {
      const item = this.options.find(i => i.nickname === v)
      this.$emit('change', item)
    }
  }
}
</script>

    <style>

    </style>

