<template>
  <div>
    <el-select
      v-model="id"
      placeholder="请选择项目名称"
      style="width: 100%"
      @change="changed"
    >
      <el-option
        v-for="item in options"
        :label="item.projectName"
        :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: [],
      id: '',
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      basicData.getProjectManagementData().then((res) => {
        this.options = res.rows
        if (this.value) {
          this.id = this.value
        } else {
          this.id = this.options[0].id
        }
        this.$emit('valueProject', this.options[0])
      })
    },
    changed(val) {
      this.options.forEach((item) => {
        if (item.id == val) {
          this.$emit('changedProject', item)
        }
      })
    },
  },
}
</script>
<style scoped>
</style>