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 AvgPriceBox: 'AvgPriceBox', // 平均售價div的class AvgPrice : 'AvgPrice', // 平均售價span的class PopPrice3 : 'pop_main_price3', // 跳窗會員價的class PopPrice2 : 'pop_main_price2', // 跳窗定價的class PopPrice1 : 'pop_main_price1', // 跳窗結帳價的class PopDiffPrice : 'pop_main_price_diff', // 跳窗省多少元的class rbonusBox : 'price-rbonus', // 紅利兌換的class bonusBox : 'get_bonus', // 購物金的class Limit_Purchase : 'Limit_Purchase', // 規格限購 className ShippingFree_Text : 'ShippingFree_Text', // 規格免運文字 className Get_RBonus_Text : 'Get_RBonus_Text', // 規格紅利文字 className 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 : 'checkbox-item', // 規格 -按鈕的class specID2 : 'SID', // 規格 -要傳送的標籤屬性 specUrl : Project_Country+'products/ajax/common/ajax_get_prod_item.php', // 規格 -ajax網址 sale_msg :'sale_msg', // 規格的特惠訊息 sale_msg_box:'salebox', // 規格的特惠訊息容器 Wear_Report :'Wear_Report', // 試穿報告 ActStrBox :'sale-string', // 列表頁活動字串/規格活動小圖 ActDStrBox :'sale', // 細節頁活動字串/規格活動小圖 ActStr1 :'ActStr1', // 規格活動字串1 ActStr2 :'ActStr2', // 規格活動字串2 ActStr3 :'ActStr3', // 規格活動字串3 ActStr4 :'ActStr4', // 規格活動字串4 PreDataBox :'Pre_Data', // 是不是預購品和預購到貨時間顯示 PriceActEndBox: 'Price_Act_End', PopupBtn1: 'PopupBtn1', // 購買跳窗-加入購物車按鈕容器 PopupBtn2: 'PopupBtn2', // 購買跳窗-立即結帳按鈕容器 PopupBtn4: 'PopupBtn4', // 購買跳窗-前往定期購按鈕容器 needChangeSID: 'sid-item', // 需要改變sid的其他class saleCover :'sale-cover', // 標籤小圖class // 加入購物車 addButton : 'add_to_cart', // 加入購物車按鈕的class addButtonIn: 'add_to_cart_In', // 直接購買按鈕的class addUrl : Project_Country+'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 informSerial: 'informSerial', // 存貨到通知的規格 ActDataID : 'ActDataID', // 存活動ID欄位的ID informEmail: 'informEmail', // Email欄位的ID informCellphone: 'informCellphone', // 手機欄位的ID informClose: 'informClose', // 關閉按鈕的ID informUrl : Project_Country+'products/ajax/common/ajax_add_prod_inform.php', // ajax網址 // wishList loveButton: 'love', // 列表加入喜愛清單 wishButton: 'wishButton', // 加入喜愛清單按鈕的class wishButtonindex: 'wishButtonindex', // 首頁加入喜愛清單按鈕的class wishUrl : Project_Country+'products/ajax/common/ajax_add_wish_list.php', // ajax網址 // 設定圖片 mobileUrl : Project_Country+'products/ajax/detail/productView_moblie.php', // ajax手機網址 pcUrl : Project_Country+'products/ajax/detail/productView_pc.php', // ajax桌機網址 picSize : 'S', 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), ActProdID = $(this).data('actprodid'), Mark = $(this).data('mark'), Page_Shop_Type = _item.attr("type"); var data = 'Type='+sets.type+'&SID='+SID+'&ActProdID='+ActProdID+'&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){ _this.setFile(_item,$this,d); // 校正部分moreview沒滿100% window.dispatchEvent(new Event('resize')) // console.log(d) // 顯示ajax規格切換叫回來的內容 } }); } }); // 尺寸下拉選單 $("."+sets.contBox).on('change',"."+sets.colorSelect+",."+sets.sizeSelect+",."+sets.sp3Select,function(){ var _item = $(this).parents("."+sets.itemBox), SID = $(this).val(), $this = $(this), ActProdID = $(this).data('actprodid'), Mark = $(this).data('mark'), Page_Shop_Type = _item.attr("type"); var data = 'Type='+sets.type+'&SID='+SID+'&ActProdID='+ActProdID+'&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){ // console.log(d) if(d.DataLayer){eval(d.DataLayer)} _this.setFile(_item,$this,d); console.log(_item); } }); } }); // 數量輸入 $("."+sets.contBox).on('change',"."+sets.amountBox,function(){ 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_num0)?1:0; if(amount == '無庫存' || $(this).hasClass('Prod_Plus')){ return false; } var amount = parseInt(amount); var max = parseInt(max); if(amount+1 >= max){ $(this).prev("."+sets.amountBox).val(max); $(this).addClass("disabled") }else{ $(this).prev("."+sets.amountBox).val(amount+1); } if(amount+1 > min && max > 1){ $(this).siblings("[class*=-minus]").removeClass("disabled") } }); $(document).off("click","[class*=-minus]") $(document).on("click","[class*=-minus]",function(){ var amount = $(this).next("."+sets.amountBox).val(), max = $(this).next("."+sets.amountBox).attr("max"), min = (parseInt(max)>0)?1:0; if(amount == '無庫存' || $(this).hasClass('Prod_Minus')){ return false; } var amount = parseInt(amount); var min = parseInt(min); if(amount-1 <= min){ $(this).next("."+sets.amountBox).val(min); $(this).addClass("disabled") }else{ $(this).next("."+sets.amountBox).val(amount-1); } if(amount-1 < max && max > 1){ $(this).siblings("[class*=-plus]").removeClass("disabled") } }); // 關閉跳窗 $("."+sets.contBox).on('click','.close',function(){ $("."+sets.itemBox).removeClass('is-show'); }); // 加入購物車按鈕 $("."+sets.contBox).on("click","."+sets.addButton,function(){ var _item = $(this).parents("."+sets.itemBox), SID = $(this).attr('sid') || 0, type = $(this).attr('type') || 'normal'; 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+'&type='+type+'&webcacheno='+$('#webcacheno').val()+sets.otherData; $.ajax({ url:sets.addUrl, type:"POST", cache:false, async:false, data:data, dataType: 'json', }).done(function(d) { $("."+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); $(".cart-total-num").html(d.Total) if(d.Open_Flag == 1){ $('#Shop_Cart_Total').addClass('can-open'); }else{ $('#Shop_Cart_Total').removeClass('can-open'); } if(d.Alert != 'OK'){ alert(d.Alert); _this.afterAlert(d.Alert); } _this.setCartOther(); if(d.Alert == 'OK'){ if(sets.type == '4') { const appendChild = `
${_jsLang.已加入購物車}
` $('body').addClass('overflow-hidden').append(appendChild) setTimeout(function () { $('#successPopupMask').fadeOut(500, function() { $('#successPopupMask').remove() $('body').removeClass('overflow-hidden') }) }, 1000) } if(d.DataLayer){ eval(d.DataLayer); } if(sets.type != '4') { $.ajax({ url:Project_Country+"ajax/ajax_get_cart.php", type:"POST", async:false, cache:false, data:{Type:'Prod',ID:SID,Act:'Add',SIT:d.SIT_Flag}, success:function(d){ $('.shopping-cartbox').removeClass('in-open'); $("#Header_Shopcart_Prod").html(d); $("#Header_Shopcart_Prod").parent(".one-cartbox").addClass('in-open'); setTimeout(function(){ $("#Header_Shopcart_Prod").parent(".one-cartbox").removeClass('in-open'); },3000); } }) } } }).fail(function(d) { alert('網路連線過慢,網頁請重新整理'); }).always(() => { if($("."+sets.contBox).hasClass('popupBox-wrapper')) { $("."+sets.contBox).trigger('click') } }) } }); // 直接購物按鈕 $("."+sets.contBox).on("click","."+sets.addButtonIn,function(){ var _item = $(this).parents("."+sets.itemBox), SID = $(this).attr('sid') || 0, num = _item.find("."+sets.amountBox).val() || 0; type = $(this).attr('type') || 'normal'; if(SID == 0){ alert(_jsLang.請選擇尺寸或規格); // errorbox(); }else if(num ==0){ alert(_jsLang.請選擇數量); // errorbox(); }else{ var data = 'SID='+SID+ '&num='+num+'&type='+type+'&webcacheno='+$('#webcacheno').val()+sets.otherData; $.ajax({ url:sets.addUrl, type:"POST", cache:false, async:false, data:data, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ console.log(d) 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+")"); $(".cart-total-num").html(d.Total) if(d.Total_Normal > 0){ $('#Shop_Cart_Total').addClass('can-open'); }else{ $('#Shop_Cart_Total').removeClass('can-open'); } if(d.Alert != 'OK'){ alert(d.Alert); _this.afterAlert(d.Alert); } _this.setCartOther(); if(d.Alert == 'OK'){ if(d.DataLayer){eval(d.DataLayer)} $("."+sets.itemBox).hide(); if(sets.type != '4') { $.ajax({ url:Project_Country+"ajax/ajax_get_cart.php", type:"POST", async:false, cache:false, data:{Type:'Prod',ID:SID}, success:function(d){ $('.shopping-cartbox').removeClass('in-open'); $("#Header_Shopcart").html(d); $("#Header_Shopcart").parent(".one-cartbox").animate({'opacity':1,'maxHeight':'999px'}).css('z-index','100'); setTimeout(function(){ $("#Header_Shopcart").parent(".one-cartbox").animate({'maxHeight':'0px','opacity':0},function(){ $(this).removeAttr('style'); $(".shopping-cartbox").removeAttr('style'); }); },3000); } }) window.location.href = '/'+$("#Website_Mall_ID").val()+'/shopcart/step1'; } } } }); } }); // 貨到通知按鈕 $("."+sets.contBox).on("click","."+sets.informBtn,function(){ $("#"+sets.informID).val($(this).attr('SID')); $("#"+sets.ActDataID).val($(this).attr('AID')); $("#"+sets.informSerial).val($(this).attr("serial")); let target = $(this).attr("for"), title = $(this).text().trim(), cellphoneFlag = $(this).data("cellphone"), wrapper = $(".addButtonBox-wrapper") if(!cellphoneFlag){ wrapper.find(".cellphone-group").remove() } if(target == "addButton_check"){ wrapper.find(".title").text(title) $("#addButton_check").prop("checked", false) wrapper.removeClass("hide") } }); $("#"+sets.informSend).off("click") $("#"+sets.informSend).click(function(){ let email = $("#"+sets.informEmail).val(); cellphone = $("#"+sets.informCellphone).val(), emailRule = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/, cellphoneRule = /^[0-9]{10}$/g if(!email && !cellphone) { alert('請輸入E-mail或手機號碼'); return false; } if(email && email.search(emailRule) == -1) { alert('E-mail格式錯誤'); return false; } if(cellphone && cellphone.search(cellphoneRule) == -1) { alert('手機號碼格式錯誤'); return false; } $.ajax({ url:sets.informUrl, type:"POST", dataType : "json", cache:false, async:false, data:{SID:$("#"+sets.informID).val(),AID:$("#"+sets.ActDataID).val(),email:email,cellphone:cellphone,Serial_No:$("#"+sets.informSerial).val()}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ console.log(d) if(d.code==200){ // alert(_jsLang.您已成功新增一筆貨到通知當商品有貨時我們會儘快通知您); alert(d.Msg); }else{ alert(_jsLang.資料庫忙線中); } $("#"+sets.informClose).trigger("click"); } }); }); // 列表增加wishList $("."+sets.contBox).on("click","."+sets.loveButton,function(){ var $this = $(this), _item = $(this).parents(".productBox"), SID = _item.find('.'+sets.loveBox).attr('sid'), type = 'del'; if($this.attr("class").match('fa-heart-o')){ type = 'add'; } $.ajax({ url:sets.wishUrl, type:"POST", cache:false, async:false, data:{Type:type,SID:SID}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Msg =='OK'){ if(d.DataLayer){eval(d.DataLayer)} if(type == 'add'){ $this.removeClass("fa-heart-o"); $this.addClass("fa-heart"); alert(_jsLang.已加入喜愛清單); }else{ $this.removeClass("fa-heart"); $this.addClass("fa-heart-o"); } }else if(d.Msg == 'NO_MEMBER'){ alert(_jsLang.請先登入會員); }else{ alert(_jsLang.資料庫忙線中); } } }); }); // wishList $("."+sets.contBox).on("click","."+sets.wishButton,function(){ var $this = $(this), SID = $this.attr('SID'), type = 'del'; if($this.find("i").attr("class").match('fa-heart-o')){ type = 'add'; } $.ajax({ url:sets.wishUrl, type:"POST", cache:false, async:false, data:{Type:type,SID:SID}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Msg == 'OK'){ if(d.DataLayer){eval(d.DataLayer)} if(type == 'add'){ $this.find("i").removeClass("fa-heart-o"); $this.find("i").addClass("fa-heart"); alert(_jsLang.已加入喜愛清單); }else{ $this.find("i").removeClass("fa-heart"); $this.find("i").addClass("fa-heart-o"); } }else if(d.Msg == 'NO_MEMBER'){ alert(_jsLang.請先登入會員); }else{ alert(_jsLang.資料庫忙線中); } } }); }); // wishList $("."+sets.contBox).on("click","."+sets.wishButtonindex,function(){ var _item = $(this).parents("."+sets.itemBox), // SID = _item.find('.button2').attr('SID'); SID = _item.find('.wishButtonindex').attr('SID'); $.ajax({ url:sets.wishUrl, type:"POST", cache:false, async:false, data:{SID:SID}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Msg == 'OK'){ if(d.DataLayer){eval(d.DataLayer)} alert(_jsLang.新增成功); }else if(d.Msg == 'NO_MEMBER'){ alert(_jsLang.請先登入會員); }else{ alert(_jsLang.資料庫忙線中); } } }); }); // 圖片輪播 if($("."+sets.picBox+" .picitem ").length > 0){ $("."+sets.picBox).owlCarousel({ dots: false, nav: true, navText: ['', ''], margin: 10, responsive:{ 0 : { items: 4 }, 1200 : { items: 3, mouseDrag: false, touchDrag: false, } } }); } }; // 設定內容 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); _item.find("."+sets.loveBox).attr("sid",d.ID); _item.find("."+sets.needChangeSID).attr("sid",d.ID) } if(d.Name)_item.find("."+sets.nameBox).html(d.Name); console.log(sets.nameBox); 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_Name1){ _item.find("."+sets.PriceName1).html(d.Price_Name1); } if(d.Price1 && d.Display_Flag != 4){ _item.find("."+sets.price1Box).html(d.Price1); _item.find("."+sets.priceBlock).show(); }else{ _item.find("."+sets.priceBlock).hide(); } if(d.Price2 && d.Display_Flag != 4){ _item.find("."+sets.price2Box).html(d.Price2).show(); }else{ _item.find("."+sets.price2Box).hide(); } if(d.Avg_Price && d.Display_Flag != 4){ _item.find("."+sets.AvgPriceBox).show(); _item.find("."+sets.AvgPrice).html(d.Avg_Price); _item.find("."+sets.pricebox).hide(); }else{ _item.find("."+sets.AvgPriceBox).hide(); _item.find("."+sets.pricebox).show(); } if(d.Price1 && d.Display_Flag != 4){ _item.find("."+sets.PopPrice1).html(d.Main_Price1); } else{ _item.find("."+sets.PopPrice1).hide(); } if(d.Price2 && d.Display_Flag != 4){ _item.find("."+sets.PopPrice2).html(d.Main_Price2); } else{ _item.find("."+sets.PopPrice2).hide(); } if(d.Price3 && d.Display_Flag != 4){ _item.find("."+sets.PopPrice3).html(d.Main_Price3); } else{ _item.find("."+sets.PopPrice3).hide(); } if(d.Price1_Diff && d.Display_Flag != 4){ _item.find("."+sets.PopDiffPrice).html(d.Price1_Diff); _item.find("."+sets.Price1_Diff).show(); } else{ _item.find("."+sets.Price1_Diff).hide(); } if(d.RBonus)_item.find("."+sets.rbonusBox).html(d.RBonus); _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.PriceActEndBox).html(d.Price_Act_End); _item.find("."+sets.Limit_Purchase).html(d.Limit_Purchase); _item.find("."+sets.ShippingFree_Text).html(d.ShippingFree_Text); _item.find("."+sets.Get_RBonus_Text).html(d.Get_RBonus_Text); // 活動小字1-4 for (let i = 1; i <= 4; i++) { _item.find("."+sets['ActStr'+i]).html(d['Act_Str'+i]); } if(d.sale_msg){ _item.find("."+sets.sale_msg).html(d.sale_msg); _item.find("."+sets.sale_msg_box).removeClass("hide") }else{ _item.find("."+sets.sale_msg_box).addClass("hide") } _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(''); } _item.find("."+sets.ActStrBox).html(d.Act_Str); if(d.Act_Str_D){ _item.find("."+sets.ActDStrBox).replaceWith(d.Act_Str_D); }else{ _item.find("."+sets.ActDStrBox).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(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); _item.find("."+sets.amountBox).val(1); _item.removeClass('activities-shortage') }else{ if(d.Amount2 == 0) { _item.find("."+sets.amountBox).attr('max',d.Amount2); _item.find("."+sets.amountBox).val(d.Amount2); _item.addClass('activities-shortage') } _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){ $("."+sets.contBox).find("."+sets.wishButton).attr("sid",d.ID); $("."+sets.contBox).find("."+sets.wishButton).find("i").removeClass("fa-heart fa-heart-o"); $("."+sets.contBox).find("."+sets.wishButton).find("i").addClass(d.Love); if(d.Serial_No){ var new_url = Project_Country + $("#Website_Mall_ID").val()+'/product-detail/'+d.Serial_No; if(sets.mode){ new_url += '?mode='+sets.mode; } if(location.pathname.indexOf("/product-detail/") > 0){ window.history.replaceState({id:d.ID},d.Name,new_url); } } if(sets.mode) if(d.Community)$(".followbox").html(d.Community); } if(d.Prod_Multi)$(".Prod_Multi").html(d.Prod_Multi); for($i=1;$i<=3;$i++){ var NewButton = d.Button[$i] || ''; _item.find("."+sets.addBox+$i).html(NewButton); } _item.find("."+sets.addBoxIn).html(d.Button2); _item.find("."+sets.PopupBtn1).html(d.ButtonPop); _item.find("."+sets.PopupBtn2).html(d.ButtonPop2); _item.find("."+sets.PopupBtn4).html(d.ButtonPop4); if(d.Serial_No) { _item.find("."+sets.needChangeSID).attr("serial",d.Serial_No); } $(".fixed-button ."+sets.PopupBtn1).html(d.ButtonPop); $(".fixed-button ."+sets.PopupBtn2).html(d.ButtonPop2); $(".fixed-button ."+sets.PopupBtn4).html(d.ButtonPop4); _this.setImg(_item,d.Pic_Path,d.Pic,d.Video, d.Back_Pic,d.Serial_No, d.saleCover); if(d.Display_Flag != '4') { _item.find(".spec-amount").show(); } else { _item.find(".spec-amount").hide(); } let tempCartNum = d.Act_Temp_Cart if(tempCartNum > 0){ _item.addClass('activities-selected') }else{ _item.removeClass('activities-selected') } if(d.LineQuestion) { $(".line-question").attr("href",d.LineQuestion); } if(d.saleCover){ _item.find("."+sets.saleCover).show(); _item.find("."+sets.saleCover).attr("src", d.saleCover); }else{ _item.find("."+sets.saleCover).hide(); _item.find("."+sets.saleCover).attr("src", ""); } _this.setFileOther(_item,d); } // 變更內容自訂Function this.setFileOther = function(){ } // 加入購物車後自訂Function this.setCartOther = function(){ } // alert跳窗後動作 this.afterAlert = function() { } // 設定圖片、影片 this.setImg = function(_item,Pic_Path,Pic,Video, Back_Pic,Serial_No, saleCover){ // 手機 if($(window).width() <=768){ // 列表 if(sets.type == 1){ var _Pic = (Pic_Path+','+Pic).split(','), $Pic = '', now_class= '', Pic_Size = 'M', tempPic = '', $loop = true; if(location.pathname.indexOf("activities14-detail") > 0){ Pic_Size = 'S' } Back_Pic = (Back_Pic)?Back_Pic:Pic_Path _item.find("."+sets.picpathBox).html(` `); } // 詳細頁 else{ _this.item_num = 1; var _Pic = (Pic_Path+','+Pic).split(','), $_Pic1 = '', $_Pic2 = ''; for($i=0;$i<_Pic.length;$i++){ $now =($i==0)?now_class:''; if(_Pic[$i]){ $_Pic1 += '
'; $_Pic1 += ''; $_Pic1 += ''; if($i == 0 && saleCover){ $_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, navText: ['', ''], dots:false, 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(); } } }); if($(".quickShop-box").length > 0){ console.log("aaa") window.dispatchEvent(new Event('resize')) } $(".previewbox").html($_Pic2+''); $(".previewbox .picitem").eq(0).addClass(now_class);; } } // PC、平板 else{ // 列表 if(sets.type == 1){ var _Pic = (Pic_Path+','+Pic).split(','), $Pic = '', now_class= '', Pic_Size = 'M', tempPic = '', $loop = true; if(location.pathname.indexOf("activities14-detail") > 0){ Pic_Size = 'S' } Back_Pic = (Back_Pic)?Back_Pic:Pic_Path _item.find("."+sets.picpathBox).html(` `); } // 詳細頁 else{ _this.item_num = 5; var _Pic = (Pic_Path+','+Pic).split(','); $Pic = '', $Pic_Path = '', now_class= 'now', Pic_Size = 'S', $loop = false; console.log(saleCover) for($i=0;$i<_Pic.length;$i++){ if(_Pic[$i]){ // $Pic_Path += '
'; $Pic_Path += '
'; $Pic_Path += ''; $Pic_Path += ''; $Pic_Path += ''; if(($i == 0) && saleCover){ $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); _item.find("."+sets.picpathBox+" .item-box").eq(0).addClass(now_class); } // 設定輪播圖 for($i=0;$i<_Pic.length;$i++){ if(_Pic[$i]){ $Pic += '
'; } } if(Video && sets.type != 1){ $Pic += '
'; } _item.find("."+sets.picBox).html($Pic); _item.find("."+sets.picBox+" .picitem").eq(0).addClass(now_class); if($("."+sets.picBox+" .picitem ").length > 0){ _item.find("."+sets.picBox).trigger('destroy.owl.carousel') .owlCarousel({ dots: false, nav: true, navText: ['', ''], margin: 8, responsive:{ 0 : { items: 4 }, 1200 : { items: 3, mouseDrag: false, touchDrag: false, } } }); } if($(".quickShop-box").length > 0){ window.dispatchEvent(new Event('resize')) } // 影片預覽圖 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 = { // 類型 type : '1', // 1->列表,2->詳細頁,3->活動詳細頁,4.一頁式購物 // 商品內容 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 : 'pageSelect', // 分頁下拉選單的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 : Project_Country+'products/ajax/list/ajax_get_prod_list.php',// 搜尋ajax網址 cleanSearch : 'cleanButton' // 清除篩選Button之ID }; $.extend(sets, option); var _this = this; // 初始 this.init = function(){ // 篩選按鈕 $(document).on('click', "."+sets.searchBtn, function(){ // console.log('filter click') 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(); }); // 手機版排序 $('#'+sets.morderBox).on('click',function(){ $('#'+sets.morderBox).removeAttr('click'); $(this).attr('click','true'); _this.Search(); }) // 下拉篩選樣式 $("#"+sets.styleBox).on('change',function(){ _this.Search(); }); // 下拉篩選尺寸 $("#"+sets.sizeBox).on('change',function(){ _this.Search(); }); // 紅綠標 $("input[name='pair_flag']").click(function(){ _this.Search(1, 'no'); }); // 手機版行銷篩選 $("."+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); } } // // 篩選價格 // if($('.nstSlider').length) { // $('.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); // }, // }); // } // 清除篩選 $(document).on('click', "#"+sets.cleanSearch, function(){ if($(this).hasClass("subCleanButton")) { $(this).parents(".filter-item").find("."+sets.searchBtn).removeClass(sets.searchFocus); // 僅清除當前篩選按鈕 } else { $("."+sets.searchBtn).removeClass(sets.searchFocus); // 篩選按鈕歸零 } // if($('.nstSlider').length) { // $('.nstSlider').nstSlider('set_position',0,$('.nstSlider').attr("data-range_max")); // } $('#'+sets.morderBox).removeAttr('click'); _this.Search(); }); }; // 篩選功能 this.Search = function(pageCode,other){ // 置頂 if(other != "no"){ $(window).scrollTop(0); } var _str = "", _style = "&style=", _material= "&material=", _beg = "&beg=", _spec1 = "&spec1=", _spec2 = "&spec2=", pageCode = parseInt(pageCode) || 1, _limit = $('input[name="viewNumder"]:checked').val(), $page = ""; // 搜尋結果頁無限制筆數功能 所以預設值20 if(_limit == undefined){ _limit = 20; } $(".loading").show(); $("."+sets.searchFocus).each(function(){ switch($(this).attr(sets.searchType)){ case "style": _style += $(this).attr(sets.searchID) +','; break; case "material": _material += $(this).attr(sets.searchID) +','; break; case "beg": _beg += $(this).attr(sets.searchID) +','; break; case "spec1": _spec1 += $(this).attr(sets.searchID) +','; break; case "spec2": _spec2 += $(this).attr(sets.searchID) +','; break; } }); _str += _style+_material+_beg+_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){ // 手機版排序 if($('#'+sets.morderBox+'[click="true"]').data('val')){ _str += "&order="+$('#'+sets.morderBox+'[click="true"]').data('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; $.ajax({ url:sets.searchUrl, type:"POST", async:false, data:$("#"+sets.urlGetID).val()+_str, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, 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).show(); $("#"+sets.prevPage).attr("send",(pageCode-1)); }else{ $("#"+sets.prevPage).hide(); } // 手機版下一頁 if(pageCode < $Total){ $("#"+sets.nextPage).show(); $("#"+sets.nextPage).attr("send",(pageCode+1)); }else{ $("#"+sets.nextPage).hide(); } // 上一頁 if(pageCode > 1){ $page += `
  • ${_jsLang['上一頁']}
  • `; } // 第一頁 // 刪節號 if(pageCode > 5){ $page += `
  • 1
  • ...
  • `; } // 頁碼 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)?'in-focus':''; // $page += ''+$i+''; $page += `
  • ${$i}
  • `; } // 刪節號 //最後一頁 if(pageCode < $Total-4) { $page += `
  • ...
  • ${$Total}
  • `; } // 下一頁 if(pageCode <$Total){ // $page += '...'+_jsLang.下一頁+''; $page += `
  • ${_jsLang['下一頁']}
  • `; } if(other != 'no' || location.hash){ window.location.hash = pageCode; } var searchstr = $("#"+sets.urlGetID).val()+_str; if(sets.type == '2'){ window.history.replaceState({pageCode:pageCode},"test",'?'+searchstr.substr(1)); } $("."+sets.pageBox).html($page); $("#"+sets.pageShow).html('顯示第 '+((pageCode-1)*_limit+1)+' - '+((Total 筆 / 共 '+Total+' 筆'); // 下拉選單分頁 var $option = ""; for($i=1;$i<=$Total;$i++){ var $select = ""; if($i==pageCode)$select = "selected"; $option +=''; } $("."+sets.pageSelect).html($option); // $(window).Scroll_Data.destroy(); }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, }); } // $(window).scrollTop(0) } }); $(".loading").hide(); } }