var t = require("../../provider/dataApi.js");

getApp();

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        pageData: {}
    },
    onLoad: function(t) {
        this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight
        }), this.initWechat();
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    initWechat: function() {
        var n = this;
        t.getBind({
            uid: wx.getStorageSync("uid")
        }).then(function(t) {
            console.log(t), 0 == t.errno && n.setData({
                pageData: t.data.data
            });
        }).catch(function(t) {
            console.log(t);
        });
    },
    goBindWechat: function() {
        var n = this;
        wx.showLoading({
            title: "绑定中..."
        }), wx.login({
            success: function(e) {
                console.log(e);
                var o = e.code;
                wx.getSetting({
                    success: function(e) {
                        console.log(e), e.authSetting["scope.userInfo"] && wx.getUserInfo({
                            success: function(e) {
                                console.log(e), t.login({
                                    uid: wx.getStorageSync("uid"),
                                    code: o,
                                    is_bind: 2,
                                    encryptedData: e.encryptedData,
                                    iv: e.iv
                                }).then(function(t) {
                                    console.log(t), wx.hideLoading(), wx.showToast({
                                        title: t.message,
                                        icon: "none"
                                    }), 0 == t.errno && n.initWechat();
                                }).catch(function(t) {
                                    console.log(t), wx.hideLoading(), wx.showToast({
                                        title: t.message,
                                        icon: "none"
                                    });
                                });
                            }
                        });
                    }
                });
            }
        });
    },
    goUntie: function() {
        wx.navigateTo({
            url: "../untieWechat/untieWechat"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});