var prod_file = function (option) { var sets = { //類型 type: '1', //1->列表,2->詳細頁,3->活動詳細頁,4.一頁式購物, 5.快速購物跳窗 pageType: 'common', //common || quickshop action: 'poducts', //頁面類型 mode: '', //PreVice時為預覽模式 //商品內容 contBox: 'content', //總容器的class itemBox: 'productBox', //商品容器的class nameBox: 'nameBox', //商品名稱的class prodnoBox: 'prodnoBox', //商品編號的class loveBox: 'product-love', //喜愛清單的class pricebox: 'pricebox', //定價+結帳價的class price2Box: 'font-delete', //定價的class PriceName1: 'PriceName1', //結帳價的名稱 price1Box: 'font-big', //結帳價的class priceBlock: 'priceBlock', //結帳價的block AvgPriceBox: 'AvgPriceBox', //平均售價div的class AvgPrice: 'AvgPrice', //平均售價span的class PopPrice3: 'pop_main_price3', //跳窗會員價的class PopPrice2: 'pop_main_price2', //跳窗定價的class PopPrice1: 'pop_main_price1', //跳窗結帳價的class PopDiffPrice: 'pop_main_price_diff', //跳窗省多少元的class rbonusBox: 'price-rbonus', //紅利兌換的class bonusBox: 'get_bonus', //購物金的class colorBox: 'colorbox', //顏色的class colorSelect: 'color-select', //顏色下拉的class colorName: 'Spec_Name1', //顏色名稱的class sizeBox: 'sizebox', //尺寸-按鈕的class sizeSelect: 'size-select', //尺寸-下拉的class sizeName: 'Spec_Name2', //尺寸名稱的class sp3Box: 'sp3box', //規格三-按鈕的class sp3Select: 'sp3-select', //規格三-下拉的class sp3Name: 'Spec_Name3', //規格三名稱的class numBlock: 'amountBlock', //數量的區塊 amountBox: 'amountBox', //數量的class stockBox: 'stockBox', //庫存的class picpathBox: 'productImg', //主圖片的class picBox: 'owl-carousel', //圖片容器的class specClass: 'checkbox-item', //規格 -按鈕的class specWrap: '.popup-choice', //規格 -按鈕外層的class specID2: 'SID', //規格 -要傳送的標籤屬性 specUrl: Project_Country + 'products/ajax/common/ajax_get_prod_item.php', //規格 -ajax網址 sale_msg: 'sale_msg', //規格的特惠訊息 sale_msg_box: 'salebox', //規格的特惠訊息容器 Wear_Report: 'Wear_Report', //試穿報告 ActStrBox: 'sale-string', //規格活動小字 ActImgBox: 'sale-img', //規格活動圖片 PreTypeBox: 'Pre_Type', //是不是預購品顯示 PreDataBox: 'Pre_Data', //預購到貨時間顯示 PopupBtn1: 'PopupBtn1', //購買跳窗-加入購物車按鈕容器 PopupBtn2: 'PopupBtn2', //購買跳窗-立即結帳按鈕容器 FixedButton: '.FixedButton', //手機版固定選單按鈕 Limit_Purchase_Text: 'Limit_Purchase_Text', //限購文字 ShippingFee_Free_Text: 'ShippingFee_Free_Text', //免運文字 Limit_Purchase_Text_Tips: 'limit-purchase-tips', //限購文字 ShippingFee_Free_Text_Tips: 'shipping-fee-free-tips', //免運文字 //加入購物車 addButton: 'add_to_cart', //加入購物車按鈕的class addButtonIn: 'add_to_cart_In', //直接購買按鈕的class addUrl: Project_Country + 'ajax/ajax_add_to_cart.php', //加入購物車網址 addBox: 'Add_Button', //加入購物車按鈕的容器 addBoxIn: 'Add_Button_In', //直接購買的容器 ordButton: 'button1', //選購按鈕(行銷) //補貨通知 informBtn: 'informButton', //補貨通知按鈕的class informSend: 'informSend', //送出按鈕的ID informID: 'informID', //存ID欄位的ID informEmail: 'informEmail', //Email欄位的ID informClose: 'informClose', //關閉按鈕的ID informUrl: Project_Country + 'products/ajax/common/ajax_add_prod_inform.php', //ajax網址 //wishList loveButton: 'product-love', //列表加入喜愛清單 wishUrl: Project_Country + 'products/ajax/common/ajax_add_wish_list.php', //ajax網址 //設定圖片 mobileUrl: Project_Country + 'products/ajax/detail/productView_moblie.php', //ajax手機網址 pcUrl: Project_Country + 'products/ajax/detail/productView_pc.php', //ajax桌機網址 otherData: '' }; $.extend(sets, option); var _this = this; //初始 this.init = function () { //點選規格 $("." + sets.contBox).on('click', "." + sets.specClass, function () { var _item = $(this).closest("." + sets.itemBox), SID = $(this).attr(sets.specID2), $this = $(this), ActID = $(this).data('aid'), Mark = $(this).data('mark'), Page_Shop_Type = ($("#Page_Shop_Type") ? $("#Page_Shop_Type").val() : _item.attr("type")); var data = 'Type=' + sets.type + '&SID=' + SID + '&ActID=' + ActID + '&Mark=' + Mark + '&mode=' + sets.mode + '&Page_Shop_Type=' + Page_Shop_Type + sets.otherData; if (SID) { $.ajax({ url: sets.specUrl, type: "POST", cache: false, async: false, data: data, dataType: 'json', error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d) { _this.setFile(_item, $this, d); console.log(d) // 顯示ajax規格切換叫回來的內容 } }); } }); //尺寸下拉選單 $("." + sets.contBox).on('change', "." + sets.colorSelect + ",." + sets.sizeSelect + ",." + sets.sp3Select, function () { var _item = $(this).closest("." + sets.itemBox), SID = $(this).val(), $this = $(this), ActID = $(this).data('aid'), Mark = $(this).data('mark'), Page_Shop_Type = _item.attr("type"); var data = 'Type=' + sets.type + '&SID=' + SID + '&ActID=' + ActID + '&Mark=' + Mark + '&mode=' + sets.mode + '&Page_Shop_Type=' + Page_Shop_Type + sets.otherData; if (SID) { $.ajax({ url: sets.specUrl, type: "POST", cache: false, async: false, data: data, dataType: 'json', error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d) { _this.setFile(_item, $this, d); } }); } }); //數量輸入 $("." + sets.contBox).on('keyup', "." + sets.amountBox, function () { var now_num = $(this).val(), max_num = $(this).attr('max'), max_limit = $(this).attr('limit'), min_num = (parseInt(max_num) > 0) ? 1 : 0; now_num = parseInt(now_num); min_num = parseInt(min_num); max_limit = parseInt(max_limit); $(this).val(now_num); if (now_num > max_limit && max_limit) { alert(_jsLang.一次最多只能加入 + max_num + _jsLang.個); $(this).val(max_limit); } else if (now_num > max_num) { alert(_jsLang.一次最多只能加入 + max_num + _jsLang.個); $(this).val(max_num); } if (now_num < min_num) { $(this).val(min_num); } if (isNaN(now_num)) { $(this).val(min_num); } }); //數量 $("." + sets.contBox).off("click.plus", "[class*=-plus]") $("." + sets.contBox).on("click.plus", "[class*=-plus]", function () { var amount = $(this).prev("." + sets.amountBox).val(), max = $(this).prev("." + sets.amountBox).attr("max"), limit = $(this).prev("." + sets.amountBox).attr("limit"); if (amount == '無庫存' || $(this).hasClass('Prod_Plus')) { return false; } var amount = parseInt(amount); var max = parseInt(max); var limit = parseInt(limit); if (amount + 1 > limit && limit) { alert(_jsLang.一次最多只能加入 + limit + _jsLang.個); $(this).prev("." + sets.amountBox).val(limit); } else if (amount + 1 > max) { alert(_jsLang.一次最多只能加入 + max + _jsLang.個); $(this).prev("." + sets.amountBox).val(max); } else { $(this).prev("." + sets.amountBox).val(amount + 1); } }); $("." + sets.contBox).off("click.minus", "[class*=-minus]") $("." + sets.contBox).on("click.minus", "[class*=-minus]", function () { var amount = $(this).next("." + sets.amountBox).val(), max = $(this).next("." + sets.amountBox).attr("max"), min = (parseInt(max) > 0) ? 1 : 0; if (amount == '無庫存' || $(this).hasClass('Prod_Minus')) { return false; } var amount = parseInt(amount); var min = parseInt(min); if (amount - 1 <= min) { $(this).next("." + sets.amountBox).val(min); } else { $(this).next("." + sets.amountBox).val(amount - 1); } }); //加入購物車按鈕 $("." + sets.contBox).off("click.add", "." + sets.addButton) $("." + sets.contBox).on("click.add", "." + sets.addButton, function () { var _item = $(this).closest("." + sets.itemBox), SID = $(this).attr('sid') || 0, type = $(this).data('type') || 'normal', leftAmount = $(this).attr("left_amount") || 'none', Add_Type = $(this).attr("page_shop_type"); if ($(this).data('aid')) { var ActID = $(this).data('aid'); } $this = $(this); if ($(this).parents().eq(0).attr('class') == 'Add_Button1') { var num = 1; } else if ($(this).hasClass('one_spec_add')) { var num = 1; } else if ($(this).closest(".select-btn-group").find("select").length == 2) { //加購單規格 var num = 1; } else { var num = _item.find("." + sets.amountBox).val() || 0; } if (SID == 0) { alert(_jsLang.請選擇尺寸或規格); //errorbox(); } else if (num == 0) { alert(_jsLang.請選擇數量); } else if (leftAmount >= 0 && num > leftAmount) { var msg = _jsLang?.只能再挑選X件商品 || '只能再挑選%s件商品'; alert(msg.replace("%s", leftAmount)); } else { var data = 'SID=' + SID + '&num=' + num + '&type=' + type + '&webcacheno=' + $('#webcacheno').val() + sets.otherData + '&Add_Type=' + Add_Type; if (ActID) { data += '&ActID=' + ActID; } $.ajax({ url: sets.addUrl, type: "POST", cache: false, async: false, data: data, dataType: 'json', error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d) { if (_item.hasClass('popupBox-wrapper')) { _item.remove() $('body').removeClass('overflow-hidden') } if (d.Pre_Flag == 1) { if (d.Stock <= 5) _item.find("." + sets.stockBox).html(_jsLang.預購品); } else { if (d.Stock > 0 && d.Stock <= 5) _item.find("." + sets.stockBox).html(_jsLang.庫存 + ' : ' + d.Stock); } if (d.Amount && d.Amount != 'null') _item.find("." + sets.amountBox).html(d.Amount); $(".cart-total").html(d.Total) if (d.Alert != 'OK') { alert(d.Alert); _this.afterAlert(d.Alert); } _this.setCartOther(d); if (d.Alert == 'OK') { console.log(sets.type) if (sets.type == '4') { $('.successPopupMask').css('display', 'flex').fadeIn() $('.successPopup').fadeIn() setTimeout(function () { $('.successPopupMask').fadeOut() $('.successPopup').fadeOut() }, 1100) } if (d.DataLayer) { eval(d.DataLayer); } // if(sets.type != '4' && typeof FloatCartPopup == 'function') { // FloatCartPopup({Type:'Prod',ID:SID,Act:'Add'}) // } // alert(_jsLang.加入購物車成功); AlertPop({ icon: '', string: _jsLang.加入購物車成功, }) } if (!$(this).hasClass('one_spec_add')) { _item.trigger("add_to_cart_success") } $.ajax({ url: sets.specUrl, type: "POST", cache: false, async: false, data: data, dataType: 'json', error: function (data) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d1) { _this.setFile(_item, $this, d1); } }); } }); } }); //直接購物按鈕 $("." + sets.contBox).off("click.addIn", "." + sets.addButtonIn) $("." + sets.contBox).on("click.addIn", "." + sets.addButtonIn, function () { var _item = $(this).closest("." + sets.itemBox), SID = $(this).attr('sid') || 0, num = _item.find("." + sets.amountBox).val() || 0; type = $(this).data('type') || 'normal'; if (SID == 0) { alert(_jsLang.請選擇尺寸或規格); //errorbox(); } else if (num == 0) { alert(_jsLang.請選擇數量); //errorbox(); } else { var data = 'SID=' + SID + '&num=' + num + '&type=' + type + '&webcacheno=' + $('#webcacheno').val() + sets.otherData; $.ajax({ url: sets.addUrl, type: "POST", cache: false, async: false, data: data, dataType: 'json', error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d) { if (_item.hasClass('popupBox-wrapper')) { _item.remove() } if (d.Pre_Flag == 1) { if (d.Stock <= 5) _item.find("." + sets.stockBox).html(_jsLang.預購品); } else { if (d.Stock > 0 && d.Stock <= 5) _item.find("." + sets.stockBox).html(_jsLang.庫存 + ' : ' + d.Stock); } if (d.Amount && d.Amount != 'null') _item.find("." + sets.amountBox).html(d.Amount); $(".cart-total").html(d.Total) // 購物商品數量 if (d.Alert != 'OK') { alert(d.Alert); _this.afterAlert(d.Alert); } _this.setCartOther(d); // if(d.Alert == 'OK'){ // if(d.DataLayer){eval(d.DataLayer)} // FloatCartPopup({Type:'Prod',ID:SID}) // } if (d.RedirectUrl) { window.location.href = d.RedirectUrl; } else if (d.Alert == 'OK') { window.location.href = '/' + $("#Website_Language").val() + '/' + $("#Website_Mall_ID").val() + '/shopcart/step1' + ((type != 'normal') ? '/preorder' : '/single'); } } }); } }); //補貨通知按鈕 $("." + sets.contBox).off("click.inform", "." + sets.informBtn) $("." + sets.contBox).on("click.inform", "." + sets.informBtn, function () { // $("#" + sets.informID).val($(this).attr('SID')); }); $("#" + sets.informSend).off("click.informSend") $("#" + sets.informSend).on("click.informSend", function () { // var email = $("#" + sets.informEmail).val(); if (!email) { alert('請輸入E-mail'); return false; } var emailRule = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/; if (email.search(emailRule) == -1) { alert('E-mail格式錯誤'); return false; } $.ajax({ url: sets.informUrl, type: "POST", cache: false, async: false, data: {SID: $("#" + sets.informID).val(), email: email}, error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d) { if (d == 'OK') { alert(_jsLang.您已成功新增一筆補貨通知當商品有貨時我們會儘快通知您); } else { alert(_jsLang.資料庫忙線中); } $("#" + sets.informClose).trigger("click"); } }); }); // 加入我的最愛 $("." + sets.contBox).off("click.love", "." + sets.loveButton) $("." + sets.contBox).on("click.love", "." + sets.loveButton, function () { const $this = $(this).find('.fa') const _item = $(this).parents("." + sets.itemBox) const SID = _item.find('.' + sets.loveBox).attr('sid') let type = 'del' if ($this.hasClass('fa-heart-o')) { type = 'add'; } $.ajax({ url: sets.wishUrl, type: "POST", cache: false, async: false, data: {Type: type, SID: SID}, dataType: 'json', error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d) { console.log(d) if (d.Msg == 'OK') { if (type == 'add') { try { if (d.DataLayer) { eval(d.DataLayer) } } catch (e) { } $this.removeClass("fa-heart-o"); $this.addClass("fa-heart"); alert(_jsLang.已加入喜愛清單); } else { $this.removeClass("fa-heart"); $this.addClass("fa-heart-o"); } } else if (d.Msg == 'NO_MEMBER') { alert(_jsLang.請先登入會員); } else { alert(_jsLang.資料庫忙線中); } } }); }); }; //設定內容 this.setFile = function (_item, $this, d) { _item.find("." + sets.loveBox).find('.fa').removeClass("fa-heart,fa-heart-o"); if (d.ID) _item.find("." + sets.ordButton).attr("sid", d.ID); if (d.ID) _item.find("." + sets.loveBox).attr("sid", d.ID); if (d.Name) _item.find("." + sets.nameBox).html(d.Name); if (d.Pos_No) _item.find("." + sets.prodnoBox).html(d.Pos_No); if (d.Love) _item.find("." + sets.loveBox).find('.fa').addClass(d.Love); if (d.Price_Name1) { _item.find("." + sets.PriceName1).html(d.Price_Name1); } if (d.Price1) { _item.find("." + sets.price1Box).html(d.Price1); _item.find("." + sets.priceBlock).show(); } else { _item.find("." + sets.priceBlock).hide(); } if (d.Price2) { _item.find("." + sets.price2Box).html(d.Price2).show(); } else { _item.find("." + sets.price2Box).hide(); } if (d.Avg_Price) { _item.find("." + sets.AvgPriceBox).show(); _item.find("." + sets.AvgPrice).html(d.Avg_Price); _item.find("." + sets.pricebox).hide(); } else { _item.find("." + sets.AvgPriceBox).hide(); _item.find("." + sets.pricebox).show(); } if (d.Price1) { _item.find("." + sets.PopPrice1).html(d.Main_Price1); } if (d.Price2) { _item.find("." + sets.PopPrice2).html(d.Main_Price2); } if (d.Price3) { _item.find("." + sets.PopPrice3).html(d.Main_Price3); } if (d.Price1_Diff) { _item.find("." + sets.PopDiffPrice).html(d.Price1_Diff); _item.find("." + sets.Price1_Diff).show(); } else { _item.find("." + sets.Price1_Diff).hide(); } if (d.RBonus) _item.find("." + sets.rbonusBox).html(d.RBonus); if (d.Get_Bonus) _item.find("." + sets.bonusBox).html(d.Get_Bonus); // if(d.Color)_item.find("."+sets.colorBox).html(d.Color); // if(d.Color_Name)_item.find("."+sets.colorName).html(d.Color_Name); _item.find("." + sets.PreTypeBox).html(d.Pre_Type); _item.find("." + sets.PreDataBox).html(d.Pre_Data); _item.find("." + sets.Limit_Purchase_Text).html(d.Limit_Purchase_Text); _item.find("." + sets.ShippingFee_Free_Text).html(d.ShippingFee_Free_Text); if(d.Limit_Purchase_Text){ _item.find("." + sets.Limit_Purchase_Text_Tips).removeClass('hide'); _item.find("." + sets.Limit_Purchase_Text_Tips + ' .tips-inner').html(d.Limit_Purchase_Text); }else{ _item.find("." + sets.Limit_Purchase_Text_Tips).addClass('hide'); } if(d.ShippingFee_Free_Text){ _item.find("." + sets.ShippingFee_Free_Text_Tips).removeClass('hide'); _item.find("." + sets.ShippingFee_Free_Text_Tips + ' .tips-inner').html(d.ShippingFee_Free_Text); }else{ _item.find("." + sets.ShippingFee_Free_Text_Tips).addClass('hide'); } if (d.sale_msg) { _item.find("." + sets.sale_msg).html(d.sale_msg); _item.find("." + sets.sale_msg_box).show() } else { _item.find("." + sets.sale_msg_box).hide() } // _item.find(".select-btn-group").html(d.ListButton); _item.find("." + sets.Wear_Report).html(d.Wear_Report); if (d.Stock) { _item.find("." + sets.stockBox).html(_jsLang.庫存 + ' : ' + d.Stock); _item.find('.popup-amount-box').removeClass('hide'); } else { _item.find("." + sets.stockBox).html(''); _item.find('.popup-amount-box').addClass('hide'); } if (d.Act_Str) { _item.find("." + sets.ActStrBox).html(d.Act_Str); _item.find("." + sets.ActStrBox).show(); } else { _item.find("." + sets.ActStrBox).html(''); _item.find("." + sets.ActStrBox).hide(); } if (d.Act_Img) { _item.find("." + sets.ActImgBox).html(d.Act_Img); _item.find("." + sets.ActImgBox).show(); } else { if (typeof (d.Act_Data_ID) == 'undefined' || d.Act_Data_ID.length == 0) { _item.find("." + sets.ActImgBox).html(''); _item.find("." + sets.ActImgBox).hide(); } } if (sets.type == 3) { if (d.Size_Sel) $this.next("." + sets.sizeSelect).html(d.Size_Sel); if (d.SP3_Sel) $this.nextAll("." + sets.sp3Select).eq(0).html(d.SP3_Sel); if (d.Amount) { $this.nextAll("." + sets.numBlock).eq(0).show(); $this.nextAll("." + sets.amountBox).eq(0).html(d.Amount); } else { $this.nextAll("." + sets.numBlock).eq(0).hide(); $this.nextAll("." + sets.amountBox).eq(0).html(''); } $this.nextAll("." + sets.amountBox).eq(0).trigger('change'); } else { if (d.Color_Button) _item.find("." + sets.colorBox + ', ' + sets.specWrap).html(d.Color_Button); if (d.Color_Sel) _item.find("." + sets.colorSelect).html(d.Color_Sel); if (d.Color_Name) _item.find("." + sets.colorName).html(d.Color_Name); if (d.Size_Button) _item.find("." + sets.sizeBox).html(d.Size_Button); if (d.Size_Sel) _item.find("." + sets.sizeSelect).html(d.Size_Sel); if (d.Size_Name) _item.find("." + sets.sizeName).html(d.Size_Name); if (d.SP3_Button) _item.find("." + sets.sp3Box).html(d.SP3_Button); if (d.SP3_Sel) _item.find("." + sets.sp3Select).html(d.SP3_Sel); if (d.SP3_Name) _item.find("." + sets.sp3Name).html(d.SP3_Name); if (d.Amount2 || d.Amount2 === 0) { _item.find("." + sets.numBlock).show(); _item.find("." + sets.amountBox).attr('max', d.Amount2); //已選值超過最大值,取最大值 if (_item.find("." + sets.amountBox).val() > d.Amount2) { _item.find("." + sets.amountBox).val(d.Amount2) } } else { _item.find("." + sets.numBlock).hide(); _item.find("." + sets.amountBox).html(''); } if (d.Amount) { _item.find("." + sets.numBlock).eq(0).show(); } if (d.Amount && _item.find("." + sets.amountBox).prop('tagName') == 'SELECT') { _item.find("." + sets.amountBox).eq(0).html(d.Amount); } _item.find("." + sets.amountBox).attr('limit', d.Limit_Purchase); } if (sets.type == 2) { $("." + sets.contBox).find("." + sets.loveButton).attr("sid", d.ID); $("." + sets.contBox).find("." + sets.loveButton).find(".fa").removeClass("fa-heart fa-heart-o"); $("." + sets.contBox).find("." + sets.loveButton).find(".fa").addClass(d.Love); if (d.Serial_No && sets.pageType == 'common' && sets.contBox !== "detail-addpurchase-item") { var new_url = '/' + $("#Website_Language").val() + '/' + $("#Website_Mall_ID").val() + '/product-detail/' + d.Serial_No; if (sets.mode) { new_url += '?mode=' + sets.mode; } window.history.replaceState({id: d.ID}, d.Name, new_url); } if (sets.mode) if (d.Community) $(".followbox").html(d.Community); } if (d.Prod_Multi) $(".Prod_Multi").html(d.Prod_Multi); for ($i = 1; $i <= 3; $i++) { var NewButton = d.Button[$i] || ''; _item.find("." + sets.addBox + $i).html(NewButton); } _item.find("." + sets.addBoxIn).html(d.Button2); _item.find("." + sets.PopupBtn1).html(d.ButtonPop); if (d.ButtonPop2) { if (_item.find("." + sets.PopupBtn2).length <= 0) { _item.find("." + sets.PopupBtn1).after('') } _item.find("." + sets.PopupBtn2).html(d.ButtonPop2); } else { _item.find("." + sets.PopupBtn2).empty() } _item.find(sets.FixedButton).replaceWith(d.FixedButton); _this.setImg(_item, d.Pic_Path, d.Pic, d.Video); _this.setFileOther(_item, d); if (d.Stock > 0) { _item.find(".soldout-cover").hide(); } else { _item.find(".soldout-cover").show(); } } //變更內容自訂Function this.setFileOther = function () { } //加入購物車後自訂Function this.setCartOther = function () { } // alert跳窗後動作 this.afterAlert = function () { } //設定圖片、影片 this.setImg = function (_item, Pic_Path, Pic, Video) { const List_Size = 'L_' const More_Size = 'S_' const ListImgPath = Project_Country + 'upload_files/fonlego-rwd/prodpic/' + List_Size + Pic_Path const pictureTarget = _item.find("." + sets.picpathBox) const moreviewTarget = _item.find("." + sets.picBox) const _Pic = (Pic_Path + ',' + Pic).split(',') const PicsCount = _Pic.filter(ele => !!ele).length; const previewItems = ['', ''] if (sets.type == 1) { //列表 pictureTarget.find('.center-box > img, .hover-box > img').attr('src', ListImgPath) } else if (sets.type == 4) { // 一頁式購物 _this.item_num = 5; let $Pic = '' let $Pic_Path = '' let now_class = 'now' let Pic_Size = 'S' let $loop = false for ($i = 0; $i < _Pic.length; $i++) { if (_Pic[$i]) { // $Pic_Path += '
'; $Pic_Path += '
'; $Pic_Path += ''; $Pic_Path += ''; $Pic_Path += ''; //$Pic_Path += ''; $Pic_Path += '
'; //$Pic_Path += ''; //$Pic_Path += '
'; } } if (Video) { //$Pic_Path += '
'; $Pic_Path += '
'; $Pic_Path += '
'; //$Pic_Path += '
'; } _item.parents(".productBox").find("." + sets.picpathBox).html($Pic_Path); _item.parents(".productBox").find("." + sets.picpathBox + " .zoonbox").eq(0).addClass(now_class); } else if (sets.type == 5) { // 快速購物跳窗 _Pic.reduce(function (prev, ele, i) { let nowItem = '' if(i === 0) { nowItem = 'now' } if(ele) { prev[0] += `
` prev[1] += ` ` } return prev }, previewItems) pictureTarget.each(function(){ let _this = $(this) if(!(_this.parents(".addpurchase-box").length > 0)){ _this.html(previewItems[0]) _this.trigger("previewUpdate") } }) moreviewTarget.html(previewItems[1]) moreviewTarget.trigger("moreviewUpdate") } else { // 詳細頁 let picCounter = 0 _Pic.reduce(function (prev, ele, i) { let nowItem = '' if (i === 0) { nowItem = 'now' } if (ele) { prev[0] += `
` prev[1] += ` ` picCounter++ } return prev }, previewItems) if (Video) { previewItems[0] += `
` previewItems[1] += ` ` picCounter++ } pictureTarget.each(function(){ let _this = $(this) if(!(_this.parents(".addpurchase-box").length > 0)){ _this.html(previewItems[0]) _this.trigger("previewUpdate") } }) moreviewTarget.html(previewItems[1]) if (picCounter > 1) { moreviewTarget.removeClass("hide") } else { moreviewTarget.addClass("hide") } moreviewTarget.trigger("moreviewUpdate") } } }; var prod_list = function (option) { var sets = { //類型 type: '1', //1->列表,2->詳細頁,3->活動詳細頁,4.一頁式購物, 5.快速購物跳窗 //商品內容 contBox: 'Main_Content', //總容器的ID styleBox: 'stylebox', //樣式下拉選單的ID sizeBox: 'sizebox', //尺寸下拉選單的ID orderBox: 'orderbox', //排序下拉選單的ID morderBoxWrap: '.aside-sort', morderBox: '.sort-link', pageBox: 'pagination-list', //分頁容器的class pageShow: 'page_show', //顯示分頁資訊的ID pageSelect: 'pageSelect', //分頁下拉選單的class prevPage: 'prev_page', //手機版上一頁的ID nextPage: 'next_page', //手機版下一頁的ID picBox: 'productSlidebox', //圖片容器的class mainPicBox: 'productImg', //主圖片容器的class searchBox: 'slideBox', //搜尋按鈕容器的class searchBtn: 'search-item', //搜尋按鈕的class searchFocus: 'search-focus', //搜尋按鈕focus的class searchType: 'type', //搜尋按鈕type標籤 searchID: 'search_id', //搜尋按鈕search_id標籤 moneyRange: 'money_range', //篩選價格的class mobileFilter: 'mobile-filter', //手機版行銷篩選器的class mobileMore: 'mobileMore', urlGetID: 'Url_Get', //塞入get資料的表單ID searchUrl: Project_Country + 'products/ajax/list/ajax_get_prod_list.php',//搜尋ajax網址 nextClassUrl: Project_Country + 'products/ajax/list/ajax_get_next_class.php', //檢查下一個分類的ajax網址 cleanSearch: 'cleanButton' //清除篩選Button之ID }; $.extend(sets, option); let _this = this; let sortFunHash = parseInt(window.location.hash.replace('#', '')) || 0 let onSort = false //初始 this.init = function () { //篩選按鈕 $("." + sets.searchBtn).on('click', function () { var $class = ""; $class = ($(this).hasClass(sets.searchFocus)) ? "" : sets.searchFocus; //$(this).parents("."+sets.searchBox).children("."+sets.searchBtn).removeClass(sets.searchFocus); $(this).removeClass(sets.searchFocus); $(this).addClass($class); _this.Search(); }); //每頁幾筆 $('input[name="viewNumder"]').on('click', function () { _this.Search(); }); //排序 $("#" + sets.orderBox).on('change', function () { onSort = true if (sortFunHash === 0) { sortFunHash = 1 } _this.Search(1, 'no'); }); //手機版排序 $(document).on('click', sets.morderBox, function (e) { e.preventDefault() $(this).parents(sets.morderBoxWrap) .find(sets.morderBox).removeClass('in-active') .end() .end().addClass('in-active') _this.Search(); }) //手機版看更多 $(window).on('infiniteScroll', function () { var mpage = parseInt($('#mobilePage').val()) + 1; $('#mobilePage').val(mpage); _this.Search(mpage, 'no', 'append'); }) /*$("#"+sets.mobileMore).on('click',function(){ var mpage = parseInt($('#mobilePage').val()) + 1; $('#mobilePage').val(mpage); _this.Search(mpage, 'no', 'append'); });*/ //下拉篩選樣式 $("#" + sets.styleBox).on('change', function () { _this.Search(); }); //下拉篩選尺寸 $("#" + sets.sizeBox).on('change', function () { _this.Search(); }); //紅綠標 $("input[name='pair_flag']").click(function () { _this.Search(); }); //手機版行銷篩選 $("." + sets.mobileFilter).on('click', function () { $("." + sets.mobileFilter + "[type=" + $(this).attr("type") + "]").removeClass("now"); $(this).addClass("now"); _this.Search(); }); //分頁 $("." + sets.pageBox).on('click', '.page,.page-next', function () { window.location.hash = $(this).attr("send"); }); //手機版上下頁 $("#" + sets.prevPage + ",#" + sets.nextPage).on('click', function () { if ($(this).attr("send") > 0) { window.location.hash = $(this).attr("send"); } }); //分頁下拉選單 $("." + sets.pageSelect).change(function () { window.location.hash = $(this).val(); }); //分頁錨點 var hash = parseInt(window.location.hash.replace('#', '')); if (hash > 0) { _this.Search(hash); } window.onhashchange = function () { if ($("#mobilePage").length <= 0) { var hash = parseInt(window.location.hash.replace('#', '')); if (hash !== 1) { sortFunHash = hash } if (hash > 0 && !(sortFunHash === 1 && onSort)) { _this.Search(hash); } else { onSort = false } } } //篩選價格 if ($('.nstSlider').length) { $('.nstSlider').nstSlider({ "rounding": { "50": "1000" }, "crossable_handles": false, "left_grip_selector": ".leftGrip", "right_grip_selector": ".rightGrip", "value_bar_selector": ".bar", "highlight": { "grip_class": "gripHighlighted", "panel_selector": ".highlightPanel" }, "user_mouseup_callback": function (leftValue, rightValue) { $('.leftLabel').text(leftValue); $('.rightLabel').text(rightValue); _this.Search(hash, 'no'); }, "value_changed_callback": function (cause, leftValue, rightValue) { $('.leftLabel').text(leftValue); $('.rightLabel').text(rightValue); }, }); } //清除篩選 $("#" + sets.cleanSearch).on('click', function () { $("." + sets.searchBtn).removeClass(sets.searchFocus); //篩選按鈕歸零 if ($('.nstSlider').length) { $('.nstSlider').nstSlider('set_position', 0, $('.nstSlider').attr("data-range_max")); } _this.Search(); }); }; //篩選功能 this.Search = function (pageCode, other, type) { //置頂 // if(other != "no"){ // const contentOffset = $('#' + sets.contBox).offset().top - $('.header-wrapper').height() // $(window).scrollTop(contentOffset); // } var _str = "", _style = "&style=", _material = "&material=", _beg = "&beg=", _spec1 = "&spec1=", _spec2 = "&spec2=", pageCode = parseInt(pageCode) || 1, _limit = $('input[name="viewNumder"]:checked').val(), $page = ""; //搜尋結果頁無限制筆數功能 所以預設值25 if (_limit == undefined) { _limit = 25; } $(".loading").show(); $("." + sets.searchFocus).each(function () { switch ($(this).attr(sets.searchType)) { case "style": _style += $(this).attr(sets.searchID) + ','; break; case "material": _material += $(this).attr(sets.searchID) + ','; break; case "beg": _beg += $(this).attr(sets.searchID) + ','; break; case "spec1": _spec1 += $(this).attr(sets.searchID) + ','; break; case "spec2": _spec2 += $(this).attr(sets.searchID) + ','; break; } }); _str += _style + _material + _beg + _spec1 + _spec2; _mobile_str = ''; $("." + sets.moneyRange).each(function () { _str += "&" + $(this).attr("id") + "=" + $(this).text(); }); if ($(sets.morderBoxWrap).length) { if ($(window).width() >= 1200) { if ($("#" + sets.orderBox).val()) { _str += "&order=" + $("#" + sets.orderBox).val(); } } else { if ($(sets.morderBox + '.in-active').attr('data-value')) { _str += "&order=" + $(sets.morderBox + '.in-active').attr('data-value'); } } } else { if ($("#" + sets.orderBox).val()) { _str += "&order=" + $("#" + sets.orderBox).val(); } } if ($("input[name='pair_flag']:checked").val()) { _str += "&pair=" + $("input[name='pair_flag']:checked").val(); } $("." + sets.mobileFilter + ".now").each(function () { _str += "&" + $(this).attr("type") + "=" + $(this).attr("val"); }) _str += "&limit=" + _limit; if ($("#mobilePage").length <= 0) { _str += "&page=" + pageCode; } else { _mobile_str += "&page=" + pageCode; } $.ajax({ url: sets.searchUrl, type: "POST", async: false, data: $("#" + sets.urlGetID).val() + _str + _mobile_str, error: function (d) { alert('網路連線過慢,網頁請重新整理'); }, success: function (d) { upwardsLocked = true //插入資料 if (type === 'append') { $("#" + sets.contBox).find('#Ajax_Total').remove() .end().append(d) } else { $("#" + sets.contBox).html(d) } // .find("."+sets.picBox) // .owlCarousel({ // loop : true, // items : 1, // nav : true // }); //處理分頁 var Total = $("#Ajax_Total").val(), $start = 0, $end = 0, $Total = Math.ceil(Total / _limit); if (_limit != 99) { // 手機版看更多 // if($("#"+sets.urlGetID).val().indexOf("cid=") != -1 && pageCode >= $Total && !($(".pagination-list").length > 0)){ // // 改下一分類 // $.ajax({ // url:sets.nextClassUrl, // type:"POST", // async:false, // data:$("#"+sets.urlGetID).val(), // dataType: 'json', // error:function(d) { // alert('網路連線過慢,網頁請重新整理'); // }, // success:function(d) { // if(d.nid){ // $('#Next_Class').val(d.nid) // } // if(d.urlParam){ // $("#Url_Get").val(d.urlParam); // $("#mobilePage").val(0); // } // if($("#Next_Class").val().length == 0) { // $(window).trigger("infiniteScrollEnd"); // } // } // }); // //$(window).trigger("infiniteScrollEnd") // //$('#'+sets.mobileMore).hide(); // } //一般分頁 $("#" + sets.pageShow).removeClass('hide'); //手機版上一頁 // if($Total >1){ // $("#"+sets.prevPage).show(); // $("#"+sets.prevPage).attr("send",(pageCode-1)); // }else{ // $("#"+sets.prevPage).hide(); // } //手機版下一頁 // if(pageCode < $Total){ // $("#"+sets.nextPage).show(); // $("#"+sets.nextPage).attr("send",(pageCode+1)); // }else{ // $("#"+sets.nextPage).hide(); // } //上一頁 if (pageCode > 1) { $page += `
  • `; } //第一頁 if (pageCode > 3 && $Total > 5) { $page += `
  • 1
  • `; $page += `
  • ...
  • `; } // 頁碼 $start = Math.max(1, pageCode - 2); $end = Math.min($Total, pageCode + 2); if (pageCode <= 3) { $end = Math.min($Total, 5); } else if (pageCode >= ($Total - 2)) { $start = $Total - 4; } for ($i = $start; $i <= $end; $i++) { var $class = (pageCode == $i) ? 'in-focus' : ''; if ($Total == 1) { $class += ' hide'; } $page += `
  • ${$i}
  • `; } // 刪節號 if (pageCode < $Total - 2 && $Total > 5) { $page += `
  • ...
  • `; $page += `
  • ${$Total}
  • `; } //下一頁 if (pageCode < $Total) { $page += `
  • `; } if ($("#mobilePage").length <= 0) { window.location.hash = pageCode; } var searchstr = $("#" + sets.urlGetID).val() + _str; if (sets.type == '2') { window.history.replaceState({pageCode: pageCode}, "test", '?' + searchstr.substr(1)); } $("." + sets.pageBox).html($page); //$("#" + sets.pageShow).html('顯示第 1 - ' + ((Total < pageCode * _limit) ? Total : pageCode * _limit) + ' 筆,共 ' + Total + ' 筆'); //下拉選單分頁 var $option = ""; for ($i = 1; $i <= $Total; $i++) { var $select = ""; if ($i == pageCode) $select = "selected"; $option += ''; } $("." + sets.pageSelect).html($option); //$(window).Scroll_Data.destroy(); } else { $("." + sets.pageBox).children().css({visibility: 'hidden'}); $("#" + sets.pageShow).css({visibility: 'hidden'}); $(window).Scroll_Data({ loading_box: "#" + sets.contBox, loading_distance: 100, url: sets.searchUrl, data: $("#" + sets.urlGetID).val() + _str, }); } setTimeout(function () { upwardsLocked = false }, 200) //$(window).scrollTop(0) } }); $(".loading").hide(); } }