$(document).ready(function () { $("html,body").animate({scrollTop: $('.login-offset').offset().top-150},800); //商品加減 $(document).on('click','.Prod_Amount',function(){ var _this = $(this), box = _this.parents('.numberBox'), ID = box.find(".amountBox").attr("sid"), Act = box.find(".amountBox").attr("act"), Ch_Flag = box.find(".amountBox").attr("ch"), Amount = 0, max = box.find(".amountBox").attr("max"); $("#Shopcart_List").find(".amountBox[sid='"+ID+"']").each(function(){ Amount += parseInt($(this).val()) || 0; }); //會計算到手機版所以除以2 Amount = Amount/2; if(_this.hasClass("fa-minus")) { Amount -= 1; if(Amount <= 1) { Amout = 1; } } else { Amount += 1; if(Amount > max) { Amount = max; } } if(ID && Amount) { var data = 'ID='+ID+'&Amount='+Amount+'&Act='+Act+'&Ch_Flag='+Ch_Flag; loadChangeProd(box,data); } }); //商品修改數量 $(document).on('change','.Prod_Amount_Change',function(){ var box = $(this).parents('.numberBox'), ID = $(this).attr("sid"), Act = $(this).attr("act"), Ch_Flag = $(this).attr("ch"), Amount = 0, max = $(this).attr("max"); //變更手機版數量 $(this).parents(".Product_Box").find(".Prod_Amount_Change").val($(this).val()); $("#Shopcart_List").find(".amountBox[sid='"+ID+"']").each(function(){ Amount += parseInt($(this).val()) || 0; }); //會計算到手機版所以除以2 Amount = Amount/2; if(Amount <= 1) { Amout = 1; } if(Amount > max) { Amount = max; } if(ID && Amount) { var data = 'ID='+ID+'&Amount='+Amount+'&Act='+Act+'&Ch_Flag='+Ch_Flag; loadChangeProd(box,data); } }); function loadChangeProd(box,data) { //載入中 box.next('.number-load').css('display','inline-block'); box.next('.amountBox').css('cursor','no-drop').attr('disabled','disabled'); box.next('.fa').css('cursor','no-drop'); //鎖定數量 $(".Prod_Amount").removeClass("Prod_Amount"); $("#Shopcart_List").find(".amountBox").prop("disabled",true); //增加數量 $.ajax({ url:"/tw/shopcart/ajax/ajax_cart_edit.php", type:"POST", cache:false, data:data, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ switch(d){ case "RET_SUCCESS": updatePage(); break; case "RET_NO_MEMBER_NO": alert(_jsLang.欲購買紅利兌換商品請先登入會員並完成會員認證); break; case "RET_RBONUS_OUT": alert(_jsLang.紅利不足); break; case "RET_ERROR": alert(_jsLang.資料庫忙線中); break; case "RET_PROD_ERROR": alert(_jsLang商品已下架); break; case "RET_NO_PROD": alert(_jsLang.請選擇商品); break; case "RET_STOCK_ERROR": alert(_jsLang.商品庫存不足); break; case "RET_LIMIT_ERROR": alert(_jsLang.數量超過限購量); break; default: alert(_jsLang.資料庫忙線中); break; }; } }); } $("#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','購物車','確認訂單'); } if(typeof fbq == 'function') { fbq('track','AddPaymentInfo'); } return true; } }); var _window = $(window); var change = 0; var moreview = false; var change_1023 = 1024; if(_window.width() < 1024){ var slide = $(".sildeBox"); slide.owlCarousel({ responsive:{ 0:{ items : 1 }, 481:{ items : 2 }, 960:{ items : 3 } }, nav : true, navText : ['',''], }); }else{ if($(".sildeBox .productBox").length>4){ var slide = $(".sildeBox"); slide.owlCarousel({ responsive:{ 0:{ items : 1 }, 481:{ items : 2 }, 960:{ items : 4 } }, nav : true, navText : ['',''], }); } } if(_window.width() > 480 && change_1023 == 1024){ change_1023 = 480; if($('.content_1 .click-block').length >3){ $('.content_1 .click-block').css('width',"98%"); $('.oproduct-tagcontent .content_1').owlCarousel({ responsive:{ 0:{ items : 1 }, 481:{ items : 2 }, 960:{ items : 3 } }, nav : true, navText : ['',''], }); } if($('.content_2 .click-block2').length >3){ $('.content_2 .click-block2').css('width',"98%"); $('.oproduct-tagcontent .content_2').owlCarousel({ responsive:{ 0:{ items : 1 }, 481:{ items : 2 }, 960:{ items : 3 } }, nav : true, navText : ['',''], }); } if($('.content_3 .click-block').length >3){ $('.content_3 .click-block').css('width',"98%"); $('.oproduct-tagcontent .content_3').owlCarousel({ responsive:{ 0:{ items : 1 }, 481:{ items : 2 }, 960:{ items : 3 } }, nav : true, navText : ['',''], }); } } $(document).on('click','.click-pic',function(){ // prodpop-new popBox var ID = $(this).data('id'); $.post('/tw/shopcart/ajax/ajax_prodnew.php',{'ID':ID},function(data){ $('.prodpop-new').replaceWith(data) $('.prodpop-new').css('display','block'); }) }); $(document).on('click','.prodpop-new .close',function(){ $('.prodpop-new').css('display','none'); }); //購物車無資料,導回step1 if(parseInt($("#Main_Form").attr('cart_num'))< 1 || $("#Main_Form").attr('cart_num')==''){ Shopcart_Step_Go('step1'); } //選擇步驟 $("#Main_Content").on('click','.Step_Button',function(){ var step = $(this).attr('step'); Shopcart_Step_Go(step); }); function Shopcart_Step_Go(step){ //步驟按鈕樣式 $("#Main_Content").find('.Step_Button').each(function(){ //初始步驟樣式 $(this).removeClass('now'); var chk_step = $(this).attr('step'); //目前步驟樣式 if(step == chk_step){ $(this).addClass('now'); } }); //步驟區塊開啟或關閉 $("#Main_Content").find('.Step_Block').each(function(){ //初始步驟區塊(關閉) $(this).addClass('hide'); var chk_step = $(this).attr('step'); //開啟目前步驟區塊 if(step == chk_step){ $(this).removeClass('hide'); } }); //切換網址 var new_url = '/tw/shopcart/'+step; window.history.replaceState({},'shopcart',new_url); //重載頁面記錄目前步驟SESSION updatePage('&step='+step); $(window).scrollTop(0); if(typeof ga == 'function') { var obj = JSON.parse($("#GA_Data").text()), ga_step = '', ga_title = ''; if(step == 'step1') { ga_step = '1'; ga_title = '進入購物車'; } else { ga_step = '2'; ga_title = '填寫寄送資料'; } for(var key in obj) { ga('ec:addProduct',obj[key]); } ga('ec:setAction','checkout',{ 'step':ga_step }); ga('send','event','購物車',ga_title); } } $(document).on('click','.click-block2 .button2',function(e){ e.preventDefault(); $(".loading").show(); var SID = $(this).attr('sid'); var Amount = $(this).parents('.click-block2').find('.num').val(); if(!$.isNumeric(Amount)){ alert(_jsLang.請選擇數量); return false; } $.ajax({ url:"/tw/shopcart/ajax/ajax_cart_add.php", type:"POST", cache:false, data:{"ID":SID,"Amount":Amount}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ switch(d.Status){ case "RET_SUCCESS": if(d.GA && typeof ga == 'function') { for(var key in d.GA) { ga('ec:addProduct',d.GA[key]); } ga('ec:setAction','add'); ga('send','event','購物車','加入購物車'); } if(d.FBQ && d.Total_Money && typeof fbq == 'function') { fbq('track', 'AddToCart', { value:d.Total_Money, currency:'TWD', content_ids:d.IDs, content_type: 'product', contents:d.FBQ }); } alert(_jsLang.加入購物車成功); updatePage(); break; case "RET_NO_MEMBER_NO": alert(_jsLang.欲購買紅利兌換商品請先登入會員並完成會員認證); break; case "RET_RBONUS_OUT": alert(_jsLang.紅利不足); break; case "RET_ERROR": alert(_jsLang.資料庫忙線中); break; case "RET_PROD_ERROR": alert(_jsLang.商品已下架); break; case "RET_NO_PROD": alert(_jsLang.請選擇商品); break; case "RET_STOCK_ERROR": alert(_jsLang.商品庫存不足); break; case "RET_LIMIT_ERROR": alert(_jsLang.數量超過限購量) break; default: alert(_jsLang.資料庫忙線中); break; }; } }); }) //刪除商品 $("#Main_Content").on('click','.prod_del',function(){ if(confirm(_jsLang.確定刪除嗎+"?")){ $(".loading").show(); $.ajax({ url:"/tw/shopcart/ajax/ajax_cart_del.php", type:"POST", cache:false, data:{ID:$(this).attr("sid"),Act:$(this).attr("act"),Ch_Flag:$(this).attr("ch")}, 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(_jsLang.刪除成功); updatePage(); } else { alert(_jsLang.資料庫忙線中); } } }); } }); //下次買 $("#Main_Content").on('click','.prod_next',function(){ if(confirm(_jsLang.確定加入喜愛清單嗎)){ $(".loading").show(); $.ajax({ url:"/tw/shopcart/ajax/ajax_cart_next.php", type:"POST", cache:false, data:{ID:$(this).attr("sid"),Act:$(this).attr("act"),Ch_Flag:$(this).attr("ch")}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ switch(d.Msg){ case "RET_SUCCESS": if(typeof fbq == 'function') { fbq('track', 'AddToWishlist', { content_ids:"['"+d.Prod_No+"']", value:d.Price1, currency:'TWD', content_type:'product' }); } alert(_jsLang.加入喜愛清單成功); updatePage(); break; case "RET_NO_MEMBER": alert(_jsLang.請先登入會員); window.location.href = '/tw/member-login'; break; default: alert(_jsLang.資料庫忙線中); break; } } }); } }); //加購加減 $(document).on('click','.Amount_Minus',function(){ var amount = parseInt($(this).next(".amountBox").val()) || 0; amount -= 1; if(amount < 1) { amount = 1; } $(this).next(".amountBox").val(amount); }); $(document).on('click','.Amount_Plus',function(){ var amount = parseInt($(this).prev(".amountBox").val()) || 0, max = parseInt($(this).prev(".amountBox").attr("max")); amount += 1; if(amount > max) { amount = max; } $(this).prev(".amountBox").val(amount); }); //加購商品 $(document).on('click','#All_Add_List .button2,#Full_Add_List .button2',function(){ $(".loading").show(); $.ajax({ url:"/tw/shopcart/ajax/ajax_cart_add.php", type:"POST", cache:false, data:{ID:$(this).attr("sid"),Amount:$(this).parents(".productBox").find(".amountBox").val()}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ switch(d.Status){ case "RET_SUCCESS": if(d.GA && typeof ga == 'function') { for(var key in d.GA) { ga('ec:addProduct',d.GA[key]); } ga('ec:setAction','add'); ga('send','event','購物車','加入購物車'); } if(d.FBQ && d.Total_Money && typeof fbq == 'function') { fbq('track', 'AddToCart', { value:d.Total_Money, currency:'TWD', content_ids:d.IDs, content_type: 'product', contents:d.FBQ }); } alert(_jsLang.加入購物車成功); updatePage(); break; case "RET_NO_MEMBER_NO": alert(_jsLang.欲購買紅利兌換商品請先登入會員並完成會員認證); break; case "RET_RBONUS_OUT": alert(_jsLang.紅利不足); break; case "RET_ERROR": alert(_jsLang.資料庫忙線中); break; case "RET_PROD_ERROR": alert(_jsLang.商品已下架); break; case "RET_NO_PROD": alert(_jsLang.請選擇商品); break; case "RET_STOCK_ERROR": alert(_jsLang.商品庫存不足); break; case "RET_LIMIT_ERROR": alert(_jsLang.數量超過限購量) break; default: alert(_jsLang.資料庫忙線中); break; }; } }); }); //取消優惠折扣 $("#Main_Content").on('click','.money-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','.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); }); //購物金勾選 $("#Main_Content").on('click',"input[name='use_bonus']",function(){ var $data = 'cate=Bonus&value='+$(this).val(); updatePage($data); }); //抵用券勾選 $("#Main_Content").on('click',"input[name='usable_no']",function(){ $("#usable_no").val($(this).val()); }); //選擇配送國家 $("#Main_Content").on('click',"input[name='Country_Type']",function(){ switch($(this).val()){ case "1": case "2": var $data = 'countryType='+$(this).val(); break; case "3": var $data = 'countryType=3&country='+$("#Country").val(); break; } updatePage($data); $.ajax({ url:"/tw/ajax/ajax_get_city-p.php", type:"POST", cache:false, data:{"Send_ID":$("#Send_Country_ID option:eq(1)").val()}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ var the_sub = 'Send_City_ID'; $("#" + the_sub).children("option:gt(0)").remove(); for(k in d){ $("#" + the_sub).append(''); } } }); }); $("#Main_Content").on('change',"#Country",function(){ var $data = 'countryType=3&country='+$(this).val(); updatePage($data); }); //選擇運送方式 $("#Main_Content").on('click',"input[name='Ship_Type']",function(){ var $data = 'shipType='+$(this).val(); updatePage($data); }); $("#Main_Content").on("click","#Choose_Store", function(){ updatePage(); window.location.href = '/tw/shopcart/e_returns/emap-p.php?url=shopcart/&type='+$(this).attr("type")+'&coll='+$(this).attr("coll"); }); //選擇付款方式 $("#Main_Content").on('click',"input[name='Pay_Type']",function(){ var $data = 'payType='+$(this).val(); if($(this).val() == 5)$data += '&countryType=1'; updatePage($data); 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','購物車','選擇付款方式'); } }); //保價勾選 $("#Main_Content").on('click',"input[name='Premiu']",function(){ var $data = 'premiu='+$(this).val(); updatePage($data); }); //國家切換 $("#Main_Content").on('change',".Country",function(){ var Send_ID = $(this).val(); $.ajax({ url:"/tw/ajax/ajax_get_city-p.php", type:"POST", cache:false, data:{"Send_ID":Send_ID}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ var the_sub = 'Send_City_ID'; $("#" + the_sub).children("option:gt(0)").remove(); for(k in d){ $("#" + the_sub).append(''); } } }); }); //縣市切換 $("#Main_Content").on('change',".City",function(){ updatePage(); }); //地區切換 $("#Main_Content").on('change',".Area",function(){ var opt = $(this).find("option:selected").text(), area = opt.split(" "), zip = area[0]; $("#Send_Area_No").val(zip); }); //同訂購人資料 $("#Main_Content").on('click',"#Same_Button",function(){ var $data = 'same=1'; updatePage($data); }); //預設發票地址 var Del_Type = $("#Del_Type").val(); var Send_Address = $("#Send_Address").val() || ''; var Send_Area_ID = $("#Send_Area_ID option:selected").attr("name") || ''; var Send_City_ID = $("#Send_City_ID option:selected").attr("name") || ''; var Send_Addr_Full = Send_City_ID+Send_Area_ID+Send_Address; if(Send_Addr_Full && Del_Type !='2'){ $("#Invo_Same_Button").prop("checked",true); $("#Invo_Address").val(Send_Addr_Full); } //同訂購人資料 $("#Main_Content").on('click',"#Invo_Same_Button",function(){ var dt = $(this).attr('dt'); if($("#Invo_Same_Button").prop("checked") && dt != '2'){ var Send_Address = $("#Send_Address").val() || ''; var Send_Area_ID = $("#Send_Area_ID option:selected").attr("name") || ''; var Send_City_ID = $("#Send_City_ID option:selected").attr("name") || ''; $("#Invo_Address").val(Send_City_ID+Send_Area_ID+Send_Address); } }); //從通訊錄中挑選 $("#Main_Content").on('click',".Send_Book",function(){ var $data = 'send_book='+$(this).attr("sid"); updatePage($data); }); //門市取貨 $("#Main_Content").on("change","#Store_Pick",function(){ var $data = 'CVSStoreID='+$(this).val(); updatePage($data); }); //發票載具 $("#Main_Content").on('change',"#CarrierType",function(){ updatePage(); }); //送出 $("#Main_Content").on('click',"#Form_Submit",function(){ var gift = $("#Left_Gift").val(); if(gift > '0'){ alert(_jsLang.尚可挑選+gift+_jsLang.件贈品請挑選後再送出購物車); }else{ $("#Main_Form").submit(); } }); //到貨日期資料同步 $("#Main_Content").on('click',"input[name='Send_Week2']",function(){ $("#Send_Week").val($(this).val()); }); $("#Main_Content").on('change',"#Send_Week",function(){ $("#Send_Week2"+$(this).val()).prop("checked",true); }); //到貨時間資料同步 $("#Main_Content").on('click',"input[name='Send_Time2']",function(){ $("#Send_Time").val($(this).val()); }); $("#Main_Content").on('change',"#Send_Time",function(){ $("#Send_Time2"+$(this).val()).prop("checked",true); }); //雲端發票資料同步 $("#Main_Content").on('click',"input[name='Invo_Mod']",function(){ updatePage(); }); $("#Main_Content").on('change',"#Invo_Mod2",function(){ $("#changeradio-0"+$(this).val()).prop("checked",true); updatePage(); }); $("#Main_Content").on('click',"input[name='Invo_Send_Type']",function(){ updatePage(); }); $("#Main_Content").on('change', "input[name='Invo_Type']",function(){ if($(this).val() == 1){ $(".invo_type1").hide(); } else{ $(".invo_type1").show(); } updatePage(); }); /* $("#Main_Content").on('click','#Invo_Agree',function(){ var val = $(this).prop('checked'), data = '&Invo_Agree='+val; updatePage(data); }); */ }); function updatePage($data){ $(".loading").show(); var $member = ""; var $invo = ""; $(".card_content").each(function(){ $member += '&'+$(this).attr("name")+'='+$(this).val(); }); $("#Buy_Data").find("input:text,input:checked,select,input:password").each(function(){ $member += '&'+$(this).attr("name")+'='+$(this).val(); }); $("#Send_Data").find("input:text,input:hidden,input:checked,select,textarea").each(function(){ $member += '&'+$(this).attr("name")+'='+$(this).val(); }); $("#Send_Data").find("#Send_Cellphone").each(function(){ $member += '&'+$(this).attr("name")+'='+$(this).val(); }); $("#Invo_Data").find("input:text,input:checked,select").each(function(){ $invo += '&'+$(this).attr("name")+'='+$(this).val(); }); $invo += '&Member_Agree='+$("#Member_Agree").val(); $.ajax({ url:"/tw/shopcart/ajax/ajax_cart_update.php", type:"POST", cache:false, async:false, data:$data+$member+$invo+'&updatePage=1', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ var _window = $(window); var change_1023 = 1024; $("#Main_Content").html(d); if(_window.width() > 480 && change_1023 == 1024){ change_1023 = 480; if($('.content_1 .click-block').length >3){ $('.content_1 .click-block').css('width',"98%"); $('.oproduct-tagcontent .content_1').owlCarousel({ responsive:{ 0:{ items : 1 }, 481:{ items : 2 }, 960:{ items : 3 } }, nav : true, navText : ['',''], }); } if($('.content_2 .click-block2').length >3){ $('.content_2 .click-block2').css('width',"98%"); $('.oproduct-tagcontent .content_2').owlCarousel({ responsive:{ 0:{ items : 1 }, 481:{ items : 2 }, 960:{ items : 3 } }, nav : true, navText : ['',''], }); } if($('.content_3 .click-block').length >3){ $('.content_3 .click-block').css('width',"98%"); $('.oproduct-tagcontent .content_3').owlCarousel({ responsive:{ 0:{ items : 1 }, 481:{ items : 2 }, 960:{ items : 3 } }, nav : true, navText : ['',''], }); } } $("#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','購物車','確認訂單'); } if(typeof fbq == 'function') { fbq('track','AddPaymentInfo'); } return true; } }); var bill = JSON.parse(base64_decode($("#Bill_Update").val())); for(s in bill){ $("#Bill_"+s).html(bill[s]); } if($("#Coupon_Msg").val()){ alert($("#Coupon_Msg").val()); } $("#Show_Shopcart_Total").html($("#Shop_Cart_Total_Update").val()); var slide = $(".sildeBox"); slide.owlCarousel({ responsive:{ 0:{ items : 1 }, 481:{ items : 2 }, 960:{ items : 4 } }, nav : true, }); //修改國旗圖片 $.post('/tw/ajax/ajax_change_country.php', {Type:'update',ID: $(this).attr('sid')}, function(h){ if(h){ $("#This_Country_Pic").attr("src","/tw/upload_files/fonlego-rwd/website/"+h); } }, 'html'); $(".loading").fadeOut(); var file_Obj = new prod_file({ amountBox:'num-select', specUrl: '/tw/shopcart/ajax/ajax_get_item.php', ordButton:'button2' }); file_Obj.init(); } }); }