<template>
  <el-select
    v-model="selected"
    v-bind="$attrs"
    :loading="loading"
    @change="change"
    @visible-change="handleVisible"
  >
    <el-option
      v-for="item in options"
      :key="item.id"
      :label="item.billNo"
      :value="item.idErp"
    >
      <el-row :gutter="20">
        <el-col :span="12">{{ item.idErp }}</el-col>
        <el-col :span="12" class="text-right">{{ item.billNo }}</el-col>
      </el-row>
    </el-option>
  </el-select>

</template>

<script>
import { getAllStockOutList } from '@/api/wms/inLibrary/periodicInventory'

export default {
  props: {
    value: {
      type: [String, Number],
      default: ''
    },
    inspectionType: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      options: [],
      loading: false
    }
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  // created() {
  //   this.fetchStockOutList()
  // },
  methods: {
    fetchStockOutList() {
      this.loading = true
      const params = {
        pageNo: 1,
        pageSize: 100
      }
      getAllStockOutList(params).then(res => {
        this.options = res.data || []
      }).finally(() => {
        this.loading = false
      })
    },
    change(value) {
      const item = this.options.find(item => item.idErp === value)
      this.$emit('change', item)
    },
    //
    handleVisible(visible) {
      if (visible) {
        this.fetchStockOutList()
      }
    }
  }
}
</script>

    <style>

    </style>

