<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.areaCode"
      :value="item.id"
    />
  </el-select>

</template>

<script>
import { getStockAreaPage } from '@/api/wms/base/stockArea'

export default {
  props: {
    value: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      options: [],
      loading: false
    }
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  methods: {
    fetchAreaList(wmsStockId) {
      this.loading = true
      const params = {
        pageNo: 1,
        pageSize: 100,
        wmsStockId
      }
      getStockAreaPage(params).then(res => {
        const { list = [] } = res.data || {}
        this.options = list
      }).finally(() => {
        this.loading = false
      })
    },
    change(v) {
      const item = this.options.find(i => i.id === v)
      this.$emit('change', item)
    }
  }
}
</script>

  <style>
  </style>

