<template>
	<div>
		<el-dialog v-model="dialogVisible" :close-on-click-modal="false" draggable width="300px" height="500px">
			<el-card :body-style="cardBodyStyle">
				<el-tree :data="dataTree" :props="defaultProps" node-key="id" :expand-on-click-node="false"
					highlight-current :default-expanded-keys="expandedKeys">
					<template #default="{ node, data }">
						<span class="custom-tree-node">
							<span>{{ node.label }}</span>
							<span>
								<a @click="handleConfirm(node, data)"> 选择 </a>
							</span>
						</span>
					</template>
				</el-tree>
			</el-card>
		</el-dialog>
	</div>
</template>

<script setup>
	import {
		ref,
		reactive,
		onBeforeMount,
		getCurrentInstance
	} from 'vue'

	const {
		proxy
	} = getCurrentInstance()

	import tools from '@/tools'
	const cardBodyStyle = ref(tools.style.card)
	const inputStyle = ref(tools.style.input)




	const defaultProps = ref({
		children: 'children',
		label: 'deptName'
	})
	// const data = ref({})
	// const node = ref({})
	const expandedKeys = ref([])
	const dataTree = ref([])
	const dialogVisible = ref(false)
	const getDataTree = () => {
		var url = 'framework/SysDepartment/queryTree'
		var param = {}
		proxy.$axios.get(url, param).then(response => {
			dataTree.value = response.data.data
			if (dataTree.value.length == 1) {
				for (var node of dataTree) {
					expandedKeys.value.push(node.id)
				}
			}
		})
	}
 
 
	const emit = defineEmits(['receiveFromChild'])
	const handleConfirm = (node, data) => { 
		emit('receiveFromChild', data,'啊');
		dialogVisible.value = false
	}


	const open = () => {
		getDataTree()
		dialogVisible.value = true
	}
	 const close = () => { 
	 	dialogVisible.value = false
	 }
	defineExpose({
		open,
		close
	})
</script>

<style>
	 
</style>