commision.js
8.02 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
// packageA//pages/distribution/commision/commision.js
const app = getApp();
let self = null;
Page({
/**
* 页面的初始数据
*/
data: {
isHiddenDropdown: true,//控制下拉菜单显隐
dropdownArr: ['综合','未付款','已付款','待分成','已分成','已取消'],
statusArr: ['未付款', '已付款', '等待分成', '已分成', '已取消'],
currentSelect: '',//记录当前下拉菜单选中项
isInputFocus: false,//记录搜索输入框是否聚焦
inputVal: '',//记录搜索输入框的内容
isSort: false,//控制排序开关状态,true开启排序
isDescending: false, //isDescending降序,ascending升序
currentQuery: null,//保存当前请求参数
list: null,
isLoading: false, // 检测是否已经发送请求,防止重复发送请求
noMore: false, // 检测是否有更多数据,true为没有更多数据,false为还有数据
pageNum: 1, // 当前页数
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.setNavigationBarTitle({
title: "佣金明细",
});
this.setData({
currentSelect: this.data.dropdownArr[0],
});
self = this;//保存全局指针
app.isLogin().then(function(data) {//进入页面前已经授权登录成功
self.setData({
userInfo: data,
});
});
// 判断会员是否授权登录,
// 没有登录则跳转到登录页,
// 已登录则设置已登录状态,请求加载签到数据
// isLogin记录登录状态
// app.isLogin().then(function(data) {
// console.log('data', data);
// // 1.登录成功
// self.setData({
// isLogin: true,
// userInfo: data,
// currentQuery: {
// store_id: app.globalData.setting.stoid,
// user_id: app.globalData.user_id,
// },
// });
// // 2.请求数据
// self.getData(true, '/api/weshop/rebateLog/commissionlist', self.data.currentQuery);
// });
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if(app.globalData.userInfo) {
if(!this.data.isLogin) {
this.setData({
userInfo: app.globalData.userInfo,
imghost: app.globalData.setting.imghost,
currentQuery: {
store_id: app.globalData.setting.stoid,
user_id: app.globalData.user_id,
},
isLogin: true,
});
// 请求数据
this.getData(true, '/api/weshop/rebateLog/commissionlist', this.data.currentQuery);
};
};
// if(app.globalData.userInfo instanceof Object) {
// this.setData({
// userInfo: app.globalData.userInfo,
// imghost: app.globalData.setting.imghost,
// currentQuery: {
// store_id: app.globalData.setting.stoid,
// user_id: app.globalData.user_id,
// },
// });
// // 检测从登录页返回后的登录状态
// if(this.data.isLogin) {
// // 初次就授权登录
// return;
// } else {
// // 初次未授权登录,过后才授权
// this.setData({
// isLogin: true
// });
// // 请求数据
// this.getData(true, '/api/weshop/rebateLog/commissionlist', this.data.currentQuery);
// };
// };
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.scrollToLower('/api/weshop/rebateLog/commissionlist', this.data.currentQuery);
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
/**
* 点击下拉菜单
*/
clickDropdown() {
this.setData({
isHiddenDropdown: !this.data.isHiddenDropdown,
});
},
/**
* 点击遮罩层
*/
clickMask() {
this.setData({
isHiddenDropdown: true,
});
},
/**
* 选择下拉菜单项
*/
selectDropdown(e) {
let status = null;
let currentIndex = e.target.dataset.index;
let data = this.data.currentQuery;
if(data.status) {//清除status
delete data.status;
};
if(data.page && data.page != 1) {//清除page
delete data.page;
};
if(data.orderField) {//清除orderField
delete data.orderField;
};
if(data.orderType) {//清除orderType
delete data.orderType;
};
if(data.key) {//清除搜索输入框
delete data.key;
};
if(currentIndex != 0) {
status = currentIndex - 1;
data.status = status;
};
this.setData({
list: null, //清空列表
isSort: false,//关闭排序
isDescending: false,
noMore: false,
pageNum: 1,
isHiddenDropdown: true,
currentSelect: this.data.dropdownArr[currentIndex],
currentQuery: data,//保存当前请求参数
inputVal: '',
});
this.getData(true, '/api/weshop/rebateLog/commissionlist', data);
},
/**
* 搜索输入框聚焦
*/
inputFocus() {
this.setData({
isInputFocus: true,
});
},
/**
* 搜索输入框失焦
*/
inputBlur() {
this.setData({
isInputFocus: false,
});
},
/**
* 搜索输入框输入内容
*/
input(e) {
this.data.inputVal = e.detail.value;
},
/**
* 搜索输入框清空内容
*/
inputClear() {
let inputVal = this.data.inputVal;
if(inputVal) {
this.setData({
inputVal: '',
});
};
},
/**
* 点击搜索
*/
search() {
let data = {
store_id: app.globalData.setting.stoid,
user_id: app.globalData.user_id,
};
if(this.data.inputVal) {
data.key = this.data.inputVal;
};
this.setData({
currentQuery: data,
currentSelect: this.data.dropdownArr[0],
});
this.getData(true, '/api/weshop/rebateLog/commissionlist', this.data.currentQuery);
},
/**
* 点击佣金排序
*/
clickSort() {
let orderType = '';
let data = this.data.currentQuery;
if(!this.data.isHiddenDropdown) {
this.setData({
isHiddenDropdown: true,
});
};
if(data.page && data.page != 1) {//清除page
delete data.page;
};
if(data.orderType) {//清除orderType
delete data.orderType;
};
if(data.key) {//清除搜索输入框
delete data.key;
};
if(this.data.isDescending) {
orderType = 'desc';
} else {
orderType = 'asc';
};
data.orderField = 'money';
data.orderType = orderType;
this.setData({
list: null,
noMore: false,
pageNum: 1,
isSort: true,
isDescending: !this.data.isDescending,
currentQuery: data,
});
this.getData(true, '/api/weshop/rebateLog/commissionlist', this.data.currentQuery);
},
/**
* 请求数据
*/
getData: function(isInit, url, data) {
app.request.promiseGet(url, {
data: data,
isShowLoading: true,
})
.then(function(res) {
// console.log('1121', res.data.code);
if(res.data.code == 0) {
self.setData({
isLoading: false
});
if(isInit) {// 第一次加载
self.setData({
list: res.data.data
});
} else {
self.setData({
'list.pageData': self.data.list.pageData.concat(res.data.data.pageData)
});
};
if((res.data.data.pageData.length == 0) || (res.data.data.pageSize * res.data.data.page >= res.data.data.total)) {
self.setData({
noMore: true
});
};
} else {
self.setData({
'list.pageData': []
});
};
})
.catch(function(err) {
console.log('出错拉!!!!',err);
self.setData({
'list.pageData': []
});
});
},
// 上拉加载
scrollToLower(url, requestData) {
// 数据总量
let total = this.data.list.total;
// 单页最大数据量
let pageSize = this.data.list.pageSize;
// 如果数据总量不为0且小于或等于单页最大数据量,说明数据已全部加载,显示‘没有更多了’
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.page = this.data.pageNum;
this.getData(false, url, requestData);
};
},
})