var prod_file = function(option){ var sets = { //類型 type : '1', //1->列表,2->詳細頁,3->活動詳細頁,4.一頁式購物 action : 'poducts', //頁面類型 mode : '', //PreVice時為預覽模式 //商品內容 contBox : 'content', //總容器的class itemBox : 'productBox', //商品容器的class nameBox : 'nameBox', //商品名稱的class prodnoBox : 'prodnoBox', //商品編號的class loveBox : 'love', //喜愛清單的class pricebox : 'pricebox', //定價+結帳價的class price2Box : 'font-delete', //定價的class PriceName1: 'PriceName1', //結帳價的名稱 price1Box : 'font-big', //結帳價的class priceBlock: 'priceBlock', //結帳價的block 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 numBlock : 'amountBlock', //數量的區塊 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網址 sale_msg :'sale_msg', //規格的特惠訊息 Wear_Report :'Wear_Report', //試穿報告 ActStrBox :'sale', //規格折扣碼 PreDataBox :'Pre_Data', //是不是預購品和預購到貨時間顯示 PopupBtn1: 'PopupBtn1', //購買跳窗-加入購物車按鈕容器 PopupBtn2: 'PopupBtn2', //購買跳窗-立即結帳按鈕容器 price_group : 'price-group', //隱藏價格用class //加入購物車 addButton : 'add_to_cart', //加入購物車按鈕的class addButtonIn: 'add_to_cart_In', //直接購買按鈕的class addUrl : '/ajax/ajax_add_to_cart.php', //加入購物車網址 addBox : 'Add_Button', //加入購物車按鈕的容器 addBoxIn : 'Add_Button_In', //直接購買的容器 ordButton : 'button1', //選購按鈕(行銷) //貨到通知 informBtn : 'informButton', //貨到通知按鈕的class informSend: 'informSend', //送出按鈕的ID informID : 'informID', //存ID欄位的ID informEmail: 'informEmail', //Email欄位的ID informType: 'informType', //Type欄位的ID informReset: 'informReset', //取消按鈕的ID informClose: 'informClose', //關閉按鈕的ID informUrl : '/products/ajax/common/ajax_add_prod_inform.php', //ajax網址 //wishList loveButton: 'love', //列表加入喜愛清單 wishButton: 'wishButton', //加入喜愛清單按鈕的class wishButtonindex: 'wishButtonindex', //首頁加入喜愛清單按鈕的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 : '', //門市庫存查詢 storeButton : 'storeButton', //門市庫存按鈕ID storeBox : 'storeBox', //門市資料容器ID }; $.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), ActID = $(this).data('aid'), Mark = $(this).data('mark'), Page_Shop_Type = _item.attr("type"); var data = 'Type='+sets.type+'&SID='+SID+'&ActID='+ActID+'&Mark='+Mark+'&mode='+sets.mode+'&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('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.GA4 && typeof gtag == 'function') { gtag("event","view_item",{ "items":d.GA4 }); } _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), ActID = $(this).data('aid'), Mark = $(this).data('mark'), Page_Shop_Type = _item.attr("type"); var data = 'Type='+sets.type+'&SID='+SID+'&ActID='+ActID+'&Mark='+Mark+'&mode='+sets.mode+'&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('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.GA4 && typeof gtag == 'function') { gtag("event","view_item",{ "items":d.GA4 }); } _this.setFile(_item,$this,d); } }); } }); //數量輸入 $("."+sets.contBox).on('keyup',"."+sets.amountBox,function() { if(!$(this).hasClass("Prod_Amount_Change")) { var now_num = $(this).val(), max_num = $(this).attr('max'), min_num = (parseInt(max_num)>0)?1:0; now_num = parseInt(now_num); min_num = parseInt(min_num); $(this).val(now_num); if(now_num>max_num){ alert('庫存不足'); $(this).val(max_num); } if(now_num max){ $(this).prev("."+sets.amountBox).val(max); }else{ $(this).prev("."+sets.amountBox).val(amount+1); } } }); $("."+sets.contBox).on("click",".fa.fa-minus",function() { if(!$(this).hasClass("Prod_Amount")) { var amount = $(this).next("."+sets.amountBox).val(), max = $(this).next("."+sets.amountBox).attr("max"), min = (parseInt(max)>0)?1:0; if(amount == '無庫存'){ return false; } var amount = parseInt(amount); var min = parseInt(min); if(amount-1 <= min){ $(this).next("."+sets.amountBox).val(min); }else{ $(this).next("."+sets.amountBox).val(amount-1); } } }); //關閉跳窗 $("."+sets.contBox).on('click','.close',function(){ $("."+sets.itemBox).removeClass('is-show'); }); //加入購物車按鈕 $("."+sets.contBox).on("click","."+sets.addButton,function(){ if($(this).hasClass('cancel-button') || $(this).hasClass('prod_del')) { return false; } var _item = $(this).parents("."+sets.itemBox), SID = $(this).attr('sid') || 0; if($(this).parents().eq(0).attr('class') == 'Add_Button1'){ var num = 1; }else{ var num = _item.find("."+sets.amountBox).val() || 0; } if(SID == 0){ alert(_jsLang.請選擇尺寸或規格); //errorbox(); }else if(num ==0){ alert(_jsLang.請選擇數量); //errorbox(); }else{ var data = 'SID='+SID+'&num='+num+'&webcacheno='+$('#webcacheno').val()+sets.otherData; $.ajax({ url:sets.addUrl, type:"POST", cache:false, async:false, data:data, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); //alert(d.responseText); }, success:function(d){ if(d.Total && $("span").hasClass("cart-number")){ $(".cart-number").html(d.Total); } $("."+sets.itemBox).removeClass('is-show'); if(d.Pre_Flag==1){ if(d.Stock<=5)_item.find("."+sets.stockBox).html(_jsLang.預購品); }else{ if(d.Stock > 0 && d.Stock<=5)_item.find("."+sets.stockBox).html(_jsLang.庫存+' : '+d.Stock); } if(d.Amount && d.Amount != 'null')_item.find("."+sets.amountBox).html(d.Amount); $("#Shop_Cart_Total>.num").html(d.Total); $("#Show_Shopcart_Total").html(d.Total); if(d.Alert != 'OK'){ alert(d.Alert); } if(d.Alert == 'OK') { //手機 if($(window).width()<=1024){ alert('加入購物車成功'); } if($(".purchaseBox-wrapper")){ $(".purchaseBox-wrapper").removeClass("in-active") } $('.cart-total').html(d.Total); if(sets.type == '4') { $('.successPopupMask').css('display','flex').fadeIn() $('.successPopup').fadeIn() setTimeout(function () { $('.successPopupMask').fadeOut() $('.successPopup').fadeOut() }, 1100) } if(d.GA && typeof ga == 'function') { for(var key in d.GA) { Pro = JSON.parse(d.GA[key]); Sku = Pro['id']; ga('ec:addProduct',Pro); } ga('ec:setAction','add'); ga('send','event','購物車','加入購物車',Sku); } if(d.GA_conversion && typeof gtag == 'function') { gtag('event', 'add_to_cart', {'send_to':d.GA_conversion,'value':d.GA_values,'items':d.GA_items}); gtag('event', 'conversion', {'send_to':d.GA_conversion}); } 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)} //LINE-Tag if(d.LINE_Tag_id){ _lt('send', 'cv', { type: 'AddToCart' },[d.LINE_Tag_id]); } window.dataLayer = window.dataLayer || []; var products = []; for(var i=0;i 0 && d.Stock<=5)_item.find("."+sets.stockBox).html(_jsLang.庫存+' : '+d.Stock); } if(d.Amount && d.Amount != 'null')_item.find("."+sets.amountBox).html(d.Amount); // $("#Shop_Cart_Total>.num").html("("+d.Total+")"); $("#Show_Shopcart_Total").html(d.Total); if(d.Alert != 'OK'){ alert(d.Alert); } if(d.Alert == 'OK') { if(d.GA && typeof ga == 'function') { for(var key in d.GA) { Pro = JSON.parse(d.GA[key]); Sku = Pro['id']; ga('ec:addProduct',Pro); } ga('ec:setAction','add'); ga('send','event','購物車','加入購物車',Sku); } if(d.GA_conversion && typeof gtag == 'function') { gtag('event', 'conversion', {'send_to':d.GA_conversion}); } if(d.FBQ){eval(d.FBQ)} //LINE-Tag if(d.LINE_Tag_id){ _lt('send', 'cv', { type: 'AddToCart' },[d.LINE_Tag_id]); } window.dataLayer = window.dataLayer || []; var products = []; for(var i=0;i 5){ $("."+sets.picBox).owlCarousel({ loop : false, items : _this.item_num, nav : true, }); } }; //設定內容 this.setFile= function(_item,$this,d){ _item.find("."+sets.loveBox).removeClass("fa-heart,fa-heart-o"); if(d.ID)_item.find("."+sets.ordButton).attr("sid",d.ID); if(d.ID && $(".purchaseBox-btn").length > 0){ $(".purchaseBox-btn").data("sid", d.ID) } if(d.ID)_item.find("."+sets.loveBox).attr("sid",d.ID); if(d.Name)_item.find("."+sets.nameBox).html(d.Name); if(d.Pos_No)_item.find("."+sets.prodnoBox).html(d.Pos_No); if(d.Love)_item.find("."+sets.loveBox).addClass(d.Love); if(d.Price_Show)_item.find("."+sets.price_group).css("display",d.Price_Show); if(d.Price_Name1){ _item.find("."+sets.PriceName1).html(d.Price_Name1); } if(d.Price1){ _item.find("."+sets.price1Box).html(d.Price1); _item.find("."+sets.priceBlock).show(); }else{ _item.find("."+sets.priceBlock).hide(); } if(d.Price2){ // _item.find("."+sets.price2Box).html(d.Price2).show(); }else{ // _item.find("."+sets.price2Box).hide(); } 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); _item.find("."+sets.PreDataBox).html(d.Pre_Data); _item.find("."+sets.sale_msg).html(d.sale_msg); _item.find("."+sets.Wear_Report).html(d.Wear_Report); if(d.Stock){ _item.find("."+sets.stockBox).html(_jsLang.庫存+' : '+d.Stock); }else{ _item.find("."+sets.stockBox).html(''); } if(d.Act_Str){ _item.find("."+sets.ActStrBox).replaceWith(d.Act_Str); }else{ _item.find("."+sets.ActStrBox).hide(); } 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.numBlock).eq(0).show(); $this.nextAll("."+sets.amountBox).eq(0).html(d.Amount); }else{ $this.nextAll("."+sets.numBlock).eq(0).hide(); $this.nextAll("."+sets.amountBox).eq(0).html(''); } $this.nextAll("."+sets.amountBox).eq(0).trigger('change'); }else{ if(sets.type == 2) { if(d.Size_Button)_item.find("."+sets.sizeBox).replaceWith(d.Size_Button); } else if(sets.type == 4) { _item.find("."+sets.sizeBox).replaceWith(d.Size_Button); } 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.Amount2){ _item.find("."+sets.numBlock).show(); _item.find("."+sets.amountBox).attr('max',d.Amount2); }else{ _item.find("."+sets.numBlock).hide(); _item.find("."+sets.amountBox).html(''); } if(d.Amount) { _item.find("."+sets.numBlock).eq(0).show(); _item.find("."+sets.amountBox).eq(0).html(d.Amount); } } if(sets.type == 2) { //購物車頁面 if(d.SSID) { _item.find("."+sets.addButton).attr("sid",d.SSID); } if(d.SSPic) { _item.find(".Pic_Box").attr('src',d.SSPic); } if(d.Store) { $('#'+sets.storeBox).html(d.Store); $('#'+sets.storeButton).show(); } else { $('#'+sets.storeButton).hide(); } if(d.Serial_No) { var new_url = '/'+$("#Website_Mall_ID").val()+'/product-detail/'+d.Serial_No; if(sets.mode){ new_url += '?mode='+sets.mode; } window.history.replaceState({id:d.ID},d.Name,new_url); } if(d.Community)$(".followbox").html(d.Community); } _item.find("."+sets.addBox).html(d.Button); _item.find("."+sets.addBoxIn).html(d.Button2); if(d.Pic_Path)_this.setImg(_item,d.Pic_Path,d.Pic,d.Video,d.Pic_Other); _this.setFileOther(_item,d); } //變更內容自訂Function this.setFileOther = function(){ } //加入購物車後自訂Function this.setCartOther = function(){ } //設定圖片、影片 this.setImg = function(_item,Pic_Path,Pic,Video,other){ //手機 if($(window).width() <=768) { //列表 if(sets.type == 1){ _item.find("."+sets.picpathBox).css("background-image","url('https://cdn-plain-me.fonlego.com//upload_files/fonlego-rwd/prodpic/"+Pic_Path+"')"); _item.find("."+sets.picpathBox).html(''); } //詳細頁 else{ if(sets.type != '4') { _item.find('.'+sets.picpathBox).trigger('destroy.owl.carousel'); _item.find('.'+sets.picpathBox).html(Pic_Path); $('#Pop_Pic_Box').html(other); const prodView = $('.productImg') prodView.owlCarousel({ loop: false, items: 1, dots: true, dotsData: true, nav: true, margin: 10, onRefreshed: function(e) { const pictureHeight = prodView.find('.picbox').height() prodView.find('.owl-nav').css({ top: (pictureHeight / 2), }); } }) setTimeout(function(){ _item.find('.'+sets.picpathBox).trigger('refresh.owl.carousel'); },500); function showNowIndex() { const nowIndex = $('.extra-slide').find('.owl-item.active').index(); $('.extra-dot').find('.owl-item').removeClass('theme-shownow').eq(nowIndex).addClass('theme-shownow') } $('.extra-dot').owlCarousel({ items: 12, nav: true, dots: false, margin: 16, }) $('.extra-slide').owlCarousel({ items: 1, nav: true, dots: false, URLhashListener: true, onTranslated: showNowIndex, onInitialized: showNowIndex, onRefreshed: showNowIndex, }) } else { _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++){ 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.parents(".productBox").find("."+sets.picpathBox).html($Pic_Path); _item.parents(".productBox").find("."+sets.picpathBox+" .zoonbox").eq(0).addClass(now_class); } $(".previewbox .picitem").eq(0).addClass(now_class);; } } //PC、平板 else{ //列表 if(sets.type == 1){ var _Pic = (Pic_Path+','+Pic).split(','), $Pic = '', now_class= '', Pic_Size = 'L', $loop = true; _item.find("."+sets.picpathBox).html(Pic_Path); } //詳細頁 else{ if(sets.type != '4') { _item.find('.'+sets.picpathBox).trigger('destroy.owl.carousel'); _item.find('.'+sets.picpathBox).html(Pic_Path); $('#Pop_Pic_Box').html(other); const prodView = $('.productImg') prodView.owlCarousel({ loop: false, items: 1, dots: true, dotsData: true, nav: true, margin: 10, onRefreshed: function(e) { const pictureHeight = prodView.find('.picbox').height() prodView.find('.owl-nav').css({ top: (pictureHeight / 2), }); } }) setTimeout(function(){ _item.find('.'+sets.picpathBox).trigger('refresh.owl.carousel'); },500); function showNowIndex() { const nowIndex = $('.extra-slide').find('.owl-item.active').index(); $('.extra-dot').find('.owl-item').removeClass('theme-shownow').eq(nowIndex).addClass('theme-shownow') } $('.extra-dot').owlCarousel({ items: 12, nav: true, dots: false, margin: 16, }) $('.extra-slide').owlCarousel({ items: 1, nav: true, dots: false, URLhashListener: true, onTranslated: showNowIndex, onInitialized: showNowIndex, onRefreshed: showNowIndex, }) } else { _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++){ 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.parents(".productBox").find("."+sets.picpathBox).html($Pic_Path); _item.find("."+sets.picpathBox+" .zoonbox").eq(0).addClass(now_class); } } if(sets.type == '4') { _item.find('.'+sets.picpathBox).trigger('destroy.owl.carousel'); _item.find('.'+sets.picpathBox).html(Pic_Path); $('#Pop_Pic_Box').html(other); const prodView = $('.productImg') prodView.owlCarousel({ loop: false, items: 1, dots: true, dotsData: true, nav: true, margin: 10, onRefreshed: function(e) { const pictureHeight = prodView.find('.picbox').height() prodView.find('.owl-nav').css({ top: (pictureHeight / 2), }); } }) setTimeout(function(){ _item.find('.'+sets.picpathBox).trigger('refresh.owl.carousel'); },500); function showNowIndex() { const nowIndex = $('.extra-slide').find('.owl-item.active').index(); $('.extra-dot').find('.owl-item').removeClass('theme-shownow').eq(nowIndex).addClass('theme-shownow') } $('.extra-dot').owlCarousel({ items: 12, nav: true, dots: false, margin: 16, }) $('.extra-slide').owlCarousel({ items: 1, nav: true, dots: false, URLhashListener: true, onTranslated: showNowIndex, onInitialized: showNowIndex, onRefreshed: showNowIndex, }) } else { _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++){ 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.parents(".productBox").find("."+sets.picpathBox).html($Pic_Path); _item.find("."+sets.picpathBox+" .zoonbox").eq(0).addClass(now_class); } } } }; var prod_list = function(option){ var sets = { //商品內容 contBox : 'Main_Content', //總容器的ID styleBox : 'stylebox', //樣式下拉選單的ID sizeBox : 'sizebox', //尺寸下拉選單的ID orderBox : 'orderbox', //排序下拉選單的ID morderBox : 'mobile_sort>div', 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('1'); }); //每頁幾筆 $('input[name="viewNumder"]').on('click',function(){ _this.Search('1'); }); //排序 $("#"+sets.orderBox).on('change',function(){ _this.Search('1'); }); //手機版排序 $('#'+sets.morderBox).on('click',function(){ $('#'+sets.morderBox).removeAttr('click'); $(this).attr('click','true'); _this.Search('1'); }) //下拉篩選樣式 $("#"+sets.styleBox).on('change',function(){ _this.Search('1'); }); //下拉篩選尺寸 $("#"+sets.sizeBox).on('change',function(){ _this.Search('1'); }); //紅綠標 $("input[name='pair_flag']").click(function(){ _this.Search('1'); }); //手機版行銷篩選 $("."+sets.mobileFilter).on('click',function(){ $("."+sets.mobileFilter+"[type="+$(this).attr("type")+"]").removeClass("now"); $(this).addClass("now"); _this.Search('1'); }); //分頁 $("."+sets.pageBox).on('click','.Page_Button,.page-next',function(){ // window.location.hash = $(this).attr("send"); _this.Search(parseInt($(this).attr("send"))); }); //手機版上下頁 $("#"+sets.prevPage+",#"+sets.nextPage).on('click',function(){ if($(this).attr("send")>0){ // window.location.hash = $(this).attr("send"); _this.Search(parseInt($(this).attr("send"))); } }); //分頁錨點 var hash = parseInt(window.location.hash.replace('#','')); if(hash > 0){ _this.Search(hash); } //清除篩選 $("#"+sets.cleanSearch).on('click',function(){ $("."+sets.searchBtn).removeClass(sets.searchFocus); //篩選按鈕歸零 // $('.nstSlider').nstSlider('set_position',0,$('.nstSlider').attr("data-range_max")); $('#'+sets.morderBox).removeAttr('click'); _this.Search('1'); }); $("#Main_Content").on('click','.cleanItem',function(){ $('[data-value="'+$.trim($(this).text())+'"]').removeClass(sets.searchFocus); _this.Search('1'); }); }; //篩選功能 this.Search = function(pageCode,other){ //置頂 if(other != "no"){ $(window).scrollTop(0); } var _str = "", _style = "&style=", _pattern = "&pattern=", _material= "&material=", _class = "&class=", _gender = "&gender=", _spec1 = "&spec1=", _spec2 = "&spec2=", _brand = "&brand=", pageCode = parseInt(pageCode) || '', _limit = $('input[name="viewNumder"]:checked').val(), $page = ""; //搜尋結果頁無限制筆數功能 所以預設值25 if(_limit == undefined){ _limit = 25; } $(".loading").show(); var search_arr = new Array(); $("."+sets.searchFocus).each(function(){ if(search_arr.indexOf($(this).attr(sets.searchType)) === -1){ search_arr.push($(this).attr(sets.searchType)); } switch($(this).attr(sets.searchType)){ case "style": _style += $(this).attr(sets.searchID) +','; break; case "pattern": _pattern += $(this).attr(sets.searchID) +','; break; case "material": _material += $(this).attr(sets.searchID) +','; break; case "class": _class += $(this).attr(sets.searchID) +','; break; case "gender": _gender += $(this).attr(sets.searchID) +','; break; case "spec1": _spec1 += $(this).attr(sets.searchID) +','; break; case "spec2": _spec2 += $(this).attr(sets.searchID) +','; break; case "brand": _brand += $(this).attr(sets.searchID) +','; break; } }); search_arr.forEach(function(value){ switch(value){ case "style": _str += _style; break; case "pattern": _str += _pattern; break; case "material": _str += _material; break; case "class": _str += _class; break; case "gender": _str += _gender; break; case "spec1": _str += _spec1; break; case "spec2": _str += _spec2; break; case "brand": _str += _brand; break; } }); // _str += _style+_pattern+_material+_class+_gender+_spec1+_spec2; // $("."+sets.moneyRange).each(function(){ // _str += "&"+$(this).attr("id")+"="+$(this).text(); // }); _str_order = ''; if($("#"+sets.orderBox).val()){ _str_order = "&order="+$("#"+sets.orderBox).val(); } if($(window).width()<=1024){ //手機版排序 if($('#'+sets.morderBox+'[click="true"]').data('value')){ _str_order = "&order="+$('#'+sets.morderBox+'[click="true"]').data('value'); } } _str += _str_order; 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; //檢查state記錄 if(!pageCode) { pageCode = window.history.state.page || '1'; } _str += "&page="+pageCode; _str = $("#"+sets.urlGetID).val()+_str; $.ajax({ url:sets.searchUrl, type:"POST", async:false, data:_str, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ //插入資料 $("#"+sets.contBox).html(d); //插入分頁 $("."+sets.pageBox).html($("#Ajax_Page").val()); //變更網址 var url = $("#Page_Url").val(); if(url) { url += '?mode=search'+_str; window.history.replaceState({page:pageCode},'',url); } } }); $(".loading").hide(); } }