var a = getApp();

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