max){
$(this).prev("."+sets.amountBox).val(max);
}else{
$(this).prev("."+sets.amountBox).val(amount+1);
$(this).prev().prev(".amount-minus").removeClass('in-disabled');
if(amount+2 > max){
$(this).addClass('in-disabled');
}
}
});
$("."+sets.contBox).on("click",".amount-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);
if(amount-1 == min){
$(this).addClass('in-disabled');
}
}else{
$(this).next("."+sets.amountBox).val(amount-1);
$(this).next().next(".amount-plus").removeClass('in-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;
//如果是特惠組 組合包 直接頁面跳轉
$.ajax({
url:"/ajax/ajax_chk_actprod.php",
type:"POST",
async:false,
cache:false,
data:{ID:SID},
success:function(d){
data = https://www.mamaway.com.tw/config/fun/prod/$.parseJSON(d);
if(data.status == true){
window.location.href = data.url[0];
}
}
});
if(data.status == false){
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.請選擇尺寸或規格);
}else if(num ==0){
alert(_jsLang.商品庫存不足);
}else{
//關閉跳窗
$('.modal-wrapper').removeClass('in-active');
$('body').removeClass('overflow-hidden');
var data = 'https://www.mamaway.com.tw/config/fun/prod/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('網路連線過慢,網頁請重新整理');
},
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);
//下方選單
$("#Shop_Cart_Total_Bottom").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','購物車','加入購物車');
}
if(d.GA_conversion && typeof gtag == 'function')
{
gtag('event', 'conversion', {'send_to':d.GA_conversion});
}
if(d.FBQ){eval(d.FBQ)}
//GA4
if(d.GA4 && typeof gtag == 'function')
{
for(var key in d.GA4)
{
gtag("event","add_to_cart",{
"items":d.GA4
});
}
}
window.sy_dataLayer = window.sy_dataLayer || [];
sy_dataLayer.push({
'product': [d.datalayer]
});
if(sets.type != '4')
{
$.ajax({
url:"/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);
$("#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:{SID:SID, num:num, webcacheno:$('#webcacheno').val()},
dataType: 'json',
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
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+")");
//下方選單
$("#Shop_Cart_Total_Bottom").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','購物車','加入購物車');
}
if(d.GA_conversion && typeof gtag == 'function')
{
gtag('event', 'conversion', {'send_to':d.GA_conversion});
}
if(d.FBQ){eval(d.FBQ)}
//GA4
if(d.GA4 && typeof gtag == 'function')
{
for(var key in d.GA4)
{
gtag("event","add_to_cart",{
"items":d.GA4
});
}
}
window.sy_dataLayer = window.sy_dataLayer || [];
sy_dataLayer.push({
'product': [d.datalayer]
});
console.log(d.datalayer);
$.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").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 = '/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('網路連線過慢,網頁請重新整理');
},
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 = $(this).attr('sid'),
type = 'del';
var productDetailPopup = $("#productDetailPopup_"+SID);
if($this.attr("class").match('theme-wishlist-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(type == 'add'){
if(d.FBQ){eval(d.FBQ)}
if(d.GA4 && typeof gtag == 'function')
{
gtag("event","add_to_wishlist",{
"items":d.GA4
});
}
$this.removeClass("theme-wishlist-o");
$this.addClass("theme-wishlist");
productDetailPopup.find("."+sets.loveButton).removeClass("theme-wishlist-o");
productDetailPopup.find("."+sets.loveButton).addClass("theme-wishlist");
alert(_jsLang.已加入喜愛清單);
}else{
$this.removeClass("theme-wishlist");
$this.addClass("theme-wishlist-o");
productDetailPopup.find("."+sets.loveButton).removeClass("theme-wishlist");
productDetailPopup.find("."+sets.loveButton).addClass("theme-wishlist-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.FBQ){eval(d.FBQ)}
if(d.GA4 && typeof gtag == 'function')
{
gtag("event","add_to_wishlist",{
"items":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){
_item.find("."+sets.loveBox).removeClass("fa-heart,fa-heart-o");
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.Prod_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){
if(sets.type == 5){
_item.find("."+sets.price1Box).html(d.Price1WithCurrency);
}else{
_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.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)_item.find("."+sets.sizeBox).html(d.Size);
if(d.Size_Sel&&d.Size_Sel!='')_item.find("."+sets.sizeSelect).html(d.Size_Sel);
if(d.Size_Name&&d.Size_Name!='')_item.find("."+sets.sizeName).html(d.Size_Name);
if(d.Sp3)_item.find("."+sets.sp3Box).html(d.Sp3);
if(d.SP3_Name)_item.find("."+sets.sp3Name).html(d.SP3_Name);
if(d.SP3_Sel)$this.nextAll("."+sets.sp3Select).eq(0).html(d.SP3_Sel);
if(d.Amount2){
_item.find("."+sets.numBlock).show();
_item.find("."+sets.amountBox).attr('max',d.Amount2);
}else if(d.Amount2 == 0){
_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 = '/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);
}
if(d.Prod_Multi)$(".Prod_Multi").html(d.Prod_Multi);
if(d.Amount2 == '0'){
$("."+sets.contBox).find("."+sets.numBox).hide();
}else{
$("."+sets.contBox).find("."+sets.numBox).show();
}
if(d.ButtonMobile2){
$(".mobile_box").find(".btn-full").remove();
$(".mobile_box").find(".amount-group").append(d.ButtonMobile2);
}
if(sets.type == 1 || sets.type == 2 || sets.type == 6){
if(d.Amount2){
$("."+sets.itemBox).find(".amount-minus").addClass('in-disabled');
$("."+sets.itemBox).find(".amount-plus").removeClass('in-disabled');
$("."+sets.amountBox).val(1);
$("."+sets.amountBox).attr('max',d.Amount2);
}else if(d.Amount2 == 0){
$("."+sets.itemBox).find(".amount-minus").addClass('in-disabled');
$("."+sets.itemBox).find(".amount-plus").addClass('in-disabled');
$("."+sets.amountBox).val(0);
$("."+sets.amountBox).attr('max','0');
}
}
if(sets.type == 1 || sets.type == 6){
$('#quickShopModal').find('.shop_btn').replaceWith(d.Button[2]);
}else if(sets.type == 2){
$("."+sets.itemBox).find('.shop_btn').replaceWith(d.Button[3]);
}
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);
_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(sets.type == '5'){
quickshopSlide()
let _Pic = (Pic_Path+','+Pic).split(',')
let $Pic = ''
let $loop = true
let tmp = '';
for($i=0;$i<_Pic.length;$i++){
if(_Pic[$i]) {
tmp += '
';
}
}
_item.find("."+sets.picBox).html(tmp);
quickshopSlide();
}
//手機
else if($(window).width() <=768){
//列表
if(sets.type == 1){
var _Pic = (Pic_Path+','+Pic).split(','),
$Pic = '',
$loop = true;
_item.find("."+sets.picpathBox).css("background-image","url('Project_Country/upload_files/fonlego-rwd/prodpic/"+Pic_Path+"')");
_item.find("."+sets.picpathBox).html('
');
if(sets.type == '1')
{
//重新設定輪播圖
$pre_this = $("."+sets.itemBox+" .productPreview");
for($i=0;$i<_Pic.length;$i++){
if(_Pic[$i]){
$Pic += '
';
}
}
$pre_this.after('');
$pre_this.remove();
quickshopSlide();
}
}
//大禮包
else if(sets.type == 6)
{
_item.find("."+sets.picpathBox).find('img').attr('src','Project_Country/upload_files/fonlego-rwd/prodpic/M_'+Pic_Path);
}
//詳細頁
else{
if(sets.type != '4')
{
_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 += '
';
$_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();
}
}
});
}
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++){
var $now =($i==0)?now_class:'';
if(_Pic[$i]){
$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);
}
$(".previewbox").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('Project_Country/upload_files/fonlego-rwd/prodpic/"+_Pic[0]+"')");
_item.find("."+sets.picpathBox).html('
');
}
//大禮包
else if(sets.type == 6)
{
_item.find("."+sets.picpathBox).find('img').attr('src','Project_Country/upload_files/fonlego-rwd/prodpic/M_'+Pic_Path);
}
//詳細頁
else{
if(sets.type != '4')
{
_item.find("."+sets.picpathBox+" .zoonbox").eq(0).find(".picbox img").attr("src", "Project_Country/upload_files/fonlego-rwd/prodpic/D_"+Pic_Path);
_item.find("."+sets.picpathBox+" .zoonbox").eq(0).find(".preview").css("background-image", "url('Project_Country/upload_files/fonlego-rwd/prodpic/D_"+Pic_Path+"')");
_item.find("."+sets.picpathBox+" .zoonbox").eq(0).attr("big-pic", Pic_Path);
_item.find("."+sets.picpathBox+" .zoonbox").removeClass('now');
_item.find("."+sets.picpathBox+" .zoonbox").eq(0).addClass('now');
_item.find(".productView .moreview .picitem img").eq(0).attr("src", "Project_Country/upload_files/fonlego-rwd/prodpic/S_"+Pic_Path);
_item.find(".productView .moreview .picitem").removeClass('now');
_item.find(".productView .moreview .picitem").eq(0).addClass('now');
var _Pic = (Pic_Path+','+Pic).split(',');
$Pic = '',
$Pic_Path = '',
now_class= 'now';
if(_Pic[0]){
$now = now_class;
$Pic += '';
$Pic += '
';
$Pic += '

';
$Pic += '
';
$Pic += '
';
$Pic += '
';
$Pic_Path += '';
}
if(Video){
$Pic += '';
$Pic += '';
$Pic += '
';
$Pic_Path += '
';
}
for($i=1;$i<_Pic.length;$i++){
var $now =($i==0)?now_class:'';
if(_Pic[$i]){
$now = ($i==0)?now_class:"";
$Pic += '';
$Pic += '
';
$Pic += '

';
$Pic += '
';
$Pic += '
';
$Pic += '
';
$Pic_Path += '';
}
}
_item.find("."+sets.picpathBox).html($Pic);
_item.find(".productView .moreview").html($Pic_Path).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++){
var $now =($i==0)?now_class:'';
if(_Pic[$i]){
$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);
}
}
if(sets.type == '1')
{
//重新設定輪播圖
$pre_this = $("."+sets.itemBox+" .productPreview");
for($i=0;$i<_Pic.length;$i++){
if(_Pic[$i]){
$Pic += '
';
}
}
$pre_this.after('');
$pre_this.remove();
quickshopSlide();
}
else if(sets.type == '6')
{
}
else if(sets.type != '4')
{
//設定輪播圖
for($i=0;$i<_Pic.length;$i++){
now_class =($i==0)?'active':'';
if(_Pic[$i]){
// $Pic += '
';
$Pic += '';
}
}
if(Video && sets.type != 1){
$Pic += '
';
}
_item.find("."+sets.picBox).find(".owl-stage").html($Pic);
if($("."+sets.picBox+" .picitem ").length > 5){
_item.find("."+sets.picBox).trigger('destroy.owl.carousel')
.owlCarousel({
loop : $loop,
items : _this.item_num,
nav : true,
});
}
//影片預覽圖
if(document.getElementById("Video")){
document.getElementById("Video").oncanplay=function(){
var video = $("#Video").get(0);
var canvas = document.getElementById("video_review");
if(location.pathname.match("product-detail")){
//商品詳細頁點選顏色或尺寸
canvas.getContext('2d').drawImage(video, 0, 0, 100, 139);
}else{
canvas.getContext('2d').drawImage(video, 0, 0, 66, 66);
}
};
}
}
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);
}
}
}
}
// 快速購物輪播
function quickshopSlide() {
const slideTarget = $('#quickShopModal .quickshop-wrapper .productPreview')
if(slideTarget.children().length > 1) {
slideTarget.owlCarousel({
loop: true,
items: 1,
navText: ['',''],
dots: false,
autoplay: true,
animateOut: 'fadeOut',
autoplayTimeout: 6000,
autoplayHoverPause: true,
responsive: {
0: {
nav : false,
},
661: {
nav : true,
},
},
})
}
}
};
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
searchFilter : 'search_filter', //搜尋按鈕(有篩選)的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
submitSearch : 'submitSearch', //確定篩選Button之ID
otherParam :'',
};
$.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();
});
//確定篩選按鈕
$("#"+sets.submitSearch).on('click',function(){
$('.'+sets.searchBtn).each(function(){
if($(this).hasClass(sets.searchFocus)){
$(this).addClass(sets.searchFilter);
}else{
$(this).removeClass(sets.searchFilter);
}
});
_this.Search();
});
//關閉篩選視窗(Modal)
$('.modal-wrapper').on('click', function(e) {
if($(this).attr('id') == 'filterModal'){
if(e.target === e.currentTarget || e.target === $(this).find('.closer')[0]) {
$('.'+sets.searchBtn).each(function(){
if($(this).hasClass(sets.searchFilter)){
$(this).addClass(sets.searchFocus);
}else{
$(this).removeClass(sets.searchFocus);
}
});
}
}
})
//每頁幾筆
$('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();
});
//手機版行銷篩選
$("."+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,$('.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 = "";
//搜尋結果頁無限制筆數功能 所以預設值25
if(_limit == undefined){
_limit = 24;
}
$(".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;
_str += sets.otherParam;
$.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($Total > 5){
if(pageCode <= 3){
$start = 1;
($Total < 4) ? $end=$Total : $end=4;
}else if(($Total - pageCode) < 3){
$start = $Total - 3;
$end = $Total;
}else{
$start = pageCode - 1;
$end = pageCode + 1;
}
//第一頁
if(pageCode >3){
$page += '1';
$page += '...';
}
for($i=$start;$i<=$end;$i++){
var $class = (pageCode == $i)?' in-focus':'';
$page += ''+$i+'';
}
//最後一頁
if(($Total - pageCode) >= 3){
$page += '...';
$page += ''+$Total+'';
}
}else{
for($i=1;$i<=$Total;$i++){
var $class = (pageCode == $i)?' in-focus':'';
$page += ''+$i+'';
}
}
//下一頁
if(pageCode <$Total){
$page += ''+_jsLang.下一頁+'';
}
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,
});
}
//$(window).scrollTop(0)
_this.happenAfterSearch();
}
});
$(".loading").hide();
}
this.happenAfterSearch = function(){
}
}