<template>
  <el-select v-model="corpSelected" clearable filterable>
    <el-option v-for="staff in corpList" :key="staff.id" :label="staff.corpName" :value="staff.id"/>
  </el-select>
</template>

<script>

import {getCompanyList} from "@/api/base/company";

export default {
  name: "",
  props:{
    value:{
      type: Object,
      default: null
    }
  },
  data() {
    return {
      corpSelected: undefined,
      corpList: null
    }
  },
  watch:{
    corpSelected(val) {
      const company = this.corpList.find(item => item.id === val);
      this.$emit("input", company);
    },
    value(val){
      if (val){
        this.corpSelected = val.id
      }else {
        this.corpSelected = null
      }
    }
  },
  mounted() {
    this.listCompany()
  },
  methods: {
    async listCompany(){
      const res = await getCompanyList();
      this.corpList = res.data
    }
  }
}
</script>

<style scoped lang="scss">

</style>
