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

e.command.aggregate;

Page({
    data: {
        competitions: "",
        loadmore: ""
    },
    onLoad: function(t) {
        wx.showLoading({
            title: "正在加载",
            mask: !0
        }), this.getCompetitions();
    },
    getCompetitions: function(n) {
        var a = this, s = this.data.competitions.length;
        e.collection("competitions").where(i.or([ i.and({
            _id: "example",
            focus: o.globalData.openid,
            status: i.and(i.neq("已删除"), i.neq("已关闭"))
        }), i.and({
            status: i.and(i.neq("已删除"), i.neq("已关闭")),
            juries: o.globalData.openid,
            juriesUnfocus: i.neq(o.globalData.openid)
        }) ])).orderBy("startTime", "desc").skip(s).field({
            title: !0,
            poster: !0,
            startTime: !0,
            site: !0,
            sponsor: !0,
            organizer: !0,
            tags: !0,
            status: !0,
            juriesUnfocus: !0,
            posterSize: !0
        }).get().then(function(o) {
            wx.hideLoading(), wx.stopPullDownRefresh();
            var e = o.data;
            if (0 == s && 0 == e.length) a.setData({
                loadmore: "未担任比赛评委"
            }); else {
                for (var i = 0; i < e.length; i++) e[i].startTime = t.formatTime("full", e[i].startTime);
                a.setData({
                    competitions: 0 == s ? e : a.data.competitions.concat(e),
                    loadmore: 20 == e.length ? "上拉加载更多" : "全部加载"
                });
            }
        }).catch(function(t) {
            console.error(t);
        });
    },
    onPullDownRefresh: function() {
        this.data.competitions = [], this.getCompetitions();
    },
    onReachBottom: function() {
        "上拉加载更多" == this.data.loadmore && (this.setData({
            loadmore: "正在加载"
        }), this.getCompetitions());
    },
    showActionSheet: function(t) {
        var e = t.currentTarget.dataset.competition, i = this;
        wx.showActionSheet({
            itemList: [ "不再关注该比赛" ],
            itemColor: "#767676",
            success: function(t) {
                switch (t.tapIndex) {
                  case 0:
                    wx.showModal({
                        content: "确认不再显示该比赛吗？建议比赛评分结束后才取消关注。",
                        cancelColor: "#484848",
                        cancelText: "取消",
                        confirmColor: "#FF5A5F",
                        confirmText: "确定",
                        success: function(t) {
                            t.confirm && (wx.showLoading({
                                title: "正在提交",
                                mask: !0
                            }), wx.cloud.callFunction({
                                name: "role",
                                data: {
                                    competition: {
                                        _id: e._id
                                    },
                                    operation: "juryUnfocus",
                                    openidDeleted: o.globalData.openid
                                }
                            }).then(function(t) {
                                i.data.competitions = [], i.getCompetitions(), wx.hideLoading(), wx.showToast({
                                    title: "取消关注",
                                    icon: "success",
                                    duration: 1e3
                                });
                            }));
                        },
                        fail: function(t) {
                            console.log(t);
                        }
                    });
                }
            }
        });
    }
});