<template>
	<view class="content">
		<view class="title">
			{{$t('titleCustomKcal')}}
			<text class="desc">{{suggestion_kcal_range_val}}</text>
		</view>
		<view class="input">
			<input type="digit" :placeholder="$t('verifyCalorie')" v-model="kcal" />
			<text>kcal</text>
		</view>
		<view class="btn" @click="handlesub">{{$t('btnSubmit')}}</view>

	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		data() {
			return {
				kcal: "",
				suggestion_kcal_range_val: ""
			}
		},
		computed: {
			...mapState(["user"]),
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: this.$t('titleSet')
			})
			this.suggestion_kcal_range_val = options.suggestion_kcal_range_val
		},
		methods: {
			handlesub() {
				let that = this
				if (that.kcal == '' || Number(that.kcal) <= 0) {
					that.$tools.msg(that.$t('verifyCalorie'))
					return
				}
				that.$model.getCountSetUserKcal({
					aud_id: that.user.aud_id,
					set_kcal: that.kcal
				}).then(res => {
					if (res.code == 0) {
						that.$tools.msg(that.$t('msgSetSuccess'))
						setTimeout(function() {
							uni.switchTab({
								url: '/pages/count/count'
							})
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 0 30rpx;
		flex-wrap: wrap;
		background-color: #fff;
	}

	.title {
		width: 100%;
		font-size: 16px;
		margin: 30rpx 0;
		font-weight: bold;

		text {
			font-size: 14px;
			color: #999;
			font-weight: 500;
			width: 100%;
			display: inline-block;
			margin-top: 20rpx;
		}
	}

	.input {
		display: flex;
		margin: 40rpx;
		height: 35px;
		line-height: 35px;
		border-bottom: 1px solid #dfdfdf;
		width: calc(100% - 80rpx);
		position: relative;

		/deep/input {
			width: 100%;
			height: 35px;
			font-size: 18px;
			line-height: 35px;
			text-align: center;
			font-weight: bold;
			position: absolute;
		}

		text {
			position: absolute;
			right: 0;
		}
	}

	.btn {
		margin-top: 80rpx;
		width: calc(100% - 60rpx);
		color: #fff;
	}
</style>