<template>
  <div>
    <el-select
      v-model="name"
      placeholder="请选择隧道名称"
      style="width:100%"
      @change="changed"
    >
      <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
  },
  data() {
    return {
      name: '',
      options: []
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      let data = {
        pageBean: {
          page: 1,
          pageSize: -1,
          showTotal: true,
        },
      }
      basicData.getTunnelManagement(data).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)
        }
      })
    }
  }
}
</script>
<style scoped>
</style>