myGift.js
6.59 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
// packageA//pages/myGift/myGift.js
const app = getApp();
let self = null;
var os = app.globalData.setting;
Page({
/**
* 页面的初始数据
*/
data: {
tabArr: ['礼包列表', '我的礼包'],
currentIndex: 0,
list: null,
isLoading: false, // 检测是否已经发送请求,防止重复发送请求
noMore: false, // 检测是否有更多数据,true为没有更多数据,false为还有数据
pageNum: 1, // 当前页数
},
clickTab(e) {
let index = e.target.dataset.index;
let url = '';
let data = {
store_id: app.globalData.setting.stoid,
user_id: app.globalData.user_id,
};
this.setData({
list: null,
pageNum: 1,
noMore: false,
currentIndex: index,
});
if(index == 0) {
url = '/api/weshop/libao/libaoForm/page';
} else if(index == 1) {
url = '/api/weshop/libao/libaoFormvip/page';
};
this.getData(true, url, data);
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
self = this;
if(options.index){
this.setData({currentIndex:1}); //查看我的礼包
}
app.isLogin().then(function(data) {//进入页面前已经授权登录成功
self.setData({
userInfo: data,
});
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if(app.globalData.userInfo) {
if(!this.data.isLogin) {
this.setData({
userInfo: app.globalData.userInfo,
imghost: app.globalData.setting.imghost,
isLogin: true,
});
var index=this.data.currentIndex;
let url = '';
let data = {
store_id: app.globalData.setting.stoid,
user_id: app.globalData.user_id,
};
this.setData({
list: null,
pageNum: 1,
noMore: false,
});
if(index == 0) {
url = '/api/weshop/libao/libaoForm/page';
} else if(index == 1) {
url = '/api/weshop/libao/libaoFormvip/page';
};
this.getData(true, url, data);
};
};
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.scrollToLower('/api/weshop/libao/libaoFormvip/page', {
store_id: app.globalData.setting.stoid,
user_id: app.globalData.user_id,
});
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
/**
* 请求数据
*/
getData: function(isInit, url, data) {
app.request.promiseGet(url, {
data: data,
isShowLoading: true,
})
.then(function(res) {
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);
};
},
/**
* 点击跳转
*/
goto(e) {
let url = '';
if(e.target.dataset.url) {
url = e.target.dataset.url;
} else {
url = e.currentTarget.dataset.url;
}
app.goto(url);
},
//-- 礼包购买 --
GetBuyPrice: function(e) {
var th = this,that=th;
var index=e.currentTarget.dataset.index;
var item=that.data.list.pageData[index];
var id = item.id; //活动id
var my_confirm = th.selectComponent("#my_confirm"); //组件的id
var user=getApp().globalData.userInfo;
my_confirm.open(
"是否确定购买该礼包",
"取消",
"确定",
function() {
my_confirm.open_cancel(0);
},
function() {
my_confirm.open_cancel(0);
var json = {
"lbid": id, //活动Id
"paytype": 2, //1=积分兑换 2=购买
"store_id": os.stoid, //商家Id
"user_id": user.user_id, //用户ID
};
var url = "/api/weshop/libao/libaoFormvip/libaoOrder";
getApp().request.post(url,
{
data:json,
success:function(res) {
if (res.data.code == 0 && res.data.data) {
res = res.data.data;
wx.requestPayment({
timeStamp: String(res.timeStamp),
nonceStr: res.nonceStr,
package: res.packageValue,
signType: res.signType,
paySign: res.paySign,
success: function(res) {
getApp().my_warnning("支付成功", 1, th);
},
fail: function(res) {
getApp().my_warnning("取消支付", 0, th);
}
});
} else {
getApp().my_warnning(res.data.msg, 0, th);
}
}
})
})
},
//-- 积分兑换 --
GetBuyIntegral: function(e) {
var th = this,that=th;
var index=e.currentTarget.dataset.index;
var item=that.data.list.pageData[index];
var id = item.id; //活动id
var my_confirm = th.selectComponent("#my_confirm"); //组件的id
var user=getApp().globalData.userInfo;
my_confirm.open(
"是否确定兑换该礼包",
"取消",
"确定",
function() {
my_confirm.open_cancel(0);
},
function() {
my_confirm.open_cancel(0);
var json = {
"lbid": id, //活动Id
"paytype": 1, //1=积分兑换 2=购买
"store_id": os.stoid, //商家Id
"user_id": user.user_id, //用户ID
};
var url = "/api/weshop/libao/libaoFormvip/libaoOrder";
getApp().request.post(url,{
data:json,
success:function(res) {
if (res.data.code == 0) {
getApp().my_warnning("兑换成功!", 1, th);
} else {
getApp().my_warnning(res.data.msg, 0, th);
}
},
})
})
},
})