main.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /**
  2. *
  3. * @authors Eric Hsiao
  4. *
  5. */
  6. var popAniRoot;
  7. main = function () {
  8. //private menbers
  9. var introAniRoot;
  10. var gameAniRoot;
  11. var isDrawing = false;
  12. var isStore = false;
  13. var drawCount;
  14. var myScore = 0;
  15. var currentScore = 0;
  16. var currentCheckinGp = 0;
  17. var scoreList = [66, 1, 3, 6, 8, 0, 9, 0];
  18. var dailyList = [1, 1, 1, 2, 2, 2, 3];
  19. var currentDaily = 0;
  20. var checkins = [];
  21. var userInfo;
  22. var LINEID;
  23. var name;
  24. var liffInitComplete = false;
  25. var testLINEID = 'Ud2534d6e1eed9cee2c919a993443352b';
  26. var testName = 'noh';
  27. var isComplete = false;
  28. var isLogin = false;
  29. var isCheck = false;
  30. var isCoupon = false;
  31. var errorMsg = '';
  32. var isAllSoldout = false;
  33. var popoutClickHandle = function () { };
  34. //private methods
  35. function init() {
  36. if (getParameterByName('test') == 1) {
  37. var vConsole = new VConsole();
  38. }
  39. console.log('main is loaded. v1005');
  40. initLiff();
  41. TweenMax.to('.page__overlayer', 0.3, { delay: 1.2, autoAlpha: 0 })
  42. var _myAnimate = new createAnimate();
  43. _myAnimate.load($('.intro__content'), 'intro',
  44. function (_exportRoot) {
  45. introAniRoot = _exportRoot;
  46. setTimeout(function () {
  47. introAniRoot.play();
  48. }, 500);
  49. });
  50. var image = new Image();
  51. image.onload = function () {
  52. // ... 在圖片載入後要進行的操作 ...
  53. console.log('gameAni image onload.');
  54. _myAnimate.load($('.main__game'), 'gameAni',
  55. function (_exportRoot) {
  56. gameAniRoot = _exportRoot;
  57. setTimeout(function () {
  58. introAniRoot.isComplete = true;
  59. }, 500);
  60. gameAniRoot.stop();
  61. initGame();
  62. });
  63. }
  64. image.src = 'images/gameAni/gameAni_atlas_1.png';
  65. $('.main__pop').hide();
  66. _myAnimate.load($('.main__pop'), 'popAni',
  67. function (_exportRoot) {
  68. popAniRoot = _exportRoot;
  69. popAniRoot.stop();
  70. //修正字體
  71. popAniRoot.get_btn.score_txt.textBaseline = "alphabetic";
  72. popAniRoot.get_btn.score_txt.y = 77;
  73. popAniRoot.content_mc.a_icon.content_txt.textBaseline = "alphabetic";
  74. popAniRoot.content_mc.b_icon.content_txt.textBaseline = "alphabetic";
  75. popAniRoot.content_mc.a_icon.content_txt.y = 80;
  76. popAniRoot.content_mc.b_icon.content_txt.y = 80;
  77. });
  78. $('.game__popout__close').click(function (e) {
  79. e.preventDefault();
  80. TweenMax.to('.game__popout', 0.3, { autoAlpha: 0 });
  81. });
  82. $('.game__popout__submit').click(function (e) {
  83. e.preventDefault();
  84. popoutClickHandle();
  85. });
  86. onResize();
  87. $(window).resize(function () {
  88. onResize();
  89. });
  90. }
  91. function initLiff() {
  92. console.log('liff.init');
  93. liff.init({
  94. liffId: URL__LIFF__ID //test
  95. })
  96. .then(() => {
  97. if (!liff.isLoggedIn()) {// 如果沒有登入LINE,就登入
  98. liff.login();
  99. }
  100. })
  101. .catch((err) => {
  102. // Error happens during initialization
  103. console.log(err.code, err.message);
  104. showError('LINE系統連線錯誤:<br>' + err.message);
  105. });
  106. }
  107. function onResize() {
  108. var _h = $(window).height();
  109. var _d = $(window).height() / 1138;
  110. if (_d > 1) _d = 1;
  111. TweenMax.set('.game__fixed', { scale: _d });
  112. }
  113. function gameInto() {
  114. // initLiff();
  115. // console.log('initLiff');
  116. liff.getProfile().then(function (e) {
  117. LINEID = e.userId;
  118. name = e.displayName;
  119. // if (getParameterByName('test') == 1) {
  120. // LINEID = testLINEID;
  121. // name = testName;
  122. // }
  123. console.log("LINEID : " + LINEID + ' , name : ' + name);
  124. updateUserData();
  125. });
  126. }
  127. function initGame() {
  128. gameAniRoot.luckydraw_mc.mainCTA_mc.addEventListener("click", handleCTAClick);
  129. function handleCTAClick(event) {
  130. if (isAllSoldout) {
  131. showError('<span style="font-size:0.8em">本次活動已結束<br>敬請期待下次遊戲。</span>');
  132. } else if (isComplete) {
  133. // showError('今天已經轉過,歡迎明天再來!');
  134. // showError('<span style="font-size:0.8em">今天已經轉過,<br>歡迎明天再來!<br>別忘了振興五倍券,<br>綁台灣Pay超優惠~</span>');
  135. showError('<span style="font-size:0.8em">活動已結束,<br>獎品兌換期限至12/6。<br>敬請期待下次活動!</span>');
  136. } else {
  137. if (!isDrawing) {
  138. isDrawing = true;
  139. //set drawCount
  140. //按下按鈕即開始轉動
  141. // gameAniRoot.luckydraw_mc.mainSpin_mc.gotoAndPlay('rolling');
  142. gameAniRoot.luckydraw_mc.mainCTA_mc.gotoAndPlay('rolling');
  143. gameAniRoot.luckydraw_mc.mainARR_mc.gotoAndPlay('rolling');
  144. gameAniRoot.luckydraw_mc.mainEffect_mc.flag_mc.gotoAndPlay('rolling');
  145. //讀取結果
  146. getGameGp(function (_res) {
  147. //顯示結果
  148. luckydrawStart();
  149. });
  150. }
  151. }
  152. }
  153. popAniRoot.addEventListener("click", handleGetClick);
  154. function handleGetClick(event) {
  155. $('.main__pop').hide();
  156. $('.main__pop__overlayer').hide();
  157. popAniRoot.gotoAndStop(0);
  158. // gameAniRoot.luckydraw_mc.mainCTA_mc.gotoAndPlay('stand');
  159. //更新分數
  160. // addScore(currentScore);
  161. updateScore();
  162. //取得Server data
  163. updateUserData();
  164. gameAniRoot.luckydraw_mc.store_mc.gotoAndPlay('complete');
  165. //更新打卡
  166. for (let index = 0; index < checkins.length; index++) {
  167. gameAniRoot.luckydraw_mc.dalylogin_mc['checkin_mc_' + index].alpha = 1;
  168. }
  169. // gameAniRoot.luckydraw_mc.dalylogin_mc['checkin_mc_' + (currentDaily - 1)].alpha = 1;
  170. }
  171. gameAniRoot.luckydraw_mc.store_mc.addEventListener("click", handleStoreClick);
  172. function handleStoreClick(event) {
  173. if (!isDrawing && !isStore) {
  174. isStore = true;
  175. gameAniRoot.luckydraw_mc.gotoAndPlay('storeInto');
  176. //每次進商店前就更新
  177. updateUserData();
  178. }
  179. }
  180. gameAniRoot.luckydraw_mc.storeClose_btn.addEventListener("click", handleStoreCloseClick);
  181. function handleStoreCloseClick(event) {
  182. gameAniRoot.luckydraw_mc.gotoAndPlay('storeClose');
  183. $('.game__store').hide();
  184. }
  185. }
  186. function updateGameContent() {
  187. //更新打卡
  188. console.log('========== updateGameContent ========');
  189. for (let index = 0; index < checkins.length; index++) {
  190. console.log('index = ' + index);
  191. gameAniRoot.luckydraw_mc.dalylogin_mc['checkin_mc_' + index].alpha = 1;
  192. //更新轉盤狀態
  193. if (userInfo.roundinfo.today == checkins[index].date) {
  194. isCheck = true;
  195. console.log('今日已簽到');
  196. }
  197. }
  198. //更新商店按鈕
  199. if (myScore > 0) {
  200. gameAniRoot.luckydraw_mc.store_mc.gotoAndPlay('complete');
  201. }
  202. //皆無庫存
  203. var selloutCount = 0;
  204. for (let index = 0; index < userInfo.goodinfo.length; index++) {
  205. if (userInfo.goodinfo[index].issoldout) {
  206. selloutCount++;
  207. console.log('selloutCount = ' + selloutCount);
  208. if (selloutCount >= userInfo.goodinfo.length) {
  209. showError('<span style="font-size:0.8em">本次活動已結束<br>敬請期待下次遊戲。</span>');
  210. isAllSoldout = true;
  211. }
  212. }
  213. }
  214. /*if (selloutCount >= userInfo.goodinfo.length) {
  215. $('.game__popout__content .content').hide();
  216. $('.game__popout__submit').hide();
  217. $('.game__popout__content .content__result').show();
  218. $('.game__popout__content .content__result__text').html('<p>活動已結束<br>感謝您的參與!​</p>');
  219. showPopout();
  220. }*/
  221. //更新Coupon
  222. updateCoupon();
  223. }
  224. function updateLogin() {
  225. if (isLogin) {
  226. setTimeout(function () {
  227. gameAniRoot.play();
  228. introAniRoot.gotoAndPlay('intoGame');
  229. }, 1000);
  230. //初始化分數
  231. setTimeout(function () {
  232. updateScore();
  233. updateGameContent();
  234. }, 2500);
  235. setTimeout(function () {
  236. // showError('<span style="font-size:0.8em">轉盤內優惠公告訊息,<br>為台灣Pay振興五倍券專屬優惠,<br>詳情洽台灣Pay官方網站。</span>');
  237. showError('<span style="font-size:0.8em">活動已結束,<br>獎品兌換期限至12/6。<br>敬請期待下次活動!</span>');
  238. }, 2800);
  239. } else {
  240. if (errorMsg == '請先加入 LINE 好友') {
  241. setTimeout(function () {
  242. alert('請先完成註冊,再重新進入遊戲');
  243. liff.openWindow({
  244. url: URL__REGISTER,
  245. external: false
  246. });
  247. }, 300);
  248. } else {
  249. showError('系統訊息:<br>' + errorMsg);
  250. $('.game__popout__close').click(function (e) {
  251. liff.closeWindow();
  252. });
  253. }
  254. }
  255. }
  256. function updateUserData() {
  257. console.log('================== updateUserData ===================');
  258. $.ajax({
  259. type: "GET",
  260. url: API__DOMAIN + "api2021/info/" + LINEID,
  261. data: {
  262. // LINEID: LINEID
  263. },
  264. dataType: "json",
  265. success: function (response) {
  266. if (response.succ) {
  267. userInfo = response.info;
  268. checkins = userInfo.roundinfo.checkins;
  269. myScore = userInfo.playerinfo.gp;
  270. ////////////////////////////////////////////////////////////////////
  271. //渲染coupon前
  272. //調整顯示邏輯 只允許 LP = 1、2、3、5
  273. var _blankGoodinfo = [
  274. { "id": 0, "lp": 1, "gp": 10, "issoldout": true, "isredeemed": false, "isnomoney": false, "canuse": false, "fromAPI": false },
  275. { "id": 0, "lp": 2, "gp": 20, "issoldout": true, "isredeemed": false, "isnomoney": false, "canuse": false, "fromAPI": false },
  276. { "id": 0, "lp": 3, "gp": 30, "issoldout": true, "isredeemed": false, "isnomoney": false, "canuse": false, "fromAPI": false },
  277. { "id": 0, "lp": 5, "gp": 50, "issoldout": true, "isredeemed": false, "isnomoney": false, "canuse": false, "fromAPI": false }
  278. ];
  279. for (let index = 0; index < userInfo.goodinfo.length; index++) {
  280. var _goodinfoData = userInfo.goodinfo[index];
  281. //檢查是否有coupon被API隱藏
  282. for (let blankIndex = 0; blankIndex < _blankGoodinfo.length; blankIndex++) {
  283. if (_goodinfoData.lp == _blankGoodinfo[blankIndex].lp) {
  284. //將blankGoodinfo替換為符合條件的userInfo.goodinfo
  285. //加入fromAPI屬性
  286. _goodinfoData.fromAPI = true;
  287. _blankGoodinfo[blankIndex] = _goodinfoData;
  288. }
  289. }
  290. }
  291. //覆寫 userInfo.goodinfo
  292. userInfo.goodinfo = _blankGoodinfo;
  293. console.log('========= Set userInfo.goodinfo ===========');
  294. console.log(userInfo.goodinfo);
  295. /////////////////////////////////////////////////////////////////////
  296. if (!isLogin) {
  297. isLogin = true;
  298. updateLogin();
  299. } else {
  300. // if (!isCoupon) initCoupon();
  301. updateGameContent();
  302. }
  303. if (!isCoupon) initCoupon();
  304. console.log(userInfo);
  305. } else {
  306. /*if (response.err == '請先加入 LINE 好友') {
  307. isLogin = false;
  308. } else {
  309. showError(response.err);
  310. }*/
  311. isLogin = false;
  312. errorMsg = response.err;
  313. updateLogin();
  314. }
  315. },
  316. error: function (XMLHttpRequest, textStatus, errorThrown) {
  317. console.log("Status: " + textStatus + ", Error: " + errorThrown);
  318. showError('使用者資料連線錯誤:<br>' + "Status: " + textStatus + ", Error: " + errorThrown);
  319. TweenMax.to('.loading', 0.3, { autoAlpha: 0 });
  320. }
  321. });
  322. }
  323. function getGameGp(_callback) {
  324. // drawCount = Math.floor(Math.random() * 8);
  325. // _callback();
  326. $.ajax({
  327. type: "POST",
  328. url: API__DOMAIN + "api2021/game/" + LINEID,
  329. data: {
  330. name: name
  331. },
  332. dataType: "json",
  333. success: function (response) {
  334. console.log('================== response ===================');
  335. console.log(response);
  336. if (response.succ) {
  337. currentScore = response.currentGameGp;
  338. currentCheckinGp = response.currentCheckinGp;
  339. myScore = response.gpAll;
  340. console.log('本次轉盤點數為 : ' + response.currentGameGp);
  341. console.log('本次簽到點數為 : ' + response.currentCheckinGp);
  342. if (response.currentGameGp == -1) isComplete = false;
  343. switch (currentScore) {
  344. case 66:
  345. drawCount = 0;
  346. break;
  347. case 1:
  348. drawCount = 1;
  349. break;
  350. case 3:
  351. drawCount = 2;
  352. break;
  353. case 6:
  354. drawCount = 3;
  355. break;
  356. case 8:
  357. drawCount = 4;
  358. break;
  359. case 0:
  360. drawCount = 5;
  361. break;
  362. case 9:
  363. drawCount = 6;
  364. break;
  365. case -1:
  366. drawCount = 7;
  367. break;
  368. }
  369. _callback();
  370. } else {
  371. // showError('<span style="font-size:0.8em">今天已經轉過,<br>歡迎明天再來!<br>別忘了振興五倍券,<br>綁台灣Pay超優惠~</span>');
  372. showError('<span style="font-size:0.8em">活動已結束,<br>獎品兌換期限至12/6。<br>敬請期待下次活動!</span>');
  373. isDrawing = false;
  374. gameAniRoot.luckydraw_mc.mainSpin_mc.gotoAndPlay('stand');
  375. // gameAniRoot.luckydraw_mc.mainCTA_mc.gotoAndPlay('stand');
  376. gameAniRoot.luckydraw_mc.mainARR_mc.gotoAndPlay('stand');
  377. gameAniRoot.luckydraw_mc.mainEffect_mc.flag_mc.gotoAndPlay('stand');
  378. isComplete = true;
  379. }
  380. },
  381. error: function (XMLHttpRequest, textStatus, errorThrown) {
  382. console.log("Status: " + textStatus + ", Error: " + errorThrown);
  383. // alert('很抱歉,資料讀取錯誤 請稍後再試。');
  384. showError('資料庫連線錯誤:<br>' + "Status: " + textStatus + ", Error: " + errorThrown);
  385. TweenMax.to('.loading', 0.3, { autoAlpha: 0 });
  386. }
  387. });
  388. }
  389. function luckydrawStart() {
  390. console.log('drawCount = ' + drawCount);
  391. isDrawing = true;
  392. // gameAniRoot.luckydraw_mc.mainSpin_mc.gotoAndPlay('rolling');
  393. // gameAniRoot.luckydraw_mc.mainCTA_mc.gotoAndPlay('rolling');
  394. // gameAniRoot.luckydraw_mc.mainARR_mc.gotoAndPlay('rolling');
  395. // gameAniRoot.luckydraw_mc.mainEffect_mc.flag_mc.gotoAndPlay('rolling');
  396. gameAniRoot.luckydraw_mc.mainSpin_mc.gotoAndPlay('rolling');
  397. gameAniRoot.luckydraw_mc.mainSpin_mc.wheel_mc.isComplete = false;
  398. setTimeout(function () {
  399. gameAniRoot.luckydraw_mc.mainSpin_mc.wheel_mc.setComplete(drawCount);
  400. }, 500);
  401. // gameAniRoot.luckydraw_mc.mainSpin_mc.wheel_mc.setComplete(drawCount);
  402. }
  403. function luckydrawComplete() {
  404. // isComplete = true;
  405. gameAniRoot.luckydraw_mc.mainTitle_mc.gotoAndPlay('complete');
  406. gameAniRoot.luckydraw_mc.mainSpin_mc.gotoAndPlay('complete');
  407. gameAniRoot.luckydraw_mc.mainARR_mc.gotoAndPlay('complete');
  408. gameAniRoot.luckydraw_mc.mainEffect_mc.flag_mc.gotoAndPlay('complete');
  409. gameAniRoot.luckydraw_mc.mainCTA_mc.gotoAndPlay('complete');
  410. if (drawCount == 7) {
  411. //再轉一次
  412. setTimeout(function () {
  413. // luckydrawStart();
  414. setTimeout(function () {
  415. isComplete = false;
  416. isDrawing = false;
  417. gameAniRoot.luckydraw_mc.mainCTA_mc.gotoAndPlay('stand');
  418. }, 1000);
  419. if (currentCheckinGp !== 0) {
  420. $('.main__pop').show();
  421. $('.main__pop__overlayer').show();
  422. popAniRoot.gotoAndPlay('into');
  423. console.log('再轉一次');
  424. popAniRoot.content_mc.a_icon.content_txt.text = 0;
  425. popAniRoot.content_mc.b_icon.content_txt.text = currentCheckinGp;
  426. // currentDaily++;
  427. if (!isCheck) {
  428. isCheck = true;
  429. gameAniRoot.luckydraw_mc.dalylogin_mc['checkin_mc_' + checkins.length].alpha = 1;
  430. }
  431. popAniRoot.get_btn.score_txt.text = currentCheckinGp;
  432. }
  433. }, 300);
  434. } else {
  435. isDrawing = false;
  436. $('.main__pop').show();
  437. $('.main__pop__overlayer').show();
  438. popAniRoot.gotoAndPlay('into');
  439. popAniRoot.content_mc.a_icon.content_txt.text = currentScore;
  440. popAniRoot.content_mc.b_icon.content_txt.text = currentCheckinGp;
  441. currentScore += currentCheckinGp;
  442. // currentDaily++;
  443. if (!isCheck) {
  444. isCheck = true;
  445. gameAniRoot.luckydraw_mc.dalylogin_mc['checkin_mc_' + checkins.length].alpha = 1;
  446. }
  447. popAniRoot.get_btn.score_txt.text = currentScore;
  448. isComplete = true;
  449. }
  450. }
  451. function addScore(_number) {
  452. myScore += _number;
  453. updateScore();
  454. }
  455. function updateScore() {
  456. $('.game__myScore').text(myScore);
  457. }
  458. function storeIntoComplete() {
  459. // $('.game__store').show();
  460. $('.game__store').show();
  461. //init loadStore
  462. TweenMax.set('.game__store', { autoAlpha: 0 });
  463. TweenMax.to('.game__store', 0.3, { autoAlpha: 1 });
  464. }
  465. function initCoupon() {
  466. isCoupon = true;
  467. $('.video__close').click(function (e) {
  468. e.preventDefault();
  469. TweenMax.to('.video__popout', 0.3, { autoAlpha: 0 });
  470. // $('.video__content').html('');
  471. player.stopVideo();
  472. });
  473. //updateCoupon
  474. updateCoupon();
  475. }
  476. function updateCoupon() {
  477. console.log('============== updateCoupon ==============');
  478. // console.log(userInfo.goodinfo);
  479. $('.game__store__coupon').html('');
  480. if (userInfo.goodinfo == '') {
  481. console.log('goodinfo 初始狀態');
  482. }
  483. var _soldout = 0;
  484. //////////////////////////////////////////////////////////////////////
  485. //渲染coupon
  486. for (let index = 0; index < userInfo.goodinfo.length; index++) {
  487. var _coupon;
  488. if (userInfo.goodinfo[index].lp < 5) {
  489. _coupon = new couponItem(index, userInfo.goodinfo[index]);
  490. } else {
  491. var _isLock;
  492. if ($.cookie('luckydraw.isVideoUnlock')) {
  493. _isLock = false;
  494. } else {
  495. _isLock = true;
  496. }
  497. console.log('luckydraw.isVideoUnlock = ' + $.cookie('luckydraw.isVideoUnlock'));
  498. //YOUTUBE LINK
  499. _coupon = new couponItem(index, $.extend(userInfo.goodinfo[index], { lock: _isLock, video: 'mDD48KKCqYw' }));
  500. }
  501. }
  502. }
  503. function showPopout() {
  504. $('.game__popout').show();
  505. TweenMax.set('.game__popout', { autoAlpha: 0 });
  506. TweenMax.to('.game__popout', 0.5, { autoAlpha: 1 });
  507. }
  508. /* function useCoupon(_number, _callback) {
  509. var _tempScore = myScore;
  510. if (_tempScore + _number < 0) {
  511. alert('很抱歉,吉點不足。');
  512. } else {
  513. addScore(_number);
  514. TweenMax.to('.game__popout', 0.3, { autoAlpha: 0 });
  515. //call 打點API
  516. //讀取Coupon新Data
  517. setTimeout(function () {
  518. //顯示成功與否
  519. $('.game__popout__content .content').hide();
  520. $('.game__popout__submit').hide();
  521. $('.game__popout__content .content__result').show();
  522. $('.game__popout__content .content__result__text').html('<p>兌換完成<br>請至LINE錢包<br>查看點數</p>');
  523. TweenMax.to('.game__popout', 0.5, { autoAlpha: 1 });
  524. //Coupon更新自己狀態
  525. _callback();
  526. }, 500);
  527. }
  528. }*/
  529. function useCoupon(_id, _number, _callback) {
  530. addScore(_number);
  531. TweenMax.to('.game__popout', 0.3, { autoAlpha: 0 });
  532. $.ajax({
  533. type: "POST",
  534. url: API__DOMAIN + "api2021/redeem/" + LINEID + '/' + _id,
  535. data: {
  536. name: name
  537. },
  538. dataType: "json",
  539. success: function (response) {
  540. console.log('================== response ===================');
  541. console.log(response);
  542. if (response.succ) {
  543. //顯示成功與否
  544. $('.game__popout__content .content').hide();
  545. $('.game__popout__submit').hide();
  546. $('.game__popout__content .content__result').show();
  547. $('.game__popout__content .content__result__text').html('<p>兌換完成<br>請至LINE錢包<br>查看點數</p>');
  548. showPopout();
  549. //Coupon更新自己狀態
  550. _callback();
  551. updateUserData();
  552. } else {
  553. showError("兌換錯誤:<br>" + response.err);
  554. }
  555. },
  556. error: function (XMLHttpRequest, textStatus, errorThrown) {
  557. console.log("Status: " + textStatus + ", Error: " + errorThrown);
  558. // alert('很抱歉,資料讀取錯誤 請稍後再試。');
  559. showError("連線錯誤:<br>" + "Status: " + textStatus + ", Error: " + errorThrown);
  560. TweenMax.to('.loading', 0.3, { autoAlpha: 0 });
  561. }
  562. });
  563. }
  564. function showLoading() {
  565. }
  566. function showError(_msg) {
  567. if (isAllSoldout) {
  568. _msg = '<span style="font-size:0.8em">本次活動已結束<br>敬請期待下次遊戲。</span>';
  569. }
  570. //顯示成功與否
  571. $('.game__popout__content .content').hide();
  572. $('.game__popout__submit').hide();
  573. $('.game__popout__content .content__result').show();
  574. $('.game__popout__content .content__result__text').html('<p>系統忙碌中<br>請稍後再試</p>');
  575. showPopout();
  576. if (_msg != undefined) {
  577. $('.game__popout__content .content__result__text').html('<p>' + _msg + '</p>');
  578. }
  579. }
  580. //constructor
  581. {
  582. $(document).ready(function () {
  583. init();
  584. });
  585. }
  586. //public
  587. return {
  588. gameInto: function () {
  589. console.log('gameInto');
  590. gameInto();
  591. },
  592. luckydrawComplete: function () {
  593. luckydrawComplete();
  594. },
  595. storeIntoComplete: function () {
  596. storeIntoComplete();
  597. },
  598. storeCloseComplete: function () {
  599. isStore = false;
  600. },
  601. showPopout: function (_clickHandle) {
  602. showPopout();
  603. popoutClickHandle = _clickHandle;
  604. },
  605. useCoupon: function (_id, _number, _callback) {
  606. useCoupon(_id, _number, _callback);
  607. },
  608. }
  609. };
  610. var main = new main();