// 鍟嗗煄鍏叡 window.is_login=M['user_name']!=''?true:false, $topcart=$("#topcart-body"); $(function(){ // 鍙充笂瑙掕喘鐗╄溅 if($topcart.length){ loadTopcart(); // 鍒犻櫎鍟嗗搧 $topcart.on('click','.topcart-remove',function(e){ e.preventDefault(); $(this).parents('.list-group-item').append('
').find('.media').hide(); $.ajax({ url:$(this).attr('href'), type:'GET', dataType:'json', success:function(result){ metShopAjaxFun(result,function(){ $topcart.find('.cart-loader').remove(); $topcart.find('.media').show(); },function(){ setTimeout(function(){ var $topcart_dropdown=$topcart.parents('.scrollable'); if($topcart.find('.list-group-item').length>1) $topcart.find('.cart-loader').parents('.list-group-item').remove(); loadTopcart('new'); $topcart_dropdown.asScrollable('update'); $topcart_dropdown.asScrollable('unStyle'); },300) }); } }); }); } $('.topcart-btn').click(function() { if(!$topcart.is(':visible')) $topcart.parent('.scrollable-container').height(''); }); // 浼氬憳鐧诲綍琛ㄥ崟楠岃瘉 if($('.login-member form').length){ metFormvalidationLoadFun(function(){ setTimeout(() => { var login_member_form_index=$('.login-member form').index('form'); validate[login_member_form_index].success(function(result,form){ if(result.status){ $('.summary-errors').remove(); location = result.msg; }else{ $('.summary-errors').html(result.msg).removeAttr('hidden'); } }) },500); }); } // 浠ユ父瀹㈣韩浠界粨绠 $('.login-guest-btn').click(function(e) { e.preventDefault(); $.ajax({ url: $(this).attr('href'), type: 'GET', dataType:'json', success: function(result) { if(result.error){ $('.summary-errors').removeAttr('hidden').find('p').html(result.error); }else if(result.success){ location = result.success; } } }); }); // 璐墿杞﹂〉闈㈢殑鏇村浜у搧 // var $masonry=$('.masonry'); // if($masonry.find('.masonry-child').length>1){ // metFileLoadFun(M['plugin']['masonry'],function(){ // return typeof $.fn.masonry=='function'; // },function(){ // setTimeout(function(){ // $masonry.masonry({itemSelector:".masonry-child"}); // },500); // }); // } // 璁㈠崟鍒楄〃銆佷紭鎯犲埜鍒楄〃閫夐」鍗″浐瀹氬湪澶撮儴 var $shop_navtab=$('.shop-discount-state,.shop-order-state'); if($shop_navtab.length){ Breakpoints.on('xs sm md',{ enter:function(){ var shop_navtab_h=$shop_navtab.height(), shop_navtab_p_t=$shop_navtab.parent().offset().top; $shop_navtab.parent().height(shop_navtab_h); $(window).scroll(function(event) { if($(this).scrollTop()>$shop_navtab.parent().offset().top+shop_navtab_h){ $shop_navtab.addClass('met-fixed animation-slide-top w-full bg-white p-x-25'); }else{ $shop_navtab.removeClass('met-fixed animation-slide-top w-full bg-white p-x-25'); } }); $shop_navtab.find('a').click(function() { if($(window).scrollTop()>shop_navtab_p_t) $(window).scrollTop(shop_navtab_p_t); }); } }) } // 鍏朵粬椤甸潰鍔犺浇鏂囦欢锛坢etv6銆佽€佹ā鏉裤€乁I妯℃澘shop椤甸潰锛 if(M['plugin'] || $('script[src*="js/app.js"]').length){ var interval_appload=setInterval(function(){ if(M['plugin']){ clearInterval(interval_appload); if(typeof alertify =='undefined') $.include(M['plugin']['alertify']); if(($topcart.length || $('.btn-logistics-track,.order-converse,.reason-detail-imgs').length) && typeof $.fn.asscrollable =='undefined') $.include(M['plugin']['asscrollable'],'','siterun'); if($('.met-showproduct').length){ if($('script[src*="js/basic_web.js"]').length){// 鑰佹ā鏉胯皟鐢ㄥ晢鍩庨粯璁ら〉闈 M['plugin']['tablesaw']=[ M['url']['public_plugins']+'filament-tablesaw/tablesaw.min.css', M['url']['public_plugins']+'filament-tablesaw/tablesaw.min.js' ]; M['plugin']['slick']=[ M['url']['public_fonts']+'iconfont/iconfont.css', M['url']['public_web_register']+'slick/slick.min.css', M['url']['public_web_register']+'slick/slick-theme.min.css', M['url']['public_web_register']+'slick/slick.min.js' ]; M['plugin']['swiper']=[ M['url']['public_web_register']+'swiper/swiper-3.3.1.min.css', M['url']['public_web_register']+'swiper/swiper-3.3.1.jquery.min.js' ]; M['plugin']['lightGallery']=[ M['url']['public_web_register']+'lightGallery/css/lightgallery.min.css', M['url']['public_web_register']+'lightGallery/js/lightgallery.min.js', M['url']['public_web_register']+'lightGallery/js/lg-fullscreen.min.js', M['url']['public_web_register']+'lightGallery/js/lg-thumbnail.min.js', M['url']['public_web_register']+'lightGallery/js/lg-zoom.min.js' ]; M['plugin']['photoswipe']=[ M['url']['public_web_register']+'PhotoSwipe/photoswipe.min.css', M['url']['public_web_register']+'PhotoSwipe/default-skin/default-skin.min.css', M['url']['public_web_register']+'PhotoSwipe/photoswipe.min.js', M['url']['public_web_register']+'PhotoSwipe/photoswipe-ui-default.min.js', M['url']['public_web_register']+'PhotoSwipe/photoswipe-plugin.js' ]; if($(".met-editor table").length) $.include(M['plugin']['tablesaw']); $.include(M['plugin']['masonry']); if($('#met-imgs-slick .slick-slide').length>1) $.include(M['plugin']['slick']); $.include(M['plugin']['swiper']); if(M['device_type']=='m'){ $.include(M['plugin']['photoswipe']); }else{ $.include(M['plugin']['lightGallery']); } $.include([ M['url']['public_web_js']+'editor.js',// 缂栬緫鍣 M['url']['public_web_js']+'img_slick.js',// 灞曠ず鍥剧墖杞挱鍥 M['url']['public_web_js']+'product.js',// 浜у搧妯″潡 ]); } $.include(M['url']['own_tem']+'js/shop_showproduct.js'); } if($('.shoppro-discount').length){ $.include(M['url']['public_fonts']+'7-stroke/7-stroke.min.css'); if(typeof $.fn.webuiPopover =='undefined') $.include(M['plugin']['webui-popover']); $.include(M['url']['own_tem']+'js/discount.js'); } if($('.moregoods-list li').length && typeof $.fn.appear =='undefined') $.include(M['plugin']['appear'],function(){ $('.moregoods-list li [data-original]').trigger('scroll'); },'siterun'); if($('.cart-list').length){ $.include(M['plugin']['touchspin']); $.include(M['url']['own_tem']+'js/cart.js'); } if($('#addr-edit-modal').length) $.include(M['url']['own_tem']+'js/address.js'); if($('.shop-address').length) $.include(M['url']['own_tem']+'js/address_set.js'); if($('.pay-form').length){ M['plugin']['labelauty']=[ M['url']['public_plugins']+'jquery-labelauty/jquery-labelauty.min.css', M['url']['public_plugins']+'jquery-labelauty/jquery-labelauty.min.js' ]; $.include(M['plugin']['labelauty'],'','siterun'); $.include(M['url']['own_tem']+'js/pay.js'); } if($('.shop-order,.shop-order-check').length && typeof $.fn.webuiPopover =='undefined') $.include(M['plugin']['webui-popover'],'','siterun'); if($('.shop-order').length) $.include(M['url']['own_tem']+'js/order.js'); if($('.shop-order-check').length) $.include(M['url']['own_tem']+'js/order_check.js'); if($('.shop-favorite').length) $.include(M['url']['own_tem']+'js/favorite.js'); if($('.shop-discount').length) $.include(M['url']['own_tem']+'js/discount.js'); } },10); } }); // 鍙充笂瑙掕喘鐗╄溅 function loadTopcart(d){ if(!d) $topcart.html('
'); $.loadCartJson(function(json){ var html = '', num=0; $.each(json, function(i, item){ item.shopmax = item.purchase>0?item.purchase:item.stock; html += ''; num++; }) if(html==''){ html='
'+METLANG.app_shop_emptycart+'
'; $('.dropdown-menu-footer').hide(); }else{ $('.dropdown-menu-footer').show(); topcartTotal(json); } $('.topcart-goodnum').html(num).removeAttr('hidden'); if(d&&!num || !d) $topcart.html(html); },d); } // 璐墿杞︿环鏍 function topcartTotal(json){ $.ajax({ url: totalurl, type: "GET", cache: false, dataType: "jsonp", success: function(data) { if(data.message == 'ok'){ $('.topcart-total').html(data.price.goods.total_str); } } }); } $.extend({ // 璐墿杞︽暟鎹 loadCartJson:function(func,d){ $.ajax({ url: jsonurl, type: 'GET', dataType:'json', success: function(json) { func(json); } }); } }); // ajax璇锋眰杩斿洖鍚庨€氱敤澶勭悊 function metShopAjaxFun(result,false_fun,true_fun){ if(result.error){ alertify.error(result.error); if(typeof false_fun =='function') false_fun(); }else if(result.success){ alertify.success(result.success); if(typeof true_fun =='function'){ true_fun(); }else{ setTimeout(function(){ location.reload(); },500) } } }