<template>
  <!-- 厂房 -->
  <el-select
    v-model="selectVal"
    filterable
    v-bind="$attrs"
    v-on="$listeners"
    clearable
  >
    <el-option
      v-for="item in dictList"
      :key="item.id"
      :label="item.name"
      :value="item.id"
      @click.native="returnName(item)"
    ></el-option>
  </el-select>
</template>

<script>
  import { getFactoryarea, factoryworkstation } from '@/api/factoryModel';
  export default {
    model: {
      prop: 'value',
      event: 'updateVal'
    },
    props: {
      value: {
        type: [String, Number, Array],
        default: ''
      },
      init: {
        type: Boolean,
        default: true
      },
      augr: {
        type: Number,
        default: 0
      }
    },
    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;
        }
      }
    },
    created() {
      if (this.init) {
        this.getList();
      }
    },
    methods: {
      returnName(item) {
        this.$emit('returnName', item.name);
        this.$emit('returnItem', item);
      },
      async getList() {
        let params = {
          pageNum: -1,
          size: -1,
          type: this.augr
        };
        if (this.augr == 0) {
          delete params.type;
          const res = await factoryworkstation(params);
          console.log('res-------', res);
          this.dictList = res.list;
          return;
        }
        const res = await getFactoryarea(params);
        this.dictList = res.list;
      }
    }
  };
</script>
