<!-- 选择部门 -->

<template>
  <div>
    <el-input v-model="selected.name" :placeholder="$t('form.placeholderSelect')" readonly @click.native="showSelectDeptUser" />
    <!-- <el-input v-if="$i18n.locale === 'zh_CN'" v-model="selected.name" :placeholder="$t('form.placeholderSelect')" readonly @click.native="showSelectDeptUser" />
    <el-input v-else v-model="selected.nameEn" :placeholder="$t('form.placeholderSelect')" readonly @click.native="showSelectDeptUser" /> -->
    <SelectDeptUserDialog ref="selectDeptUserDialog" @change="handleChange" />
  </div>
</template>

<script>
import SelectDeptUserDialog from './SelectDeptUserDialog.vue'
export default {
  name: "SelectDeptUser",
  components: {SelectDeptUserDialog},
  props: {
    value: {
      type: [Number, String , Array],
      default: ''
    },
    name: {
      type: String,
      default: ''
    },
    nameEn: {
      type: String,
      default: ''
    },
    readOnly: {
      type: Boolean,
      default: false
    },
  },
  watch: {
    value: {
      immediate: true,
      handler(v) {
        this.selected.id = v ?((v+'').indexOf('u_')>-1? v:('u_'+v)):''
      }
    },
    name: {
      immediate: true,
      handler(v) {
        if(v&&v!=undefined&&v!=''){
          this.selected.name=v 
        }
      }
    },
    nameEn: {
      immediate: true,
      handler(v) {
        if(v&&v!=undefined&&v!=''){
          this.selected.nameEn=v 
        }
      }
    },
  },
  data() {
    return {
      selected:{
        id:'',
        name:'',
        nameEn:'',
      },
    };
  },
  mounted() {
  },
  methods: {
    showSelectDeptUser(){
      if(!this.readOnly){
        this.$refs.selectDeptUserDialog.show(this.selected.id,this.selected.name,this.selected.nameEn)
      }
    },
    handleChange(obj) {
      this.selected.name=obj.name 
      this.selected.nameEn=obj.nameEn 
      this.$emit('change', obj)
      this.$emit('input', obj.id)
    },
  }
};
</script>