$(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"); _this.parents(".shopcart-list").find(".amountBox[sid='"+ID+"']").each(function(){ Amount += parseInt($(this).val()) || 0; }); //會計算到手機版所以除以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()); $(this).parents(".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:Project_Country+"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; case "RET_OVER_SIT_MAX": alert(_jsLang.數量超過定期購限購量); break; case "RET_PROD_IN_ONESHOPPAGE_ERROR": alert(_jsLang.此商品於一頁式購物推廣中+','+_jsLang.暫無法加入購物車); break; default: alert(_jsLang.資料庫忙線中); break; } } }); } $("#Main_Form").fromsAuth({ type:'NONE', callafter:function(){ return true; } }); var _window = $(window); var change = 0; var moreview = false; var change_1023 = 1024; runSildeBoxOwl() runOproductSlide() $(document).on('click','.click-pic',function(){ // prodpop-new popBox var ID = $(this).data('id'); $.post(Project_Country+'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_Input").val())< 1 || $("#Main_Form_Input").val()==''){ var frozen = '' if($(this).attr('frozen') == '1'){ frozen = 'normal'; } else if($(this).attr('frozen') == '2'){ frozen = 'freezing'; } else if($(this).attr('frozen') == '3'){ frozen = 'fridge'; } Shopcart_Step_Go('step1',frozen); } //選擇步驟 $("#Main_Content").on('click','.Step_Button',function(){ var step = $(this).attr('step'); var frozen = '' if($(this).attr('frozen') == '1'){ frozen = 'normal'; } else if($(this).attr('frozen') == '2'){ frozen = 'freezing'; } else if($(this).attr('frozen') == '3'){ frozen = 'fridge'; } Shopcart_Step_Go(step,frozen); }); function Shopcart_Step_Go(step,frozen=''){ //步驟按鈕樣式 $("#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 = Project_Country+$("#Website_Mall_ID").val()+'/shopcart/'+step+'/'+frozen+'/'; window.history.replaceState({},'shopcart',new_url); //重載頁面記錄目前步驟SESSION updatePage('&step='+step+'&frozen='+frozen); $(window).scrollTop(0); } $(document).on('click','.click-block2 .btn-primary',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:Project_Country+"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.DataLayer){eval(d.DataLayer)} 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; case "RET_OVER_SIT_MAX": alert(_jsLang.數量超過定期購限購量); break; case "RET_PROD_IN_ONESHOPPAGE_ERROR": alert(_jsLang.此商品於一頁式購物推廣中+','+_jsLang.暫無法加入購物車); break; default: alert(_jsLang.資料庫忙線中); break; } } }); }) //刪除商品 $("#Main_Content").on('click','.prod_del',function(){ if(confirm(_jsLang.確定刪除嗎+"?")){ $(".loading").show(); $.ajax({ url:Project_Country+"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.DataLayer){eval(d.DataLayer)} alert(_jsLang.刪除成功); updatePage(); } else { alert(_jsLang.資料庫忙線中); } } }); } }); //下次買 $("#Main_Content").on('click','.prod_next',function(){ if(confirm(_jsLang.確定加入喜愛清單嗎)){ $(".loading").show(); $.ajax({ url:Project_Country+"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(d.DataLayer){eval(d.DataLayer)} alert(_jsLang.加入喜愛清單成功); updatePage(); break; case "RET_NO_MEMBER": alert(_jsLang.請先登入會員); window.location.href = '/'+$("#Website_Mall_ID").val()+'/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:Project_Country+"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.DataLayer){eval(d.DataLayer)} 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; case "RET_OVER_SIT_MAX": alert(_jsLang.數量超過定期購限購量); break; case "RET_PROD_IN_ONESHOPPAGE_ERROR": alert(_jsLang.此商品於一頁式購物推廣中+','+_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") == '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&Bonus_Code='+$(this).attr('Bonus_Code')+'&value='+$(this).val(); updatePage($data); }); //購物金取消 $("#Main_Content").on('click',"#Cancel_Bonus",function(){ updatePage('&Cancel_Bonus=1'); }); //紅利勾選 $("#Main_Content").on('click',"input[name='use_Rbonus']",function(){ var $data = 'cate=RBonus&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:Project_Country+"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(); var frozen = '' if($(this).attr('frozen') == '1'){ frozen = 'normal'; } else if($(this).attr('frozen') == '2'){ frozen = 'freezing'; } else if($(this).attr('frozen') == '2'){ frozen = 'fridge'; } window.location.href = '/shopcart/e_returns/emap-p.php?url=shopcart/step3/'+frozen+'/&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); }); //保價勾選 $("#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:Project_Country+"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_ID",function(){ var $data = 'Store_Pick_ID='+$(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(); // } var $data = 'Invo_Type='+$(this).val(); updatePage($data); }); /* $("#Main_Content").on('click','#Invo_Agree',function(){ var val = $(this).prop('checked'), data = '&Invo_Agree='+val; updatePage(data); }); */ if($('.prod_in_page_area').length > 0){ var alert_check_prod_in_page = "親愛的會員您好,目前下列產品正在一頁式購物推廣中,故系統將自動移除\n"; $('.prod_in_page_area .prod_data').each(function(index){ alert_check_prod_in_page += "\n《"+$(this).val()+"》"; }) alert(alert_check_prod_in_page); window.location.reload(); } $(document).on("click", ".popBox, .popBox2", function(e){ if(e.target == e.currentTarget){ $(this).find(".close").click() } }) }); 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,input:password").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:Project_Country+"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); runOproductSlide() $("#Main_Form").fromsAuth({ type:'NONE', callafter:function(){ 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()); runSildeBoxOwl() //修改國旗圖片 $.post(Project_Country+'ajax/ajax_change_country.php', {Type:'update',ID: $(this).attr('sid')}, function(h){ if(h){ $("#This_Country_Pic").attr("src","/upload_files/fonlego-rwd/website/"+h); } }, 'html'); $(".loading").fadeOut(); var file_Obj = new prod_file({ amountBox:'num-select', specUrl: Project_Country+'shopcart/ajax/ajax_get_item.php', ordButton:'button2' }); file_Obj.init(); } }); //步驟二刪除購物車,如果無資料,導回step1 var StepFlow = $("#StepFlow").val(); if(StepFlow == 'step2' && (parseInt($("#Main_Form_Input").val())< 1 || $("#Main_Form_Input").val()=='') ){ // console.log($("#Main_Form_Input").val()); window.location.href = Project_Country+'/'+$("#Website_Mall_ID").val()+'/shopcart/step1/'; } } function runSildeBoxOwl() { $('.sildeBox').owlCarousel({ nav: true, navText: ['', ''], dots: false, responsive: { 0: { items: 1, margin: 10, }, 480: { items: 2, margin: 10, }, 768: { items: 3, margin: 15, }, 992: { items: 4, margin: 15, }, }, }) } function runOproductSlide() { const owlStep = { responsive:{ 0:{ margin : 15, items : 2 }, 576:{ margin : 15, items : 3 }, 768:{ margin : 15, items : 4 }, 1201:{ margin : 30, items : 4 } }, nav : true, navText : ['',''], dots: false, } $(".oproduct-carousel").each(function(){ let _this = $(this), width = $(window).width() if(width < 576){ _this.trigger("destroy.owl.carousel") }else if(_this.find(".oproduct-item").length > 0){ _this.owlCarousel(owlStep); } $(window).on("resize", function(){ let width = $(window).width() if(width < 576){ _this.trigger("destroy.owl.carousel") }else if(_this.find(".oproduct-item").length > 0){ _this.owlCarousel(owlStep); } }) }) }