<template>
  <el-select filterable :value="company === 0 ? undefined : company" @change="change" v-bind="$attrs" clearable>
    <el-option v-for="user in getUser" :key="user.id" :value="user.id" :label="$l(user, 'company')"></el-option>
  </el-select>
</template>

<script>
/**
 * 用户
 */
export default {
  name: "userSelect",
  inheritAttrs: false,
  props: {
    value: Number | Array,
    allUsers: Array,
  },
  model: {
    prop: "value",
    event: "change",
  },
  data() {
    return {};
  },
  computed: {
    getUser() {
      this.allUsers.forEach(element => {
        if(!element.companyEn) {
          element.companyEn = element.companyZh
        }
      });
      return this.allUsers;
    },
    company: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit("change", val);
      }
    }
  },
  created() {
      this.company = this.value
      let com = this.getUser.findIndex(item=>item.id==this.company)
      if(com == -1){
        this.company = 0
      }
  },
  methods: {
    change(val) {
      this.$emit("change", val);
    },
  },
};
</script>
