index.js
4.9 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
import wx from '../../utils/wx';
import config from '../../common/config';
import Yas from '../../common/yas';
import LimitModel from '../../models/limit/index';
// 获取应用实例
let app = getApp();
let yas;
let router = global.router;
Page({
data: {
tabSelected: 0,
refreshText: '下拉刷新',
footText: '内容加载中...',
userInfo: {},
tabBarArr: [
{
// icon: '../../static/images/limit/icon_jjfs_n@3x.png',
// iconSelected: '../../static/images/limit/icon_jjfs_p@3x.png',
name: '即将发售',
method: 'app.limitProduct.soonToSaleLimitProduct',
reportName: 'home_soon'
},
{
// icon: '../../static/images/limit/icon_rmfs_n@3x.png',
// iconSelected: '../../static/images/limit/icon_rmfs_p@3x.png',
name: '热门发售',
method: 'app.limitProduct.hotLimitProduct',
reportName: 'home_hot'
},
{
// icon: '../../static/images/limit/icon_yjfs_n@3x.png',
// iconSelected: '../../static/images/limit/icon_yjfs_p@3x.png',
name: '已经发售',
method: 'app.limitProduct.alreadySaleLimitProduct',
reportName: 'home_already'
}
],
listData: [
{}, {}, {}
],
icon: {
clock: '../../static/images/limit/clock_left.png'
}
},
onLoad: function() {
yas = new Yas(app);
let that = this;
setTimeout(function() {
that.getList(0, 1, 20, false);
}, 300);
// this.getList(0, 1, 20, false);
},
onShow: function() {
let pageName = this.data.tabBarArr[this.data.tabSelected].reportName;
yas.pageOpenReport('', { PAGE_NAME: pageName });
},
onShareAppMessage() {
// 右上角转发、默认内容
},
onPullDownRefresh: function() {
this.setData({
refreshText: '加载中...'
});
let pageName = this.data.tabBarArr[this.data.tabSelected].reportName;
yas.pageOpenReport('', { PAGE_NAME: pageName });
this.getList(this.data.tabSelected, 1, 20, false).then(() => {
wx.stopPullDownRefresh();
this.setData({
refreshText: '下拉刷新'
});
});
},
onReachBottom: function() {
let page = this.data.listData[this.data.tabSelected].page;
let page_total = this.data.listData[this.data.tabSelected].page_total;
if (page < page_total) {
page += 1;
this.getList(this.data.tabSelected, page, 20, true);
}
},
tabChange: function(e) { // 切换TAB
let index = e.currentTarget.dataset.index;
if (index !== this.data.tabSelected) {
this.setData({
tabSelected: index
});
let pageName = this.data.tabBarArr[this.data.tabSelected].reportName;
yas.pageOpenReport('', { PAGE_NAME: pageName });
// 如果listData没有数据,或者数据为空,则调用接口
if (!this.data.listData[index].limitProductVoList || this.data.listData[index].limitProductVoList.length === 0) {
this.getList(index, 1, 20, false);
}
}
},
/**
* 获取限定发售列表
* index: tab的index,
* page:分页,
* limit: 每页数量,
* isBottom:是否是到达底部后触发的
*/
getList: function(index, page, limit, isBottom) {
let method = this.data.tabBarArr[index].method;
let that = this;
this.setData({
footText: '内容加载中...'
});
return LimitModel.getLimitSaleList({
method: method,
page: page,
limit: limit
}).then(res => {
console.log(res.data);
if (res.data && res.data.limitProductVoList) {
// 获取到已有的data数据,对某部分数据进行赋值后再setData
let list = that.data.listData;
if (isBottom) {
list[index].page = page;
list[index].limitProductVoList =
list[index].limitProductVoList.concat(res.data.limitProductVoList);
} else {
list[index] = res.data;
}
that.setData({
listData: list,
footText: '暂无更多内容'
});
}
});
},
navigateToDetail: function(e) { // 跳转到详情页
console.log(e);
let id = e.currentTarget.dataset.id;
let limitProductCode = e.currentTarget.dataset.code;
let isApp = e.currentTarget.dataset.isApp;
if (isApp == 'Y') {
wx.showModal({
title: '',
content: '请打开有货APP参与活动',
showCancel: false
})
return;
}
if (app.getUid() && app.getUserInfo().wechat) {
router.go('productDetail', {limitProductCode});
} else {
let pages = getCurrentPages();
let referer = `/pages/product/detail/detail?limitProductCode=${limitProductCode}`;
router.go('userCenter', {referer});
}
},
navigateToHome: function(e) { // 跳转到我的限购码
router.go('userCenter');
},
goToRule: function (e) {
router.goUrl('https://activity.yoho.cn/feature/2593.html?share_id=5035&title=限定频道说明');
}
});