<template>
  <el-select
    v-model="selected"
    class="size-select"
    placeholder="请选择"
    @change="select"
    :style="styles"
    :multiple="multiple"
    clearable
  >
    <el-option
      v-for="item in optionList"
      :key="item.id"
      :label="item.name"
      :value="item.id"
    >
      <span>{{ item.name }}</span>
    </el-option>
  </el-select>
</template>

<script>
import { searchUsers } from "@/api/system-user";
export default {
  name: "InvigilatorSelect",
  props: {
    value: [String, Array],
    multiple: Boolean,
    styles: { type: String },
  },
  data() {
    return {
      optionList: [],
      selected: null,
    };
  },
  async created() {
    const res = await searchUsers({ roleCode: "INVIGILATE", pageSize: 1000 });
    // console.log(res.data);
    this.optionList = res.data.data.records;
  },
  watch: {
    value: {
      immediate: true,
      handler(val) {
        this.selected = val;
      },
    },
  },
  methods: {
    select() {
      this.$emit("input", this.selected);
      this.$emit("change", this.selected);
    },
  },
};
</script>

<style></style>
