var config = require("../../config/config.js");
var app = getApp();
const Http = require("../../utils/HttpBasics");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    canIUse: wx.canIUse('official-account'),
    flag: 'hidden',
    score:'0',
    name:"",
    birthdate:"",
    sex:"",
    showEdit:false
  },
  /**
   * 跳转到成长值的页面
   */
  gotograde:function(){
    wx.navigateTo({
      url: '/pages/grade/grade',
    })
  },
  // getrun:function(){
  //   let that = this;
  //   wx.getWeRunData({
  //     success: function (res) {
  //       console.log(res);
  //       Http.post({
  //         url: config.api.getWeRunData,
  //         data: {
  //           encryptedData: res.encryptedData,
  //           iv: res.iv
  //         }
  //       }).then(res => {
  //         console.log(res);
  //         that.setData({
  //           step: res.data.stepInfoList[30].step
  //         })
  //       })
  //     }
  //   })
  // },
  /**
   * 
   */
  // getxinghao:function(){
  //   wx.getSystemInfo({
  //     success:function(res){
  //       console.log(res);
  //       wx.showModal({
  //         content: res.brand,
  //       })
  //     }
  //   })
  // },
  navigateTo() {
    wx.navigateTo({
      url: `/pages/login/index`
    });
  },
  showVersion: function() {
    /**
     * 长按显示版本号
     */
    let that = this;
    if (that.data.flag == 'hidden') {
      that.setData({  
        flag: 'show'
      });
    }
    console.log(that.data.flag)
  },
  gotoedit:function(){
    wx.navigateTo({
      url: '/pages/edit/edit',
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this;
    let num = wx.getStorageSync('couponNum');
    wx.hideTabBarRedDot({
      index: 2
    });
    console.log("我是渲染")
    if (num == 'couponNum1') {
      wx.setStorage({
        key: 'couponNum',
        data: "couponNum1",
      })
      that.setData({
        couponNum: "couponNum1"
      })
    } else if (num == 'couponNum') {
      that.setData({
        couponNum: "couponNum"
      })
    };
    Http.get({
      url: config.api.getScore,
      data: {}
    }).then(res=>{
      console.log(res); 
      if (res.data.address && res.data.name && res.data.sex && res.data.birthdate){
        that.setData({
          showEdit:true
        })
      }
      that.setData({
        score: res.data.score,
        levelName: res.data.levelName
      })
    });
    // that.getrun();
  }
});