<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"
      :value="item.id"
      :label="item.name"
    ></el-option>
  </el-select>
</template>

<script>
  import producetask from '@/api/technology/production';
  export default {
    model: {
      prop: 'value',
      event: 'updateVal'
    },
    props: {
      value: {
        type: [String, Number, Array],
        default: ''
      },
      init: {
        type: Boolean,
        default: true
      }
    },
    data () {
      return {
        dictList: []
      };
    },
    computed: {
      selectVal: {
        set (val) {
          this.$emit(
            'selfChange',
            val,
            this.dictList.find((i) => i.id === val)
          );
          this.$emit('updateVal', val);
        },
        get () {
          return this.value;
        }
      }
    },
    created () {
      if (this.init) {
        this.getList();
      }
    },
    methods: {
      async getList () {
        const res = await producetask.list({
          pageNum: 1,
          size: -1
        });
        this.dictList = res.list;
      }
    }
  };
</script>
