// 处于页面配置时,绑定方法 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') $('.ys-header__cover').removeClass('display-none') }, function () { $(this).find('.ys-header__card').removeClass('show') $('.ys-header__cover').addClass('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() // 熊猫体育官网首页入口 tabs切换 const moreTypeList = ['information', 'catalog'] // 存在 more 的类型 $('.service-cate li').hover(function () { let type = $(this).attr('data-type') if (type) { $('.service-cate li').removeClass('active') $(this).addClass('active') $('.ys-header__service .content-item').addClass('display-none') $('.ys-header__service .content-item[data-type='+type+']').removeClass('display-none') if(moreTypeList.includes(type)){ $('.service-content-more').not('.' + type).addClass('display-none') $('.service-content-slide').removeClass('display-none') $('.service-content-more.' + type).removeClass('display-none') } else { $('.service-content-more').addClass('display-none') $('.service-content-slide').addClass('display-none') } } }) // 关于我们tabs切换 $('.about-cate-item').hover(function () { let type = $(this).attr('data-type') if (type) { $('.about-cate-item').removeClass('active') $(this).addClass('active') $('.about-content .about-item').addClass('display-none') $('.about-content .about-item[data-type='+type+']').removeClass('display-none') // 用于切换底部更多链接跳转,现在没有更多,如果需要参考上方取消注释 /* $('.about-content-slide').addClass('display-none') $('.about-content-more').addClass('display-none') */ } }) }) // 搜索 $(".ys-product-search").on("click", "span", function (e) { let val = $(this).parent().find('input').val() search(val) }); $(".ys-product-search").on("keyup", "input", function (e) { let val = $(this).val() if (e.keyCode === 13) { search(val) } }); function search(val) { if (!val) return $message.warning('请输入搜索关键词') window.open('/search_result.html?keyword=' + val,'_self') customSearchLog(val) // 埋点,搜索词记录 } /* 埋点 start */ // 搜索词记录 function customSearchLog(searchVal) { if(!searchVal) return const searchEventObj = { 'event' : 'search', 'searchTerm' : searchVal } customEventLog('search', searchEventObj, {onlyTrack: ["DataLayerTracker"]}) } /* 埋点 end */ $('.search-input').change(function (event) { // 输入之后路由跳转 const value = $(event.target).val() if (value) { location.href = location.origin + location.pathname + `?name=${value}` } else { location.href = location.origin + location.pathname } }) $(function () { window.addEventListener('spu_search', topSearch) // 监听搜索事件 window.addEventListener('product_filter', filter) // 监听筛选结果 window.addEventListener('pager_change', pagerChange) // 监听分页条数变化 window.addEventListener('current_page', currentPage) // 监听页码变化 const params = { page: 1, pageSize: 8, attributes: {}, keyword: '' } const result = { type: -1, total: 0, list: [] } let filters = [] function topSearch(e) { params.keyword = e.detail params.page = 1 result.list = [] request() } function filter(e) { filters = e.detail.filters if (e.detail.category_id) params.category_id = e.detail.category_id params.attributes = {} filters.forEach(e => { if (e.pid === 'category_id') { params.category_id = +e.id.slice(1) } else { params.attributes[e.pid] = +e.id } }) params.page = 1 result.list = [] request() } function pagerChange(e) { params.pageSize = e.detail params.page = 1 result.list = [] request() } function currentPage(e) { if (e.detail == params.page) return params.page = e.detail request() } function request() { result.type = filters.find(e => e.type == 1) ? 1 : 0 if (params.category_id == 0) params.category_id = null $loading.start() $request .post("/api/goods/filter-products", params) .then((res) => { if(res.data.redirect_url) { window.location.href = res.data.redirect_url return; } let filter = { options: res.data.options, categorys: res.data.categorys } window.dispatchEvent( new CustomEvent('product_options', { detail: filter }) ) $('.ys-product').remove() let html = '' if ((result.type === 0 && res.data.spus.total > 1) || !res.data.skus.list.length) { $('.ys-product__sku').css('display', 'none') result.list = params.page === 1 ? res.data.spus.list : result.list.concat(res.data.spus.list) result.total = res.data.spus.total let search_html = `
抱歉,没有找到相关的内容
抱歉,没有找到相关的内容
客服电话:15016918160
抱歉,没有找到相关的内容
抱歉,没有找到相关的内容