<template>
  <div>
    <el-select v-model="selectVal" style="width: 100%;" placeholder="请选择学年" :clearable="clearable" :filterable="filterable" @change="change">
      <el-option v-for="item in schoolYearList" :key="item.value" :label="item.label" :value="item.value" />
    </el-select>
  </div>
</template>

<script>
export default {
  name: 'SelectSchoolYear',
  props: {
    value: {
      type: String,
      default: ''
    },
    clearable: {
      type: Boolean,
      default: false
    },
    filterable: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      schoolYearList: []
    }
  },
  computed: {
    selectVal: {
      get() {
        return this.value
      },
      set(newValue) {
        this.$emit('input', newValue)
      }
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      const currYear = (new Date().getFullYear() + 1)
      for (let i = 5; i > 0; i--) {
        this.schoolYearList.push({
          value: String(currYear - i),
          label: String(currYear - i)
        })
      }
      this.schoolYearList.reverse()
    },
    change(newValue) {
      this.$emit('change', newValue)
    }
  }
}
</script>

<style scoped>
</style>
