<template>
	<div>
		<el-tree ref="tree" highlight-current :data="treeData" default-expand-all :props="defaultProps" node-key="id"   @node-click="handleNodeClick">
		  <span class="icon-tree" slot-scope="{ node, data }">
				<div v-if=" type === 'org' || type === 'student' || type === 'teacher' || type === 'org01'|| type === 'org02'">
					<div v-if="data.alias == 'top'">
						<i class="fa fa-university"></i>
						<span>&nbsp;{{node.label}}</span>
					</div>
					<div v-if="data.alias == 'JG001'">
						<i class="fa fa-building"></i>
						<span>&nbsp;{{node.label}}</span>
					</div>
						<div v-if="data.alias == 'JG002'">
						<i class="fa fa-building"></i>
						<span>&nbsp;{{node.label}}</span>
					</div>
						<div v-if="data.alias == 'JG003'">
						<i class="fa fa-building"></i>
						<span>&nbsp;{{node.label}}</span>
					</div>
					<div v-if="data.alias == 'user'">
						<i class="fa fa-users"></i>
						<span>&nbsp;{{node.label}}</span>
					</div>
				</div>
				<div v-else>
					 <div v-if="data.alias === 'top'">
					 	<i class="fa fa-university"></i>
					 	<span>&nbsp;{{node.label}}</span>
					 </div>
					 <div v-if="data.alias === 'fix02'">
					 	<i class="fa fa-building"></i>
					 	<span>&nbsp;{{node.label}}</span>
					 </div>
				</div>
		</span>
		</el-tree>
	</div>
</template>

<script>
	import {TreeNodeOrg,TreeNodeStu,TreeNodeEqu} from '../../api/sys/public'
	export default{
		props: {
			type: {
			  type: String,
			  default: ''
			}
		},
		data(){
			return{
				//orgId:'',
				treeData: [],
				defaultProps: {
				  children: 'children',
				  label: 'name'
				},
			}
		},
		methods:{
			  handleTreeNode () {
					if(this.type === 'student'){
						TreeNodeStu({depType:'JG002'}).then(res=>{
						  this.treeData = JSON.parse(res.msgDat)
							this.$emit('orgId', this.treeData[0].id)
						})
					}else if(this.type === 'org'){
						TreeNodeOrg({depType:''}).then(res=>{
						  this.treeData = JSON.parse(res.msgDat)
							this.$emit('orgId', this.treeData[0].id)
							//this.$parent.handList();
						})
					}else if(this.type === 'teacher'){
						TreeNodeStu({depType:'JG001'}).then(res=>{
						  this.treeData = JSON.parse(res.msgDat)
							this.$emit('orgId', this.treeData[0].id)
						})
					}else if(this.type === 'equ'){
						TreeNodeEqu().then(res=>{
						  this.treeData = JSON.parse(res.msgDat)
							console.log(this.treeData)
							//this.$emit('orgId', this.treeData[0].id)
						})
					}else if(this.type === 'org01'){
						TreeNodeOrg({depType:'JG002'}).then(res=>{
						  this.treeData = JSON.parse(res.msgDat)
							this.$emit('orgId', this.treeData[0].id)
							this.$emit('handleList')
						})
					}else if(this.type === 'org02'){
						TreeNodeOrg({depType:'JG001'}).then(res=>{
						  this.treeData = JSON.parse(res.msgDat)
							this.$emit('orgId', this.treeData[0].id)
							this.$emit('handleList')
						})
					}
			},
			handleNodeClick(data){
				this.$emit('action', data)
			}
		},
		 mounted () {
			this.handleTreeNode()
		}
	}
</script>

<style>
</style>
