common.js 7.35 KB
/**
 * Created by moli on 15/5/26.
 */
$(function(){
    var DiliPath = {
        loginPath : "",
        registPath : "",
        logoOut : "https://passport.nong12.com/uc/loginService?ltype=logout",
        userInfo : "http://user.nong12.com/account/security.html"
    };
    var View = {
        headder : '<div class="nav site-width"><div class="info clearfix"><em>欢迎您!来到农丰网</em><div class="islogin">请'
                 +'<a href="#" class="hover-color-green">登录</a> <a href="#" class="hover-color-green">免费注册</a>'
                 +'</div> <div class="im" onclick="javascript:IM.openWindow(\'农丰客服\', \'农丰客服\', \'0\', \'\', \'\' , \'1\');$(\'#total\').text(0);$(\'.noti.new-msg-icon\').remove();"> <div class="im-tip hover-color-green">消息<span>0</span><span class="icon-im-new"></span></div>'
                 +'<div class="im-msgs"><div class="on-msg">暂无更多消息</div><div class="im-list"><ul>'
                 +'<li><a href="#">海州海参</a><span>29</span></li></ul> </div> </div> </div> </div> <div class="menu">'
                 +'<ul><li><a href="http://user.nong12.com/account/security.html">账户中心</a></li><li class="more"><a href="http://user.nong12.com/">采购中心<b class="icon-direction"></b></a>'
                 +'<div class="menu-list"><div class="menu-list-panel"><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://user.nong12.com/seller/shop/setting_shop.html">销售中心<b class="icon-direction"></b></a>'
                 +'<div class="menu-list"><div class="menu-list-panel"><a href="http://user.nong12.com/seller/shop/setting_shop.html">我的店铺</a> <a href="http://user.nong12.com/seller/order/get_order_list.do">已卖出的商品</a>'
                 +'<a href="http://user.nong12.com/seller/product/onsale.html">出售中的商品</a><a href="http://user.nong12.com/seller/product/publish.html">免费发布商品</a></div></div></li>'
                 +'<li><a href="http://www.nong12.com/purchase_list.html">进货单<span class="color-green">(0)</span></a></li>'
                 +'<li><a href="javascript:void(0);" onclick="IM.openWindow(\'农丰客服\',\'农丰客服\', \'\', \'\', \'\' , \'1\');" >客服服务<span class="icon-im"></span></a></li>'
                 +'<li><a href="http://www.nong12.com/helpcenter.html">帮助中心</a></li></ul></div></div></div>',
        footer : '<div class="footer"><div class="helper-end"><div class="helper clearfix">'
                 +'<div class="help"><ul></div><div class="contact"><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">上午9:00 - 晚上21:00</span></p></li>'
                 +'<li><span class="icon-f-im"></span><p class="dili-im" href=""><span class="icon-im-call"></span>联系我们</p></li>'
                 +'</ul></div></div></div><div class="dili site-width"><div class="about"><a href="http://www.nong12.com/helpcenter/articles.html?categoryId=3&articleId=9">关于我们</a>'
                 +'|<a href="http://www.nong12.com/helpcenter/articles.html?categoryId=3&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></div>'
                 +'<p> Copyright © 2013-2014 nong12.com,All Rights Reserved 陕ICP备14002958号</p><p>版权所有 地利网络农业有限公司</p></div></div>'
    };


    var Methods = {
		/* 依据data.dtype 发送ajax请求 */
        http : function(url, success, error, data){
            var parm = {
                type : 'GET',
                url : url,
                dataType : "jsonp",
                cache : false,
                success : function(data){
                    success(data);
                },
                error : function(ero){
                    if(error){error(ero)};
                }
            };
            if(data && data.dtype){
                parm.jsonp = data.dtype;
            }
            if(data && data.call){
                parm.jsonpCallback = data.call;
            }
            $.ajax(parm);
        },
		/* 初始化 需要使用的函数*/
        init : function(){
            $(".header").prepend(View.headder);
            $("body").append(View.footer);

            //检查登陆
            Methods.http("https://passport.nong12.com/uc/ws/callHelloJSONP", function(data){
                Methods.isLogin(data);
            }, function(){
                window.loginInfo = false;
                return false;
            });
            //加载底部
            Methods.http("http://www.nong12.com/common/footerJson.html", function(data){
                Methods.setFooter(data);
            }, function(){
                window.loginInfo = false;
                return false;
            }, {dtype : "callFn", call : 'success_jsonpCallback1' + (new Date()).getTime()});
        },
		/* 判断是否登录  javascript:IM.openWindow('农丰客服', '农丰客服', '0', '', '' , '1');$('#total').text(0);$('.noti.new-msg-icon').remove();*/
        isLogin : function(data){
            if(data && data.isLogin){
                $(".islogin").html("");
                $(".islogin").html('<a href="'+DiliPath.logoOut+'" class="hover-color-green logout">退出</a>');
                $(".header .info").prepend('<a href="'+DiliPath.userInfo+'" class="hover-color-green user-name" >'+data.userName+'</a>');
            }else{
                $(".islogin .hover-color-green").eq(0).attr("href", DiliPath.loginPath + "?ReturnUrl=" + window.location.href);
                $(".islogin .hover-color-green").eq(1).attr("href", DiliPath.registPath);
            }
        },
        setUserImage : function(){//获取用户图片
            Methods.http("http://user.nong12.com/api/userservice/getUserName.do", function(data){
                $("#my-face").attr("src", data.face);
            });
        },
		/* 动态设置底部HTML片段 */
        setFooter : 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].title + "</p><div class='f-list'>");
                    var vc = eval(data[i].extendsOne);
                    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></div>");
                        }
                    }
                }
                $(".footer .help ").html(html.join(""));
            }
        }
    };

    Methods.init();
});