var _Project_Country = ""; // ========================================================== // 骰子跳窗 // ========================================================== ;(function(jQuery, $, window, document) { //測試 let res = {"url":"#", "path":"./images/gift/gift_01.png"} let played = false function playGame(){ $('.dice-start, .dice-static').removeClass('show') $('.dice-end, .dice-dynamic').addClass('show') $.ajax({ url: _Project_Country + '/game/dice/data/ajax_get_gift-p.php', dataType: 'json', async: false, method: 'POST', data: { Act_Game_ID: $("#Act_Game_ID").val(), Order_Num: $("#Act_Order_Num").val(), } }).done(function(res) { //console.log(res) switch(res.status){ case "OK": modelStep = 1 played = true modelCheck(modelStep) $('.dice-start, .dice-static').removeClass('show') $('.dice-end, .dice-dynamic').addClass('show') setTimeout(function(){ let giftText = '' if(res.name && (location.href.indexOf('step2') > 0 )){ giftText = `${res.name}` } $('body').append( `
` ) },3000); if(res.DataLayer){ eval(res.DataLayer) } break; case "TODAY_PLAYED": alert('今天已玩過遊戲了'); closePopup() break; case "ACT_PLAYED": alert('已參加過該活動'); closePopup() break; case "WAIT_FOR_ORDER": alert('已參加過該活動,待結帳後取得下一次遊戲資格'); closePopup() window.location = res.url; break; case "MEMBER_NOT_LOGIN": alert('須登入會員才可遊戲'); window.location = res.url; break; case "ORDER_NOT_FULL": alert('訂單金額不符合遊戲條件'); closePopup() break; case "GAME_OVER": case "ERROR": alert('遊戲已結束'); closePopup() break; } }).fail(function(x, y, z) { //console.log(x) //console.log(y) //console.log(z) }); } function closePopup(){ $('.game-model').fadeOut(400) //購物車頁送出訂單 $("#Form_Submit").click() $(this).parents('.gmodel-wrapper').remove() } $('body').on('click', '.act_game_click_bt', function(e) { e.preventDefault() playGame() }) $('body').on('click', '.dice-start', function(){ playGame() }); $('body').on('click', '.game-model .game-model-closer', function(e) { if(!played){ playGame() } closePopup() }); $('body').on('click', '.gmodel-wrapper .game-model-closer', function(e) { modelStep = 0 modelCheck(modelStep) //購物車頁送出訂單 $("#Form_Submit").click() $(this).parents('.gmodel-wrapper').remove() }) function modelCheck(step) { if(step) { $('body, #game-wrapper').addClass('theme-stock') } else { $('body, #game-wrapper').removeClass('theme-stock') } } })(jQuery, $, window, document)