<template>
  <el-select
    v-model="selected"
    class="size-select"
    placeholder="考试状态"
    @change="select"
    :style="styles"
    clearable
  >
    <el-option
      v-for="item in optionList"
      :key="item.code"
      :label="item.name"
      :value="item.code"
    >
      <span>{{ item.name }}</span>
    </el-option>
  </el-select>
</template>

<script>
export default {
  name: "StateSelect",
  props: {
    value: {
      type: Number,
      default: 1,
    },
    options: { type: Array, default: () => null },
    styles: { type: String },
  },
  data() {
    return {
      optionList: this.options || [
        { code: 0, name: "禁用" },
        { code: 1, name: "启用" },
      ],
      selected: "",
    };
  },
  async created() {},
  watch: {
    value: {
      immediate: true,
      handler(val) {
        this.selected = val;
      },
    },
  },
  methods: {
    select() {
      this.$emit("input", this.selected);
      this.$emit("change", this.selected);
    },
  },
};
</script>

<style></style>
