<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">{{resultStr}}</text>
			<button class="help" @click="onHelp(0, $event)">宁哥笔记</button>
			
			<view class="select-area">
				<view :class="(selected != index)?'block':'block-selected'" v-for="(option,index) in optionArr" @click="onClick(index, $event)">{{option}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				resultStr:'',
				optionArr:[
					'办公室久坐没有什么运动',
					'每周轻松1-3次运动',
					'每周中等强度3-5次',
					'每周大强度运动5-7次以上',
					'大强度训练每周8次以上',
				],
				selected:0,
			}
		},
		onLoad() {
			if(getApp().globalData.bmr !=undefined)
			{
				let calorie = getApp().globalData.bmr * 1.2;
				this.resultStr = '每天消耗的总热量： ' + Math.round(calorie);
			}
			else
			{
				uni.navigateBack({
					delta:1,
					animationType: 'slide-in-left',
					animationDuration: 2000,
					success: res => {
						alert('清先测量基础代谢');
					},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		methods: {
			onBack: function(id,e) {
				//uni.navigateBack()//默认delta:1
				uni.navigateBack({
					delta:1,//返回层数，2则上上页
				})
			},
			onHelp: function(id,e) {
				uni.navigateTo({
					url: '/pages/dayCalorie/help',
					animationType: 'slide-in-left',
					animationDuration: 2000,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			onClick: function(id,e) {
				// console.log(id);
				this.selected = id;
			
				let calorie = -1;
				
				switch (id){
					case 0:
						calorie = getApp().globalData.bmr * 1.2;
						break;
					
					case 1:
						calorie = getApp().globalData.bmr * 1.375;
						break;
					
					case 2:
						calorie = getApp().globalData.bmr * 1.5;
						break;
						
					case 3:
						calorie = getApp().globalData.bmr * 1.725;
						break;
						
					case 4:
						calorie = getApp().globalData.bmr * 1.9;
						break;
					default:
						break;
				}
				getApp().globalData.calorie = calorie;
				this.resultStr = '每天消耗的总热量： ' + Math.round(calorie);
			},
		}
	}
</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);
	}
	
	.select-area{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		
		width:60%;
		height:60%;
		margin: 1%;
	}
	.block{
		width:60%;
		height:60%;
		margin: 1%;
		
		background-color: rgb(115,164,164);
	}
	.block-selected{
		width:60%;
		height:60%;
		margin: 1%;
		
		box-shadow: 3px 3px 6px 3px rgba(0, 0, 0, 1);
		
		background-color: rgb(115,164,164);
	}
</style>