var a;

a = getApp(), Page({
    data: {
        api: a.globalData.api_host,
        data: "",
        placeholder: "蛇、打雷",
        value: "",
        category: a.globalData.category,
        catelayer: !1,
        id: "",
        cate_name: "",
        p: 1,
        height: "",
        pageCount: "",
        backtop: !1,
        search: !1,
        keywords: ""
    },
    onLoad: function(t) {
        var e = this, o = e.options.id;
        if (isNaN(o)) for (d = 0; d < e.data.category.length; d++) o == e.data.category[d].en && (o = e.data.category[d].id);
        e.setData({
            id: o
        });
        for (var d = 0; d < e.data.category.length; d++) e.data.category[d].id == e.data.id && e.setData({
            cate_name: e.data.category[d].name
        });
        var n = decodeURI(e.options.q);
        n ? (e.setData({
            search: !0,
            cate_name: "搜索结果",
            value: n,
            keywords: n
        }), a.request({
            key: n,
            p: e.data.p,
            ps: 10,
            detail: 1,
            order: "level DESC,update_time DESC"
        }, function(a) {
            e.setData({
                data: a.data,
                pageCount: a.pageCount
            });
        })) : a.request({
            cate: e.data.id,
            attr: 1,
            p: e.data.p,
            ps: 10,
            detail: 1,
            order: "level DESC,update_time DESC"
        }, function(a) {
            e.setData({
                data: a.data,
                pageCount: a.pageCount
            });
        });
    },
    onShareAppMessage: function(a) {
        return console.log(this.data.keywords, this.data.id), this.data.keywords ? {
            title: "梦册" + this.data.value,
            content: "解释你的梦境,感悟你的人生,了解你的心情,梦就是现实的写照！",
            path: "/pages/search/search?q=" + encodeURI(this.data.keywords)
        } : {
            title: "梦册分析",
            content: "解释你的梦境,感悟你的人生,了解你的心情,梦就是现实的写照！",
            path: "/pages/list/list?id=" + this.data.id
        };
    },
    formSubmitHandle: function(t) {
        var e = this, o = t.detail.value.keywords;
        if (!o) return e.setData({
            tip: !0,
            tipShow: !0,
            keywords: o
        }), setTimeout(function() {
            e.setData({
                tip: !1
            }), setTimeout(function() {
                e.setData({
                    tipShow: !1
                });
            }, 300);
        }, 3e3), !1;
        this.setData({
            p: 1,
            value: o,
            search: !0
        }), a.request({
            key: o,
            p: 1,
            ps: 10,
            detail: 1
        }, function(a) {
            e.setData({
                data: a.data || "",
                pageCount: a.pageCount,
                cate_name: "搜索结果"
            });
        });
    },
    hideCatelayer: function() {
        this.setData({
            catelayer: !1
        });
    },
    handleCatelayer: function() {
        this.setData({
            catelayer: !0
        });
    },
    handleChageCate: function(t) {
        var e = this, o = t.currentTarget.dataset.id;
        e.setData({
            attr: 1,
            search: !1,
            p: 1,
            id: o,
            cate_name: t.currentTarget.dataset.name,
            keywords: "",
            value: ""
        }), a.request({
            cate: o,
            p: 1,
            ps: 10,
            detail: 1,
            order: "level DESC,update_time DESC"
        }, function(a) {
            e.setData({
                data: a.data,
                catelayer: !1,
                pageCount: a.pageCount
            });
        });
    },
    onReachBottom: function() {
        var t = this, e = t.data.p + 1;
        if (e > t.data.pageCount) return !1;
        t.setData({
            p: e
        }), t.data.search ? a.request({
            key: t.data.value,
            p: e,
            ps: 10,
            detail: 1
        }, function(a) {
            var e = t.data.data.concat(a.data);
            t.setData({
                data: e
            });
        }) : a.request({
            cate: t.data.id,
            p: e,
            ps: 10,
            detail: 1
        }, function(a) {
            var e = t.data.data.concat(a.data);
            t.setData({
                data: e
            });
        });
    },
    onPageScroll: function(a) {
        var t = !1;
        a.scrollTop >= 100 && (t = !0), this.setData({
            backtop: t
        });
    },
    handleBacktop: function() {
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
        });
    }
});