console.dir('load') window.bexSource = 39; if(typeof window.$ === 'undefined') window.$ = window.jQuery; window.BEXCatchProduct = () => { let products = []; let urlExp = /[http(s):]?\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; $('.contents_').each(function (index, item) { let item_image = $(item).find('#gallery .src_l_ img').attr('src'); if(typeof item_image === 'undefined') item_image = $(item).find('#etc_goodsimg_slider_control .etc_goodsimg_slider_control_item_:first img').attr('src'); let item_attribute = []; if($(item).find('.sizewrap_').css('display') !== 'none' && $(item).find('#sizeline').length > 0){ item_attribute.push($.trim($(item).find('#sizeline').find('.sizeitem_.active_ .sizeitem_bottom_').text())) } if($(item).find('.color_').css('display') !== 'none' && $(item).find('#colorline').length > 0){ item_attribute.push($.trim($(item).find('#colorline').find('.coloritem_.active_ .overlay_').text())) } let productDetail = { item_code: index + 1, item_num: 1, item_attribute: item_attribute.join(';'), item_price: parseInt($(item).find('.spec_price .price_ .value_').text().replace(/[^(0-9)(\.)]/ig, "")), item_name: $.trim($(item).find('h1.goods_name_').text()), 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: urlExp.test(item_url) ? item_url : window.location.protocol + '//' + window.location.host + item_url, item_url: location.href, } if(productDetail.item_price && productDetail.item_name) products.push(productDetail); console.dir(productDetail); }); return products; } 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') 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(){ let products = window.BEXCatchProduct(); 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)); }, })) 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('bexSourceLogo',false); Alpine.store('bexLanguage',localStorage.getItem('bexLanguage') ?? 'en'); Alpine.store('bexLanguageText',localStorage.getItem('bexLanguageText') ?? 'English'); }) window.bexShowCartDetail = function(){ Alpine.store('bexConfirmShow', false); Alpine.store('cartMiniShow', false); Alpine.store('cartDetailShow', true); Alpine.store('cartToolShow', 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(typeof window.BEXMatchProductPage === 'function'){ if(window.BEXMatchProductPage()){ $('body').append(res.confirm_html); $('body').append(res.cart_html); }else{ $('body').append(res.alert_html); } }else{ if(window.location.href.indexOf(res.source_info.cart_page_url) !== -1){ $('body').append(res.confirm_html); $('body').append(res.cart_html); }else{ $('body').append(res.alert_html); } } } } }) });