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

<script>
const PREDEFINE_OPTIONS = [
  {
    value: "14px",
    label: "小（5号）"
  },
  {
    value: "18.7px",
    label: "中（4号）"
  },
  {
    value: "21.3px",
    label: "大（3号）"
  },
  {
    value: "29.3px",
    label: "特大（2号）"
  },
  {
    value: "34.7px",
    label: "超大（1号）"
  }
];

export default {
  name: "size-select",
  props: {
    value: String,
    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>
