import { API } from './../../../utils/network/api'
let api = new API()
const app = getApp()
Page({
  data: {
    navbarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '我的信息', //导航栏 中间的标题
    },
    height: app.globalData.height,
    card_name: "",
    card_num_mask: "",
    doctor_id: "",
    idcard_status: 0,
    iden_auth_status: 0,
    is_bind_bank: 0,
    user_name: "",
    brief_introduction: "点击编辑",
    v_show: false,
    v_message: "",
    next_url: "/Pages/yishi/identity/index"
  },
  onLoad(){
    //获取医生我的账户数据
    api.getDoctorCenterInfo().then(response => {
      console.log(response);
      this.setData({
        doctor_id: response.data.doctor_id,
        brief_introduction: response.data.brief_introduction==null?this.data.brief_introduction:response.data.brief_introduction,
        idcard_status:response.data.idcard_status,
        iden_auth_status:response.data.iden_auth_status,
        card_name:response.data.card_name,
        card_num_mask:response.data.card_num_mask,
      })
    }).catch(errors => {console.error(errors);})
  },
  onShow(){
    let usertype =  wx.getStorageSync('usertype');
    let user_id = wx.getStorageSync("user_id_"+usertype);
    let is_bind_bank = wx.getStorageSync(user_id+'_is_bind_bank');
    this.setData({
      is_bind_bank: is_bind_bank
    })
  },
  logOut(){
    console.log("退出登录");
    wx.showModal({
      title: '确认退出登录',
      content: '退出登录后您需要重新登录',
      success (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          let usertype =  wx.getStorageSync('usertype');
          wx.setStorageSync('AUTH_TOKEN_'+usertype, "");
          wx.setStorageSync('user_id_'+usertype, "");
         
          wx.setStorageSync('client_user_id_'+usertype, "");
          app.imLogout();
          app.globalData.isLogin=false;
          wx.setStorageSync('usertype','')
          app.go("/Pages/index/index");
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  go(e){
    console.log(2222)
    if(this.data.idcard_status != 1){
      this.setData({
        v_show: true,
        v_message: "请先进行实名认证",
        next_url: "/Pages/yishi/identity/index"
      })
      return;
    }
    if(this.data.iden_auth_status != 1){
      this.setData({
        v_show: true,
        v_message: "请先进行医师身份认证",
        next_url: "/Pages/yishi/identity/index?selected_tab=1",
      })
      return;
    }
    if(this.data.is_bind_bank != 1){
      this.setData({
        v_show: true,
        v_message: "请您先绑定结算银行卡",
        next_url: "/Pages/yishi/bankcard/index",
      })
      return;
    }
    app.go(e.currentTarget.dataset.url)
  },
  go1(e){
    if(this.data.idcard_status != 1){
      this.setData({
        v_show: true,
        v_message: "请先进行实名认证",
        next_url: "/Pages/yishi/identity/index"
      })
      return;
    }
    app.go(e.currentTarget.dataset.url)
  },
  go2(e){
    if(this.data.idcard_status != 1){
      this.setData({
        v_show: true,
        v_message: "请先进行实名认证",
        next_url: "/Pages/yishi/identity/index"
      })
      return;
    }
    if(this.data.iden_auth_status != 1){
      this.setData({
        v_show: true,
        v_message: "请先进行医师身份认证",
        next_url: "/Pages/yishi/identity/index?selected_tab=1",
      })
      return;
    }
    app.go(e.currentTarget.dataset.url)
  },
  goIn(){
    this.setData({
      v_show: false
    })
    app.go(this.data.next_url)
  },
  cancelDialog(){
    this.setData({
      v_show: false
    })
  }
  
})