<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.userId"
      :label="item.nickName"
      :value="item.userId"
    />
  </el-select>
</template>

<script>
import { listAllUser } from "@/api/system/user";

export default {
  name: "UserSelect",
  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() {
      listAllUser().then(response => {
        this.list = response.data;
      });
    },
  }
};
</script>