$(function() { $("#Main_Form").fromsAuth({ type:'NONE', callafter:function(){ if(typeof ga == 'function') { var obj = JSON.parse($("#GA_Data").text()); for(var key in obj) { ga('ec:addProduct',obj[key]); } ga('ec:setAction','checkout',{ 'step':4 }); ga('send','event','購物車','確認訂單'); } return true; } }); var header_height = 100; if($(window).width() <= 480){ header_height = 70; } $('.product-link').on('click',function(){ if($('#productbox').length!=0){ $("html,body").animate({scrollTop: $('#productbox').offset().top - header_height},800); }else{ $("html,body").animate({scrollTop: $('#productlist').offset().top - header_height},800); } }); $('.article-link').on('click',function(){ $("html,body").animate({scrollTop: $('#articlebox').offset().top - header_height},800); }); $('.shopcart-link').on('click',function(){ $("html,body").animate({scrollTop: $('#s1').offset().top - header_height},800); }); $("#Main_Content").on('click', '#step2', function() { var sh = $("#s2 .section-wrapper").height() + 100; $("html,body").animate({scrollTop: $('#s2').offset().top - sh}, 800); }); $("#Main_Content").on('click', '#step3', function() { var sh2 = $("#s3").height(); if($(window).width() <= 480){ $("html,body").animate({scrollTop: $('#s3').offset().top - 70}, 800); } else { $("html,body").animate({scrollTop: $('#s3').offset().top}, 800); } }); $("#Main_Content").on('click','#productlist .button-full',function(){ if(!$(this).is('.button-cant')){ var $class = $(this).attr("class"), type = '1'; if($(this).hasClass('button-add')) { type = '2'; } $('.popupbg').addClass('is-show'); $('.popupbg').attr("type",type); $('.popupbg').empty().html($(this).parents(".productBox").find(".Box_Data").html()); $('.popupbg').find("[id^='product-']").each(function(){ let _this = $(this) let oldId = _this.attr("id") let newId = oldId + "-popup" _this.attr("id", newId) }) $('.popupbg').find("[for^='product-']").each(function(){ let _this = $(this) let oldFor = _this.attr("for") let newFor = oldFor + "-popup" _this.attr("for", newFor) }) moreviewInit() } }); $("#Main_Content").on('click','.popupbg .close',function(){ $('.popupbg').removeClass('is-show'); $('.popupbg').removeAttr('style'); }); $("#Main_Content").on('click','.informButton',function(){ $("#informID").val($(this).attr("sid")); $('.emailPopup').css('display','flex'); }); $("#Main_Content").on('click','.emailPopup .close',function(){ $('.emailPopup').css('display','none'); }); $("#Main_Content").on('click','#loginButton',function(){ $('.memberPopup').css('display','flex'); }); $("#Main_Content").on('click','.memberPopup .close',function(){ $('.memberPopup').css('display','none'); }); $("#Change_Pic").click(function(e){ $("#Checkspan").load('/ajax/ajax_get_check_pic.php',{change:1}); }); $("#Main_Content").on('focusin','.input-text',function(){ $(this).next('.text-title').addClass('now'); }); $("#Main_Content").on('focusout','.input-text',function(){ if($(this).val()==''){ $(this).next('.text-title').removeClass('now'); } }); $('.gotop').on('click',function(){ $("html,body").animate({scrollTop: 0},800); }); $('.header-wrapper').on('click', '.fa-bars', function(event) { $(this).removeClass('fa-bars').addClass('fa-times'); $(this).next('.header-aside').addClass('open'); }); $('.header-wrapper').on('click', '.fa-times', function(event) { $(this).removeClass('fa-times').addClass('fa-bars'); $(this).next('.header-aside').removeClass('open'); }); var _window = $(window); _window.on('scroll', function(event) { var scrollTop = _window.scrollTop(); if(scrollTop>0){ $(".gotop").css("opacity","1"); $("body").addClass('is-sticky'); // _body.css('padding-top',body_padding_s+'px'); }else{ $(".gotop").css("opacity","0"); $("body").removeClass('is-sticky'); // _body.css('padding-top',body_padding+'px'); } }); //時間倒數 var num = parseInt($("#CountDown_Box").attr("second"),10), _this = $("#CountDown_Box"); if(num > 0) { setInterval(function() { num--; if(num <= 0) { window.location.reload(); } var day = Math.floor(num/(3600*24)), hour = Math.floor((num - (day*3600*24) )/3600), min = Math.floor((num - (day*3600*24) - (hour*3600) )/60 ), second = num - (day*3600*24) - (hour*3600) - (min*60), pad = '00'; if(day > 0) { _this.find(".timer").eq(0).html(day); _this.find(".timer").eq(1).html(pad.substring(hour.toString().length)+hour); _this.find(".timer").eq(2).html(pad.substring(min.toString().length)+min); _this.find(".timer").eq(3).html(pad.substring(second.toString().length)+second); } else { _this.find(".Date_Box").remove(); _this.find(".timerbox").html(_this.find(".timerbox").html().replace('天','')); _this.find(".timer").eq(0).html(pad.substring(hour.toString().length)+hour); _this.find(".timer").eq(1).html(pad.substring(min.toString().length)+min); _this.find(".timer").eq(2).html(pad.substring(second.toString().length)+second); } },1000); } }); //刪除購物車 $("#Main_Content").on('click','.product-del',function() { $.ajax({ url:"/quickshop/ajax/ajax_del_cart.php", type:"POST", cache:false, data:{ID:$(this).attr("sid"), Page_Shop_ID:$("#Page_Shop_ID").val()}, dataType:'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Status == 'RET_SUCCESS') { if(d.GA && typeof ga == 'function') { for(var key in d.GA) { ga('ec:addProduct',d.GA[key]); } ga('ec:setAction','remove'); ga('send','event','購物車','移除購物車'); } alert('刪除成功'); updatePage(); } else { alert('資料庫忙線中'); } } }); setTimeout(function () { $('.emptyCartPrompt').fadeOut() }, 5000) }); //修改數量 $("#Main_Content").on('click','.Prod_Plus',function(){ var Amount = 1, SID = $(this).prev(".Prod_Amount").attr('sid'), Stock = parseInt($(this).attr("max")); //同商品總數量 $(".Prod_Amount").each(function(){ if($(this).attr('sid') == SID){ Amount += parseInt($(this).val()); } }); if(Amount > 100 || Amount > Stock) { return false; } changeAmount(SID,Amount); }); $("#Main_Content").on('click','.Prod_Minus',function(){ var Amount = -1, SID = $(this).next(".Prod_Amount").attr('sid'); //同商品總數量 $(".Prod_Amount").each(function(){ if($(this).attr('sid') == SID){ Amount += parseInt($(this).val()); } }); if(Amount < 1) { return false; } changeAmount(SID,Amount); }); $("#Main_Content").on('change','.Prod_Amount',function(){ var ID = $(this).parents(".listbox-item").find(".product-del").attr("sid"), Amount = $(this).val(); if(Amount > 100) { Amount = 100; } if(Amount < 1) { Amount = 1; } changeAmount(ID,Amount); }); function changeAmount(ID,Amount){ $.ajax({ url:"/quickshop/ajax/ajax_change_cart.php", type:"POST", cache:false, data:{ID:ID,Amount:Amount,Page_Shop_ID:$("#Page_Shop_ID").val()}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ var d = d.trim(); switch(d){ case "RET_SUCCESS": updatePage(); break; case "RET_NO_MEMBER_NO": alert('欲購買紅利兌換商品請先登入會員並完成會員認證'); break; case "RET_RBONUS_OUT": alert('紅利不足'); break; case "RET_ERROR": alert('資料庫忙線中'); break; case "RET_PROD_ERROR": alert('商品已下架'); break; case "RET_NO_PROD": alert('請選擇商品'); break; case "RET_STOCK_ERROR": alert('商品庫存不足'); break; case "RET_LIMIT_ERROR": alert('數量超過限購量'); break; default: alert('資料庫忙線中'); break; }; } }); } //活動字串 $("#Main_Content").on('click','#Act_Str_Button',function(){ var str = $("#Act_Str_Input").val(); if(str) { updatePage('&Act_Str='+str); } }); $("#Main_Content").on('click','#Act_Str_Cancel',function(){ updatePage('&Act_Str=Cancel_Act_Str'); }); //切換配送國家 $("#Main_Content").on('change','#Send_Country',function(){ updatePage('&Country='+$(this).val()); }); //切換配送方式 $("#Main_Content").on('click','input[name="Ship_Type"]',function(){ updatePage('&Ship_Type='+$(this).val()); //GA4 if(typeof gtag == 'function') { gtag("event","add_shipping_info",{ "shipping_tier":$(this).data('name') }); } }); //門市取貨 $("#Main_Content").on("change","#Store_Pick",function(){ updatePage('&CVSStoreID='+$(this).val()); }); //切換付款方式 $("#Main_Content").on('click','input[name="Pay_Type"]',function(){ updatePage('&Pay_Type='+$(this).val()); if(typeof ga == 'function') { var obj = JSON.parse($("#GA_Data").text()); for(var key in obj) { ga('ec:addProduct',obj[key]); } ga('ec:setAction','checkout',{ 'step':3 }); ga('send','event','購物車','選擇付款方式'); } //GA4 if(typeof gtag == 'function') { gtag("event","add_payment_info",{ "payment_type":$(this).data('name') }); } }); //切換配送城市 $("#Main_Content").on('change','#Send_City',function(){ updatePage('&City='+$(this).val()); }); //切換配送地區 $("#Main_Content").on('change','#Send_Area',function(){ updatePage('&Area='+$(this).val()); }); //切換配送國家 $("#Main_Content").on('change','#Buy_Country',function(){ updatePage('&Buy_Country='+$(this).val()); }); //切換訂購城市 $("#Main_Content").on('change','#Buy_City',function(){ updatePage('&Buy_City='+$(this).val()); }); //切換訂購地區 $("#Main_Content").on('change','#Buy_Area',function(){ updatePage('&Buy_Area='+$(this).val()); }); //選擇門市 $("#Main_Content").on("click","#Choose_Store", function(){ var $return = encodeURIComponent('quickshop/quickshop.php?ID='+$("#Page_Shop_ID_As").val()+'#shopcartbox'), $type = $(this).attr("type"), $coll = $(this).attr("coll"); updatePage('&save=1'); setTimeout(function(){ window.location.href = '/shopcart/e_returns/emap-p.php?url='+$return+'&type='+$type+'&coll='+$coll+'&shop_id='+$("#Page_Shop_ID").val(); },500); }); //送出訂單 $("#Main_Content").on('click','#Form_Submit',function(){ $("#Main_Form").submit(); }); //姓名、電話、Email、地址、備註 $("#Main_Content").on('change','#Send_Name,#Send_Cellphone,#Email,#Send_Address,#Send_Memo,#Buy_Name,#Buy_Cellphone,#Buy_Address',function(){ updatePage('&save=1'); }); //自動加入會員、收貨時間 $("#Main_Content").on('click',"#Auto_Add,input[name='Send_Time']",function(){ updatePage('&save=1'); }); //切換載具類型 $("#Main_Content").on('change',"#CarrierType",function(){ updatePage(); }); //切換發票類型 $("#Main_Content").on('click',"input[name='Invo_Mod']",function(){ updatePage(); }); //同收件地址 $("#Main_Content").on('click','#Invo_Same_Button',function(){ if($(this).prop("checked")) { var same = '1'; $("#Invo_Address_Box").hide(); $("#Invo_Address").attr("fun",""); } else { var same = '2'; $("#Invo_Address_Box").show(); $("#Invo_Address").attr("fun","checkNull"); } updatePage('&Invo_Same='+same+'&save=1'); $("input[name='Invo_Same']").val(same); }); $("#Main_Content").on('click','.title-big',function(){ var num = $(this).parent('section').attr("num"); if(num > '0') { $(this).parent('section').toggleClass("open",500); } else { $(".emptyCartPrompt").css("display","flex"); setTimeout(function () { $('.emptyCartPrompt').fadeOut() }, 5000) } }); $("#Main_Content").on('click','.shopcart-link',function(){ $('section').addClass("open",500); }); // $('body').on('click','.arrow .title-big', function(event) { // // console.log($('.is-nowStep')); // if(!$(this).is('.open')){ // $('section').not(this).removeClass('open'); // $(this).parent('section').addClass('open'); // updatePage('&Step='+$(this).parent('section').attr("id").substr(1,1)+'&save=1'); // } // }); $("#Main_Content").on('click','#step2',function(){ $('#s2').addClass("open",500); $('#s2').addClass("arrow",500); // $(this).parents('.section-wrapper').parent('section').removeClass('open'); updatePage('&Step=2&save=1&MoneyShow=1'); if(typeof ga == 'function') { var obj = JSON.parse($("#GA_Data").text()); for(var key in obj) { ga('ec:addProduct',obj[key]); } ga('ec:setAction','checkout',{ 'step':2 }); ga('send','event','購物車','我要結帳'); } }); $("#Main_Content").on('click','#step3',function(){ $('#s3').addClass("open",500); $('#s3').addClass("arrow",500); // $(this).parents('section').removeClass('open'); updatePage('&Step=3&save=1'); }); // 按下我要結帳後出現底部浮動 $("#Main_Content").on('click', '#step2', function() { $('.moneyPrompt').css('display', 'flex').hide().fadeIn() }); // 收件同訂購人 $(document).on("change", "#copyCustomerData", function(){ if($(this).prop("checked")){ var $data = '©CustomerData=1'; updatePage($data); }else{ $("#Send_Name").val("").prop("disabled",false).next(".text-title").removeClass("now") $("#Send_Cellphone").val("").prop("disabled",false).next(".text-title").removeClass("now") $("#Send_Country").val("").prop("disabled",false) } }) //取消優惠折扣 $("#Main_Content").on('click','.cate-button',function(e){ var $data = '&cate='+$(this).attr("cate")+'&value='; if($(this).attr("class").indexOf("usd") != -1){ e.preventDefault(); updatePage($data); } }); //購物金勾選 $("#Main_Content").on('click',"#use_bonus1",function(){ // var $data = 'cate=Bonus&value='+$(this).val(); var $data = '&cate=Bonus&value='+$("#use_bonus_money").val(); updatePage($data); }); //抵用券勾選 $("#Main_Content").on('click',"input[name='usable_no']",function(){ $("#usable_no").val($(this).val()); }); //優惠折扣送出 $("#Main_Content").on('click','.money-send',function(){ if($(this).attr("cate") == 'RBonus' || $(this).attr("cate") == 'MemberMoney'){ var $data = '&cate='+$(this).attr("cate")+'&value='+$(this).parents("p").find("input").val(); }else{ var $data = '&cate='+$(this).attr("cate")+'&value='+$(this).parents("p").find("input").val(); } updatePage($data); }); function updatePage(data) { //取得一般配送資料 var send = ''; var data = data || ''; //訂購資料 $("#Buy_Name,#Buy_Cellphone,#Buy_Address,#Buy_Login_Password,#Buy_Login_Password2").each(function(){ send += '&'+$(this).attr("name")+'='+$(this).val(); }); //寄送資料 $("#Send_Name,#Send_Office_Name,#Send_Cellphone,#Email,#Send_Address,input[name='Send_Time']:checked,#Send_Memo,#Del_Type,#Auto_Add:checked").each(function(){ send += '&'+$(this).attr("name")+'='+$(this).val(); }); if($('#copyCustomerData').prop('checked')){ send += '©CustomerData=1'; } //發票資料 $("input[name='Invo_Mod']:checked,#CarrierType,#CarrierId1,#CarrierId2,#NPOBAN,#Invo_Title,#Invo_No,#Invo_Address").each(function(){ send += '&'+$(this).attr("name")+'='+$(this).val(); }); var $data = 'type=update'+data+send+'&Page_Shop_ID='+$("#Page_Shop_ID").val(); $.ajax({ url:"/quickshop/ajax/ajax_get_cart.php", type:"POST", async: true, data:$data, cache:false, error:function(d,e,f){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d) { $("#Ajax_Box").html(d); //活動字串訊息 if($("#Coupon_Msg").val()){ alert($("#Coupon_Msg").val()); } $("#Main_Form").fromsAuth({ type:'NONE', callafter:function(){ if(typeof ga == 'function') { var obj = JSON.parse($("#GA_Data").text()); for(var key in obj) { ga('ec:addProduct',obj[key]); } ga('ec:setAction','checkout',{ 'step':4 }); ga('send','event','購物車','確認訂單'); } return true; } }); //加購按鈕 var add = parseInt($("#CanAdd").val()); if(add > 0) { $(".Add_Button").removeClass('button-cant').addClass('button-add'); $(".Add_Button").html('加購'); } else { $(".Add_Button").removeClass('button-add').addClass('button-cant'); $(".Add_Button").html('未符合加購'); } //滿額按鈕 var gift = parseInt($("#CanGift").val()); if(gift > 0) { $(".Gift_Button").removeClass('button-cant'); $(".Gift_Button").html('挑選'); } else { $(".Gift_Button").addClass('button-cant'); $(".Gift_Button").html('未符合滿額贈品挑選'); } var amount = parseInt($("#ChooseGift").val()); $("#Gift_Amount").html(amount); } } }) } // ========================================================== // 小圖hover效果及切換功能 // ========================================================== function moreviewInit() { const moreviewTarget = $(".popupbg .moreview") if(moreviewTarget.children('.picitem').length > 5){ moreviewTarget.owlCarousel({ loop:false, items : 5, nav : true, navText : ['',''], dots: false, }).on('mouseenter','.owl-item', function() { var now = $(this).index(), box = $(this).parents(".popupbg"); box.find(".zoonbox").css('display','none').eq(now).css('display','flex'); }).on('mouseleave','.owl-stage-outer', function() { var box = $(this).parents(".popupbg"); box.find(".zoonbox").removeAttr('style'); }).on('click','.owl-item', function() { var now = $(this).index(), box = $(this).parents(".popupbg"); $(this).siblings('.owl-item').children('.picitem').removeClass('now'); $(this).children('.picitem').addClass('now'); box.find(".zoonbox").removeClass('now').eq(now).addClass('now'); }) moreviewTarget.trigger('refresh.owl.carousel') }else{ moreviewTarget.on('mouseenter','.picitem', function() { var now = $(this).index(), box = $(this).parents(".popupbg"); box.find(".zoonbox").css('display','none').eq(now).css('display','block'); }).on('mouseleave', function() { var box = $(this).parents(".popupbg"); box.find(".zoonbox").removeAttr('style'); }).on('click','.picitem', function() { var now = $(this).index(), box = $(this).parents(".popupbg"); $(this).addClass('now').siblings('.picitem').removeClass('now') box.find(".zoonbox").removeClass('now').eq(now).addClass('now'); }) } } // ========================================================== // 跳窗內頁籤切換功能 // ========================================================== ;(function($) { $("#Main_Content").on('click','.Content_Title',function(){ var num = $(this).attr("num"); $(this).parents(".popupbg").find(".Content_Title").css({"color":"#909090","border-top":"1px solid #e2e2e2"}); $(this).css({"color":"#000000","border-top":"1px solid #2f2f2f"}); $(this).parents(".popupbg").find(".Box1,.Box2,.Box3").hide(); $(this).parents(".popupbg").find(".Box"+num).show(); }); })($)