var e = require("./utils/network.js");

require("./utils/util.js");

App({
    onLaunch: function() {
        wx.login({
            success: function(s) {
                if (s.code) {
                    var o = s.code;
                    wx.getSetting({
                        success: function(s) {
                            s.authSetting["scope.userInfo"] || wx.authorize({
                                scope: "scope.userInfo",
                                success: function() {
                                    wx.getUserInfo ? wx.getUserInfo({
                                        success: function(s) {
                                            wx.showToast({
                                                title: "加载中",
                                                icon: "loading",
                                                duration: 1500,
                                                mask: !0
                                            });
                                            var t = s.userInfo;
                                            wx.setStorage({
                                                key: "userInfo",
                                                data: t
                                            }), wx.getStorage({
                                                key: "userInfo",
                                                success: function(s) {
                                                    console.log(s), e.POST({
                                                        url: "User/register",
                                                        header: "application/x-www-form-urlencoded",
                                                        params: {
                                                            code: o,
                                                            nickname: s.data.nickName,
                                                            headimg: s.data.avatarUrl
                                                        },
                                                        success: function(e) {
                                                            var s = e.data.ouid;
                                                            wx.setStorage({
                                                                key: "ouid",
                                                                data: s,
                                                                success: function(e) {
                                                                    console.log(e), wx.hideToast(), wx.showToast({
                                                                        title: "登录成功!",
                                                                        icon: "success",
                                                                        mask: !0,
                                                                        duration: 1e3
                                                                    });
                                                                }
                                                            });
                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    }) : wx.showToast({
                                        title: "版本过低",
                                        icon: "none"
                                    });
                                },
                                fail: function() {
                                    var e = new Object();
                                    e.userid = "", wx.setStorage({
                                        key: "userInfo",
                                        data: e
                                    });
                                }
                            }), wx.hideToast();
                        }
                    });
                }
            }
        });
    },
    uploadimg: function(e) {
        var s = this, o = e.i ? e.i : 0, t = e.success ? e.success : 0, a = e.fail ? e.fail : 0;
        wx.uploadFile({
            url: e.url,
            filePath: e.path[o],
            name: "logo",
            formData: {
                id: e.id
            },
            success: function(e) {
                t++;
            },
            fail: function(e) {
                a++;
            },
            complete: function(i) {
                ++o == e.path.length || (e.i = o, e.success = t, e.fail = a, s.uploadimg(e));
            }
        });
    }
});