<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">
			<view class="result-area">
				<view class="border">
					<image class="item-logo" src="../../static/home/dayCalorieLogo.png" mode=""></image>
					<view class="">
						{{resultStr}}千卡
					</view>
					<!-- <view class="">
						基础代谢率
					</view> -->
				</view>
			</view>
			
			<!-- <button class="help" @click="onHelp(0, $event)">宁哥笔记</button> -->
			
			<view class="select-area">
				<view :class="(selected != index)?'block':'block-selected'":style="{background:backList[index%6]}" v-for="(option,index) in optionArr" @click="onClick(index, $event)">{{option}}</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				resultStr:'0',
				optionArr:[
					'办公室久坐没有什么运动',
					'每周轻松1-3次运动',
					'每周中等强度3-5次',
					'每周大强度运动5-7次以上',
					'大强度训练每周8次以上',
				],
				backList:['#F2CDB7', '#F1F1EC','#E9F2F1','#FDEFEE','#FBF0EA'],
				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: 8%;
		font-weight: 700;
		color: white;
		font-size: 37rpx;
		background-color: #FABAB9;
	}
	
	.item-logo
	{
		z-index: 4;
		height: 20%;
		width: 11%;
	}
	.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%;
		//testing
		// border: 1px solid rgb(255,0,0);
		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:90%;
		height:30%;
		margin: 1%;
		border-radius: 25rpx;
		background-color: #FABAB9;
		text-align: center;
		font-size: 44rpx;
		font-weight: 700;
		color: #4D857C;
		image{
			margin-top: 10%;
		}
		.border{
			border: 2rpx solid #F4F4F4;
			height: 90%;
			width: 90%;
			border-radius: 25rpx;
			view{
				margin-top: 5%;
			}
		}
	}
	
	
	.help{
		color: azure;
		background-color: rgb(0,0,0);
	}
	
	.select-area{
		width:90%;
		height:60%;
		margin: 1%;
		view{
			height: 142rpx;
			margin-top: 30rpx;
		}
	}
	.block{
		width:100%;
		margin: 1%;
		font-size: 30rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: rgb(115,164,164);
	}
	.block-selected{
		width:100%;
		margin: 1%;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: rgb(115,164,164);
		box-shadow: 0rpx 12rpx 16rpx 0rpx rgba(0, 0, 0, 0.22);
		font-size: 50rpx;
	}
	.confirm{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width:90%;
		height:7%;
		margin: 1%;
		background: #FABAB9;
		border-radius: 24rpx;
		color: #C65E5C;
		font-weight: bold;
		font-size: 49rpx;
	}
</style>