// custom-tab-bar/index.js
const app = getApp()
Component({

  /**
   * 页面的初始数据
   */
  data: {
    tabBarShow: true,
    active: 0,
    "backgroundColor": "#ffffff",
    "selectedColor": "#fff",
    "listAll": {
      "list1":[
        {
        "pagePath": "/Pages/yaoshi/home/home",
        "text": "首页",
        "iconPath": "/static/images/yaoshi/tabbar_icon/home.png",
        "selectedIconPath": "/static/images/yaoshi/tabbar_icon/home_select.png",
        "info": ""
      },
      {
        "pagePath": "/Pages/yaoshi/my/my",
        "text": "我的",
        "iconPath": "/static/images/yaoshi/tabbar_icon/my.png",
        "selectedIconPath": "/static/images/yaoshi/tabbar_icon/my_select.png",
        "info": ""
      }],
      "list2":[
        {
        "pagePath": "/Pages/yishi/index/index",
        "text": "首页",
        "iconPath": "/static/images/yishi/tabbar_icon/index.png",
        "selectedIconPath": "/static/images/yishi/tabbar_icon/index_select.png",
        "info": ""
      },
      {
        "pagePath": "/Pages/yishi/wenzhen_v2/wenzhen",
        "text": "问诊",
        "iconPath": "/static/images/yishi/tabbar_icon/wenzhen.png",
        "selectedIconPath": "/static/images/yishi/tabbar_icon/wenzhen_select.png",
        "info": "99"
      },
      {
        "pagePath": "/Pages/yishi/my/index",
        "text": "我的",
        "iconPath": "/static/images/yishi/tabbar_icon/my.png",
        "selectedIconPath": "/static/images/yishi/tabbar_icon/my_select.png",
        "info": ""
      }]
    },
    items: [ ],
    dialog_visible: false,
    dialog_content: "",
    usertype: 2,
    index_info: "",
    wenzhen_info: "",
    my_info: "",
    next_url: "/Pages/yishi/identity/index",
    info_inter: 0
  },

  lifetimes: {
    attached(){
      this.setData({
        usertype: 2,
        items: this.data.listAll.list2
      })
    },
    ready() {
      const usertype = wx.getStorageSync('usertype')
      if (usertype == 3) {
        this.setData({
          usertype: 3,
          items: this.data.listAll.list1
        })
      }else{
        this.setData({
          usertype: 2,
          items: this.data.listAll.list2
        })
      }
    },
  },
 
  methods: {
    startInterval(){
      let _this = this;
      const usertype = wx.getStorageSync('usertype')
      let userID = wx.getStorageSync('user_id_'+usertype);
      let info_inter = setInterval(() => {
        if(app.globalData.config.userID == userID){
          let index_info = wx.getStorageSync(userID+'_index_info');
          let wenzhen_info = wx.getStorageSync(userID+'_wenzhen_info');
          let my_info = wx.getStorageSync(userID+'_my_info');
          _this.setData({
            index_info: this.formatNum(index_info),
            wenzhen_info: this.formatNum(wenzhen_info),
            my_info: this.formatNum(my_info),
          })
        }
      }, 500);
      this.setData({
        info_inter: info_inter
      })
    },
    stopInterval(){
      clearInterval(this.data.info_inter)
    },
    formatNum(val){
      if(val > 99) val = '+99';
      if(val == 0) val = '';
      return val;
    },
    // swichNav: function (e) {
    //   console.log(123);
    //   let that = this;
    //   if (this.data.currentTab === e.target.dataset.current) {
    //     return false;
    //   } else {
    //     that.setData({    
    //       currentTab: e.target.dataset.current
    //     })
    //     let url = e.currentTarget.dataset.url;  // 点击tabbar时，跳转对应的页面
    //     wx.switchTab({
    //       url: url,
    //     })
    //   }
    // },
    onChange(e) {
      const usertype = wx.getStorageSync('usertype');
      let userID = wx.getStorageSync('user_id_'+usertype);
      let idcard_status = wx.getStorageSync(userID+'_idcard_status');
      let iden_auth_status = wx.getStorageSync(userID+'_iden_auth_status');
      let multi_point_status = wx.getStorageSync(userID+'_multi_point_status');
      let is_bind_bank = wx.getStorageSync(userID+'_is_bind_bank');

      if(idcard_status != 1 && usertype != 3){
        this.setData({
          dialog_visible: true,
          dialog_content: "请您先完成实名认证",
          next_url: "/Pages/yishi/identity/index",
        })
        return;
      }
      if(iden_auth_status != 1 && usertype != 3){
        this.setData({
          dialog_visible: true,
          dialog_content: "请您先医师身份认证",
          next_url: "/Pages/yishi/identity/index?selected_tab=1",
        })
        return;
      }
      if(is_bind_bank != 1 && usertype != 3){
        this.setData({
          dialog_visible: true,
          dialog_content: "请您先绑定结算银行卡",
          next_url: "/Pages/yishi/bankcard/index"
        })
        return;
      }
      let url = this.data.items[e.detail].pagePath;
      wx.switchTab({
        url: url,
      })
    },
    confirmDialog(){
      this.setData({
        dialog_visible: false
      })
      let next_url = this.data.next_url;
      app.go(next_url);
    },
    cancelDialog(){
      this.setData({
        dialog_visible: false
      })
    },
  }
  
})