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

e.command.aggregate;

Page({
    data: {
        scrollTop: 0,
        competitions: "",
        loadmore: ""
    },
    onLoad: function(t) {
        var a = this;
        wx.showLoading({
            title: "正在加载",
            mask: !0
        }), e.collection("_config").where({
            _id: "config"
        }).field({
            v: !0,
            button: !0
        }).get().then(function(t) {
            a.setData({
                c: o.globalData.c,
                v: t.data[0].v,
                button: t.data[0].button
            });
        }).catch(function(t) {
            console.error(t);
        });
    },
    onShow: function() {
        this.data.competitions = [], this.getCompetitions();
    },
    getCompetitions: function(i) {
        var n = this, s = this.data.competitions.length;
        e.collection("competitions").where(a.or([ a.and({
            _id: "example",
            usersUnfocus: a.neq(o.globalData.openid),
            status: a.neq("已删除")
        }), a.and({
            status: a.neq("已删除"),
            workers: 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,
            rechargeable: !0,
            posterSize: !0
        }).get().then(function(o) {
            var e = o.data;
            if (0 == s && 0 == e.length) n.setData({
                loadmore: "未创建比赛活动"
            }); else {
                for (var a = 0; a < e.length; a++) e[a].startTime = t.formatTime("full", e[a].startTime);
                n.setData({
                    competitions: 0 == s ? e : n.data.competitions.concat(e),
                    loadmore: 20 == e.length ? "上拉加载更多" : "全部加载"
                });
            }
            wx.hideLoading(), wx.stopPullDownRefresh();
        }).catch(function(t) {
            console.error(t);
        });
    },
    onPullDownRefresh: function() {
        this.data.competitions = [], this.getCompetitions();
    },
    onReachBottom: function() {
        "上拉加载更多" == this.data.loadmore && (this.setData({
            loadmore: "正在加载"
        }), this.getCompetitions());
    },
    newCompetition: function() {
        o.globalData.authorized ? wx.navigateTo({
            url: "/pages/competition/edit/edit"
        }) : wx.showModal({
            content: "授权微信登录后方可创建新的比赛",
            cancelColor: "#484848",
            cancelText: "以后再说",
            confirmColor: "#FF5A5F",
            confirmText: "去登录",
            success: function(t) {
                t.confirm ? wx.navigateTo({
                    url: "/pages/more/authorize/authorize?page=worker"
                }) : t.cancel;
            }
        });
    },
    onPageScroll: function(t) {}
});