<template>
	<view>
		<u-navbar title="关联子女"></u-navbar>
		<view class="content-2">
			<view class="search">
				<u-search v-model="queryName" placeholder="搜索学员姓名" action-text="查询" @custom="queryStudent"></u-search>
			</view>

			<view class="student-card" v-for="(item,index) in studentList" :key="index">
				<view class="details">
					<view class="photo">
						<u-avatar class="avatar" mode="square"
							:src="item.student.headPhoto != null ? item.student.headPhoto : '../../assets/img/head.png'" size="112">
						</u-avatar>
					</view>
					<view class="information">
						<view class="name">
							{{item.student.studentName}}
						</view>
						<view class="item">
							<view class="item-name">
								报读课程
							</view>
							<view class="item-content">
								<li v-for="c in item.buyLogMapList">{{c.courseName}}</li>
							</view>
						</view>
						<view class="item">
							<view class="item-name">
								班级名称
							</view>
							<view class="item-content">
								<li v-for="c in item.buyLogMapList">{{c.className}}</li>
							</view>
						</view>
						<view class="item">
							<view class="item-name">
								教师
							</view>
							<view class="item-content">
								<li v-for="c in item.buyLogMapList">{{c.teacherName}}</li>
							</view>
						</view>
					</view>
				</view>
				<view class="check-more" @click="getUpdateStudent(item.student)">
					<view class="call-name">
						关联子女
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import * as mineApi from '@/apis/parents/mine.js'
	import * as loginApi from '@/apis/login.js'

	export default {
		data() {
			return {
				queryName: '',
				studentList: [],
				form: {}
			}
		},
		onReady() {
			this.getParentsInfo();
		},
		methods: {
			getParentsInfo() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				loginApi.findByOpenId({
					openId: this.carhelp.getOpenId()
				}).then((response) => {
					uni.hideLoading();
					this.form = response.data.regUser;
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			queryStudent() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				mineApi.findByStudentName({
					studentName: this.queryName
				}).then((res) => {
					uni.hideLoading();
					this.studentList = res.data.studentList;
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			getUpdateStudent(student) {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				mineApi.updateStudent({
					studentId: student.studentId,
					studentName: student.studentName,
					gender: student.gender,
					birthday: student.birthday,
					headPhoto: student.headPhoto,
					firstContactName: this.form.nickName,
					firstContactPhone: this.form.phone
				}).then((response) => {
					uni.hideLoading();
					uni.showToast({
						title: '关联成功',
						icon: "none"
					})
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	li{
		list-style: none;
	}
	
	.check-more {
		display: flex;
		text-align: center;
		font-size: 16px;
		margin-top: 17px;
		border-top: 1px solid rgba(229, 231, 234, 1);
		line-height: 38px;
	
		.history {
			flex: 1;
			color: rgba(119, 119, 119, 1);
			border-right: 1px solid rgba(229, 231, 234, 1);
		}
	
		.call-name {
			flex: 1;
			color: rgba(13, 186, 199, 1);
	
		}
	}
	
	.u-tabs {
		position: fixed;
		top: 88rpx;
		left: 0;
		right: 0;
		z-index: 999;
	}

	.content-1 {
		margin-top: 80rpx;
	}

	.student-card {
		margin: 0rpx 32rpx 16rpx;
		padding: 2rpx 32rpx 16rpx 32rpx;
		background-color: #fff;
		border-radius: 12px;

		.title {
			display: flex;
			align-items: center;
			color: rgba(51, 51, 51, 1);
			font-weight: bold;

			img {
				vertical-align: middle;
				margin-right: 16rpx;
			}
		}

		.details {
			margin-top: 40rpx;
			display: flex;

			.photo {
				width: 160rpx;
				height: 120px;
				border-radius: 8px;
				margin-right: 32rpx;
				overflow: hidden;

				img {
					width: 100%;
					height: 100%;
				}
			}
		}

		.information {
			.name {
				color: rgba(51, 51, 51, 1);
				font-size: 36rpx;
				font-weight: bold;
				margin-bottom: 20rpx;
			}

			.item {
				display: flex;
				margin-bottom: 16rpx;
				justify-content: space-between;
				font-size: 28rpx;

				.item-name {
					width: 180rpx;
					color: rgba(119, 119, 119, 1);
				}

				.item-content {
					flex: 1;
					color: rgba(51, 51, 51, 1);
					margin-left: 16rpx;

				}

			}

		}
	}


	::v-deep.u-tab-item {
		color: #101010 !important;
	}

	::v-deep.u-cell_title {
		color: rgba(119, 119, 119, 1);
	}

	::v-deep.u-cell__value {
		color: #333333;
		flex: 0.45;
		margin-left: auto;
	}

	.search {
		// background-color: #fff;
		padding: 16rpx 24rpx;
		margin-top: 80rpx;
	}

	::v-deep.u-action {
		width: 17.1%;
		text-align: center;
		line-height: 56rpx;
		border-radius: 50px;
		background-color: rgba(13, 186, 199, 1);
		color: rgba(255, 255, 255, 1);
	}

	::v-deep.u-content {
		height: 56rpx !important;
		background-color: #fff !important;
	}

	::v-deep.u-input {
		background-color: #fff !important;
	}

	.student-details {
		padding: 24rpx 32rpx;
		background-color: #fff;
		display: flex;
		position: relative;
		border-bottom: 1px solid rgba(229, 231, 234, 1);
		;

		.photo {
			width: 112rpx;
			height: 112rpx;
			border-radius: 4px;
			overflow: hidden;
			margin-right: 22rpx;

			img {
				width: 100%;
				height: 100%;
			}
		}

		.details {
			display: flex;
			align-items: center;

			.name-tel {


				.name {
					margin-right: 12px;
					color: rgba(51, 51, 51, 1);
					font-size: 18px;
					margin-bottom: 16rpx;
				}

				.tel {
					color: rgba(119, 119, 119, 1);
					// line-height: 24px;
					display: flex;
					align-items: center;



				}

			}

		}

		.more {
			color: #333333;
			position: absolute;
			bottom: 65rpx;
			right: 24rpx;
		}
	}

	@media screen and (max-width:320px) {
		.student-card {
			padding: 2rpx 12rpx 0rpx 12rpx;
			margin: 32rpx 16rpx;
		}

		.item-name {
			width: 244rpx !important;
		}
	}

	::v-deep.uni-input-placeholder {
		font-size: 24rpx
	}

	.content-2 {
		margin-top: 90rpx;

		.search {
			position: fixed;
			left: 0rpx;
			right: 0rpx;
			top: 0rpx;
			z-index: 999;
			background-color: #F2F4F4;
		}

	}
</style>