<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.name"
      :value="item.code"
    >
      <el-row>
        <el-col :span="12">{{ item.code }}</el-col>
        <el-col :span="12" class="text-right">{{ item.name }}</el-col>
      </el-row>
    </el-option>

  </el-select>
</template>

<script>
import { getOutSourceSupplerList } from '@/api/wms/inLibrary/outsourcePreparation'
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(keyWord) {
      this.loading = true
      const params = {
        keyWord
      }
      getOutSourceSupplerList(params).then(response => {
        this.options = response.data || []
      }).finally(() => {
        this.loading = false
      })
    },
    change(v) {
      const item = this.options.find(i => i.code === v)
      this.$emit('change', item)
    }
  }
}
</script>

    <style>

    </style>

