index.js
3.47 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
import wx from '../../utils/wx';
import resource from '../../common/resource';
import indexModel from '../../models/index/index';
//获取应用实例
let app = getApp();
Page({
data: {
resource,
productList: [],
showFilterHolder: false,
filterInitialTop: 0,
topSearchHeight: 0
},
onLoad: function () {
this.productList();
setTimeout(() => {
let query = wx.createSelectorQuery();
query.select('.recommend-product .filter').boundingClientRect();
query.select('.container .top-search').boundingClientRect();
query.exec(res => {
this.setData({
filterInitialTop: res[0].top,
topSearchHeight: res[1].bottom - res[1].top,
});
})
}, 1000)
},
onShow: function () {
},
onShareAppMessage: function (res) {
// let param = {
// FROM: res.from,
// SHARE_RESUIL: 0,
// TITLE: 'Yoho!Buy有货-潮流购物逛不停',
// PATH: '/pages/index/index'
// }
//
// // 用户点击右上角分享
// return {
// title: param.TITLE, // 分享标题
// desc: '精选1400+全球潮流品牌,明星潮牌和新锐原创品牌每日上新,100%正品行货。', // 分享描述
// path: param.PATH, // 分享路径
// success: function (res) {
// param.SHARE_RESUIL = 1
// logEvent(YB_SHARE_RESULT_L, param);
// },
// fail: function (res) {
// param.SHARE_RESUIL = 2
// logEvent(YB_SHARE_RESULT_L, param);
// }
// }
},
onPullDownRefresh: function () {
// wx.stopPullDownRefresh();
// this.getLastChannel();
// this.fetchNewHomeData(true);
},
//回到顶部
backToTop: function () {
wx.pageScrollTo({
scrollTop: 0
})
},
onPageScroll: function () {
let query = wx.createSelectorQuery();
query.selectViewport().scrollOffset();
query.exec(res => {
this.setData({
showFilterHolder: res[0].scrollTop > this.data.filterInitialTop - this.data.topSearchHeight
});
});
},
sortChange: function (e) {
let params;
let {curSort, gender} = e.detail;
params = {
gender,
order: curSort,
};
this.productList(params)
},
productList: function (params) {
indexModel.productList(params).then(res => {
if (res.code === 200) {
const keyAdapter = {
skn: 'product_skn',
salePriceStr: 'sales_price',
productName: 'product_name',
defaultImages: 'default_images'
};
let list = [];
(res.data.product_list || []).forEach(product => {
let item = {};
Object.keys(keyAdapter).forEach(key => {
item[key] = product[keyAdapter[key]]
});
list.push(item);
});
this.setData({
productList: list
});
}
});
},
toSearch: function () {
wx.navigateTo({
url: '../search/search'
});
}
});