var t = getApp();

Page({
    data: {
        list: [],
        lastid: 0,
        tid: 0,
        catname: "",
        copyright: "",
        cats: [],
        currentTabsIndex: 0,
        fid: 0,
        currentCatId: 0,
        fatherId: 0,
        blist: {},
        tcolor: "",
        cattype: "0",
        catkey: -1,
        imgView_height: 147,
        thumb_height: "",
        hide_tabbar: "0",
        is_addHeight: 0,
        thumb_width: 0,
        is_addWidth: 0
    },
    onLoad: function(a) {
        var e = a.tid, i = a.fid;
        i || (i = 0), this.setData({
            tid: e,
            fid: i,
            currentCatId: e
        }), this.loadData(0), this.setData({
            copyright: t.globalData.copyright
        }), this.setTabBar(e);
    },
    loadMore: function(t) {
        var a = t.currentTarget.dataset.lastid;
        this.loadData(a);
    },
    catClick: function(t) {
        var a = t.currentTarget.dataset.cid, e = t.currentTarget.dataset.fid, i = t.currentTarget.dataset.catkey;
        this.data.catkey != i && (this.setData({
            tid: a,
            fid: e,
            catkey: i,
            lastid: 0
        }), this.loadData(0));
    },
    loadData: function(a) {
        var e = this;
        t.util.footer(e);
        var i = t.siteInfo.uniacid, r = e.data.tid, d = e.data.fid;
        t.util.request({
            url: "entry/wxapp/news",
            data: {
                m: "yyf_company",
                lastid: a,
                uniacid: i,
                tid: r,
                fid: d
            },
            cachetime: 0,
            success: function(t) {
                if (!t.data.errno) {
                    if (!e.data.is_addHeight) {
                        var a = parseInt(t.data.data.thumb_height), i = 0;
                        140 != a && (i = e.data.imgView_height + (a - 105), e.setData({
                            imgView_height: i,
                            is_addHeight: 1
                        }));
                    }
                    e.setData({
                        catname: t.data.data.catname,
                        currentTabsIndex: t.data.data.currentIndex,
                        fatherId: t.data.data.fatherId,
                        thumb_height: t.data.data.thumb_height,
                        thumb_width: t.data.data.thumb_width
                    }), e.setData({
                        cats: t.data.data.cats,
                        cattype: t.data.data.type
                    }), wx.setNavigationBarTitle({
                        title: t.data.data.catname
                    });
                    var r = t.data.data.list.length, d = t.data.data.currentCatId;
                    if (e.data.currentCatId != d && (console.log(e.data.currentCatId + "---" + d), e.setData({
                        list: [],
                        currentCatId: d
                    })), r > 0) {
                        var s = e.data.lastid + 8;
                        e.setData({
                            lastid: s
                        });
                        var n = e.data.list.concat(t.data.data.list);
                        e.setData({
                            list: n
                        });
                    }
                }
            }
        }), t.util.request({
            url: "entry/wxapp/TabBar",
            data: {
                m: "yyf_company",
                uniacid: i
            },
            cachetime: 0,
            success: function(t) {
                if (!t.data.errno) {
                    var a = wx.getStorageSync("barlist");
                    "" != a && a.uptime == t.data.data.uptime || (wx.setStorageSync("barlist", t.data.data), 
                    e.setTabBar());
                }
            }
        });
    },
    onShareAppMessage: function(t) {
        return {
            title: this.data.catname,
            path: "/yyf_company/pages/case/case?tid=" + this.data.fatherId
        };
    },
    setTabBar: function(t) {
        if (!(d = wx.getStorageSync("barlist"))) return !1;
        this.setData({
            blist: d,
            tcolor: d.tcolor,
            hide_tabbar: d.hide_tabbar
        });
        var a, e;
        a = "" != d.font_color ? d.font_color : "#ffffff", e = "" != d.head_color ? d.head_color : d.tcolor, 
        wx.setNavigationBarColor({
            frontColor: a,
            backgroundColor: e
        });
        var i = getCurrentPages(), r = i[i.length - 1], d = this.data.blist;
        r.options.tid == t && (d.isCurrentPage = !0);
        var s = new Array(d.m1_path, d.m2_path, d.m3_path, d.m4_path), n = 0;
        for (var o in s) s[o] == t && (n = parseInt(o) + 1);
        d.currentNum = n, this.setData({
            blist: d
        });
    },
    tel: function() {
        var t = this.data.blist.phone;
        wx.makePhoneCall({
            phoneNumber: t
        });
    },
    driver: function() {
        wx.openLocation({
            latitude: Number(this.data.blist.jing),
            longitude: Number(this.data.blist.wei),
            address: this.data.blist.address
        });
    },
    navigateMini: function(t) {
        var a = t.currentTarget.dataset.sid, e = this.data.list[a].appid, i = this.data.list[a].pageaddress;
        wx.navigateToMiniProgram({
            appId: e,
            path: i,
            success: function(t) {
                console.log("11");
            }
        });
    },
    tabNav: function(t) {
        var a = t.currentTarget.dataset.url, e = t.currentTarget.dataset.tab;
        "-1" != a.indexOf("https") ? (wx.setStorageSync("navurl", a), a = "../webview/webview?op=" + e, 
        wx.navigateTo({
            url: a
        })) : wx.redirectTo({
            url: a
        });
    },
    copy_action: function() {
        var t = this.data.blist.copyright;
        if ("1" == t.copy_kind) {
            var a = t.copy_phone;
            wx.makePhoneCall({
                phoneNumber: a
            });
        }
        if ("2" == t.copy_kind) {
            var e = t.copy_appid, i = t.copy_ddress;
            wx.navigateToMiniProgram({
                appId: e,
                path: i,
                success: function(t) {}
            });
        }
    }
});