var t = getApp();

Page({
    data: {
        list: [],
        lastid: 0,
        tid: 0,
        catname: "",
        copyright: "",
        cats: [],
        currentTabsIndex: 0,
        fid: 0,
        currentCatId: 0,
        fatherId: 0,
        blist: {},
        tcolor: "",
        catkey: -1,
        hide_tabbar: "0"
    },
    onLoad: function(a) {
        var e = a.tid, r = a.fid;
        r || (r = 0), this.setData({
            tid: e,
            fid: r,
            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, r = t.currentTarget.dataset.catkey;
        this.data.catkey != r && (this.setData({
            tid: a,
            fid: e,
            catkey: r,
            lastid: 0
        }), this.loadData(0));
    },
    loadData: function(a) {
        var e = this, r = t.siteInfo.uniacid, i = e.data.tid, d = e.data.fid;
        t.util.request({
            url: "entry/wxapp/news",
            data: {
                m: "yyf_company",
                lastid: a,
                uniacid: r,
                tid: i,
                fid: d
            },
            cachetime: 0,
            success: function(t) {
                if (!t.data.errno) {
                    e.setData({
                        catname: t.data.data.catname,
                        currentTabsIndex: t.data.data.currentIndex,
                        fatherId: t.data.data.fatherId
                    }), e.setData({
                        cats: t.data.data.cats
                    }), wx.setNavigationBarTitle({
                        title: t.data.data.catname
                    });
                    var a = t.data.data.list.length, r = t.data.data.currentCatId;
                    if (e.data.currentCatId != r ? (console.log(e.data.currentCatId + "---" + r), e.setData({
                        list: [],
                        currentCatId: r
                    })) : console.log(1111), a > 0) {
                        var i = e.data.lastid + 8;
                        e.setData({
                            lastid: i
                        });
                        var d = e.data.list.concat(t.data.data.list);
                        e.setData({
                            list: d
                        });
                    }
                }
            }
        }), t.util.request({
            url: "entry/wxapp/TabBar",
            data: {
                m: "yyf_company",
                uniacid: r
            },
            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/news/news?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 r = getCurrentPages(), i = r[r.length - 1], d = this.data.blist;
        i.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
        });
    },
    playVideo: function(t) {
        var a = t.currentTarget.dataset.sidx, e = this.data.list;
        console.log(e), console.log(a), e[a].show_video = !0, this.setData({
            list: e
        });
    },
    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, r = t.copy_ddress;
            wx.navigateToMiniProgram({
                appId: e,
                path: r,
                success: function(t) {}
            });
        }
    }
});