//$(".shopcart-group").addClass("in-collapse")
//表單驗證
;(function($) {
$("#Main_Form").fromsAuth({
callafter: function () {
//未符合活動檢查
let notFitAlert = $("#ShopcartListNotFitAlert").html() || '';
if(notFitAlert)
{
alert(_jsLang.以下活動含不符合條件商品請調整商品數量+"
"+notFitAlert, false);
return false;
}
//贈品檢查
let act13Left = $("#Act13_Left_Amount").val() || 0;
if(act13Left > 0)
{
alert(_jsLang.尚可挑選 + act13Left + _jsLang.件贈品請挑選後再送出購物車, false);
return false;
}
//國外地址檢查
const check_country = ['TW', 'CN', 'HK', 'MO']; //不檢查的國家
let pattern_En = /^[A-Za-z0-9\~\!\@\#\$\%\^\&\(\)\_\+\`\-\=\.\,\/ ]+$/;
let check_Address = $("#Send_Address").val();
let check_Address2 = $("#Send_Address2").val();
let selected = $("#Send_Country").find("option:selected");
if(selected.data("countrytype") == 3 && !check_country.includes(selected.data("code")) && (!pattern_En.test(check_Address) || !pattern_En.test(check_Address2)))
{
alert(_jsLang.地址為英數, false);
return false;
}
return true;
}
})
})($)
//商品詳細
;(function($) {
let file_Obj = new prod_file({
type: '2',
contBox: 'activities-detail',
itemBox: 'activities-detail',
picBox: 'moreview',
onepageFlag: true
});
file_Obj.init()
})($)
//刷新驗證碼
;(function($) {
$(document).on("click", "#Change_Pic", function(e){
$("#Checkspan").load(Project_Country+'ajax/ajax_get_check_pic.php',{change:1});
})
})($)
//活動nav
function navIntoView(item){
//將當前選項置中
if($(window).width() >= 768){
let owlitem = item.parents(".owl-item")
let cIndex = owlitem.index()
let vItem = $(".nav-list").find(".owl-item.active").length
let mIndex = Math.floor(vItem / 2)
let targetIndex = cIndex - mIndex
if(targetIndex < 0){
targetIndex = 0
}
$(".activities-nav .nav-list").trigger("to.owl.carousel",[targetIndex, 300, true])
}else{
item[0].scrollIntoView({
behavior:"smooth",
block:"nearest",
inline: "center"
})
}
}
;(function($) {
//活動nav朝向
let nav = $(".activities-nav .nav-list")
let navClickFlag = false
if(nav.length){
function navCheck(){
nav.trigger("destroy.owl.carousel")
if(nav[0].scrollWidth > nav.innerWidth()){
nav.addClass("theme-justify-start")
if($(window).width() >= 768){
nav.owlCarousel({
margin:0,
nav:false,
dots:false,
autoWidth: true,
items:1,
navText: ['', ''],
})
}else{
nav.trigger("destroy.owl.carousel")
}
}else{
nav.removeClass("theme-justify-start")
}
}
navCheck()
$(window).on("resize", function(){
navCheck()
})
$(document).on("click", ".activities-nav .nav-item", function(e){
let _this = $(this)
navClickFlag = true
$(".activities-nav .nav-item").removeClass("in-active")
_this.addClass("in-active")
navIntoView(_this)
})
//滾動時更新nav
function updateActiveBlock(){
//若經由點擊nav的scroll忽略
if(!navClickFlag){
let scrollTop = $(window).scrollTop()
let blocks = $("[id^='ActBlock']")
let currentId = null
let headerHeight = $('.header-wrapper').height()
if($("body.is-sticky:not(.is-upwards)").length){
headerHeight = 0
}
scrollTop += headerHeight
let positions = blocks.map(function(){
let _this = $(this)
let top = checkPosition(_this)
return {
id: this.id,
top: top,
bottom: top + _this.outerHeight()
}
}).get()
positions.sort(function(a, b){
return a.top - b.top
})
// let centerFlag = false
for(let i = 0; i < positions.length; i++){
let thisTop = positions[i].top
let thisBottom = positions[i].bottom
let nextTop = positions[i + 1] ? positions[i + 1].top : Number.MAX_VALUE
// if(scrollTop >= thisTop && scrollTop < nextTop){
// centerFlag = true
// }
if(scrollTop >= thisTop && scrollTop < thisBottom){
currentId = positions[i].id
break;
}
}
// if(!centerFlag){
// $(".nav-list .nav-item").removeClass("in-active")
// }
$(".nav-list .nav-item").removeClass("in-active")
if(currentId){
$(".nav-list .nav-item").removeClass("in-active")
let item = $(".nav-button[data-target='#" + currentId + "']").parents(".nav-item")
item.addClass("in-active")
navIntoView(item)
}
}else{
navClickFlag = false
}
}
let throttle = throttleScroll(function(){
updateActiveBlock()
}, 300)
throttle.init()
}
//活動nav輪播
})($)
;(function($) {
//開啟登入彈窗
$(document).on("click", ".js-trigger-login", function(){
$(".login-popup").removeClass("hide")
})
})($)
// 一頁式滑動到指定位置
function checkPosition(target){
let headerHeight = $('.header-wrapper').height()
let actNav = $(".activities-nav")
let currentScroll = $(window).scrollTop()
let targetOffset = target.offset().top
if(currentScroll < targetOffset){
headerHeight = 0
}
if(target.length) {
let targetOffset = target.offset().top
let scrollTop = targetOffset - headerHeight
if(actNav.length){
scrollTop = scrollTop - actNav.outerHeight(true)
}
return scrollTop
}
return false
}
function scrollToTarget(scrollTarget){
let scrollTop = checkPosition(scrollTarget)
if(scrollTop || scrollTop === 0){
$('html, body').animate({
scrollTop:scrollTop
}, 300)
}
}
;(function($) {
$(document).on('click', '.js-scroll-to', function(e) {
e.preventDefault()
let _this = $(this)
let target = _this.data('target')
const scrollTarget = $(target).eq(0)
if(scrollTarget.length){
scrollToTarget(scrollTarget)
_this.trigger("scrollFinished")
}
})
})($)
//右側優惠筆記
;(function($) {
let storageKey = "noteNoticeClose" + $("#Page_Shop_ID").val()
let today = new Date().toLocaleDateString()
let hiddenList = JSON.parse(localStorage.getItem(storageKey)) || {}
//移除過期紀錄
Object.keys(hiddenList).forEach(function(id){
if(hiddenList[id] !== today){
delete hiddenList[id]
}
})
//隱藏項目
$(".side-note-notice .note-item").each(function(){
let _this = $(this)
let id = _this.data("id")
if(hiddenList[id] === today){
_this.addClass("hide")
}
})
$(".side-note-notice").removeClass("hide")
$(document).on("click", ".side-note-btn", function(){
$(".side-note-notice").empty()
$(".side-note").toggleClass("hide")
})
$(document).on("click", ".note-closer", function(){
$(".side-note").toggleClass("hide")
})
$(document).on("scrollFinished", ".note-item", function(){
$(".side-note").addClass("hide")
})
$(document).on("click", ".note-item-closer", function(e){
e.stopPropagation()
let parentItem = $(this).parents(".note-item")
let id = parentItem.data("id")
parentItem.remove()
hiddenList[id] = today
//寫入storage本次不再出現
localStorage.setItem(storageKey, JSON.stringify(hiddenList))
})
})($)
//商品加減
;(function($) {
/**
*
* @param {*} box 帶有額外data-*的輸入區塊容器
* @param {*} sid
* @param {*} amount 更動後的數量 要刪除為0
* @param {*} callback
*/
function updateCartProduct(box, sid, amount, prodtType, callback = null){
let groupId = box.data("group-id") || '';
box.find(".spec-button,.quick-btn").addClass("in-disabled in-loading")
var pageType = $("#Page_Type").val();
$.ajax({
url: Project_Country+'quickshop/ajax/ajax_update_num.php',
type:"POST",
cache:false,
dataType:'json',
data:$.extend({}, box.data(), {
Prod_Sell_ID:sid,
Amount:amount,
Page_Shop_ID:box.data("onepage-id"),
//一般、定期、預購
Prod_Type:prodtType,
groupId:groupId,
pageType:pageType,
})
}).done(function(d){
if(d.Status == 'RET_SUCCESS')
{
let actID = box.data("act-id") || 0;
let updateKey = actID+'-'+sid;
$("#updateCartTotal").html(d.totalAmount);
updateAmountBox(box, amount);
box.find(".quick-input").val(amount).data("before-change", amount);
box.find(".quick-current").html(amount);
//更新全館區塊,特惠組組合包加子商品的時候不更新購物車
if(d.actType == '7' || d.actType == '8')
{
if(d.actType == '7')
{
for(let group in d.canChooseAmount)
{
$(".canChooseAmount"+actID+"-"+group).html(d.canChooseAmount[group]);
}
for(let group in d.leftAmount)
{
$(".leftAmount"+actID+"-"+group).html(d.leftAmount[group]);
}
if(d.needUpdate)
{
$(".act78Box"+actID+"-"+d.parent).find(".onepage-amount").each(function(){
let groupId = $(this).data("parent");
let prodSellId = $(this).find(".quick-input").attr("sid");
let newVal = d.updateSubAmount?.[groupId]?.[prodSellId] || 0;
updateAmountBox($(this), newVal);
$(this).find(".quick-input").val(newVal).data("before-change", newVal);
$(this).find(".quick-current").html(newVal);
});
$(".act78Box"+actID+"-"+d.parent).find(".act78MainAmount"+d.parent).val(d.mainProdAmount[d.parent] || 0);
}
}
else
{
for(let mains in d.canChooseAmount)
{
for(let group in d.canChooseAmount[mains])
{
$(".canChooseAmount"+actID+"-"+mains+"-"+group).html(d.canChooseAmount[mains][group]);
}
}
for(let mains in d.leftAmount)
{
for(let group in d.leftAmount[mains])
{
$(".leftAmount"+actID+"-"+mains+"-"+group).html(d.leftAmount[mains][group]);
}
}
if(d.needUpdate)
{
$(".act78Box"+actID+"-"+d.parent).find(".onepage-amount").each(function(){
let groupId = $(this).data("parent");
let subGroup = $(this).data("group");
let prodSellId = $(this).find(".quick-input").attr("sid");
let newVal = d.updateSubAmount?.[groupId]?.[subGroup]?.[prodSellId] || 0;
updateAmountBox($(this), newVal);
$(this).find(".quick-input").val(newVal).data("before-change", newVal);
$(this).find(".quick-current").html(newVal);
});
$(".act78Box"+actID+"-"+d.parent).find(".act78MainAmount"+d.parent).val(d.mainProdAmount[d.parent] || 0);
}
}
box.find(".spec-button,.quick-btn").removeClass("in-disabled in-loading")
updateShopcart()
}else if(d.actType == '11' || d.actType == '13'){
//滿額加購
updateShopcart()
}else{
updateShopcart({}, function(){
updateBox = $(".onepage-amount[data-updatekey='"+updateKey+"']");
//console.log(updateKey)
let fixedAmount = 0
if(actID == 0){
//一般商品
$(".shopcart-group-main").find(".spec-input[sid='"+sid+"']").each(function(){
let temp = parseInt($(this).val()) || 0
fixedAmount += temp
})
}else{
//活動商品
$(".shopcart-group-product[data-id='"+actID+"']").find(".spec-input[sid='"+sid+"']").each(function(){
let temp = parseInt($(this).val()) || 0
fixedAmount += temp
})
}
updateAmountBox(updateBox, fixedAmount);
updateBox.find(".quick-current").html(fixedAmount);
updateBox.find(".quick-input").val(fixedAmount).data("before-change", fixedAmount);
// 修正:使用 updateBox 並根據實際值和最大值設定按鈕狀態(#44343)
let inputEl = updateBox.find(".quick-input");
let maxVal = parseInt(inputEl.attr("max")) || 0;
let plusBtn = updateBox.find(".quick-plus");
updateBox.find(".quick-btn").removeClass("in-loading");
if(fixedAmount >= maxVal){
plusBtn.addClass("in-disabled");
}else{
plusBtn.removeClass("in-disabled");
}
});
}
if(typeof callback == 'function'){
callback(d)
}
if(d.DataLayer)eval(d.DataLayer);
if(d.Alert){
alert(d.Alert);
}
}else{
// 錯誤時恢復原本數量(#44343)
let originVal = box.data("origin-val") || 0;
box.find(".spec-input,.quick-input").val(originVal);
box.find(".quick-current").html(originVal);
updateAmountBox(box, originVal);
// 根據恢復的值和最大值設定按鈕狀態(#44343)
let inputEl = box.find(".quick-input");
let maxVal = parseInt(inputEl.attr("max")) || 0;
let plusBtn = box.find(".quick-plus");
box.find(".quick-btn").removeClass("in-loading");
if(originVal >= maxVal){
plusBtn.addClass("in-disabled");
}else{
plusBtn.removeClass("in-disabled");
}
if(d.Alert){
alert(d.Alert);
}else{
alert("發生錯誤");
}
}
}).fail(function(d){
alert('網路連線過慢,網頁請重新整理');
})
}
//更新原本數量
$(document).on("focus", ".onepage-amount", function(){
let origin = $(this).find(".quick-input").val() || 0;
$(this).data("origin-val", origin);
});
$(document).on("focus", ".spec-amount", function(){
let origin = $(this).find(".spec-input").val() || 0;
$(this).data("origin-val", origin);
});
//列表型
function mainProductAlert(box, val, targetBlock)
{
let msg = _jsLang.請先增加主商品數量 || '請先增加主商品數量';
alert(msg);
updateAmountBox(box, val);
box.find(".quick-input").val(val)
box.find(".quick-current").html(val);
scrollToTarget(targetBlock)
let amountBox = targetBlock.find(".spec-amount")
amountBox.addClass("theme-alert")
setTimeout(function(){
amountBox.removeClass("theme-alert")
}, 5000)
}
$(document).on("amountChange", ".onepage-amount", function(){
//如果是活動7、8的話先檢查是否能加入
let box = $(this)
let actType = box.data("act-type")
let input = box.find(".quick-input")
if(actType == '7' || actType == '8'){
let block = box.parents(".activities-section").find(".activities-detail").eq(0)
let boxKey = box.data("act-id") + "-" + box.data("parent");
let leftAmount = 0;
let origin = parseInt(input.data("before-change") || 0);
if(actType == '7'){
leftAmount = parseInt(box.parents(".act78Box"+boxKey).find(".leftAmount"+boxKey).html())
}else{
let groupKey = boxKey + "-" + box.data("group");
leftAmount = parseInt(box.parents(".act78Box"+boxKey).find(".leftAmount"+groupKey).html())
}
//如果沒有剩下可選,且修改數量比原數量大的時候警告後歸零
if(leftAmount <= 0 && origin < input.val()){
mainProductAlert(box, origin, block);
return false;
}
//有剩下可選 更改後超出上限
if((parseInt(input.val()) - origin) > leftAmount){
let tempval = origin + leftAmount
mainProductAlert(box, tempval, block);
}
}
if(box.data("timeout")){
clearTimeout(box.data("timeout"))
}
let updateTimerList = setTimeout(function(){
let val = parseInt(input.val())
updateCartProduct(box, input.attr("sid"), val, input.attr("prodtype"))
},250)
box.data("timeout", updateTimerList)
})
// //詳細型(A5)
// $(".activities-detail").on("click", ".add_to_cart", function(){
// let _this = $(this)
// let wrapper = _this.parents(".activities-detail")
// let amount = parseInt(_this.parents(".popup-content").find(".amountBox").val())
// //找出已在購物車內的數量往上加
// let item = $(".shopcart-group-product[data-id="+ wrapper.data("act-id") +"]").find("[sid="+_this.attr("sid")+"]").eq(0)
// if(item.length){
// amount += parseInt(item.val())
// }
// if(amount > 0){
// updateCartProduct(wrapper, _this.attr("sid"), amount, input.attr("prodtype"))
// }else{
// alert(_jsLang.請選擇數量)
// }
// })
$(document).on("click", ".popup-content .spec-button", function(){
let _this = $(this)
let box = _this.parents('.spec-amount')
let input = box.find(".spec-input")
input.trigger("change")
})
//下方集合購物車
$(document).on("click", ".shopcart-group-product .spec-button", function(){
let _this = $(this)
let box = _this.parents('.spec-amount')
let input = box.find(".spec-input")
let plus = box.find(".spec-plus")
let minus = box.find(".spec-minus")
let max = input.attr("max")
let min = 0
let val = parseInt(input.val())
if(_this.hasClass("spec-plus")){
if(val < max){
input.val(val + 1)
input.trigger("change")
}
}else{
if(val > 0){
input.val(val - 1)
input.trigger("change")
}
}
if(parseInt(input.val()) == min){
minus.addClass("in-disabled")
}else{
minus.removeClass("in-disabled")
}
if(parseInt(input.val()) == max){
plus.addClass("in-disabled")
}else{
plus.removeClass("in-disabled")
}
})
$(document).on("input", ".spec-input", function(){
let val = this.value.replace(/\D/g,'')
this.value = val
})
$(document).on("change", ".spec-input", function(){
let input = $(this)
let box = input.parents(".spec-amount")
let plus = box.find(".spec-plus")
let minus = box.find(".spec-minus")
let sid = input.attr("sid")
let prodType = input.attr("prodtype")
let min = 0
let max = parseInt(input.attr("max"))
let val = parseInt(input.val())
if(input.parents(".shopcart-group-product").length){
val = 0
input.parents(".shopcart-group-product").find(".spec-input[sid='"+sid+"']").each(function(){
let temp = parseInt($(this).val()) || 0
val += temp
})
}
let actType = box.data("acttype");
if(actType == 7 || actType == 8)
{
let actId = box.data("act-id");
$(".act78Box"+actId+"-"+sid).find(".needClear").html(0);
}
if(val > max)
{
let msg = (_jsLang['最多可購買數量'] ??'最多可購買數量') + max;
alert(msg);
input.val(max)
val = max;
}
if(val < min){
input.val(min);
val = min;
}
if(parseInt(input.val()) == min){
minus.addClass("in-disabled")
}else{
minus.removeClass("in-disabled")
}
if(parseInt(input.val()) == max){
plus.addClass("in-disabled")
}else{
plus.removeClass("in-disabled")
}
if(parseInt(input.val()) <= 1){
minus.find(".icon").removeClass("icon-minus").addClass("icon-trash")
}else{
minus.find(".icon").removeClass("icon-trash").addClass("icon-minus")
}
if(box.data("num-locked")){
val += (parseInt(box.data("num-locked"))??0)
}
box.trigger("amountChange")
if(box.data("timeout")){
clearTimeout(box.data("timeout"))
}
updateTimerCart = setTimeout(function(){
updateCartProduct(box, sid, val, prodType)
},250)
box.data("timeout", updateTimerCart)
})
//下方刪除
$(document).on("click", ".calc-delete-btn", function(){
let _this = $(this)
let input = _this.parents(".row-calc").find(".spec-amount").find(".spec-input")
if(input.length){
input.val(0).trigger("change")
}
})
})($)
var cartTimer = null
function updateShopcart(extraData = {}, callback = null){
extraData.type = 'ajax';
extraData.Page_Shop_ID_As = $("#Page_Shop_ID_As").val();
extraData.Page_Shop_Sub_ID = $("#Page_Shop_Sub_ID").val();
clearTimeout(cartTimer)
cartTimer = setTimeout(function(){
$.ajax({
url: Project_Country+'quickshop/ajax/ajax_update_all.php',
type:"POST",
dataType:"JSON",
data:$.extend({},collectData($("#RedpointBlock")), extraData, {
Page_Shop_ID: $("#Page_Shop_ID").val(),
})
}).done(function(res)
{
if(res.errorMsg)
{
alert(res.errorMsg);
if(res.redirectUrl)
{
window.location.href = res.redirectUrl;
}
return false;
}
if(res.act)
{
for(let actId in res.act)
{
$(".totalAmount"+actId).html(res.act[actId].totalAmount);
$(".delPrice"+actId).html(res.act[actId].delPrice);
$(".totalPrice"+actId).html(res.act[actId].totalPrice);
$(".priceGap"+actId).html(res.act[actId].priceGap);
}
}
if(res.list)
{
$("#UpdateListBlock").html(res.list);
}
if(res.shopcart)
{
$("#UpdateShopcartBlock").html(res.shopcart);
//加購輪播
simpleProductList($(".product-simple-list:not(.carousel-disabled) .wrapper"));
}
if(res.sendContent)
{
$("#Send_Data").replaceWith(res.sendContent);
}
if(res.deliveryContent)
{
$("#Delivery_Data").replaceWith(res.deliveryContent);
}
if(res.paymentContent)
{
$("#Pay_Data").replaceWith(res.paymentContent);
}
if(res.sideContent)
{
$("#Side_Data").replaceWith(res.sideContent);
let storageKey = "noteNoticeClose" + $("#Page_Shop_ID").val()
let today = new Date().toLocaleDateString()
let hiddenList = JSON.parse(localStorage.getItem(storageKey)) || {}
$(".side-note-notice .note-item").each(function(){
let _this = $(this)
let id = _this.data("id")
if(hiddenList[id] === today){
_this.addClass("hide")
}
})
$(".side-note-notice").removeClass("hide")
}
if(res.dataLayer)
{
eval(res.dataLayer);
}
if(typeof callback == 'function'){
callback(res)
}
}).fail(function(d){
alert('網路連線過慢,網頁請重新整理');
})
})
}
function collectData(ele){
//將給予的元素內的input/select值轉為{}格式
let data = {}
ele.find("input, select, textarea").each(function(){
let _this = $(this)
let name = _this.attr("name")
let type = _this.attr("type")
let value = _this.val()
if(!name){
return
}
if(type === 'checkbox'){
if(!data[name]){
data[name] = []
}
if(_this.is(':checked')){
data[name].push(value)
}
}else if(type === 'radio'){
if(_this.is(':checked')){
data[name] = value
}
}else{
data[name] = value
}
})
return data
}
//加購
;(function($) {
const productCarousel = $(".product-simple-list:not(.carousel-disabled) .wrapper")
if(productCarousel.length){
simpleProductList(productCarousel)
$(window).on("resize", function(){
simpleProductList(productCarousel)
})
}
})($)
//驗證
;(function($) {
function startCountdown(btn, countdown, textbox){
let remaining = parseInt(countdown)
let timer
function updateBtn(){
let min = Math.floor(remaining / 60)
let sec = remaining % 60
textbox.text(`有效時間(${min}:${sec < 10 ? "0" : ""}${sec})`)
if(remaining > 0){
remaining--
}else{
clearInterval(timer)
btn.prop("disabled",false).text(btn.data("origin-text"))
textbox.text("")
}
}
updateBtn()
timer = setInterval(updateBtn, 1000)
}
//企業帳號管理
$(document).on("click", "#SendEmailVerify", function(){
let _this = $(this)
let textBox = _this.parents(".table-row").find(".form-tips")
_this.prop("disabled", true).text(_this.data("send-text"))
$.ajax({
url: Project_Country+'quickshop/ajax/ajax_send_email_verify.php',
type:"POST",
cache:false,
dataType:'json',
data: {
email:$("#Crop_Email").val()
},
success: function(res){
let countdown = res.countdown || 300
startCountdown(_this, countdown, textBox)
},
error: function(){
_this.prop("disabled", false).text(_this.data("origin-text"))
}
})
})
//手機驗證
$(document).on("click", ".VerifyCode_Button", function(){
var btn = $(this);
var Email = $('#Buy_Email').val();
var Buy_Cellphone = $('#Buy_Cellphone').val();
var Password = $('#Login_Password').val();
var Country_Tel_Code = $('#Buy_Country_Tel_Code').val();
var Country_ID = $('#Send_Country_ID').val();
let type = btn.data("type") || "tel"
if(type == "tel"){
if (Buy_Cellphone == "") { alert('請輸入訂購人的行動電話', false); return false; }
}else if(type == "email"){
if(Email == ""){alert('請輸入訂購人的E-mail', false);return false;}
}
//if(Password == ""){alert('請輸入密碼');return false;}
//if(Country_Tel_Code == ""){alert("請輸入國碼");return false;}
$.ajax({
url: Project_Country + "shopcart/ajax/ajax_verifycode.php",
type: "POST",
cache: false,
dataType:"JSON",
data: { Email: Email, CellPhone: Buy_Cellphone, Password: Password, Country_Tel_Code: Country_Tel_Code, Country_ID: Country_ID, type: type },
success: function (res) {
if (res.status == 'TEL_OK') {
btn.attr('disabled', 'disabld');
btn.attr('countdown', res.countdown);
timeout(btn);
alert('認證簡訊已發送', false);
btn.parents(".form-input-group").find(".show-after-send").removeClass("hide")
//鎖定不能修改
btn.parents(".form-tel-group").find("input,select").prop("readonly", true);
} else if (res.status == 'EMAIL_OK') {
btn.attr('disabled', 'disabld');
btn.attr('countdown', res.countdown);
timeout(btn);
alert('認證Email已發送', false);
btn.parents(".form-input-group").find(".show-after-send").removeClass("hide")
//鎖定不能修改
btn.parents(".form-tel-group").find("input").prop("readonly", true);
} else if (res.status == 'RET_EMAIL_REPLY' || res.status == 'RET_CELLPHONE_REPLY') {
alert(_jsLang.此會員已存在請使用其他信箱或手機, false);
} else if (res.status == 'WRONG_CELLPHONE_FORMAT') {
alert(_jsLang.手機格式錯誤, false);
} else if (res.status == 'WRONG_EMAIL_FORMAT') {
alert(_jsLang.信箱格式錯誤, false);
} else if (res.status == 'RET_REPLY') {
btn.parents(".form-input-group").find(".show-after-send").removeClass("hide")
btn.parents(".form-tel-group").find("input,select").prop("readonly", true);
alert('請勿重覆發送驗證碼, 請等侯5分鐘' + '\n' + '請直接輸入先前收到的驗證碼', false);
} else if (res.status == 'RET_OVER') {
alert('手機簡訊發送已上限', false);
} else if (res.status == 'MDC_FAIL') {
alert('簡訊發送失敗,請稍後再試', false);
} else if (res.status == 'RET_CELLPHONE_REPLY') {
alert('您已經是會員,請登入會員,如忘記登入密碼,可至會員登入處點選「忘記密碼?」', false);
window.location.href = '/' + $("#Website_Mall_ID").val() + '/member-login';
}
}
});
})
//送出驗證
$(document).on("click", ".btn-send-verify", function(){
let _this = $(this)
let input = _this.prev("input")
let type = _this.data("type")
if(input.val()){
$.ajax({
url:Project_Country + "shopcart/ajax/ajax_verify_check.php",
type:"POST",
dataType:"JSON",
data: {
type: type,
val: input.val(),
countryId: $("#Buy_Country_Tel_Code").find("option:selected").data('cid'),
cellphone: $('#Buy_Cellphone').val(),
email:$('#Buy_Email').val(),
},
success: function(res){
if(res.status == 'OK'){
let name = '';
let final = '';
let hiddenVal = '';
let hiddenTelCode = '';
let box = $(".VerifyCode_Button[data-type='" + type + "']").parents(".form-input-group");
if(type == 'email')
{
name = 'Buy_Email';
final = $('#Buy_Email').val();
hiddenVal = $('#Buy_Email').val();
//需前端支援調整區塊
box.html(`