<template>
	<view>
		<view class="section" v-for="(item,index) in list" :key="index">
			<view class="box">
				<view class="item">
					<view class="left">
						<view class="icon" v-if="active == index" @click.stop="change_active(index,item.id)">
							<image src="./icon/close.png" mode=""></image>
						</view>
						<view class="icon" v-if="active != index" @click.stop="change_active(index,item.id)">
							<image src="./icon/open.png" mode=""></image>
						</view>
						<view class="text">{{item.title}} （{{item.user_num}}）</view>
					</view>
					<view class="right">
						<uni-icons type="eye"></uni-icons>
					</view>
				</view>
				<view class="list" v-if="active == index">
					<view class="item" v-for="(item_2,index_2) in user_list" :key="index_2">
						<view class="icon">{{item_2.name.charAt(0)}}</view>
						<view class="text">{{item_2.name}} {{item_2.position_name}}</view>
					</view>
				</view>
			</view>
			
			<view class="inner">
				<origanizationTree :list="list.child"></origanizationTree>
			</view>
		</view>
	</view>
</template>

<script>
	import origanizationTree from "@/components/origanizationTree/origanizationTree.vue"

	export default {
		name: "origanizationTree",
		components: {
			origanizationTree
		},
		props: [
			// 部门列表
			"list"
		],
		data() {
			return {
				active: 99999999,
				
				// 人员列表
				user_list:[]
			};
		},
		methods: {
			change_active(index,id) {
				this.user_list = []
				if (this.active == index) {
					this.active = 99999999
				} else {
					this.active = index
					this.get_user_list(id)
				}
			},
			// 获取当前部门人员
			get_user_list(id){
				this.$api.user_list({
					id:id
				}).then((res)=>{
					console.log(res)
					this.user_list = res.data.data
				})
			}
		}
	}
</script>

<style lang="scss">
	.section{
		box-sizing: border-box;
		padding: 0 20rpx;
		
		.box{
			
			.item{
				height: 95rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				
				margin-left: 20rpx;
				border-bottom: 1rpx solid #F3F8F7;
				
				.left{
					display: flex;
					align-items: center;
					.icon{
						line-height: 95rpx;
						width: 90rpx;
						text-align: center;
						image{
							width: 24rpx;
							height: 24rpx;
						}
					}
					.text{
						font-size: 28rpx;
					}
				}
				.right{
					line-height: 95rpx;
					width: 90rpx;
					text-align: center;
				}
			}
			
			.list{
				.item{
					height: 95rpx;
					
					display: flex;
					justify-content: left;
					align-items: center;
					
					margin-left: 108rpx;
					border-bottom: 1rpx solid #F3F8F7;
					.icon{
						width: 35rpx;
						text-align: center;
						line-height: 35rpx;
						border-radius: 50%;
						border: 1rpx solid #00A1E9;
						
						font-size: 24rpx;
						color: #00A1E9;
					}
					.text{
						margin-left: 18rpx;
						font-size: 28rpx;
						
					}
				}
			}
		
		}
		
		.inner{
			
		}
		
	}
</style>
