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
    },
    onLoad: function(t) {
        var e = this, o = e.options.id;
        if (isNaN(o)) for (i = 0; i < e.data.category.length; i++) o == e.data.category[i].en && (o = e.data.category[i].id);
        e.setData({
            id: o
        });
        for (var i = 0; i < e.data.category.length; i++) e.data.category[i].id == e.data.id && e.setData({
            cate_name: e.data.category[i].name
        });
        e.options.q ? (e.setData({
            search: !0,
            cate_name: "搜索结果",
            value: e.options.q
        }), a.request({
            key: e.options.q,
            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
            });
        }), this.mengjian();
    },
    mengjian: function() {
        var t = this;
        console.log(t.data.id), a.request({
            attr: 1,
            ps: 28,
            cate: t.data.id,
            field: "id,title,cate_id",
            order: "level DESC,update_time DESC"
        }, function(e) {
            11 == t.data.id ? t.setData({
                group: 4
            }) : t.setData({
                group: 5
            });
            var o = a.group(e.data, t.data.group);
            t.setData({
                mengList: e.data,
                newArray: o
            }), console.log(o);
        });
    },
    onShareAppMessage: function(a) {
        return this.data.value ? {
            title: "梦册" + this.data.value,
            content: "解释你的梦境,感悟你的人生,了解你的心情,梦就是现实的写照！",
            path: "/pages/search/search?q=" + encodeURI(this.data.value)
        } : {
            title: "梦册分析",
            content: "解释你的梦境,感悟你的人生,了解你的心情,梦就是现实的写照！",
            path: "/pages/list/list?id=" + this.data.id
        };
    },
    formSubmitHandle: function(a) {
        var t = this, e = a.detail.value.keywords;
        if (!e) return t.setData({
            tip: !0,
            tipShow: !0
        }), setTimeout(function() {
            t.setData({
                tip: !1
            }), setTimeout(function() {
                t.setData({
                    tipShow: !1
                });
            }, 300);
        }, 3e3), !1;
        this.setData({
            p: 1,
            value: e,
            search: !0
        }), wx.navigateTo({
            url: encodeURI("/pages/search/search?q=" + e)
        });
    },
    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({
            search: !1,
            p: 1,
            id: o,
            cate_name: t.currentTarget.dataset.name,
            value: ""
        }), a.request({
            attr: 1,
            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
            });
        }), e.mengjian();
    },
    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
        });
    }
});