console.dir('load') window.bexSource = 53; if(typeof window.$ === 'undefined') window.$ = window.jQuery; window.bexSourceInfo = {}; var bexProductsData = JSON.parse(localStorage.getItem('bexProductsData') ?? '[]'); for(let i in bexProductsData){ if(bexProductsData[i].expire < Date.now()) bexProductsData.slice(i,1); } localStorage.setItem('bexProductsData',JSON.stringify(bexProductsData)); document.addEventListener('alpine:init', () => { console.dir('alpine:init') let bexAlertCloseExpire = localStorage.getItem('bexAlertCloseExpire'); if(bexAlertCloseExpire && bexAlertCloseExpire > Date.now()){ Alpine.store('bexAlertShow', false); }else{ Alpine.store('bexAlertShow', true); } Alpine.store('bexConfirmShow', false); Alpine.store('cartMiniShow', false); Alpine.store('cartDetailShow', false); Alpine.store('cartToolShow', true); Alpine.store('cartSelectOptionShow', false); Alpine.store('cartSelectOptions', []); Alpine.store('bexSourceLogo',false); Alpine.store('bexLanguage',localStorage.getItem('bexLanguage') ?? 'en'); Alpine.store('bexLanguageText',localStorage.getItem('bexLanguageText') ?? 'English'); Alpine.data('bexInit', () => ({ //语言包部分 bexLanguageBoxOpen:false, setLanguage:function(lang,langText){ localStorage.setItem('bexLanguage',lang); localStorage.setItem('bexLanguageText',langText); this.bexLanguageBoxOpen = false; Alpine.store('bexLanguage', lang); Alpine.store('bexLanguageText', langText); }, //购物车部分 bexProducts:bexProductsData, deleteProduct(index){ this.bexProducts.splice(index,1) localStorage.setItem('bexProductsData',JSON.stringify(this.bexProducts)); }, addProduct(step = 1,option = {}){ Alpine.store('cartSelectOptionShow', false); Alpine.store('cartSelectOptions', []); // https://www.fitpartner.jp/ 需要弹窗显示规格筛选 const _bex_product_price = $('meta[property="product:price:amount"]') ? $('meta[property="product:price:amount"]').attr('content').toString().replace(/[^(0-9)(\.)]/ig, "") : parseInt($('.FS2_itemPrice_text .itemPrice').text().replace(/[^(0-9)(\.)]/ig, "")) const _bex_product_name = $('meta[property="og:title"]').attr('content').toString(); if(step === 1){ //判断是否多规格 if( $('.FS2_additional_image_tableVariation_table tbody tr').length > 0) { let bex_options = []; var bex_option_base = ''; $('.FS2_additional_image_tableVariation_table tbody tr').each(function () { if ($(this).find('th').text().trim()) { bex_option_base = $(this).find('th').text().trim(); } let bex_option_other = $(this).find('td:first').text().trim(); let submitBtn = $(this).find('td:last'); // 如果尺寸不包含"SOLDOUT",则添加到商品属性数组中 if (!bex_option_other.includes('SOLDOUT') || !submitBtn) { bex_options.push({ label: bex_option_base + (bex_option_other ? ' - ' + bex_option_other : ''), price: null }); } }); Alpine.store('cartSelectOptionShow', true); Alpine.store('cartSelectOptions', bex_options); }else if($('#FS2_Variation_cartbutton').length > 0){ let bex_options = []; var bex_option_base = ''; $('#FS2_Variation_cartbutton .FS2_VariationValueList').each(function () { bex_option_base = $(this).find('h2').text().trim(); $(this).find('li').each(function(){ let _this = $(this); let bex_option_other = _this.find('.FS2_Variation_value').text().trim(); let submitBtn = _this.find('.FS2_Button_container'); // 如果尺寸不包含"SOLDOUT",则添加到商品属性数组中 if (!submitBtn || !_this.find('.FS2_Variation_stock').text().trim()) { bex_options.push({ label: bex_option_base + (bex_option_other ? ' - ' + bex_option_other : ''), price: null }); } }) }); Alpine.store('cartSelectOptionShow', true); Alpine.store('cartSelectOptions', bex_options); }else{ this.addProduct(2,{ label:_bex_product_price, price:_bex_product_name }) } }else{ let products = []; let urlExp = /[http(s):]?\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; let item_image = $('meta[property="og:image"]').attr('content').toString(); let productDetail = { item_code: $('input[name="goodsId"]').val(), item_num: 1, item_attribute: option.label ?? '', item_price: _bex_product_price, item_name: _bex_product_name, item_img: urlExp.test(item_image) ? ((item_image.indexOf('http:') === 0 || item_image.indexOf('https:') === 0 ) ? item_image : 'https:'+item_image) : window.location.protocol + '//' + window.location.host + item_image, item_url: location.href, } if(productDetail.item_price && productDetail.item_name) products.push(productDetail); console.dir(productDetail); if(products.length > 0){ Alpine.store('bexConfirmShow', true); Alpine.store('cartMiniShow', false); Alpine.store('cartDetailShow', false); Alpine.store('cartToolShow', true); for(let j in this.bexProducts){ for(let i in products){ if( products[i].item_url === this.bexProducts[j].item_url && products[i].item_name === this.bexProducts[j].item_name && products[i].item_price === this.bexProducts[j].item_price && products[i].item_attribute === this.bexProducts[j].item_attribute ){ this.bexProducts[j].item_num = parseInt(this.bexProducts[j].item_num+products[i].item_num); this.bexProducts[j].item_img = products[i].item_img; products.splice(i,1) } } } for(let i in products){ products[i].expire = Date.now()+(2*60*60*1000) this.bexProducts.push(products[i]) } localStorage.setItem('bexProductsData',JSON.stringify(this.bexProducts)); }else{ console.dir('ERROR') } } }, submitCart(){ let _this = this; $.ajax({ url:'https://benlyexpress.com/shopextend/index/cartDataSave', method:"POST", data:{cartData:this.bexProducts,lang:localStorage.getItem('bexLanguage') ?? 'en'}, dataType: 'json', success:function(rs){ if(rs.code==0) { //清除数据 _this.bexProducts = []; localStorage.removeItem('bexProductsData'); Alpine.store('cartMiniShow', false); Alpine.store('cartDetailShow', false); Alpine.store('cartToolShow', true); window.open(rs.redirect_url+'&source='+window.bexSource) }else{ console.dir(rs.msg); } }, error:function(rs){ console.dir("Network Error."); } }) }, editNum(index,type){ if(this.bexProducts[index]){ if(type == 1 && this.bexProducts[index].item_num === 1) this.bexProducts.splice(index,1) else{ let item_num_ = this.bexProducts[index].item_num; item_num_ = type === 1 ? item_num_-1 : item_num_+1; this.bexProducts[index].item_num = item_num_; } } localStorage.setItem('bexProductsData',JSON.stringify(this.bexProducts)); }, })) }) window.bexShowCartDetail = function(){ Alpine.store('bexConfirmShow', false); Alpine.store('cartMiniShow', false); Alpine.store('cartDetailShow', true); Alpine.store('cartToolShow', false); Alpine.store('cartSelectOptionShow', false); } $(function(){ $.ajax({ url:'https://benlyexpress.com/shoppulgin/index/data', data:{lang:"en",source:window.bexSource}, dataType: 'json', success:function(res){ if(res.hasOwnProperty('enable') && res.enable === true){ window.bexSourceInfo = res.source_info; Alpine.store('bexSourceLogo',res.source_info.logo ?? false); if($('meta[property="og:type"][content="product"]').length > 0){ $('body').append(res.confirm_html); $('body').append(res.cart_html); $('body').append(res.select_option_html); }else{ $('body').append(res.alert_html); } } } }) });