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(),
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(){
var _item = $(this).parents("."+sets.itemBox),
SID = $(this).attr('sid') || 0;
if($(this).parents().eq(0).attr('class') == 'Add_Button1'){
var num = 1;
}else{
//airspace需求,不顯示數量欄位所以預設1
var num = _item.find("."+sets.amountBox).val() || 1;
}
if(SID == 0){
alert(_jsLang.請選擇尺寸或規格);
//errorbox();
}else if(num ==0){
alert(_jsLang.請選擇數量);
//errorbox();
}else{
var data = 'Act=Add&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(_jsLang.網路連線過慢網頁請重新整理);
},
success: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);
$("#Shop_Cart_Total>.num").html(d.Total);
$("#Show_Shopcart_Total").html(d.Total);
$("#RightTotal").html(d.Total);
if(d.Alert != 'OK'){
alert(d.Alert);
}
_this.setCartOther();
if(d.Alert == 'OK'){
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)
{
ga('ec:addProduct',d.GA[key]);
}
ga('ec:setAction','add');
ga('send','event','購物車','addtocart',d.GA_event);
}
if(d.GA_conversion && typeof gtag == 'function')
{
gtag('event', 'conversion', {'send_to':d.GA_conversion});
}
if(d.GA_conversion2 && typeof gtag == 'function')
{
gtag('event', 'conversion', {'send_to':d.GA_conversion2});
}
if(d.FBQ)
{
eval(d.FBQ)
}
if(d.GA4 && typeof gtag == 'function')
{
gtag("event","add_to_cart",d.GA4);
}
if(d.Criteo && typeof window.criteo_q == 'object')
{
var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";
window.criteo_q.push({event: "setAccount", account: d.Criteo_Account});
if(d.email)
{
window.criteo_q.push({event: "setEmail", email: d.email, hash_method: "sha256"});
}
window.criteo_q.push({event: "setSiteType", type: deviceType});
window.criteo_q.push({event: "setZipcode", zipcode: d.Zip});
window.criteo_q.push({event: "addToCart", item:d.Criteo});
}
if(sets.type != '4')
{
$.ajax({
url:"/my/ajax/ajax_get_cart.php",
type:"POST",
async:false,
cache:false,
data:{Type:'Prod',ID:SID,Act:'Add'},
success:function(d){
$(".shopping-cartbox").css('display','none');
$("#Header_Shopcart_Prod").html(d);
let offset = $(window).width() - ($(".shopbox.icon-wrapper").offset().left+$(".shopbox.icon-wrapper").outerWidth(false))
$('.one-cartbox').css({"right": -offset})
$("#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');
});
},3000);
}
})
}
}
}
});
}
});
//直接購物按鈕
$("."+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;
if(SID == 0){
alert(_jsLang.請選擇尺寸或規格);
//errorbox();
}else if(num ==0){
alert(_jsLang.請選擇數量);
//errorbox();
}else{
$.ajax({
url:sets.addUrl,
type:"POST",
cache:false,
async:false,
data:{Act:"Add", SID:SID, num:num, webcacheno:$('#webcacheno').val()},
dataType: 'json',
error:function(d){
alert(_jsLang.網路連線過慢網頁請重新整理);
},
success:function(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+")");
$("#Show_Shopcart_Total").html(d.Total);
if(d.Alert != 'OK'){
alert(d.Alert);
}
_this.setCartOther();
if(d.Alert == 'OK'){
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','購物車','addtocart',d.GA_event);
}
if(d.GA_conversion && typeof gtag == 'function')
{
gtag('event', 'conversion', {'send_to':d.GA_conversion});
}
if(d.GA_conversion2 && typeof gtag == 'function')
{
gtag('event', 'conversion', {'send_to':d.GA_conversion2});
}
if(d.FBQ)
{
eval(d.FBQ)
}
if(d.GA4 && typeof gtag == 'function')
{
gtag("event","add_to_cart",d.GA4);
}
if(d.Criteo && typeof window.criteo_q == 'object')
{
var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";
window.criteo_q.push({event: "setAccount", account: d.Criteo_Account});
if(d.email)
{
window.criteo_q.push({event: "setEmail", email: d.email, hash_method: "sha256"});
}
window.criteo_q.push({event: "setSiteType", type: deviceType});
window.criteo_q.push({event: "setZipcode", zipcode: d.Zip});
window.criteo_q.push({event: "addToCart", item:d.Criteo});
}
$.ajax({
url:"/my/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").html(d);
let offset = $(window).width() - ($(".shopbox.icon-wrapper").offset().left+$(".shopbox.icon-wrapper").outerWidth(false))
$('.one-cartbox').css({"right": -offset})
$("#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');
});
},3000);
}
})
}
window.location.href = '/my/'+$("#Website_Mall_ID").val()+'/shopcart/step1';
}
});
}
});
//貨到通知按鈕
$("."+sets.contBox).on("click","."+sets.informBtn,function(){
$("#"+sets.informID).val($(this).attr('SID'));
});
$("#"+sets.informSend).click(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(_jsLang.網路連線過慢網頁請重新整理);
},
success:function(d){
if(d=='OK'){
alert(_jsLang.您已成功新增一筆貨到通知當商品有貨時我們會儘快通知您);
}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(_jsLang.網路連線過慢網頁請重新整理);
},
success:function(d){
if(d.Msg =='OK'){
$("#Order_Next_Total>.num").html(d.Order_Next_Total);
if(type == 'add')
{
if(d.GA_event && typeof ga == 'function')
{
ga('send','event','瀏覽','addtowishlist',d.GA_event);
}
if(d.FBQ)
{
eval(d.FBQ)
}
if(d.GA4 && typeof gtag == 'function')
{
gtag("event","add_to_wishlist",d.GA4);
}
$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.請先登入會員);
window.location.href = '/my/'+$("#Website_Mall_ID").val()+'/member-login';
}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(_jsLang.網路連線過慢網頁請重新整理);
},
success:function(d){
if(d.Msg == 'OK'){
$("#Order_Next_Total>.num").html(d.Order_Next_Total);
if(type == 'add')
{
if(d.FBQ)
{
eval(d.FBQ)
}
if(d.GA4 && typeof gtag == 'function')
{
gtag("event","add_to_wishlist",d.GA4);
}
$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(_jsLang.網路連線過慢網頁請重新整理);
},
success:function(d){
if(d.Msg == 'OK')
{
$("#Order_Next_Total>.num").html(d.Order_Next_Total);
if(d.FBQ)
{
eval(d.FBQ)
}
if(d.GA4 && typeof gtag == 'function')
{
gtag("event","add_to_wishlist",d.GA4);
}
alert(_jsLang.新增成功);
}else if(d.Msg == 'NO_MEMBER'){
alert(_jsLang.請先登入會員);
}else{
alert(_jsLang.資料庫忙線中);
}
}
});
});
//圖片輪播
/*if($("."+sets.picBox+" .picitem ").length > 5){
$("."+sets.picBox).owlCarousel({
loop : false,
items : _this.item_num,
nav : true,
});
}*/
};
//設定內容
this.setFile= function(_item,$this,d){
//console.log(d)
_item.find("."+sets.loveBox).removeClass("fa-heart,fa-heart-o");
if(d.Return_Flag)_item.find('#Return_Text').html(d.Return_Flag);
if(d.ID)_item.find("."+sets.ordButton).attr("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_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.Avg_Price){
_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.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.Size_Button)_item.find("."+sets.sizeBox).html(d.Size_Button);
if(d.SP3_Sel)$this.nextAll("."+sets.sp3Select).eq(0).html(d.SP3_Sel);
if(d.Amount)
{
_item.find("."+sets.numBlock).eq(0).show();
_item.find("."+sets.amountBox).eq(0).html(d.Amount);
}else{
_item.find("."+sets.numBlock).eq(0).hide();
_item.find("."+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(sets.type == 2){
if(d.Amount2 > 0){
_item.find("."+sets.amountBox).val(1);
}else{
_item.find("."+sets.amountBox).val(0);
}
}else{
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){
$("."+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 = '/my/'+$("#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(sets.mode)
if(d.Community)$(".followbox").html(d.Community);
_item.find("."+sets.ActStrBox).html(d.Act_Str);
}
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);
if(!d.Size_Button && !d.Color){
_item.find("."+sets.PopupBtn1).addClass("no-spec")
}else{
_item.find("."+sets.PopupBtn1).removeClass("no-spec")
}
if(d.Stock > 0){
_item.find("."+sets.PopupBtn1).removeClass("out-stock")
}else{
_item.find("."+sets.PopupBtn1).addClass("out-stock")
}
if(d.Size_Button && d.Color && (d.Stock > 0)){
$(".selectPopupBox-mobile-btn").removeClass("disabled")
}else{
$(".selectPopupBox-mobile-btn").addClass("disabled")
}
_item.find("."+sets.PopupBtn2).html(d.ButtonPop2);
_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() <=960){
//列表
if(sets.type == 1){
_item.find("."+sets.picpathBox).css("background-image","url('/my/upload_files/fonlego-rwd/prodpic/"+Pic_Path+"')");
_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++){
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 += '
';
$Pic_Path += '';
}
_item.find("."+sets.picpathBox).html($Pic_Path);
_item.find("."+sets.picpathBox+" .zoonbox").eq(0).addClass(now_class);
$('.productImg').trigger("destroy.owl.carousel")
$('.productImg').owlCarousel({
loop : false,
items : 1,
nav : false,
slideTransition : 'linear',
}).on("changed.owl.carousel", function(){
$(".productImg").find("#Video").trigger("pause")
$(".video-icon").removeClass("video-playing")
})
//設定輪播圖
for($i=0;$i<_Pic.length;$i++){
if(_Pic[$i]){
$Pic += '';
}
}
if(Video && sets.type != 1){
$Pic += '';
$Pic += '';
}
_item.find("."+sets.picBox).html($Pic);
_item.find("."+sets.picBox+" .picitem").eq(0).addClass(now_class);
$("."+sets.picBox).trigger("specChangeSlider")
}
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 += '
';
$Pic_Path += '';
}
_item.parents(".productBox").find("."+sets.picpathBox).html($Pic_Path);
_item.parents(".productBox").find("."+sets.picpathBox+" .zoonbox").eq(0).addClass(now_class);
}
$(".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 = 'L',
$loop = true;
_item.find("."+sets.picpathBox).html('
');
_item.find(".productImg-1").css("background-image","url('/my/upload_files/fonlego-rwd/prodpic/"+_Pic[0]+"')");
}
//詳細頁
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++){
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 += '
';
$Pic_Path += '';
}
_item.find("."+sets.picpathBox).html($Pic_Path);
_item.find("."+sets.picpathBox+" .zoonbox").eq(0).addClass(now_class);
}
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 += '
';
$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')
{
//設定輪播圖
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);
$("."+sets.picBox).trigger("specChangeSlider")
/*if($("."+sets.picBox+" .picitem ").length > 5){
_item.find("."+sets.picBox).trigger('destroy.owl.carousel')
.owlCarousel({
loop : $loop,
items : _this.item_num,
nav : true,
});
}*/
//影片預覽圖
videoBox()
}
else
{
var x = 0;
//設定輪播圖
for($i=0;$i<_Pic.length;$i++){
now_class =($i==0)?'now':'';
if(_Pic[$i]){
$Pic += '
';
x++;
}
}
if(Video && sets.type != 1){
$Pic += '';
x++;
}
if(x > 1)
{
_item.parents(".productBox").find("."+sets.picBox).html($Pic);
}
}
}
}
};
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
searchBtnUrl: 'search_item_url', //搜尋按鈕的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 : '/my/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.searchBtnUrl, function(){
let $class = ($(this).hasClass(sets.searchFocus))?"":sets.searchFocus;
let btn = $("."+sets.searchBtnUrl+"[type="+$(this).attr("type")+"][search_id="+$(this).attr("search_id")+"]");
btn.removeClass(sets.searchFocus);
btn.addClass($class);
btn.find("."+sets.searchBtnUrl).removeClass(sets.searchFocus);
btn.find("."+sets.searchBtnUrl).addClass($class);
if($(window).width() > 1024)
{
_this.Search('','','2');
}
});
//篩選按鈕
$(document).on('click', "."+sets.searchBtn, 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);
if($(window).width() > 1024){
_this.Search();
}
});
//篩選確定
$(document).on("click",".filter-check-btn",function(){
_this.Search('','','2');
})
//每頁幾筆
$(document).on('change', 'select[name="viewNumder"]', function(){
_this.Search();
});
//排序
$(document).on('change', "#"+sets.orderBox, function(){
_this.Search('','','2');
});
//手機版排序
$(document).on('click', '#'+sets.morderBox,function(){
$('#'+sets.morderBox).removeAttr('click');
$(this).attr('click','true');
_this.Search();
})
//下拉篩選樣式
$(document).on('change', "#"+sets.styleBox,function(){
_this.Search();
});
//下拉篩選尺寸
$(document).on('change', "#"+sets.sizeBox,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);
}
}
$(document).on("priceSelectorChange", function(){
_this.Search()
})
//清除篩選
$(document).on('click', "#"+sets.cleanSearch,function(){
$("."+sets.searchBtn).removeClass(sets.searchFocus); //篩選按鈕歸零
$("."+sets.searchBtnUrl).removeClass(sets.searchFocus); //篩選按鈕歸零
if($('.nstSlider').length > 0){
$('.nstSlider').nstSlider('set_position',0,$('.nstSlider').attr("data-range_max"));
}
$('#'+sets.morderBox).removeAttr('click');
if($(window).width() > 1024)
{
_this.Search('','','2');
}
else
{
_this.Search();
}
});
};
//篩選功能
//searchType:1.ajax換頁2.頁面跳轉
this.Search = function(pageCode,other,searchType='1'){
//置頂
if(other != "no" && searchType != '2'){
$(window).scrollTop(0);
}
var _str = "",
_style = ",",
_material= ",",
_beg = ",",
_spec1 = ",",
_spec2 = ",",
pageCode = parseInt(pageCode) || 1,
_limit = $('select[name="viewNumder"]').val(),
$page = "",
_limit_param = $('select[name="viewNumder"]').val();
//搜尋結果頁無限制筆數功能 所以預設值25
var _limit_radio = $('input[name="viewNumder"]:checked').val();
if(_limit_param == undefined){
if(_limit_radio){
_limit = _limit_radio;
}else{
_limit = 60;
}
}else if (_limit_param == "scroll"){
_limit = 60
}
$(".loading").show();
$("."+sets.searchFocus).each(function(){
switch($(this).attr(sets.searchType)){
case "style":
if(_style.indexOf(','+$(this).attr(sets.searchID)+',') == -1)
{
_style += $(this).attr(sets.searchID) +',';
}
break;
case "material":
if(_material.indexOf(','+$(this).attr(sets.searchID)+',') == -1)
{
_material += $(this).attr(sets.searchID) +',';
}
break;
case "beg":
if(_beg.indexOf(','+$(this).attr(sets.searchID)+',') == -1)
{
_beg += $(this).attr(sets.searchID) +',';
}
break;
case "spec1":
if(_spec1.indexOf(','+$(this).attr(sets.searchID)+',') == -1)
{
_spec1 += $(this).attr(sets.searchID) +',';
}
break;
case "spec2":
if(_spec2.indexOf(','+$(this).attr(sets.searchID)+',') == -1)
{
_spec2 += $(this).attr(sets.searchID) +',';
}
break;
}
});
if(_style != ',')
{
_str += '&style='+_style.substring(1,_style.length - 1);
}
if(_material != ',')
{
_str += '&material='+_material.substring(1,_material.length - 1);
}
if(_beg != ',')
{
_str += '&beg='+_beg.substring(1,_beg.length - 1);
}
if(_spec1 != ',')
{
_str += '&spec1='+_spec1.substring(1,_spec1.length - 1);
}
if(_spec2 != ',')
{
_str += '&spec2='+_spec2.substring(1,_spec2.length - 1);
}
$("."+sets.moneyRange).each(function(){
_str += "&"+$(this).attr("id")+"="+$(this).text();
});
if($("#"+sets.orderBox).val()){
_str += "&order="+$("#"+sets.orderBox).val();
_order = "?order="+$("#"+sets.orderBox).val();
// window.history.replaceState({order: $("#"+sets.orderBox).val()}, 'order', location.pathname+_order+'#'+pageCode);
}
if($(window).width()<=1024){
//手機版排序
if($('#'+sets.morderBox+'[click="true"]').data('val')){
_str += "&order="+$('#'+sets.morderBox+'[click="true"]').data('val');
_order = "?order="+$('#'+sets.morderBox+'[click="true"]').data('val');
// window.history.replaceState({order: $("#"+sets.orderBox).val()}, 'order', location.pathname+_order+'#'+pageCode);
}
}
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;
if(searchType == '2')
{
var url = '?mode=search'+_str;
window.location.href = url;
return false;
}
$.ajax({
url:sets.searchUrl,
type:"POST",
async:false,
data:$("#"+sets.urlGetID).val()+_str,
error:function(d){
alert(_jsLang.網路連線過慢網頁請重新整理);
},
success:function(d){
//插入資料
$("#"+sets.contBox).html(d)
.find("."+sets.picBox)
.css("opacity", 0)
.owlCarousel({
loop : true,
items : 1,
nav : true,
dots : false,
slideTransition : 'linear',
});
setTimeout(function(){
$("#"+sets.contBox).find("."+sets.picBox).css("opacity", 1)
},2000)
//處理分頁
var Total = $("#Ajax_Total").val(),
$start= 0,
$end = 0,
$Total= Math.ceil(Total/_limit);
$('.filter-total').text(Total);
if(_limit_param != "scroll"){
$(window).Scroll_Data({
loading_distance : -1
})
//一般分頁
$("."+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 += '';
}
//第一頁
if(pageCode >=6){
$page += '1...';
}
if(pageCode <5){
var $max = ($Total-1>=6)?6:$Total-1;
$start = 1;
$end = 1+$max;
}else if(pageCode >=($Total-1)){
$min = ($Total-6>0)?6:$Total-1;
$start = $Total-$min;
$end = $Total;
}else{
$start = pageCode-4;
$end = pageCode+4;
}
for($i=$start;$i<=$end;$i++){
var $class = (pageCode == $i)?'now':'';
var $class2 = (((pageCode - 2) > $i) || ((pageCode + 2) < $i))?'page-mobile-hide':'';
$page += ''+$i+'';
}
//最後一頁
if(pageCode <=$Total-5){
$page += '...'+$Total+'';
}
//下一頁
if(pageCode <$Total){
$page += '';
}
window.location.hash = pageCode;
$("."+sets.pageBox).html($page);
$("#"+sets.pageShow).html('Showing '+((pageCode-1)*_limit+1)+'-'+((Total'+_jsLang.第X頁.replace("%u",$i)+'';
}
$("."+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,
});
}
url = '?mode=search'+_str;
window.history.replaceState({},'',url);
//cache愛心刷新
RefreshLove();
//$(window).scrollTop(0)
}
});
$(".loading").hide();
}
}