/*jQuery placeholder, fix for IE6,7,8,9*/ var JPlaceHolder = { _check : function(){ return 'placeholder' in document.createElement('input'); }, init : function(){ if(!this._check()){ this.fix(); } }, fix : function(){ jQuery(':input[placeholder]').each(function(index, element) { var self = $(this), txt = self.attr('placeholder'); self.nextAll('.placeholder').remove(); var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left'), paddingtop = self.css('padding-top'); var holder = $('').text(txt).css({position:'absolute', left:pos.left+1, top:pos.top, height:h, lienHeight:h, padding:self.css('padding'), color:'#aaa'}).appendTo(self.parent()); self.focusin(function(e) { holder.hide(); }).focusout(function(e) { if(!self.val()){ holder.show(); } }); holder.click(function(e) { holder.hide(); self.focus(); }); }); } }; $(document).ready(function(){ LOGIN.status(); //鑷姩鎻愮ず JPlaceHolder.init(); //鍦ㄧ嚎瀹㈡湇 $('#float01 .float01_link01').mouseenter(function(){ $('#concat-list').show(); }); $('#concat-list').mouseleave(function(){ $('#concat-list').hide(); }); if(typeof(layer) == 'undefined') { var layer = layui.layer; } }); /**鐧诲綍**/ var LOGIN = { show: function(toUrl){ $.post(shopUri+'user/checkLogin?isAjax=1',function(data){ if(MESSAGE.ajaxError(data)){ if(data.data && data.data.username){ if(toUrl != '') TOURL.go(toUrl); }else{ $('#toUrl').val(toUrl); IMGCODE.change('login_imgcode', 'login'); layui.use('layer', function(){ var layer = layui.layer; layer.open({ type :1 ,title: '瀹㈡埛鐧诲綍' ,content: $('#loginBox') ,btn: [] }); }); } } }, 'json'); }, check: function(){ var error = ''; var checkname_arr = new Array('username', 'password', 'checkcode'); for(var i in checkname_arr) { var obj = $('#login-form [name="'+checkname_arr[i]+'"]:visible'); if(obj.length > 0) { var val = $.trim(obj.val()); switch(checkname_arr[i]) { case 'username': if(val.length < 4) error = '璐﹀彿鑷冲皯4涓瓧绗?; break; case 'password': if (val.length < 6 || val.length > 20) error = '瀵嗙爜涓?~20涓瓧绗︾粍鍚?; break; case 'checkcode': if (!(/^[0-9a-zA-Z]{5}$/).test(val)) error = '楠岃瘉鐮佷笉姝g‘'; break; } if(error != '') { $('#login_error').show().html(error); obj.focus(); break; } } } if(error != '') return false; $.post(shopUri+'user/ajaxLogin?isAjax=1', $('#login-form').serialize(), function(data){ if(data.status){ $('#login_error').hide().html(''); var toUrl = $('#toUrl').val(); if(toUrl != ''){ TOURL.go(toUrl); }else{ location.reload(); } return false; }else{ switch(data.code) { case 'checkcode_error': $('#login_error').show().html(data.data); $('#login-form [name="checkcode"]').focus(); IMGCODE.change('login_imgcode', 'login'); break; default: $('#login_error').show().html(data.data); $('#login-form [name="username"]').focus(); break; } } }, 'json'); return false; }, status:function(){ $.post(shopUri+'user/checkLogin?isAjax=1',function(data){ if(MESSAGE.ajaxError(data)){ if(data.data && data.data.username){ var html = '鍡紝'+data.data.username+' 涓汉涓績 [閫€鍑裹/a>]'; $('#login-a').parent().prepend(html); $('#login-a').remove(); if(data.data.carCount > 0) $('#cartCount').html(data.data.carCount); } } }, 'json'); } }; var AJAX = { //鍚屾鎵ц锛屼竴鑸湪琛ㄥ崟楠岃瘉鏃朵娇鐢 synchronize: function(atype, aurl, adata){ var return_data = {}; adata['isAjax'] = 1; $.ajax({ type: atype, url: aurl, async: false, data: adata, dataType: "jsonp", success:function(data){ return_data = data; } }); return return_data; } }; //楠岃瘉鐮 var IMGCODE = { change:function(toid, type){ $('#'+toid+'').attr('src', shopUri+'index/imgcode?type='+type+'&t='+Math.random()); }, check:function(val){ return AJAX.synchronize("post", shopUri+"index/checkImgcode", {"val": val}); } }; var MOBILECODE = { //mobile鎵嬫満鍙风爜, code楠岃瘉鐮? act鍔熻兘(bind|unbind|password) check:function(mobile, code, act){ return AJAX.synchronize("post", shopUri+"index/checkMobilecode", {'mobile': mobile, 'code': code, 'act':act}); } }; //甯哥敤JS楠岃瘉 var VERIFICATION = { email: function(val){ return (/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test($.trim(val)); }, imgcode: function(val){ return (/^[0-9a-zA-Z]{5}$/).test($.trim(val)); }, username: function(val){ return (/^(?![0-9]+$)[0-9A-Za-z_]{4,20}$/).test($.trim(val)); }, //鏀粯瀹 alipay: function(val){return (VERIFICATION.email(val) || VERIFICATION.mobile(val)); }, //閾惰鍗 bankCard: function(val){ return (/^(\d{16}|\d{19})$/).test($.trim(val)); }, worker_name: function(val){ return (/^[0-9A-Za-z_]{4,20}$/).test($.trim(val)); }, tel: function(val){ return (/^$/).test($.trim(val)); }, mobile: function(val){ return (/^1\d{10}$/).test($.trim(val)); }, mobile_code: function(val){ return (/^\d{6}$/).test($.trim(val)); }, is_int: function(val){return (/^[1-9]\d*$/).test($.trim(val)); }, strlen:function(val){return $.trim(val).replace(/[^\x00-\xff]/g,"xx").length;}, companyName:function(val){ return (/^[\u4e00-\u9fa5]{5,}$/).test($.trim(val)); }, societyCode:function(val){ return (/^[0-9a-zA-Z]{14,18}$/).test($.trim(val)); }, //寮哄埗淇濈暀灏忔暟鐐逛綅鏁 floatNum:function(num, count){ var f = parseFloat(num); if (isNaN(f)) return false; var f = new Number(num).toFixed(count); var s = f.toString(); var rs = s.indexOf('.'); if (rs < 0) { rs = s.length; s += '.'; } while (s.length <= rs + count) { s += '0'; } return parseFloat(s).toFixed(count); }, check: function(){ $('[check]').each(function(i1, e1){ var anyCheck = $(e1).attr('check').split(' '); for(var i in anyCheck) { var type = anyCheck[i].split(':'); switch(type[0]) { //瀛楃缁熻count:200 case 'count': var maxCount = parseInt(type[1]); $(e1).after(''+VERIFICATION.strlen($(this).val())+'/'+maxCount+''); $(e1).keyup(function(){ var len = VERIFICATION.strlen($(this).val()); $(this).nextAll('.check-count').eq(0).find('span').html(len); if(len > maxCount) $(this).nextAll('.check-count').eq(0).find('span').addClass('red'); else $(this).nextAll('.check-count').eq(0).find('span').removeClass('red'); }).blur(function(){ $(this).val(STRING.subString($(this).val(), maxCount)); $(this).nextAll('.check-count').eq(0).find('span').removeClass('red').html(VERIFICATION.strlen($(this).val())); }); break; //price:0.01:9999.99[鏈€澶у€煎彲閫塢 case 'price': var min = parseFloat(type[1]); $(e1).keyup(function(){ var val= $(this).val().replace(/[^\d.]/g,"").replace(/^\./g,"").replace(/\.{2,}/g,".").replace(".","$#$").replace(/\./g,"").replace("$#$","."); $(this).val(val); }).blur(function(){ var val= $(this).val().replace(/[^\d.]/g,"").replace(/^\./g,"").replace(/\.{2,}/g,".").replace(".","$#$").replace(/\./g,"").replace("$#$","."); if(!(/^\d+(\.\d+)?$/).test(val) || val < min){ val = min; }else if(type.length == 3){ var max = parseFloat(type[2]); if(val > max) val = max; } $(this).val(VERIFICATION.floatNum(val, 2)); }); break; case 'shopVipPrice': var min = parseFloat(type[1]); $(e1).keyup(function(){ var val= $(this).val().replace(/[^\d.]/g,"").replace(/^\./g,"").replace(/\.{2,}/g,".").replace(".","$#$").replace(/\./g,"").replace("$#$","."); if(val){ $(this).val(val); } }).blur(function(){ var val= $(this).val().replace(/[^\d.]/g,"").replace(/^\./g,"").replace(/\.{2,}/g,".").replace(".","$#$").replace(/\./g,"").replace("$#$","."); if(!(/^\d+(\.\d+)?$/).test(val) || val < min){ val = min; }else if(type.length == 3){ var max = parseFloat(type[2]); if(val > max) val = max; } if(val && val>0){ $(this).val(VERIFICATION.floatNum(val, 2)); }else{ $(this).val(''); } }); break; //number:1:99[鏈€澶у€煎彲閫塢 case 'number': $(e1).keyup(function(){ var min = parseInt(type[1]); var val = $(this).val().replace(/\D|^0/g,''); if (!(/^\d+$/).test(val) || val < min){ val = min; }else if(type.length == 3){ var max = parseInt(type[2]); if(val > max) val = max; } $(this).val(val); }); break; //娴偣鏁癴loat:1:8.5:99.2[鏈€澶у€煎彲閫塢 case 'float': $(e1).keyup(function(){ var val= $(this).val().replace(/[^\d.]/g,"").replace(/^\./g,"").replace(/\.{2,}/g,".").replace(".","$#$").replace(/\./g,"").replace("$#$","."); $(this).val(val); }).blur(function(){ var len = parseInt(type[1]); var min = parseFloat(type[2]); var val= $(this).val().replace(/[^\d.]/g,"").replace(/^\./g,"").replace(/\.{2,}/g,".").replace(".","$#$").replace(/\./g,"").replace("$#$","."); if(!(/^\d+(\.\d+)?$/).test(val) || val < min){ val = min; }else if(type.length == 4){ var max = parseFloat(type[3]); if(val > max) val = max; } if(len > 0) $(this).val(VERIFICATION.floatNum(val, len)); else $(this).val(val); }); break; } } }); } }; /** * @method 娑堟伅寮圭獥 * @author soul 2017/6/16 * @example MESSAGE.alert('aa'); MESSAGE.confirm('纭畾瑕佸垹闄ゆ璁板綍鍚?, "test(1,2)"); callback涓哄洖璋冩柟娉曠殑瀛楃涓 MESSAGE.show('璺戣鐨勭敤鎴锋敞鍐屽崗璁?, '鍗忚鍐呭', ''); */ var MESSAGE = { alert: function(msg){ MESSAGE.allType('alert', '娑堟伅鎻愮ず', msg, '', ''); }, //tarId銆愮己鐪併€戞寚瀹氬姞杞界殑鏍囩ID show:function(title, msg, foot, tarId){ if(!arguments[3]) var tarId = ''; MESSAGE.allType('show', title, msg, foot, tarId); }, confirm: function(msg, callback){ MESSAGE.allType('confirm', '娓╅Θ鎻愰啋', msg, callback, ''); }, ajaxError: function(json){ var errorMsg = ''; if(json.hasOwnProperty("status") && json.status){ }else if(json.hasOwnProperty("code")){ if(json.code == 'noLogin'){ TOURL.login(); return false; } errorMsg = json.data; }else{ errorMsg = '缃戠粶寮傚父锛岃绋嶅悗閲嶈瘯锛?; } if(errorMsg != ''){ if($('.message_box:visible').length > 0){ alert(json.data); }else{ MESSAGE.allType('alert', '娑堟伅鎻愮ず', json.data, '', ''); } return false; } return true; }, //鍙互绉诲姩鐨 moveBox: function(title, msg, foot, tarId){ if(!arguments[3]) var tarId = ''; MESSAGE.allType('move', title, msg, foot, tarId); }, allType: function(type, title, msg, foot, tarId){ var randClass = ''; if(tarId == '') { randClass = ' message_rand'; tarId = 'massage_'+ (new Date().getTime() + Math.ceil(Math.random()*1000000)); } $('.message_box:not("#'+tarId+'")').hide(); if($('#'+tarId).length < 1) { if(type == 'confirm'){ var footHtml = '
'; }else{ var footHtml = foot == ''? '': '