// pages/ucenter/index/index.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    isLogin: false
  },
  tologin(e) {
    let url = '/pages/login/phone_login/phone_login';
    wx.navigateTo({
      url
    });
  },
  toUserCenter(e){
    if (this.phoneCheck()) {
      let url = '/pages/ucenter/center/center';
      wx.navigateTo({
        url
      });
    }
  },
  logout(e){
    if (this.data.isLogin) {
      wx.clearStorageSync();
      wx.reLaunch({
        url: '/pages/index/index',
      });
    }
  },
  phoneCall(e){
    wx.makePhoneCall({
      phoneNumber: getApp().globalData.helpPhoneNum
    });
  },

  phoneCheck(){
    if (this.data.userInfo.bindingPhone==0 && !this.data.userInfo.flag) {
      wx.showModal({
        title: '提示',
        content: '当前账户未绑定手机号，请您进行手机号绑定操作',
        showCancel:false,
        confirmText: '去绑定',
        confirmColor:'#00AADD',
        success: function (res1) {
            let url = `/pages/bindPhone/bindPhone`;
            wx.navigateTo({
              url
            });
        }
      })
      return false;
    }else{
      return true;
    }
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //wx.setNavigationBarTitle({
    // title: '个人中心'
    //})
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let userInfo = wx.getStorageSync('userInfo');
    let isLogin = wx.getStorageSync('isLogin');
    // console.log(userInfo.flag);
    // 页面显示
    if (userInfo && isLogin) {
      //userInfo.flag = true;
      this.setData({
        userInfo: userInfo,
        isLogin: isLogin
      });
    } else {
      //未登录信息
      this.setData({
        userInfo: {},
        isLogin: false
      });
    }
  },

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

  },

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

  },

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

  },

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

  },

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

  },
  goCharginglog(e) {
    if (!this.data.isLogin) {
      let url = `/pages/login/phone_login/phone_login`;
      wx.navigateTo({
        url
      });
      return;
    }
    let url = '/pages/ucenter/charginglog/charginglog'
    wx.navigateTo({
      url
    });
  },
  goChargemoneylog(e) {
    if (!this.data.isLogin) {
      let url = `/pages/login/phone_login/phone_login`;
      wx.navigateTo({
        url
      });
      return;
    }
    let url = '/pages/ucenter/chargemoneylog/chargemoneylog'
    wx.navigateTo({
      url
    });
  },
  goyuyt(e){
    if (!this.data.isLogin) {
      let url = `/pages/login/phone_login/phone_login`;
      wx.navigateTo({
        url
      });
      return;
    }
    let url = '/pages/ucenter/yuyt/yuyt'
    wx.navigateTo({
      url
    });

  },
  gozhanw(e){
    if (!this.data.isLogin) {
      let url = `/pages/login/phone_login/phone_login`;
      wx.navigateTo({
        url
      });
      return;
    }
    let url = '/pages/ucenter/zhanw/zhanw'
    wx.navigateTo({
      url
    });

  },
  goPurse(e) {
    if (!this.data.isLogin) {
      let url = `/pages/login/phone_login/phone_login`;
      wx.navigateTo({
        url
      });
      return;
    }
    let url = '/pages/ucenter/purse/purse'
    wx.navigateTo({
      url
    });
  },
  goCar(e) {
    if (!this.data.isLogin) {
      let url = `/pages/login/phone_login/phone_login`;
      wx.navigateTo({
        url
      });
      return;
    }
    let url = '/pages/ucenter/car/car'
    wx.navigateTo({
      url
    });
  },
  goMyChargeSation(e) {
    let url = '/pages/ucenter/mychargestation/mychargestation'
    wx.navigateTo({
      url
    });
  },
  goChargpileMonitor(e) {
    let url = '/pages/ucenter/chargpilemonitor/chargpilemonitor'
    wx.navigateTo({
      url
    });
  },
  goMyWorksheet(e) {
    let url = '/pages/ucenter/myworksheet/myworksheet'
    wx.navigateTo({
      url
    });
  },
  goAccountSecrity(e){
    if (!this.data.isLogin) {
      let url = `/pages/login/phone_login/phone_login`;
      wx.navigateTo({
        url
      });
      return;
    }
    if (this.phoneCheck()) {
      let url = '/pages/ucenter/accountsecurity/index/index'
      wx.navigateTo({
        url
      });
    }
  },
  goAgreement(){
    let url = '/pages/agreement/list'
    wx.navigateTo({
      url
    });
  },
  goHelp(){
    // wx.downloadFile({
    //   //url: getApp().globalData.postHeadAgreement + '/restapi/wechat/updateUser',//要预览的PDF的地址
    //   url: 'http://localhost:8080/aiconfig/index/downloadTest',//要预览的PDF的地址
    //   success: function (res) {
    //     console.log(res);
    //     if (res.statusCode === 200) {                     //成功
    //       var Path = res.tempFilePath                     //返回的文件临时地址，用于后面打开本地预览所用
    //       wx.openDocument({
    //         filePath: Path,                               //要打开的文件路径
    //         success: function (res) {
    //           console.log('打开PDF成功');
    //         }
    //       });
    //     }
    //   },
    //   fail: function (res) {
    //     console.log(res);                                  //失败
    //   }
    // });
    let url = '/pages/ucenter/help/help'
    wx.navigateTo({
      url
    });
  },
  goNotice(){
    if (!this.data.isLogin) {
      let url = `/pages/login/phone_login/phone_login`;
      wx.navigateTo({
        url
      });
      return;
    }
    let url = '/pages/ucenter/notice/notice'
    wx.navigateTo({
      url
    });
  },
  toindex(e) {
    let url = '/pages/index/index';
    // wx.reLaunch({
    //   url
    // });
    wx.navigateBack();
  },
  goCarControl(){
    wx.navigateTo({
        url: '/pages/ucenter/control/carControl',
      })
  },
  goBatteryControl(){
    // wx.scanCode({
    //     success (res) {
    //       wx.navigateTo({
    //         url: '/pages/ucenter/control/batteryControl?code=' +  res.result,
    //       })
    //     }
    //   })
      wx.navigateTo({
        url: '/pages/ucenter/control/batteryControl',
      })
  }
  /*,
  goLogin: function() {
    wx.navigateTo({
      url: '/pages/auth/tologin/tologin?from=ucenter',
    })
  },
  callService: function () {
    wx.makePhoneCall({
      phoneNumber: '17621230884'
    })
  },
  afterSale: function () {
    wx.showModal({
      title: '提示',
      content: '请在官网或APP中申请售后',
      showCancel: false,
      confirmColor: '#b4282d',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  toLogin: function () {
    wx.navigateTo({
      url: '/pages/auth/tologin/tologin',
    })
  },
  toOrder: function () {
    if (this.data.isLogin) {
      wx.navigateTo({
        url: '/pages/ucenter/order/order',
      })
    } else {
      this.toLogin()
    }
  },
  toCoupon: function () {
    if (this.data.isLogin) {
      wx.navigateTo({
        url: '/pages/ucenter/coupon/coupon',
      })
    } else {
      this.toLogin()
    }
  },
  toAddress: function () {
    if (this.data.isLogin) {
      wx.navigateTo({
        url: '/pages/ucenter/address/address',
      })
    } else {
      this.toLogin()
    }
  }*/
})