<template>
  <el-select
    v-model="selectVal"
    filterable
    style="width: 100%"
    v-bind="$attrs"
    v-on="$listeners"
    clearable
  >
    <el-option
      v-for="item in dictList"
      :key="item.id"
      :label="item.name"
      :value="item.id"
    ></el-option>
  </el-select>
</template>

<script>
  import { listFactoryLineByParentId } from '@/api/factoryModel';
  export default {
    model: {
      prop: 'value',
      event: 'updateVal'
    },
    props: {
      value: {
        type: [String, Number, Array],
        default: ''
      },
      workshopId: {
        type: [String, Number],
        default: ''
      }
    },
    data () {
      return {
        dictList: []
      };
    },
    computed: {
      selectVal: {
        set (val) {
          this.$emit('updateVal', val);
          this.$emit(
            'selfChange',
            val,
            this.dictList.find((i) => i.id === val)
          );
        },
        get () {
          return this.value;
        }
      }
    },
    methods: {
      async getList () {
        const res = await listFactoryLineByParentId(this.workshopId);
        this.dictList = res;
      }
    }
  };
</script>
