group_list.js
8.15 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
var e = getApp(), i = e.request, a = e.globalData.setting,os=a,ut = require("../../../utils/util.js");
var regeneratorRuntime = require('../../../utils/runtime.js');
const app = getApp();
let self = null;
Page({
/**
* 页面的初始数据
*/
data: {
url: a.imghost,
type:1,
// goodlist: null,
isLogin: false,
list: [],
isLoading: false, // 检测是否已经发送请求,防止重复发送请求
noMore: false, // 检测是否有更多数据,true为没有更多数据,false为还有数据
pageNum: 1, // 当前页数
time_arr:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
self = this;
//群id
if(options && options.groupchat_id){
getApp().globalData.groupchat_id=options.groupchat_id
}
var first_leader = options.first_leader;
if (first_leader) {
getApp().globalData.first_leader = first_leader;
//调用接口判断是不是会员
getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + first_leader, {}).then(res => {
if (res.data.code == 0) {
getApp().globalData.guide_id = res.data.data.id;
getApp().globalData.guide_pick_id= res.data.data.pickup_id
}
})
}
app.isLogin().then(function(data) {//进入页面前已经授权登录成功
self.setData({
userInfo: data,
});
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
getApp().check_can_share(this);
var user=app.globalData.userInfo;
this.setData({
userInfo: user,
imghost: app.globalData.setting.imghost,
isLogin: true,
});
let typeVal = this.data.type;
let url = '/api/weshop/goods/groupBuy/page';
let data = {
store_id: app.globalData.setting.stoid,
is_show: 1,
is_end: 0,
timetype: typeVal
};
this.setData({
list: [],
pageNum: 1,
noMore: false,
});
this.getData(true, url, data).then(function() {
self.setData({
currentData: data,
});
});
this.data.is_timer = 1;
//设置全局定时器
clearInterval(this.data.timer);
this.data.timer = setInterval(function () {
self.countDown();
}, 1000);
},
// 底部按钮切换
tip: function(e) {
// 1进行中 0预热
let typeValue = e.currentTarget.dataset.ty;
this.data.type = typeValue;
let url = '/api/weshop/goods/groupBuy/page';
let data = {
store_id: app.globalData.setting.stoid,
is_show: 1,
is_end: 0,
timetype: typeValue
};
this.getData(true, url, data).then(function() {
self.setData({
currentData: data,
});
});
this.setData({
list: [],
type: typeValue,
});
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
clearInterval(this.data.timer);
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if(this.data.isLoading) return false;
let data = this.data.currentData;
this.scrollToLower('/api/weshop/goods/groupBuy/page', data);
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
getApp().globalData.no_clear=1;
var store_name = getApp().globalData.config ? getApp().globalData.config.store_name:'';
var pagePath = this.route; //当前页面url
if(!store_name) store_name = getApp().globalData.setting.appName;
if(pagePath.indexOf('/') != 0) {
pagePath = '/' + pagePath;
}
if(getApp().globalData.user_id){
if(pagePath.indexOf('?')>0){
pagePath += '&first_leader=' + getApp().globalData.user_id;
}else{
pagePath += '?first_leader=' + getApp().globalData.user_id;
}
//群id分享
if (getApp().globalData.groupchat_id) {
pagePath+="&groupchat_id="+getApp().globalData.groupchat_id
}
}else{
if(pagePath.indexOf("?")>0){
pagePath+="&groupchat_id="+getApp().globalData.groupchat_id
}else{
pagePath+="?groupchat_id="+getApp().globalData.groupchat_id
}
}
return {
title: store_name + '-团购',
path: pagePath,
}
},
/**
* 请求数据
*/
getData: function(isInit, url, data) {
wx.showLoading();
let p = app.request.promiseGet(url, {
data: data,
isShowLoading: false,
})
.then(function(res) {
if(ut.ajax_ok(res)) {
self.setData({
['list['+(self.data.pageNum-1)+']']:res.data.data.pageData
})
if(res.data.data.pageSize * res.data.data.page >= res.data.data.total){
self.setData({
noMore: true
});
};
} else {
self.setData({ noMore: true });
};
self.setData({
isLoading: false,
is_get:1
});
wx.hideLoading();
});
return p;
},
/**
* 上拉加载
*/
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);
};
},
//---小于10的格式化函数----
timeFormat(param) {
return param < 10 ? '0' + param : param;
},
//----倒计时函数-----
countDown() {
if (!this.data.is_timer) return false;
var th = this;
// 获取当前时间,同时得到活动结束时间数组
let newTime = ut.gettimestamp();
var time_arr=[];
for (let j = 0; j < this.data.list.length; j++) {
var endTimeList = this.data.list[j];
if (endTimeList == null) return null;
var arr_new=[];
// 对结束时间进行处理渲染到页面
for (var i = 0; i < endTimeList.length; i++) {
var o = endTimeList[i];
var endTime = this.data.type == 1 ? o.end_time : o.start_time;
// if(th.data.type==0) endTime = o.start_time;
let obj = null;
// 如果活动未结束,对时间进行处理
if (endTime - newTime > 0) {
let time = (endTime - newTime);
// 获取天、时、分、秒
let day = parseInt(time / (60 * 60 * 24));
let hou = parseInt(time % (60 * 60 * 24) / 3600);
let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
obj = {
day: this.timeFormat(day),
hou: this.timeFormat(hou),
min: this.timeFormat(min),
sec: this.timeFormat(sec),
hide: 1
}
} else {
//活动已结束,全部设置为'00'
obj = {day: '00', hou: '00', min: '00', sec: '00'}
}
//var txt = "goodlist[" + i + "].djs";
//th.setData({[txt]: obj});
var e={djs:obj};
arr_new.push(e);
}
time_arr.push(arr_new);
}
this.setData({time_arr:time_arr});
},
//图片失败,默认图片
bind_bnerr2: function (e) {
var _errImg = e.target.dataset.errorimg;
var val = e.target.dataset.val;
if(val!=undefined && val!=null && val!='null' ){
var _errObj = {};
_errObj[_errImg] = "/public/images/default_goods_image_240.gif";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
}
},
goto(e) {
let index = e.currentTarget.dataset.index;
let pidx = e.currentTarget.dataset.pidx;
let item=this.data.list[pidx][index];
let url="/pages/goods/goodsInfo/goodsInfo?goods_id="+item.goods_id+"&prom_id="+item.id+"&prom_type=2";
//-- 如果是服务卡项的时候 --
if(item.goods_type==1){
url="/packageG/pages/group_buy/goodsInfo/goodsInfo?goods_id="+item.goods_id+"&prom_id="+item.id;
}
app.goto(url);
},
})