import { API } from './../../../utils/network/api'
let api = new API()
const app = getApp();
Page({
  data: {
    title: "我的",
    navHeight: 0,
    stateHeight: 0,
    doctor_title:'',
    user_name: "医师姓名",
    iden_auth_status: "0",
    idcard_status: "0",
    multi_point_status: "0",
    static_host: api.getStaticHost(),
    avatar: api.getStaticHost()+"/applet/doctor/static/images/default_photo.png",
    balance_account: "0",
    estimate_income: "0",
    doctor_id: ""
  },
  onPullDownRefresh(){
    console.log("用户下拉动作")
    this.onShow();
  },
  //  获取状态栏信息
  getMenuButtonBound() {
    let stateHeight = 0; //  接收状态栏高度
    const navHeight = wx.getMenuButtonBoundingClientRect().height; //  获取胶囊高度
    let top = 0;
    wx.getSystemInfo({
      success(res) {
        stateHeight = res.statusBarHeight;
      },
    });
    top = wx.getMenuButtonBoundingClientRect().top - stateHeight; //  获取top值
    // console.log('navHeight', navHeight);
    // console.log('top', top);
    this.setData({
      // navHeight: navHeight + top * 2, //  导航栏高度
      navHeight, //  导航栏高度
      stateHeight: stateHeight + top, //  状态栏高度
    });
  },
  onLoad(){
    //console.log("onLoad ");
  },
  onShow: function () {
    // console.log("onshow ");
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        active: 2  //数字是当前页面在tabbar的索引,如我的查询页索引是2，因此这边为2，同理首页就为0，审批页面为1
      })

      this.getTabBar().startInterval()
      
    }
    this.getMenuButtonBound();
 
    // console.log("my onLoad");
    //获取个人中心数据
    api.getDoctorCenter().then(response => {
      this.setData({
        user_name: response.data.user_name,
        doctor_title:response.data.doctor_title,
        iden_auth_status: response.data.iden_auth_status,
        idcard_status: response.data.idcard_status,
        multi_point_status: response.data.multi_point_status,
        balance_account: response.data.balance_account,
        doctor_id: response.data.doctor_id,
        estimate_income: response.data.estimate_income
      })  

      let avatar = response.data.avatar;
      if(avatar && (avatar.indexOf("http") == -1)){
        avatar = api.getStaticHost() + avatar;
      }
      this.setData({
        "avatar": avatar
      })
    }).then(res => {
      wx.stopPullDownRefresh()
    }).catch(errors => {
      console.error(errors);
    })
  },
  onHide(){
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().stopInterval()
    }
  },
  go(e){
    let url = e.currentTarget.dataset.url;
    app.go(url)
  }
})