<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.wmsPurchaseOrderDetailId"
      :label="item.materialNo"
      :value="item.materialNo"
    >
      <!-- {{ item.materialNo }} -->
      <el-row :gutter="20" class="materialSelect">
        <el-col :span="8" class="materialNo">{{ item.materialNo }}</el-col>
        <el-col :span="8" class="materialName">{{ item.materialName }}</el-col>
        <el-col :span="8" class="text-right">{{ item.shouldReceiveQty }}</el-col>
      </el-row>
    </el-option>

  </el-select>
</template>

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

<style scoped>
</style>

