// 处于页面配置时,绑定方法 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')
)
})
// 搜索
$(".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.dispatchEvent(
new CustomEvent('spu_search', {
detail: val
})
)
customSearchLog(val)
}
/* 埋点 start */
function customSearchLog(searchVal) {
if(!searchVal) return
const searchEventObj = {
'event' : 'search',
'searchTerm' : searchVal
}
customEventLog('search', searchEventObj, {onlyTrack: ["DataLayerTracker"]})
}
/* 埋点 end */
$(document).ready(function() {
handleClearAllChecked()
})
// 点击筛选项
let filters = []
$(".ys-product-filter__box").on("click", ".filter-item input[type=checkbox]", function (e) {
let id = $(this).attr('id').replace('attr-','')
// 如果第一个就是勾选了分类,则直接跳转分类
// if(filters.length === 0 && id.startsWith('c')) {
// location.href = `/category/${$(this).data('title')}.html`
// return
// }
let checked = $(this).is(":checked")
let type = $(this).parents('.filter-item').attr('data-filter_target')
let pid = $(this).parents('.filter-item').attr('data-filter_id')
if (checked) {
let i = filters.findIndex(i => i.pid === 'category_id')
if (i > -1 && pid === 'category_id') {
filters[i] = {
id,
pid,
type,
title: $(this).attr('data-title')
}
} else {
filters.push({
id,
pid,
type,
title: $(this).attr('data-title')
})
}
$(this).parents('.selection-item').addClass('checked')
} else {
filters.splice(filters.findIndex(i => i.id === id), 1)
$(this).parents('.selection-item').removeClass('checked')
if(pid === 'category_id') {
handleClearCategory()
}
}
filterEvent()
});
$(".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))
handleClearCategory()
}else {
handleClearChecked($('#attr-' + id))
}
filters.splice(filters.findIndex(e => e.id == id && e.pid == pid), 1)
filterEvent()
});
$(".ys-product-filter").on("click", ".ys-product-filter-checked button", function () {
filters = []
$('.selection-item.checked').removeClass('checked')
handleClearAllChecked()
filterEvent()
});
function handleClearAllChecked() {
$('.selection-item input[type=checkbox]').prop('checked', false)
}
// 筛选事件
function filterEvent() {
let params = {
filters
}
if ($('.ys-product-filter').attr('data-category_id')) {
params.category_id = $('.ys-product-filter').attr('data-category_id')
}
window.dispatchEvent(
new CustomEvent('product_filter', {
detail: params
})
)
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}
`)
}
}
$(function () {
window.addEventListener('product_options', setOptionsDisable) // 监听筛选项变化事件
window.addEventListener('product_options_init', setOptionsInit) // 处理筛选器默认禁用
// 初始化已筛选的值
function setOptionsInit(event) {
if(!Array.isArray(event.detail) || !event.detail.length) return
filters = event.detail
showFiltered()
}
// 设置筛选项options
// 如果detail中不存在,则禁用
function setOptionsDisable(event){
// if (!event.detail || !event.detail.options || !event.detail.options.length) {
// $('.ys-product-filter__box').addClass('display-none')
// return
// }
$('.ys-product-filter__box').removeClass('display-none')
if (event.detail.categorys) {
$('.filter-item.category .selection-item').addClass('disable')
event.detail.categorys.forEach(e => {
$('#c' + e.id).parents('.selection-item').removeClass('disable')
})
}
// 将不在options里的数据全部禁用
handleOptionItemDisable(event.detail.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(event) {
if (!event.detail || !event.detail.options || !event.detail.options.length) {
$('.ys-product-filter__box').addClass('display-none')
return
}
$('.ys-product-filter__box').removeClass('display-none')
let html = ''
if (event.detail.categorys) {
let c_html = ''
event.detail.categorys.forEach(e => {
c_html += `
i.pid === 'category_id' && i.id === 'c' + e.id) ? 'checked' : ''} />
`
})
html += `
`
}
event.detail.options.forEach((e, i) => {
let c_html = ''
e.value.forEach(child => {
c_html += `
i.pid !== 'category_id' && +i.id === child.id) ? 'checked' : ''} />
`
})
html += `
`
})
$('.ys-product-filter__box .swiper-wrapper').html(html)
updateFilterSwiper()
}
})
/******** 筛选器选中关闭 begin *********/
// 防止分类只能筛选单个分类
function handleClearCategory(){
$('.ys-product-filter').attr('data-category_id', '0')
}
/******** 筛选器选中关闭 end *********/
/******** 筛选器搜索过滤 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)
if(pid === 'category_id') {
handleClearCategory()
}
filterEvent()
})
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 *********/
$('.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('product_filter', filter) // 监听筛选结果
window.addEventListener('pager_change', pagerChange) // 监听分页条数变化
window.addEventListener('current_page', currentPage) // 监听页码变化
$('.ys-product__sku .ys-product__search').css('display', 'none')
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 initPagination() {
const pagination = $('.ys-product__sku .c-pagination-nav').data()
$(".c-pagination").html('')
$(".c-pagination").zPager({
totalData: pagination.total,
pageStep: 5,
current: pagination.page,
pageData: pagination.pageSize
})
}
initPagination()
// 初始化过滤器选中
function initFilter() {
let query = parsePath(location.href).query || {}
if(query.cid) {
params.category_id = query.cid
const node = $('#c' + query.cid)
node.prop('checked', true)
node.parents('.selection-item').addClass('checked')
$('.ys-product-filter').attr('data-category_id', query.cid)
}
if(query.apid && query.aid) {
params.attributes[query.apid] = query.aid
const node = $('#attr-'+query.aid)
node.prop('checked', true)
node.parents('.selection-item').addClass('checked')
}
if(query.cid || query.apid && query.apid) {
request(true)
}
}
initFilter()
// 处理初始化filter请求相关
function handelFilterRequest(filter){
if(Array.isArray(filter.categorys) && filter.categorys.length && filter.categorys[0].id == params.category_id) {
filters.push({
id: 'c' + params.category_id,
title: filter.categorys[0].name,
type: '0',
pid: "category_id"
})
}
// 不从 filter.options 获取,因为有可能存在不存在的规格
if(typeof params.attributes === 'object' && JSON.stringify(params.attributes) !== '{}' ){
Object.keys(params.attributes).forEach(e => {
const item = params.attributes[e]
filters.push({
id: item,
title: $('#attr-' + item).data('title'),
type: '0',
pid: e
})
})
}
if(Array.isArray(filters) && filters.length) {
window.dispatchEvent(
new CustomEvent('product_options_init', {
detail: filters
})
)
}
}
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(init = false) {
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
})
)
// 初始化禁用其他筛选项
if(init) {
handelFilterRequest(filter)
}
result.type = 1
result.list = res.data.skus.list
result.total = res.data.skus.total
$('.ys-product__sku').css('display', 'block')
$('.ys-product__sku .ys-product__total span').html(result.total)
$('.ys-product__sku .ys-product__search button span').html(0 + '/' + result.list.length)
let sku_html = ''
if (result.list.length) {
result.list.forEach(e => {
sku_html += `
|
${e.sku_code}
|
${e.name}
|
${
e.paper_2d
? `
`
: ``
}
|
${
e.paper_3d
? `
`
: ``
}
|
|
`
})
$('.ys-product__sku .ys-product__table').html(`
`+ sku_html + `
`)
productViewListItem({from_filter: 1}) // 埋点,看后续需不需要把过滤器值传递
} else {
sku_html += `
抱歉,没有找到相关的内容
抱歉,没有找到相关的内容
`
$('.ys-product__sku .ys-product__table').html(sku_html)
$('.c-pagination-nav').remove()
}
$(".c-pagination").html('')
$(".c-pagination").zPager({
totalData: result.total,
pageStep: 5,
current: params.page,
pageData: params.pageSize
})
}).finally(() => {
$loading.end()
})
}
// 滚动到底部
$(window).scroll(function () {
if (result.type === 0) {
if ($(document).scrollTop() + 400 >= $(document).height() - $(window).height()) {
if (result.total > params.page * params.pageSize && !$loading.status) {
params.page++
request()
}
}
}
})
// sku搜索事件
$("body").on("click", ".ys-product__sku .ys-product__input i", function (e) {
let val = $(this).parent().find('input').val()
search(val)
});
$("body").on("keyup", ".ys-product__sku .ys-product__input input", function (e) {
let val = $(this).val()
if (e.keyCode === 13) {
search(val)
}
});
// 顶部搜索
$("body").on("click", ".ys-product-banner .ys-product-search span", function (e) {
let val = $(this).parent().find('input').val()
search(val)
});
$("body").on("keyup", ".ys-product-banner .ys-product-search input", function (e) {
let val = $(this).val()
if (e.keyCode === 13) {
search(val)
}
});
function search(val) {
params.keyword = val
params.page = 1
result.list = []
request()
}
/* 埋点 start */
productViewListItem()
productSelectItemClick()
/* 埋点 end */
})
/* 埋点方法 start */
const ItemListId = 'groups_products_list'; // ga view_item_list 列表id
const ItemListName = 'Groups products list';// ga view_item_list 列表名称
function productViewListItem(otherInfo = {}) {
const itemsInfoList = getProductListInfo(otherInfo)
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 = []
const query = parsePath(location.href).query || {}
const cid = typeof query.cid === 'undefined'? '': query.cid,
apid = typeof query.apid === 'undefined'? '': query.apid,
aid = typeof query.aid === 'undefined'? '': query.aid;
$('.ys-product__sku .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,
form_cid: cid,
form_apid: apid,
form_aid: aid,
...otherInfo || {} // 其他自定义属性 主要为 {from_filter: 1} 分辨是否经过过滤
}
itemInfoList.push(item)
})
return itemInfoList
}
// 列表点击商品
function productSelectItemClick() {
$('.ys-product__sku').on('click', '.product-table-img', productSelectItem)
$('.ys-product__sku').on('click', '.product-table-item > .product-table-cell:nth-child(2) a', productSelectItem)
$('.ys-product__sku').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 query = parsePath(location.href).query || {}
const cid = typeof query.cid === 'undefined'? '': query.cid,
apid = typeof query.apid === 'undefined'? '': query.apid,
aid = typeof query.aid === 'undefined'? '': query.aid;
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,
form_cid: cid,
form_apid: apid,
form_aid: aid,
}]
}
}
customEventLog('ecommerce', ecommerceItemObj, {onlyTrack: ["DataLayerTracker"]})
}
// 图纸点击
$('.ys-product__sku').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 */
// 点击表格行(选中/取消选中)
let compare_skus = []
$('.ys-product__table').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-product__search button span').html(
compare_skus.length + '/' + ($('.product-table-item').length - $('.product-table-item.display-none').length)
)
$('.ys-product__action .batch-action-num i').text(compare_skus.length)
if (compare_skus.length) {
$('.ys-product__search button').removeClass('disabled')
$('.ys-product__action').addClass('active')
} else {
$('.ys-product__search button').addClass('disabled')
$('.ys-product__action').removeClass('active')
}
})
// 开始对比按钮
$('.ys-product__sku').on('click', '.ys-product__search 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-product__sku").on("click", ".ys-product__search button div", function (e) {
compare_skus = []
$('.product-table-item').each(function() {
$(this).find('input').prop('checked', false)
})
$('.ys-product__search button span').html(compare_skus.length + '/' + ($('.product-table-item').length - $('.product-table-item.display-none').length))
$('.ys-product__search button').addClass('disabled')
$('.ys-product__action .batch-action-num i').text(compare_skus.length)
$('.ys-product__action').removeClass('active')
e.preventDefault();
});
// 保存至清单
$('.ys-product__sku').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('保存成功')
// 取消选择
$('.ys-product__search button div').click()
})
})
// 分页
function currentPage(currentPage) {
window.dispatchEvent(
new CustomEvent('current_page', {
detail: currentPage,
})
)
}
function changePager(sizes) {
window.dispatchEvent(
new CustomEvent('pager_change', {
detail: sizes,
})
)
}
// 清除选中
window.addEventListener('clearSku', clearSku)
function clearSku() {
compare_skus = []
}
// 客服
$('.ys-product__table').on('click', '.product-table-enquiry', function() {
window.dispatchEvent(
new CustomEvent('openService')
)
})
// 处于页面配置时,绑定方法
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) => `
`)
.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) => `
`)
.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')
})