storePage.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /**
  2. *
  3. * @authors Eric Hsiao
  4. *
  5. */
  6. storePage = function (_couponData) {
  7. //private menbers
  8. var couponData = [];
  9. var popoutClickHandle = function () { };
  10. //private methods
  11. function init() {
  12. console.log('storePage is init.');
  13. //////////////////////////////////////////
  14. //UI
  15. $('.video__close').click(function (e) {
  16. e.preventDefault();
  17. TweenMax.to('.video__popout', 0.3, { autoAlpha: 0 });
  18. player.stopVideo();
  19. });
  20. $('.game__popout__close').click(function (e) {
  21. e.preventDefault();
  22. TweenMax.to('.game__popout', 0.3, { autoAlpha: 0 });
  23. });
  24. $('.game__popout__submit').click(function (e) {
  25. e.preventDefault();
  26. popoutClickHandle();
  27. });
  28. }
  29. function updateCoupon(_data) {
  30. couponData = _data;
  31. console.log('============== updateCoupon ==============');
  32. // console.log(userInfo.goodinfo);
  33. for (let index = 0; index < couponData.length; index++) {
  34. var _coupon;
  35. if (couponData[index].lp < 5) {
  36. _coupon = new couponItem(index, couponData[index]);
  37. } else {
  38. var _isLock = true;
  39. if ($.cookie('luckydraw.isVideoUnlock') === 'true') {
  40. _isLock = false;
  41. } else {
  42. _isLock = true;
  43. }
  44. console.log('luckydraw.isVideoUnlock = ' + $.cookie('luckydraw.isVideoUnlock') + ', _isLock = ' + _isLock);
  45. //YOUTUBE LINK
  46. _coupon = new couponItem(index, $.extend(couponData[index], { lock: _isLock, video: YOUTUBE__ID }));
  47. }
  48. }
  49. }
  50. function showPopout(_html) {
  51. $('.game__popout').show();
  52. TweenMax.set('.game__popout', { autoAlpha: 0 });
  53. $('.game__popout__content .content').hide();
  54. $('.game__popout__submit').hide();
  55. $('.game__popout__content .content__result').show();
  56. $('.game__popout__content .content__result__text').html(_html);
  57. TweenMax.to('.game__popout', 0.5, { autoAlpha: 1 });
  58. }
  59. function useCoupon(_id, _number, _callback) {
  60. //按下submit才執行
  61. popoutClickHandle = function () {
  62. $.ajax({
  63. type: "POST",
  64. url: API__DOMAIN + "api2021/redeem/" + LINE__ID + '/' + _id,
  65. data: {
  66. name: USER__NAME
  67. },
  68. dataType: "json",
  69. success: function (response) {
  70. console.log('================== response ===================');
  71. console.log(response);
  72. if (response.succ) {
  73. //顯示成功與否
  74. showPopout('<p>兌換完成<br>請至LINE錢包<br>查看點數</p>');
  75. //Coupon更新自己狀態
  76. _callback();
  77. //Coupon更新玩家狀態、剩餘點數
  78. // updateUserData();
  79. TweenMax.to('.game__popout', 0.3, { autoAlpha: 0 });
  80. } else {
  81. //錯誤訊訊息
  82. showError("兌換錯誤:<br>" + response.err);
  83. }
  84. },
  85. error: function (XMLHttpRequest, textStatus, errorThrown) {
  86. console.log("Status: " + textStatus + ", Error: " + errorThrown);
  87. // alert('很抱歉,資料讀取錯誤 請稍後再試。');
  88. showError("連線錯誤:<br>" + "Status: " + textStatus + ", Error: " + errorThrown);
  89. }
  90. });
  91. };
  92. }
  93. //////////////////////////////////////
  94. function intoPage() {
  95. }
  96. function leavePage() {
  97. }
  98. //constructor
  99. {
  100. $(document).ready(function () {
  101. init();
  102. });
  103. }
  104. //public
  105. return {
  106. intoPage: function () {
  107. intoPage();
  108. },
  109. leavePage: function () {
  110. leavePage();
  111. },
  112. updateCoupon: function (_data) {
  113. updateCoupon(_data);
  114. },
  115. showPopout: function (_html) {
  116. showPopout(_html);
  117. },
  118. useCoupon: function (_id, _number, _callback) {
  119. useCoupon(_id, _number, _callback);
  120. },
  121. };
  122. };
  123. var storePage = new storePage();
  124. ///////////////////////////////////////////////
  125. var videoCallback;
  126. // Load the IFrame Player API code asynchronously.
  127. var tag = document.createElement('script');
  128. tag.src = "https://www.youtube.com/player_api";
  129. var firstScriptTag = document.getElementsByTagName('script')[0];
  130. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  131. // Replace the 'ytplayer' element with an <iframe> and
  132. // YouTube player after the API code downloads.
  133. var player;
  134. function onYouTubePlayerAPIReady() {
  135. console.log('Yiutube API Ready');
  136. player = new YT.Player('video__content', {
  137. height: '360',
  138. width: '640',
  139. videoId: '',
  140. playerVars: { 'autoplay': 0, 'controls': 0 },
  141. events: {
  142. 'onStateChange': onPlayerStateChange
  143. }
  144. });
  145. }
  146. function onPlayerStateChange(e) {
  147. console.log('onPlayerStateChange');
  148. if (e.data == 0) {
  149. videoCallback();
  150. }
  151. }