<template>
  <el-select
    class="rotation-select"
    v-model="selected"
    placeholder="请选择"
    @change="select"
  >
    <el-option
      v-for="item in optionList"
      :key="item"
      :label="item"
      :value="item"
    >
    </el-option>
  </el-select>
</template>

<script>
const PREDEFINE_OPTIONS = [0, 90, 180, 270];

export default {
  name: "rotation-select",
  props: {
    value: Number,
    predefine: Array,
  },
  data() {
    return {
      optionList: [],
      selected: "",
    };
  },
  watch: {
    value: {
      immediate: true,
      handler(val) {
        this.selected = val;
      },
    },
  },
  created() {
    this.optionList =
      this.predefine && this.predefine.length
        ? this.predefine
        : PREDEFINE_OPTIONS;
  },
  methods: {
    select() {
      this.$emit("input", this.selected);
      this.$emit("change", this.selected);
    },
  },
};
</script>
