<template>
  <el-select
    v-model="selected"
    @focus="fetchItems"
    :placeholder="placeholder"
    :filterable="filterable"
    :value-key="valueKey"
    :style="style"
    @change="onChange"
  >
    <el-option
      v-for="item in items"
      :key="item.bom_account_id"
      :label="item.zzkw_code"
      :value="item"
    >
      <span>{{ item.zzkw_code }}</span>
      <span>{{ item.item_code }}</span>
      <span>{{ item.gw_code }}</span>

    </el-option>

  </el-select>
</template>

<script>
import crudBomAccount from '@/api/bomAccount'

export default {
  name: 'BomAccountPointSelect',
  props: {
    value: null, // v-model
    placeholder: {
      type: String,
      default: '请选择制造库位'
    },
    filterable: {
      type: Boolean,
      default: true
    },
    valueKey: {
      type: String,
      default: 'id'
    },
    isEnabled:{
      type: Boolean,
      default: true
    },
    style: {
      type: String,
      default: 'width: 200px;'
    }
  },
  data() {
    return {
      items: [],
      selected: this.value
    }
  },
  watch: {
    value(val) {
      this.selected = val
    },
/*    selected(val) {
      this.$emit('input', val)
      this.$emit('change', val)
    }*/
  },
  methods: {
    fetchItems() {
      if (this.items.length === 0) {
        crudBomAccount.queryBomAccountPoints().then(res => {
          this.items = res
        })
      }
    },
    onChange(val) {
      console.log(1111)
      this.$emit('change', val)
    }
  }
}
</script>
