<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="weight">
					<view class="input-title">体重 : </view>
					<!-- <input  class="input" type="number"  placeholder="请输入体重" v-model="weight" @input="onInput(0, $event)" :value="weight"/> -->
					<input  class="input" type="number"  placeholder="请输入体重" v-model="weight" />
				</view>
				
				<view class="high">
					<view class="input-title">身高 : </view>
					<input  class="input" type="number"  placeholder="请输入身高" v-model="high" />
				</view>
				
				<view class="age">
					<view class="input-title">年龄 : </view>
					<input  class="input" type="number"  placeholder="请输入年龄" v-model="age" />
				</view>
			</view>
			
			<button class="confirm" @click="onClick(0, $event)">确定</button>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				weight:-1,
				high:-1,
				age:-1,
				//基础代谢率
				bmr:-1,
				result:'',
			}
		},
		onLoad() {
			
			this.weight = 0;
			this.high = 0;
			this.age = 0;
			
			// console.log('gender=',getApp().globalData.gender)
			// console.log('weight=',getApp().globalData.weight)
			// console.log('high=',getApp().globalData.high)
			// console.log('age=',getApp().globalData.age)
			if(getApp().globalData.weight != undefined)
			{
				this.weight = getApp().globalData.weight;
			}
			
			if(getApp().globalData.high != undefined)
			{
				this.high = getApp().globalData.high;
			}

			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/bodyFatRatio/help',
					animationType: 'slide-in-left',
					animationDuration: 2000,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			onClick: function(id,e) {
				
				if(this.weight != -1 && this.high !=-1 && this.age != -1)
				{
					let gender = getApp().globalData.gender;
					
					getApp().globalData.weight = this.weight;				
					getApp().globalData.high = this.high;					
					getApp().globalData.age = this.age;
					
					if(gender == 0)
					{
						this.bmr = 66+(13.7*this.weight)+(5*this.high)-(6.8*this.age);
					}
					else
					{
						this.bmr = 655+(9.6*this.weight)+(1.8*this.high)-(4.7*this.age);
					}
					
					this.result = '你的基础代谢率为： '+ Math.round(this.bmr);
					
					getApp().globalData.bmr = this.bmr;
				}
				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%;
		
		.weight{
			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);
		}
		
		.high{
			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);
		}
		
		.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{
			//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>