<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.erpOrderNo"
      :value="item.erpOrderNo"
    >
      <!-- <el-row :gutter="20">
        <el-col :span="12">{{ item.id }}</el-col>
        <el-col :span="12" class="text-right">{{ item.erpOrderNo }}</el-col>
      </el-row> -->
      {{ item.erpOrderNo }}
    </el-option>

  </el-select>
</template>

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

  <style>

  </style>

