// 澶勪簬椤甸潰閰嶇疆鏃讹紝缁戝畾鏂规硶 start if ($isDecorateMode) { document.addEventListener("diy_header/1", (event) => { const { field, value } = event.detail; console.log(field, value) if (field === 'hots') { let html = '' value.forEach(e => { html += `${e.name}` }) $('.' + field).html(html) } }); } // 澶勪簬椤甸潰閰嶇疆鏃讹紝缁戝畾鏂规硶 end $(function () { $("#logout").click(function () { $request .post("/api/user/logout") .then((res) => { // 璺宠浆椤甸潰 location.href = "/"; }); }) // 闃叉涓€寮€濮嬭繘鍏ラ〉闈㈠湪搴曢儴涓嶆樉绀� setHeaderSticky() $(window).scroll(setHeaderSticky) function setHeaderSticky(){ let offset = $("html,body").scrollTop() if (offset) { $('.ys-header').addClass('is-sticky') } else { $('.ys-header').removeClass('is-sticky') } } // 瀵艰埅鏍忔偓鍋� $('.ys-header__nav .nav-item').hover(function () { $(this).find('.ys-header__card').addClass('show') if(!$(this).hasClass('ignore')) $('.ys-header__cover').removeClass('display-none') }, function () { $(this).find('.ys-header__card').removeClass('show') $('.ys-header__cover').addClass('display-none') }) // 浜у搧涓績鎮仠 $('.ys-header__nav .product-item').hover(function () { $('.ys-header__nav .product-child').addClass('display-none') $('.ys-header__nav .product-item').removeClass('active') $(this).addClass('active') $(this).next().removeClass('display-none') }) // 鎼滅储妗嗘偓鍋滀簨浠� $('.ys-header__search').focus(function () { $('.ys-header__nav').addClass('display-none') $('.ys-header__right').addClass('open') }, function() { if (!$('.ys-header__search-card').hasClass('show')) { $('.ys-header__nav').removeClass('display-none') $('.ys-header__right').removeClass('open') } }) // 鎼滅储妗嗚仛鐒︿簨浠� $('.ys-header__search input').focus(function () { openSearchCard() }) $('.ys-header__search-card .icon-close').click(function () { closeSearchCard() }) $(document).on('click', function (e) { if (!$('.ys-header__search-card')[0].contains(e.target) && !$('.ys-header__search input').is(':focus')) { closeSearchCard() } }) // 鎼滅储 $('.ys-header__search input').keyup(function (e) { if (e.keyCode === 13) { search() } }) $('.ys-header__search .search-btn').click(function () { search() }) // 娓呯┖鍘嗗彶璁板綍 $('.ys-header__search-card .search-history span').click(function () { localStorage.removeItem('searchHistory') setHistory() }) // 灞曞紑鎼滅储鍗$墖 function openSearchCard() { $('.ys-header__nav').addClass('display-none') $('.ys-header__search-card').addClass('show') $('.ys-header__cover').removeClass('display-none') $('.ys-header__right').addClass('open') } // 鏀惰捣鎼滅储鍗$墖 function closeSearchCard() { $('.ys-header__nav').removeClass('display-none') $('.ys-header__search-card').removeClass('show') $('.ys-header__cover').addClass('display-none') $('.ys-header__right').removeClass('open') } // 鎼滅储浜嬩欢 function search() { let val = $('.ys-header__search input').val() if (!val) return $message.warning('璇疯緭鍏ユ悳绱㈠叧閿瘝') let history = JSON.parse(localStorage.getItem('searchHistory')) || [] history.unshift(val) history = [...new Set(history)] localStorage.setItem('searchHistory', JSON.stringify(history.slice(0, 10))) window.open('/search_result.html?keyword=' + val) closeSearchCard() setHistory() } // 璁剧疆鎼滅储鍘嗗彶 function setHistory() { let history = JSON.parse(localStorage.getItem('searchHistory')) || [] let html = '' history.forEach(e => { html += `${e}` }) $('.ys-header__search-card .search-history .search-words').html(html) } setHistory() }) // 瀹㈡湇 $('.ys-header-shortcut__server span').click(function(){ window.dispatchEvent( new CustomEvent('openService') ) }) // 鐐瑰嚮tabs椤� $(".ys-search__tabs").on("click", "li", function (e) { $(".ys-search__tabs li").removeClass('active') $(this).addClass('active') let type = $(this).attr('data-type') $('.ys-search__result').each(function (e) { if ($(this).attr('data-target') == type) { $(this).removeClass('display-none') } else { $(this).addClass('display-none') } }) delete params.attributes filters = [] $('.ys-product-filter-checked').remove() if (type === 'content') { result.type = $('.result-type input:checked').val() } else { result.type = type } params.page = 1 request() e.preventDefault(); }); // 鐐瑰嚮绛涢€夐」 let filters = [] $(".ys-product-filter__box").on("click", ".filter-item input[type=checkbox]", function (e) { let id = $(this).attr('id').replace('attr-','') let checked = $(this).is(":checked") let pid = $(this).parents('.filter-item').attr('data-filter_id') if (checked) { filters.push({ id, pid, title: $(this).attr('data-title') }) } else { filters.splice(filters.findIndex(i => i.id === id), 1) } handleFilterRequest() }); $(".ys-product-filter").on("click", ".ys-product-filter-checked .icon-close", function () { let id = $(this).parent().data('id') let pid = $(this).parent().data('pid') if(pid === 'category_id') { handleClearChecked($('#' + id)) }else { handleClearChecked($('#attr-' + id)) } filters.splice(filters.findIndex(e => e.id == id && e.pid == pid), 1) handleFilterRequest() }); $(".ys-product-filter").on("click", ".ys-product-filter-checked button", function () { filters = [] $('.selection-item.checked').removeClass('checked') handleClearAllChecked() handleFilterRequest() }); function handleClearAllChecked() { $('.selection-item input[type=checkbox]').prop('checked', false) } function handleFilterRequest() { params.attributes = {} filters.forEach(e => { params.attributes[e.pid] = +e.id }) params.page = 1 result.list = [] request() showFiltered() } // 鏄剧ず宸查€夌瓫閫夐」 function showFiltered() { $('.ys-product-filter-checked').remove() let html = '' filters.forEach(e => { html += `
${e.title}
` }) if (filters.length) { $('.ys-product-filter__box').before(`
${html}
`) } } // 璁剧疆绛涢€夐」options // 濡傛灉detail涓笉瀛樺湪锛屽垯绂佺敤 function setOptionsDisable(options){ if (!options || !options.length) { $('.ys-product-filter').addClass('display-none') return } $('.ys-product-filter__box').removeClass('display-none') // 灏嗕笉鍦╫ptions閲岀殑鏁版嵁鍏ㄩ儴绂佺敤 handleOptionItemDisable(options) } function handleOptionItemDisable(options){ const optionsIdMap = handleOptionsIdMap(options) $('.filter-item.options .selection-item').addClass('disable') $('.filter-item.options').each(function(){ const pid = $(this).data('filter_id') if(!optionsIdMap[pid]) return $(this).find('.selection-item').each(function(){ const item = $(this).find('input[type=checkbox]') const id = item.attr('id').replace('attr-','') if(!optionsIdMap[pid][id]) return $(this).removeClass('disable') // item.prop('checked', true) }) }) // $('.selection-item input[type=checkbox]').each(function(){ // $(this).prop('checked', false) // }) } function handleOptionsIdMap(options){ if(!Array.isArray(options) || !options.length ) return {} const idMap = {} options.forEach((e) => { if(!idMap[e.id]) idMap[e.id] = {} e.value.forEach(child => { idMap[e.id][child.id] = 1 }) }) return idMap } // 璁剧疆绛涢€夐」options function setOptions(options) { if (!options || !options.length) { $('.ys-product-filter').addClass('display-none') return } $('.ys-product-filter').removeClass('display-none') let html = '' options.forEach((e, i) => { let c_html = '' e.value.forEach(child => { c_html += `
i.pid !== 'category_id' && +i.id === child.id) ? 'checked' : ''} />
` }) html += `
${e.attribute_name}
`+ c_html + `
灞曞紑
` }) $('.ys-product-filter__box').html(html) } /******** 绛涢€夊櫒鎼滅储杩囨护 begin *********/ $('.ys-product-filter').on('input', '.filter-item-search', function(){ const text = $(this).val() const selectionItemList = $(this).parents('.filter-item').find('.selection-item') selectionItemList.each(function(i,e){ const current = $(e).find('label>span').text() if(!queryMatch(text, current)){ $(e).addClass('display-none') return } $(e).removeClass('display-none') }) }) function queryMatch(query, current) { let parsedQuery = String(query).replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, '\\$1'); const visible = new RegExp(parsedQuery, 'i').test(current); return visible; } /******** 绛涢€夊櫒鎼滅储杩囨护 end *********/ /******** 绛涢€夊櫒閲嶇疆鎸夐挳 begin *********/ $('.ys-product-filter').on('click', '.filter-item-reset', function(){ const parent = $(this).parent() const pid = parent.data('filter_id') parent.find('.selection-item input[type=checkbox]').prop('checked', false) parent.find('.selection-item.checked').removeClass('checked') filters = filters.filter(e => e.pid != pid) handleFilterRequest() }) function handleClearChecked(item){ if(!item) return item.prop('checked', false) } /******** 绛涢€夊櫒閲嶇疆鎸夐挳 end *********/ /******** 绛涢€夊櫒 swiper begin *********/ const filterSwiper = new Swiper(".ys-product-filter__box", { slidesPerView: "auto", // scrollbar: ".swiper-scrollbar", scrollbarHide: false, mousewheelControl: false, scrollbarDraggable: true, noSwipingSelector: 'input,label,button,.selection-item', scrollbar: { el: '.swiper-scrollbar', draggable: true }, }) function updateFilterSwiper() { filterSwiper.update() filterSwiper.onResize(); } /******** 绛涢€夊櫒 swiper end *********/ const params = { page: 1, pageSize: 8, keyword: '' } const result = { total: 0, list: [], has_more: false, type: 'product' } params.keyword = parsePath(window.location).query.keyword if ($('.product-table-item').length) { $(".c-pagination").zPager({ totalData: +$('.ys-search__result[data-target="product"]').find('.result-num span').text(), pageStep: 5, current: params.page, pageData: params.pageSize }) } // 鍒嗛〉 function currentPage(currentPage) { if (params.page === currentPage) return params.page = currentPage request() } function changePager(sizes) { params.pageSize = sizes params.page = 1 result.list = [] request() } // 鎼滅储浜嬩欢 $(".ys-search").on("click", ".ys-search__input i", function (e) { let val = $(this).parent().find('input').val() search(val) }); $(".ys-search").on("keyup", ".ys-search__input input", function (e) { let val = $(this).val() if (e.keyCode === 13) { search(val) } }); function search(query) { if (!query) return $message.warning('璇疯緭鍏ユ悳绱㈠叧閿瘝') location.href = location.pathname + `?keyword=${query}` // 1/11璋冩暣锛氭墽琛屾悳绱㈢殑鏃跺€欙紝璺敱涓€璧锋敼鍙� // $('.ys-search__title').html('姝e湪鎼滅储鈥�' + e + '鈥�') // params.keyword = e // params.page = 1 // request() } function request() { $loading.start() $request .post("/api/search/" + result.type, params) .then((res) => { if(res.data.redirect_url) { window.location.href = res.data.redirect_url return; } result.list = params.page === 1 || result.type === 'product' ? res.data.list : result.list.concat(res.data.list) result.total = res.data.total result.has_more = res.data.has_more $('.ys-search__result .result-num span').html(res.data.total) $('.ys-search__empty').remove() let html = '' $('.ys-search__result').each(function() { if ($(this).attr('data-target') === result.type) { $(this).removeClass('display-none') } }) if (result.type === 'content') { $('.ys-search__result[data-target="product"]').addClass('display-none') $('.ys-search__solution').css('display', 'none') $('.ys-search__article').css('display', 'block') result.list.forEach(content => { html += `
${content.title}

