<template>
	<view class="container">
		<view class="navigation-bar">有氧运动心率</view>
		<view class="back" @click="onBack(0, $event)">
			<image src="/static/backArrow.png" mode="aspectFit" style="width:100%"></image>
		</view>
		
		<view class="content">
			<text class="result-area">{{result}}</text>
			<button class="help" @click="onHelp(0, $event)">宁哥笔记</button>
			
			<view class="input-area">
				<view class="age">
					<view class="input-title">年龄 : </view>
					<input  class="input" type="number"  placeholder="请输入年龄" v-model="age" />
				</view>
				
				<view class="static-heart-rate">
					<view class="input-block">
						<view class="input-title">静态心率 : </view>
						<input class="input" type="number"  placeholder="请输入静态心率" v-model="heartRate" />
						<button class="heart-rate-help" @click="onClickHelp(0, $event)">?</button>
					</view>
					
				</view>
			</view>
			
			<button class="confirm" @click="onClick(0, $event)">确定</button>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				age:-1,
				heartRate:-1,
				result:'',
			}
		},
		onLoad() {
			this.heartRate = 0;
			this.age = 0;
			
			// console.log('heartRate=',getApp().globalData.heartRate);
			// console.log('age=',getApp().globalData.age);
			
			if(getApp().globalData.heartRate != undefined)
			{
				this.heartRate = getApp().globalData.heartRate;
			}
			
			if(getApp().globalData.age != undefined)
			{
				this.age = getApp().globalData.age;
			}
		},
		methods: {
			onBack: function(id,e) {
				//uni.navigateBack()//默认delta:1
				uni.navigateBack({
					delta:1,//返回层数，2则上上页
				})
			},
			onHelp: function(id,e) {
				uni.navigateTo({
					url: '/pages/heartRhythms/help',
					animationType: 'slide-in-left',
					animationDuration: 2000,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			onClickHelp: function(id,e) {
				uni.navigateTo({
					url: '/pages/heartRhythms/staticHeartRateHelp',
					animationType: 'slide-in-left',
					animationDuration: 2000,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			onClick: function(id,e) {
				
				if(this.heartRate != -1 && this.age != -1)
				{
					getApp().globalData.heartRate = this.heartRate;							
					getApp().globalData.age = this.age;
					
					let lowestHeartRate  = 220 - this.age-(this.heartRate*0.55)+this.heartRate;
					let highestHeartRate = 220 - this.age-(this.heartRate*0.75)+this.heartRate;
				
					this.result = '你的最低有氧心率： '+ Math.round(lowestHeartRate) + '\n' + '最高有氧心率： '+ Math.round(highestHeartRate);
					
					getApp().globalData.lowestHeartRate = this.lowestHeartRate;
					getApp().globalData.highestHeartRate = this.highestHeartRate;
				}
				else
				{
					switch (id)
					{
						case 0:
							alert('请输入体重');
							break;
						
						case 1:
							alert('请输入身高');
							break;
							
						case 2:
							alert('请输入年龄');
							break;
							
						default:
							break;
					}
					
				}
			},
		}
	}
</script>


<style lang="scss">

	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		
		width:100%;
		height: 100vh; 
	}
	
	.navigation-bar
	{
		display: flex;
		align-items: center;
		justify-content: center;
		
		width: 100%;
		height: 10%;
		
		font-weight: 700;
		color: white;
		
		background-color: rgb(115,164,164);
	}
	.back{
		position: absolute;
		
		display: flex;
		align-items: center;
		justify-content: center;
		
		width: 2%;
		height: 2%;
		top: 3%;
		left: 1%;
		//testing
		// border: 1px solid rgb(255,0,0);
	}
	
	.content{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		
		width:100%;
		height:100%;
	}
	
	.result-area{
		display: flex;
		align-items: center;
		justify-content: center;
		
		width:60%;
		height:30%;
		margin: 1%;
		
		border-radius: 25rpx;
		background-color: rgb(115,164,164);
	}
	
	.help{
		color: azure;
		background-color: rgb(0,0,0);
	}
	
	.input-area{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		
		width:60%;
		height:60%;
		margin: 1%;
		
		.static-heart-rate{
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			
			width:100%;
			height:100%;
			margin: 1%;
			
			border-radius: 25rpx;
			background-color: rgb(115,164,164);
			
			.input-block
			{
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				
				width:40%;
			}
			.heart-rate-help
			{
				// position: absolute;
				// right: 40%;
				//testing
				// border: 1px solid rgb(255,0,0);
			}
		}
		
		.age{
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			
			width:100%;
			height:100%;
			margin: 3%;
			
			border-radius: 25rpx;
			background-color: rgb(115,164,164);
		}
		
		.input-title{
			margin-right: 1%;
			//testing
			// border: 1px solid rgb(255,0,0);
		}
		.input{
			display: flex;
			justify-content: center;
			align-items: center;
			background: #F4F4F4;
			border-radius: 4upx;
			height: 70upx;
			font-size: 28upx;
			line-height: 70upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #848484;
			
			text-align:center;
			
			margin: 1%;
		}
	}
	
	.confirm{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		
		width:10%;
		height:10%;
		margin: 1%;
	}

</style>