<template>
  <div>
    <el-select
      v-model="name"
      placeholder="请选择"
      style="width:100%"
      @change="changed"
    >
      <el-option
        v-for='item in options'
        :label="item.fullname"
        :value="item.fullname"
      ></el-option>
    </el-select>
  </div>
</template>
<script>
import basicData from '@/api/basicData.js'
export default {
  props: {
    valueInfo: String, //公司路径id
    editValue: String //修改传值
  },
  data() {
    return {
      name: '',
      options: [],
      value: this.valueInfo,
      editval: this.editValue
    }
  },
  created() {
    this.getInfo()
  },
  //监听value的变化,实时更新值
  watch: {
    valueInfo(val) {
      this.value = val
      this.getInfo()
    },
    editValue(val) {
      this.editval = val
    }
  },
  methods: {
    getInfo() {
      // console.log(this.value, 'dddddddddddddd')
      if (this.value) {
        const params = {
          path: this.valueInfo,
          querys: [
            {
              group: 'main',
              operation: 'RIGHT_LIKE',
              property: 'path_',
              relation: 'AND',
              value: this.valueInfo
            }
          ]
        }
        this.$http
          .post('${uc}/api/user/v1/users/queryByType', params)
          .then(rep => {
            let res = rep.data.rows
            this.options = res
            //默认赋值第一条数据,判断是否是修改传值
            // console.log(this.editval)
            if (this.editval) {
              this.name = this.editval
              if (this.options[0]) {
                this.name = this.options[0].fullname
                this.$emit('defaultValue', this.name)
              } else {
                this.name = ''
              }
            } else {
              if (this.options[0]) {
                this.name = this.options[0].fullname
                this.$emit('defaultValue', this.name)
              } else {
                this.name = ''
              }
            }
          })
      }
    },
    changed(val) {
      this.$emit('changed', val)
    }
  }
}
</script>
<style scoped>
</style>