var prod_file = function(option){ var sets = { //類型 type : '1', //1->列表,2->詳細頁,3->活動詳細頁,4.一頁式購物 action : 'poducts', //頁面類型 //商品內容 contBox : 'content', //總容器的class itemBox : 'productBox', //商品容器的class nameBox : 'nameBox', //商品名稱的class prodnoBox : 'prodnoBox', //商品編號的class loveBox : 'love', //願望清單的class price2Box : 'font-delete', //定價的class price1Box : 'font-big', //結帳價的class rbonusBox : 'price-rbonus', //紅利的class bonusBox : 'get_bonus', //購物金的class colorBox : 'colorbox', //顏色的class colorSelect: 'color-select', //顏色下拉的class colorName : 'Spec_Name1', //顏色名稱的class sizeBox : 'sizebox', //尺寸-按鈕的class sizeSelect: 'size-select', //尺寸-下拉的class sizeName : 'Spec_Name2', //尺寸名稱的class sp3Box : 'sp3box', //規格三-按鈕的class sp3Select : 'sp3-select', //規格三-下拉的class sp3Name : 'Spec_Name3', //規格三名稱的class amountBox : 'amountBox', //數量的class stockBox : 'stockBox', //庫存的class picpathBox: 'productImg', //主圖片的class picBox : 'owl-carousel', //圖片容器的class specClass : 'box-item', //規格 -按鈕的class specID2 : 'SID', //規格 -要傳送的標籤屬性 specUrl : '/products/ajax/common/ajax_get_prod_item.php', //規格 -ajax網址 //加入購物車 addButton : 'add_to_cart', //加入購物車按鈕的class toButton : 'to_cart', //加入購物車按鈕的class addUrl : '/ajax/ajax_add_to_cart.php', //加入購物車網址 addBox : 'Add_Button', //加入購物車按鈕的容器 ordButton : 'button1', //選購按鈕(行銷) //貨到通知 informBtn : 'informButton', //貨到通知按鈕的class informSend: 'informSend', //送出按鈕的ID informID : 'informID', //存ID欄位的ID informEmail: 'informEmail', //Email欄位的ID informClose: 'informClose', //關閉按鈕的ID informUrl : '/products/ajax/common/ajax_add_prod_inform.php', //ajax網址 //紅利(電子書) bookcaseBtn : 'add_bookcase', //電子書按鈕class bookcaseUrl : '/activities/ajax/act15/ajax_buy_ebook.php', //電子書紅利ajax網址, //wishList loveButton: 'love', //列表加入願望清單 wishButton: 'wishButton', //加入願望清單按鈕的class wishUrl : '/products/ajax/common/ajax_add_wish_list.php', //ajax網址 //設定圖片 mobileUrl : '/products/ajax/detail/productView_moblie.php', //ajax手機網址 pcUrl : '/products/ajax/detail/productView_pc.php', //ajax桌機網址 otherData : '' }; $.extend(sets, option); var _this = this; if(sets.type == 1 || $(window).width() <= 768){ _this.item_num = 1; }else{ _this.item_num = 5; } //初始 this.init = function(){ //點選規格 $("."+sets.contBox).on('click',"."+sets.specClass,function(){ var _item = $(this).parents("."+sets.itemBox), SID = $(this).attr(sets.specID2), $this = $(this), Page_Shop_Type = _item.attr("type"); var data = 'Type='+sets.type+'&SID='+SID+'&Page_Shop_Type='+Page_Shop_Type+sets.otherData; if(SID){ $.ajax({ url:sets.specUrl, type:"POST", cache:false, async:false, data:data, dataType: 'json', error:function(d){ alert(d.responseText); }, success:function(d){ _this.setFile(_item,$this,d); } }); } }); //尺寸下拉選單 $("."+sets.contBox).on('change',"."+sets.colorSelect+",."+sets.sizeSelect+",."+sets.sp3Select,function(){ var _item = $(this).parents("."+sets.itemBox), SID = $(this).val(), $this = $(this), Page_Shop_Type = _item.attr("type"); var data = 'Type='+sets.type+'&SID='+SID+'&Page_Shop_Type='+Page_Shop_Type+sets.otherData; if(SID){ $.ajax({ url:sets.specUrl, type:"POST", cache:false, async:false, data:data, dataType: 'json', error:function(d){ alert(d.responseText); }, success:function(d){ _this.setFile(_item,$this,d); } }); } }); //數量輸入 $("."+sets.contBox).on('keyup',"."+sets.amountBox,function(){ var now_num = $(this).val(); var max_num = $(this).attr('max'); var limit_num = $(this).attr('limit'); now_num = parseInt(now_num); $(this).val(now_num); if(now_num>max_num){ if(max_num == 100){ alert('單次放入購物車數量上限為100'); }else{ alert('庫存不足'); } $(this).val(max_num); return false; } if(now_num>limit_num && limit_num > 0){ alert('超過限購數量,請重新輸入'); $(this).val(limit_num); return false; } if(now_num<1){ $(this).val(1); } if(isNaN(now_num)){ $(this).val(1); } }); //數量 $("."+sets.contBox).on("click",".fa.fa-plus",function(){ var amount = $(this).prev("."+sets.amountBox).val(), max = $(this).prev("."+sets.amountBox).attr("max"); if(amount == '無庫存'){ return false; } var amount = parseInt(amount); if(amount+1 > max){ $(this).prev("."+sets.amountBox).val(max); }else{ $(this).prev("."+sets.amountBox).val(amount+1); } }); $("."+sets.contBox).on("click",".fa.fa-minus",function(){ var amount = $(this).next("."+sets.amountBox).val(); if(amount == '無庫存'){ return false; } var amount = parseInt(amount); if(amount-1 <= 1){ $(this).next("."+sets.amountBox).val(1); }else{ $(this).next("."+sets.amountBox).val(amount-1); } }); //關閉跳窗 $("."+sets.contBox).on('click','.close',function(){ $("."+sets.itemBox).removeClass('is-show'); }); //直接購買按鈕 $("."+sets.contBox).on("click","."+sets.toButton,function(){ var _item = $("."+sets.addButton).parents("."+sets.itemBox), SID = $(this).attr('sid') || 0, num = _item.find("."+sets.amountBox).val() || 1; if(SID == 0){ alert('請選擇尺寸或規格'); //errorbox(); }else if(num ==0){ alert('請選擇數量'); //errorbox(); }else{ $.ajax({ url:sets.addUrl, type:"POST", cache:false, async:false, data:{SID:SID, num:num, webcacheno:$('#webcacheno').val()}, dataType: 'json', error:function(d){ alert(d.responseText); }, success:function(d){ alert(d.Alert); if(d.Alert == '加入購物車成功'){ 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.GA4 && typeof gtag == 'function') { for(var key in d.GA4) { gtag("event","add_to_cart",{ "items":d.GA4 }); } } if(d.FBQ){eval(d.FBQ)} $.ajax({ url:"/ajax/ajax_get_cart.php", type:"POST", async:false, cache:false, data:{Type:'Prod',ID:SID}, success:function(d){ window.location="/shopcart/step1/"; } }) } } }); } }); //加入購物車按鈕 $("."+sets.contBox).on("click","."+sets.addButton,function(){ var _item = $(this).parents("."+sets.itemBox), SID = $(this).attr('sid') || 0, addtype = $(this).parent(".PopupBtn1").attr('addtype') || 0, num = _item.find("."+sets.amountBox).val() || 1; if(SID == 0){ alert('請選擇尺寸或規格'); //errorbox(); }else if(num ==0){ alert('請選擇數量'); //errorbox(); }else{ var data = 'SID='+SID+'&num='+num+'&webcacheno='+$('#webcacheno').val()+sets.otherData+'&addtype='+addtype; $.ajax({ url:sets.addUrl, type:"POST", cache:false, async:false, data:data, dataType: 'json', error:function(d){ alert(d.responseText); }, success:function(d){ $("."+sets.itemBox).removeClass('is-show'); if(d.Pre_Flag==1){ if(d.Stock<=5)_item.find("."+sets.stockBox).html('預購品'); }else{ if(d.Stock<=5)_item.find("."+sets.stockBox).html('庫存 : '+d.Stock); } if(d.Amount)_item.find("."+sets.amountBox).html(d.Amount); $("#Shop_Cart_Total2,#Shop_Cart_Total3").html(d.Total); alert(d.Alert); _this.setCartOther(); if(d.Alert == '加入購物車成功'){ 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.GA4 && typeof gtag == 'function') { for(var key in d.GA4) { gtag("event","add_to_cart",{ "items":d.GA4 }); } } if(d.FBQ){eval(d.FBQ)} if(sets.type != '4') { $.ajax({ url:"/ajax/ajax_get_cart.php", type:"POST", async:false, cache:false, data:{Type:'Prod',ID:SID}, success:function(d){ $(".shopping-cartbox").css('display','none'); $("#Header_Shopcart_Prod").html(d); $("#Header_Shopcart_Prod").parent(".one-cartbox").animate({'opacity':1,'maxHeight':'999px'}).css('z-index','100'); setTimeout(function(){ $("#Header_Shopcart_Prod").parent(".one-cartbox").animate({'maxHeight':'0px','opacity':0},function(){ $(this).removeAttr('style'); $(".shopping-cartbox").removeAttr('style'); }); },5000); } }) } } } }); } }); //紅利購買 $("."+sets.contBox).on("click","."+sets.bookcaseBtn,function(){ var _item = $(this).parents("."+sets.itemBox), SID = $(this).attr('sid') || 0; $.ajax({ url:sets.bookcaseUrl, type:"POST", cache:false, async:false, data:{'sid':SID}, dataType: 'html', error:function(d){ alert(d.responseText); }, success:function(d){ console.log(d); switch(d){ case "NO_MEMBER_ID": alert('請先登入'); window.location='/member-login/'; break; case "NO_ENOUGH_MONEY": alert('紅利不足,無法兌換'); break; case "ERROR1": case "ERROR2": alert('兌換失敗,資料庫異常'); break; case "ALREADY_BUY": alert('已擁有此本電子書,請至「我的書櫃」觀看'); break; case "SUCCESS": alert('兌換成功,請至「我的書櫃」觀看'); break; } } }); }); //貨到通知按鈕 $("."+sets.contBox).on("click","."+sets.informBtn,function(){ $("#"+sets.informID).val($(this).attr('SID')); }); $("."+sets.contBox).on("click","#"+sets.informSend,function(){ var email = $("#"+sets.informEmail).val(); if(!email) { alert('請輸入E-mail'); return false; } var emailRule = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/; if(email.search(emailRule) == -1) { alert('E-mail格式錯誤'); return false; } $.ajax({ url:sets.informUrl, type:"POST", cache:false, async:false, data:{SID:$("#"+sets.informID).val(),email:email}, error:function(d){ alert(d.responseText); }, success:function(d){ if(d=='OK'){ alert('您已成功新增一筆貨到通知,當商品有貨時我們會儘快通知您!'); }else{ alert('資料庫忙線中'); } $("#"+sets.informClose).trigger("click"); } }); }); //列表增加wishList $("."+sets.contBox).on("click","."+sets.loveButton,function(){ var $this = $(this), _item = $(this).parents("."+sets.itemBox), SID = _item.find('.'+sets.addButton).attr('sid'), type = 'add'; if(!SID){ var SID = _item.find('.'+sets.informBtn).attr('sid') } if($this.attr("class").match('click')){ type = 'del'; } $.ajax({ url:sets.wishUrl, type:"POST", cache:false, async:false, dataType: 'json', data:{Type:type,SID:SID}, error:function(d){ alert(d.responseText); }, success:function(d){ if(d.Msg=='OK'){ if(type == 'add'){ if(d.FBQ){eval(d.FBQ)} if(d.GA4 && typeof gtag == 'function') { gtag("event","add_to_wishlist",{ "items":d.GA4 }); } $this.addClass("click"); alert('加入願望清單成功'); }else{ alert('此商品已加入願望清單'); } }else if(d.Msg == 'NO_MEMBER'){ alert('請先登入會員'); }else if(d.Msg == 'ADULT'){ alert('本商品為限制級商品,限18歲以上會員瀏覽,請先登入會員,並確認已於會員中心補充「個人資料修改」(含出生年/月)。修改後請重新登入。'); }else if(d.Msg == 'ADULT2'){ alert('本商品為限制級商品,限18歲以上會員瀏覽,請先登入會員,並確認已於會員中心補充「個人資料修改」(含出生年/月)。修改後請重新登入。'); }else{ alert('資料庫忙線中'); } } }); }); //wishList $("."+sets.contBox).on("click","."+sets.wishButton,function(){ var _item = $(this).parents("."+sets.itemBox), SID = _item.find('.button2').attr('SID'); $.ajax({ url:sets.wishUrl, type:"POST", cache:false, async:false, dataType: 'json', data:{SID:SID}, error:function(d){ alert(d.responseText); }, success:function(d){ if(d.Msg=='OK'){ if(d.FBQ){eval(d.FBQ)} if(d.GA4 && typeof gtag == 'function') { gtag("event","add_to_wishlist",{ "items":d.GA4 }); } _item.find('.button2').addClass('click') alert('新增成功!'); }else if(d.Msg == 'NO_MEMBER'){ alert('請先登入會員'); }else if(d.Msg == 'ADULT'){ alert('未滿18歲,無法加入希望清單'); }else{ alert('資料庫忙線中'); } } }); }); //圖片輪播 if($("."+sets.picBox+" .picitem ").length > 5){ $("."+sets.picBox).owlCarousel({ loop : false, items : _this.item_num, nav : true, }); } }; //設定內容 this.setFile= function(_item,$this,d){ _item.find("."+sets.loveBox).removeClass("click"); if(d.ID)_item.find("."+sets.ordButton).attr("sid",d.ID); if(d.Name)_item.find("."+sets.nameBox).html(d.Name); if(d.Prod_No)_item.find("."+sets.prodnoBox).html(d.Prod_No); if(d.Love)_item.find("."+sets.loveBox).addClass(d.Love); _item.find("."+sets.price1Box).html(d.Price1); _item.find("."+sets.price2Box).html(d.Price2); if(d.RBonus)_item.find("."+sets.rbonusBox).html(d.RBonus); if(d.Get_Bonus)_item.find("."+sets.bonusBox).html(d.Get_Bonus); if(d.Color)_item.find("."+sets.colorBox).html(d.Color); if(d.Color_Name)_item.find("."+sets.colorName).html(d.Color_Name); if(d.Stock){ _item.find("."+sets.stockBox).html('庫存 : '+d.Stock); }else{ _item.find("."+sets.stockBox).html(''); } if(sets.type == 3){ if(d.Size_Sel)$this.next("."+sets.sizeSelect).html(d.Size_Sel); if(d.SP3_Sel)$this.nextAll("."+sets.sp3Select).eq(0).html(d.SP3_Sel); if(d.Amount)$this.nextAll("."+sets.amountBox).eq(0).html(d.Amount); $this.nextAll("."+sets.amountBox).eq(0).trigger('change'); }else{ if(d.Size_Button)_item.find("."+sets.sizeBox).html(d.Size_Button); if(d.Size_Sel)_item.find("."+sets.sizeSelect).html(d.Size_Sel); if(d.Size_Name)_item.find("."+sets.sizeName).html(d.Size_Name); if(d.SP3_Button)_item.find("."+sets.sp3Box).html(d.SP3_Button); if(d.SP3_Sel)_item.find("."+sets.sp3Select).html(d.SP3_Sel); if(d.SP3_Name)_item.find("."+sets.sp3Name).html(d.SP3_Name); if(d.Amount > '0'){ if(d.Amount > '20'){ d.Amount = '20'; } _item.find("."+sets.amountBox).val('1'); _item.find("."+sets.amountBox).attr('max',d.Amount); _item.find("."+sets.amountBox).attr('readonly',false); }else{ _item.find("."+sets.amountBox).val('無庫存'); _item.find("."+sets.amountBox).attr('readonly',true); } } for($i=1;$i<=3;$i++){ if(d.Button[$i])_item.find("."+sets.addBox+$i).not('.button1').html(d.Button[$i]); } _this.setImg(_item,d.Pic_Path,d.Pic,d.Video); _this.setFileOther(_item,d); } //變更內容自訂Function this.setFileOther = function(){ } //加入購物車後自訂Function this.setCartOther = function(){ } //設定圖片、影片 this.setImg = function(_item,Pic_Path,Pic,Video){ //手機 if($(window).width() <=768){ //列表 if(sets.type == 1){ _item.find("."+sets.picpathBox).css("background-image","url('/upload_files/fonlego-rwd/prodpic/"+Pic_Path+"')"); _item.find("."+sets.picpathBox).html(''); } //詳細頁 else{ if(sets.type != '4') { _this.item_num = 1; var _Pic = (Pic_Path+','+Pic).split(','); $_Pic1 = '', $_Pic2 = ''; for($i=0;$i<_Pic.length;$i++){ if(_Pic[$i]){ $_Pic1 += '
'; $_Pic1 += ''; $_Pic1 += '
'; $_Pic2 += ''; } } if(Video){ $_Pic1 += '
'; $_Pic1 += ''; $_Pic1 += '
'; } _item.find("."+sets.picpathBox).html($_Pic1).trigger('destroy.owl.carousel') .owlCarousel({ loop : false, items : _this.item_num, nav : true, }); _item.find("."+sets.picpathBox).on('changed.owl.carousel',function(e){ var num = e.item.index; if(document.getElementById("Video")){ if($(".productView").find(".owl-item").eq(num).find("#Video").attr("class")){ $("#big_picture").hide(); document.getElementById("Video").play(); }else{ $("#big_picture").show(); document.getElementById("Video").pause(); } } }); $(".previewbox").html($_Pic2+''); } else { _this.item_num = 5; var _Pic = (Pic_Path+','+Pic).split(','); $Pic = '', $Pic_Path = '', $_Pic2 = '', now_class= 'now', Pic_Size = 'S', $loop = false; for($i=0;$i<_Pic.length;$i++){ var $now =($i==0)?now_class:''; if(_Pic[$i]){ $Pic_Path += '
'; $Pic_Path += '
'; $Pic_Path += ''; $Pic_Path += '
'; $_Pic2 += ''; } } if(Video){ $Pic_Path += '
'; $Pic_Path += '
'; $Pic_Path += '
'; } _item.parents(".productBox").find("."+sets.picpathBox).html($Pic_Path); _item.parents(".productBox").find("."+sets.picBox).html($_Pic2); } } } //PC、平板 else{ //列表 if(sets.type == 1){ var _Pic = (Pic_Path+','+Pic).split(','), $Pic = '', now_class= '', Pic_Size = 'L', $loop = true; _item.find("."+sets.picpathBox).css("background-image","url('/upload_files/fonlego-rwd/prodpic/"+_Pic[0]+"')"); _item.find("."+sets.picpathBox).html(''); } //詳細頁 else{ if(sets.type != '4') { _this.item_num = 5; var _Pic = (Pic_Path+','+Pic).split(','); $Pic = '', $Pic_Path = '', now_class= 'now', Pic_Size = 'S', $loop = false; for($i=0;$i<_Pic.length;$i++){ now_class =($i==0)?now_class:''; if(_Pic[$i]){ $Pic_Path += '
'; $Pic_Path += '
'; $Pic_Path += ''; $Pic_Path += ''; $Pic_Path += '
'; $Pic_Path += ''; $Pic_Path += '
'; } } if(Video){ $Pic_Path += '
'; $Pic_Path += ''; $Pic_Path += '
'; } _item.find("."+sets.picpathBox).html($Pic_Path); } else { _this.item_num = 5; var _Pic = (Pic_Path+','+Pic).split(','); $Pic = '', $Pic_Path = '', $_Pic2 = '', now_class= 'now', Pic_Size = 'S', $loop = false; for($i=0;$i<_Pic.length;$i++){ var $now =($i==0)?now_class:''; if(_Pic[$i]){ $Pic_Path += '
'; $Pic_Path += '
'; $Pic_Path += ''; $Pic_Path += '
'; $_Pic2 += ''; } } if(Video){ $Pic_Path += '
'; $Pic_Path += '
'; $Pic_Path += '
'; } _item.parents(".productBox").find("."+sets.picpathBox).html($Pic_Path); _item.parents(".productBox").find("."+sets.picBox).html($_Pic2); } } if(sets.type != '4') { var now_class = 'now'; //設定輪播圖 for($i=0;$i<_Pic.length;$i++){ now_class =($i==0)?now_class:''; if(_Pic[$i]){ $Pic += '
'; } } if(Video && sets.type != 1){ $Pic += '
'; } if($($Pic).find('.picitem').length > 5){ _item.find("."+sets.picBox).html($Pic) .trigger('destroy.owl.carousel') .owlCarousel({ loop : $loop, items : _this.item_num, nav : true, }); }else{ _item.find("."+sets.picBox).html($Pic) .tigger('destroy.owl.carousel'); } //影片預覽圖 if(document.getElementById("Video")){ document.getElementById("Video").oncanplay=function(){ var video = $("#Video").get(0); var canvas = document.getElementById("video_review"); canvas.getContext('2d').drawImage(video, 0, 0, 66, 92); }; } } } } }; var prod_list = function(option){ var sets = { //商品內容 contBox : 'Main_Content', //總容器的ID styleBox : 'stylebox', //樣式下拉選單的ID sizeBox : 'sizebox', //尺寸下拉選單的ID orderBox : 'orderbox', //排序下拉選單的ID morderBox : 'mobile_sort>div', morderBoxLi : 'mobile_sort>li', pageBox : 'pagebox', //分頁容器的class pageShow : 'page_show', //顯示分頁資訊的ID pageSelect : 'page-select', //分頁下拉選單的class prevPage : 'prev_page', //手機版上一頁的ID nextPage : 'next_page', //手機版下一頁的ID picBox : 'productSlidebox', //圖片容器的class mainPicBox : 'productImg', //主圖片容器的class searchBox : 'slideBox', //搜尋按鈕容器的class searchBtn : 'search_item', //搜尋按鈕的class searchFocus : 'search_focus', //搜尋按鈕focus的class searchType : 'type', //搜尋按鈕type標籤 searchID : 'search_id', //搜尋按鈕search_id標籤 moneyRange : 'money_range', //篩選價格的class mobileFilter: 'mobile-filter', //手機版行銷篩選器的class urlGetID : 'Url_Get', //塞入get資料的表單ID searchUrl : '/products/ajax/list/ajax_get_prod_list.php',//搜尋ajax網址 cleanSearch : 'cleanButton' //清除篩選Button之ID }; $.extend(sets, option); var _this = this; //初始 this.init = function(){ //篩選按鈕 $("."+sets.searchBtn).on('click',function(){ var $class= ""; $class = ($(this).hasClass(sets.searchFocus))?"":sets.searchFocus; //$(this).parents("."+sets.searchBox).children("."+sets.searchBtn).removeClass(sets.searchFocus); $(this).removeClass(sets.searchFocus); $(this).addClass($class); _this.Search(); }); //每頁幾筆 $('input[name="viewNumder"]').on('click',function(){ _this.Search(); }); //排序 $("#"+sets.orderBox).on('change',function(){ _this.Search(); }); //手機版排序-1 $('#'+sets.morderBox).on('click',function(){ $('#'+sets.morderBox).removeAttr('click'); $(this).attr('click','true'); _this.Search(); }); //手機版排序-2 $('#'+sets.morderBoxLi).on('click',function(){ var datavalue = $(this).find('button').attr('data-value'); var dataArr = [[0],[2],[1],[4],[3],[6],[5]]; $('#'+sets.morderBoxLi).removeClass('in-sort'); $(this).addClass('in-sort'); if($(this).attr('class').indexOf('arrow-up') > 0){ $(this).removeClass('arrow-up').addClass('arrow-down'); $(this).find('button').attr('data-value', dataArr[datavalue]); } else{ $(this).removeClass('arrow-down').addClass('arrow-up'); $(this).find('button').attr('data-value', dataArr[datavalue]); } _this.Search(); }); //下拉篩選樣式 $("#"+sets.styleBox).on('change',function(){ _this.Search(); }); //下拉篩選尺寸 $("#"+sets.sizeBox).on('change',function(){ _this.Search(); }); //紅綠標 $("input[name='pair_flag']").click(function(){ _this.Search(); }); //手機版行銷篩選 $("."+sets.mobileFilter).on('click',function(){ $("."+sets.mobileFilter+"[type="+$(this).attr("type")+"]").removeClass("now"); $(this).addClass("now"); _this.Search(); }); //分頁 $("."+sets.pageBox).on('click','.page,.page-next',function(){ window.location.hash = $(this).attr("send"); }); //手機版上下頁 $("#"+sets.prevPage+",#"+sets.nextPage).on('click',function(){ if($(this).attr("send")>0){ window.location.hash = $(this).attr("send"); } }); //分頁下拉選單 $("."+sets.pageSelect).change(function(){ window.location.hash = $(this).val(); }); //分頁錨點 var hash = parseInt(window.location.hash.replace('#','')); if(hash > 0){ _this.Search(hash); } window.onhashchange=function(){ var hash = parseInt(window.location.hash.replace('#','')); if(hash > 0){ _this.Search(hash); } } //篩選價格 $('.nstSlider').nstSlider({ "rounding":{ "50":"1000" }, "crossable_handles":false, "left_grip_selector": ".leftGrip", "right_grip_selector": ".rightGrip", "value_bar_selector": ".bar", "highlight": { "grip_class": "gripHighlighted", "panel_selector": ".highlightPanel" }, "user_mouseup_callback": function(leftValue, rightValue) { $('.leftLabel').text(leftValue); $('.rightLabel').text(rightValue); _this.Search(hash,'no'); }, "value_changed_callback": function(cause, leftValue, rightValue) { $('.leftLabel').text(leftValue); $('.rightLabel').text(rightValue); }, }); //清除篩選 $("#"+sets.cleanSearch).on('click',function(){ $("."+sets.searchBtn).removeClass(sets.searchFocus); //篩選按鈕歸零 $('.nstSlider').nstSlider('set_position',0,3000); $('#'+sets.morderBox).removeAttr('click'); _this.Search(); }); }; //篩選功能 this.Search = function(pageCode,other){ //置頂 if(other != "no"){ $('#wrapper').scrollTop(0); } var _str = "", _style = "&style=", _spec1 = "&spec1=", _spec2 = "&spec2=", pageCode = parseInt(pageCode) || 1, _limit = $('input[name="viewNumder"]:checked').val(), $page = ""; tag = $('input[name="tag"]').val() ?? null; console.log("mytest: " + tag); //搜尋結果頁無限制筆數功能 所以預設值25 if(_limit == undefined){ _limit = 25; } $(".loading").show(); $("."+sets.searchFocus).each(function(){ switch($(this).attr(sets.searchType)){ case "style": _style += $(this).attr(sets.searchID) +','; break; case "spec1": _spec1 += $(this).attr(sets.searchID) +','; break; case "spec2": _spec2 += $(this).attr(sets.searchID) +','; break; } }); _str += _style+_spec1+_spec2; $("."+sets.moneyRange).each(function(){ _str += "&"+$(this).attr("id")+"="+$(this).text(); }); if($("#"+sets.orderBox).val()){ _str += "&order="+$("#"+sets.orderBox).val(); } if($(window).width()<=1024){ //手機版排序-1 if($('#'+sets.morderBox+'[click="true"]').data('val')){ _str += "&order="+$('#'+sets.morderBox+'[click="true"]').data('val'); } //手機版排序-2 $('#'+sets.morderBoxLi+'[class*="in-sort"]').find('button').each(function(){ _str += "&order="+$(this).attr('data-value'); }); } if($("#"+sets.styleBox).val()){ _str += "&style="+$("#"+sets.styleBox).val(); } if($("#"+sets.sizeBox).val()){ _str += "&spec2="+$("#"+sets.sizeBox).val(); } if($("input[name='pair_flag']:checked").val()){ _str += "&pair="+$("input[name='pair_flag']:checked").val(); } $("."+sets.mobileFilter+".now").each(function(){ _str += "&"+$(this).attr("type")+"="+$(this).attr("val"); }) _str += "&limit="+_limit; _str += "&page="+pageCode; _str += "&tag="+tag; // console.log(_str); $.ajax({ url:sets.searchUrl, type:"POST", async:false, data:$("#"+sets.urlGetID).val()+_str, error:function(d){ alert(d.responseText); }, success:function(d){ //插入資料 $("#"+sets.contBox).html(d) .find("."+sets.picBox) .owlCarousel({ loop : true, items : 1, nav : true }); //處理分頁 var Total = $("#Ajax_Total").val(), $start= 0, $end = 0, $Total= Math.ceil(Total/_limit); if(_limit != 99){ //一般分頁 $("."+sets.pageBox).children().css({visibility:''}); $("#"+sets.pageShow).css({visibility:''}); //手機版上一頁 if($Total >1){ $("#"+sets.prevPage).css('opacity', 1); $("#"+sets.prevPage).attr("send",(pageCode-1)); if(pageCode == 1){ $("#"+sets.prevPage).css('opacity', 0); } }else{ $("#"+sets.prevPage).css('opacity', 0); } //手機版下一頁 if(pageCode < $Total){ $("#"+sets.nextPage).css('opacity', 1); $("#"+sets.nextPage).attr("send",(pageCode+1)); }else{ $("#"+sets.nextPage).css('opacity', 0); } if(pageCode == 1){ $("#"+sets.prevPage).css('opacity', 0); } //第一頁 if(pageCode >=4){ $page += '1'; } //上一頁 if(pageCode > 1){ $page += '上一頁...'; } if(pageCode <3){ var $max = ($Total-1>=4)?4:$Total-1; $start = 1; $end = 1+$max; }else if(pageCode >=($Total-1)){ $min = ($Total-4>0)?4:$Total-1; $start = $Total-$min; $end = $Total; }else{ $start = pageCode-2; $end = pageCode+2; } for($i=$start;$i<=$end;$i++){ var $class = (pageCode == $i)?'now':''; $page += ''+$i+''; } //下一頁 if(pageCode <$Total){ $page += '...下一頁'; } //最後一頁 if(pageCode <=$Total-3){ $page += ''+$Total+''; } window.location.hash = pageCode; $("."+sets.pageBox).html($page); $("#"+sets.pageShow).html('此頁顯示 '+((pageCode-1)*_limit+1)+'-'+((Total第'+$i+'頁'; } $("."+sets.pageSelect).html($option); //延遲載入 $('.'+sets.mainPicBox+' img, img.lazyimg').lazyload({ src: 'data-original', }); }else{ $("."+sets.pageBox).children().css({visibility:'hidden'}); $("#"+sets.pageShow).css({visibility:'hidden'}); $(window).Scroll_Data({ loading_box : "#"+sets.contBox, loading_distance : 100, url : sets.searchUrl, data : $("#"+sets.urlGetID).val()+_str, }); } $('#wrapper').scrollTop(0); } }); $(".loading").hide(); } }