$(function() {
$("#Main_Form").fromsAuth({
type:'NONE',
});
$("#Member_Form").fromsAuth();
var header_height = 100;
if($(window).width() <= 480){
header_height = 70;
}
$('.product-link').on('click',function(){
if($('#productbox').length!=0){
$("html,body").animate({scrollTop: $('#productbox').offset().top - header_height},800);
}else{
$("html,body").animate({scrollTop: $('#productlist').offset().top - header_height},800);
}
});
$('.article-link').on('click',function(){
$("html,body").animate({scrollTop: $('#articlebox').offset().top - header_height},800);
});
$('.shopcart-link').on('click',function(){
$("html,body").animate({scrollTop: $('#s1').offset().top - header_height},800);
});
$("#Main_Content").on('click', '#step2', function() {
var sh = $("#s2 .section-wrapper").height() + 100;
$("html,body").animate({scrollTop: $('#s2').offset().top - sh}, 800);
});
$("#Main_Content").on('click', '#step3', function() {
var sh2 = $("#s3").height();
if($(window).width() <= 480){
$("html,body").animate({scrollTop: $('#s3').offset().top - 70}, 800);
} else {
$("html,body").animate({scrollTop: $('#s3').offset().top}, 800);
}
});
$("#Main_Content").on('click','.Content_Button',function(){
$('.popupbg').addClass('is-show');
$('.popupbg').html($("#Content"+$(this).attr("sid")).html());
});
if($(window).width()>769){
$("#Main_Content").on('click','#productlistbox .Pop_Prod_Data',function(){
if(!$(this).is('.button-cant')){
var $class = $(this).attr("class"),
$id = $(this).attr("sid"),
type = '1';
if($class == 'button-add')
{
type = '2';
}
$('.popupbg').addClass('is-show');
$('.popupbg').attr("type",type);
$('.popupbg').html($("#Data-"+$id).html());
//====================================
// 商品小圖輪播
//====================================
$(".moreview-onepage").owlCarousel({
items: 3,
margin: 10,
nav:false,
dots:false
}).on('mouseleave','.owl-stage-outer', function() {
var box = $(this).parents(".popupbg");
box.find(".productView .zoonbox").removeAttr('style');
}).on('click','.owl-item', function() {
var now = $(this).index(),
box = $(this).parents(".popupbg");
box.find(".productView .owl-item").not(this).find('.picitem').removeClass('now');
$(this).find('.picitem').addClass('now');
box.find(".productView .zoonbox").removeClass('now').eq(now).addClass('now');
}).on('mouseenter','.owl-item', function() {
var now = $(this).index(),
box = $(this).parents(".popupbg");
box.find(".productView .zoonbox").css('display','none').eq(now).css('display','flex');
});
}
});
}
if($(window).width()<769){
$("#Main_Content").on('click','#productlistbox .Pop_Prod_Data',function(){
if(!$(this).is('.button-cant')){
var $class = $(this).attr("class"),
$id = $(this).attr("sid"),
type = '1';
if($class == 'button-add')
{
type = '2';
}
$('.popupbg').addClass('is-show');
$('.popupbg').attr("type",type);
$('.popupbg').html($("#Prod_Data > #Data-"+$id).html());
$('.popupbg').find(".productView .productImg").owlCarousel({
loop:false,
responsive:{
0:{
items : 1,
},
768:{
items : 1,
}
},
nav : true,
navText : ['','']
});
$('.moreview').remove();
}
});
}
$("#Main_Content").on('click','.informButton',function(){
$("#informID").val($(this).attr("sid"));
$('.emailPopup').css('display','flex');
});
$("#Main_Content").on('click','.emailPopup .close',function(){
$('.emailPopup').css('display','none');
});
$("#Main_Content").on('click','.popupbg .close',function(){
$('.popupbg').removeClass('is-show');
$('.popupbg').removeAttr('style');
});
$("#Main_Content").on('click','.Content_Title',function(){
var num = $(this).attr("num");
$(this).parents(".popupbg").find(".Content_Title").css({"color":"#909090","border-top":"1px solid #e2e2e2"});
$(this).css({"color":"#000000","border-top":"1px solid #2f2f2f"});
$(this).parents(".popupbg").find(".Box1,.Box2,.Box3").hide();
$(this).parents(".popupbg").find(".Box"+num).show();
});
$("#Main_Content").on('click','.loginButton',function(){
$('.memberPopup').css('display','flex');
});
$("#Main_Content").on('click','.memberPopup .close',function(){
$('.memberPopup').css('display','none');
});
$("#Change_Pic").click(function(e){
$("#Checkspan").load('/ajax/ajax_get_check_pic.php',{change:1});
});
$("#Main_Content").on('focusin','.input-text',function(){
$(this).next('.text-title').addClass('now');
});
$("#Main_Content").on('focusout','.input-text',function(){
if($(this).val()==''){
$(this).next('.text-title').removeClass('now');
}
});
$('.gotop').on('click',function(){
$("html,body").animate({scrollTop: 0},800);
});
// $('.header-wrapper').on('click', '.menu-b', function(event) {
// $(this).removeClass('menu-b').addClass('menu-b close');
// $(this).next('.header-aside').addClass('open');
// });
// $('.header-wrapper').on('click', '.close', function(event) {
// $(this).removeClass('close').addClass('menu-b');
// $(this).next('.header-aside').removeClass('open');
// });
var _window = $(window);
_window.on('scroll', function(event) {
var scrollTop = _window.scrollTop();
if(scrollTop>0){
$(".gotop").css("opacity","1");
$("body").addClass('is-sticky');
// _body.css('padding-top',body_padding_s+'px');
}else{
$(".gotop").css("opacity","0");
$("body").removeClass('is-sticky');
// _body.css('padding-top',body_padding+'px');
}
});
//時間倒數
var num = parseInt($("#CountDown_Box").attr("second"),10),
_this = $("#CountDown_Box");
if(num > 0) {
setInterval(function() {
num--;
if(num <= 0) {
window.location.reload();
}
var day = Math.floor(num/(3600*24)),
hour = Math.floor((num - (day*3600*24) )/3600),
min = Math.floor((num - (day*3600*24) - (hour*3600) )/60 ),
second = num - (day*3600*24) - (hour*3600) - (min*60),
pad = '00';
if(day > 0) {
_this.find(".timer").eq(0).html(day);
_this.find(".timer").eq(1).html(pad.substring(hour.toString().length)+hour);
_this.find(".timer").eq(2).html(pad.substring(min.toString().length)+min);
_this.find(".timer").eq(3).html(pad.substring(second.toString().length)+second);
} else {
_this.find(".Date_Box").remove();
_this.find(".timerbox").html(_this.find(".timerbox").html().replace('天',''));
_this.find(".timer").eq(0).html(pad.substring(hour.toString().length)+hour);
_this.find(".timer").eq(1).html(pad.substring(min.toString().length)+min);
_this.find(".timer").eq(2).html(pad.substring(second.toString().length)+second);
}
},1000);
}
$("#Main_Content").on("click",".table-button",function(){
$(".table-button").removeClass('now');
$(this).addClass('now');
var type=$(this).data('type');
$(".tableBox").hide();
$("#Box-"+type).show();
$(".wear_report").show();
});
$("#Main_Content").on("click",".table-button1",function(){
$(".table-button1").removeClass('now');
$(this).addClass('now');
var type=$(this).data('type');
$(".tableBox1").hide();
$("#Box1-"+type).show();
$(".wear_report").show();
});
});
//刪除購物車
$("#Main_Content").on('click','.product-del',function() {
$.ajax({
url:"/quickshop/ajax/ajax_del_cart.php",
type:"POST",
cache:false,
dataType: 'json',
data:{ID:$(this).attr("sid"), Page_Shop_ID:$("#Page_Shop_ID").val()},
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success:function(d){
switch(d.Status){
case "RET_SUCCESS":
if(d.GA4 && typeof gtag == 'function')
{
for(var key in d.GA4)
{
gtag("event","remove_from_cart",{
"items":d.GA4
});
}
}
updatePage('&action=del');
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;
default:
alert(_jsLang.資料庫忙線中);
break;
};
}
});
setTimeout(function () {
$('.emptyCartPrompt').fadeOut()
}, 5000)
});
//修改數量
$("#Main_Content").on('click','.Prod_Plus',function(){
var Amount = parseInt($(this).prev(".Prod_Amount").val())+1,
Stock = parseInt($(this).attr("max"));
if(Amount > 100 || Amount > Stock)
{
return false;
}
$(this).prev(".Prod_Amount").val(Amount).change();
});
$("#Main_Content").on('click','.Prod_Minus',function(){
var Amount = parseInt($(this).next(".Prod_Amount").val())-1;
if(Amount < 1)
{
return false;
}
$(this).next(".Prod_Amount").val(Amount).change();
});
$("#Main_Content").on('change','.Prod_Amount',function(){
var ID = $(this).parents(".listbox-item").find(".product-del").attr("sid"),
Amount = $(this).val();
if(Amount > 100)
{
Amount = 100;
}
if(Amount < 1)
{
Amount = 1;
}
$.ajax({
url:"/quickshop/ajax/ajax_change_cart.php",
type:"POST",
cache:false,
data:{ID:ID,Amount:Amount,Page_Shop_ID:$("#Page_Shop_ID").val()},
error:function(d){
alert('網路連線過慢,網頁請重新整理');
},
success:function(d){
var d = d.trim();
switch(d){
case "RET_SUCCESS":
updatePage();
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;
default:
alert(_jsLang.資料庫忙線中);
break;
};
}
});
});
//活動字串
$("#Main_Content").on('click','#Act_Str_Button',function(){
var str = $("#Act_Str_Input").val();
if(str)
{
updatePage('&Act_Str='+str);
}
});
$("#Main_Content").on('click','#Act_Str_Cancel',function(){
updatePage('&Act_Str=Cancel_Act_Str');
});
//切換配送國家
$("#Main_Content").on('change','#Send_Country',function(){
updatePage('&Country='+$(this).val());
});
//切換配送方式
$("#Main_Content").on('click','input[name="Ship_Type"]',function(){
if(typeof gtag == 'function')
{
gtag("event","add_shipping_info",{
"shipping_tier":$(this).data('name')
});
}
updatePage('&Ship_Type='+$(this).val());
});
//切換付款方式
$("#Main_Content").on('click','input[name="Pay_Type"]',function(){
if(typeof gtag == 'function')
{
gtag("event","add_payment_info",{
"payment_type":$(this).data('name')
});
}
updatePage('&Pay_Type='+$(this).val());
});
//切換配送城市
$("#Main_Content").on('change','#Send_City',function(){
updatePage('&City='+$(this).val());
});
//切換配送地區
$("#Main_Content").on('change','#Send_Area',function(){
updatePage('&Area='+$(this).val());
});
//切換定期定額扣款天數
$("#Main_Content").on('change','#Sit_Frequency',function(){
updatePage('&Sit_Frequency='+$(this).val());
});
//切換定期定額扣款次數
$("#Main_Content").on('change','#Sit_Period',function(){
updatePage('&Sit_Period='+$(this).val());
});
//選擇門市
$("#Main_Content").on("click","#Choose_Store", function(){
var $return = encodeURIComponent('quickshop/'+$("#Page_Shop_IDAs").val()+'/#shopcartbox'),
$type = $(this).attr("type"),
$coll = $(this).attr("coll");
updatePage('&save=1');
setTimeout(function(){
window.location.href = '/shopcart/e_returns/emap-p.php?url='+$return+'&type='+$type+'&coll='+$coll+'&shop_id='+$("#Page_Shop_ID").val();
},500);
});
//送出訂單
$("#Main_Content").on('click','#Form_Submit',function(){
let Fullfill_Num = $("input[name='Fullfill_Num']").val()
let Fullfill_Current = $("input[name='Fullfill_Current']").val()
if(Fullfill_Num > Fullfill_Current){
alert("需要購買" + Fullfill_Num + "件商品,目前已挑選" + Fullfill_Current + "件")
}else{
$("#Main_Form").submit();
}
// $('.cart-complete').addClass('in-active');// 開啟結帳完成視窗
// $('body').addClass('in-sticky');// 視窗鎖定
});
// 關閉結帳完成視窗
$('.js-close').on('click', function(e) {
$('.cart-complete').removeClass('in-active');
$('body').removeClass('in-sticky');
})
//姓名、電話、Email、地址、備註
$("#Main_Content").on('change','#Send_Name,#Send_Cellphone,#Email,#Send_Address,#Send_Memo,#Buy_Login_Password,#Buy_Login_Password2',function(){
updatePage('&save=1');
});
//自動加入會員、收貨時間
$("#Main_Content").on('click',"#Auto_Add,input[name='Send_Time']",function(){
updatePage('&save=1');
});
//切換載具類型
$("#Main_Content").on('change',"#CarrierType",function(){
updatePage();
});
//切換發票類型
$("#Main_Content").on('click',"input[name='Invo_Mod']",function(){
updatePage();
});
//同收件地址
$("#Main_Content").on('click','#Invo_Same_Button',function(){
if($(this).prop("checked"))
{
var same = '1';
$("#Invo_Address_Box").hide();
$("#Invo_Address").attr("fun","");
}
else
{
var same = '2';
$("#Invo_Address_Box").show();
$("#Invo_Address").attr("fun","checkNull");
}
updatePage('&Invo_Same='+same+'&save=1');
$("input[name='Invo_Same']").val(same);
});
$("#Main_Content").on('click','.title-big',function(){
$(this).parent('section').toggleClass("open",500);
});
$("#Main_Content").on('click','.shopcart-link',function(){
$('section').addClass("open",500);
});
$('body').on('click','.arrow .title-big', function(event) {
// console.log($('.is-nowStep'));
if(!$(this).is('.open')){
$('section').not(this).removeClass('open');
$(this).parent('section').addClass('open');
updatePage('&Step='+$(this).parent('section').attr("id").substr(1,1)+'&save=1');
}
});
$("#Main_Content").on('click','#step2',function(){
$('#s2').addClass("open",500);
$('#s2').addClass("arrow",500);
//$(this).parents('.section-wrapper').parent('section').removeClass('open');
updatePage('&Step=2&save=1&MoneyShow=1');
});
$("#Main_Content").on('click','#step3',function(){
$('#s3').addClass("open",500);
$('#s3').addClass("arrow",500);
//$(this).parents('section').removeClass('open');
updatePage('&Step=3&save=1');
});
//門市國家
$("#Main_Content").on('change','#store_country',function(){
var country = $(this).val();
if(country <= 0)
{
country = 'none';
}
updatePage('&store_country='+country);
});
//門市區域
$("#Main_Content").on('change','#store_area',function(){
var area = $(this).val();
if(area <= 0)
{
area = 'none';
}
updatePage('&store_area='+area);
});
//門市搜尋
$("#Main_Content").on('click','#searchBtn',function(){
updatePage('&store_search=1');
});
//門市按鈕
$("#Main_Content").on('click','.storeBtn',function(){
if($(this).hasClass("active"))
{
return false;
}
updatePage('&Store_ID='+$(this).attr("sid"));
});
//推薦門市國家
$("#Main_Content").on('change','#Recommender_country',function(){
var rec_country = $(this).val();
if(rec_country <= 0)
{
rec_country = 'none';
}
updatePage('&Recommender_country='+rec_country);
});
//推薦門市區域
$("#Main_Content").on('change','#Recommender_area',function(){
var rec_area = $(this).val();
if(rec_area <= 0)
{
rec_area = 'none';
}
updatePage('&Recommender_area='+rec_area);
});
//推薦門市
$("#Main_Content").on('change','#Recommender_Store',function(){
var rec_store = $(this).val();
if(rec_store <= 0)
{
rec_store = 'none';
}
updatePage('&Recommender_Store='+rec_store);
});
// 按下我要結帳後出現底部浮動
$("#Main_Content").on('click', '#step2', function() {
$('.moneyPrompt').css('display', 'flex').hide().fadeIn()
});
//使用禮券
$("#Main_Content").on("click",".gift-sent,.gift-jump",function(){
var usable = '';
$(".Choose_Usable:checked").each(function(){
usable += $(this).val()+',';
});
updatePage('&Usable='+usable);
});
//取消使用禮券
$("#Main_Content").on('click','.Usable_Cancel',function(){
updatePage('&Cancel_Usable='+$(this).attr("sid"));
});
function updatePage(data) {
//取得一般配送資料
var send = '';
var data = data || '';
//寄送資料
$("#Send_Name,#Send_Cellphone,#Email,#Send_Address,input[name='Send_Time']:checked,#Send_Memo,#Del_Type,#Auto_Add:checked,#Buy_Login_Password,#Buy_Login_Password2").each(function(){
send += '&'+$(this).attr("name")+'='+$(this).val();
});
//發票資料
$("input[name='Invo_Mod']:checked,#CarrierType,#CarrierId1,#CarrierId2,#NPOBAN,#Invo_Title,#Invo_No,#Invo_Address").each(function(){
send += '&'+$(this).attr("name")+'='+$(this).val();
});
var $data = 'type=update'+data+send+'&Page_Shop_ID='+$("#Page_Shop_ID").val();
$.ajax({
url:"/quickshop/ajax/ajax_get_cart.php",
type:"POST",
async: true,
data:$data,
cache:false,
error:function(d,e,f){
alert('網路連線過慢,網頁請重新整理');
},
success:function(d){
$('body').css('overflow','auto');
if(d)
{
$("#Ajax_Box").html(d);
//活動字串訊息
if($("#Coupon_Msg").val()){
alert($("#Coupon_Msg").val());
}
$("#Main_Form").fromsAuth({
type:'NONE'
});
//加購按鈕
var add = parseInt($("#CanAdd").val());
if(add > 0)
{
$(".Add_Button").removeClass('button-cant');
$(".Add_Button").addClass('add_to_cart');
$(".Add_Button").html('加購');
}
else
{
$(".Add_Button").addClass('button-cant');
$(".Add_Button").removeClass('add_to_cart');
$(".Add_Button").html('未符合加購');
}
//滿額按鈕
var gift = parseInt($("#CanGift").val());
if(gift > 0)
{
$(".Gift_Button").removeClass('button-cant');
$(".Gift_Button").addClass('add_to_cart');
$(".Gift_Button").html('挑選');
}
else
{
$(".Gift_Button").addClass('button-cant');
$(".Gift_Button").removeClass('add_to_cart');
$(".Gift_Button").html('未符合滿額贈品挑選');
}
var amount = parseInt($("#ChooseGift").val());
$("#Gift_Amount").html(amount);
$('#shopcart-num').html($('#Shop_Cart_Num').val())
}
}
})
}
//移至list.js加入成功才顯示
$("#Main_Content").on("click",".add_to_cart",function(){
// $('.successPopupMask').css('display','flex').fadeIn()
// $('.successPopup').fadeIn()
// setTimeout(function () {
// $('.successPopupMask').fadeOut()
// $('.successPopup').fadeOut()
// }, 1100)
});
//禮券開關
$("#Main_Content").on("click",".gift-jump,.gift-button,.loginButton",function(){
$('.gift-content,.gift-jump').removeClass('is-show');
$('body').removeAttr('style');
});
$("#Main_Content").on("click",".gift",function(){
//未登入
if($(this).hasClass('loginButton'))
{
return false;
}
$('.gift-content,.gift-jump').addClass('is-show');
$('body').css('overflow','hidden');
});
// ==========================================================
// 主選單開關
// ==========================================================
$(".menu-b").click(function(){
$(".header-01").toggleClass("open-nav");
$(".navBox").toggleClass("open-nav");
$('body').toggleClass('in-sticky')
$(this).toggleClass('close');
});
//語系選擇
$("#Select_This_Lang3").on("click",".menu_sub_a",function(){
$.post('/ajax/ajax_change_language.php', {Name: $(this).attr('sid')}, function(h){
window.location.reload();
}, 'html');
});
$('#menu-nav').on('click','.item-title',function(){
var n = $(this).parent(".open").length;
var t = $(this).attr("type");
if(t==''){
$('#menu-nav .nav-item').removeClass('open');
$('#menu-nav .menu-item').removeClass('open-sub');
$(".subitembox").removeClass('open-sub');
if(n == 0){
$(this).parent(".nav-item").addClass('open');
}
}else{
$('#menu-nav .nav-item').removeClass('open');
$('#menu-nav .menu-item').removeClass('open-sub');
$(".subitembox").removeClass('open-sub');
if(n == 0){
$(this).parent(".nav-item").find("#subitembox"+t).addClass('open-sub');
$(this).parent(".nav-item").addClass('open');
}
}
}).on(' click','.subtitle',function(){
var n = $(this).parent(".open-sub").length;
$('#menu-nav .menu-item').removeClass('open-sub');
if(n == 0){
$(this).parent(".menu-item").addClass('open-sub');
}
});