锘縱ar ct={}; $.ajaxSetup({cache:false}); $(function(){ $.cart=new CartHelper; //鍥炬爣 $('body').append(''); $('#get-box .my-cart').hover(function(){ ct.refresh_cart_view(false); },function(){ }).attr('href', ct.getHost()+'/customer/cart'); $('.btn-show-to-cart').click(function(){ location= ct.getHost() +'/customer/cart'; return false; }); //浜у搧鍒楄〃娣诲姞杩涜喘鐗╄溅 $('.btn-add-to-cart2').click(function(){ var me=$(this),pdiv=me.parent().parent(); var ckds=pdiv.find('table input[name="hidden"]'); var qlt=pdiv.find('table input[type="text"]'); var len = 0; $(qlt).each(function(qq,tt){ if($(tt).val() > 0){ len++; } }); if(len<=0){ alert('Please enter at least 1 quantity.');return false; } var carts=[]; $(qlt).each(function(kk,vv){ if($(vv).val() > 0){ var pcart={}; pcart.pid=$(vv).next().val(); pcart.qlt=$(vv).val(); carts.push(pcart); } }).attr('action',''); ct.add_pro(carts,pdiv); }); $("input[name=qlt]").each(function(){ $(this).blur(function(){ var par=/\D/g; not_number=par.test($(this).val()); if(not_number){ alert('鏁伴噺蹇呴』鏄暟瀛?); return false; } }); }); $(".btn-add-to-cart.btn-green").click(function(){ pdiv=$(".product_table_cart_div") var carts=[]; var ckds = $(".product_table_cart_div").find('table input:checked'); if(ckds.length<=0){ alert('璇烽€夋嫨浜у搧');return false; } $(ckds).each(function(kk,vv){ pid=$(this).parents('tr').find('.pid').find('.product_id').html(); catalog_no=$(this).parents('tr').find('.catalog_no').html(); name=$("h1").html(); plink=document.URL; size=$(this).parents('tr').find('.size').html(); price=$(this).parents('tr').find('.price').html(); qlt=$(this).parents('tr').find('input[name="qlt"]').val(); carts[kk]={'catalog_no':catalog_no,'pid':pid,'name':name,'plink':plink,'size':size,'price':price,'qlt':qlt}; }).attr('action',''); // console.log(carts); ct.add(carts,pdiv); }); //鐩稿叧浜у搧 $("div.product_related .button-box .btn-add-to-cart.button-related").click(function(){ pdiv=$(".product_related") var ckds=pdiv.find('table.gridtable input:checked'); if(ckds.length<=0){ alert('璇烽€夋嫨浜у搧');return false; } // console.log(ckds); var carts=[]; $(ckds).each(function(kk,vv){ catalog_no=$(this).parents('tr').find('.catalog_no').html(); name=$(this).parents('tr').find('.name').html(); plink=$(this).parents('tr').find('.name').attr('href'); size=$(this).parents('tr').find('.size').html(); price=$(this).parents('tr').find('.price').html(); pid=$(this).parents('tr').find('input[name="pid"]').val(); qlt=$(this).parents('tr').find('input[name="qlt"]').val(); carts[kk]={'catalog_no':catalog_no,'pid':pid,'name':name,'plink':plink,'size':size,'price':price,'qlt':qlt}; }).attr('action',''); ct.add(carts,pdiv); }); ct.update_num(); }); ////////////////////////////////////////////////////鍔犲叆璐墿杞﹀姩鐢 ct.add_animate=function(me){ var cartView=$('#ge-cart'); var btn=cartView.clone(); var addBtn=me.find('.btn-add-to-cart'); btn.css({ 'z-index': 9000, 'display': 'block', 'position': 'absolute', 'top': addBtn.offset().top +'px', 'left': addBtn.offset().left+30 +'px', 'width': cartView.width() +'px', 'height': cartView.height() +'px' }); $('body').append(btn); var win_width=$(window).width(); var _left=Math.ceil(win_width/2+610); var speed=1000; speed=Math.ceil(me.offset().top/1000)*1000; btn.animate({ top:70, left:_left, width:100, height:50 },speed,function(){ $(this).remove(); }); }; ///////////////////////////////////////////////////////娣诲姞涓€鏉¤褰 ct.add=function(data,me){ ct.add_animate(me); $.ajax({ url:ct.getHost()+'/customer/cart/add?sign=t21', data:{carts:data}, type:'post', dataType:'jsonp', success:function(d){ if(d.status){ if(d.status == -1){ ct.location_info(d.data); }else{ //ct.show_info(); $('#get-box .my-cart').html('('+d.data+')My Cart'); ct.refresh_cart_view(true); } }else{ alert('Error') } }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("Error"); } }); }; ///////////////////////////////////////////////////////浜у搧鍒楄〃椤垫坊鍔犱竴鏉¤褰 ct.add_pro=function(data,me){ ct.add_animate_pro(me); $.ajax({ url:ct.getHost()+'/customer/cart/add?sign=t21', data:{carts:data}, type:'post', dataType:'jsonp', success:function(d){ if(d.status){ if(d.status == -1){ ct.location_info(d.data); }else{ //ct.show_info(); $('#get-box .my-cart').html('('+d.data+')My Cart'); ct.refresh_cart_view(true); } }else{ alert('Error') } } }); }; ////////////////////////////////////////////////////浜у搧鍒楄〃椤靛姞鍏ヨ喘鐗╄溅鍔ㄧ敾 ct.add_animate_pro=function(me){ var cartView=$('#ge-cart'); var btn=cartView.clone(); var addBtn=me.find('.btn-add-to-cart2'); btn.css({ 'z-index': 9000, 'display': 'block', 'position': 'absolute', 'top': addBtn.offset().top +'px', 'left': addBtn.offset().left+30 +'px', 'width': cartView.width() +'px', 'height': cartView.height() +'px' }); $('body').append(btn); var win_width=$(window).width(); var _left=Math.ceil(win_width/2+610); var speed=1000; speed=Math.ceil(me.offset().top/1000)*1000; btn.animate({ top:70, left:_left, width:100, height:50 },speed,function(){ $(this).remove(); }); } //璺宠浆缃戠珯椤甸潰寮瑰嚭鎻愮ず妗 ct.location_info=function(info){ $('#show_alert').html(info); $( "#show_alert" ).dialog({ resizable: false, width:500, title:"Add to cart", modal: true, buttons: { "OK": function() { $( this ).dialog( "close" ); } } }); $("#show_alert").css({"text-align":"center"}); }; //浜у搧娣诲姞鎴愬姛浠ュ悗寮瑰嚭鎻愮ず妗 ct.show_info=function(){ $('#show_alert').text("娣诲姞璐墿杞︽垚鍔?); $( "#show_alert" ).dialog({ resizable: false, width:500, title:"娣诲姞璐墿杞?, modal: true, buttons: { "缁х画璐墿": function() { $( this ).dialog( "close" ); }, "鏌ョ湅璐墿杞 & 缁撶畻": function() { window.location.href = "/customer/cart"; //$( this ).dialog( "close" ); } } }); $("#show_alert").css({"text-align":"center"}); } ct.del=function(){ } ct.getHost=function(){ return 'https://'+location.host; } //////////////////////////////////////////////////////鏄剧ずcart view ct.refresh_cart_view=function(frflag){ if($('.my-cart-div').length>0 && frflag==false ){ $('.my-cart-div').slideDown();return; } //$('.my-cart-div').remove(); //璁$畻涓棿鐨勪綅缃? $("#get-box").prepend("
"); $(".my-cart-div-box").prepend(""); var my_cart_div=$('.my-cart-div').html('load....').show(); $.ajax({ url:ct.getHost()+'/customer/cart/get', dataType:'jsonp', success:function(d){ var t="

"; if(d.data=='no'){ //no content t+="

璐墿杞︿腑杩樻病鏈夊晢鍝侊紝璧剁揣閫夎喘鍚э紒

"; my_cart_div.html(t); my_cart_div.slideDown().hover(function(){},function(){ my_cart_div.slideUp(); }); return; } var result=d.data; t+=''; var json = result.list; $(json).each(function(k,v){ t+=''; if(k == 4){ t+=''; return false; } }); t+="
浜у搧缂栧彿浠锋牸('+result.currency_unit+')鏁伴噺
'+v.code+''+v.unit_price+''+v.quantity+'
禄 鏌ョ湅鏇村
"; t+="

鏌ョ湅璐墿杞?/a>

"; t+="

鍒锋柊

"; t+=""; my_cart_div.html(t); my_cart_div.slideDown().hover(function(){},function(){ my_cart_div.slideUp(); }); ct.update_num(); } }); } ct.refresh_cart_view_Anchor=function(frflag){ if($('.my-cart-div2').length>0 && frflag==false ){ $('.my-cart-div2').slideDown();return; } //$('.my-cart-div').remove(); //璁$畻涓棿鐨勪綅缃? $("#Anchor").prepend("
"); $("#Anchor .my-cart-div-box2").prepend(""); var my_cart_div=$('.my-cart-div2').html('load....').show(); $.ajax({ url:ct.getHost()+'/customer/cart/get', dataType:'jsonp', success:function(d){ var t="

"; if(d.data=='no'){ //no content t+="

璐墿杞︿腑杩樻病鏈夊晢鍝侊紝璧剁揣閫夎喘鍚э紒

"; my_cart_div.html(t); my_cart_div.slideDown().hover(function(){},function(){ my_cart_div.slideUp(); }); return; } var result=d.data; t+=''; var json = result.list; $(json).each(function(k,v){ t+=''; if(k == 4){ t+=''; return false; } }); t+="
浜у搧缂栧彿浠锋牸('+result.currency_unit+')鏁伴噺
'+v.code+''+v.unit_price+''+v.quantity+'
禄 鏌ョ湅鏇村
"; t+="

鏌ョ湅璐墿杞?/a>

"; t+="

鍒锋柊

"; t+=""; my_cart_div.html(t); my_cart_div.slideDown().hover(function(){},function(){ my_cart_div.slideUp(); }); ct.update_num(); } }); } function r(){ location=location } ////////////////////////////////////////////////////// ct.update_num=function(){ //璺熸柊鏁伴噺 $.ajax({ url:ct.getHost()+'/customer/cart/count', dataType:'jsonp', success:function(d){ if(d.status){ $('span.my-cart').html( '('+d.data+') 璐墿杞? ); if(d.data !== 0){ $('#Anchor .my-cart').html('' + d.data + ''); }else{ $('#Anchor .cart-number').css('display', 'none'); } }else{ alert('Error') } } }); };