<template>
  <el-select
    v-model="selected"
    v-bind="$attrs"
    :loading="loading"
    v-on="$listeners"
    @change="change"
  >
    <el-option
      v-for="item in representations"
      :key="item.id"
      :label="item.label"
      :value="item.value"
    />
  </el-select>

</template>

<script>
import { getFactoryPage } from '@/api/wms/base/stock'

export default {
  props: {
    value: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      options: [],
      loading: false,
      representations: [
        {
          value: 'equal',
          label: '等于'
        },
        {
          value: 'contain',
          label: '包含'
        },
        {
          value: 'likely',
          label: '类似于'
        }
      ]
    }
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  created() {
    this.fetchFactoryList()
  },
  methods: {
    async fetchFactoryList() {
      this.loading = true
      const params = {
        pageNo: 1,
        pageSize: 100
      }
      await getFactoryPage(params).then(res => {
        this.options = res.data.list
        this.$emit('getOptions', this.options)
      }).finally(() => {
        this.loading = false
      })
    },
    change(v) {
      this.$emit('change', v)
    }
  }
}
</script>

  <style>

  </style>

