<template>
	<view>
		<!-- 头部信息 -->
		<view class="home-topinfo">
			<!-- 更新时间戳 -->
			<view class="refresh-time" :style="'top:'+ capsuleBottom + 'px;left:'+ capsuleMiddle + 'px;'  ">
				<text class="time-text">更新于: {{timeStamp}}</text>
			</view>
		</view>
		<view style="display: flex;margin-top: -450rpx;
    margin-bottom: 120rpx;">
			<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-icon">
						<view class="t-icon t-icon-youjiantou" @click="select = true"></view>
					</view>
				</view>
			</view>
		</view>

		<u-picker class="picker" :show="select" :closeOnClickOverlay="true" :columns="semesterList" ref="uPicker"
			@confirm="selectSemester" @cancel="selectCancel"></u-picker>
		
		<!-- 切换孩子 -->
		<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",
		props: {
			timeStamp: {
				type: String,
				default: false
			}
		},
		created() {
			this.getCapsuleSite()
		},
		data() {
			return {
				show: false,
				select: false,
				//下边界坐标
				capsuleBottom: 0,
				capsuleMiddle: 0
			};
		},
		computed: {
			...mapState('m_children', ['childreninfo', 'semester', 'semesterList']),
			...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
			},
			//获取胶囊位置信息
			getCapsuleSite(){
				let res=uni.getMenuButtonBoundingClientRect()
				this.capsuleBottom = res.bottom + 5
				this.capsuleMiddle = res.left
			}

		}
	}
</script>

<style lang="scss">
	.home-topinfo {
		height: 600rpx;
		background: linear-gradient(#0080ff, #f1f3f5);
	}

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

	.children-name {
		margin-left: 25rpx;
		padding-top: 5rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;

		.name {
			color: #3B4144;
			font-size: 36rpx;
			font-weight: bold;
		}

		.detail-box {
			display: flex;

			.detail {
				color: #FFFFFF;
				font-weight: bold;
				font-size: 30rpx;
			}

			.select-icon {
				margin:2rpx 0 0 10rpx;
				width: 30rpx;
				height: 30rpx;
			}
		}
	}
	.refresh-time {
		position: relative;
	
		.time-text {
			padding: 10rpx;
			font-size: 24rpx;
			color: #FFFFFF;
			font-weight: bold;
		}
	}

	

	.list-box {
		margin: -130rpx 40rpx 120rpx 33rpx;
		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>
