<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.code"
      :value="item.code"
    >
      <!-- {{ item.materialNo }} -->
      <el-row :gutter="20">
        <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 { getMaterialDropDownListOfIpqc } from '@/api/wms/base/material'
export default {
  props: {
    value: {
      type: [String, Number, Array],
      default: ''
    },
    processNo: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      options: []
    }
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  methods: {
    remoteMethod(keyWorld) {
      this.loading = true
      const params = {
        keyWorld
      }
      getMaterialDropDownListOfIpqc(params).then(response => {
        this.options = response.data.list || []
      }).finally(() => {
        this.loading = false
      })
    },
    change(v) {
      const item = this.options.find(i => i.code === v)
      this.$emit('change', item)
    }
  }
}
</script>

      <style>

      </style>

