index.js
3.98 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
import { YOHOOD_HOST, API_HOST } from '../../libs/config';
import { GET, POST } from '../../libs/request';
import jumpToMiniapp from '../../router/jump-to-miniapp';
Page({
data: {
imageArray: [ 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2700915385,2771074487&fm=26&gp=0.jpg', 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2700915385,2771074487&fm=26&gp=0.jpg'],
floorData: {},
newsList: {
type: 1, //页数
list: [],
},
},
onLoad: function(options) {
//Do some initialize when page load.
this.fetchHomedata();
this.fetchNewsList();
},
onReady: function() {
//Do some when page ready.
},
onShow: function() {
//Do some when page show.
},
fetchHomedata() {
let that = this;
GET(YOHOOD_HOST + '/activity/home', {})
.then(json => {
if (json && json.code == 200) {
let floorData = json.data;
console.log('====================================');
console.log(floorData);
console.log('====================================');
that.setData({
floorData
})
wx.setStorage({
key: "mars",
data: floorData.mars
});
wx.setStorage({
key: "social",
data: floorData.social
});
wx.setStorage({
key: "map",
data: floorData.map
});
}
})
.catch(error => {
})
},
fetchNewsList(isLoadMore) {
let that = this;
let newsList = this.data.newsList;
let type = newsList.type;
if (isLoadMore && type <= 10) { //上限10页
type += 1;
} else {
type = 1;
}
newsList.type = type;
let param = {
type,
};
GET(YOHOOD_HOST + '/default/H5LoadNews', param)
.then(json => {
if (json) {
var list = newsList.list;
for(var i = 0; i< json.length; i++) {
let item = json[i];
item.create_time = that.formatDateForNews(parseInt(item.create_time));
list.push(item);
}
that.setData({
newsList
})
}
})
.catch(error => {
})
},
formatDateForNews: function (timestamp) {
var time = new Date(timestamp * 1000);
var y = time.getFullYear();
var m = time.getMonth() + 1;
var d = time.getDate();
return this.add0(m) + '.' + this.add0(d) + '.' + this.add0(y);
},
add0: function (m) {
if (m < 10 && m > 0){
return '0' + m;
} else if (m === 0){
return '00';
} else {
return m;
}
},
tapBanner(e){
let href = e.detail.href || '';
let articleId = e.detail.articleId || '';
if (articleId) {//跳资讯详情
wx.navigateTo({
url: '/pages/index/newsDetail?id=' + articleId
});
} else {
wx.navigateTo({
url: `../webview/webview?url=${encodeURIComponent(href)}`,
})
}
},
jumpYohobuyGoodsDetail(e) {
let productSkn = e.detail.productSkn || '';
if (productSkn.length) {
jumpToMiniapp({ app: 'yohobuy', page: 'productDetail', data: {productSkn:productSkn} })
}
},
jumpStarBrand(e) {
let index = e.detail.index;
let href = e.detail.href || '';
if (index == 0) { //参展明星
wx.navigateTo({
url: `../webview/webview?url=${encodeURIComponent(href)}`,
})
} else if (index == 1) {// 参展品牌
wx.navigateTo({
url: '../brands/brands'
})
}
},
//跳资讯详情
jumpNewsDetail(e) {
let newsId = e.detail || '';
wx.navigateTo({
url: '/pages/index/newsDetail?id=' + newsId
});
},
onHide: function() {
//Do some when page hide.
},
onUnload: function() {
//Do some when page unload.
},
onReachBottom: function() {
this.fetchNewsList(true);
},
onPullDownRefresh: function() {
//Do some when page pull down.
wx.stopPullDownRefresh();
this.fetchHomedata();
this.fetchNewsList();
}
})