
LCGT.setcookie("isLogin", '', 0, 0, 1);
window.console = window.console || {
    log: function() {}
};



LCGT.getMousePos = function(event) {
    var e = event || window.event;
    var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
    var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
    var x = e.pageX || e.clientX + scrollX;
    var y = e.pageY || e.clientY + scrollY;
    return {
        'x': x,
        'y': y
    }
}

//--未登录提示
LCGT.loginTips = function(a) {
    var el = $(".login-tips");
    if (!el.length) {
        el = $('<div class="login-tips">');
        el.html('<div class="bd clearfix"><i class="ico"></i><span class="words">提示：登录后方可进行询价</span><a class="btn">登录</a></div><div class="close"></div>');
        $("body").append(el);
        el.find('.close').off('click').on('click', function(event) {
            el.css('display', 'none');
        });
        el.find('.btn').off('click').on('click', function(event) {
            el.remove();
            LCGT.loginWidget();//新登录框
            //LCGT.loginPopup.init();
        });
    }
    if (el.css('display') == 'none') {
        var pos = LCGT.getMousePos(a);
        el.css({
            display: 'block',
            left: pos.x - 282,
            top: pos.y
        });
    }
}




//保存是否公开询价信息
function save_inquiry_contact(obj, type) {
    //open_contact 是否公开联系方式,0为不操作，1为不公开，2为公开
    var is_open = type == 'b' ? 1 : 2;
    //是否公开询价信息
    $.ajax({
        type: 'POST',
        dataType: "text",
        url: '/inquiry/openContact',
        data: {is_open:is_open},
        success: function (response) {
            try{
                var data = JSON.parse(response);
                //if(data['code']==1){
                //    alert('保存成功');
                //}else{
                //    alert('保存失败');
                //}
                if (data['code'] == 1) {
                    LCGT.msg({
                        content: "保存成功"
                    });
                    //alert('保存成功');
                    document.location.reload();
                }else if(data['code']==-1) {
                    //未登录
                    LCGT.loginTips(event);
                } else {
                    LCGT.msg({
                        content: "保存失败"
                    });
                    //alert('保存失败');
                    //var goods_id = $(obj).attr('goods_id');
                    //$('#login_inquiry').hide();
                    //$('#open_contact_inquiry').hide();
                    ////get_goods_inquiry(goods_id);
                }
            }catch(e){

            }
        }
    });

}

/////////////////////热门商品询价////////////////////////////////
//--点击询价
LCGT.inquiry2 = function() {
    var el = $(".hot-pro .yywebwer");
    //var isLogin = LCGT.getcookie("isLogin");
    //var inquiry = el.attr('data-inquiry');
    el.off('click').on('click', function(event) {
        //已经询价按钮
        if ($(this).hasClass('yywebwer-ckxj')) {
            //打开弹框
            //LCGT.popup({
            //    el: "#open_contact_inquiry"
            //});
            return true;//继续跳转
        }else{
            var self = this;
            var inquiryId = $(this).attr('data-inquiry');
            var inquiryNum = $('#inquiry2_number'+inquiryId).val();
            var inquiryNum = parseFloat(inquiryNum);
            if(inquiryNum&&inquiryNum>0) {
            }else{
                //失败提示
                LCGT.tips({
                    el: $('#inquiry2_number' + inquiryId),
                    text: '请输入正确的数量'
                });
                return;
            }
            //发起询价
            $.ajax({
                type: 'POST',
                dataType: "text",
                url: '/product/inquiry',
                data: {goods_id:inquiryId,num:inquiryNum},
                success: function (response) {
                    try{
                        var data = JSON.parse(response);
                        if(data['code']==1){
                            $('#inquiry2_no_'+inquiryId).hide();
                            $('#inquiry2_yes_'+inquiryId).show();
                            //询价成功
                            //alert('询价成功');
                            LCGT.msg({
                                content: "询价成功"
                            });
                        }else if(data['code']==-1) {
                            //未登录
                            LCGT.loginTips(event);
                        }else{
                            //失败提示
                            LCGT.tips({
                                el: $(self),
                                text: data['msg']
                            });
                            //alert(data['msg']);
                        }
                    }catch(e){

                    }
                }
            });

        }

        return false;
    });
}

$(function() {
    LCGT.inquiry2();
})

/////////////////////产品列表询价部分 已经迁移到search-panel.js////////////////////////////////
