card.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. $(function() {
  2. // 禁止微信字体修改
  3. (function () {
  4. if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
  5. handleFontSize();
  6. } else {
  7. if (document.addEventListener) {
  8. document.addEventListener("WeixinJSBridgeReady", handleFontSize, false);
  9. } else if (document.attachEvent) {
  10. document.attachEvent("WeixinJSBridgeReady", handleFontSize);
  11. document.attachEvent("onWeixinJSBridgeReady", handleFontSize);
  12. }
  13. }
  14. function handleFontSize() {
  15. // 设置网页字体为默认大小
  16. WeixinJSBridge.invoke('setFontSizeCallback', {
  17. 'fontSize': 0
  18. });
  19. // 重写设置网页字体大小的事件
  20. WeixinJSBridge.on('menu:setfont', function () {
  21. WeixinJSBridge.invoke('setFontSizeCallback', {
  22. 'fontSize': 0
  23. })
  24. });
  25. }
  26. })();
  27. var dev = false; // 测试数据开关
  28. var $cards = $(".box li"), //所有卡牌
  29. $maskCard = $("#mask-card"), //翻牌遮罩
  30. length = $cards.length,
  31. index = length, //轮流滚动的卡牌下标
  32. data = 9999, //次数
  33. rem = 72,
  34. initArr = [
  35. [80 / rem, 0],
  36. [280 / rem, 0],
  37. [480 / rem, 0],
  38. [80 / rem, 300 / rem],
  39. [280 / rem, 300 / rem],
  40. [480 / rem, 300 / rem]
  41. ], //卡牌位置数组
  42. clickTime = 0,
  43. bool = false, //首次点击时不能在卡牌归位期间
  44. timer, //轮流提示定时器
  45. nowTab = 0;
  46. var isFirst = true;
  47. $("#change").html(data);
  48. var timer_a = null;
  49. var list_data = { // Tab 中奖名单nameList,我的奖品recordList
  50. 'nameList': '',
  51. 'recordList': ''
  52. };
  53. var srandom = Math.random();
  54. var _data = '';
  55. //url参数
  56. var actId = GetQueryString('actId') || '';
  57. var url = GetQueryString('json'),
  58. opub,
  59. opri,
  60. drawtime = null,
  61. drawopen = true,
  62. getdrawdata,
  63. tiptime = null;
  64. var isiOS = false;
  65. // 判断是否在url拿到json参数
  66. if (url) {
  67. url = JSON.parse(url);
  68. if (url['pub']) {
  69. opub = url['pub'];
  70. if (!opub.p) {
  71. opub.p = 0;
  72. // wifilogdp([602,'json_pub_p_null']);
  73. }
  74. // 通过参数确认是否是ios
  75. try {
  76. if (opub.appCode == 'i001') {
  77. isiOS = true;
  78. }
  79. } catch (e) {
  80. console.log(e);
  81. }
  82. } else {
  83. console.log('没有拿到pub参数');
  84. // wifilogdp([602,'json_pub_null']);
  85. }
  86. if (url['pri']) {
  87. opri = url['pri'];
  88. if (!opri.uId) {
  89. opri = {
  90. 'uId': 0
  91. };
  92. // wifilogdp([602,'json_pri_uId_null']);
  93. }
  94. } else {
  95. opri = {
  96. 'uId': 0
  97. };
  98. console.log('没有拿到pri参数');
  99. // wifilogdp([602,'json_pri_null']);
  100. }
  101. } else {
  102. console.log('没有拿到json参数');
  103. // wifilogdp([602,'json_null']);
  104. }
  105. if (dev) {
  106. _data = {
  107. "data": {
  108. "userAwardList": [{
  109. "awardName": "再来一次",
  110. "type": 6,
  111. "bookId": null
  112. },
  113. {
  114. "awardName": "100成长值",
  115. "type": 4,
  116. "bookId": null
  117. },
  118. {
  119. "awardName": "100成长值",
  120. "type": 4,
  121. "bookId": null
  122. },
  123. {
  124. "awardName": "再来一次",
  125. "type": 6,
  126. "bookId": null
  127. },
  128. {
  129. "awardName": "10元话费",
  130. "type": 2,
  131. "bookId": null
  132. },
  133. {
  134. "awardName": "10元话费",
  135. "type": 2,
  136. "bookId": null
  137. },
  138. {
  139. "awardName": "再来一次",
  140. "type": 6,
  141. "bookId": null
  142. },
  143. {
  144. "awardName": "100成长值",
  145. "type": 4,
  146. "bookId": null
  147. },
  148. {
  149. "awardName": "再来一次",
  150. "type": 6,
  151. "bookId": null
  152. },
  153. {
  154. "awardName": "100成长值",
  155. "type": 4,
  156. "bookId": null
  157. }
  158. ],
  159. "drawNum": 175,
  160. "endTime": 287798618,
  161. "awardList": [{
  162. "id": 77,
  163. "name": "68元小说",
  164. "type": 5,
  165. "img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/prize2.png"
  166. },
  167. {
  168. "id": 78,
  169. "name": "58看点",
  170. "type": 1,
  171. "img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/prize5.png"
  172. },
  173. {
  174. "id": 79,
  175. "name": "kindle",
  176. "type": 3,
  177. "img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/prize1.jpg"
  178. },
  179. {
  180. "id": 81,
  181. "name": "100成长值",
  182. "type": 4,
  183. "img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/grow.png"
  184. },
  185. {
  186. "id": 82,
  187. "name": "10元话费",
  188. "type": 2,
  189. "img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/huafei.jpg"
  190. },
  191. {
  192. "id": 83,
  193. "name": "100看点",
  194. "type": 1,
  195. "img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/prize4.png"
  196. }
  197. ]
  198. },
  199. "code": 1,
  200. "msg": "获取列表成功"
  201. }
  202. // data结束
  203. // renderData(_data);
  204. init();
  205. var _nameList = [{
  206. 'id': '123****8282',
  207. 'type': 1,
  208. 'name': '《斗魂1大陆》'
  209. }, {
  210. 'id': '123****8282',
  211. 'type': 1,
  212. 'name': '《斗魂2大陆》'
  213. }, {
  214. 'id': '123****8282',
  215. 'type': 1,
  216. 'name': '《斗魂3大陆》'
  217. }, {
  218. 'id': '123****8282',
  219. 'type': 1,
  220. 'name': '《斗魂4大陆》'
  221. }, {
  222. 'id': '123****8282',
  223. 'type': 1,
  224. 'name': '《斗魂5大陆》'
  225. }, {
  226. 'id': '123****8282',
  227. 'type': 1,
  228. 'name': '《斗魂6大陆》'
  229. }, {
  230. 'id': '123****8282',
  231. 'type': 1,
  232. 'name': '《斗魂7大陆》'
  233. }, {
  234. 'id': '123****8282',
  235. 'type': 1,
  236. 'name': '《斗魂8大陆》'
  237. }, {
  238. 'id': '123****8282',
  239. 'type': 1,
  240. 'name': '《斗魂9大陆》'
  241. }, {
  242. 'id': '123****8282',
  243. 'type': 1,
  244. 'name': '《斗魂0大陆》'
  245. }];
  246. var _recordList = [{
  247. 'type': 1,
  248. 'name': '《斗魂1大陆》',
  249. 'url': '#1111##'
  250. }, {
  251. 'type': 2,
  252. 'name': '12天VIP会员',
  253. 'url': '##2222##'
  254. }, {
  255. 'type': 3,
  256. 'name': '100 代金券',
  257. 'url': ''
  258. }, {
  259. 'type': 4,
  260. 'name': '华为 Nova 7s',
  261. 'url': '##333##'
  262. }];
  263. list_data.nameList = _nameList;
  264. list_data.recordList = _recordList;
  265. renderLi();
  266. } else {
  267. // 非测试数据时运行
  268. if (!opub || opub.p < 24) {
  269. // tipbox('您当前版本太低<br/>请升级到最新版本参与该活动');
  270. // wifilogdp([602,'opub_'+ (!opub ? 'null' : 'p_' + opub.p)]);
  271. // return false;
  272. fnGetPrizeList();
  273. } else {
  274. fnGetPrizeList();
  275. }
  276. }
  277. // ios:i001
  278. // 游戏开始
  279. // 获取基本信息
  280. function fnGetPrizeList() {
  281. $.ajax({
  282. url: '/api/card/getAwardList',
  283. type: 'post',
  284. timeout: 5000,
  285. // dataType: 'json',
  286. // contentType: 'application/json',
  287. data: {
  288. actId: actId,
  289. },
  290. success: function(data) {
  291. var odata = data.data;
  292. switch (data.code) {
  293. case 1:
  294. // 存储 Banner图和规则
  295. var storage = window.localStorage;
  296. storage.fanpaiRule = odata.rule;
  297. storage.fanpaiImg = odata.img;
  298. // 渲染图片及消耗看点数量
  299. // $('.bannerImg').attr('src', odata.img);
  300. $('.consume_num').html(odata.playAmount);
  301. var bgColorM = odata.mainColor || '';
  302. if (bgColorM) {
  303. $('html,body,#wrap').css('background-color', bgColorM);
  304. $('.banner .after').css({
  305. 'background': '-moz-linear-gradient(top, rgba(255,255,255,0) 0%, ' + bgColorM + ' 100%)',
  306. 'background': '-webkit-linear-gradient(top, rgba(255,255,255,0) 0%,' + bgColorM + ' 100%)',
  307. 'background': 'linear-gradient(to bottom, rgba(255,255,255,0) 0%,' + bgColorM + ' 100%)'
  308. })
  309. }
  310. renderData(odata); // 渲染奖品展示图和名称
  311. init(); // 初始化动画效果
  312. // 改变数据中奖广播
  313. list_data.nameList = []; // 清空数组
  314. list_data.nameList = odata.win_list;
  315. // 改变数据中奖记录
  316. list_data.recordList = []; // 清空数组
  317. list_data.recordList = odata.record_award;
  318. // 渲染Tab 改变数据/中奖记录
  319. renderLi();
  320. break;
  321. default:
  322. // $('.bannerImg').attr('src', odata.img);
  323. break;
  324. }
  325. },
  326. error: function() {
  327. $('#dialog-no').show();
  328. /*jshint multistr: true */
  329. $('#dialog-no .win_show').html('<div class="div2">活动过于火爆,请稍候再试</div>\
  330. <div class="btns">\
  331. <a href="javascript:;" class="redlongbtn closebtn">朕知道了</a>\
  332. </div>');
  333. }
  334. });
  335. }
  336. //获取地址栏参数
  337. function GetQueryString(name) {
  338. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  339. var r = window.location.search.substr(1).match(reg);
  340. if (r != null) {
  341. return unescape(r[2]);
  342. }
  343. return '';
  344. }
  345. //json 字符串 对象 互转 objstr必须是对象或者是对象格式的字符串
  346. function jsonStr(objStr) {
  347. if (!objStr) {
  348. return objStr;
  349. }
  350. if (typeof objStr == 'object') {
  351. return JSON.stringify(objStr);
  352. } else if (typeof objStr == 'string') {
  353. return JSON.parse(objStr);
  354. } else {
  355. //console.log('objStr:"是一个'+typeof objStr+'"类型 既不是对象也不是对象格式的字符串')
  356. return objStr;
  357. }
  358. }
  359. // 随机打乱数组
  360. // function shuffle(arr) {
  361. // var arr = arr || [];
  362. // var i = arr.length;
  363. // while (i) {
  364. // var j = Math.floor(Math.random() * i--);
  365. // [arr[j], arr[i]] = [arr[i], arr[j]];
  366. // }
  367. // return arr;
  368. // }
  369. //url地址多问号修复
  370. function sHrefReplace(url) {
  371. var reg = /\s+/g;
  372. var reg_2 = /\?/g;
  373. var reg_amp = /amp;/g;
  374. url = decodeURIComponent(url);
  375. url = url.replace(reg, '');
  376. url = url.replace(reg_amp, '');
  377. url = url.replace(reg_2, '&');
  378. url = url.replace(/&{2,}/g, '&');
  379. url = url.replace(/&/, '?');
  380. return url;
  381. }
  382. // tipbox弹层
  383. function tipbox(str, ms, jump) {
  384. clearTimeout(tiptime);
  385. $('.tip_box span').html(str);
  386. $('.tip_box').show();
  387. if (ms) {
  388. tiptime = setTimeout(function() {
  389. $('.tip_box').hide();
  390. $('.tip_box span').html('');
  391. if (jump) {
  392. // wifilogdp([602,'tip_top_up']);
  393. // window.location.href="/top_up.html";
  394. }
  395. }, ms);
  396. }
  397. }
  398. // 插入 toast
  399. var toast = function(params) {
  400. var toastId = document.getElementById("toast");
  401. if (toastId) {
  402. toastId.parentNode.removeChild(toastId); // 删除原有的toast
  403. }
  404. var el = document.createElement("div");
  405. el.setAttribute("id", "toast");
  406. el.innerHTML = params.message;
  407. document.body.appendChild(el);
  408. el.classList.add("fadeIn");
  409. setTimeout(function() {
  410. el.classList.remove("fadeIn");
  411. el.classList.add("fadeOut");
  412. el.addEventListener("animationend", function() {
  413. el.classList.add("hide");
  414. });
  415. }, params.time);
  416. };
  417. // 渲染奖品展示图和名称
  418. function renderData(data) {
  419. var ndataArr = data.award_list; //随机打乱数组
  420. console.log(ndataArr);
  421. var $cards = $(".box li"); //所有卡牌
  422. for (var i = 0; i < ndataArr.length; i++) {
  423. var _img = '<img src="' + ndataArr[i].image + '" />';
  424. var _prizeName = '<p>' + ndataArr[i].show_name + '</p>';
  425. $cards.eq(i).html(_img + _prizeName);
  426. }
  427. }
  428. // 初始化动画
  429. function init() {
  430. bool = false;
  431. var initTime = 2; // CSS动画时间 0.5秒+0.5秒
  432. if (isFirst) { // 第一次翻转图片
  433. isFirst = false;
  434. var timer_showCard = setInterval(function() {
  435. $cards.addClass('hide-card');
  436. removeImg(); // 0.5秒后删除图片
  437. clearInterval(timer_showCard);
  438. }, initTime * 1000);
  439. // 删除图片 1/2 .hide-card 的时间 = 0.5s
  440. function removeImg() {
  441. var timer_removeImg = setInterval(function() {
  442. $cards.addClass('hide-data');
  443. $cards.find('img').remove();
  444. $cards.find('p').remove();
  445. clearInterval(timer_removeImg);
  446. }, 500);
  447. }
  448. } else {
  449. initTime = 0;
  450. }
  451. // 卡牌右下角发牌
  452. var timer_moveCard = setInterval(function() {
  453. $cards.css({ //所有卡牌放到右下角
  454. left: 512 / rem + "rem",
  455. top: 268 / rem + "rem"
  456. });
  457. $cards.removeClass('hide-card');
  458. clearInterval(timer_moveCard);
  459. // 0.5秒后发牌
  460. var timer_cardInit = setInterval(function() {
  461. cardInit();
  462. clearInterval(timer_cardInit);
  463. }, 500);
  464. //
  465. }, (initTime + 1) * 1000);
  466. function cardInit() {
  467. //卡牌归位动画
  468. for (var i = 0; i < length; i++) {
  469. (function(i) {
  470. var seat = setTimeout(function() {
  471. $cards.eq(i).css({
  472. left: initArr[i][0] + "rem",
  473. top: initArr[i][1] + "rem"
  474. });
  475. clearTimeout(seat);
  476. }, 300 * i);
  477. })(i);
  478. }
  479. // 定时选中卡牌 0为顺序选择 1为随机选择
  480. // cardActive(1);
  481. bool = true; //卡牌归位,可以点击
  482. }
  483. //生成从minNum到maxNum的随机数
  484. function randomNum(minNum, maxNum) {
  485. switch (arguments.length) {
  486. case 1:
  487. return parseInt(Math.random() * minNum + 1, 10);
  488. break;
  489. case 2:
  490. return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
  491. break;
  492. default:
  493. return 0;
  494. break;
  495. }
  496. }
  497. //卡牌轮流选中动画 1为随机 0为顺序
  498. function cardActive(isRandomNum) {
  499. if (isRandomNum || 1) {
  500. setTimeout(function() {
  501. timer = setInterval(function() {
  502. bool = true; //卡牌归位,可以点击
  503. $cards.removeClass("active");
  504. $cards.eq(randomNum(0, index)).addClass("active");
  505. }, 1000);
  506. }, 1000);
  507. } else {
  508. setTimeout(function() {
  509. timer = setInterval(function() {
  510. bool = true; //卡牌归位,可以点击
  511. $cards.eq(index - 1).removeClass("active");
  512. index %= 6;
  513. $cards.eq(index).addClass("active");
  514. index++;
  515. }, 1000);
  516. }, 1000);
  517. }
  518. }
  519. }
  520. //点击卡牌
  521. $(".box").on("click", "li", function() {
  522. if (new Date() - clickTime > 2000 && bool) { //两次点击的间隔不能小于2秒
  523. clickTime = new Date(); //时间更新
  524. if (data > 0) {
  525. var speed = 200; //滑动的速度
  526. // $('body,html').animate({ scrollTop: 0 }, speed); // 点击的时候回到顶部
  527. //return false;
  528. fnLottery($(this));
  529. } else {
  530. alert("没有次数了~");
  531. }
  532. }
  533. // window.bookSotre.logClick('fanpai_index', 'dianjikapai', '', '', '');
  534. });
  535. // 模拟开奖结果------------------------
  536. function initFnLottery(_liThis) {
  537. // $('.dialog_prize_img').attr('src', data.data.img);
  538. // $('.wintxt').html(_wintxt);
  539. // $('.red-body h1').html(_h1txt);
  540. $maskCard.show();
  541. clearInterval(timer); //清除轮流选中动画
  542. $cards.removeClass("active"); //清除轮流滚动类名
  543. _liThis.addClass("open-card"); //添加翻牌动画
  544. //动画监听
  545. _liThis.on("animationend", () => {
  546. _liThis.removeClass("open-card"); //移除翻牌动画
  547. $cards.css({ //所有卡牌放到右下角
  548. left: 280 / rem + "rem",
  549. top: 168 / rem + "rem"
  550. });
  551. $maskCard.hide();
  552. win(_liThis);
  553. _liThis.off("animationend"); //解绑动画监听
  554. });
  555. }
  556. //中奖信息提示
  557. // $("#close,.win,.btn").click(function () {
  558. // clickTime = new Date();//时间更新
  559. // index = length;//卡牌选中重新从第一张开始
  560. // init();
  561. // });
  562. // 渲染Tab 中奖名单和我的奖品
  563. function renderLi(dataType) {
  564. console.log(list_data);
  565. var _dataType = dataType || '';
  566. var _html = '';
  567. // 中奖广播
  568. if (_dataType == 'tab1' || _dataType == '') {
  569. var _item = list_data.nameList;
  570. $('.tab_nav li').removeClass('cur');
  571. $('.tab_nav li').eq(0).addClass('cur');
  572. if (_item.length == 0) {
  573. $('.tab_list').html('');
  574. // $('.emtpy').show();
  575. // return; -------------------
  576. } else {
  577. $('.empty').hide();
  578. $('.name-list').show();
  579. for (var i = 0; i < _item.length; i++) {
  580. if (i == 10) {
  581. break;
  582. }
  583. _html += '<li>恭喜<span class="pl1">' + _item[i].id + '</span><span class="pl1">抽中《' + _item[i].name + '》奖品</span></li>';
  584. }
  585. }
  586. }
  587. // 中奖记录
  588. if (_dataType == 'tab2') {
  589. var _jtem = list_data.recordList;
  590. console.log(_jtem);
  591. $('.tab_nav li').removeClass('cur');
  592. $('.tab_nav li').eq(1).addClass('cur');
  593. if (_jtem.length == 0) {
  594. $('.tab_list').html('');
  595. $('.empty').show();
  596. $('.name-list').hide();
  597. $('.empty').html('你没有奖品赶快去抽奖吧!');
  598. return;
  599. } else {
  600. $('.empty').hide();
  601. $('.name-list').show();
  602. for (var j = 0; j < _jtem.length; j++) {
  603. var _linkTxt = '';
  604. if(_jtem[j].book_id > 0){
  605. _linkTxt = '<a class="link_btn go_bookId" href="/index/book/chapter?book_id='+_jtem[j].book_id+'" data-bookId="' + _jtem[j].book_id + '"><span class="txt">去看书</span></a>';
  606. _html += '<li class="recordList" style="padding-right:2.0rem;"><span class="left">《' + _jtem[j].show_name +'》</span>'+_linkTxt+'</li>';
  607. }else{
  608. _linkTxt = '<span class="right"><span class="txt">已到账</span></span>';
  609. _html += '<li class="recordList" style="padding-right:2.0rem;"><span class="left">' + _jtem[j].show_name +'</span>'+_linkTxt+'</li>';
  610. }
  611. }
  612. }
  613. }
  614. $('.name-list').html(_html);
  615. }
  616. // 点击Tab时渲染数据
  617. $('.tab_nav span').click(function() {
  618. var $this = $(this);
  619. var data_type = $this.attr('data-type');
  620. nowTab = data_type;
  621. renderLi(nowTab);
  622. if (data_type == 'tab2') {
  623. // window.bookSotre.logClick('fanpai_index', 'dianjijiangpin', '', '', '');
  624. }
  625. // fnGetPrizeList(1); // 点击时进行数据请求,参数:是否为Tab点击
  626. });
  627. var $maskRule = $("#mask-rule"), //规则遮罩层
  628. $mask = $("#mask"), //红包遮罩层
  629. $winning = $(".winning"), //红包
  630. $card = $("#card"),
  631. $close = $("#close");
  632. //link = false;//判断是否在链接跳转中
  633. // 获取中奖信息
  634. var flagDraw = false;
  635. function fnLottery(_liThis) {
  636. // if(flagDraw){
  637. // return;
  638. // }
  639. // flagDraw = true;
  640. cpslog([702, {map:{campaign_status:'cardFlip'}}, 'card_flip_lottery_click']);
  641. $.ajax({
  642. url: '/api/card/lottery',
  643. type: 'post',
  644. timeout: 6000,
  645. data: {
  646. actId: actId,
  647. },
  648. success: function(data) {
  649. // wifilogdp([602,'getdrawsuccess_'+data.code]);
  650. flagDraw = false;
  651. console.log(data);
  652. switch (data.code) {
  653. case 0:
  654. //活动未开始
  655. toast({
  656. message: "活动未开始,请耐心等待",
  657. time: 2000
  658. });
  659. break;
  660. case 1:
  661. //成功
  662. /*console.log(222);*/
  663. // 1 看点(代金券) 2 话费 3 实物 4 成长值 5 书籍 6 再来1次 7 谢谢参与 8 vip
  664. var _wintxt = '<p>' + data.data.awardName + '</p>';
  665. var _h1txt = '恭喜获奖';
  666. $('.dialog_prize').removeClass('thanksImg');
  667. switch (data.data.type) {
  668. case 1:
  669. _h1txt = '谢谢参与';
  670. _wintxt = '<p>好可惜,差点就中了<br>别灰心,幸运女神总会降临的</p>';
  671. $('.dialog_prize').addClass('thanksImg');
  672. break;
  673. case 2:
  674. _wintxt = '<p>获得一本免费书籍<br>《' + data.data.name + '》</p><p class="p2"></p>';
  675. break;
  676. case 3:
  677. _wintxt = '<p>恭喜您获得了' + data.data.name + '</p><p class="p2">请在VIP个人中心进行查看</p>';
  678. break;
  679. case 4:
  680. _wintxt = '<p>恭喜您获得了' + data.data.kandian + '书币</p><p class="p2">已放入您的账户余额</p>';
  681. // 写入一条数据
  682. list_data.recordList.unshift(data.data);
  683. list_data.nameList.unshift(data.data);
  684. break;
  685. case 5:
  686. _h1txt = '免费再来一次';
  687. _wintxt = '<p>赶快试试手气吧~</p>';
  688. // 写入一条数据
  689. list_data.recordList.unshift(data.data);
  690. list_data.nameList.unshift(data.data);
  691. break;
  692. default:
  693. _h1txt = '谢谢参与';
  694. _wintxt = '<p>好可惜,差点就中了<br>别灰心,幸运女神总会降临的</p>';
  695. $('.dialog_prize').addClass('thanksImg');
  696. break;
  697. }
  698. $('.dialog_prize_img').attr('src', data.data.image);
  699. $('.wintxt').html(_wintxt);
  700. $('.red-body h1').html(_h1txt);
  701. $maskCard.show();
  702. clearInterval(timer); //清除轮流选中动画
  703. $cards.removeClass("active"); //清除轮流滚动类名
  704. _liThis.addClass("open-card"); //添加翻牌动画
  705. //动画监听
  706. _liThis.on("animationend", function() {
  707. _liThis.removeClass("open-card"); //移除翻牌动画
  708. $cards.css({ //所有卡牌放到右下角
  709. left: 280 / rem + "rem",
  710. top: 168 / rem + "rem"
  711. });
  712. $maskCard.hide();
  713. win();
  714. _liThis.off("animationend"); //解绑动画监听
  715. });
  716. //
  717. // initFnLottery($(this));
  718. break;
  719. case 2:
  720. toast({
  721. message: "今天抽奖次数用完了,明天再来吧!",
  722. time: 2000
  723. });
  724. break;
  725. case 3:
  726. toast({
  727. message: "很抱歉,当前账户余额不足~",
  728. time: 2000
  729. });
  730. setTimeout(function () {
  731. window.location.href="/index/recharge/pay?from=wechat&type=2&active_id="+actId;
  732. },2000)
  733. break;
  734. default:
  735. toast({
  736. message: "手速太快了!",
  737. time: 2000
  738. });
  739. break;
  740. }
  741. },
  742. error: function() {
  743. toast({
  744. message: "很遗憾,抽奖失败了",
  745. time: 2000
  746. });
  747. },
  748. complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
  749.   
  750. if (status == 'timeout') { //超时,status还有success,error等值的情况
  751. toast({
  752. message: "很遗憾,抽奖失败了",
  753. time: 2000
  754. });    
  755. }  
  756. }
  757. })
  758. }
  759. // 中奖信息
  760. function win(target) {
  761. //遮罩层显示
  762. $mask.show();
  763. $winning.addClass("reback");
  764. // setTimeout(function() {
  765. // $card.addClass("pull");
  766. // }, 500);
  767. //中奖信息提示------------------------
  768. $(".mask-btn").click(() => {
  769. clickTime = new Date(); //时间更新
  770. index = length; //卡牌选中重新从第一张开始
  771. $mask.hide();
  772. // target.html(`<img src="./images/result-vip.png" alt="" srcset=""><p>7天VIP</p>`)
  773. init();
  774. window.location.reload();
  775. });
  776. /*$(".win,.btn").click(function () {
  777. link = true;
  778. });*/
  779. }
  780. // 关闭弹出层
  781. $("#close,.win,.btn").click(function() {
  782. clickTime = new Date(); //时间更新
  783. index = length; //卡牌选中重新从第一张开始
  784. init();
  785. $mask.hide();
  786. $winning.removeClass("reback");
  787. $card.removeClass("pull");
  788. // 渲染Tab 改变数据/中奖记录
  789. alert(222);
  790. renderLi(nowTab);
  791. });
  792. // 关闭dialog弹层
  793. $('.tip_box_dialog .dialog_tip_close').click(function() {
  794. $('.tip_box_dialog').hide();
  795. });
  796. // 去充值
  797. $('.tip_box_dialog .recharge').click(function() {
  798. $('.tip_box_dialog').hide();
  799. window.bookSotre.bookStoreClick('', '6', '', '');
  800. window.bookSotre.logClick('fanpai_index', 'dianjichongzhi', '', '', '');
  801. });
  802. // 跳转链接IOS-7,安卓-4
  803. // 打开rule
  804. $('.rule').click(function() {
  805. var _json = {
  806. 'url': window.location.protocol + '//' + window.location.host + '/huodong/fanpai/activity-rules.html'
  807. };
  808. if (isiOS) {
  809. window.bookSotre.bookStoreClick('', '7', _json.url, '');
  810. } else {
  811. window.bookSotre.bookStoreClick('', '4', '', JSON.stringify(_json));
  812. }
  813. });
  814. // 领取实物 需要区分客户端
  815. $('.tab_list').on('click', '.go_getAwardCenterList', function() {
  816. // /asg/portal/awardcenter/getAwardCenterList.do
  817. var SEARCH = $(this).attr('data-url');
  818. if (isiOS) {
  819. var _url = window.location.protocol + '//' + window.location.host + '/asg/portal/awardcenter/getAwardCenterList.do' + SEARCH
  820. window.bookSotre.bookStoreClick('', '7', _url, '');
  821. } else {
  822. var _json = '';
  823. if (opub && opub.p >= 32) {
  824. _json = {
  825. 'url': window.location.protocol + '//' + window.location.host + '/php/user/awardcenter' + SEARCH
  826. };
  827. } else {
  828. _json = {
  829. 'url': window.location.protocol + '//' + window.location.host + '/asg/portal/awardcenter/getAwardCenterList.do' + SEARCH
  830. };
  831. }
  832. window.bookSotre.bookStoreClick('', '4', '', JSON.stringify(_json));
  833. }
  834. });
  835. function go_book(){
  836. // // 领取实物 需要区分客户端
  837. // $('.go_bookId').onclick() {
  838. // alert(111);
  839. // var bookId = $(this).attr('data-bookId');
  840. // window.location.href="/index/book/chapter?sid="+bookId;
  841. // });
  842. $('.go_bookId').click(function () {
  843. alert(111);
  844. });
  845. }
  846. // go_vip 我的VIP页面
  847. $('.tab_list').on('click', '.go_vip', function() {
  848. var iosUrl = '/phpios/vip/viphome';
  849. var _json = {
  850. 'url': window.location.protocol + '//' + window.location.host + iosUrl
  851. };
  852. if (isiOS) {
  853. window.bookSotre.bookStoreClick('', '7', _json.url, '');
  854. } else {
  855. if (opub.p > 24) {
  856. window.bookSotre.bookStoreClick('', '32', '', '');
  857. } else {
  858. openVip();
  859. }
  860. }
  861. });
  862. });
  863. // window.bookSotre.logPv('fanpai_index', '', '');