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

o.command.aggregate;

Page({
    data: {
        competitions: "",
        loadmore: "",
        tags: [],
        selectedTag: "比赛精选"
    },
    onLoad: function(t) {
        var a = this;
        wx.showLoading({
            title: "正在加载",
            mask: !0
        }), o.collection("_config").where({
            _id: "config"
        }).field({
            v: !0
        }).get().then(function(t) {
            a.data.c = e.globalData.c, a.data.v = t.data[0].v, a.getCompetitions(), e.globalData.c, 
            t.data[0].v;
        }).catch(function(t) {
            console.error(t);
        });
    },
    getCompetitions: function(i) {
        var n = this, s = this.data.competitions.length;
        this.data.c != this.data.v ? o.collection("competitions").where({
            note: "宝职"
        }).where({
            status: a.and(a.neq("已删除"), a.neq("已关闭"))
        }).orderBy("startTime", "desc").skip(s).field({
            title: !0,
            poster: !0,
            startTime: !0,
            site: !0,
            sponsor: !0,
            organizer: !0,
            tags: !0,
            audiences: !0,
            posterSize: !0
        }).get().then(function(e) {
            wx.hideLoading(), wx.stopPullDownRefresh();
            for (var o = e.data, a = 0; a < o.length; a++) o[a].startTime = t.formatTime("full", o[a].startTime);
            n.setData({
                competitions: 0 == s ? o : n.data.competitions.concat(o),
                loadmore: 20 == o.length ? "上拉加载更多" : "全部加载"
            });
        }).catch(function(t) {
            console.error(t);
        }) : o.collection("competitions").where(a.or([ a.and({
            _id: "example",
            focus: e.globalData.openid
        }), a.and({
            _id: a.neq("example"),
            note: a.neq("不开放")
        }), {
            audiences: e.globalData.openid
        } ])).where({
            status: a.and(a.neq("已删除"), a.neq("已关闭"))
        }).orderBy("startTime", "desc").skip(s).field({
            title: !0,
            poster: !0,
            startTime: !0,
            site: !0,
            sponsor: !0,
            organizer: !0,
            tags: !0,
            audiences: !0,
            status: !0,
            posterSize: !0
        }).get().then(function(e) {
            wx.hideLoading(), wx.stopPullDownRefresh();
            for (var o = e.data, a = 0; a < o.length; a++) o[a].startTime = t.formatTime("full", o[a].startTime);
            n.setData({
                competitions: 0 == s ? o : n.data.competitions.concat(o),
                loadmore: 20 == o.length ? "上拉加载更多" : "全部加载"
            });
        }).catch(function(t) {
            console.error(t);
        });
    },
    showActionSheet: function(t) {
        var o = t.currentTarget.dataset.competition._id;
        if ("oRnCI5JYWT9dmVycOnBjYaX1Yx7k" == e.globalData.openid || "oRnCI5GgJ8Kc3sGye-ungAdL7r4U" == e.globalData.openid) {
            var a = this;
            wx.showActionSheet({
                itemList: [ "标记为不开放" ],
                success: function(t) {
                    switch (t.tapIndex) {
                      case 0:
                        wx.showLoading({
                            title: "正在提交",
                            mask: !0
                        }), wx.cloud.callFunction({
                            name: "competition",
                            data: {
                                competition: {
                                    _id: o,
                                    note: "不开放"
                                },
                                operation: "update"
                            }
                        }).then(function(t) {
                            wx.hideLoading(), wx.showToast({
                                title: "标记为不开放",
                                icon: "success",
                                duration: 1500
                            }), a.getActive();
                        });
                    }
                },
                fail: function(t) {}
            });
        }
    },
    onPullDownRefresh: function() {
        this.data.competitions = [], this.getCompetitions();
    },
    onReachBottom: function() {
        "上拉加载更多" == this.data.loadmore && (this.setData({
            loadmore: "正在加载"
        }), this.getCompetitions());
    },
    onShareAppMessage: function() {
        return {
            title: "我发现了一款高效好用的比赛评分小程序",
            path: "/pages/index/index",
            imageUrl: "/images/sharePic.png"
        };
    }
});