Authored by 李奇

资源位曝光组件修改

... ... @@ -103,7 +103,18 @@ export default {
break;
case 'tfGoodsList':
// 楼层内存在多个item, 交给子组件各自检测
component.checkReqFromParent();
let visible = component.checkReqFromParent();
if (visible.length) {
param = [];
_.each(visible, item => {
param.push(Object.assign(item, {
P_NAME: this.$route.name,
F_NAME: reportData.template_name,
F_ID: reportData.template_id,
F_INDEX: index,
}));
});
}
break;
case 'newSingleImage':
param = {
... ...
<template>
<resource class="no-padding-right product-list-more">
<resource class="no-padding-right product-list-more" ref="resource">
<ul class="resource-tf-goods"
@touchstart="touchStart"
@touchmove="touchMove"
... ... @@ -23,6 +23,7 @@
</template>
<script>
import _ from 'lodash';
import Resource from './resource';
export default {
... ... @@ -34,7 +35,8 @@ export default {
moveX: 0,
disX: 0,
moreSlider: '',
moreMove: ''
moreMove: '',
itemVisibleStatus: {}
};
},
props: {
... ... @@ -133,8 +135,26 @@ export default {
// 用于检测楼层内部item的曝光状态, 暴露给父组件调用
checkReqFromParent() {
console.log('out from self check')
// TODO 检测组件内child item曝光、并返回给parent
let rect;
let isVisible;
let visible = [];
let items = this.$el.querySelectorAll('.product-item');
_.each(items, (item, idx) => {
rect = item.getBoundingClientRect();
isVisible = (rect.left > 0 && rect.left < window.screen.width) ||
((rect.left + rect.width) > 0 && (rect.left + rect.width) < window.screen.width);
if (isVisible && !this.itemVisibleStatus[idx]) {
visible.push({
I_INDEX: idx + 1,
PRD_SKN: this.value.data && this.value.data.list[idx].product_skn
});
}
this.itemVisibleStatus[idx] = isVisible;
});
return visible;
}
},
components: {Resource}
... ...