// 指定全局变量 /*global checkVersion locateJudge EnvCheck tools erbanMask wx wxConfig VConsole androidJsObj initNav */ var info = {}; var browser = checkVersion(); var api = locateJudge(); var env = EnvCheck(); var totalPrice = 0; var shareUrl = location.origin + '/activity'; var share = { title: '', link: shareUrl, imgUrl: 'https://img.erbanyy.com/new-logo.png', desc: '' }; // eslint-disable-next-line function getMessage(key, value) { info[key] = value; } wx.ready(function() { wx.onMenuShareTimeline({ title: share.title, link: share.link, imgUrl: share.imgUrl, desc: share.desc }); wx.onMenuShareAppMessage({ title: share.title, desc: share.desc, link: share.link, imgUrl: share.imgUrl, type: 'link', dataUrl: '' }); wx.onMenuShareQQ({ title: share.title, desc: share.desc, link: share.link, imgUrl: share.imgUrl }); }); erbanMask('activity-name', 'activity-name'); initNav({ type: 2, data: { msg: 'wewawa', link: share.link, title: share.title, showUrl: share.link, imgUrl: share.imgUrl, desc: share.desc } }); browser.weixin && wxConfig(); $(function() { if (env == 'test') { new VConsole(); } var main = { init: function() { this.getMsgFromDevice(); setTimeout(() => { this.getData(); }, 100); this.eventRegister(); }, getMsgFromDevice: function() { if (browser.app) { if (browser.ios) { window.webkit.messageHandlers.getDeviceId.postMessage(null); } else if (browser.android) { if (androidJsObj && typeof androidJsObj === 'object') { info.deviceId = window.androidJsObj.getDeviceId(); } } info.uid = tools.nativeUtils.getUid(); info.ticket = tools.nativeUtils.getTicket(); } else { // info.uid = 906238; info.uid = 906709; info.deviceId = 'safhksafhksajhfs1kjahsfkjsf0000aaaaaaaacaa'; info.ticket = 'eyJhbGciOiJIUzI1NiJ9.eyJ0aWNrZXRfdHlwZSI6bnVsbCwidWlkIjo5MDYyMzgsInRpY2tldF9pZCI6IjdiZWQ2NzcwLWJmMjktNGRiYi04MzZmLTc0NzBmY2RiMDZjYSIsImV4cCI6MzYwMCwiY2xpZW50X2lkIjoiZXJiYW4tY2xpZW50In0.ye2Zv8nyZkqiT_bIWq-50qcS6_SCWmRpBjxxLX7mQvs'; } }, eventRegister: function() { // 打开规则弹窗 $('.rule-btn').on('click', function() { $('.rule-mask,.shade').fadeIn(300); }) // 关闭购买弹窗 $('.buy-mask').on('click', '.close-btn', function() { $('.buy-mask,.shade').fadeOut(300); }) // 关闭规则弹窗 $('.rule-mask').on('click', '.cancel', function() { $('.rule-mask,.shade').fadeOut(300); }) // 关闭购买之后弹窗 $('.statusMask').on('click', '.cancel', function() { $('.statusMask,.shade').fadeOut(300); }) // 关闭弹窗 $('.shade').on('click', function() { $('.rule-mask,.buy-mask,.statusMask,.shade').fadeOut(300); }) // 监听input输入 $('.b-input').bind('input propertychange', function() { var _this = $(this); if (_this.val().length == 1) { _this.val(_this.val().replace(/[^1-9]/gi, '')); } else { _this.val(_this.val().replace(/[\D]/gi, '')); _this.val(parseInt(_this.val())); } if(_this.val() == '') { totalPrice = 0; $('.day').text(0); _this.val(0) }else{ if(_this.val() >= 100000000) { _this.val(100000000) } totalPrice = parseInt(_this.val()) * parseInt(_this.attr('data-price')); $('.day').text(_this.val()); } $('.totalprice').html(totalPrice); }) // 增加按钮 $('.add-btn').on('click', function() { var val = parseInt($('.b-input').val()); var price = parseInt($('.b-input').attr('data-price')); val = val + 1; totalPrice = val * price; $('.day').text(val); $('.b-input').val(val); $('.totalprice').html(totalPrice); }) // 减少按钮 $('.remove-btn').on('click', function() { var val = parseInt($('.b-input').val()); var price = parseInt($('.b-input').attr('data-price')); if(val > 1) { val = val - 1; }else{ val = 1; } totalPrice = val * price; $('.day').text(val); $('.b-input').val(val); $('.totalprice').html(totalPrice); }) // 购买确认 $('.confirm-btn').on('click', function() { var packNum = $('.b-input').val(); var packId = $(this).attr('data-pid'); if(packNum == 0) { ajaxTip('最少购买一个哦~'); return; }else{ $.ajax({ headers: { pub_ticket: info.ticket }, type: 'POST', url: api + '/activity/pack/buy', data: { uid: info.uid, ticket: info.ticket, packId: packId, packNum: packNum }, success: function(res) { if(res) { if (res.code == 200) { // 购买成功 $('.buy-mask').hide().siblings('.statusMask').fadeIn(300); $('.success').show(); $('.fail').hide(); $('.statusMask .tip').html('获赠门票×' + res.data); renderTicket(); } else if (res.code == 2103) { // 余额不足 $('.buy-mask').hide().siblings('.statusMask').fadeIn(300); $('.buy-mask,.success').hide(); $('.fail').show(); $('.statusMask .tip').html('亲,余额不足~'); if (browser.ios) { $('.android').hide(); } else if (browser.android) { $('.ios').hide(); } } else { ajaxTip(res.message); return; } } } }) } }) // 充值跳转 $('.recharge').on('click', function() { if (browser.ios) { $('.statusMask,.shade').fadeOut(300); } else { tools.nativeUtils.jumpAppointPage('RECHARGE_PAGE'); } }) }, getData: function() { renderTicket(); renderGift(); } }; main.init(); }); // 渲染底部tab function renderTicket() { $.ajax({ type: 'GET', url: api + '/activities/draw/queryTicketNum', data: { uid: info.uid }, success: function(res) { if(res.code === 200) { if (res.data.nick.length > 10) { res.data.nick = res.data.nick.substring(0, 10) + '...' } $('.mine').find('.avatar img').attr('src', res.data.avatar) $('.mine').find('.nick').html(res.data.nick) $('.mine').find('.score').html(res.data.num) }else{ ajaxTip(res.message); return; } } }) } // 渲染礼包信息 function renderGift() { $.ajax({ headers: { pub_ticket: info.ticket }, type: 'POST', url: api + '/activities/draw/getPackList', data: { uid: info.uid, ticket: info.ticket }, success: function(res) { if (res.code == 200) { var html = ''; var num = ''; res.data.forEach(function(item, index) { if(item.sellingPrice == 200) { num = '7-10' }else if(item.sellingPrice == 1000) { num = '30-50' }else if(item.sellingPrice == 2000) { num = '70-100' }else if(item.sellingPrice == 10000) { num = '300-500' } // 新增的档位20000,赠送600-1000门票,添加日期2020-12-08 else if(item.sellingPrice == 20000) { num = '600-1000' } html += '
  • ' + '

    限定装扮' + NoToChinese(index + 1) + '

    ' + '
    ' + '
    ' + '

    ' + item.name + '

    ' + '

    ' + item.sellingPrice + '金币/天

    ' + '

    ' + item.originalPrice + '金币/天

    ' + '

    随机赠送门票' + num + '张

    ' + '
    ' + '
    ' + '
  • ' }) $('.cloth-box').html(html); renderBuyStatus(); // 购买弹窗 $('.cloth-box').on('click', '.buy-btn', function() { var packId = $(this).attr('data-gid'); var name = $(this).siblings('.gift-text').find('p:first').text(); var sellingPrice = $(this).siblings('.gift-text').find('.price').attr('data-money'); $('.buy-mask .day').text(1); $('.buy-mask .b-input').val(1); $('.buy-mask .giftName').html(name); $('.buy-mask .totalprice').html(sellingPrice); $('.buy-mask .confirm-btn').attr('data-pid', packId); $('.buy-mask .b-input').attr('data-price', sellingPrice); $('.shade,.buy-mask').fadeIn(300); }) }else{ ajaxTip(res.message); return; } } }) } // 渲染购买状态 function renderBuyStatus() { $.ajax({ type: 'GET', url: api + '/activities/draw/getDate', data: {}, success: function(res) { if(res.code == 200) { var date = new Date().getTime(); var start = (browser.ios) ? res.data.start : res.data.start; var end = (browser.ios) ? res.data.end : res.data.end; if (start < date && date < end) { $('.buy-btn').removeClass('gray').prop('disabled', false); } else { $('.buy-btn').removeClass().addClass('buy-btn gray').prop('disabled', true); } }else{ ajaxTip(res.message); return; } } }) } // 封装提示信息 function ajaxTip(callText) { var thisBody = document.getElementsByTagName('body')[0]; var Div = document.createElement('div'); var text = "

    " + callText + '

    ' Div.setAttribute('class', 'ajaxtiplayer'); Div.innerHTML = text; Div.style.display = 'block'; thisBody.appendChild(Div); setTimeout(function() { thisBody.removeChild(Div); }, 2000); } // 将数字转为中文数字 function NoToChinese(num) { if (!/^\d*(\.\d*)?$/.test(num)) { alert('Number is wrong!'); return 'Number is wrong!'; } // eslint-disable-next-line no-array-constructor var AA = new Array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九'); // eslint-disable-next-line no-array-constructor var BB = new Array('', '十', '百', '千', '万', '亿', '点', ''); var a = ('' + num).replace(/(^0*)/g, '').split('.'); var k = 0; var re = ''; for (var i = a[0].length - 1; i >= 0; i--) { switch (k) { case 0: re = BB[7] + re; break; case 4: if (!new RegExp('0{4}\\d{' + (a[0].length - i - 1) + '}$').test(a[0])) { re = BB[4] + re; } break; case 8: re = BB[5] + re; BB[7] = BB[5]; k = 0; break; } if (k % 4 == 2 && a[0].charAt(i + 2) != 0 && a[0].charAt(i + 1) == 0) re = AA[0] + re; if (a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k % 4] + re; k++; } if (a.length > 1) { re += BB[6]; // eslint-disable-next-line no-redeclare for (var i = 0; i < a[1].length; i++) re += AA[a[1].charAt(i)]; } return re; }