//$(".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(`
${final}
`) } else { name = 'Buy_Cellphone'; final = '+'+$("#Buy_Country_Tel_Code").find("option:selected").val()+' '+$('#Buy_Cellphone').val(); hiddenVal = $('#Buy_Cellphone').val(); hiddenTelCode = $("#Buy_Country_Tel_Code").val(); //需前端支援調整區塊 box.html(`
${final}
`); } }else{ alert("驗證碼錯誤", false) } }, }) }else{ alert(input.attr("nullstr"), false) } }) function timeout(btn) { let sec = btn.attr('countdown'); let t sec = sec - 1; let count_min = 0; let count_sec = 0; count_min = Math.floor(sec / 60); count_sec = (Array(2).join('0') + (sec % 60)).slice(-2); if (sec != '0') { btn.text(count_min + ':' + count_sec); btn.attr('countdown', sec); t = setTimeout(function(){ timeout(btn) }, 1000); } else { clearTimeout(t); btn.prop("disabled", false); btn.text("重發驗證信"); btn.attr('countdown', '0'); //解除鎖定 btn.parents(".form-tel-group").find("input,select").prop("readonly", false); } } })($) //條款閱讀 ;(function($) { $(document).on("click", ".terms-trigger", function(){ $(this).parents(".terms-label").find("input").prop("disabled", false) }) })($) //使用愛康幣/優惠券/購物金 ;(function($) { $(document).on("click", ".discount-send", function(){ let _this = $(this) let discountRow = _this.parents(".discount-label") discountRow.find(".discount-radio").prop("checked", true) if(_this.hasClass("popup-trigger")){ return false } let discountType = discountRow.find(".discount-radio:checked").val() let discountStr = discountRow.find(".discount-input").val() if(!discountType){ alert("請選擇使用優惠類型") return false } let send = {cate:discountType,value:discountStr}; if(!discountStr) { let key = "Cancel_"+discountType; send = {[key]:1}; } updateShopcart(send); }) $(document).on("focus", ".discount-input", function(){ let _this = $(this) let discountRow = _this.parents(".discount-label") discountRow.find(".discount-radio").prop("checked", true) }) })($) // ========================================================== // 優惠券選擇 // ========================================================== ;(function($) { //選擇就直接使用 $(document).on("click", ".coupon-radio", function(){ updateShopcart({cate:'Usable', value:$(this).val()}) }) //規則 $(document).on("click", ".coupon-rule", function(){ let _this = $(this) let id = _this.data("id") let title = _this.parents(".coupon-item").find(".coupon-radio").data("title") $.ajax({ url: Project_Country+'ajax/ajax_get_coupon_rule.php', type:"POST", dataType:"JSON", data: { id: id }, success: function(res){ if(res.content){ $("body").append(` `) } }, error: function(){ alert('網路連線過慢,網頁請重新整理'); } }) }) })($) // ========================================================== // 一般會員登入 // ========================================================== ;(function($) { //登入檢查 $(document).on("input", ".login-account-check input", function(){ let val = $(this).val() let codeSelect = $(".login-account-check select") let isValid = /^\d+$/.test(val) && val.length >=3 if(isValid){ codeSelect.removeClass("hide") }else{ codeSelect.addClass("hide") } }) //處理登入表單 $("#Member_Login_From").fromsAuth({type:'NONE'}); //處理註冊表單 $("#Member_Add_From").fromsAuth({type:'NONE'}); // 登入表單 AJAX 提交(攔截傳統 POST,顯示登入失敗錯誤訊息) $(document).on('submit', "#Member_Login_From", function(e) { e.preventDefault(); var $form = $(this); $.ajax({ url: Project_Country + 'quickshop/ajax/ajax_member_login.php', type: 'POST', contentType: 'application/json', data: JSON.stringify($form.serializeArray()), dataType: 'json', success: function(res) { if (res.msg) { alert(res.msg); // 刷新驗證碼 $form.find("#Checkspan").load(Project_Country + 'ajax/ajax_get_check_pic.php', {change: 1}); // 重置 Turnstile var cfWidget = $form.find('.cf-turnstile'); if (cfWidget.length && typeof turnstile !== 'undefined') turnstile.reset(cfWidget[0]); } else { window.location.reload(); } }, error: function() { alert('系統錯誤,請稍後再試'); } }); return false; }); $(document).on('click', '.show-login-popup', function(){ $(".add-popup").addClass("hide"); $(".login-popup").removeClass("hide"); $(".login-popup").find("#Checkspan").load(Project_Country+'ajax/ajax_get_check_pic.php',{change:1}); }); $(document).on('click', '.show-add-popup', function(){ $(".login-popup").addClass("hide"); $(".add-popup").removeClass("hide"); }); })($) // ========================================================== // 企業會員登入 // ========================================================== ;(function($) { //處理登入表單 $("#Corp_Login_From").fromsAuth({type:'NONE'}); // 企業登入表單 AJAX 提交 $(document).on('submit', "#Corp_Login_From", function(e) { e.preventDefault(); var $form = $(this); $.ajax({ url: Project_Country + 'quickshop/ajax/ajax_member_login.php', type: 'POST', contentType: 'application/json', data: JSON.stringify($form.serializeArray()), dataType: 'json', success: function(res) { if (res.msg) { alert(res.msg); $form.find("#Checkspan").load(Project_Country + 'ajax/ajax_get_check_pic.php', {change: 1}); var cfWidget = $form.find('.cf-turnstile'); if (cfWidget.length && typeof turnstile !== 'undefined') turnstile.reset(cfWidget[0]); } else { window.location.reload(); } }, error: function() { alert('系統錯誤,請稍後再試'); } }); return false; }); })($) // ========================================================== // 物流區塊 // ========================================================== ;(function($) { $(document).on("click", ".js-choose-store", function () { window.location.href = '/shopcart/e_returns/emap-p.php?url='+$("#Page_Shop_Url").val()+'&type=' + $(this).attr("service") + '&coll=' + $(this).attr("coll") + '&Country=' + $(this).attr("Country") + '&Cart=' + $('#Cart_Type').val(); }); })($) // ========================================================== // 紀錄訂購資料 // ========================================================== function updatePost() { let data = ''; $("#Buy_Data").find("input:text,input:hidden,input:checked,select,input:password").each(function () { if ($(this).attr("name") && $(this).attr("name") != undefined) { data += '&' + $(this).attr("name") + '=' + $(this).val(); } }); $("#Send_Data").find("input:text,input:hidden,input:checked,select,textarea").each(function () { if ($(this).attr("name") && $(this).attr("name") != undefined) { data += '&' + $(this).attr("name") + '=' + $(this).val(); } }); $("#Invo_Data").find("input:text,input:hidden,input:checked,select,textarea").each(function () { if ($(this).attr("name") && $(this).attr("name") != undefined) { data += '&' + $(this).attr("name") + '=' + $(this).val(); } }); let terms = ''; $("#Pay_Data").find("input[name='Terms_Data_ID']:checked").each(function(){ terms += $(this).val()+','; }) data += '&Terms_Data_ID=' + terms; //jquery選擇器抓不到input:tel所以另外做 data += '&Code='+$("#Code").val(); //一頁式ID data += '&Page_Shop_ID='+$("#Page_Shop_ID").val(); $.ajax({ url: Project_Country + "quickshop/ajax/ajax_update_post.php", type: "POST", cache: false, async: false, data: data, dataType: 'JSON', error: function (d) { }, success: function (d) { if(d.extra.sendArea) { $("#Send_Area_ID").html(d.extra.sendArea); } if(d.extra.buyCity) { $("#Buy_City_ID").html(d.extra.buyCity); } if(d.extra.buyArea) { $("#Buy_Area_ID").html(d.extra.buyArea); } }, }); } ;(function($) { $(document).on("blur", "#Buy_Data input:text, #Send_Data input:text, #Invo_Data input:text", function(){ updatePost(); }) $(document).on("change", "#Buy_Data select, #Invo_Data select", function(){ updatePost(); }) $(document).on("change", "#Send_City_ID, #Send_Area_ID", function(){ updatePost(); }) $(document).on("click", "#Buy_Data input:checked, #Invo_Data input:checked, #Pay_Data input:checkbox", function(){ updatePost(); }) $(document).on("click", "#Buy_Data input:radio, #Invo_Data input:radio", function(){ updatePost(); }) // $(document).on("change", "#Send_Data select", function(){ // let extraData = {}; // $("#Send_Data").find("input:text,input:hidden,input:checked,select,textarea").each(function () { // if ($(this).attr("name") && $(this).attr("name") != undefined) { // extraData[$(this).attr("name")] = $(this).val(); // } // }); // //國家類型 // let countryType = $("#Send_Country").find("option:selected").data("countrytype") || ''; // extraData['countryType'] = countryType; // updateShopcart(extraData); // }) //更新地址 //檢查預設地址 function updateCountry(){ let extraData = {}; $("#Send_Data").find("input:text,input:hidden,input:checked,select,textarea").each(function () { if ($(this).attr("name") && $(this).attr("name") != undefined) { extraData[$(this).attr("name")] = $(this).val(); } }); //國家類型 let addresstype = $("#Send_Country").find("option:selected").data("addresstype") || ''; extraData['addresstype'] = addresstype; extraData['same'] = "2"; updateShopcart(extraData, function(){ checkAddressType() //更換國別清空地址&手機 $("#Send_Cellphone").val("") $("#Send_Address").val("") }) } function checkAddressType(){ if($("#Send_Country").val()){ switch($("#Send_Country option:selected").data("addresstype")){ case 1: $("#Send_City_ID, #Send_Area_ID").removeClass("hide").attr("fun", "checkNull") break; case 2: $("#Send_Area_ID").addClass("hide").attr("fun", "") $("#Send_City_ID").removeClass("hide").attr("fun", "checkNull") break; case 3: $("#Send_City_ID, #Send_Area_ID").addClass("hide").attr("fun", "") break; } } if($("#Buy_Country").val()){ switch($("#Buy_Country option:selected").data("addresstype")){ case 1: $("#Buy_City_ID, #Buy_Area_ID").removeClass("hide").attr("fun", "checkNull") break; case 2: $("#Buy_Area_ID").addClass("hide").attr("fun", "") $("#Buy_City_ID").removeClass("hide").attr("fun", "checkNull") break; case 3: $("#Buy_City_ID, #Buy_Area_ID").addClass("hide").attr("fun", "") break; } } } checkAddressType() $(document).on("change", ".address-select-group select", function(){ let _this = $(this) let id = _this.attr("id") if(id == "Buy_Country" || id == "Send_Country"){ $.ajax({ type: "POST", url: Project_Country + "ajax/ajax_get_city-p.php", data: "&Send_ID=" + _this.val(), async: false, dataType: 'json', error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (jsonObj) { let cityID = "" let areaID = "" if(id == "Buy_Country"){ cityID = "Buy_City_ID" areaID = "Buy_Area_ID" }else{ cityID = "Send_City_ID" areaID = "Send_Area_ID" } $("#" + cityID).empty(); $("#" + areaID).empty().append(``); let options = `` for (k in jsonObj) { options += '' } $("#" + cityID).append(options); $("#Area_ID").children("option:gt(0)").remove(); checkAddressType() } }); } if(id == "Buy_City_ID" || id == "Send_City_ID"){ $.ajax({ type: "POST", url: Project_Country + "ajax/ajax_get_area-p.php", data: "&Send_ID=" + _this.val(), async: false, dataType: 'json', error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (jsonObj) { let areaID = "" if(id == "Buy_City_ID"){ areaID = "Buy_Area_ID" }else{ areaID = "Send_Area_ID" } let options = `` for (k in jsonObj.area) { options += '' } $("#" + areaID).empty().append(options); if(id == "Buy_City_ID" && $("#recipientCopy").is(":checked")){ $("#Buy_City_ID").find("option").clone().appendTo($("#Send_City_ID").empty()) $("#Send_City_ID").val($("#Buy_City_ID").val()) $("#Buy_Area_ID").find("option").clone().appendTo($("#Send_Area_ID").empty()) $("#Send_Area_ID").val($("#Buy_Area_ID").val()) } } }); } if(id == "Buy_Area_ID" && $("#recipientCopy").is(":checked")){ $("#Buy_Area_ID").find("option").clone().appendTo($("#Send_Area_ID").empty()) $("#Send_Area_ID").val($("#Buy_Area_ID").val()) } if(id == "Send_Country" || id == "Send_City_ID" || id == "Send_Area_ID"){ $("#recipientCopy").prop("checked", false) } if(id == "Send_Country" || id == "Buy_Country"){ updateCountry() } }) $(document).on("click", "#Delivery_Data input:radio, #Pay_Data input:radio", function(){ let extraData = {}; $("#Delivery_Data").find("input:radio:checked").each(function () { extraData['shipType'] = $(this).val(); }); $("#Delivery_Data").find("textarea").each(function () { if ($(this).attr("name") && $(this).attr("name") != undefined) { extraData[$(this).attr("name")] = $(this).val(); } }); $("#Pay_Data").find("input:radio:checked").each(function () { extraData['payType'] = $(this).val(); }); $("#Pay_Data").find("select").each(function () { if ($(this).attr("name") && $(this).attr("name") != undefined) { extraData[$(this).attr("name")] = $(this).val(); } }); updateShopcart(extraData); }) //同訂購人資料 copyAddress() $(document).on("change", "#recipientCopy", function(){ copyAddress() }) //訂購資料修改時取消同訂購人 $(document).on("change input", ".send-input-same", function(){ $("#recipientCopy").prop("checked", false) $("#Buy_Name").off('keyup') $("#Buy_Cellphone").off('keyup') $("#Buy_Address").off('keyup') }) function copyAddress(){ let _this = $("#recipientCopy") let countryChangeFlag = false if(_this.prop("checked")){ $("#Send_Name").val($("#Buy_Name").val()) $("#Country_Tel_Code").val($("#Buy_Country_Tel_Code").val()) $("#Send_Cellphone").val($("#Buy_Cellphone").val()) $("#Send_Name").val($("#Buy_Name").val()) if($("#Buy_Country").val() != $("#Send_Country").val()){ countryChangeFlag = true } $("#Buy_Country").find("option").clone().appendTo($("#Send_Country").empty()) $("#Send_Country").val($("#Buy_Country").val()) $("#Buy_City_ID").find("option").clone().appendTo($("#Send_City_ID").empty()) $("#Send_City_ID").val($("#Buy_City_ID").val()) $("#Buy_Area_ID").find("option").clone().appendTo($("#Send_Area_ID").empty()) $("#Send_Area_ID").val($("#Buy_Area_ID").val()) $("#Send_Address").val($("#Buy_Address").val()) $("#Buy_Name").on('keyup', function(){ $("#Send_Name").val($("#Buy_Name").val()) }) $("#Buy_Cellphone").on('keyup', function(){ $("#Send_Cellphone").val($("#Buy_Cellphone").val()) }) $("#Buy_Address").on('keyup', function(){ $("#Send_Address").val($("#Buy_Address").val()) }) }else{ $("#Buy_Name").off('keyup') $("#Buy_Cellphone").off('keyup') $("#Buy_Address").off('keyup') } updatePost(); if(countryChangeFlag){ updateCountry() } } })($) ;(function($) { if($(".top-marquee").length <= 0){ $("body").addClass("no-marquee") } })($) ;(function($) { //活動click $(document).on("click", ".row-sale .sale-label, .row-sale .sale-name", function(){ let eid = $(this).parents(".shopcart-group-product").data("id") if(eid){ //模擬點擊上方nav 觸發scroll $(".nav-list").find("[data-target='#ActBlock"+eid+"']").click() } }) //組合類下方增加 $(document).on("click", ".act-setitem-amount", function(e){ if(!$(e.target).closest(".spec-minus").length){ let eid = $(this).parents(".shopcart-group-product").data("id") if(eid){ //模擬點擊上方nav 觸發scroll ConfirmPop({ string:_jsLang['欲調整組合品數量,請重新確認商品。']??'欲調整組合品數量,請重新確認商品。', trueFunction: function(){ $(".nav-list").find("[data-target='#ActBlock"+eid+"']").click() } }) } } }) })($) // ========================================================== // 忘記密碼彈窗 // ========================================================== ;(function($) { // 當彈窗開啟時初始化表單驗證 $(document).on("click", ".forget-password-link", function(){ // 確保表單驗證已初始化 if(!$("#Forget_Password_Form").data('fromsAuth-initialized')) { $("#Forget_Password_Form").fromsAuth({type: 'NONE'}); $("#Forget_Password_Form").data('fromsAuth-initialized', true); } }); // 切換到手機驗證 $(document).on('click', "#Forget_Show_Phone", function() { $("#Forget_Email_Forget").addClass("hide"); $("#Forget_Phone_Forget").removeClass("hide"); $("#Forget_Login_Email").attr("fun", ""); $("#Forget_Cellphone").attr("fun", "checkNull"); $("#Forget_Show_Phone").addClass("in-active"); $("#Forget_Show_Email").removeClass("in-active"); $("#Forget_Kind").val("SMS"); $("#Forget_Memo1").html('請輸入您註冊會員資料時填寫的手機,系統稍後會將您的會員密碼以簡訊發送給您'); $("#Forget_Memo2").html('若未收到網站發送的密碼簡訊請致電客服詢問謝謝'); }); // 切換到 Email 驗證 $(document).on('click', "#Forget_Show_Email", function() { $("#Forget_Email_Forget").removeClass("hide"); $("#Forget_Phone_Forget").addClass("hide"); $("#Forget_Cellphone").attr("fun", ""); $("#Forget_Login_Email").attr("fun", "checkNull"); $("#Forget_Show_Email").addClass("in-active"); $("#Forget_Show_Phone").removeClass("in-active"); $("#Forget_Kind").val("MAIL"); $("#Forget_Memo1").html('請輸入您註冊會員資料時填寫的帳號,系統稍後會將您的會員密碼以此Email發送給您'); $("#Forget_Memo2").html('若未收到網站發送的密碼Email麻煩請至垃圾信件夾確認或是致電客服詢問謝謝'); }); // 表單提交 - 使用 AJAX 呼叫原本的 member_forget-p.php $(document).on('submit', "#Forget_Password_Form", function(e) { e.preventDefault(); var formData = $(this).serialize(); $.ajax({ url: Project_Country + 'member/member_forget-p.php', type: 'POST', data: formData, success: function(response) { // 解析 sessionStorage 中的訊息 var messageMatch = response.match(/sessionStorage\.setItem\('backAlert',\s*'([^']*)'\)/); var message = messageMatch ? messageMatch[1] : ''; // 檢查是否包含導向到 member-pwd 的程式碼 var tokenMatch = response.match(/member-pwd\/([a-zA-Z0-9]+)/); if (tokenMatch) { // 成功:有 token,進入下一步 var token = tokenMatch[1]; if(message) { alert(message); } // 關閉忘記密碼彈窗 $('.forget-password-popup').addClass('hide'); // 開啟設定密碼彈窗並傳入 token openSetPasswordModal(token); } else if (message) { // 有訊息但沒有 token:顯示錯誤訊息 alert(message); } else { // 無法解析回應 alert('系統錯誤,請稍後再試'); } }, error: function() { alert('系統錯誤,請稍後再試'); } }); return false; }); // 點擊忘記密碼連結 $(document).on('click', '.forget-password-link', function(e) { e.preventDefault(); // 關閉其他所有彈窗 $('.popupBox-wrapper').addClass('hide'); // 開啟忘記密碼彈窗 $('.forget-password-popup').removeClass('hide'); // 預設顯示手機驗證 $("#Forget_Show_Phone").trigger('click'); }); })($) // ========================================================== // 設定密碼彈窗 // ========================================================== ;(function($) { // 表單提交 - 使用 AJAX 呼叫原本的 member_set_pwd-p.php $(document).on('submit', "#Set_Password_Form", function(e) { e.preventDefault(); var formData = $(this).serialize(); $.ajax({ url: Project_Country + 'member/member_set_pwd-p.php', type: 'POST', data: formData, success: function(response) { // 解析 sessionStorage 中的訊息 var messageMatch = response.match(/sessionStorage\.setItem\('backAlert',\s*'([^']*)'\)/); var message = messageMatch ? messageMatch[1] : ''; // 檢查是否包含導向到 member-login 的程式碼 var successMatch = response.match(/member-login/); if (successMatch || (message && (message.indexOf('密碼變更成功') !== -1 || message.indexOf('成功') !== -1))) { // 成功:密碼變更完成 // 關閉設定密碼彈窗 $('.set-password-popup').addClass('hide'); // 顯示訊息並重新整理 if(message) { alert(message); window.location.reload(); } else { window.location.reload(); } } else if (message) { // 有訊息但不是成功:顯示錯誤訊息 alert(message); } else { // 無法解析回應 alert('系統錯誤,請稍後再試'); } }, error: function() { alert('系統錯誤,請稍後再試'); } }); return false; }); })($) // 開啟設定密碼彈窗的全域函數 function openSetPasswordModal(token) { $('#Set_Token').val(token); $('.set-password-popup').removeClass('hide'); // 初始化表單驗證(如果尚未初始化) if(!$("#Set_Password_Form").data('fromsAuth-initialized')) { $("#Set_Password_Form").fromsAuth({type: 'NONE'}); $("#Set_Password_Form").data('fromsAuth-initialized', true); } } // ========================================================== // 訂單管理跳窗 // ========================================================== ;(function($) { // 開啟訂單列表 $(document).on("click", ".js-open-order-list", function(){ let pageShopId = $("#Page_Shop_ID").val(); openOrderListModal(pageShopId); }); // 搜尋訂單按鈕 $(document).on("click", "#SearchOrderBtn", function(){ let pageShopId = $("#Page_Shop_ID").val(); loadOrderList(pageShopId); }); // 點擊訂單項目開啟詳情 $(document).on("click", ".order-list-item", function(){ let orderNum = $(this).data("order-num"); openOrderDetailModal(orderNum); }); // 從訂單列表內點擊開啟詳情(按鈕形式) $(document).on("click", ".js-open-order-detail-inline", function(){ let orderNum = $(this).data("order"); openOrderDetailModal(orderNum); }); // 查看訂單詳情按鈕 (從成功頁) $(document).on("click", ".js-view-order-detail", function(){ // 移除 URL 參數避免重複跳窗 if (window.history.replaceState) { let url = window.location.pathname; window.history.replaceState({}, document.title, url); } let orderNum = $(".order-success-popup .order-num").text(); $(".order-success-popup").addClass("hide"); openOrderDetailModal(orderNum); }); // 繼續購物按鈕 $(document).on("click", ".js-back-to-shop", function(){ // 移除 URL 參數避免重複跳窗 if (window.history.replaceState) { let url = window.location.pathname; window.history.replaceState({}, document.title, url); } $(".order-success-popup").addClass("hide"); }); // 提交客服留言 $(document).on("submit", "#ContactForm", function(e){ e.preventDefault(); let formData = new FormData(this); $.ajax({ url: Project_Country + 'quickshop/ajax/ajax_submit_contact.php', type: 'POST', data: formData, processData: false, contentType: false, dataType: 'json', success: function(res) { if(res.status == 'success') { alert(res.message); // 重新載入訂單詳情以顯示新留言 let orderNum = formData.get('Order_Num'); openOrderDetailModal(orderNum); } else { alert(res.message); } }, error: function() { alert('網路連線過慢,請重新整理'); } }); return false; }); })($); // 開啟訂單列表彈窗 function openOrderListModal(pageShopId) { // 設定預設日期區間(最近一年) let endDate = new Date(); let stDate = new Date(); stDate.setFullYear(stDate.getFullYear() - 1); $("#Order_St_Date").val(stDate.toISOString().split('T')[0]); $("#Order_End_Date").val(endDate.toISOString().split('T')[0]); $("#Order_Search_Num").val(''); $(".order-list-popup").removeClass("hide"); loadOrderList(pageShopId); } // 載入訂單列表 function loadOrderList(pageShopId) { $("#OrderListContainer").html('
載入中...
'); $.ajax({ url: Project_Country + 'quickshop/ajax/ajax_get_order_list.php', type: 'POST', dataType: 'json', data: { Page_Shop_ID: pageShopId, Search_Order_Num: $("#Order_Search_Num").val(), St_Date: $("#Order_St_Date").val(), End_Date: $("#Order_End_Date").val() }, success: function(res) { if(res.status == 'success') { // 直接使用後端回傳的完整 HTML $("#OrderListContainer").html(res.html); } else { alert(res.message || '載入失敗'); } }, error: function() { alert('網路連線過慢,請重新整理'); } }); } // 開啟訂單詳情彈窗 function openOrderDetailModal(orderNum) { $(".order-detail-popup").removeClass("hide"); $("#OrderDetailContainer").html('
載入中...
'); $.ajax({ url: Project_Country + 'quickshop/ajax/ajax_get_order_detail.php', type: 'POST', dataType: 'json', data: { Order_Num: orderNum }, success: function(res) { if(res.status == 'success') { $("#OrderDetailContainer").html(res.html); } else { alert(res.message || '載入失敗'); } }, error: function() { alert('網路連線過慢,請重新整理'); } }); } // 開啟付款成功彈窗 function openOrderSuccessModal(orderNum, payType, orderAmount) { $(".order-success-popup .order-num").text(orderNum); $(".order-success-popup .pay-type").text(payType); $(".order-success-popup .order-amount").text('NT$ ' + orderAmount); $(".order-success-popup").removeClass("hide"); }