<!--
@ 作者: 秦东
@ 时间: 2023-07-20 13:49:22
@ 备注: 
-->
<script lang='ts' setup>
import { computed, onMounted, nextTick } from 'vue'
import { criteriaForPeopleList } from '@/api/hr/org/type'
const props = withDefaults(
    defineProps<{
		modelValue?: string
		disabled?: boolean
    }>(),
    {}
)
const emits = defineEmits<{
    (e: 'update:modelValue', value: string): void
}>()
const userDialogEl = ref()
// const value:any = computed({
//     get() {
//       	return props.modelValue
//     },
//     set(newVal: string) {
//       	emits('update:modelValue', newVal)
//     }
// })
const userlist = ref("")
const value = computed({
	get: () => props.modelValue,
	set: (newVal: any) => {
		// console.log("value-set",newVal)
		emits('update:modelValue', newVal)
		let newValJson:criteriaForPeopleList[] = JSON.parse(newVal)
		// console.log("value-newValJson",newValJson)
		if(newValJson.length > 0){
			let userAry = new Array
			newValJson.forEach(item =>{
				userAry.push(item.name+"("+item.number+")")
			})
			userlist.value = userAry.join(',')
		}
		
	},
});

const openDialog = () => {
    userDialogEl.value.open()
}
onMounted(() => {
    nextTick(() => {})
})

</script>
<template>
	<el-input
		placeholder="请选择用户或输入用户名称"
		v-bind="$props"
		v-model="userlist"
		@click="openDialog"
	>
		<template #append>
			<i class="icon-user" @click.stop="openDialog"></i>
		</template>
  	</el-input>
  	<user-dialog ref="userDialogEl" v-model="value" />
</template>
<style  lang='scss' scoped>

</style>
