seckill-detail.js
4.54 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
import {
getBindtapData,
formatDateTime,
} from '../../utils/util';
let Date = require('../../utils/date.js');
var timer = require('../../utils/wxTimer.js');
var wxTimer;
let app = getApp();
Page({
data: {
authorizeVisible: false,
seckillOrderVisible: true,
userInfo: {},
productInfo: {},
navBackTimeout: 0,
options: {},
wxTimerList: {},
lastTime: "",
},
onShareAppMessage() {},
showAuth() {
this.setData({
authorizeVisible: true
})
},
onShow() {
if (wxTimer) {
wxTimer.calibration()
}
},
onLoad(options) {
this.setData({
options
})
this.querySeckillDetail().then((result) => {
this.startTimer();
})
this.initData();
},
onUnload() {
this.removeTimer();
},
initData() {
this.queryMember().then((result) => {});
},
// 开始倒计时
startTimer() {
let _this = this;
if (wxTimer) {
wxTimer.stop();
}
let beginTime = _this.getTimeStr();
console.log("beginTime:", beginTime);
if (!beginTime) return;
wxTimer = new timer({
beginTime: beginTime,
complete() {
_this.removeTimer();
_this.querySeckillDetail();
},
interval: 1,
intervalFn() {
let lastTime = _this.getTimeStr({
day: true
});
_this.setData({
lastTime
})
// console.log("lastTime:", lastTime);
}
})
wxTimer.start(_this);
},
/**
* 移除倒计时
*/
removeTimer() {
if (wxTimer) {
wxTimer.stop()
}
},
/**
* 获取时间字符串
* @param {*} initObj
*/
getTimeStr(initObj) {
let productInfo = this.data.productInfo;
let endTime = productInfo && productInfo.endTime || 0;
return formatDateTime(endTime, initObj)
},
/**
* 我要秒杀
*/
onSubmitHandler() {
let productInfo = this.data.productInfo;
if (productInfo && productInfo.status == 1) {
// 显示弹窗
this.setData({
seckillOrderVisible: true
})
let minNum = productInfo.minNum;
this.seckillOrderComp = this.selectComponent("#seckillOrderComp");
console.log("this.seckillOrderComp:",this.seckillOrderComp);
console.log("minNum:",minNum);
if (this.seckillOrderComp) {
this.seckillOrderComp.setNum(minNum);
}
}
},
/**
* 秒杀详情
*/
querySeckillDetail() {
let code = this.data.options.code;
let _this = this;
return new Promise((resolve, reject) => {
app.post({
url: app.api.seckillDetail,
data: {
seckillCode: code
}
}).then((result) => {
this.setData({
productInfo: result
})
console.log("result:", result);
resolve();
}).catch((err) => {
clearTimeout(_this.data.navBackTimeout);
_this.data.navBackTimeout = setTimeout(() => {
wx.navigateBack({
delta: 1
});
}, 1000);
});
})
},
/**
* 拍卖出价提交
* @param {*} price
*/
querySeckillSubmit(price) {
let code = this.data.options.code;
app.post({
toast: false,
url: app.api.seckillSubmit,
data: {
seckillCode: code,
price: price * 100 //转成分
}
}).then((result) => {
console.log("result:", result);
// this.setData({
// auctionBidSuccessVisible: true
// })
}).catch((err) => {
console.log("querySeckillSubmit err:", err);
// switch (err.code) {
// // 来晚一步,该价格已经被其他用户提交 显示组件
// case 1010:
// this.setData({
// auctionBidFailVisible: true
// })
// break;
// default:
// wx.showToast({
// title: err.errMsg || "系统开小差"
// })
// break;
// }
});
},
/**
* 获取会员信息
*/
queryMember() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.member,
data: {}
}).then((result) => {
this.setData({
userInfo: result
})
resolve(result);
})
});
},
// 隐藏蒙层
hideMask() {
this.setData({
authorizeVisible: false,
seckillOrderVisible: false,
})
},
// 子组件事件
evtcomp(evt) {
let {
name,
data
} = evt.detail;
console.log("@seckill-detail || evt:", name)
switch (name) {
// 隐藏弹窗
case "_evt_hide_mask":
this.hideMask();
break;
default:
break;
}
},
})