list.vue
10.4 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<template>
<div>
<LayoutApp :show-back="true" :title="title">
<div class="filter">
<div class="filter-tab">
<div class="tab-item" :class="selectedType === 2 && 'selected-tab'" @click="pressType(2)">人气</div>
<div class="tab-item middle" @click="pressType(1)">
<span :class="selectedType === 1 && 'selected-tab'">价格</span>
<div :class="arrowImage"></div>
</div>
<div class="tab-item" :class="selectedType === 3 && 'selected-tab'" @click="pressType(3)">新品</div>
</div>
<div class="middle">
<div class="screen middle" @click="goFilter()">
<div class="screen-img"></div>
筛选
</div>
<div class="search-img" @click="goSearch()"></div>
</div>
</div>
<Scroll ref="scroll" class="product-list" v-show="!productList.isEmpty"
:scroll-events="['scroll-end']"
:options="scrollOptions"
:data="productList.list"
@scroll-end="scrollHandler"
@pulling-up="onPullingUp">
<ProductList ref="product" :list="productList.list" :yasParams="yasParams"></ProductList>
</Scroll>
<EmptyList class="empty-wrapper product-list" :tip="`暂无数据`" v-show="productList.isEmpty">
</EmptyList>
</LayoutApp>
<Filtrate ref="filtrate" :yasParams="yasParams"></Filtrate>
</div>
</template>
<script>
import ProductList from './components/productList';
import Filtrate from './filtrate';
import EmptyList from '../../components/ufo-no-item';
import {Scroll} from 'cube-ui';
import {mapState, createNamespacedHelpers} from 'vuex';
const {mapActions} = createNamespacedHelpers('list');
export default {
name: 'List',
components: {
ProductList,
Scroll,
Filtrate,
EmptyList
},
data: function() {
return {
scrollOptions: {
bounce: {
top: false
},
pullUpLoad: true,
pullDownRefresh: false,
useTransition: false,
},
fixed: false,
selectedType: 2, // tab类型高亮
priceDesc: true,
arrowImage: '',
title: '',
yasParams: {P_NAME: 'XY_UFOSearchList', TYPE_ID: 1},
productList: {
showErrorPage: false,
isFetching: false,
error: null,
page: 0, // 当前页
page_size: 10, // 每页数量
page_total: 0, // 总共多少页
total: 0, // 总共多少条
endReached: false, // 到达底部
list: [], // 商品列表
isEmpty: false,
},
searchParams: {
type: 0, // type:0,推荐;1,热销;2,即将发售; 3,品类; 4,品牌;5,系列;6,搜索 7, 收藏
order: '', // 指定排序
productPool: null, // 商品池id
sort: null, // 品类id
brand: null, // 品牌id
series: null, // 系列id
gender: null, // 性别
size: null, // 尺码id
isSoonSale: null, // 是否是即将售卖
query: null, // 搜索词
limit: null, // 每页记录数
page: null, // 当前页号
coupon_token: null, // 优惠券token
},
};
},
activated: async function() {
if (this.yoho.direction === 'forword') {
this.$refs.filtrate.hide();
Object.assign(this.$data, this.$options.data());
}
this.changeArrow();
let params = {...this.$route.query};
if (params.title) {
this.title = params.title;
delete params.title;
} else {
this.title = '商品列表';
}
this.setYasParam({param: params, tab: {index: 1, name: '人气'}});
!params.order && (params.order = 'sale_desc');
await this.fetchList({...params, isReset: true});
this.yasShowPage();
},
computed: {
...mapState(['yoho'])
},
methods: {
...mapActions(['fetchProductList', 'getDirection']),
// 上拉加载
async onPullingUp() {
await this.fetchList();
},
scrollHandler({y}) {
let height = -y;
this.$refs.product.yasShowEvent(height);
},
// 查询商品列表
fetchList: async function(params) {
let searchParams = this.searchParams;
let list = this.productList;
let pageSize = list.page_size;
let isReset = false;
if (params && params.isReset) {
isReset = true;
delete params.isReset;
}
if (!isReset && (list.endReached || (!list.endReached && list.page_total === 1))) {
return;
}
if (typeof params === 'object' && Object.keys(params)) {
searchParams = Object.assign({...searchParams}, params);
this.searchParams = searchParams;
}
let page = isReset ? 1 : (list.page + 1);
for (let key in searchParams) {
if (!searchParams[key]) {
delete searchParams[key];
}
}
let result = await this.fetchProductList({
...searchParams,
page,
pageSize
});
let {data} = result;
if (result.code === 200) {
data.endReached = (data.page === data.page_total) && (data.page_size !== 1) || !data.page_total;
}
if (typeof data === 'object' && Object.keys(data).length) {
for (let key in data) {
if (key === 'product_list') {
list.list = data.page > 1 ? list.list.concat(data.product_list) : data.product_list;
} else {
list[key] = data[key];
}
}
list.list && list.list.length ? list.isEmpty = false : list.isEmpty = true;
this.productList = list;
}
},
// 点击tab flag, 0: 推荐, 1: 价格, 2: 人气, 3: 新品
async pressType(flag) {
if (flag === this.selectedType && flag !== 1) {
return;
}
let filterParams = this.$refs.filtrate.getParams();
let {sort} = this.searchParams;
let params = {
sort: filterParams.sort.join(',') || sort,
brand: filterParams.brand.join(','), // 品牌id
gender: filterParams.gender.join(','), // 性别
size: filterParams.size.join(','), // 尺码id
};
this.selectedType = flag;
if (flag === 1) {
this.setYasParam({tab: {index: 2, name: '价格'}});
this.priceDesc = !this.priceDesc;
params.order = this.priceDesc ? 'availableNowPrice:asc' : 'availableNowPrice:desc';
} else if (flag === 2) {
this.setYasParam({tab: {index: 1, name: '人气'}});
this.priceDesc = true;
params.order = 'sale_desc';
} else if (flag === 3) {
this.setYasParam({tab: {index: 3, name: '新品'}});
this.priceDesc = true;
params.order = 'st_desc';
}
params.isReset = true;
await this.fetchList(params);
this.$refs.scroll.scrollTo(0, 0, 300);
this.changeArrow();
this.yasShowPage();
this.yasTab();
},
goSearch() {
this.$router.push({
name: 'Search',
});
},
changeArrow() {
this.arrowImage = (this.selectedType === 3 || this.selectedType === 2) ? 'price-arrow' :
this.priceDesc ? 'desc-arrow' : 'asc-arrow';
},
goFilter() {
this.$refs.filtrate.show();
},
setYasParam: function({param, tab}) {
if (param && typeof param === 'object' && Object.keys(param).length) {
let P_NAME = 'XY_UFOSearchList', TYPE_ID = 1, P_PARAM = [];
for (let key in param) {
if (key === 'brand' && param[key] && param.type !== 6) {
P_NAME = 'XY_UFOBrandList';
TYPE_ID = 3;
}
if (key === 'series' && param[key] && param.type !== 6) {
P_NAME = 'XY_UFOSeriesList';
TYPE_ID = 2;
}
if (key === 'productPool' && param[key] && param.type !== 6) {
P_NAME = 'XY_UFOProductPoolList';
TYPE_ID = 4;
}
if (!param[key]) {
delete param[key];
}
P_PARAM.push(param[key]);
}
Object.assign(this.yasParams, {
P_NAME,
P_PARAM: P_PARAM.toString(),
TYPE_ID,
TAB_ID: this.tabIndex || '',
TAB_NAME: this.tabName || ''
});
}
if (tab && typeof tab === 'object' && Object.keys(tab).length) {
this.yasParams.TAB_ID = tab.index;
this.yasParams.TAB_NAME = tab.name;
}
},
yasShowPage() {
let {total, list} = this.productList;
let PRD_LIST = [];
for (let item of list) {
PRD_LIST.push(item.id);
}
PRD_LIST = PRD_LIST.toString();
this.$store.dispatch('reportYas', {
params: {
param: {...this.yasParams, TOTAL: total, PRD_LIST},
appop: 'XY_UFO_PRD_LIST_L'
}
});
},
yasTab() {
this.$store.dispatch('reportYas', {
params: {
param: {...this.yasParams},
appop: 'XY_UFO_PRD_LIST_TAB_C'
}
});
}
}
};
</script>
<style scoped>
.filter {
display: flex;
height: 120px;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding-left: 42px;
padding-right: 38px;
z-index: 999;
background: #fff;
position: relative;
}
.filter-tab {
display: flex;
flex-direction: row;
align-items: center;
font-size: 32px;
color: #999;
text-align: center;
}
.selected-tab {
color: #000;
font-weight: bold;
}
.tab-item {
margin-right: 60px;
}
.screen {
font-size: 32px;
color: #000;
letter-spacing: 0;
margin-right: 24px;
}
.middle {
display: flex;
align-items: center;
}
.asc-arrow {
width: 40px;
height: 40px;
background: url(~statics/image/list/asc_arrow@3x.png) no-repeat;
background-size: cover;
}
.desc-arrow {
width: 40px;
height: 40px;
background: url(~statics/image/list/desc_arrow@3x.png) no-repeat;
background-size: cover;
}
.price-arrow {
width: 40px;
height: 40px;
background: url(~statics/image/list/price_arrow@3x.png) no-repeat;
background-size: cover;
}
.screen-img {
width: 40px;
height: 40px;
background: url(~statics/image/list/filter@3x.png) no-repeat;
background-size: cover;
}
.product-list {
background: #f5f5f5;
}
.search-img {
width: 40px;
height: 40px;
margin-left: 20px;
background: url(~statics/image/list/search_icon@3x.png) no-repeat;
background-size: cover;
}
.empty-wrapper {
margin: auto 0;
position: absolute;
top: 0;
bottom: 0;
}
</style>