<template>
	<view class="wrapper" v-if="isRecord">
		<view class="bg" @click="onTap">
			<view class="edit" @click.stop>
				<view class="title">{{$t("manualRecording")}}</view>
				<view class="editem">
					<view class="left">{{$t("titleDate")}}</view>
					<view class="right">
						<picker mode="date" :end="endDate" @change="changeLog" :fields="fields">
							<view class="uni-input">{{regTime?regTime:$t("verifyPicker")}}</view>
							<icon class="iconfont icon-arrow-down-bold"></icon>
						</picker>
					</view>
				</view>
				<!-- 身体 -->
				<view>
					<view class="editem" v-if="userInfo&&userInfo.height">
						<view class="name">{{$t("infoHeight")}}</view>
						<view class="right">
							<input type="digit" v-model="height" :placeholder="$t('verifyHeight')" />cm
						</view>
					</view>
					<view class="editem" v-if="userInfo&&userInfo.weight">
						<view class="name">{{$t("infoWeight")}}</view>
						<view class="right">
							<input type="digit" v-model="weight" :placeholder="$t('verifyWeight')">kg
						</view>
					</view>
					<view class="editem" v-if="userInfo.stage==3">
						<view class="left">{{$t("infoHead")}}</view>
						<view class="right">
							<input v-model="head" type="digit" :placeholder="$t('verifyHead')" />cm
						</view>
					</view>
				</view>
				<view class="btn close" @click="onTap()">{{$t("btnSancellation")}}</view>
				<view class="btn" @click="handleinsertmeasure()">{{$t("btnConfirm")}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		props: {
			rtype: null,
		},
		data() {
			return {
				regTime: '',
				weight: "",
				height: '',
				fields: "",
				head: ""
			}
		},
		computed: {
			...mapState(["user", "isRecord"]),
			userInfo() {
				return this.user
			},
			endDate() {
				return this.$tools.getDate("start")
			},
		},
		mounted() {
			let that = this
			// #ifdef APP-PLUS
			that.fields = "time"
			// #endif 
			// #ifndef APP-PLUS 
			that.fields = "day"
			// #endif
		},
		methods: {
			// 身体
			handleinsertmeasure() {
				let that = this
				if (!that.regTime) {
					that.$tools.msg(that.$t('verifyBodyDate'))
					return
				}
				if (!that.height) {
					that.$tools.msg(that.$t('verifyHeight'))
					return
				}
				if (!that.weight) {
					that.$tools.msg(that.$t('verifyWeight'))
					return
				}
				that.$model.getinsertmeasure({
					aud_id: that.user.aud_id,
					time: that.regTime,
					weight: that.weight,
					height: that.height,
					head_data: that.head ? that.head : 0
				}).then(res => {
					if (res.code != 0) return
					that.$tools.msg(res.msg)
					that.$store.dispatch("getResult", {
						aud_id: that.user.aud_id
					})
					that.$store.dispatch("getUserInfo", {
						aud_id: that.user.aud_id
					})
					that.onTap()
				})
			},
			changeLog(e) {
				this.regTime = e.detail.value
			},
			onTap() {
				let that = this
				that.weight = ""
				that.height = ""
				that.regTime = ""
				that.$store.commit("changeRecord", false);
			},
		}
	}
</script>

<style scoped lang="scss">
	.btn {
		width: 40%;
		float: right;
		margin-top: 15px;
		background: $maincolor !important;
	}

	.close {
		background: #dfdfdf !important;
		float: left;
	}
</style>