<template>
	<view>
		<statusBar :item="navBarData"></statusBar>

		<view class="editBox">
			<view class="edit_avatar">
				<view class="edit_title">
					<span>头像</span>
				</view>
				<view class="userAvatar">
					<image src="../../static/mine/Rectangle 1547.png" mode="aspectFill"></image>
				</view>
			</view>
			<view class="setName">
				<view class="edit_title">
					<span>昵称</span>
				</view>
				<view class="input_details">
					<view class="nickname">
						<input type="text" maxlength="10" placeholder="请输入一个昵称"
							placeholder-style="font-size: 28rpx; color: rgb(153, 153, 153);" v-model="nickname" />
					</view>
				</view>
			</view>
			<view class="setPicker">
				<picker mode="selector" :range="genderList" @change="handelGender">
					<view class="content">
						<view class="edit_title">
							<span>性别</span>
						</view>
						<view class="input_details">
							<view class="details">
								<view class="uni-input text">{{gender}}</view>
							</view>
							<view class="arrow">
								<image src="../../static/mine/arrow-right_gray.png" mode="aspectFill"></image>
							</view>
						</view>
					</view>
				</picker>
			</view>
			<view class="setPicker">
				<picker mode="selector" :range="schoolList" @change="handelSchool">
					<view class="content">
						<view class="edit_title">
							<span>学校</span>
						</view>
						<view class="input_details">
							<view class="details">
								<view class="uni-input text">{{school}}</view>
							</view>
							<view class="arrow">
								<image src="../../static/mine/arrow-right_gray.png" mode="aspectFill"></image>
							</view>
						</view>
					</view>
				</picker>
			</view>
			<view class="setPicker">
				<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
					<view class="content">
						<view class="edit_title">
							<span>生日</span>
						</view>
						<view class="input_details">
							<view class="details">
								<view class="uni-input text">{{date}}</view>
							</view>
							<view class="arrow">
								<image src="../../static/mine/arrow-right_gray.png" mode="aspectFill"></image>
							</view>
						</view>
					</view>
				</picker>
			</view>
			<view class="setPicker">
				<picker mode="selector" :range="hobbyList" @change="handelHobby">
					<view class="content">
						<view class="edit_title">
							<span>兴趣标签</span>
						</view>
						<view class="input_details">
							<view class="details">
								<view class="uni-input text">{{hobby}}</view>
							</view>
							<view class="arrow">
								<image src="../../static/mine/arrow-right_gray.png" mode="aspectFill"></image>
							</view>
						</view>
					</view>
				</picker>
			</view>
			<view class="setIntro">
				<view class="edit_title">
					<span>简介</span>
				</view>
				<view class="input_details">
					<view class="selfdomIntro">
						<textarea type="text" placeholder="请输入你的个性签名" maxlength="75"
							placeholder-style="font-size: 28rpx; color: rgb(153, 153, 153);" v-model="selfdomintro" />
					</view>
				</view>
			</view>
		</view>
		<view class="btnBox">
			<view class="btn">
				<button>保存修改</button>
				<button @click="gotoLogin">退出登录</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				navBarData: {
					title: '个人资料',
					btn: 1
				},
				nickname: '',
				selfdomintro: '',

				genderList: ['男', '女'],
				gender: '男',

				schoolList: ['xx学院', 'xx学院', 'xx学院'],
				school: 'xx学院',

				date: currentDate,

				hobbyList: ['篮球'],
				hobby: '篮球'
			};
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		methods: {
			handelGender(e) {
				this.gender = this.genderList[e.detail.value]
			},
			handelSchool(e) {
				this.school = this.schoolList[e.detail.value]
			},
			handeHobby(e) {
				this.hobby = this.hobbyList[e.detail.value]
			},
			bindDateChange: function(e) {
				this.date = e.detail.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			gotoLogin(){
				uni.navigateTo({
					url:'/pages/login/login'
				})
			},
		}
	}
</script>

<style lang="scss">
	.edit_title {
		display: flex;
		align-items: center;
		font-size: 32rpx;
	}

	.editBox {
		width: 100%;
		height: 840rpx;
		display: flex;
		flex-direction: column;
		background-color: #fff;
		border-top: 1px solid #E7E7E7;
		padding: 0 18px;

		.edit_avatar {
			height: 164rpx;
			display: flex;
			justify-content: space-between;

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

				image {
					width: 120rpx;
					height: 120rpx;
				}
			}
		}

		.setName {
			display: flex;
			justify-content: space-between;
			height: 92rpx;
			border-top: 1px solid #E7E7E7;

			.input_details {
				display: flex;
				align-items: center;
				flex-direction: row;

				.nickname {
					width: 100px;
					text-align: end;
					font-size: 28rpx;
					color: rgb(153, 153, 153);
				}
			}
		}

		.setPicker {
			height: 92rpx;
			border-top: 1px solid #E7E7E7;

			.content {
				height: 92rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

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

					.details {
						display: flex;
						flex-direction: row;

						.text {
							font-size: 28rpx;
							color: rgb(153, 153, 153);
						}
					}

					.arrow {
						display: flex;

						image {
							width: 32rpx;
							height: 32rpx;
						}
					}
				}
			}
		}
		.setIntro {
			display: flex;
			flex-direction: column;
			justify-content: space-evenly;
			height: 216rpx;
			border-top: 1px solid #E7E7E7;
		
			.input_details {
				display: flex;
				align-items: center;
		
				.selfdomIntro {
					width: 100%;
					height: 88rpx;
					
					textarea{
						width: 100%;
						height: 88rpx;
						font-size: 28rpx;
						color: rgb(153, 153, 153);
					}
				}
			}
		}
	}
	.btnBox{
		position: absolute;
		margin: 0 85rpx;
		bottom: 40px;
		.btn{
			button{
				width: 580rpx;
				height: 88rpx;
				border: none;
				border-radius: 100rpx;
				border: 1px solid lightgray;
				font-size: 36rpx;
				color: #545454;
				text-align: center;
				&:first-child{
					background-color: rgb(0, 86, 168);
					color: white;
					margin-bottom: 24rpx;
				}
				&::after{
					border: none;
				}
			}
		}
	}
</style>