<template>
	<view>
		<!-- 头部信息 -->
		<view class="home-topinfo">
			<image class="children-avatar" :src="childreninfo.avatar" @click="showChildrenList"></image>
			<view class="children-name">
				<text class="name">{{childreninfo.name}}</text>
				<view class="detail-box">
					<text class="detail" @click="select = true">{{semester}}</text>
					<!-- 选择学期 -->
					<view class="select-box">
						<u-picker class="picker" :show="select" :closeOnClickOverlay="true" :columns="semesterList" ref="uPicker" @confirm="selectSemester" @cancel="selectCancel"></u-picker>
						<view class="t-icon t-icon-youjiantou" @click="select = true"></view>
					</view>
				</view>
			</view>
		</view>
		<!-- 切换孩子 -->
		<view class="list-box" v-show="show">
			<view class="children-item" v-for="(item,index) in parentdetail.childrenList" :key="index" @click="switchChildren(item)">
				<view class="item-box">
					<image class="item-avatar" :src="item.avatar"></image>
					<text class="item-text">{{item.name}}</text>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	
	export default {
		name: "top-box",
		data() {
			return {
				
				show: false,
				
				select: false,
				semesterList:[
					['19学年上学期','19学年下学期','20学年上学期','20学年下学期']
				],
				
			};
		},
		computed: {
			...mapState('m_children', ['childreninfo','semester']),
			...mapState('m_parent',['parentdetail'])
		},
		methods: {
			...mapMutations('m_children',['updateChildrenInfo','updateChildrenSemester']),
			
			//学期选择
			selectSemester(e){
				console.log('selectSemester',e)
				uni.$showMsg('切换完成')
				this.updateChildrenSemester(e.value[0])
				this.select = false
			},
			//取消选择
			selectCancel(){
				uni.$showMsg('取消选择')
				this.select = false
			},
			
			//头部孩子选择
			showChildrenList(e){
				console.log('chooseChildren' + e)
				this.show = !this.show
			},
			switchChildren(item){
				console.log(item);
				this.updateChildrenInfo(item)
				this.show = false
			}
		}
	}
</script>

<style lang="scss">
	.home-topinfo {
		height: 400rpx;
		background: linear-gradient(#0080ff, #f1f3f5);
		display: flex;
		justify-content: flex-start;
		align-items: center;

		.children-avatar {
			margin-top: 22rpx;
			margin-left: 40rpx;
			width: 96rpx;
			height: 96rpx;
			border-radius: 50rpx;
			border: 4rpx solid #FFFFFF;
			box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.2);

		}

		.children-name {
			margin-top: 44rpx;
			margin-left: 20rpx;
			display: flex;
			flex-direction: column;

			.name {
				color: #3B4144;
				font-size: 32rpx;
				margin: 4rpx 0 0 10rpx;
				font-weight: bold;
			}
			.detail-box{
				display: flex;

				.detail {
					color: #2197ef;
					font-weight: bold;
					font-size: 28rpx;
					margin: 10rpx 0rpx 0 10rpx;
				}
				.select-box{
					margin: 10rpx;
				}
			}
		}
	}
	.list-box{
		margin: -120rpx 40rpx 120rpx 30rpx;
		display: flex;
		flex-wrap: wrap;
		.children-item{
			margin: 0 10rpx 0 10rpx;
			.item-box{
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				.item-avatar{
					width: 90rpx;
					height: 90rpx;
					border-radius: 50rpx;
					border: 4rpx solid #FFFFFF;
				}
				.item-text{
					font-size: 24rpx;
					font-weight: bold;
					color: #6b778d;
				}
			}
		}
	}
	.t-icon{
			width: 40rpx;
			height: 40rpx;
		}
	.picker{
		z-index: 99;
	}
</style>
