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
|
var seckill = { URL: { now: function () { return "/seckill/time/now"; }, exposer: function (seckillId) { return "/seckill/" + seckillId + "/exposer"; }, killUrl: function (seckillId, md5) { return "/seckill/" + seckillId + "/" + md5 + "/execution"; } }, validatePhone: function (phone) { if (phone && phone.length == 11 && !isNaN(phone)) { return true; } else { return false; } }, handlerSeckillkill: function (seckillId, node) { node.hide().html('<button class="btn btn-primary btn-lg" id="killBtn">开始秒杀</button>'); $.post(seckill.URL.exposer(seckillId), {}, function (result) { if (result && result['success']) { var exposer = result['data']; if (exposer['exposed']) { var md5 = exposer['md5']; var killUrl = seckill.URL.killUrl(seckillId, md5); console.log("秒杀地址" + killUrl); $("#killBtn").one('click', function () { $(this).addClass('disabled'); $.post(killUrl, {}, function (result) { if (result && result['success']) { var killResult = result['data']; var state = killResult['state']; var stateInfo = killResult['stateInfo']; node.html("<span class='label label-success'>" + stateInfo + "</span>"); }
}); }); node.show(); } else { var now = exposer['now']; var start = exposer['start']; var end = exposer['end']; seckill.mycountdown(seckillId, now, start, end); } } else { console.log(result['data']); } }); }, mycountdown: function (seckillId, nowTime, startTime, endTime) { var seckillBox = $("#seckill-box"); if (nowTime > endTime) { seckillBox.html("秒杀结束"); } else if (nowTime < startTime) { var killTime = new Date(startTime + 1000); seckillBox.countdown(killTime, function (event) { var format = event.strftime('秒杀倒计时: %D天 %H时 %M分 %S秒'); seckillBox.html(format); }).on('finish.countdown', function () { seckill.handlerSeckillkill(seckillId, seckillBox); }) } else { seckill.handlerSeckillkill(seckillId, seckillBox); } }, detail: { init: function (params) { var killPhone = $.cookie('killPhone'); if (!seckill.validatePhone(killPhone)) { var killPhoneModal = $("#killPhoneModal"); killPhoneModal.modal({ show: true, backdrop: 'static', keyboard: false }); $("#killPhoneBtn").click(function () { var inputPhone = $("#killPhoneKey").val(); if (seckill.validatePhone(inputPhone)) { $.cookie('killPhone', inputPhone, {expires: 7, path: '/seckill'}); window.location.reload(); } else { $("#killPhoneMessage").hide() .html('<label class="label label-danger">手机号错误</label>') .show(300); } }); } var startTime = params['startTime']; var endTime = params['endTime']; var seckillId = params['seckillId'];
$.get(seckill.URL.now(), {}, function (result) { if (result && result['success']) { var nowTime = result['data']; seckill.mycountdown(seckillId, nowTime, startTime, endTime); } else { console.log('result:' + result); } });
$("#clearPhone").click(function () { $.removeCookie("killPhone"); window.location.reload(); }); } } };
|