<template>
    <view v-if="isTarget" class="wrapper">
        <view class="bg" @click="onTap">
            <view class="edit" @click.stop>
                <view class="title">目标体重</view>
                <view class="editem">
                    <view class="left">目标体重</view>
                    <view class="right">
                        <input class="text" type="digit" placeholder="请输入目标体重" v-model="inputvalue" />kg
                    </view>
                </view>
                <view class="btn close" @click="onTap()">取消</view>
                <view class="btn" @click="handleWeight">确定</view>
            </view>
        </view>
    </view>
</template>

<script>
    import {
        mapState
    } from "vuex";
    export default {
        data() {
            return {
                inputvalue: "",
            }
        },
        computed: {
            ...mapState(["user", "isTarget"]),
            startDate() {
                return this.$tools.getDate('start');
            }
        },
        methods: {
            // 目标体重
            handleWeight() {
                let that = this
                console.log("startDate", that.startDate)
                if (!that.inputvalue) {
                    that.$tools.msg("请输入目标体重")
                    return
                }
                that.$model.setTarget({
                    familyid: that.user.familyid,
                    time: that.startDate,
                    weight: that.inputvalue,
                }).then(res => {
                    if (res.code != 0) return
                    that.$tools.msg(res.message)
                    that.$store.commit("changeTarget", false);
                    that.$store.dispatch("getUserInfo", {
                        familyid: that.user.familyid,
                    })
                })
            },
            onTap() {
                this.inputvalue = ""
                this.$store.commit("changeTarget", false);
            }
        }
    }
</script>

<style scoped>
    .btn {
        width: 40%;
        float: right;
        margin-top: 15px;
    }

    .edit {
        top: 20%
    }

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