<template>
	<view v-if="isFirst" class="wrapper wrapperbg">
		<view class="bg" @click="onTap">
			<view class="edit" @click.stop>
				<view class="title">{{type==1?$t("body.target_weight"):$t("body.initial_weight")}}</view>
				<view class="editem" @click="hideKeyboard" v-if="type!=1">
					<view class="name">{{$t("common.titleDate")}}</view>
					<view class="right">
						<picker mode="date" :end="endDate" @change="changeLog" :fields="fields">
							<view class="uni-input">{{regTime?regTime:$t("tips.verifyPicker")}}</view>
							<icon class="iconfont icon-arrow-down-bold"></icon>
						</picker>
					</view>
				</view>
				<view class="editem">
					<view class="name">{{$t("common.infoWeight")}}</view>
					<view class="right">
						<input v-model="weight" type="digit" :placeholder="$t('tips.verifyRecord')" />kg
					</view>
				</view>
				<view class="btn close" @click="onTap()">{{$t("tips.btnSancellation")}}</view>
				<view class="btn" @click="handleTarget">{{$t("tips.btnConfirm")}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		props: {
			type: {}
		},
		data() {
			return {
				regTime: "",
				weight: "",
				fields: "",
			}
		},
		computed: {
			...mapState(["user", "isFirst"]),
			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: {
			// 初始体重
			handleTarget() {
				let that = this
				if (that.type != 1 && !that.regTime) {
					that.$tools.msg(that.$t("tips.verifyDate"))
					return
				}
				if (!that.weight) {
					that.$tools.msg(that.$t("tips.verifyWeight"))
					return
				}
				that.$model.getfirstweight({
					aud_id: that.user.id,
					time: that.type == 1 ? '' : that.regTime ? that.regTime : that.user.firstresulttime,
					weight: that.weight,
					type: that.type
				}).then(res => {
					that.$tools.msg(res.msg)
					if (res.code == 0) {
						that.$store.commit("changeFirst", false);
						that.$store.commit('changeMeasureResult', {
							target_current: res.data
						})
						that.regTime = ""
						that.weight = ""
					}
				})
			},
			//
			changeLog(e) {
				this.regTime = e.detail.value
			},
			onTap() {
				this.weight = ""
				this.regTime = ""
				this.$store.commit("changeFirst", 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>