${content.title}

${content.tags.length ? ` `:''}

${content.abstract}

${content.publish_time} ${content.clicks}

` }) if(result.list.length) { $('.ys-search__result[data-target="content"]').removeClass('display-none') if (!$('.ys-search__result[data-target="content"]').find('.ys-search__slide').length) { $('.ys-search__article').before('
') } } $('.ys-search__article').html(html) } else if (result.type === 'solution') { $('.ys-search__result[data-target="product"]').addClass('display-none') $('.ys-search__article').css('display', 'none') $('.ys-search__solution').css('display', 'flex') result.list.forEach(sector => { html += `
${sector['title']}

${sector['title']}

${sector['abstract']}

` }) if(result.list.length) { $('.ys-search__result[data-target="content"]').removeClass('display-none') if (!$('.ys-search__result[data-target="content"]').find('.ys-search__slide').length) { $('.ys-search__article').before('
') } } $('.ys-search__solution').html(html) } else { $('.ys-search__result[data-target="content"]').addClass('display-none') result.list.forEach(e => { html += ` ${e.name} ${e.sku_code}

${e.name}

${ e.paper_2d ? ` ` : `` } ${ e.paper_3d ? ` ` : `` } ` }) $('.ys-search__product .ys-product__table').html(` 鍟嗗搧鍥剧墖 鐗╂枡缂栫爜 鐗╂枡鍚嶇О 2D鍥剧焊 3D鍥剧焊 璇环 `+ html + ` `) $('.ys-search__result button span').html(compare_skus.length + '/' + $('.ys-search__product .product-table-item').length) if (!result.list.length) { $('.ys-search__result[data-target="product"]').addClass('display-none') } else { $('.ys-search__result[data-target="product"]').removeClass('display-none') $(".c-pagination").zPager({ totalData: result.total, pageStep: 5, current: params.page, pageData: params.pageSize }) } setOptionsDisable(res.data.options) } if (!result.list.length) { $('.ys-search__slide').remove() $('.ys-search').append(`
鏆傛棤鍐呭

