<template>
  <div>
    <el-select
      v-model="id"
      placeholder="请选择路段名称"
      style="width: 100%"
      @change="changed"
      :disabled="disabled"
    >
      <el-option
        v-for="item in options"
        :label="item.name"
        :value="item.id"
      ></el-option>
    </el-select>
  </div>
</template>
<script>
import basicData from '@/api/basicData.js'
export default {
  props: {
    value: String,
    disabled: Boolean
  },
  data() {
    return {
      name: '',
      options: [],
      id:''
    }
  },
  created() {
    this.getInfo()
  },
  // watch: {
  //   value: function (oldValue, newValue) {
  //     this.$emit('value', {name: newValue, id: ''})
  //   }
  // },
  methods: {
    getInfo() {
      basicData.getRoadManagement().then((res) => {
        console.log(res)
        this.options = res.rows
        if (this.value) {
          this.id = this.value
        } else {
          console.log(this.options)
          this.id = this.options[0].id
        }
        this.$emit('value', this.options[0])
      })
    },
    changed(val) {
      this.options.forEach((item) => {
        if (item.id == val) {
          this.$emit('changed', item)
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
/deep/.el-select-dropdown__item.selected {
  color: #fff !important;
}
/deep/.el-select-dropdown__item.hover,
.el-select-dropdown__item:hover {
  color: #fff !important;
}
</style>