// pages/my/my.js
import {getCenter} from "../../api/personCenter"
import {setBarData,throttle} from "../../utils/util"
import {coupon} from "../../api/personCenter"
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    patient_info:'',
    opacity:0,
    show_fuli:false,
    img_host:'https://oss.prod.applets.igandanyiyuan.com/applet/patient/static'
  },
  getInfo(){
    getCenter().then((data)=>{
      this.setData({
        patient_info:data,
        show_fuli:data.coupon
      })
      
      //this.getcoupon()
    })
   },
  goCenter:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/personCenter/personCenter',
    })
  }),
  goAgreement:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/agreeList/agreeList',
    })
  }),
  goWelfare:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/myWelfare/myWelfare',
    })
  }),
  goMedinceRecord:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/medinceRecord/medinceRecord',
    })
  }),
  goMyDoctor:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/myDoctor/myDoctor',
    })
  }),
  goFamily:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/familyDoc/familyDoc',
    })
  }),
  goSickMange:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/sickManage/sickManage',
    })
  }),
  goAddress:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/address/address',
    })
  }),
  goConsultOrder:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/consultOrder/consultOrder',
    })
  }),
  goCheckOrder:throttle(function(){
    app.method.navigateTo({
      url: '/sugarCheck/pages/checkOrder/checkOrder',
    })
  }),
  goHealthyOrder:throttle(function(){
    app.method.navigateTo({
      url: '/healthyService/pages/healthyOrder/healthyOrder',
    })
  }),
  goMyPrescript:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/myPrescript/myPrescript',
    })
  }),
  goMedinceOrder:throttle(function(){
    app.method.navigateTo({
      url: '/patient/pages/medinceOrder/medinceOrder',
    })
  }),
  watchBack(){
    let total=app.globalData.totalUnread;
    setBarData(total);
   },
   getcoupon() {
    coupon({
      user_coupon_status:0
    }).then(data => {
        if(data.length>0){
          this.setData({
            show_fuli:true
          })
        }else{
          this.setData({
            show_fuli:false
          })
        }

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
   
    wx.removeTabBarBadge({
      index:1
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  onPageScroll: function(e) {
    let opacity=0;
    if(e.scrollTop/(86/10)>=1){
      opacity=1
    }else{
      opacity=e.scrollTop/(86/10)
    }
    this.setData({
      opacity:opacity
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getInfo();
    app.globalData.origion=0;
    this.setData({
      img_host:app.hostConfig().imghost
    }); 
    app.watch(this.watchBack.bind(this))//注册监听
    if(!app.globalData.totalUnread && app.globalData.totalUnread!=0){
      app.imLogin();
    }else{
      let total=app.globalData.totalUnread;
      setBarData(total);
    }
 
  
  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  
})