var t = getApp(), a = require("../../../wxParse/wxParse.js");

Page({
    data: {
        slide: [],
        sysinfo: {},
        list: [],
        cats: [],
        copyright: "",
        blist: {},
        tcolor: "",
        horn: "",
        slide_close: "0",
        nav_close: "0",
        notice_close: "0",
        slide_height: "",
        adsense: {},
        nav_style: "0",
        title_style: "0",
        show_video: !1,
        hide_time: "0",
        hide_tabbar: "0",
        nav_height: "0",
        contentList: {},
        hide_search: "0",
        form: {},
        t1v: "",
        t2v: "",
        t3v: "",
        t4v: "",
        rv: "",
        cv: "",
        av: "",
        av1: ""
    },
    onLoad: function(e) {
        var i = this, n = t.siteInfo.uniacid;
        i.setTabBar(), t.util.request({
            url: "?action=index",
            data: {
                m: "yyf_company",
                action: "index",
                uniacid: n
            },
            cachetime: 0,
            success: function(e) {
                if (!e.data.errno) {
                    for (var n = e.data.data.list, r = 0; r < n.length; r++) if (3 == n[r].type) {
                        a.wxParse("article1", "html", n[r].content, i, 10);
                        var s = n[r].id, o = i.data.contentList;
                        o[s] = i.data.article1, i.setData({
                            contentList: o
                        });
                    }
                    i.setData({
                        slide: e.data.data.slide,
                        sysinfo: e.data.data.sysinfo,
                        list: e.data.data.list,
                        cats: e.data.data.cats,
                        horn: e.data.data.horn,
                        notice_close: e.data.data.notice_close,
                        slide_close: e.data.data.slide_close,
                        nav_close: e.data.data.nav_close,
                        slide_height: e.data.data.slide_height,
                        nav_style: e.data.data.nav_style,
                        title_style: e.data.data.title_style,
                        hide_time: e.data.data.hide_time,
                        nav_height: e.data.data.nav_height,
                        hide_search: e.data.data.hide_search
                    }), wx.setNavigationBarTitle({
                        title: e.data.data.sysinfo.title
                    }), t.globalData.copyright = e.data.data.sysinfo.copyright;
                }
                console.log(e.data.data);
            }
        }), t.util.request({
          url: "?action=adsense",//entry/wxapp/Adsense
            data: {
              m: "yyf_company",
              action: "adsense",
                uniacid: n
            },
            cachetime: 0,
            success: function(t) {
                t.data.errno || i.setData({
                    adsense: t.data.data
                });
            }
        }), t.util.request({
          url: "?action=tabbar",
            data: {
              m: "yyf_company",
              action: "tabbar",
                uniacid: n
            },
            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), 
                    i.setTabBar());
                }
            }
        }), t.util.request({
            url: "?action=form",
            data: {
              m: "yyf_company",
              action: "form",
                uniacid: n
            },
            cachetime: 0,
            success: function(t) {
                t.data.errno || (i.setTabBar(), i.setData({
                    form: t.data.data
                }));
            }
        });
    },
    search: function(a) {
        t.siteInfo.uniacid;
        var e = a.detail.value;
        "" != e && wx.navigateTo({
            url: "../search/search?keyword=" + e
        });
    },
    onShareAppMessage: function(t) {
        return {
            title: this.data.sysinfo.name,
            path: "/yyf_company/pages/index/index"
        };
    },
    setTabBar: function() {
        if (!(n = wx.getStorageSync("barlist"))) return !1;
        this.setData({
            blist: n,
            tcolor: n.tcolor,
            hide_tabbar: n.hide_tabbar
        });
        var t, a;
        t = "" != n.font_color ? n.font_color : "#ffffff", a = "" != n.head_color ? n.head_color : n.tcolor, 
        wx.setNavigationBarColor({
            frontColor: t,
            backgroundColor: a
        });
        var e = getCurrentPages(), i = e[e.length - 1].route, n = this.data.blist, r = i.split("/");
        "index" == r[r.length - 1] && (n.isCurrentPage = !0);
        var s = new Array(n.m1_path, n.m2_path, n.m3_path, n.m4_path), o = 0;
        for (var d in s) "index" == s[d] && (o = parseInt(d) + 1);
        n.currentNum = o, this.setData({
            blist: n
        });
    },
    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 = t.currentTarget.dataset.fid, i = this.data.list[e].list[a].appid, n = this.data.list[e].list[a].pageaddress;
        wx.navigateToMiniProgram({
            appId: i,
            path: n,
            success: function(t) {}
        });
    },
    playVideo: function(t) {
        var a = t.currentTarget.dataset.fidx, e = t.currentTarget.dataset.sidx, i = this.data.list;
        i[a].list[e].show_video = !0, this.setData({
            list: i
        });
    },
    navto: function(t) {
        var a = t.currentTarget.dataset.nid, e = this.data.cats[a].url;
        wx.setStorageSync("navurl", e), "-1" != e.indexOf("https") && (e = "../webview/webview?op=nav" + this.data.cats[a].id), 
        wx.navigateTo({
            url: e
        });
    },
    ad1nav: function() {
        if (t = this.data.adsense.a1urlnew, wx.setStorageSync("navurl", t), "-1" != t.indexOf("https")) var t = "../webview/webview?op=ads1";
        wx.navigateTo({
            url: t
        });
    },
    ad2nav: function() {
        if (t = this.data.adsense.a2urlnew, wx.setStorageSync("navurl", t), "-1" != t.indexOf("https")) var t = "../webview/webview?op=ads2";
        wx.navigateTo({
            url: t
        });
    },
    ad3nav: function() {
        if (t = this.data.adsense.a3urlnew, wx.setStorageSync("navurl", t), "-1" != t.indexOf("https")) var t = "../webview/webview?op=ads3";
        wx.navigateTo({
            url: t
        });
    },
    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) {}
            });
        }
    },
    imgError: function() {},
    notice: function(t) {
        wx.showModal({
            title: t,
            content: "",
            success: function(t) {}
        });
    },
    notice1: function(t) {
        wx.showModal({
            title: "",
            content: t,
            success: function(t) {}
        });
    },
    t1: function(t) {
        console.log(t.detail.value), this.setData({
            t1v: t.detail.value
        });
    },
    t2: function(t) {
        this.setData({
            t2v: t.detail.value
        });
    },
    t3: function(t) {
        this.setData({
            t3v: t.detail.value
        });
    },
    t4: function(t) {
        this.setData({
            t4v: t.detail.value
        });
    },
    radioChange: function(t) {
        this.setData({
            rv: t.detail.value
        });
    },
    checkChange: function(t) {
        this.setData({
            cv: t.detail.value
        });
    },
    textareaBlur: function(t) {
        this.setData({
            av: t.detail.value
        });
    },
    submitClick: function(a) {
        var e = !0, i = this.data;
        if ("" == i.t1v && "1" == i.form.t1full && "1" == i.form.t1show) return this.notice(i.form.t1name + "不能为空!"), 
        e = !1, !1;
        if ("" == i.t2v && "1" == i.form.t2full && "1" == i.form.t2show) return this.notice(i.form.t2name + "不能为空!"), 
        e = !1, !1;
        if ("" == i.t3v && "1" == i.form.t3full && "1" == i.form.t3show) return this.notice(i.form.t3name + "不能为空!"), 
        e = !1, !1;
        if ("" == i.t4v && "1" == i.form.t4full && "1" == i.form.t4show) return this.notice(i.form.t4name + "不能为空!"), 
        e = !1, !1;
        if ("" == i.rv && "1" == i.form.rfull && "1" == i.form.rshow) return this.notice(i.form.rname + "不能为空!"), 
        e = !1, !1;
        if ("" == i.cv && "1" == i.form.cfull && "1" == i.form.cshow) return this.notice(i.form.cname + "不能为空!"), 
        e = !1, !1;
        if ("" == i.av && "1" == i.form.afull && "1" == i.form.ashow) return this.notice(i.form.aname + "不能为空!"), 
        e = !1, !1;
        if (e) {
            var n = t.siteInfo.uniacid, r = this;
            t.util.footer(r);
            var s = wx.getStorageSync("sendtime");
            "" == s && (s = 0), t.util.request({
                url: "entry/wxapp/formadd",
                data: {
                    m: "yyf_company",
                    uniacid: n,
                    t1v: r.data.t1v,
                    t1name: r.data.form.t1name,
                    t2v: r.data.t2v,
                    t2name: r.data.form.t2name,
                    t3v: r.data.t3v,
                    t3name: r.data.form.t3name,
                    t4v: r.data.t4v,
                    t4name: r.data.form.t4name,
                    rv: r.data.rv,
                    rname: r.data.form.rname,
                    cv: r.data.cv,
                    cname: r.data.form.cname,
                    av: r.data.av,
                    aname: r.data.form.aname,
                    sendtime: s
                },
                cachetime: 0,
                success: function(t) {
                    if (!t.data.errno) if (1 == t.data.errno) r.notice(t.data.message); else {
                        var a = Date.parse(new Date());
                        a /= 1e3, wx.setStorageSync("sendtime", a), r.notice1(r.data.form.successtext);
                    }
                }
            });
        }
    }
});