var e = require("49539051658710DF2F35F8564970FAA0.js"), t = getApp(), o = wx.cloud.database();

o.command;

Page({
    data: {
        competition: {},
        maskStatus: !1,
        juriesGroupTitle: ""
    },
    onLoad: function(t) {
        var i = this;
        wx.hideShareMenu(), wx.showLoading({
            title: "正在加载",
            mask: !0
        }), o.collection("juriesGroups").doc(t.scene).get().then(function(t) {
            i.data.juriesGroupTitle = t.data.juriesGroupTitle, o.collection("competitions").doc(t.data.competition_id).field({
                juries: !0,
                status: !0,
                juriesUnfocus: !0,
                settings: !0,
                juriesGroups: !0,
                rule: !0
            }).get().then(function(e) {
                var t = e.data;
                i.data.competition = t, wx.getStorageSync("getUserProfile") || t.settings && t.settings.unAuthorizeJury ? i.addRole(t, wx.getStorageSync("openid")) : (wx.hideLoading(), 
                i.setData({
                    maskStatus: !0
                }));
            }).catch(function(t) {
                e.competitionNoExistShowModal(t.errCode);
            });
        }).catch(function(e) {
            console.error(e), -1 == e.errCode && (wx.hideLoading(), wx.stopPullDownRefresh(), 
            wx.hideShareMenu(), wx.showModal({
                showCancel: !1,
                content: "该邀请码已失效，请联系工作人员",
                confirmColor: "#FF5A5F",
                confirmText: "我知道了",
                success: function(e) {
                    wx.reLaunch({
                        url: "/pages/index/index"
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            }));
        });
    },
    getUserProfile: function() {
        var e = this;
        e.hideMaskStatus(), wx.getUserProfile({
            desc: "用于展示头像和昵称",
            lang: "zh_CN",
            success: function(o) {
                var i = o.userInfo;
                wx.setStorageSync("getUserProfile", !0), wx.showLoading({
                    title: "授权登录",
                    mask: !0
                }), wx.cloud.callFunction({
                    name: "updateUserInfo",
                    data: {
                        userInfo: i
                    }
                }).then(function(o) {
                    t.globalData.authorized = !0, t.globalData.userInfo = {
                        nickName: i.nickName,
                        avatarUrl: i.avatarUrl
                    }, e.addRole(e.data.competition, o.result.openid);
                });
            }
        });
    },
    hideMaskStatus: function(e) {
        this.setData({
            maskStatus: !1
        });
    },
    addRole: function(e, t) {
        wx.showLoading({
            title: "正在加载",
            mask: !0
        }), "已删除" == e.status || "已关闭" == e.status ? (wx.hideLoading(), wx.showModal({
            content: "主办方" + e.status + "比赛，或联系工作人员",
            showCancel: !1,
            confirmColor: "#FF5A5F",
            confirmText: "我知道了",
            success: function(e) {
                wx.reLaunch({
                    url: "/pages/index/index"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        })) : e.juries.indexOf(t) >= 0 && -1 == e.juriesUnfocus.indexOf(t) ? setTimeout(function() {
            wx.redirectTo({
                url: "/pages/competition/judge/judge?id=" + e._id
            });
        }, 1500) : wx.cloud.callFunction({
            name: "role",
            data: {
                competition: {
                    _id: e._id
                },
                juriesGroups: e.juriesGroups,
                juriesGroupTitle: this.data.juriesGroupTitle,
                operation: "addJuryByGroup",
                role: "jury"
            }
        }).then(function(t) {
            "addRole_crawler" == t.result.errMsg ? (wx.showToast({
                title: "检测到用户身份异常",
                icon: "none",
                duration: 1500
            }), setTimeout(function() {
                wx.reLaunch({
                    url: "/pages/index/index"
                });
            }, 1500)) : (wx.hideLoading(), wx.showToast({
                title: "已成为评委",
                icon: "success",
                duration: 2500
            }), setTimeout(function() {
                wx.redirectTo({
                    url: "/pages/competition/judge/judge?id=" + e._id
                });
            }, 1500));
        });
    }
});