// pages/personal/personal.js
const app = getApp();
const util = require('../../utils/util');
let WebIM = require("../../utils/WebIM")["default"];

Page({

    /**
     * 页面的初始数据
     */
    data: {
        imgPath: app.globalData.imgPath,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let userInfo = wx.getStorageSync('userInfo');
        let roleInfo = wx.getStorageSync('roleInfo');
        this.setData({
            photo: userInfo.headImgUrl,
            username: userInfo.usernameShow,
            roleName: roleInfo.name,
        });
    },

    /**
     * 退出登录
     */
    logout: function () {
        wx.showModal({
            content: '确定退出登录',
            success: (res) => {
                console.log(res)
                if (res.confirm) {
                    wx.clearStorageSync();
                    WebIM.conn.close();
                    wx.reLaunch({
                        url: '../login/login',
                    });
                }
            }
        });
    },

    /**
     * 打开关于页
     */
    about: function () {
        wx.navigateTo({
            url: '../personal-about/personal-about',
        });
    },

    /**
     * 编辑个人信息
     */
    editInfo: function () {
        wx.navigateTo({
            url: '../personal-edit/personal-edit?nickName=' + this.data.username,
        });
    }

})