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

Page({
    data: {
        currentIndex: 3,
        user: {
            chatHeads: "https://wx.qlogo.cn/mmopen/vi_32/GhKAicgjqaCK1oZDfibe4ciaBWicWDnMFqibzWU0qp5diaE8tatUQCyTpDvlJIHJTbVprC1Dbwjh5WkWcgdmlO4VicJ8w/132",
            name: "微信昵称微信昵称微微信微信昵称微信昵称微微信",
        },
        isLogin: false,
        listData: [
            {
                title: "我发布的需求",
                code: "my-release",
            },
            {
                title: "我收藏的需求",
                code: "my-collect",
            },
            {
                title: "我关注的类型",
                code: "my-attention",
            },
            {
                title: "联系客服",
                code: "my-contact",
            },
        ],
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (app.globalData.businessCommunicationCustomer) {
            this.setData({
                user: app.globalData.businessCommunicationCustomer,
                isLogin: true
            })
            console.log(`------------------当前登录用户-----------------------`)
            console.log(app.globalData.businessCommunicationCustomer);
            console.log(`------------------当前登录用户-----------------------`)
        }
    },
    onShow() {
        this.setData({
            currentIndex: 3
        })
    },
    // 前往登录页
    goLogin(e) {
        app.goLogin();
    },
    //  路由跳转
    goRouterPage(e) {
        let code = e.currentTarget.dataset.code;
        let customerid = this.data.user.customerId;
        if (!customerid && code != 'my-contact') {
            app.goLogin();
            return
        }
        let url = "";
        // 前往主页
        if (code == 'homepage') {
            url = "/pages/index/components/homepage/homepage";
        }
        // 前往发布的需求
        if (code == 'my-release') {
            url = "/pages/myModule/components/myRelease/myRelease";
        }
        // 前往收藏的需求
        if (code == 'my-collect') {
            url = "/pages/myModule/components/myCollect/myCollect";
        }
        // 前往关注的类型
        if (code == 'my-attention') {
            url = "/pages/myModule/components/myAttention/myAttention";
        }
        // 前往联系客服
        if (code == 'my-contact') {
            url = "/pages/outLink/outLink";
        }
        wx.navigateTo({
            url,
            success: function (res) {
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('customerid', { customerid })
            }
        })
    },
    // 退出登录
    exitLogin() {
        let _this = this;
        wx.showModal({
            title: '提示',
            content: "是否确认退出账号？",
            confirmText: "确认",
            cancelText: "取消",
            success(res){
                if (res.confirm) {
                    wx.removeStorageSync('userInfo');
                    wx.removeStorageSync('businessCommunicationCustomer');
                    app.globalData.businessCommunicationCustomer = null;
                    app.globalData.customerId = null;
                    _this.setData({
                        user: {},
                        isLogin: false
                    })
                }
            }
        })
    },
    /**
    * 用户点击右上角分享给朋友
    */
    onShareAppMessage() {
        return {
            title: "分享你一个需求交流平台！推荐你一起来关注~",
            imageUrl: '/images/home/ShareApp-index.png',
            path: 'pages/index/index'
        }
    },
})