var e = require("../../../49539051658710DF2F35F8564970FAA0.js"), t = getApp(), o = wx.cloud.database(), a = o.command, i = o.command.aggregate;

Page({
    data: {
        id: "",
        programs: [],
        competition: {},
        averageScores: [],
        juries: [],
        loadmore: "",
        isWorker: !1,
        editedAward: !1,
        orderBy: "index",
        notice: "",
        watcherCompetition: "",
        watcherInterval: 1e3,
        calculateScoresByJuriesGroups: !1,
        platform: "",
        idProgramSettingExtraPoints: "",
        programExtraPoints: 0,
        extraPointsMaskStatus: !1,
        contactServiceView: !1,
        config_rechargeable: !1,
        user_vip: !1
    },
    onLoad: function(e) {
        var i = this;
        this.data.id = e.id || e.scene, wx.showLoading({
            title: "计算实时成绩"
        }), o.collection("_config").where({
            _id: "config"
        }).field({
            v: !0,
            rechargeable: !0
        }).get().then(function(e) {
            i.data.config_rechargeable = e.data.rechargeable, i.setData({
                c: t.globalData.c,
                v: e.data[0].v,
                platform: t.globalData.platform,
                openid: t.globalData.openid
            });
        }).catch(function(e) {
            console.error(e);
        }), o.collection("users").where({
            _openid: t.globalData.openid,
            vipExpiryTime: a.gt(o.serverDate())
        }).count().then(function(e) {
            1 == e.total && (i.data.user_vip = !0);
        }).catch(function(e) {
            console.log(e);
        });
    },
    onShow: function() {
        this.getCompetition();
    },
    getCompetition: function() {
        var a = this;
        o.collection("competitions").doc(this.data.id).field({
            title: !0,
            startTime: !0,
            site: !0,
            sponsor: !0,
            organizer: !0,
            juries: !0,
            poster: !0,
            status: !0,
            rechargeable: !0,
            rule: !0,
            workers: !0,
            juriesGroups: !0,
            settings: !0,
            posterSize: !0
        }).get().then(function(o) {
            var i = o.data;
            i.startTime = e.formatTime("short", i.startTime);
            var r = "oRnCI5JYWT9dmVycOnBjYaX1Yx7k" == t.globalData.openid || "oRnCI5GgJ8Kc3sGye-ungAdL7r4U" == t.globalData.openid || "example" == i._id || i.workers.indexOf(t.globalData.openid) >= 0;
            a.data.isWorker = r, a.data.competition = i, a.setData({
                v: i.settings && !i.settings.showVote ? "0.0.0" : a.data.v,
                competition: i,
                isWorker: r
            }), "windows" != t.globalData.platform && "mac" != t.globalData.platform || wx.setNavigationBarTitle({
                title: i.title
            }), r || "已删除" != i.status && "已关闭" != i.status ? 0 == i.programsTotal ? (wx.hideLoading(), 
            wx.stopPullDownRefresh(), that.setData({
                loadmore: "暂未添加参赛者"
            })) : (a.getAwards(), a.watcherCompetition()) : (wx.hideLoading(), wx.showModal({
                content: "主办方" + i.status + "比赛，或联系工作人员",
                showCancel: !1,
                confirmColor: "#FF5A5F",
                confirmText: "我知道了",
                success: function(e) {
                    wx.reLaunch({
                        url: "/pages/index/index"
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            }));
        }).catch(function(t) {
            e.competitionNoExistShowModal(t.errCode);
        });
    },
    watcherCompetition: function() {
        var e = this;
        wx.getSystemInfo({
            success: function(t) {
                var a = t.platform;
                "windows" != a && (e.data.watcherCompetition = o.collection("competitions").doc(e.data.id).watch({
                    onChange: function(t) {
                        1 == t.docs.length && "init" != t.type && (t.docChanges[0].updatedFields.behaviors || t.docChanges[0].updatedFields.juriesGroups || t.docChanges[0].updatedFields.rules) && e.getJuries(t.docs[0].juries);
                    },
                    onError: function(t) {
                        setTimeout(function() {
                            e.watcherCompetition();
                        }, e.data.watcherInterval), o.collection("_errorsWatcher").add({
                            data: {
                                competition_id: e.data.id,
                                desc: "watcherCompetitionError",
                                page: "newestScores",
                                platform: a,
                                interval: e.data.watcherInterval,
                                createtime: o.serverDate()
                            }
                        }).then(function(e) {}).catch(console.error), e.data.watcherInterval = e.data.watcherInterval + 1e3;
                    }
                }));
            }
        });
    },
    getAwards: function() {
        var e = this;
        o.collection("awards").aggregate().match({
            competition_id: this.data.id
        }).group({
            _id: null,
            awards: i.addToSet({
                _id: "$_id",
                index: "$index",
                title: "$title",
                competition_id: "$competition_id",
                prizeWinners: "$prizeWinners"
            })
        }).end().then(function(t) {
            var o = t.list.length >= 1 ? t.list[0].awards : [];
            o.sort(function(e, t) {
                return e.index - t.index;
            }), e.data.awards = o, e.getJuries(e.data.competition.juries), e.setData({
                awards: o
            });
        }).catch(console.error);
    },
    getJuries: function(e) {
        var t = this;
        o.collection("users").aggregate().addFields({
            matched: i.in([ "$_openid", e ])
        }).match({
            matched: !0
        }).group({
            _id: null,
            juries: i.addToSet({
                _openid: "$_openid",
                avatarUrl: "$avatarUrl",
                authorized: "$authorized",
                nickName: "$nickName",
                realName: "$realName"
            })
        }).end().then(function(e) {
            t.data.juries = e.list.length >= 1 ? e.list[0].juries : [], t.getPrograms();
        });
    },
    getPrograms: function() {
        var t = this;
        o.collection("programs").aggregate().match({
            competition_id: t.data.id
        }).group({
            _id: null,
            programs: i.addToSet({
                _id: "$_id",
                averageScore: "$averageScore",
                awards: "$awards",
                competition_id: "$competition_id",
                index: "$index",
                note: "$note",
                scores: "$scores",
                title: "$title",
                votesTotal: "$votesTotal",
                judging: "$judging",
                extraPoints: "$extraPoints",
                comments: "$comments"
            })
        }).end().then(function(a) {
            for (var i = a.list.length >= 1 ? a.list[0].programs : [], r = t.data.competition, n = t.data.juries, s = t.data.awards, c = t.data.editedAward, d = !0, l = !1, u = [], h = "", g = 0; g < i.length; g++) {
                if (r.juriesGroups && r.juriesGroups.length >= 1) for (var p = 0; p < r.juriesGroups.length; p++) r.juriesGroups[p].scores = [];
                for (var m = 0; m < i[g].scores.length; m++) {
                    var w = m, f = i[g].scores[m]._openid;
                    if (-1 == JSON.stringify(n).indexOf(i[g].scores[m]._openid)) i[g].scores.splice(m, 1), 
                    m--, t.addError({
                        competition_id: i[g].competition_id,
                        program_id: i[g]._id,
                        program_index: i[g].index,
                        score_index: w,
                        score_openid: f,
                        desc: "非评委提交分数"
                    }); else for (var x = m + 1; x < i[g].scores.length; x++) i[g].scores[m]._openid == i[g].scores[x]._openid && (i[g].scores.splice(x, 1), 
                    x--, t.addError({
                        competition_id: i[g].competition_id,
                        program_id: i[g]._id,
                        program_index: i[g].index,
                        score_index: w,
                        score_openid: f,
                        desc: "评委重复提交分数"
                    }));
                }
                var v = 0, _ = 0, S = {
                    averageScore: 0,
                    totalScore: 0
                };
                if (i[g].scores.length > 0) {
                    for (var T = [], P = 0; P < i[g].scores.length; P++) if (T.push(i[g].scores[P].score), 
                    r.juriesGroups && r.juriesGroups.length >= 1) for (var j = 0; j < r.juriesGroups.length; j++) JSON.stringify(r.juriesGroups[j].juriesDetails).indexOf(i[g].scores[P]._openid) >= 0 && r.juriesGroups[j].scores.push(i[g].scores[P].score);
                    if (i[g].scores.sort(function(e, t) {
                        return t.score - e.score;
                    }), T.sort(function(e, t) {
                        return t - e;
                    }), i[g].arrScores = T.join("/"), r.juriesGroups && r.juriesGroups.length >= 1) {
                        for (var F = 0; F < r.juriesGroups.length; F++) S = e.calculateScores(r.juriesGroups[F].scores, r.rule.decimalPlaces, r.juriesGroups[F].lowestScoresExcludedTotal, r.juriesGroups[F].topScoresExcludedTotal), 
                        v += parseFloat(S.averageScore) * r.juriesGroups[F].weight, _ += parseFloat(S.totalScore) * r.juriesGroups[F].weight;
                        l = !0;
                    } else S = e.calculateScores(T, r.rule.decimalPlaces, r.rule.lowestScoresExcludedTotal, r.rule.topScoresExcludedTotal), 
                    v = parseFloat(S.averageScore), _ = parseFloat(S.totalScore);
                } else i[g].arrScores = [];
                v += i[g].extraPoints, _ += i[g].extraPoints, v = parseFloat(v.toFixed(r.rule.decimalPlaces)), 
                _ = parseFloat(_.toFixed(r.rule.decimalPlaces)), u.push(v), i[g].scores.length == n.length && i[g].averageScore != v && o.collection("programs").doc(i[g]._id).update({
                    data: {
                        averageScore: v
                    }
                }).then(function(e) {}), i[g].averageScore = v, i[g].totalScore = _, i[g].unjudgedJuries = [];
                for (var C = function(e) {
                    var o = n.findIndex(function(t) {
                        return t._openid == n[e]._openid;
                    });
                    if (n[o].avatarUrl = n[o].authorized || n[o].avatarUrl ? n[o].avatarUrl : "/images/user-unlogin.png", 
                    n[o].nickName = n[o].authorized || n[o].nickName ? n[o].nickName : "该评委未授权微信登录", 
                    n[o].realName = n[o].authorized || n[o].realName ? n[o].realName : "", -1 == JSON.stringify(i[g].scores).indexOf(n[e]._openid)) o >= 0 && (n[o].authorized || "example" != t.data.id) && i[g].unjudgedJuries.push({
                        avatarUrl: n[o].avatarUrl,
                        nickName: n[o].nickName,
                        realName: n[o].realName
                    }); else for (var a = 0; a < i[g].scores.length; a++) i[g].scores[a]._openid == n[e]._openid && (i[g].scores[a].avatarUrl = n[o].avatarUrl, 
                    i[g].scores[a].nickName = n[o].nickName, i[g].scores[a].realName = n[o].realName);
                }, D = n.length - 1; D >= 0; D--) C(D);
                0 != n.length && i[g].scores.length == n.length && "已结束" != r.status && "已删除" != r.status && "已关闭" != r.status || (d = !1);
            }
            u.sort(function(e, t) {
                return t - e;
            });
            for (var b = function(e) {
                if (i[e].averageScore > 0) {
                    var t = u.indexOf(i[e].averageScore) + 1;
                    i[e].order = t;
                } else i[e].order = 1e3;
                if (i[e].awards) for (var o = function(t) {
                    var o = s.findIndex(function(o) {
                        return i[e].awards[t].award_id == o._id;
                    });
                    o >= 0 && (i[e].awards[t].title = c ? s[o].title + (c ? " X" : "") : s[o].title);
                }, a = 0; a < i[e].awards.length; a++) o(a); else i[e].awards = [];
            }, k = 0; k < i.length; k++) b(k);
            if (i.sort(function(e, t) {
                return e.index - t.index;
            }), n.length < 100 && wx.getStorageSync("hideNoticeBarId").competition_id != t.data.id) for (var y = 0; y < i.length; y++) "" == h && i[y].judging && 0 != i[y].index && "已关闭" != r.status && i[y].unjudgedJuries.length > 0 && 2 * i[y].unjudgedJuries.length <= n.length && i[y].scores.length > 0 && "example" != t.data.id && (h = "#系统提示#序号为" + i[y].index + "的参赛者还有" + i[y].unjudgedJuries.length + "位评委未评分，请工作人员提醒评委及时提交分数！");
            "order" != t.data.orderBy && "votes" != t.data.orderBy || i.sort(function(e, t) {
                return e.order - t.order;
            }), "votes" == t.data.orderBy && i.sort(function(e, t) {
                return t.votesTotal - e.votesTotal;
            });
            var G = 0 == t.data.programs.length ? i : t.data.programs;
            if (wx.hideLoading(), wx.stopPullDownRefresh(), n.length <= 200) for (var A = 0; A < i.length; A++) if (!t.data.removeProgramScores && (G[A].scores.length != i[A].scores.length || G[A].averageScore != i[A].averageScore || G.length != i.length)) {
                wx.showToast({
                    title: "序号" + i[A].index + "最新成绩",
                    icon: "none",
                    duration: 1e3
                });
                break;
            }
            t.setData({
                programs: i,
                loadmore: 0 == i.length ? "暂未添加参赛者" : "全部加载",
                averageScores: u,
                orderBy: t.data.orderBy,
                notice: h,
                calculateScoresByJuriesGroups: l
            }), wx.setStorageSync("newestScores", {
                competition: r,
                programs: i,
                loadmore: 0 == i.length ? "暂未添加参赛者" : "全部加载",
                averageScores: u,
                orderBy: t.data.orderBy,
                calculateScoresByJuriesGroups: l
            }), t.data.removeProgramScores = !1, d && 0 != t.data.programs && wx.cloud.callFunction({
                name: "competition",
                data: {
                    competition: {
                        _id: r._id,
                        status: "已结束"
                    },
                    operation: "update"
                }
            }).then(function(e) {});
        }).catch(console.error);
    },
    addError: function(e) {
        "example" != e.competition_id && o.collection("_errorsScore").where(e).count().then(function(t) {
            0 == t.total ? (e.createtime = o.serverDate(), o.collection("_errorsScore").add({
                data: e
            }).then(function(e) {
                console.log("addError", e);
            }).catch(console.error)) : console.log("errorData已经存在");
        }).catch(console.error);
    },
    onHide: function() {
        this.data.watcherAwards && this.data.watcherAwards.close(), this.data.watcherCompetition && this.data.watcherCompetition.close();
    },
    onUnload: function() {
        this.data.watcherAwards && this.data.watcherAwards.close(), this.data.watcherCompetition && this.data.watcherCompetition.close();
    },
    addAward: function(e) {
        var i = this.data.awards, r = this.data.programs, n = e.currentTarget.dataset.program, s = e.detail.value, c = r.findIndex(function(e) {
            return n._id == e._id;
        });
        "example" == this.data.competition._id ? wx.showToast({
            title: "比赛示例不支持添加奖项",
            icon: "none",
            duration: 1e3
        }) : this.data.competition.workers.indexOf(t.globalData.openid) >= 0 ? r[c].awards.findIndex(function(e) {
            return i[s]._id == e.award_id;
        }) >= 0 ? wx.showToast({
            title: "重复添加奖项",
            icon: "none",
            duration: 2e3
        }) : (this.data.editedAward = !0, wx.showLoading({
            title: "正在提交",
            mask: !0
        }), o.collection("programs").doc(n._id).update({
            data: {
                awards: a.push({
                    award_id: i[s]._id,
                    title: i[s].title
                })
            }
        }).then(function(e) {
            wx.showToast({
                title: "已添加奖项",
                icon: "success",
                duration: 2e3
            }), wx.cloud.callFunction({
                name: "behavior",
                data: {
                    competition_id: n.competition_id,
                    behavior: "29设置获奖"
                }
            }).then(function(e) {
                console.log("29设置获奖", e);
            });
        })) : wx.showToast({
            title: "仅工作人员有权限",
            icon: "none",
            duration: 1500
        });
    },
    deleteProgramAward: function(e) {
        if ("example" == this.data.competition._id) wx.showToast({
            title: "比赛示例的参赛者不能使用此操作",
            icon: "none",
            duration: 1e3
        }); else if (this.data.competition.workers.indexOf(t.globalData.openid) >= 0) {
            var i = e.currentTarget.dataset.program, r = e.currentTarget.dataset.idxaward, n = this;
            wx.showActionSheet({
                itemList: [ "删除奖项" ],
                itemColor: "#767676",
                success: function(e) {
                    switch (e.tapIndex) {
                      case 0:
                        wx.showLoading({
                            title: "正在提交",
                            mask: !0
                        }), o.collection("programs").doc(i._id).update({
                            data: {
                                awards: a.pull({
                                    award_id: a.eq(i.awards[r].award_id)
                                })
                            }
                        }).then(function(e) {
                            n.getPrograms(), wx.showToast({
                                title: "已删除奖项",
                                icon: "success",
                                duration: 1500
                            }), console.log("deleteProgramAward", e);
                        }).catch(console.error);
                    }
                }
            });
        }
    },
    viewProgramDetails: function(e) {
        var t = this.data.competition, o = this.data.calculateScoresByJuriesGroups, a = this.data.juries;
        wx.navigateTo({
            url: "/pages/competition/newestScores/programDetails/programDetails",
            success: function(i) {
                i.eventChannel.emit("acceptDataFromOpenerPage", {
                    competition: t,
                    calculateScoresByJuriesGroups: o,
                    program: e.currentTarget.dataset.program,
                    juries: a
                });
            }
        });
    },
    editJudgingStatus: function(e) {
        if ("example" == this.data.competition._id) wx.showToast({
            title: "比赛示例的参赛者不能使用此操作",
            icon: "none",
            duration: 1e3
        }); else {
            var a = this.data.competition, i = e.currentTarget.dataset.program;
            if (a.workers.indexOf(t.globalData.openid) >= 0) {
                var r = this;
                wx.showModal({
                    title: "序号" + i.index + ":" + i.title,
                    content: i.judging ? "暂停评委提交成绩吗？" : "允许评委继续提交成绩吗？",
                    cancelColor: "#484848",
                    cancelText: "取消",
                    confirmColor: "#FF5A5F",
                    confirmText: "确定",
                    success: function(e) {
                        e.confirm && (wx.showLoading({
                            title: "正在处理",
                            mask: !0
                        }), o.collection("programs").doc(i._id).update({
                            data: {
                                judging: !i.judging
                            }
                        }).then(function(e) {
                            r.getPrograms(), wx.hideLoading(), i.judging ? wx.showToast({
                                title: "暂停提交",
                                icon: "success",
                                duration: 1500
                            }) : wx.showModal({
                                showCancel: !1,
                                title: "重要提醒",
                                content: "已允许评委继续提交该参赛者分数，请提醒评委下拉刷新后提交分数。",
                                confirmColor: "#FF5A5F",
                                confirmText: "我知道了"
                            });
                        }).catch(console.error));
                    },
                    fail: function(e) {
                        console.log(e);
                    }
                });
            } else wx.showToast({
                title: "仅工作人员有权限",
                icon: "none",
                duration: 1500
            });
        }
    },
    showActionSheet: function(e) {
        if ("example" == this.data.competition._id) wx.showToast({
            title: "比赛示例的参赛者不能使用此操作",
            icon: "none",
            duration: 1e3
        }); else {
            var a = this.data.competition, i = e.currentTarget.dataset.program;
            if (a.workers.indexOf(t.globalData.openid) >= 0) {
                var r = this;
                wx.showActionSheet({
                    itemList: [ "设置加分或扣分", "删除该参赛者所有已评分数", "删除某位评委已评分数", "删除该参赛者" ],
                    itemColor: "#767676",
                    success: function(e) {
                        switch (e.tapIndex) {
                          case 0:
                            r.data.idProgramSettingExtraPoints = i._id, r.setData({
                                extraPointsMaskStatus: !0,
                                programExtraPoints: i.extraPoints
                            });
                            break;

                          case 1:
                            wx.showModal({
                                title: "序号" + i.index + ":" + i.title,
                                content: "确认清除该参赛者所有已评分数吗？比赛中清除分数后需要所有评委重新对该参赛者评分。",
                                cancelColor: "#484848",
                                cancelText: "取消",
                                confirmColor: "#FF5A5F",
                                confirmText: "确定",
                                success: function(e) {
                                    e.confirm && (wx.showLoading({
                                        title: "正在清除",
                                        mask: !0
                                    }), o.collection("programs").doc(i._id).update({
                                        data: {
                                            scores: [],
                                            judging: !0,
                                            averageScore: 0
                                        }
                                    }).then(function(e) {
                                        r.data.removeProgramScores = !0, r.getPrograms(), wx.hideLoading(), wx.showModal({
                                            showCancel: !1,
                                            title: "重要提醒",
                                            content: "该参赛者分数已清除，请提醒评委在评分页面中下拉刷新后重新提交分数。",
                                            confirmColor: "#FF5A5F",
                                            confirmText: "我知道了"
                                        });
                                    }).catch(console.error));
                                },
                                fail: function(e) {
                                    console.log(e);
                                }
                            });
                            break;

                          case 2:
                            wx.showModal({
                                title: "删除某位评委已评分数",
                                content: "进入“评分详情”后点击需要删除的分数，确认后即可删除，删除后需要提醒该评委在评分页面中下拉刷新后重新提交分数。",
                                showCancel: !1,
                                confirmColor: "#FF5A5F",
                                confirmText: "去删除",
                                success: function(e) {
                                    if (e.confirm) {
                                        var t = r.data.calculateScoresByJuriesGroups;
                                        wx.navigateTo({
                                            url: "/pages/competition/newestScores/programDetails/programDetails",
                                            success: function(e) {
                                                e.eventChannel.emit("acceptDataFromOpenerPage", {
                                                    competition: a,
                                                    calculateScoresByJuriesGroups: t,
                                                    program: i,
                                                    juries: r.data.juries
                                                });
                                            }
                                        });
                                    }
                                },
                                fail: function(e) {
                                    console.log(e);
                                }
                            });
                            break;

                          case 3:
                            wx.showModal({
                                title: "确认删除该参赛者吗？如果评委已提交过分数，将同步删除。",
                                cancelColor: "#484848",
                                cancelText: "取消",
                                confirmColor: "#FF5A5F",
                                confirmText: "确定",
                                success: function(e) {
                                    e.confirm && (wx.showLoading({
                                        title: "正在删除",
                                        mask: !0
                                    }), wx.cloud.callFunction({
                                        name: "program",
                                        data: {
                                            program: i,
                                            operation: "delete"
                                        }
                                    }).then(function(e) {
                                        wx.hideLoading(), wx.showToast({
                                            title: "删除参赛者",
                                            icon: "success",
                                            duration: 2e3
                                        }), r.data.programs = [], r.getPrograms();
                                    }));
                                },
                                fail: function(e) {
                                    console.log(e);
                                }
                            });
                        }
                    }
                });
            } else wx.showToast({
                title: "仅工作人员有权限",
                icon: "none",
                duration: 1500
            });
        }
    },
    submitExtraPoints: function(e) {
        var t = this;
        wx.showLoading({
            title: "正在提交",
            mask: !0
        });
        var a = parseFloat(e.detail.value.extraPoints);
        a >= 0 || a < 0 ? o.collection("programs").doc(this.data.idProgramSettingExtraPoints).update({
            data: {
                extraPoints: a
            }
        }).then(function(e) {
            wx.hideLoading(), wx.showToast({
                title: "已设置",
                icon: "success",
                duration: 1500
            }), t.hideExtraPointsMaskStatus(), wx.cloud.callFunction({
                name: "behavior",
                data: {
                    competition_id: t.data.competition._id,
                    behavior: "16编辑节目"
                }
            }).then(function(e) {});
        }) : wx.showToast({
            title: "请输入后再提交",
            icon: "none",
            duration: 1500
        });
    },
    hideExtraPointsMaskStatus: function() {
        this.data.idProgramSettingExtraPoints = "", this.setData({
            extraPointsMaskStatus: !1,
            programExtraPoints: 0
        });
    },
    hideNoticeBar: function() {
        wx.setStorageSync("hideNoticeBarId", {
            competition_id: this.data.competition._id
        });
    },
    onPullDownRefresh: function() {
        this.data.programs = [], this.getCompetition();
    },
    changeOrderBy: function(e) {
        switch (wx.showLoading({
            title: "切换排序",
            mask: !0
        }), this.data.orderBy) {
          case "index":
            for (var t = this.data.programs, o = !1, a = 0; a < t.length; a++) if (t[a].averageScore > 0) {
                o = !0;
                break;
            }
            o ? (this.data.orderBy = "order", this.data.programs = [], this.getPrograms()) : wx.showToast({
                title: "评委暂未提交分数",
                icon: "none",
                duration: 1500
            });
            break;

          case "order":
            this.data.c == this.data.v ? this.data.orderBy = "votes" : this.data.orderBy = "index", 
            this.data.programs = [], this.getPrograms();
            break;

          case "votes":
            this.data.orderBy = "index", this.data.programs = [], this.getPrograms();
        }
    },
    drawPoster: function() {
        var e = this.data.competition;
        wx.navigateTo({
            url: "/pages/competition/drawPoster/drawPoster",
            success: function(t) {
                t.eventChannel.emit("acceptDataFromOpenerPage", {
                    competition: e,
                    role: "newestScores"
                });
            }
        });
    },
    refreshScores: function() {
        wx.showLoading({
            title: "获取最新成绩"
        }), this.data.programs = [], this.getCompetition();
    },
    getScoresSheet: function() {
        wx.cloud.callFunction({
            name: "behavior",
            data: {
                competition_id: this.data.competition._id,
                behavior: "33导出成绩"
            }
        }).then(function(e) {}), 0 == this.data.competition.programsTotal ? wx.showToast({
            title: "未添加参赛者",
            icon: "none",
            duration: 2e3
        }) : this.data.competition.rechargeable || this.data.config_rechargeable || this.data.user_vip || "example" == this.data.competition._id ? (wx.showLoading({
            title: "正在导出成绩"
        }), wx.cloud.callFunction({
            name: "getScoresSheet",
            data: {
                id: this.data.competition._id
            }
        }).then(function(e) {
            wx.hideLoading();
            var t = e.result.scoresSheetUrl;
            wx.showModal({
                showCancel: !1,
                content: "成绩表已生成，点击复制链接后粘贴到电脑或手机浏览器下载",
                confirmColor: "#FF5A5F",
                confirmText: "复制链接",
                success: function(e) {
                    wx.setClipboardData({
                        data: t,
                        success: function(e) {
                            wx.getClipboardData({
                                success: function(e) {}
                            });
                        }
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        })) : this.setData({
            contactServiceView: !0
        });
    },
    hideContactService: function(e) {
        this.setData({
            contactServiceView: !1
        });
    },
    contactService: function(e) {
        o.collection("behaviors").add({
            data: {
                createTime: o.serverDate(),
                competition_id: this.data.competition._id,
                competition_title: this.data.competition.title,
                type: "newestScores",
                page: "competition"
            }
        }).then(function(e) {}).catch(console.error), this.setData({
            contactServiceView: !1
        });
    },
    onShareAppMessage: function() {
        return {
            title: "查看比赛实时成绩",
            path: "/pages/competition/newestScores/newestScores?id=" + this.data.competition._id
        };
    }
});