//(function($){ //切換方案 $(document).on("click", ".plan-group .spec-button", function(){ let _this = $(this) let item = _this.parent(".spec-item") let priceSale = parseInt(_this.data("price-sale")).toLocaleString() let priceOrigin = parseInt(_this.data("price-origin")).toLocaleString() let amount = parseInt(_this.data("amount")) let sid = _this.data("sid") $(".highlight-slot").text(priceSale) $(".delete-slot").text(priceOrigin) $(".with-sid").data("sid", sid) $(".plan-group").find(".spec-item").removeClass("in-active") //更新自訂包數選項 let optionHtml = '' for(let i = 1; i< amount / 3 + 1; i++){ optionHtml += `` } $(".amount-input").html(optionHtml) updateNum(1) item.addClass("in-active") }) //切換配送方式 $(document).on("click", ".delivery-group .spec-button", function(){ let _this = $(this) let item = _this.parent(".spec-item") let deliveryType = _this.data("type") let amountWrapper = $(".amount-group").parents(".product-group") if(deliveryType == "custom"){ amountWrapper.addClass("theme-popup") amountWrapper.removeClass("hide") }else{ amountWrapper.addClass("hide") amountWrapper.removeClass("theme-popup") } $(".delivery-group").find(".spec-item").removeClass("in-active") item.addClass("in-active") }) //自訂數量範圍限制 $(document).on("change", ".amount-input", function(){ let _this = $(this) let val = parseInt(_this.val()) updateNum(val) }) //自訂首次配送彈窗 $(document).on("click", ".product-group .popup-closer, .product-group .popup-check", function(){ $(this).parents(".product-group").removeClass("theme-popup") }) //加入最愛 $(document).on('click','.love-btn',function(){ var _this = $(this), SID = _this.data('sid'), type = 'del'; if(_this.hasClass('theme-wishlist-o')){ type = 'add'; } $.ajax({ url:'/products/ajax/common/ajax_add_wish_list.php', type:"POST", cache:false, async:false, data:{Type:type,SID:SID}, dataType: 'json', error:function(res){ alert('網路連線過慢,網頁請重新整理'); }, success:function(res){ if(res.Msg =='OK'){ if(type == 'add'){ _this.removeClass("theme-wishlist-o"); _this.addClass("theme-wishlist"); alert(_jsLang.已加入喜愛清單); }else{ _this.removeClass("theme-wishlist"); _this.addClass("theme-wishlist-o"); } }else if(res.Msg == 'NO_MEMBER'){ alert(_jsLang.請先登入會員); }else{ alert(_jsLang.資料庫忙線中); } } }); }); //加入購物車 $(document).on("click", ".btn-submit", function(){ let _this = $(this) let sid = _this.data("sid") let act = _this.data("act") let num = $(".delivery-group .spec-item.in-active .spec-button").data("num") $.ajax({ url:"/products/ajax/detail/ajax_add_warehouse.php", type:"POST", data:{num:num,sid:sid,act:act}, dataType: 'json', error:function(res){ alert('網路連線過慢,網頁請重新整理'); }, success:function(res){ if(res.status == "OK"){ location.href = res.redirectUrl } else { alert(res.Msg); } } }) }) //更新input值和包數 function updateNum(val){ let total = parseInt($(".amount-input").val()) * 3 $(".amount-input").val(val) $(".amount-num").text(total) $(".spec-button-custom").data("num", total) } //})