$(function() { var controller = $('#search ul.tab').attr('dstype'); $('#search ul.tab li span').eq(0).html('商品'); $('#search-form').attr("action", HOMESITEURL + "/Search/index.html"); $('#search').hover(function() { $('#search ul.tab li').eq(1).show(); $('#search ul.tab li i').addClass('over').removeClass('arrow'); }, function() { $('#search ul.tab li').eq(1).hide(); $('#search ul.tab li i').addClass('arrow').removeClass('over'); }); $('#search ul.tab li').eq(1).click(function() { $(this).hide(); $('#keyword').attr('placeholder', '请输入您要搜索的商品关键字'); $('#search ul.tab li span').eq(0).html('商品'); $('#search-form').attr("action", HOMESITEURL+"/Search/index.html"); $("#keyword").focus(); }); }); /** * * @param {type} formid form表单ID * @param {type} type 返回类型 reload 刷新当前界面 default 保持默认状态不做刷新 * @param {type} url 跳转的连接地址 * @param {type} time 跳转的时间 * @returns {undefined} */ function ds_ajaxpost(formid,type,url,waittime){ if (typeof(waittime) == "undefined"){ waittime = 1000; } var _form = $("#"+formid); $.ajax({ type: "POST", url: _form.attr('action'), data: _form.serialize(), dataType:"json", success: function (res) { // layer.msg(res.message, {time: waittime}, function () { if (res.code == 10000) { if (typeof (type) == 'undefined' && type == null && type == '') { location.reload(); } else if(type=='url') { location.href = url; } else if(type=='default') { //不做操作只显示 }else{ location.reload(); } } // }); } }); } /** * * @param {type} url URL链接地址 * @param {type} type 返回类型 reload remove(移除指定行) default默认不做任何操作 * @param {type} param 参数 * @returns {undefined} */ function ds_ajaxget(url,type,param) { $.ajax({ url: url, type: "get", dataType: "json", success: function (data) { layer.msg(data.message, {time: 1000}, function () { if (data.code == 10000) { if (typeof (type) == "undefined" || type == null || type == '' || type=='reload') { location.reload(); } else if (type == "remove") { $("#ds_row_" + param).remove(); }else { //不做操作 } } }); } }); } /** * * @param {type} url URL链接地址 * @param {type} msg 显示提示内容 * @param {type} type 返回类型 reload remove(移除指定行) default默认不做任何操作 * @param {type} param 参数 * @returns {undefined} */ function ds_ajaxget_confirm(url,msg,type,param) { if (typeof (msg) != 'undefined' && msg != null && msg != '') { layer.confirm(msg, { btn: ['确定', '取消'], title: false, }, function () { ds_ajaxget(url,type,param); }); }else{ ds_ajaxget(url,type,param); } } /** * * @param {type} msg 显示提示 * @param {type} url 跳转URL * @returns {undefined} */ function ds_get_confirm(msg, url){ if(msg != ''){ layer.confirm(msg, { btn: ['确定', '取消'], title: false, }, function () { window.location = url; }); }else{ window.location = url; } } function go(url){ window.location = url; } /* 格式化金额 */ function price_format(price){ if(typeof(PRICE_FORMAT) == 'undefined'){ PRICE_FORMAT = '¥%s'; } price = number_format(price, 2); return price; } function number_format(num, ext){ if(ext < 0){ return num; } num = Number(num); if(isNaN(num)){ num = 0; } var _str = num.toString(); var _arr = _str.split('.'); var _int = _arr[0]; var _flt = _arr[1]; if(_str.indexOf('.') == -1){ /* 找不到小数点,则添加 */ if(ext == 0){ return _str; } var _tmp = ''; for(var i = 0; i < ext; i++){ _tmp += '0'; } _str = _str + '.' + _tmp; }else{ if(_flt.length == ext){ return _str; } /* 找得到小数点,则截取 */ if(_flt.length > ext){ _str = _str.substr(0, _str.length - (_flt.length - ext)); if(ext == 0){ _str = _int; } }else{ for(var i = 0; i < ext - _flt.length; i++){ _str += '0'; } } } return _str; } /* 火狐下取本地全路径 */ function getFullPath(obj) { if(obj) { //ie if (window.navigator.userAgent.indexOf("MSIE")>=1) { obj.select(); if(window.navigator.userAgent.indexOf("MSIE") == 25){ obj.blur(); } return document.selection.createRange().text; } //firefox else if(window.navigator.userAgent.indexOf("Firefox")>=1) { if(obj.files) { //return obj.files.item(0).getAsDataURL(); return window.URL.createObjectURL(obj.files.item(0)); } return obj.value; } return obj.value; } } /* 转化JS跳转中的 & */ function transform_char(str) { if(str.indexOf('&')) { str = str.replace(/&/g, "%26"); } return str; } //图片垂直水平缩放裁切显示 (function($){ $.fn.VMiddleImg = function(options) { var defaults={ "width":null, "height":null }; var opts = $.extend({},defaults,options); return $(this).each(function() { var $this = $(this); var objHeight = $this.height(); //图片高度 var objWidth = $this.width(); //图片宽度 var parentHeight = opts.height||$this.parent().height(); //图片父容器高度 var parentWidth = opts.width||$this.parent().width(); //图片父容器宽度 var ratio = objHeight / objWidth; if (objHeight > parentHeight && objWidth > parentWidth) { if (objHeight > objWidth) { //赋值宽高 $this.width(parentWidth); $this.height(parentWidth * ratio); } else { $this.height(parentHeight); $this.width(parentHeight / ratio); } objHeight = $this.height(); //重新获取宽高 objWidth = $this.width(); if (objHeight > objWidth) { $this.css("top", (parentHeight - objHeight) / 2); //定义top属性 } else { //定义left属性 $this.css("left", (parentWidth - objWidth) / 2); } } else { if (objWidth > parentWidth) { $this.css("left", (parentWidth - objWidth) / 2); } $this.css("top", (parentHeight - objHeight) / 2); } }); }; })(jQuery); function ResizeImage(ImgD,FitWidth,FitHeight){ var image=new Image(); image.src=ImgD.src; if(image.width>0 && image.height>0) { if(image.width/image.height>= FitWidth/FitHeight) { if(image.width>FitWidth) { ImgD.width=FitWidth; ImgD.height=(image.height*FitWidth)/image.width; } else { ImgD.width=image.width; ImgD.height=image.height; } } else { if(image.height>FitHeight) { ImgD.height=FitHeight; ImgD.width=(image.width*FitHeight)/image.height; } else { ImgD.width=image.width; ImgD.height=image.height; } } } } function trim(str) { return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, ''); } //弹出框登录 function login_dialog(){ CUR_DIALOG = ajax_form('login','登录',HOMESITEURL+'/Login/login.html?inajax=1',360,1); } /* 显示Ajax表单 */ function ajax_form(id, title, url, width, model) { if (!width) width = 480; if (!model) model = 1; var d = DialogManager.create(id); d.setTitle(title); d.setContents('ajax', url); d.setWidth(width); d.show('center',model); return d; } //显示一个内容为自定义HTML内容的消息 function html_form(id, title, _html, width, model) { if (!width) width = 480; if (!model) model = 0; var d = DialogManager.create(id); d.setTitle(title); d.setContents(_html); d.setWidth(width); d.show('center',model); return d; } //收藏商品js function collect_goods(fav_id, jstype, jsobj) { $.get(HOMESITEURL+'/Index/login.html', function(result) { if (result == '0') { //login_dialog(); $(".tips-wrap").addClass("show") } else { var url = HOMESITEURL+'/Memberfavorites/favoritesgoods'; $.getJSON(url, {'fid': fav_id}, function(data) { if (data.done) { layer.msg(data.msg); if (jstype == 'count') { $('[dstype="' + jsobj + '"]').each(function() { $(this).html(parseInt($(this).text()) + 1); }); } if (jstype == 'succ') { $('[dstype="' + jsobj + '"]').each(function() { $(this).html("收藏成功"); }); } } else { layer.msg(data.msg); } }); } }); } //加载购物车信息 function load_cart_information() { $.getJSON(HOMESITEURL + '/Cart/ajax_load', function(result) { var obj = $('.header .user_menu .my-cart'); var mini =$('#rtoolbar_cartlist'); if (result) { var html = ''; if (result.cart_goods_num > 0) { for (var i in result['list']) { var goods = result['list'][i]; html += '
共' + result.cart_goods_num + '种商品
共计:¥' + result.cart_all_price + '
'); if (obj.find('.addcart-goods-num').size() == 0) { obj.append('