var a = getApp();

Page({
    data: {
        list: [],
        lastid: 0,
        tid: 0,
        catname: "",
        copyright: "",
        cats: [],
        currentTabsIndex: 0,
        fid: 0,
        currentCatId: 0,
        cid: 0,
        fatherId: 0,
        blist: {},
        tcolor: "",
        cattype: "0",
        catkey: -1,
        imgView_height: 147,
        thumb_height: "",
        hide_tabbar: "0",
        is_addHeight: 0
    },
    onLoad: function(t) {
        var e = t.tid, i = t.fid,cid = t.cid;
        i || (i = 0), this.setData({
            tid: e,
            fid: i,
            cid:cid,
            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, i = a.currentTarget.dataset.catkey;
        this.data.catkey != i && (this.setData({
            tid: t,
            fid: e,
            catkey: i,
            lastid: 0
        }), this.loadData(0));
    },
    loadData: function(t) {
        var e = this;
        a.util.footer(e);
        var i = a.siteInfo.uniacid, r = e.data.tid, d = e.data.fid,cid=e.data.cid;
        a.util.request({
          url: "?action=prod_list",//entry/wxapp/news
            data: {
                m: "yyf_company",
                action: "prod_list",
                cid:cid,
                lastid: t,
                uniacid: i,
                tid: r,
                fid: d
            },
            cachetime: 0,
            success: function(a) {
                if (!a.data.errno) {
                    if (!e.data.is_addHeight) {
                        var t = parseInt(a.data.data.thumb_height), i = 0;
                        140 != t && (i = e.data.imgView_height + (t - 105), e.setData({
                            imgView_height: i,
                            is_addHeight: 1
                        }));
                    }
                    e.setData({
                        catname: a.data.data.catname,
                        currentTabsIndex: a.data.data.currentIndex,
                        fatherId: a.data.data.fatherId,
                        thumb_height: a.data.data.thumb_height
                    }), e.setData({
                        cats: a.data.data.cats,
                        cattype: a.data.data.type
                    }), wx.setNavigationBarTitle({
                        title: a.data.data.catname
                    });
                    var r = a.data.data.list.length, d = a.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(a.data.data.list);
                        e.setData({
                            list: n
                        });
                    }
                }
            }
        }), 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/case/case?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 i = getCurrentPages(), r = i[i.length - 1], d = this.data.blist;
        r.options.tid == a && (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] == a && (n = parseInt(o) + 1);
        d.currentNum = n, 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
        });
    },
    navigateMini: function(a) {
        var t = a.currentTarget.dataset.sid, e = this.data.list[t].appid, i = this.data.list[t].pageaddress;
        wx.navigateToMiniProgram({
            appId: e,
            path: i,
            success: function(a) {
                console.log("11");
            }
        });
    },
    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, i = a.copy_ddress;
            wx.navigateToMiniProgram({
                appId: e,
                path: i,
                success: function(a) {}
            });
        }
    }
});