<template>
	<view class="wrapper">
		<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">
						<uni-datetime-picker type="datetime" @change="changeLog" :border="false" :end="endDate"
							:clear-icon='false' :hide-second='true' />
					</view>
				</view>
				<view class="">
					<view class="editem">
						<view class="name">时长</view>
						<view class="right">
							<picker mode="multiSelector" :range="timeList" :value="timesTndex" @change="bindTimeChange">
								<view>{{time_m?time_m:'请选择'}}{{time_s?time_s:''}}</view>
							</picker>
						</view>
					</view>
					<view class="editem">
						<view class="name">个数</view>
						<view class="right">
							<input type="digit" v-model="number" placeholder="请输入">个
						</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: "",
				number: '',
				timeList: [],
				time_m: "",
				time_s: "",
				timesTndex: [0, 0]
			}
		},
		computed: {
			...mapState(["user"]),
			endDate() {
				return this.$tools.getDate("start")
			},
			startDate() {
				return this.$tools.GetDateStr(-90);
			},
		},
		mounted() {
			this.timeList = this.$tools.gethms()
		},
		methods: {
			bindTimeChange(e) {
				let m = e.target.value[0]
				let s = e.target.value[1]
				this.timesTndex = e.target.value
				this.time_m = this.timeList[0][m]
				this.time_s = this.timeList[1][s]
			},
			// 手动记录
			handleTarget() {
				let that = this
				if (!that.regTime) {
					that.$tools.msg("请选择测量日期")
					return
				}
				if (!that.number) {
					that.$tools.msg("请输入跳绳个数")
					return
				}
				that.$model.getskipmeasure({
					aud_id: uni.getStorageSync('userid'),
					r_time: that.regTime,
					num: that.number,
					time_m: that.time_m.substring(0, 2),
					time_s: that.time_s.substring(0, 2),
					type: "free",
				}).then(res => {
					if (res.code != 0) return
					that.$tools.msg(res.msg)
					that.$store.commit("changeRecord", false);
					that.$store.dispatch("getUserInfo", {
						aud_id: uni.getStorageSync('userid'),
					})
					that.$store.dispatch("getSkipResult", {
						aud_id: uni.getStorageSync('userid'),
					})
					that.regTime = ""
					that.weight = ""
				})
			},
			//
			changeLog(e) {
				this.regTime = e
			},
			onTap() {
				this.regTime = ""
				this.weight = ""
				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>