<template>
  <el-select
    v-model="selected"
    v-bind="$attrs"
    :loading="loading"
    @change="change"
  >
    <el-option
      v-for="item in options"
      :key="item.id"
      :label="item.name"
      :value="item.code"
    >
      <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 { getDepartmentList } from '@/api/wms/incoming/register'

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.fetchCustomerList()
  },
  methods: {
    fetchCustomerList() {
      this.loading = true
      const params = {
        pageNo: 1,
        pageSize: 100
      }
      getDepartmentList(params).then(res => {
        const { list = [] } = res.data || {}
        this.options = list
      }).finally(() => {
        this.loading = false
      })
    },
    change(value) {
      const item = this.options.find(item => item.code === value)
      this.$emit('change', item)
    }
  }
}
</script>

    <style>

    </style>

