// 账号与安全页面逻辑
Page({
  /**
   * 页面的初始数据
   */
  data: {
    phone: '+86 18500006666',
    wechatStatus: '已绑定',
    email: 'annabk666@gmail.com',
    // 初始化默认值，避免null导致的错误
    menuButtonInfo: {
      height: 32, // 默认高度
      width: 32,  // 默认宽度
      top: 0
    },
    statusBarHeight: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

    try {
      // 获取系统信息，用于导航栏定位
      const systemInfo = wx.getSystemInfoSync();
      const menuButtonInfo = wx.getMenuButtonBoundingClientRect();

      this.setData({
        statusBarHeight: systemInfo.statusBarHeight,
        menuButtonInfo: menuButtonInfo,
        // 计算导航栏高度 = 胶囊按钮底部距离 - 状态栏高度
        navbarHeight: menuButtonInfo.bottom - systemInfo.statusBarHeight
      });
    } catch (error) {
      console.error('获取系统信息失败:', error);
      // 如果获取失败，使用默认值
      this.setData({
        statusBarHeight: 20,
        navbarHeight: 44
      });
    }
  },

  /**
   * 返回上一页
   */
  navigateBack: function() {
    wx.navigateBack({
      delta: 1
    });
  },

  /**
   * 查看手机号码
   */
  viewPhone: function() {
    wx.showModal({
      title: '手机号码',
      content: this.data.phone,
      showCancel: false
    });
  },

  /**
   * 查看微信绑定
   */
  viewWechat: function() {
    wx.showModal({
      title: '微信绑定',
      content: '您的账号已绑定微信',
      showCancel: false
    });
  },

  /**
   * 查看邮箱
   */
  viewEmail: function() {
    wx.showModal({
      title: '邮箱',
      content: this.data.email,
      showCancel: false
    });
  },

  /**
   * 推荐给好友
   */
  recommendToFriend: function() {
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    });
  },

  /**
   * 查看已屏蔽账户
   */
  viewBlockedAccounts: function() {
    wx.navigateTo({
      url: '/subpackages/settings/account-security/account-security?tab=blocked'
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      title: 'FindMe - 账号与安全',
      path: '/subpackages/settings/account-security/account-security'
    };
  }
});
