<template>
  <el-select 
    v-model="selectValue" 
    :placeholder="placeholder"
    clearable
    filterable
    :disabled="disabled"
    :multiple="multiple"
    v-on="$listeners"
    style="width: 100%;"
  >
    <el-option
      v-for="item in list"
      :key="item.id"
      :label="item.name"
      :value="item.id"
    />
  </el-select>
</template>

<script>
import { listAllProject } from "@/api/bst/project";

export default {
  name: "ProjectSelect",
  props: {
    value: {
      type: [String, Array],
      default: null
    },
    placeholder: {
      type: String,
      default: "请选择项目"
    },
    disabled: {
      type: Boolean,
      default: false
    },
    multiple: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      list: [],
    };
  },
  computed: {
    selectValue: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      listAllProject().then(response => {
        this.list = response.data;
      });
    },
  }
};
</script>