seckill_list.js
5.8 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
var e = getApp(), i = e.request, a = e.globalData.setting,os=a,ut = require("../../../utils/util.js");
var regeneratorRuntime = require('../../../utils/runtime.js');
Page({
data: {
url: a.imghost,
killtime: null,
currentPage: 1,
goodlist: null,
type:1,
timer:null,
ismore:1, //是否可以加载更多
isshow:0,
},
//------初始化加载----------
onLoad: function(t) {
var first_leader = t.first_leader;
console.log("------------");
console.log(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;
}
})
}
},
onShow: function(t) {
wx.setNavigationBarTitle({ title: "商品秒杀",})
this.data.is_timer=1;
this.data.currentPage=1;
var th=this;th.setData({goodlist:null,})
this.requestSalelist();
//设置全局定时器
th.data.timer=setInterval(function () {
th.countDown();
},1000);
},
onHide:function(){
//--清理定时器--
clearInterval(this.timer);
this.setData({isshow:0});
},
//---小于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 endTimeList = this.data.goodlist;
if(endTimeList==null) return null
// 对结束时间进行处理渲染到页面
for (var i = 0; i < endTimeList.length;i++){
var o = endTimeList[i];
var endTime = o.end_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});
}
},
async requestSalelist() {
//--没有更多就不调用--
if(!this.data.ismore) return false;
var e = this,th=e, i = "/api/ms/flash_sale/spikepage?page=" + e.data.currentPage;
var plist=null,alllist=th.data.goodlist;
if(!alllist) alllist=[];
await getApp().request.promiseGet(i,
{isShowLoading:1,data:{store_id:os.stoid,timetype:th.data.type,is_end:0,is_show:1}}
).then(res=>{
plist=res.data.data.pageData;
console.log("是什么即将开始",plist);
});
if(plist.length<=0){
getApp().showWarning("没有更多数据");
th.data.ismore=0;
}
//--循环读取接口---
for(var i=0;i<plist.length;i++) {
var prom_id = plist[i].id;
await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" +
os.stoid + "/1/" + prom_id, {}
).then(res=>{
if(res.data.code==0){
plist[i].status=1;
if(res.data.data<=0) plist[i].status=3;
}
})
alllist.push(plist[i]);
}
e.data.currentPage++;
console.log("秒杀商品列表", alllist);
th.setData({goodlist:alllist,isshow:1});
},
onPullDownRefresh: function() {
this.reloadGoodList();
},
reloadGoodList: function() {
this.data.goodlist = null, this.data.currentPage = 1, this.requestSalelist();
},
onReachBottom: function() {
this.requestSalelist();
},
//点击tab事件
tip:function(e){
var a=e.currentTarget.dataset.ty,th=this;th.data.ismore=1;
this.setData({type:a,goodlist:null});
this.reloadGoodList();
},
//---------分享配置--------
onShareAppMessage: function (e) {
var curPage=this;
var pagePath = curPage.route; //当前页面url
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;
}
}
console.log("11"+pagePath);
return {
title: "限时秒杀",
path:pagePath,
}
},
//图片失败,默认图片
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) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
}
},
onShareTimeline() {
return {
title: '秒杀活动-' + getApp().globalData.config.store_name,
}
},
});