seckill-detail.page.js
1.5 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
const tip = require('js/plugin/tip');
$(window).on('seckill', function() {
$('.btn-c').before('<a href="https://union.yoho.cn/union/app-downloads.html" class="seckill-download-app">下载APP购买</a>');
$('.btn-c').remove();
});
$(function() {
$('#goodsDiscount').hide(); // 隐藏折扣楼层
$('.current-price').hide();
let ajaxUrl = '/product/seckillDetail/seckillData/' + $('#productSkn').val();
let timestamp = Date.parse(new Date());
$.ajax({
type: 'GET',
url: ajaxUrl + '?tamp=' + timestamp,
success: function(data) {
let secKillPrice = toDecimal2(data.secKillPrice); // eslint-disable-line
if (secKillPrice) {
$('.current-price').before('<h1 class="seckill-price" style="display: inline-block;"></h1>').hide();
$('.current-price').remove();
$('.seckill-price').text('¥' + secKillPrice).show();
} else {
$('.current-price').show();
}
},
error: function() {
tip.show('网络异常~');
}
});
});
// 强制保留2位小数点
function toDecimal2(num) {
let f = parseFloat(num);
if (isNaN(f)) {
return false;
}
f = Math.round(num * 100) / 100;
let s = f.toString();
let rs = s.indexOf('.');
if (rs < 0) {
rs = s.length;
s += '.';
}
while (s.length <= rs + 2) {
s += '0';
}
return s;
}
// 调用新商品详情页js
require('./new-detail');