<template>
    <el-select
      v-model="name"
      placeholder="请选择路线名称"
      @change="changed"
      :disabled="disabledCreated"
      clearable
      @clear="clear"
    >
      <el-option
        v-for='item in options'
        :label="item.name"
        :value="item.id"
      ></el-option>
    </el-select>
</template>
<script>
import basicData from '@/api/basicData.js'
export default {
  props: {
    value: String,
    disabledCreated: Boolean
  },
  data() {
    return {
      name: '',
      options: []
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      basicData.getRouterManagement().then(res => {
        this.options = res.rows
        // if (this.value) {
        //   this.name = this.value
        // } else {
        //   this.name = this.options[0].id
        // }   
        this.$emit('value', this.options[0])
      })
    },
    changed(val) {
      this.options.forEach(item => {
        if (item.id == val) {
          this.$emit('changed', item)
        }
      })
    },
    clear(){
      this.$emit('clear')
    }
  }
}
</script>
<style lang='scss' scoped>

</style>