鎶辨瓑锛屾病鏈夋壘鍒扮浉鍏崇殑鍐呭

鎶辨瓑锛屾病鏈夋壘鍒扮浉鍏崇殑鍐呭

`) } }).finally(() => { $loading.end() }) } // 鍒囨崲璧勮/瑙e喅鏂规 $(".ys-search__result").on("click", ".result-type input", function (e) { result.type = $(this).val() params.page = 1 request() }); // 婊氬姩鍒板簳閮� $(window).scroll(function () { if (result.type === 'product') return if ($(document).scrollTop() + 400 >= $(document).height() - $(window).height()) { if (result.has_more && !$loading.status) { params.page++ request() } } }) // 鐐瑰嚮琛ㄦ牸琛岋紙閫変腑/鍙栨秷閫変腑锛� let compare_skus = [] $(".ys-search__result").on("click", ".product-table-item input", function (e) { let checked = $(this).is(":checked") if (checked) { compare_skus.push($(this).attr('id')) } else { compare_skus.splice(compare_skus.findIndex(e => e === $(this).attr('id')), 1) } $('.ys-search__result button span').html(compare_skus.length + '/' + $('.product-table-item').length) $('.ys-product__action .batch-action-num i').text(compare_skus.length) if (compare_skus.length) { $('.ys-search__result button').removeClass('disabled') $('.ys-product__action').addClass('active') } else { $('.ys-search__result button').addClass('disabled') $('.ys-product__action').removeClass('active') } }); // 寮€濮嬪姣旀寜閽� $(".ys-search__result").on("click", ".ys-search__num button", function (e) { if (!compare_skus.length) return if (compare_skus.length < 2) return $message.info("璇疯嚦灏戦€夋嫨涓ょ鐗╂枡") window.open('/compare.html?sku_code=' + compare_skus.join(',')) }); $(".ys-search__result").on("click", ".ys-search__num button div", function (e) { compare_skus = [] $('.product-table-item').each(function() { $(this).find('input').prop('checked', false) }) $('.ys-search__result button span').html(compare_skus.length + '/' + $('.product-table-item').length) $('.ys-search__result button').addClass('disabled') $('.ys-product__action .batch-action-num i').text(compare_skus.length) $('.ys-product__action').removeClass('active') e.preventDefault(); }); // 淇濆瓨鑷虫竻鍗� $('.ys-search__product').on('click', '.save-sku', function (e) { if (!$isLogin) { $message.info('璇峰厛鐧诲綍') return } let sku_id = $(this).attr('data-id') $request.post('/api/user/collect', { sku_id }).then((res) => { $message.success('淇濆瓨鎴愬姛') }) }) // 鎵归噺淇濆瓨鑷虫竻鍗� $('.ys-product__action .batch-action-save').on('click', function (e) { if (!$isLogin) { $message.info('璇峰厛鐧诲綍') return } $request .post('/api/user/collect', { sku_id: $('.product-table-item:has(input:checked) .save-sku') .map(function () { return $(this).data('id') }) .toArray(), }) .then((res) => { $message.success('淇濆瓨鎴愬姛') // 鍙栨秷閫夋嫨 $(".product-table-item input[type='checkbox']").prop('checked', false) }) }) // 瀹㈡湇 $('.ys-product__table').on('click', '.product-table-enquiry', function() { window.dispatchEvent( new CustomEvent('openService') ) }) /* 鍩嬬偣鏂规硶 start */ $(function() { productViewListItem() // 鎼滅储鍒楄〃灞曠ず productSelectItemClick() // 鎼滅储鍒楄〃鐐瑰嚮 }) const ItemListId = 'search_products_list'; // ga view_item_list 鍒楄〃id const ItemListName = 'Search products list';// ga view_item_list 鍒楄〃鍚嶇О function productViewListItem() { const itemsInfoList = getProductListInfo({from_search: $('.ys-search__title > span').text()}) if(!Array.isArray(itemsInfoList) || !itemsInfoList.length) return const ecommerceListObj = { event: "view_item_list", ecommerce: { item_list_id: ItemListId, item_list_name: ItemListName, items: itemsInfoList, } } customEventLog('ecommerce', ecommerceListObj, {onlyTrack: ["DataLayerTracker"]}) } function getProductListInfo(otherInfo = {}) { const itemInfoList = [] $('.ys-search__product .product-table-item').each(function (index, value) { const colsEle = $(this).children("td"); const item = { item_id: colsEle.eq(1).find('a').text(), item_name: colsEle.eq(2).find('.product-table-desc').text(), index: index + 1, item_list_id: ItemListId, item_list_name: ItemListName, ...otherInfo || {} // 鍏朵粬鑷畾涔夊睘鎬� 涓昏涓� {from_search: 鎼滅储璇峿 鍒嗚鲸鏄惁缁忚繃杩囨护 } itemInfoList.push(item) }) return itemInfoList } // 鍒楄〃鐐瑰嚮鍟嗗搧 function productSelectItemClick() { $('.ys-search__product').on('click', '.product-table-img', productSelectItem) $('.ys-search__product').on('click', '.product-table-item > .product-table-cell:nth-child(2) a', productSelectItem) $('.ys-search__product').on('click', '.product-table-item > .product-table-cell:nth-child(3) a', productSelectItem) } function productSelectItem() { const tableItemEle = $(this).parents('.product-table-item') const colsEle = tableItemEle.children("td") const ecommerceItemObj = { event: "select_item", ecommerce : { item_list_id: ItemListId, item_list_name: ItemListName, items: [{ item_id: colsEle.eq(1).find('a').text(), item_name: colsEle.eq(2).find('.product-table-desc').text(), index: tableItemEle.index() + 1, item_list_id: ItemListId, item_list_name: ItemListName, from_search: $('.ys-search__title > span').text() }] } } customEventLog('ecommerce', ecommerceItemObj, {onlyTrack: ["DataLayerTracker"]}) } // 鍥剧焊鐐瑰嚮 $('.ys-search__result').on('click', '.product-table-draw', function() { const drawEle = $(this) const tableItemEle = drawEle.parents('.product-table-item') const colsEle = tableItemEle.children("td") const drawInfo = { draw_type: drawEle.attr('title') === '2D鍥剧焊' ? '2d' : '3d', // 鍥剧焊绫诲瀷 draw_event_type: 'preview', // 浜嬩欢绫诲瀷 draw_item_id: colsEle.eq(1).find('a').text(), // sku draw_item_name: colsEle.eq(2).find('.product-table-desc').text(), // name from_list_name: ItemListName // 鍒楄〃鍚嶇О } customEventLog("set", { key:'clue', value:'click_draw_list'}, {onlyTrack: ["ClarityTracker"]}); // clarity鏍囩 customEventLog('click_draw', drawInfo, {onlyTrack: ["DataLayerTracker"]}) }) /* 鍩嬬偣鏂规硶 end */ // 澶勪簬椤甸潰閰嶇疆鏃讹紝缁戝畾鏂规硶 if ($isDecorateMode) { document.addEventListener('diy_footer/1', (event) => { const { field, value } = event.detail console.log(field, value) if (field === 'footer_ad') { const nodes = $( value .map((item) => `${item.alt}`) .join('') ) $('.ys-footer__ad').empty() $('.ys-footer__ad').append(nodes) } else if (field === 'contact_phone') { $('.footer_phone').text(value) } else if (field === 'work_time') { $('.footer_work_time').text(value) } else if (field === 'contact_email') { $('.footer_email').text(value) } else if (field === 'footer_nav') { const nodes = $( value .map( (c) => ` ` ) .join('') ) $('.ys-footer__content .center-part').empty() $('.ys-footer__content .center-part').append(nodes) } else if (field === 'right_part') { const nodes = $( value .map((item) => `${item.alt}`) .join('') ) $('.ys-footer__content .right-part').empty() $('.ys-footer__content .right-part').append(nodes) } else if (field === 'friendly_links') { const nodes = $( value .map( (e) => `
  • ${e.title}
  • ` ) .join('') ) $('.ys-footer__friendly ul').empty() $('.ys-footer__friendly ul').append(nodes) } else if (field === 'copyright') { $('.copyright-wrap span').text(value) } else if (field === 'beian') { $('.copyright-wrap a').text(value) } else if (field === 'footer_logo') { $('.footer-logo').attr('alt', value.alt) $('.footer-logo').attr('src', value.src) } else if (field === 'map_links') { const nodes = $( value .map( (e) => ` ${e.title} ` ) .join('') ) $('.ys-footer__end .end-link').empty() $('.ys-footer__end .end-link').append(nodes) } }) } window.addEventListener('openService', openService) // 鐩戝惉鍏ㄥ眬瀹㈡湇鐐瑰嚮浜嬩欢 $('#backTop').click(function () { $('html, body').animate({ scrollTop: 0 }, 300) }) $('.ys-rightNav .online-serve').click(function() { openService() }) // 鎵撳紑瀹㈡湇寮圭獥 function openService() { if ($('#aff-im-root .embed-icon-pcIcon5').length > 0) { $('#aff-im-root .embed-icon-pcIcon5').click() } else { $('#newBridge .nb-icon-wrap').click() } customEventLog("open_server"); // 鎵撶偣 customEventLog("set", { key:'purchase', value:'service'}, {onlyTrack: ["ClarityTracker"]}); // clarity鏍囩 } // 鐩戝惉椤甸潰婊氬姩 $(window).scroll(function () { $('.ys-rightNav #backTop').css('display', $(document).scrollTop() ? 'block' : 'none') })