<template>
	<view>
		<!-- 头部信息 -->
		<view class="home-topinfo">
			<!-- 更新时间戳 -->
			<view class="refresh-time"
				:style="'top:'+ capsuleBottom + 'px;left:'+ capsuleMiddle + 'px;'+'width:'+capsuleWidth+ 'px'">
				<!-- 订阅版本 -->
				<text class="time-text">更新于: {{timeStamp}}</text>
				<button class="estate" :style="{backgroundImage:`url(${backgroundImage})`}">{{myData.subscribeLevel}}</button>
				
			</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="setSemesterPicker = true">{{semester}}</text>
					<!-- 选择学期 -->
					<view class="select-icon">
						<u-icon name="arrow-down" color="#FFF" @click="setSemesterPicker = true"></u-icon>
					</view>
				</view>
			</view>
		</view>

		<u-picker class="picker" :show="setSemesterPicker" :closeOnClickOverlay="true" :columns="semesterList"
			ref="uPicker" @confirm="pickerConfirm" @cancel="pickerCancel" :immediateChange="true"></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,
				setSemesterPicker: false,
				//胶囊坐标
				capsuleBottom: 0,
				capsuleMiddle: 0,
				capsuleWidth: 0,
				//订阅背景图片
				backgroundImage: 'https://tse1-mm.cn.bing.net/th/id/OIP-C.Vg_hgwLC0hRD46zTHmCD8wHaHr?pid=ImgDet&rs=1',
			};
		},
		computed: {
			...mapState('m_children', ['childreninfo', 'semester', 'semesterList']),
			...mapState('m_parent', ['parentdetail', 'myData'])
		},
		methods: {
			...mapMutations('m_children', ['updateChildrenInfo', 'updateChildrenSemester']),
			//学期选择
			pickerConfirm(e) {
				//拼接图表数据
				this.updateChildrenSemester(e.value[0])
				uni.$showMsg('切换完成', 1000)
				this.setSemesterPicker = false
			},
			//取消选择
			pickerCancel() {
				uni.$showMsg('取消选择', 1000)
				this.setSemesterPicker = 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: 600rpx;
		background: linear-gradient($color-blue, $page-background-color);
	}

	.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: 7rpx 0 0 10rpx;
				width: 30rpx;
				height: 30rpx;
			}
		}
	}

	.refresh-time {
		height: auto;
		position: relative;
		display: flex;
		flex-direction: column;

		.time-text {
			margin: 0 auto;
			font-size: 24rpx;
			color: #FFFFFF;
			font-weight: bold;
		}

		.estate {
			margin: 5rpx auto;
			font-size: 22rpx;
			line-height: 40rpx;
			height: 40rpx;
			width: 100%;
			color: #FFFFFF;
			font-weight: bold;
			border-radius: 20rpx;
			border: none;
			background-size: cover;
			background-repeat: no-repeat;
		}
	}

	.list-box {
		margin: -100rpx 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;
	}
</style>
