// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    basicList: [{
        name: '我的房屋',
        url: '/page/mine/pages/myhouse/index',
        image: "http://ro7r875ut.hn-bkt.clouddn.com/myhouse.png"
      },
      {
        name: '我的车位',
        url: "/page/mine/pages/mypaking/paking",
        image: "http://ro7r875ut.hn-bkt.clouddn.com/mypaking.png"
      },
      {
        name: '我的爱车',
        url: "/page/mine/pages/mycar/mycar",
        image: "http://ro7r875ut.hn-bkt.clouddn.com/mycar.png"
      },
      {
        name: '生活缴费',
        url: "/page/mine/pages/livingPay/index",
        image: "http://ro7r875ut.hn-bkt.clouddn.com/livingpayment.png"
      },
    ],
    otherList: [{
        name: '楼栋管家',
        url: "/page/mine/pages/manager/manager",
        image: "http://ro7r875ut.hn-bkt.clouddn.com/buildingmanager.png"
      },
      {
        name: '我的预约',
        url: "/page/mine/pages/myappointment/myappointment",
        image: "http://ro7r875ut.hn-bkt.clouddn.com/yuyue.png"
      },
      {
        name: '设置',
        url: '/page/mine/pages/setting/index',
        image: "http://ro7r875ut.hn-bkt.clouddn.com/setting.png"
      },
      {
        name: '帮助中心',
        click: "helpCenter",
        image: "http://ro7r875ut.hn-bkt.clouddn.com/help.png"
      },
    ],
    userInfo: {},
    phone: "",
    hasUserInfo: false,
    canIUseOpenData: false,
    tabbar: {},
    authentication: false
  },

  onLoad() {
    getApp().watch('unreadCountMine',this.watchBack);
    app.editTabbar();
    if (wx.getStorageSync('userInfo')) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  watchBack(name, value) {
    let data = {};
    data[name] = value;
    this.setData(data);
  },
  getUserProfile(e) {
    wx.getUserProfile({
      desc: '展示用户信息',
      success: (res) => {
        wx.navigateTo({
          url: '/page/mine/login/login',
        })
      }
    })
  },
  onShow() {
    const that = this;
    let {
      authentication
    } = app.globalData;
    this.setData({
      authentication
    })
    wx.getStorage({
      key: 'userInfo',
      success(res) {
        let phone = res.data.phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
        that.setData({
          userInfo: res.data,
          phone
        })
      }
    });
    wx.getStorage({
      key: "token",
      success(res) {
        that.setData({
          hasUserInfo: true,
        })
      },
      fail(res) {
        that.setData({
          hasUserInfo: false
        })
      }
    })
  },
  getUserInfo(e) {
    app.globalData.user_encrypt = e.detail.encryptedData
    app.globalData.user_iv = e.detail.iv
  },
  // 事件处理函数
  handleContact(e) {
    console.log(e.detail.path)
    console.log(e.detail.query)
  }
})