<template>
  <view class="wrapper" v-if="isedit">
    <view class="bg" @click="onTap">
      <view class="edit" @click.stop>
        <view class="title">
          健康资料
        </view>
        <!--  -->
        <view class="editem">
          <view class="name">性别</view>
          <view class="radio mr-10" @click="selectsex(1)">
            <icon class="iconfont radioimg" :class="[info.sex==1?'icon-radio':'icon-kongradio']">
            </icon>
            <view class="ml-10">男</view>
          </view>
          <view class="radio" @click="selectsex(2)">
            <icon class="iconfont radioimg" :class="[info.sex==2?'icon-radio':'icon-kongradio']">
            </icon>
            <view class="ml-10">女</view>
          </view>
        </view>
        <!--  -->
        <view class="editem">
          <view class="name">身高</view>
          <view class="right">
            <input type="digit" v-model="info.height" placeholder="请输入身高" />cm
          </view>
        </view>
        <view class="editem">
          <view class="name">出生日期</view>
          <view class="right">
            <picker mode="date" :end="endDate" class="f-r" :value="info.birthday" @change="onBirthdayArr">
              <view class="uni-input">{{info.birthday?info.birthday:"请选择"}}
                <icon class="iconfont icon-arrow-down"></icon>
              </view>
            </picker>
          </view>
        </view>
        <view class="tips">
          请准确填写信息方便我们给您更精确的报告
        </view>
        <view class="btn mt-15" @click="handleCloseClick">保存信息</view>
      </view>
    </view>
  </view>
</template>

<script>
  import {
    mapState
  } from "vuex";
  export default {
    data() {
      return {
        info: {
          height: "",
          birthday: "",
          sex: 0,
        },
        ageArr: [],
      }
    },
    computed: {
      ...mapState(["user", "isedit"]),
      userInfo: function() {
        return this.user
      },
      endDate() {
        return this.$tools.getDate("start")
      }
    },
    mounted() {
      var agedata = []
      for (var i = 12; i <= 80; i++) {
        agedata.push(i);
      }
      this.ageArr = agedata
      this.info = this.user
    },
    methods: {
      onTap() {
        // this.isHeight = false
        // this.slideheight = this.userInfo.height
        // this.$store.commit("changeEdit", false);
      },
      // 性别切换
      selectsex(e) {
        this.info.sex = e
      },
      // 出生日期
      onBirthdayArr(e) {
        this.info.birthday = e.target.value
      },
      // 提交、
      handleCloseClick() {
        let that = this
        if (!that.info.sex) {
          that.$tools.msg("请选择性别")
          return
        }
        if (!that.info.height) {
          that.$tools.msg("请选择身高")
          return
        }
        if (!that.info.birthday) {
          that.$tools.msg("请选择出生日期")
          return
        }
        that.$store.commit("changeEdit", false);
        that.getResult()
      },
      getResult() {
        let that = this
        that.$model.getResult({
          birthday: that.userInfo.birthday,
          familyid: that.userInfo.familyid,
          height: that.userInfo.height,
          sex: that.userInfo.sex,
        }).then((res) => {
          if (res.code == 0) {
            that.$store.commit('changeMeasureResult', res.data)
          }
          that.$store.dispatch("getUserInfo", {
            familyid: that.userInfo.familyid,
          })
          that.$store.dispatch("getFamilyList");
        })
      },
    },
  }
</script>

<style lang="scss" scoped>
</style>
