productList.vue
5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<template>
<div class="bg" v-if="list.length">
<div class="product-list-item" v-for="(product,index) in list" @click="goDetail(product, index)"
:key="index" :class="(index) % 2 === 0 && 'magrin-right'">
<div class="item-top">
<div class="item-price">
<span class="price-flag">{{product[priceKey] && '¥'}}</span><span>{{product[priceKey] || ' '}}</span>
</div>
<div class="item-sales">{{product.sales && product.sales + '人付款'}}</div>
</div>
<ImgSize class="item-imge" :src="product.default_images" :width="274" :height="274"/>
<div class="item-name">{{product.product_name}}</div>
<div
v-if="product.customize_tag && product.customize_tag.length"
class="tag-wrapper">
<ImgSize class="item-tag" :src="product.customize_tag[0].url2" :width="200" :height="200"/>
</div>
</div>
</div>
</template>
<script>
import {Scroll} from 'cube-ui';
import ImgSize from '../../../components/img-size';
export default {
props: {
list: Array,
yasParams: Object,
yasEventName: {
type: String,
default: 'XY_UFO_PRD_LIST_C'
},
priceKey: {
type: String,
default: 'available_now_price',
},
},
data: function() {
return {
yasFirstId: 0,
itemHeight: 0
};
},
methods: {
goDetail(product, index) {
if (this.yasParams && Object.keys(this.yasParams).length) {
this.yasDetail(product.id, index);
}
this.$router.push({
name: 'ProductDetail',
params: {
productId: product.id,
/**
* 传递可用的初始化数据,避免白屏
*/
productInfo: {
...product,
price: product[this.priceKey], // 统一接收端使用的价格key
},
yasParams: this.yasParams,
}
});
},
yasShowEvent: function(height) {
if (!this.itemHeight) {
let item = document.querySelector('.product-list-item');
this.itemHeight = item && item.offsetHeight || 0;
}
if (!this.itemHeight) {
return;
}
// 获取列表单个元素高度
let index = 0;
if (Number(height) > 0) {
// 获取第一个曝光元素
let row = parseInt((height - 12) / this.itemHeight) + 1;
index = row * 2 - 2;
}
// 获取曝光列表
let list = [];
for (let i = 0; i < 6; i++) {
if (this.list[i + index]) {
list.push(this.list[i + index]);
}
}
// 判断是否是重复曝光
if (list.length && list[0].id !== this.yasFirstId) {
this.yasFirstId = list[0].id;
// 1.P_NAME:页面名称,XY_UFOSearchList,XY_UFOSeriesList,XY_UFOBrandList、XY_UFOProductPoolList等;
// 2.TYPE_ID:列表页入口类型,1-搜索结果页,2-系列,3-品牌,4-商品池;
// 3.P_PARAM:页面参数,搜索关键词,系列ID,品牌ID,商品池ID;
// 4.TAB_ID:tab切id,1-人气,2-价格,3-新品;
// 5.TAB_NAME:tab切名称,人气,价格,新品;
// 6.I_INDEX:曝光顺序;
// 7.PRD_ID:商品id;
let DATA = [];
list.map((value, i) => {
DATA.push({...this.yasParams, I_INDEX: i + index + 1, PRD_ID: value.id});
});
this.$store.dispatch('reportYas', {
params: {
param: {DATA},
appop: 'XY_UFO_SHOW_EVENT'
}
});
}
},
yasDetail(id, index) {
// XY_UFO_PRD_LIST_C
// 1.P_NAME:页面名称,XY_UFOSearchList,XY_UFOSeriesList,XY_UFOBrandList、XY_UFOProductPoolList等;
// 2.TYPE_ID:列表页入口类型,1-搜索结果页,2-系列,3-品牌,4-商品池;
// 3.P_PARAM:页面参数,搜索关键词,系列ID,品牌ID,商品池ID;
// 4.TAB_ID:tab切id,1-人气,2-价格,3-新品;
// 5.TAB_NAME:tab切名称,人气,价格,新品;
// 6.I_INDEX:商品顺序号,从1开始递增;
// 7.PRD_ID:商品id
this.$store.dispatch('reportYas', {
params: {
param: {...this.yasParams, I_INDEX: index + 1, PRD_ID: id },
appop: this.yasEventName
}
});
}
},
components: {
ImgSize,
Scroll,
}
};
</script>
<style lang="scss" scoped>
.magrin-right {
margin-right: 14px;
}
.product-list-item {
border-radius: 16px;
width: 344px;
padding: 24px 24px 32px;
// height: 498px;
background: #fff;
margin-bottom: 16px;
position: relative;
&:before {
content: "";
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 1;
}
}
.item-top {
height: 40px;
display: flex;
justify-content: space-between;
margin-bottom: 32px;
align-items: center;
}
.item-price {
color: #d0021b;
font-size: 32px;
vertical-align: center;
@include num
}
.item-imge {
width: 274px;
height: 274px;
margin: 0 10px;
}
.tag-wrapper {
width: 120px;
height: 40px;
position: absolute;
top: 72px;
}
.item-tag {
width: 84px;
height: 26px;
}
.item-name {
font-size: 24px;
color: #000;
letter-spacing: 0;
line-height: 40px;
margin-top: 14px;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.item-sales {
font-size: 22px;
color: #999;
}
.price-flag {
font-size: 24px;
}
.bg {
padding: 24px 24px 8px;
display: flex;
flex-wrap: wrap;
}
</style>