$(function(){ /*評論預覽商品圖*/ $(".pic-box").on("click",".pic-over",function(){ var _this = $(this), pic_src = _this.find("img").attr('src'); _this.parents(".pic-box").find(".click").removeClass("click"); _this.addClass("click"); _this.parents(".pic-box").find(".pic-viewer").addClass("click") .find('img').attr({src: pic_src}); }); $('.pic-box').on('click', '.close', function(event) { var _this = $(this).parents(".pic-box"); _this.find(".pic-viewer").removeClass("click"); _this.find(".click").removeClass("click"); }); }) $(function(){ var breadcrumb_on =0; $('#breadcrumb .inline-block').on('click',function(){ if(breadcrumb_on==0){ $(this).addClass('on'); breadcrumb_on++; }else{ $(this).removeClass('on'); breadcrumb_on=0; } }); $(".owl-carousel").owlCarousel({ loop : true, items : 1, nav : true, dots: false, navText: ['', ''], }); if($("#picSlides .picItem").length>1){ $("#picSlides").owlCarousel({ loop : true, items : 1, nav : true, autoplay:true, autoplayTimeout:5000, dots: false, navText: ['', ''], }); } var clickbutton=0; $('.filter-button,.filterbox .close').on('click',function(){ clickbutton++; if(clickbutton==1){ $('.filterbox').css({'top':'10%'}); } if(clickbutton==2){ $('.filterbox').css({'top':'-100%'}); clickbutton=0; } }); var owl6 = $(".user-list6 .orderSlide"); tempCarousel(owl6, 1) var owlSingle = $(".user-list-single .orderSlide"); tempCarousel(owlSingle, 1) var owlMultiple = $(".user-list-multi .orderSlide"); tempCarousel(owlMultiple, 2) }); // 商品大小格切換 ;(function($) { $('.switch-group').on('click', '.switch-item', function(e) { const targetClass = $(this).data('target') $(this).addClass('now').siblings('.switch-item').removeClass('now') $('#Main_Content').removeAttr('class').addClass('items-list combosBox').addClass(targetClass) }) })($) ;(function($) { var tempSwitchFlag = false //折疊展開已加購 $(document).on("click", ".temp-title", function(e){ let wrapper = $(this).parents(".activities-temp"), box = wrapper.find(".temp-box") if(wrapper.hasClass("in-open")){ wrapper.removeClass("in-open") }else{ wrapper.addClass("in-open") } }) //點選展開黑底關閉 $(document).on("click", ".activities-temp", function(e){ let wrapper = $(this) if((e.target == e.currentTarget) && wrapper.hasClass("in-open")){ wrapper.removeClass("in-open") } }) //更新活動商品暫存區 function setTempProduct(data){ let tempWrapper = $(".activities-temp"), tempProducts = tempWrapper.find(".temp-products"), tempTips = $(".temp-tips"), tempBox = $(".temp-box"), tempCartNum = $(".temp-cartnum"), tempAddpurchaseNum = $(".temp-addpurchasenum") if(data.tempProductBoxAlias){ tempProducts = tempWrapper.find(".temp-products[data-alias=" + data.tempProductBoxAlias + "]") } let currentPage = (tempProducts.data("owl.carousel")) ? tempProducts.data("owl.carousel")._current : 0 if(tempProducts.data('owl.carousel')){ tempProducts.data('owl.carousel').destroy() tempProducts.trigger("destroy.owl.carousel") } tempTips.html(data.tempTitle); tempCartNum.html(data.tempCartNum) tempProducts.html(data.tempProducts); if(data.tempAddpurchaseNum){ tempAddpurchaseNum.html(data.tempAddpurchaseNum) } if($(".user-list-multi .orderSlide").length > 0){ tempCarousel(tempProducts, 2) }else{ tempCarousel(tempProducts) } tempProducts.trigger('to.owl.carousel', [currentPage, 0, true]) // if(!tempWrapper.hasClass("in-open")){ // tempBox.slideDown() // if(tempSwitchFlag){ // tempWrapper.addClass("in-open") // /*setTimeout(function(){ // tempWrapper.removeClass("in-open") // tempSwitchFlag = false // }, 1500)*/ // } // } } //發送請求 function tempUpdate(data, callback = () => {}){ $.ajax({ url:$('.temp-box').data('url'), type:"POST", cache:false, async:true, data:data, dataType:'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.msg){ alert(d.msg) }else{ setTempProduct(d, true) if(callback && typeof(callback) == 'function'){ callback() } } } }); } //增加 $(document).on('click','.activities-cart-add',function(e){ let _this = $(this), id = _this.attr("sid"), productBox = _this.parents(".productBox"), num = productBox.find(".num-select").val(), pair = productBox.data('pair'), add_type = productBox.data('addtype'), group = productBox.data('group'), boxAlias = productBox.data('alias') if(id && num){ tempSwitchFlag = true tempUpdate( { type: 'add', Prod_Sell_ID: id, Amount: num, pair: pair, add_type: add_type, group: group }, function(){ if(boxAlias){ //多個輪播才會有data-alias smailPic(_this, $('.temp-products[data-alias=' + boxAlias + ']')) }else{ smailPic(_this, $('.temp-products')) } productBox.addClass("activities-selected") } ) }else{ if(!id){ alert(_jsLang.請選擇尺寸與規格); }else if(!num){ alert(_jsLang.請選擇數量); } return false; } }); //取消商品 $(document).on('click', ".activities-cart-cancel", function(){ let _this = $(this), id = _this.attr("sid"), productBox = _this.parents(".productBox"), num = $('.temp-item[data-sid='+id+']').find('.spec-input').val(), pair = productBox.data('pair'), add_type = productBox.data('addtype'), group = productBox.data('group') if(id){ //相當於全刪掉 tempSwitchFlag = false tempUpdate( { type:'del', Prod_Sell_ID:id, Amount:num, pair: pair, add_type: add_type, group: group } ) productBox.removeClass('activities-selected') } }) $(document).on('change', '.temp-item .spec-input', function(){ let amountBox = $(this) let item = amountBox.parents('.temp-item') let amount = Number(amountBox.val()) let max = amountBox.attr('max') let sid = item.data('sid') let type = 'add' let pair = item.data('pair') let add_type = item.data('addtype') let group = item.data('group') let old_val = Number(amountBox.data("old-val")) tempSwitchFlag = false if(amount <= 0){ //全刪掉 amount = old_val type = 'del' }else if(amount > old_val){ //增加 amount = amount - old_val if(max && (max < amount)){ amount = max - old_val } }else if(amount < old_val){ //減少 amount = old_val - amount type = 'del' }else{ return false } tempUpdate( { type: type, Prod_Sell_ID: sid, Amount: amount, pair: pair, add_type: add_type, group: group, }, function() { let specAmount = $(".activities-cart-btn[sid=" + sid + "]").siblings('.spec-amount') if(amount === Number(amountBox.val()) && type === 'del'){ console.log(`delete all`) //移除商品後 specAmount.find('.spec-input').val(1).parents(".activities-product").removeClass("activities-selected") } else if(type === 'del') { specAmount.find('.spec-input').val(Number(old_val - amount)) checkAmountDisabled(Number(old_val - amount), max, specAmount) } else if(type === 'add') { specAmount.find('.spec-input').val(Number(old_val + amount)) checkAmountDisabled(Number(old_val + amount), max, specAmount) } } ) }) $(document).on('click', '.temp-item .spec-minus, .temp-item .spec-plus, .temp-item .delete ', function(e){ let _this = $(this) let item = _this.parents('.temp-item') let amountBox = item.find('.spec-input') let amount = Number(amountBox.val()) let max = amountBox.attr('max') let sid = item.data('sid') let type = 'add' let pair = item.data('pair') let add_type = item.data('addtype') let group = item.data('group') let old_val = Number(amountBox.data("old-val")) let currentPage = 0 if(_this.hasClass("disabled")){ return false } tempSwitchFlag = false if($(e.currentTarget).hasClass('spec-plus')){ if(max && (max < (amount + 1))){ return false } amount = 1 }else if($(e.currentTarget).hasClass('spec-minus')){ amount = 1 type = 'del' }else { //全刪掉 amount = old_val type = 'del' } _this.addClass("disabled") tempUpdate( { type: type, Prod_Sell_ID: sid, Amount: amount, pair: pair, add_type: add_type, group: group, }, function() { let specAmount = $(".activities-cart-btn[sid=" + sid + "]").siblings('.spec-amount') if(amount === Number(amountBox.val()) && type === 'del'){ console.log(`delete all`) //移除商品後 specAmount.find('.spec-input').val(1).parents(".activities-product").removeClass("activities-selected") } else if(type === 'del') { specAmount.find('.spec-input').val(Number(old_val - amount)) checkAmountDisabled(Number(old_val - amount), max, specAmount) } else if(type === 'add') { specAmount.find('.spec-input').val(Number(old_val + amount)) checkAmountDisabled(Number(old_val + amount), max, specAmount) } } ) }) //加入購物車 $(document).on('click','.Add_Tmp_To_Cart, .Add_Tmp_To_Cart_In',function(e){ $.ajax({ url:Project_Country+'activities/ajax/ajax_add_to_cart.php', type:"POST", cache:false, async:true, data:{ Act_Type:$(this).attr("act_type"), ID:$(this).attr("prod_id") }, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Msg){ alert(d.Msg); }else{ switch(d.Status){ case "RET_SUCCESS": if(d.DataLayer){eval(d.DataLayer)} if($(e.currentTarget).hasClass("Add_Tmp_To_Cart_In")){ window.location.href = '/'+$("#Website_Mall_ID").val()+'/shopcart/step1'; }else{ alert(_jsLang.加入購物車成功); window.location.reload(); } break; case "RET_NO_MEMBER_NO": alert(_jsLang.欲購買紅利兌換商品請先登入會員並完成會員認證); break; case "RET_RBONUS_OUT": alert(_jsLang.紅利不足); break; case "RET_ERROR": alert(_jsLang.資料庫忙線中); break; case "RET_PROD_ERROR": alert(_jsLang.商品已下架); break; case "RET_NO_PROD": alert(_jsLang.請選擇商品); break; case "RET_STOCK_ERROR": alert(_jsLang.商品庫存不足); break; case "RET_LIMIT_ERROR": alert(_jsLang.數量超過限購量) break; case "RET_OVER_SIT_MAX": alert(_jsLang.數量超過定期購限購量); break; case "RET_PROD_IN_ONESHOPPAGE_ERROR": alert(_jsLang.此商品於一頁式購物推廣中+','+_jsLang.暫無法加入購物車); break; default: alert(_jsLang.資料庫忙線中); break; }; } } }); }); })($) //活動商品暫存區輪播 function tempCarousel(carousel , colNum = 1){ //colNum = 一排有幾個輪播區塊 let carouselParam = {} function resizeCarousel(){ if($(window).width() < 768){ carousel.trigger("destroy.owl.carousel") }else{ carousel.owlCarousel(carouselParam); } } switch(colNum){ case 1: carouselParam = { nav: true, dots: false, navText: ['', ''], margin: 15, responsive: { 0: { items: 2 }, 450: { items: 3 }, 1200 : { items: 4 }, }, } break; case 2: carouselParam = { nav: true, dots: false, navText: ['', ''], margin: 15, responsive: { 0: { items: 1 }, 576: { items: 2 }, 675: { items: 1 }, 768 : { items: 2 }, }, } break; } resizeCarousel() $(window).on("resize", resizeCarousel) } function smailCallback(event){ setTimeout(function(){ $('.hidebox').animate({'opacity':1}).removeClass('hidebox'); }, 300); } function smailPic(target, smailBox){ if(target.attr("class").indexOf('add_to_cart') !=-1){ return false; } const add_array = new Array() let img = target.parents('.productBox') let img_src = img.find('img').attr('src') let img_title = img.find('.title').html() let img_price = img.find('.insert-price').html() let img_spec = img.find('.color-select').find('option:selected').text(); let img_amount= img.find('.num-select').val() let img_act= img.find('.shopping-link').attr('act') let img_index = 0 let add_type = null let addHtml = '' add_array[0] = 0; $(".delete[add_type="+add_type+"]").each(function(){ add_array.push(parseInt($(this).attr("del_id"))); }) img_index = Math.max.apply(null,add_array); //避免A7點選加購時顯示兩次的BUG if(img_act == 'activities7-detail') { return false; } var smailBox_top = smailBox.offset().top, smailBox_left = smailBox.offset().left, smailBox_width = smailBox.width()/6, smailBox_height = smailBox.height()-20; var choseImg = target.parents('.productBox').find('.productImg'), Img_html = choseImg.clone().addClass('moveImg'), choseImg_top = choseImg.offset().top, choseImg_left = choseImg.offset().left, choseImg_width = choseImg.width(), choseImg_height = choseImg.height(); $('body').append(Img_html); $('.moveImg').css({'top':choseImg_top,'left':choseImg_left,'width':choseImg_width,'height':choseImg_height}) .animate({ 'top': smailBox_top, 'left': smailBox_left, 'width': smailBox_width, 'height': smailBox_height },350, function() { $(this).remove(); $(".activities-temp").removeClass("in-open") }); smailCallback(); }