<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="blue" @click="onHelp(0, $event)">
			<image src="../../static/home/blue.png" mode=""></image>
		</view>
		<view class="content">
			
			<!-- <text class="result-area">{{result}}</text> -->
			
			<view class="result-area">
				<view class="border">
					<image class="item-logo" src="../../static/home/bodyFatRatioLogo.png" mode=""></image>
					<view class="">
						{{result1}}
					</view>
					<view class="">
						{{result2}}
					</view>
					<!-- <view class="">
						脂肪总重量/体脂率
					</view> -->
				</view>
			</view>
			<!-- <button class="help" @click="onHelp(0, $event)">宁哥笔记</button> -->
			
			<view class="input-area">
				<view class="waistline">
					<view class="input-title">腰围 : </view>
					<input  class="input" type="number"  placeholder="请输入腰围" v-model="waistline" />
					<text class="Company">厘米</text>
				</view>
				
				<view class="weight">
					<view class="input-title">体重 : </view>
					<input  class="input" type="number"  placeholder="请输入体重" v-model="weight" />
					<text class="Company">公斤</text>
				</view>
			</view>
			
			<button class="confirm" @click="onClick(0, $event)">确定</button>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				waistline:-1,
				weight:-1,
				result1:'',
				result2:'',
			}
		},
		onLoad() {
			this.waistline = "";
			this.weight = "";
			
			// console.log('waistline=',getApp().globalData.waistline);
			// console.log('weight=',getApp().globalData.weight);
			
			if(getApp().globalData.waistline != undefined)
			{
				this.waistline = getApp().globalData.waistline;
			}
			
			if(getApp().globalData.weight != undefined)
			{
				this.weight = getApp().globalData.weight;
			}
		},
		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.heartRate != -1 && this.age != -1)
				{
					getApp().globalData.waistline = this.waistline;							
					getApp().globalData.weight = this.weight;
					//身体脂肪总重量（单位:千克）
					let fatWeight = -1;
					//体脂率=（身体脂肪总量÷体重）
					let fatRate = -1;
					
					let num1 = 0;
					let num2 = 0;
					if(getApp().globalData.gender == 0)
					{//男
						num1 = this.waistline*0.74;
						num2 = this.weight*0.082+44.74;
						fatWeight = Number(num1) - Number(num2);
						fatRate = fatWeight/this.weight* 100;
					}
					else
					{//女
						num1 = this.waistline*0.74;
						num2 = (this.weight*0.082)+Number(34.89);
						fatWeight = num1 - num2;
						fatRate = fatWeight/this.weight * 100;
					}
				
					this.result1 = '身体脂肪总重量： '+ Math.round(fatWeight) + '公斤';
					this.result2 = '体脂率： '+ Math.round(fatRate*100)/100+'%';
					getApp().globalData.fatWeight = this.fatWeight;
					getApp().globalData.fatRate = this.fatRate;
				}
				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: 120rpx;
		font-weight: 700;
		color: white;
		font-size: 37rpx;
		background-color: #C9C7AF;
	}
	
	.item-logo
	{
		z-index: 4;
		height: 21%;
		width: 15%;
		// margin: 1%;
	}
	.back{
		position: absolute;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 3%;
		height: 3%;
		top: 2%;
		left: 3%;
		//testing
		// border: 1px solid rgb(255,0,0);
	}
	
	.blue{
		position: absolute;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 7%;
		height: 7%;
		top: 1%;
		right: 3%;
		border-radius: 50%;
		width: 75rpx;
		height: 75rpx;
		border-radius: 50%;
		overflow: hidden;
		image{
			width: 100%;
			height: 75rpx;
		}
	}
	.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:95%;
		height: 500rpx;
		margin: 1%;
		border-radius: 25rpx;
		background-color: #C9C7AF;
		text-align: center;
		font-weight: 700;
		color: #7B784E;
		font-size: 40rpx;
		image{
			margin-top: 10%;
		}
		.border{
			border: 4rpx solid #F4F4F4;
			height: 90%;
			width: 90%;
			border-radius: 25rpx;
			view{
				margin-top: 5%;
			}
		}
	}
	
	
	.help{
		color: azure;
		background-color: rgb(0,0,0);
	}
	
	.input-area{
		// display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width:95%;
		height:60%;
		margin: 1%;
		font-size: 36rpx;
		font-weight: bold;
		.waistline{
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			width:100%;
			height:20%;
			margin: 1%;
			border-radius: 25rpx;
			background: #FBF0EA;
			input{
				background: #F5DACB;
			}
		}
		
		.weight{
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			width:100%;
			height:20%;
			margin-top: 3%;
			border-radius: 25rpx;
			background: #FEEBEA;
			input{
				background: #FBCDCC;
			}
		}
		
		.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%;
			width: 75%;
			height: 120rpx;
			background: #D8D7C5;
			border-radius: 20rpx;
			font-size: 46rpx;
		}
	}
	
	.confirm{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width:95%;
		height:7%;
		margin: 20%;
		background: #C9C7AF;
		border-radius: 24rpx;
		font-size: 49rpx;
		font-weight: bold;
		color: #7B784E;
	}

	.Company{
		position: absolute;
		right: 13%;
	}
</style>