chongzhi.js
4.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
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
// packageA//pages/chongzhi/chongzhi.js
const app = getApp();
var util = require('../../../utils/util.js');
Page({
/**
* 页面的初始数据
*/
data: {
url: app.globalData.setting.imghost,
imgAd: '',
ad_color:'',
currentIndex: 0,
list: null,
// 检测是否已经发送请求,防止重复发送请求
isLoading: false,
// 检测是否有更多数据,true为没有更多数据,false为还有数据
noMore: false,
// 当前页数
pageNum: 1,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var self = this;
this.getData(true,'/api/weshop/users/pageNewVIPAddMoney',{
store_id: app.globalData.userInfo.store_id,
user_id: app.globalData.userInfo.user_id,
IsPos: 0,
});
app.request.get('/api/weshop/ad/page', {
data: {
pid: 601,
store_id: app.globalData.userInfo.store_id,
enabled: 1,
},
success: function (res) {
// console.log('604',res.data.data[0].ad_code);
if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0 ){
var a = res.data.data.pageData;
self.setData({
imgAd: a[0].ad_code,
ad_color: a[0].bgcolor,
});
}
},
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
console.log('上拉加载');
var data = this.data.saveData;
// 数据总量
var total = this.data.result.total;
// 单页最大数据量
var pageSize = this.data.result.pageSize;
if((total !== 0)&&(total <= pageSize)) {
this.setData({
noMore: true
});
};
if(!this.data.isLoading && !this.data.noMore) {
this.setData({
isLoading: true,
pageNum: this.data.pageNum + 1
});
data.page = this.data.pageNum;
this.getData(false,'/api/weshop/users/pageNewVIPAddMoney',data);
};
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
onClickTab(e) {
var data = {
store_id: app.globalData.userInfo.store_id,
user_id: app.globalData.userInfo.user_id,
page: 1,
};
this.setData({
currentIndex: e.target.dataset.index,
list: [],
});
if(e.target.dataset.index == 0) {
data.IsPos = 0;
} else {
data.IsPos = 1;
this.setData({
saveData: data
});
}
this.getData(true,'/api/weshop/users/pageNewVIPAddMoney',data);
},
// 请求数据
getData(isInit, url, data, callback) {
var self = this;
// 请求数据
app.request.get(url, {
data: data,
success: function (res) {
console.log('res-->', res);
// 请求成功后,把正在请求加载状态置为false
self.setData({
isLoading: false,
});
// 检测是否是初始化第一次加载
if(isInit) {
//第一页数据直接赋值
self.setData({
list: res.data.data.pageData,
// 这里保存了一份完整的响应数据
result: res.data.data,
});
} else {
// 下一页的数据拼接在原有数据后面
self.setData({
list: self.data.list.concat(res.data.data.pageData)
});
};
console.log('result', self.data.list);
// 回调函数
if(callback) callback();
// 1、第一次请求返回的数据为空,显示‘没有更多了’;
// 2、后面的请求,如果返回的数据为空,就表示没有下一页了,noMore置为true,这样上拉加载scrollToLower不再发起请求;
if((res.data.data.pageData.length === 0) || (res.data.data.total <= res.data.data.pageSize)) {
self.setData({
noMore: true
});
};
},
});
},
goDetails(e) {
let id = e.currentTarget.dataset.id;
app.goto('../chongzhiDetails/chongzhiDetails?id=' + id+"&type=1");
},
viewDetails(e){
var index=e.currentTarget.dataset.index;
var WriteOffCode=this.data.list[index].WriteOffCode;
var qrcode = this.selectComponent("#qrcode"); //组件的id
var code=WriteOffCode;
var e={is_fw:1,val:code,code:code}
qrcode.open(e);
},
// 检测上拉滚动到底部
// scrollToLower: function (requestData, callback) {
// // 数据总量
// var total = this.data.result.total;
// // 单页最大数据量
// var pageSize = this.data.result.pageSize;
// if((total !== 0)&&(total <= pageSize)) {
// this.setData({
// noMore: true
// });
// };
// if(!this.data.isLoading && !this.data.noMore) {
// this.setData({
// isLoading: true,
// pageNum: this.data.pageNum + 1
// });
// requestData.data.page = this.data.pageNum;
// this.getData(false, requestData, callback);
// };
// },
onerror:function(e){
var _errImg = e.currentTarget.dataset.errimg;
var _errObj = {};
_errObj[_errImg] = "/miniapp/images/default_g_img.gif";
this.setData(_errObj);
}
})