top_footer.js 10.8 KB
$(function () {
    var nav = '<div class="responsive clearfix"><div class="left">欢迎来到农丰网! 请<a class="lay-in" href="#">登录</a> | <a href="#">免费注册</a></div><ul class="right"><li><a href="http://user.nong12.com/account/security.html"><span>账户中心</span></a></li><li class="more"><a href="http://user.nong12.com/"><span>我的农丰</span></a><span class="icon-more"></span><div class="mroe-list"><div class="list-a"><a href="http://user.nong12.com/purchase/order.html">已买到的商品</a><a href="http://user.nong12.com/purchase/favorite/product.html">我的收藏</a><a href="http://user.nong12.com/purchase/history.html">我的浏览</a></div></div></li><li class="more"><a href="http://shop.nong12.com/order/list.html"><span>销售中心 </span></a><span class="icon-more"></span><div class="mroe-list"><div class="list-a"><a href="http://shop.nong12.com/open/shop.html">我的店铺</a><a href="http://shop.nong12.com/order/list.html">已卖出的商品</a><a href="http://shop.nong12.com/seller/product/list/onsale.html">出售中的商品</a><a href="http://shop.nong12.com/seller/product/showCategory.html">免费发布商品</a></div></div></li><li><a href="http://www.nong12.com/purchase_list.html"><span>进货单</span><span class="num">(<span class="cart-num">0</span>)</span></a></li><li><a href="javascript:void(0)" onclick="IM.openWindow(\'农丰客服\',\'农丰客服\', \'\', \'\', \'\' , \'1\');"><span>客服服务</span></a></li><li><a href="http://www.nong12.com/helpcenter.html"><span>帮助中心</span></a></li></ul></div>';
    var footer = '<div class="bg-F9"><div class="footer-view clearfix"><div class="left"><ul id="footer_cms"></ul></div><div class="right"><span class="icon-shield"></span><ul class="clearfix"><li><span class="icon-f-phone"></span><p>服务热线:<span class="text-phone">400-645-5158</span></p></li><li><span class="icon-f-customerservice"></span><p>服务时间:<span class="text-time">上午8:00 - 下午16:00</span></p></li><li><span class="icon-f-im"></span><a class="dili-im" href="javascript:void(0)" onclick="IM.openWindow(\'农丰客服\',\'农丰客服\', \'\', \'\', \'\' , \'1\');"><i></i>联系客服</a></li></ul></div></div></div><div class="footer-end"><p><a href="http://www.nong12.com/helpcenter/articles.html?categoryId=3&amp;articleId=9">关于我们</a> |<a href="http://www.nong12.com/helpcenter/articles.html?categoryId=3&amp;articleId=10">联系我们</a> |<a href="http://www.nong12.com/helpcenter/articles.html?categoryId=3&amp;articleId=11">人才招聘</a> |<a href="http://www.nong12.com/helpcenter.html">帮助中心</a></p><p class="col-999"> Copyright © 2013-2015 nong12.com,All Rights Reserved 京ICP备15030623号</p><p class="col-999"> 版权所有 北京农丰吉瑞网络科技有限公司 | 地址:北京市朝阳区光华路甲8号院1号楼5层6-501A室 | 电话:010-65816529 </p></div>';
    $('.pnr-top .nav').html(nav);
    $('.footer').html(footer);

    window.loginInfo = true;
    //渲染hello头
    jQuery.ajax({
        type: "GET",
        url: "https://passport.nong12.com/uc/ws/callHelloJSONP",
        dataType: "jsonp",
        cache: false,
        success: function (data) {
            if (data) {
                if (data.isLogin) {
                    $(".responsive .left").remove();
                    $(".responsive .right").before("<div class='left'><a href='http://user.nong12.com/account/security.html' target='_blank'><span id='uname'>" + data.userName + "</span></a>&nbsp;欢迎来到农丰网! <a href='https://passport.nong12.com/uc/loginService?ltype=logout'>退出</a></div>");

                    $("#right-login .state-success").show();
                    $("#userName").html(data.userName);

                    if(window.isRight){
                    	 jQuery.ajax({
                             type: "GET",
                             url: "http://user.nong12.com/api/userservice/getUserName.do",
                             dataType: "jsonp",
                             cache: false,
                             success: function (data) {
                                 $("#my-face").attr("src", data.face);
                             }
                         });
                    	window.loginInfo = true;
                    }
                	 $(".responsive .left").append('<a class="h-user-msg" href="javascript:void(0)" id="notify"></a>');
                	 IM.notification($("#notify"));
                } else {
                    $(".responsive .left a").first().attr("href", DiliPath.loginPath + "?ReturnUrl=" + window.location.href);
                    $(".responsive .left a").last().attr("href", DiliPath.registPath);
                    window.loginInfo = false;
                }
            }
            window.passportcon = true;
        },
        error: function () {
            window.loginInfo = false;
            return false;
        }
    });

    $("#my-info").hover(function () {
        if (!window.loginInfo) {
            window.loginInfo = true;
            PassportPopupLogin.settings.callbackFn = function () {
                //window.location.reload();
                // Edit By Lai Kui 修改右边登录异步刷新开始
                jQuery.ajax({
                    type: "GET",
                    url: "https://passport.nong12.com/uc/ws/callHelloJSONP",
                    dataType: "jsonp",
                    cache: false,
                    success: function (data) {
                        if (data) {
                            if (data.isLogin) {
                                $(".responsive .left").remove();
                                $(".responsive .right").before("<div class='left'><a href='http://user.nong12.com/account/security.html' target='_blank'><span id='uname'>" + data.userName + "</span></a>&nbsp;欢迎来到农丰网! <a href='https://passport.nong12.com/uc/loginService?ltype=logout'>退出</a></div>");

                                $("#right-login .state-success").show();
                                $("#userName").html(data.userName);

                                if(window.isRight){
                                    jQuery.ajax({
                                        type: "GET",
                                        url: "http://user.nong12.com/api/userservice/getUserName.do",
                                        dataType: "jsonp",
                                        cache: false,
                                        success: function (data) {
                                            $("#my-face").attr("src", data.face);
                                        }
                                    });
                                    window.loginInfo = true;
                                }
                                $(".responsive .left").append('<a class="h-user-msg" href="javascript:void(0)" id="notify"></a>');
                                IM.notification($("#notify"));
                                if(window.location.href.indexOf("cartList") < 0 && window.location.href.indexOf("purchase_list") < 0) {
                            		cartTools.showCart();
                            	}
                            } else {
                                $(".responsive .left a").first().attr("href", DiliPath.loginPath + "?ReturnUrl=" + window.location.href);
                                $(".responsive .left a").last().attr("href", DiliPath.registPath);
                                window.loginInfo = false;
                            }
                        }
                    },
                    error: function () {
                        window.loginInfo = false;
                        return false;
                    }
                });
                $("#right-login").html(' <div id="right-login" class="floatinglayer f-login"> <div class="triangle"></div> <div class="state-success" style="display:none"> <div class="state-head"> <a href="http://user.nong12.com/account/security.html" target="_blank"><img id="my-face" src="http://static.nong12.com/static/newStatic/pnr/dist/images/t-default.png" alt=""></a> <span> <a href="http://user.nong12.com/account/security.html" target="_blank"><span id="userName"></span></a><span>欢迎回到农丰网!</span> </span> </div> </div> </div>');
                // 修改右边登录异步刷新结束
            };
            PassportPopupLogin.init();
            if (window.passportcon) {
                $("#right-login").html('<div class="triangle"></div><div class="f-hover-view"></div><iframe frameborder="0" scrolling="no" class="login-frame" src="https://passport.nong12.com/uc/newPopup/login.aspx?referUrl=http://www.nong12.com"></iframe>');
            }
        }
    }, function () {
    });

    //渲染footer
    jQuery.ajax({
        type: "GET",
        url: DiliPath.homePath + "common/footerJson.html",
        dataType: "jsonp",
        jsonp: "callFn",
        jsonpCallback: 'success_jsonpCallback1' + (new Date()).getTime(),
        success: function (data) {
        	if(data){
        		var html = [];
        		var iconArr = ["icon-we", "icon-aftersales", "icon-shopping", "icon-identity", "icon-novice"];
        		for (var i = 0; i < data.length; i++) {
        			var showIcon = data.length <= iconArr.length ? iconArr[i] : iconArr[0];
        			html.push("<li><span class='" + showIcon + "'></span><p>" + data[i].text + "</p><div class='f-list'>");
        			var vc = data[i].subNodes;
        			for (var j = 0; j < vc.length; j++) {
        				if (j == vc.length - 1) {
        					html.push("<a href='" + vc[j].link + "'>" + vc[j].text + "</a></div></li>");
        				} else {
        					html.push("<a href='" + vc[j].link + "'>" + vc[j].text + "</a>");
        				}
        			}
        		}
        		$("#footer_cms").html(html.join(""));
        	}
        }
    });

    if ($("head").find("script[src*='jquery.lazyload']").size() > 0) {
        $("body").find("img").each(function () {
            $(this).lazyload({
                effect: "fadeIn",
                skip_invisible: false
            });
        });
    }
});

function replaceAll(str, sptr, sptr1) {
    while (str.indexOf(sptr) >= 0) {
        str = str.replace(sptr, sptr1);
    }
    return str;
}

var otherTools = {
    /**
     * im
     * @param sellerType
     * @param sellerName
     */
    imConnection: function (sellerType, sellerName) {
        var type = 2;//2默认客服
        var name = '农丰客服';
        //第3方
        if (sellerType == 30) {
            type = 0;
            name = sellerName;
        }

        var timestamp = (new Date()).valueOf();
        var ht = (screen.height - 500) / 2;
        var wt = (screen.width - 800) / 2;
        var url = 'http://chat.nong12.com/launch/launch.action?uid=' + name + '&type=' + type + '&_t=' + timestamp;
        var param = 'height=555,width=800,resizable=yes,top=' + ht + ',left=' + wt;
        window.open(url, name, param);
    }
};