weight.js 3.6 KB
// pages/weight/weight.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    weightLists:[],
    show: false,
    showtype:0,
    mask: false,
    rote: -15
  },
  add_record(){
    wx.navigateTo({
      url: '/pages/addWeight/addWeight', 
    })
  },
  get_records(){
    let url = '/user/getWeightLog' 
    app.post(url,{}).then((res)=>{
      let rote = parseInt(res.new.scale)
      this.setData({ 
        weightLists: res.list,
        latestRecord: res.new,
        bmi: res.bmi,
        rote: rote - 90,
        week: res.new.week,
        day: res.new.day,
        nowWeight: res.new.weight,
        residual_quota: res.new.residual_quota,
        increase: res.new.increase, 
        residual_msg: res.new.residual_msg,

        baseData:{
          week: res.new.week,
          day: res.new.day,
          nowWeight: res.new.weight,
          rote: rote - 90,
          residual_quota: res.new.residual_quota,
          residual_msg: res.new.residual_msg,
          increase: res.new.increase
        }
      })
      let status = this.data.weightLists[0].sign_status
      let newWeight = wx.getStorageSync('newWeight')
      // let type = status == '1' && 'newWeight' ? '1' : status == '2' && 'newWeight' ? '2' : status == '3' && newWeight ? '3' : status == '4' && newWeight ? '4' : status == '5' && newWeight?'5':'';
      if (newWeight){
        this.setData({
          showtype: 8,
          mask: true,
          sign_mbi: this.data.weightLists[0].sign_mbi
          
        })
      }

    }).catch((errMsg)=>{
      
    })
  }, 
  showTips(){ 
    let that = this; 
    let show = this.data.show;
    if(!show){
      that.setData({
        show: !that.data.show
      })
      setTimeout(function(){
        that.setData({
          show: !that.data.show
        }) 
      },3000)
    } 
  },
  showtoast(e){
    console.log(e)
    let rote = parseInt(e.currentTarget.dataset.roate)
    this.setData({
      showtype: 8,
      mask: true,
      sign_mbi: e.currentTarget.dataset.current.sign_mbi,
      rote: rote - 90,
      week: e.currentTarget.dataset.current.week,
      day: e.currentTarget.dataset.current.day,
      nowWeight: e.currentTarget.dataset.current.current_weight,
      residual_quota: e.currentTarget.dataset.current.residual_quota,
      residual_msg: e.currentTarget.dataset.current.residual_msg,
      increase: e.currentTarget.dataset.current.increase
    })
  },
  closefirst(){
    this.setData({
      showtype: 0,
      mask: false
      // rote: this.data.baseData.rote,
      // week: this.data.baseData.week,
      // day: this.data.baseData.day,
      // nowWeight: this.data.baseData.nowWeight
    }) 
    wx.removeStorageSync('first')
    wx.removeStorageSync('newWeight')
  },
  /**
   * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {
    let first = wx.getStorageSync('first')
    if (first) {
      this.setData({
        showtype: 6,
        mask: true
      })
    } 
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.get_records();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})