2024 - Flycurvy  2024 - Flycurvy
(function () { class SPZCustomMbFilter extends SPZ.BaseElement { constructor(element) { super(element); // 模板代码, 按需复制 this.xhr_ = SPZServices.xhrFor(this.win); this.action_ = SPZServices.actionServiceForDoc(this.element); this.templates_ = SPZServices.templatesForDoc(this.element); } isLayoutSupported(layout) { // 支持的 layout 类型, 若无界面, 限定 "logic" return layout === 'logic'; } buildCallback() { this.setupAction_(); } trigger_(name, data) { const event = SPZUtils.Event.create(this.win, 'spz-custom-mb-filter.${name}', { data }); this.action_.trigger(this.element, name, event); } setupAction_() { // 注册 spz 方法, 这里是供其他组件事件中调用的方法 this.registerAction('select', (invocation) => { const data = {}; const mbFilter = document.querySelector('.custom_solution_size_filter_modal'); const checked = mbFilter.querySelectorAll('div[selected="true"]'); let resultStr = '' checked.forEach(ele=>{ resultStr = resultStr + ',' + ele.getAttribute('value'); }); const resultArr = resultStr.split(',').filter(ele=>!!ele); data.selectedOptions = resultArr; data.values = [resultArr[0]]; data.targetOption = resultArr[resultArr.length-1]; this.trigger_('select', data); }); } mountCallback() { // } } SPZ.defineElement('spz-custom-mb-filter', SPZCustomMbFilter); })()
438 Products
438 Products
(function () { class SPZCustomMarketImage extends SPZ.BaseElement { constructor(element) { super(element); // 模板代码, 按需复制 this.element = element; this.xhr_ = SPZServices.xhrFor(this.win); this.action_ = SPZServices.actionServiceForDoc(this.element); this.templates_ = SPZServices.templatesForDoc(this.element); } isLayoutSupported(layout) { return true; } buildCallback() { this.setupAction_(); } getParams(url) { url = url || window.location.href; var params = {}; url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (str, key, value) { try { var decodeValue = decodeURIComponent(value); var decodeKey = decodeURIComponent(key); if (params[decodeKey]) { params[decodeKey].push(decodeValue); }else{ params[decodeKey] = [decodeValue]; }; } catch (e) { params[key] = [value]; } }); return params; }; insertMarket(){ const market_img = "e7a6ea39c21834f138407733bcdb99b6.png"; const custom_img = document.querySelector('.custom_solution_insert_market_img'); if(custom_img){ custom_img.remove(); } // 带有筛选条件不展示 if(!market_img || location.search.includes('filter.v')) { return; }; const settings = JSON.parse(this.element.dataset.settings); const allProdCount = Number(438); const countPerPage = Number(settings.count); let market_img_index = Number(settings.market_img_index); if(market_img_index > allProdCount){ market_img_index = allProdCount; } const locatePage = market_img_index === 0 ? 1 : Math.ceil(market_img_index / countPerPage); const params = this.getParams(); // console.info('[params]', params ) let curPage = Number(params['page'] ? params['page'][0] : 1); if(countPerPage > allProdCount){ curPage = 1 } const container = document.querySelector('spz-list.collection-products-wrapper'); const insertImg = document.querySelector('.custom_insert_market_img'); if(!container || insertImg) return; const products = container.querySelectorAll('.shoplazza-product-snippet'); const pagination_type = "number"; this.templates_.findAndRenderTemplate(this.element, { value: {} }).then(el => { // 保存当前模板信息 this.templateBuilt = el; const imgWrapper = el; // 滚动加载 点击加载 if(pagination_type === 'scroll' || pagination_type === "click" ){ if( market_img_index < products.length ){ let referenceNode = products[market_img_index - 1]; if(referenceNode){ referenceNode = referenceNode.nextSibling }else{ referenceNode = products[0] } container.insertBefore(imgWrapper, referenceNode) }else if(market_img_index == products.length ){ container.append(imgWrapper); } return; } // 分页加载 if( Number(locatePage) == Number(curPage)){ const container = document.querySelector('spz-list.collection-products-wrapper'); if(container){ //console.info('market_img_index', market_img_index, products.length); let curPageMarketIndex = market_img_index - (curPage-1) * countPerPage; if(curPageMarketIndex >= products.length){ container.append(imgWrapper); }else{ let referenceNode = products[curPageMarketIndex - 1]; if(referenceNode){ referenceNode = referenceNode.nextSibling }else{ referenceNode = products[0] } container.insertBefore(imgWrapper, referenceNode) } } } }); } setupAction_() { // 注册 spz 方法, 这里是供其他组件事件中调用的方法 this.registerAction('insertmarketImg', (invocation) => { this.insertMarket(); }); } mountCallback() { this.insertMarket(); // } } SPZ.defineElement('spz-custom-market-image', SPZCustomMarketImage); })()