<template>
	<view class="wrapper wrapperbg">
		<view class="bg" @click="onTap">
			<view class="edit" @click.stop>
				<view class="title">手动记录</view>
				<!--  -->
				<view class="editem" @click="hideKeyboard">
					<view class="left">日期</view>
					<view class="right">
						<picker mode="date" :end="endDate" @change="changeLog" fields="time">
							<view class="uni-input">{{regTime?regTime:'请选择'}}</view>
							<icon class="iconfont icon-arrow-down-bold"></icon>
						</picker>
					</view>
				</view>
				<view class="">
					<view class="editem">
						<view class="name">身高</view>
						<view class="right">
							<input type="digit" v-model="height" placeholder="请输入身高" />cm
						</view>
					</view>
					<view class="editem">
						<view class="name">体重</view>
						<view class="right">
							<input type="number" v-model="weight" placeholder="请输入体重">kg
						</view>
					</view>
				</view>
				<view class="btn close" @click="onTap()">取消</view>
				<view class="btn" @click="handleTarget">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		data() {
			return {
				regTime: "",
				weight: "",
				height: ''
			}
		},
		computed: {
			...mapState(["user", "isWeight"]),
			endDate() {
				return this.$tools.getDate("start")
			},
			startDate() {
				return this.$tools.GetDateStr(-90);
			},
		},
		methods: {
			// 手动记录
			handleTarget() {
				let that = this
				if (!that.regTime) {
					that.$tools.msg("请选择测量日期")
					return
				}
				if (!that.height) {
					that.$tools.msg("请输入测量身高")
					return
				}
				if (!that.weight) {
					that.$tools.msg("请输入测量体重")
					return
				}
				that.$store.commit("changeRecord", false);
				that.$model.getinsertmeasure({
					aud_id: uni.getStorageSync('userid'),
					time: that.regTime,
					weight: that.weight,
					height: that.height,
				}).then(res => {
					if (res.code != 0) return
					that.$tools.msg(res.msg)
					that.$store.dispatch("getResult", {
						aud_id: uni.getStorageSync('userid')
					})
					that.$store.dispatch("getUserInfo", {
						aud_id: uni.getStorageSync('userid')
					})
					that.$store.dispatch("GetBodyTrendList", {
						aud_id: uni.getStorageSync('userid'),
						s_time: that.startDate,
						e_time: that.endDate
					})
					that.regTime = ""
					that.weight = ""
					that.height = ""
				})
			},
			//
			changeLog(e) {
				this.regTime = e.detail.value
			},
			onTap() {
				this.regTime = ""
				this.weight = ""
				this.height = ""
				this.$store.commit("changeRecord", false);
			},
			hideKeyboard() {
				uni.hideKeyboard()
			},
		}
	}
</script>

<style scoped lang="scss">
	.btn {
		width: 40%;
		float: right;
		margin-top: 15px;
		background: $maincolor !important;
	}
	
	.edit {
		top: 20%
	}
	
	.close {
		background: #fff !important;
		float: left;
		color: #333;
	}
</style>