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

  </el-select>
</template>

<script>
import { getStockAreadropDownList } from '@/api/wms/base/stockArea'
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(name) {
      this.loading = true
      const params = {
        pageNo: 1,
        pageSize: 100,
        name
      }
      getStockAreadropDownList(params).then(response => {
        this.options = response.data || []
      }).finally(() => {
        this.loading = false
      })
    },
    change(v) {
      const item = this.options.find(i => i.id === v)
      this.$emit('change', item)
    }
  }
}
</script>

    <style>

    </style>

