Showing
2 changed files
with
48 additions
and
318 deletions
1 | +const tip = require('plugin/tip'); | ||
2 | + | ||
1 | $(window).on('seckill', function() { | 3 | $(window).on('seckill', function() { |
2 | $('.btn-c').before('<a href="https://union.yoho.cn/union/app-downloads.html" class="seckill-download-app">下载APP购买</a>'); | 4 | $('.btn-c').before('<a href="https://union.yoho.cn/union/app-downloads.html" class="seckill-download-app">下载APP购买</a>'); |
3 | $('.btn-c').remove(); | 5 | $('.btn-c').remove(); |
4 | }); | 6 | }); |
5 | 7 | ||
6 | -// 调用秒杀js | ||
7 | -// $(window).on('seckill', function(event, detailData) { | ||
8 | - | ||
9 | -// /** | ||
10 | -// * [秒抢页面js] | ||
11 | -// * author: 李靖<jing.li@yoho.cn> | ||
12 | -// * date: 2016/09/08 | ||
13 | -// */ | ||
14 | - | ||
15 | -// let $ = require('yoho-jquery'), | ||
16 | -// tip = require('plugin/tip'); | ||
17 | - | ||
18 | -// let seckillObj = {}; | ||
19 | - | ||
20 | -// let offsetTime = 0; | ||
21 | - | ||
22 | -// let nowTime = 0; | ||
23 | - | ||
24 | -// let startTime = 0; | ||
25 | - | ||
26 | -// let endTime = 0, | ||
27 | -// diffTime = 0; // 误差时间 | ||
28 | - | ||
29 | -// let dateText = 0, | ||
30 | -// newDate = 0, | ||
31 | -// newMonth = 0, | ||
32 | -// newDay = 0, | ||
33 | -// newHour = 0, | ||
34 | -// newMinus = 0; | ||
35 | - | ||
36 | - | ||
37 | -// let secKillPrice = 0; | ||
38 | - | ||
39 | -// // 隐藏折扣信息 | ||
40 | -// $('.good-detail-page').addClass('hide-discount'); | ||
41 | - | ||
42 | -// require('common'); | ||
43 | - | ||
44 | -// seckillObj = { | ||
45 | -// el: { | ||
46 | -// iScroll: null, | ||
47 | -// currentTick: null | ||
48 | -// }, | ||
49 | - | ||
50 | -// startTick: function(status, offTime) { | ||
51 | -// let that = this, | ||
52 | -// $el = this.el, | ||
53 | -// day = parseInt(offTime / (60 * 60 * 24), 10), | ||
54 | -// hour = parseInt(offTime % (60 * 60 * 24) / (60 * 60), 10), | ||
55 | -// minute = parseInt(offTime % (60 * 60) / 60, 10), | ||
56 | -// second = offTime % 60; | ||
57 | - | ||
58 | -// let $elem = status === 0 ? $('.seckill-count-num') : $('.end-time'); | ||
59 | - | ||
60 | -// if (offTime >= -1) { | ||
61 | -// if (day <= 0) { | ||
62 | -// $('.day-c').addClass('hide'); | ||
63 | -// } | ||
64 | -// $elem.find('.tick.day').text(that.formatNumber(day)); | ||
65 | -// $elem.find('.tick.hour').text(that.formatNumber(hour)); | ||
66 | -// $elem.find('.tick.minute').text(that.formatNumber(minute)); | ||
67 | -// $elem.find('.tick.second').text(that.formatNumber(second)); | ||
68 | - | ||
69 | -// if (offTime <= -1) { // 结束倒计时刷新状态 | ||
70 | -// window.location.reload(); | ||
71 | -// } else { | ||
72 | -// $el.currentTick = setTimeout(function() { | ||
73 | -// that.startTick(status, --offTime); | ||
74 | -// }, 1000); | ||
75 | -// } | ||
76 | -// } | ||
77 | - | ||
78 | -// }, | ||
79 | -// formatNumber: (number) => { | ||
80 | -// if (number < 0) { | ||
81 | -// return '00'; | ||
82 | -// } else if (number < 10) { | ||
83 | -// return '0' + number; | ||
84 | -// } else { | ||
85 | -// return number; | ||
86 | -// } | ||
87 | -// }, | ||
88 | -// }; | ||
89 | - | ||
90 | -// $( | ||
91 | -// function() { | ||
92 | -// $('#goodsDiscount').hide(); // 隐藏折扣楼层 | ||
93 | -// $('.cart-bar').hide(); | ||
94 | -// $('.current-price').hide(); | ||
95 | -// let ajaxUrl = '/product/seckillDetail/seckillData/' + $('#productSkn').val(); | ||
96 | -// let timestamp = Date.parse(new Date()); | ||
97 | - | ||
98 | -// $.ajax({ | ||
99 | -// type: 'GET', | ||
100 | -// url: ajaxUrl + '?tamp=' + timestamp, | ||
101 | -// success: function(data) { | ||
102 | - | ||
103 | -// // 秒杀是否结束 | ||
104 | -// if (data === '' || data.status === 0 || data.status === 3) { | ||
105 | -// window.location.replace('/product/' + $('#productSkn').val() + '.html'); // 商品url改版 | ||
106 | - | ||
107 | -// // $('.sold-out').hide(); | ||
108 | -// // $('.cart-bar a:first').append('<a href="javascript:;" class="sold-out">已售罄</a>'); | ||
109 | -// // $('.addto-cart').hide(); | ||
110 | -// // $('.cart-bar').show(); | ||
111 | -// // $('.current-price').show(); | ||
112 | -// } else { | ||
113 | - | ||
114 | -// // 秒杀开始前 | ||
115 | -// if (data.status === 1) { | ||
116 | -// $('.cart-bar').before( | ||
117 | -// '<div class="seckill-count">' + | ||
118 | -// '<div class="seckill-count-bg"></div>' + | ||
119 | -// '<div class="seckill-count-num">距秒杀开始:' + | ||
120 | -// '<span class="day-c"><i class="tick day">00</i>天</span>' + | ||
121 | -// '<i class="tick hour">00</i>时' + | ||
122 | -// '<i class="tick minute">00</i>分' + | ||
123 | -// '<i class="tick second">00</i>秒' + | ||
124 | -// '</div>' + | ||
125 | -// '</div>' | ||
126 | -// ); | ||
127 | -// $('.current-price').text('¥' + data.secKillPrice).show(); | ||
128 | -// $('.price-date').eq(0).append( | ||
129 | -// '<div class="seckill-time notStart">' + | ||
130 | -// '<span class="seckill-time-pic">秒杀预告</span>' + | ||
131 | -// '<span class="seckill-time-c">月日</span>' + | ||
132 | -// '</div>' | ||
133 | -// ); | ||
134 | -// $('.sold-out').hide(); | ||
135 | -// $('.btn-c').append('<a href="javascript:;" class="sold-out">即将开抢</a>'); | ||
136 | -// $('.addto-cart').hide(); | ||
137 | -// $('.cart-bar').show(); | ||
138 | -// $('.current-price').show(); | ||
139 | -// timeInit(data); // eslint-disable-line | ||
140 | -// } | ||
141 | - | ||
142 | -// // 秒杀进行中 | ||
143 | -// if (data.status === 2) { | ||
144 | -// $('#addtoCart').off('touchstart'); | ||
145 | - | ||
146 | -// // 插入倒计时 | ||
147 | -// addTimeout($('.price-date').eq(0)); // eslint-disable-line | ||
148 | - | ||
149 | -// let chosePanel = require('common/chose-panel-new'); | ||
150 | -// let seckillData = data.secKillSku; | ||
151 | - | ||
152 | -// detailData.cartInfo.skus.forEach( | ||
153 | -// function(val) { | ||
154 | -// seckillData.forEach( | ||
155 | -// function(item) { | ||
156 | -// if (val.skuId === item.productSku) { | ||
157 | -// val.storage = item.storageNum; | ||
158 | -// } | ||
159 | -// } | ||
160 | -// ); | ||
161 | -// } | ||
162 | -// ); | ||
163 | - | ||
164 | -// $('#addtoCart').on('touchstart', function() { | ||
165 | -// $('.cart-bar').hide(); | ||
166 | -// chosePanel.show({ | ||
167 | -// data: detailData, | ||
168 | -// disableNum: true | ||
169 | -// }).then(result => { | ||
170 | -// $('.cart-bar').show(); | ||
171 | -// if (result && result.sku) { | ||
172 | -// window.location.href = '/cart/index/seckill?skn=' + | ||
173 | -// $('#productSkn').val() + '&sku=' + result.sku.skuId; | ||
174 | -// } | ||
175 | -// }, () => { | ||
176 | -// $('.cart-bar').show(); | ||
177 | -// }); | ||
178 | -// $('.text-info').append($('.seckill-time').clone()); | ||
179 | -// $('.chose-items .num').find('.clearfix').append( | ||
180 | -// '<span class="limit-num-text">限购1件</span>' | ||
181 | -// ); | ||
182 | -// $('.sale-price').text('¥' + secKillPrice).show(); | ||
183 | -// return false; | ||
184 | -// }); | ||
185 | - | ||
186 | - | ||
187 | -// secKillPrice = toDecimal2(data.secKillPrice); // eslint-disable-line | ||
188 | -// $('.current-price').text('¥' + secKillPrice).show(); | ||
189 | -// $('.left-num').hide(); | ||
190 | -// $('.btn-plus').removeClass('btn-plus'); | ||
191 | -// $('.addto-cart').text('立即购买'); | ||
192 | -// $('#chose-btn-sure').text('立即购买').addClass('isSecKill'); | ||
193 | -// $('.cart-bar').show(); | ||
194 | -// let seckillNum = 0; | ||
195 | - | ||
196 | -// for (let i = 0; i < data.secKillSku.length; i++) { | ||
197 | -// seckillNum = seckillNum + data.secKillSku[i].storageNum; | ||
198 | -// } | ||
199 | -// if (seckillNum === 0) { | ||
200 | -// $('.sold-out').hide(); | ||
201 | -// $('.btn-c').append('<a href="javascript:;" class="sold-out">已售罄</a>'); | ||
202 | -// $('.addto-cart').hide(); | ||
203 | -// } | ||
204 | -// $('.current-price').show(); | ||
205 | -// timeInit(data); // eslint-disable-line | ||
206 | -// } | ||
207 | - | ||
208 | -// } | ||
209 | -// }, | ||
210 | -// error: function() { | ||
211 | -// tip.show('网络异常~'); | ||
212 | -// } | ||
213 | -// }); | ||
214 | - | ||
215 | -// } | ||
216 | -// ); | ||
217 | - | ||
218 | -// // function seckHide() { | ||
219 | -// // $('.chose-panel .size-list ul').each( | ||
220 | -// // function() { | ||
221 | -// // hideNum = 0; | ||
222 | -// // $(this).find('li').each( | ||
223 | -// // function() { | ||
224 | -// // if ($(this).hasClass('hide')) { | ||
225 | -// // oneIndex = $(this).index() + 1; | ||
226 | -// // twoIndex = $(this).parent('ul').index() - 2; | ||
227 | -// // $('.color-list ul:eq(' + oneIndex + ') li:eq(' + twoIndex + ')').hide(); | ||
228 | -// // } else { | ||
229 | -// // hideNum++; | ||
230 | -// // } | ||
231 | -// // } | ||
232 | -// // ); | ||
233 | -// // if (hideNum === 0) { | ||
234 | -// // hideIndex = $(this).index() - 2; | ||
235 | -// // $('.color-list ul:first li:eq(' + hideIndex + ')').hide(); | ||
236 | -// // } | ||
237 | -// // } | ||
238 | -// // ); | ||
239 | - | ||
240 | -// // $('.chose-panel .color-list ul').each( | ||
241 | -// // function() { | ||
242 | -// // hideNum = 0; | ||
243 | -// // $(this).find('li').each( | ||
244 | -// // function() { | ||
245 | -// // if ($(this).hasClass('hide')) { | ||
246 | -// // oneIndex = $(this).index() + 1; | ||
247 | -// // twoIndex = $(this).parent('ul').index() - 2; | ||
248 | -// // $('.size-list ul:eq(' + oneIndex + ') li:eq(' + twoIndex + ')').hide(); | ||
249 | -// // } else { | ||
250 | -// // hideNum++; | ||
251 | -// // } | ||
252 | -// // } | ||
253 | -// // ); | ||
254 | -// // if (hideNum === 0) { | ||
255 | -// // hideIndex = $(this).index() - 2; | ||
256 | -// // $('.size-list ul:first li:eq(' + hideIndex + ')').hide(); | ||
257 | -// // } | ||
258 | -// // } | ||
259 | -// // ); | ||
260 | -// // } | ||
261 | - | ||
262 | -// function addTimeout(obj) { | ||
263 | -// obj.append( | ||
264 | -// '<div class="seckill-time seckill-time-border">' + | ||
265 | -// '<span>距结束 </span>' + | ||
266 | -// '<span class="end-time">' + | ||
267 | -// '<i class="tick day hide">00</i>' + | ||
268 | -// '<i class="tick hour">00</i>:' + | ||
269 | -// '<i class="tick minute">00</i>:' + | ||
270 | -// '<i class="tick second">00</i>' + | ||
271 | -// '</span>' + | ||
272 | -// '</div>' | ||
273 | -// ); | ||
274 | -// } | ||
275 | - | ||
276 | -// // 强制保留2位小数点 | ||
277 | -// function toDecimal2(num) { | ||
278 | -// let f = parseFloat(num); | ||
279 | - | ||
280 | -// if (isNaN(f)) { | ||
281 | -// return false; | ||
282 | -// } | ||
283 | -// f = Math.round(num * 100) / 100; | ||
284 | -// let s = f.toString(); | ||
285 | -// let rs = s.indexOf('.'); | ||
286 | - | ||
287 | -// if (rs < 0) { | ||
288 | -// rs = s.length; | ||
289 | -// s += '.'; | ||
290 | -// } | ||
291 | -// while (s.length <= rs + 2) { | ||
292 | -// s += '0'; | ||
293 | -// } | ||
294 | -// return s; | ||
295 | -// } | ||
296 | - | ||
297 | -// function timeInit(data) { | ||
298 | -// let status = 0; | ||
299 | - | ||
300 | -// startTime = data.startTime; | ||
301 | -// endTime = data.endTime; | ||
302 | -// diffTime = data.currentTime; | ||
303 | -// nowTime = diffTime; | ||
304 | -// if (startTime > nowTime) { | ||
305 | -// offsetTime = startTime - nowTime; | ||
306 | -// } else if (nowTime > startTime && nowTime < endTime) { | ||
307 | -// offsetTime = endTime - nowTime; | ||
308 | -// status = 1; | ||
309 | -// } | 8 | +$(function() { |
9 | + $('#goodsDiscount').hide(); // 隐藏折扣楼层 | ||
10 | + $('.current-price').hide(); | ||
11 | + let ajaxUrl = '/product/seckillDetail/seckillData/' + $('#productSkn').val(); | ||
12 | + let timestamp = Date.parse(new Date()); | ||
13 | + | ||
14 | + $.ajax({ | ||
15 | + type: 'GET', | ||
16 | + url: ajaxUrl + '?tamp=' + timestamp, | ||
17 | + success: function(data) { | ||
18 | + let secKillPrice = toDecimal2(data.secKillPrice); // eslint-disable-line | ||
19 | + | ||
20 | + if (secKillPrice) { | ||
21 | + $('.current-price').before('<h1 class="seckill-price" style="display: inline-block;"></h1>').hide(); | ||
22 | + $('.current-price').remove(); | ||
23 | + $('.seckill-price').text('¥' + secKillPrice).show(); | ||
24 | + } else { | ||
25 | + $('.current-price').show(); | ||
26 | + } | ||
27 | + }, | ||
28 | + error: function() { | ||
29 | + tip.show('网络异常~'); | ||
30 | + } | ||
31 | + }); | ||
32 | +}); | ||
310 | 33 | ||
311 | -// dateText = Number(data.startTime * 1000); | ||
312 | -// newDate = new Date(dateText); | ||
313 | -// newMonth = newDate.getMonth() + 1; | ||
314 | -// newDay = newDate.getDate(); | ||
315 | -// newHour = newDate.getHours(); | ||
316 | -// newMinus = newDate.getMinutes(); | ||
317 | -// if (newMinus === 0) { | ||
318 | -// newMinus = '00'; | ||
319 | -// } | ||
320 | -// $('.notStart').find('.seckill-time-c').text(newMonth + '月' + newDay + '日' + newHour + ':' + newMinus); | ||
321 | -// seckillObj.startTick(status, offsetTime); | ||
322 | -// } | ||
323 | -// }); | 34 | +// 强制保留2位小数点 |
35 | +function toDecimal2(num) { | ||
36 | + let f = parseFloat(num); | ||
37 | + | ||
38 | + if (isNaN(f)) { | ||
39 | + return false; | ||
40 | + } | ||
41 | + f = Math.round(num * 100) / 100; | ||
42 | + let s = f.toString(); | ||
43 | + let rs = s.indexOf('.'); | ||
44 | + | ||
45 | + if (rs < 0) { | ||
46 | + rs = s.length; | ||
47 | + s += '.'; | ||
48 | + } | ||
49 | + while (s.length <= rs + 2) { | ||
50 | + s += '0'; | ||
51 | + } | ||
52 | + return s; | ||
53 | +} | ||
324 | 54 | ||
325 | // 调用新商品详情页js | 55 | // 调用新商品详情页js |
326 | require('./new-detail'); | 56 | require('./new-detail'); |
327 | - |
-
Please register or login to post a comment