awardActivity.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  6. <title>免费活动</title>
  7. <link rel="icon" href="../static/img/favicon2.ico" type="img/x-ico">
  8. <link rel="stylesheet" href="../static/js/vender/toastr/toastr.min.css">
  9. <link rel="stylesheet" href="../static/css/awardActivity.css">
  10. <script src="../static/js/vender/jquery-3.4.1.min.js"></script>
  11. <script src="../static/js/vender/toastr/toastr.min.js"></script>
  12. <script src="../static/js/vender/config.js"></script>
  13. </head>
  14. <body>
  15. <div class="container">
  16. <div class="all-bg-wrap">
  17. <img class="all-bg-img" src="../static/img/awardActivity/all-bg.png" />
  18. </div>
  19. <div class="rule-wrap">活动规则</div>
  20. <div class="time-position"></div>
  21. <div class="time-wrap"></div>
  22. <div class="top-container">
  23. <img class="top-bg-one" src="../static/img/awardActivity/top-bg-one.png" />
  24. <img class="top-bg-two" src="../static/img/awardActivity/top-bg-two.png" />
  25. <div class="get-award-container">
  26. <div class="award-lists"></div>
  27. </div>
  28. <div class="all-award-wrap"></div>
  29. </div>
  30. <div class="rest-wrap">
  31. <div class="award-btn-wrap">
  32. <img class="start-award" src="../static/img/awardActivity/bug-phone.png" />
  33. </div>
  34. <div class="get-time-wrap">
  35. <div class="rest-time">剩余抽奖次数 <span class="times"></span>次</div>
  36. <div class="get-time-btn">获取次数</div>
  37. </div>
  38. <div class="tab-wrap">
  39. <img class="tab-bg1" src="../static/img/awardActivity/tab-bg1.png" />
  40. <img class="tab-bg2" src="../static/img/awardActivity/tab-bg2.png" />
  41. <img class="tab-bg3" src="../static/img/awardActivity/tab-bg3.png" />
  42. <img class="tab-bg4" src="../static/img/awardActivity/tab-bg4.png" />
  43. <div class="award-container">
  44. <div class="award-title-wrap">
  45. <div class="award-title active-title">奖励一览</div>
  46. <div class="award-title">分配奖励(<span class="all-times"></span>)</div>
  47. </div>
  48. <div class="award-list">
  49. <div class="award-list-title-wrap">
  50. <div class="award-list-title">时间</div>
  51. <div class="award-list-title">奖品</div>
  52. </div>
  53. <div class="award-list-wrap"></div>
  54. </div>
  55. <div class="distribution-wrap">
  56. <div class="distribution-list-wrap">
  57. <div class="distribution-list">
  58. <div class="distribution-total-wrap">
  59. <div class="award-total-data">奖励总时长<span class="red"></span>天</div>
  60. <div class="award-total-data">已分配时长<span class="red"></span>天</div>
  61. <div class="award-total-data">未分配时长<span class="red"></span>天</div>
  62. </div>
  63. <div class="distribution-container"></div>
  64. <div class="distribution-award-btn">分配奖励</div>
  65. </div>
  66. <div class="award-record-list">
  67. <div class="record-list-title">分配时长记录</div>
  68. <div class="award-record-list-title-wrap">
  69. <div class="award-record-list-title">云机名称</div>
  70. <div class="award-record-list-title">时间</div>
  71. <div class="award-record-list-title">时长</div>
  72. </div>
  73. <div class="award-record-list-wrap"></div>
  74. </div>
  75. </div>
  76. </div>
  77. <div class="no-award-data">
  78. <img class="no-award-img" src="../static/img/awardActivity/no-award.png" />
  79. <div class="no-award-text">没有抽奖记录,我都替你着急~</div>
  80. </div>
  81. <div class="no-distribution-data">
  82. <img class="no-distribution-img" src="../static/img/awardActivity/no-data.png" />
  83. <div class="no-distribution-text">先购买云手机,才能分配喔~</div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="rule-mask">
  89. <div class="rule-result-dialog">
  90. <div class="rule-content">
  91. <div class="rule-title-wrap">
  92. <div class="rule-title-icon"></div>
  93. <div class="rule-title">活动规则</div>
  94. <div class="rule-title-icon"></div>
  95. </div>
  96. <div class="rule-point-wrap">
  97. <!-- <div class="rule-point">1、活动期间,购买获得的抽取资格不限次数, 活动期间可用,活动结束后未使用的做过期处理。</div>
  98. <div class="rule-point">2、参与活动的套餐是星曜月卡与年卡套餐,其他套餐不参与活动。</div>
  99. <div class="rule-point">3、星币、激活码购买的订单不参与本次活动。</div>
  100. <div class="rule-point">4、抽取的奖励只能新增云机,请去云手机首页查看。</div>
  101. <div class="rule-point">5、活动结束后3天保留奖励分配入口,但不能再参与活动。</div>
  102. <div class="rule-point">6、双子星官方对活动具有最终解释权。</div> -->
  103. </div>
  104. </div>
  105. <img class="rule-close" src="../static/img/anniversaryCelebrate/close.png" />
  106. </div>
  107. </div>
  108. <div class="result-mask">
  109. <div class="result-dialog">
  110. <div class="result-content">
  111. <div class="rule-title-wrap result-title-wrap">
  112. <div class="rule-title-icon"></div>
  113. <div class="rule-title">换个姿势,再抽一次</div>
  114. <div class="rule-title-icon"></div>
  115. </div>
  116. <div class="main-contain"></div>
  117. </div>
  118. <img class="card-close" src="../static/img/anniversaryCelebrate/close.png" />
  119. </div>
  120. </div>
  121. <div class="sure-distribution-wrap">
  122. <div class="sure-distribution-box">
  123. <div class="sure-distribution-title">确定分配奖励时长</div>
  124. <div class="sure-distribution-btn-list">
  125. <div class="sure-distribution-btn sure-distribution-cannel">取消</div>
  126. <div class="sure-distribution-btn sure-distribution-sure">确定</div>
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. <script type="text/html" id="card">
  132. <img class="card-img" src="{{icon}}" />
  133. <div class="card-title">{{goodsName}}</div>
  134. <div class="card-tips">{{tips}}</div>
  135. <div class="card-btn">{{cardBtn}}</div>
  136. <div class="card-rest-times">剩余次数{{lotteryCount}}次</div>
  137. </script>
  138. <script type="text/html" id="award1">
  139. <div class="curr-award-item curr-award-item-one">
  140. <div class="curr-award-img curr-award-img-one">
  141. <img class="award-img" src="{{icon}}" />
  142. </div>
  143. <div class="curr-award-name">{{goodsName}}</div>
  144. <div class="curr-award-id">{{id}}</div>
  145. </div>
  146. </script>
  147. <script type="text/html" id="award2">
  148. <div class="curr-award-item">
  149. <div class="curr-award-img">
  150. <!-- <img class="award-img" src="{{icon}}" /> -->
  151. </div>
  152. <div class="curr-award-name">{{goodsName}}</div>
  153. <div class="curr-award-id">{{id}}</div>
  154. </div>
  155. </script>
  156. <script type="text/html" id="awardRecord">
  157. <div class="award-list-item">
  158. <div class="award-list-content">{{createTime}}</div>
  159. <div class="award-list-content">{{goodsName}}</div>
  160. </div>
  161. </script>
  162. <script type="text/html" id="distribution">
  163. <div class="distribution-item">
  164. <div class="distribution-main-content">
  165. <img class="phone-logo" src="../static/img/awardActivity/home_list_icon_xingyao.jpg" />
  166. <div class="distribution-info">
  167. <div class="distribution-name">{{diskName}}</div>
  168. <div class="distribution-time">{{timeLeft}}</div>
  169. </div>
  170. </div>
  171. <div class="change-num-wrap">
  172. <div class="cut" data-id={{userCardId}} data-index={{index}}>-</div>
  173. <input class="num-ipt" value="0" />
  174. <div class="add" data-id={{userCardId}} data-index={{index}}>+</div>
  175. </div>
  176. </div>
  177. </script>
  178. <script type="text/html" id="record">
  179. <div class="award-record-list-item">
  180. <div class="award-record-list-content">{{diskName}}</div>
  181. <div class="award-record-list-content">{{exceptTime}}</div>
  182. <div class="award-record-list-content">{{validTime}}</div>
  183. </div>
  184. </script>
  185. <script>
  186. toastr.options.positionClass = 'toast-center-center';
  187. toastr.options.timeOut = '1500';
  188. </script>
  189. <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
  190. <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
  191. <script type="text/javascript">
  192. // var baseUrl = 'http://gntest.phone.androidscloud.com:1280'
  193. const fileCenterApi = 'https://file.phone.androidscloud.com:8121';
  194. let uploadKey = ''
  195. if (window.location.origin.includes('client.phone.androidscloud.com')) {
  196. uploadKey = 'edv834e74a9c43eaac02'
  197. } else if (window.location.origin.includes('prese.phone.androidscloud')) {
  198. uploadKey = '347905r86eb745a1sc38'
  199. } else {
  200. uploadKey = '13d0arghebcc4cm49cf04'
  201. }
  202. let timer,flag = true;
  203. var url = window.location.href;
  204. url = url.split('/')
  205. var loc = window.location.search,
  206. n1 = loc.length,//地址的总长度
  207. n2 = loc.indexOf("="),//取得=号的位置
  208. id = loc.substr(n2 + 1, n1 - n2),//从=号后面的内容
  209. u = navigator.userAgent,
  210. ua = navigator.userAgent.toLowerCase(),
  211. awardData = [],
  212. distributionList = [],
  213. topVal = -0.5,
  214. unAllotTime = 0,
  215. recordFlag = true,
  216. pageNum = 1,
  217. pages = 0,
  218. recordFlag1 = true,
  219. pageNum1 = 1,
  220. recordFlag2 = true,
  221. pageNum2 = 1,
  222. pages2 = 0,
  223. cardList = [],
  224. lotteryCount = 0,
  225. lotteryResult = {},
  226. lotteryFlag = true,
  227. activityState = 0,
  228. awardNumber = 0,
  229. currTotalTime = 0,
  230. phoneRemainQuantity = 0,
  231. flagNum = 1;
  232. isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
  233. isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
  234. (function(doc) {
  235. var init = function () {
  236. getPhoneNumber();
  237. bindEvent();
  238. goodsList();
  239. rewardList();
  240. allotTimeRecord();
  241. allotTimeCardList();
  242. }
  243. function bindEvent () {
  244. //点击开始抽奖
  245. $('.start-award')[0].addEventListener('click', startLottery, false);
  246. //点击继续抽奖
  247. $('.main-contain')[0].addEventListener('click', nextLottery, false);
  248. //点击抽奖结果关闭弹窗
  249. $('.card-close')[0].addEventListener('click', cardClose, false);
  250. //点击获取次数
  251. $('.get-time-btn')[0].addEventListener('click',getTimeHandle,false);
  252. //tab切换
  253. $('.award-title')[0].addEventListener('click', tabHandle1, false);
  254. $('.award-title')[1].addEventListener('click', tabHandle2, false);
  255. //点击分配时长按钮
  256. $('.distribution-award-btn')[0].addEventListener('click', distributionTime, false);
  257. //点击规则
  258. $('.rule-wrap')[0].addEventListener('click', ruleHandle, false);
  259. //关闭规则
  260. $('.rule-close')[0].addEventListener('click', ruleClose, false);
  261. }
  262. function tabHandle1 (e) {
  263. operate('mfhd_2022_h5_tab奖励一览');
  264. $('.tab-bg1').eq(0).css('display', 'block');
  265. $('.tab-bg2').eq(0).css('display', 'none');
  266. $('.tab-bg3').eq(0).css('display', 'none');
  267. $('.tab-bg4').eq(0).css('display', 'none');
  268. $('.tab-wrap').eq(0).css('height', '5.75rem');
  269. $('.award-title')[0].className = 'award-title active-title';
  270. $('.award-title')[1].className = 'award-title';
  271. $('.award-list').eq(0).css('display', 'block');
  272. $('.no-distribution-data').eq(0).css('display', 'none');
  273. $('.distribution-list-wrap').eq(0).css('display', 'none');
  274. if(pages === 0) {
  275. $('.no-award-data').eq(0).css('display', 'block');
  276. $('.award-list').eq(0).css('display', 'none');
  277. } else {
  278. $('.award-list').eq(0).css('display', 'block');
  279. $('.no-award-data').eq(0).css('display', 'none');
  280. }
  281. }
  282. function tabHandle2 (e) {
  283. if(activityState == 0){
  284. stopManyClick(() =>{
  285. toastr.error('活动未开始!');
  286. })
  287. return
  288. }
  289. if(activityState == 2){
  290. stopManyClick(() =>{
  291. toastr.error('活动已结束!');
  292. })
  293. return
  294. }
  295. operate('mfhd_2022_h5_tab分配奖励');
  296. $('.tab-bg1').eq(0).css('display', 'none');
  297. $('.tab-wrap').eq(0).css('height', '14.75rem');
  298. $('.award-title')[0].className = 'award-title';
  299. $('.award-title')[1].className = 'award-title active-title';
  300. $('.distribution-list-wrap').eq(0).css('display', 'block');
  301. $('.award-list').eq(0).css('display', 'none');
  302. $('.no-award-data').eq(0).css('display', 'none');
  303. if(cardList.length === 0) {
  304. $('.tab-bg2').eq(0).css('display', 'none');
  305. $('.tab-bg3').eq(0).css('display', 'none');
  306. $('.tab-bg4').eq(0).css('display', 'block');
  307. $('.tab-wrap').eq(0).css('height', '5.76rem');
  308. $('.distribution-list-wrap').eq(0).css('display', 'none');
  309. $('.no-distribution-data').eq(0).css('display', 'block');
  310. } else if(pages2 == 0) {
  311. $('.tab-bg4').eq(0).css('display', 'none');
  312. $('.tab-bg2').eq(0).css('display', 'none');
  313. $('.tab-bg3').eq(0).css('display', 'block');
  314. $('.tab-wrap').eq(0).css('height', '9.05rem');
  315. } else {
  316. $('.tab-bg4').eq(0).css('display', 'none');
  317. $('.tab-bg3').eq(0).css('display', 'none');
  318. $('.tab-bg2').eq(0).css('display', 'block');
  319. $('.award-record-list').eq(0).css('display', 'block');
  320. $('.tab-wrap').eq(0).css('height', '14.75rem');
  321. }
  322. }
  323. // 继续抽奖
  324. function nextLottery(e) {
  325. if(e.target.className === 'card-btn'){
  326. $('.main-contain').eq(0).empty();
  327. let num = flagNum > 12 ? flagNum - 12 : flagNum;
  328. $('.curr-award-item').eq(num).css('background', '#ffffff');
  329. cardClose();
  330. stopManyClick(() =>{
  331. startLottery('next');
  332. })
  333. }
  334. }
  335. function animation(num, time, result) {
  336. if(num >= 0) {
  337. $('.curr-award-item').eq(num).css('background', '#ffffff');
  338. }
  339. num++;
  340. $('.curr-award-item').eq(num).css('background', '#FAE892');
  341. if(time < 160) {
  342. time += 30;
  343. } else if(num === flagNum - 5) {
  344. time += 50;
  345. } else if(num === flagNum - 4) {
  346. time += 100;
  347. } else if(num === flagNum - 3) {
  348. time += 200;
  349. } else if(num === flagNum - 2) {
  350. time += 300;
  351. } else if(num === flagNum - 1) {
  352. time += 300;
  353. } else if(num === flagNum) {
  354. time += 100;
  355. } else {
  356. time += 30;
  357. }
  358. let flag = $('.curr-award-id').eq(num).text();
  359. if(flag == lotteryResult.id){
  360. flagNum = num < 6 ? num + awardNumber : num;
  361. }
  362. timer = setTimeout(() => {
  363. if(num === awardNumber) {
  364. num = -1;
  365. animation(num, time);
  366. } else if(flag == lotteryResult.id && time > 500) {
  367. lotteryResultHandle();
  368. clearTimeout(timer);
  369. } else {
  370. animation(num, time)
  371. }
  372. }, time)
  373. }
  374. // 开始抽奖
  375. function startLottery(type){
  376. if(activityState == 0){
  377. stopManyClick(() =>{
  378. toastr.error('活动未开始!');
  379. })
  380. return
  381. }
  382. if(activityState == 2){
  383. stopManyClick(() =>{
  384. toastr.error('活动已结束!');
  385. })
  386. return
  387. }
  388. if(lotteryCount === 0) {
  389. operate('mfhd_2022_h5_购买云机');
  390. getTimeHandle('buy');
  391. return
  392. } else if(type === 'next') {
  393. operate('mfhd_2022_h5_继续抽奖');
  394. } else {
  395. operate('mfhd_2022_h5_开始抽奖');
  396. }
  397. if(!lotteryFlag) {
  398. return
  399. }
  400. lotteryFlag = false;
  401. if(!GetRequest().token){
  402. return
  403. }
  404. $.ajax({
  405. url: baseUrl + '/api/activity/gratis/startLottery',
  406. type: 'get',
  407. headers: {
  408. 'Authorization': GetRequest().token //id
  409. },
  410. data: {
  411. clientType: GetRequest().clientType
  412. },
  413. contentType: "application/json",
  414. dataType: 'json',
  415. cache: false,
  416. success: function (res) {
  417. if(res.status === 0){
  418. let time = 20;
  419. let num = -1;
  420. lotteryResult = res.data;
  421. animation(num, time, 3);
  422. }else{
  423. stopManyClick(() =>{
  424. toastr.error(res.msg)
  425. })
  426. lotteryFlag = true
  427. }
  428. }
  429. })
  430. }
  431. //抽奖结果展示
  432. function lotteryResultHandle() {
  433. $('.result-dialog').animate({top: '3.86rem'},"fast");
  434. $('.result-mask').show();
  435. document.documentElement.style.overflow='hidden';
  436. lotteryFlag = true;
  437. let result = '';
  438. lotteryCount--;
  439. lotteryResult.lotteryCount = lotteryCount;
  440. lotteryResult.tips = lotteryResult.goodsType != 5 ?'奖励已发送您的账户内,请注意查收' : '中奖不是最终的追求,重要的是开心咯';
  441. lotteryResult.cardBtn = lotteryResult.lotteryCount != 0 ?'继续抽奖' : '获取次数';
  442. lotteryResult.icon = `https://file.phone.androidscloud.com:8121/document/newFile/download/0/${uploadKey}?fileKey=${lotteryResult.icon}`
  443. result = $('#card').text().replace(/{{(.*?)}}/g, function(node, key) {
  444. return lotteryResult[key];
  445. })
  446. goodsList();
  447. allotTimeCardList();
  448. $('.main-contain').eq(0).append(result)
  449. $('.times').eq(0).text(lotteryResult.lotteryCount)
  450. }
  451. // 抽奖记录
  452. function rewardList(type){
  453. if(!GetRequest().token){
  454. return
  455. }
  456. $.ajax({
  457. url: baseUrl + '/api/activity/gratis/rewardList',
  458. type: 'get',
  459. headers: {
  460. 'Authorization': GetRequest().token //id
  461. },
  462. data: {
  463. pageNum: pageNum,
  464. pageSize: 5
  465. },
  466. contentType: "application/json",
  467. dataType: 'json',
  468. cache: false,
  469. success: function (res) {
  470. if(res.status === 0){
  471. recordFlag = true;
  472. let list = res.data.list
  473. pages = res.data.pages;
  474. if(type != 'down'){
  475. $('.award-list-wrap').eq(0).empty();
  476. }
  477. if(pages === 0) {
  478. $('.no-award-data').eq(0).css('display', 'block');
  479. $('.award-list').eq(0).css('display', 'none');
  480. } else {
  481. $('.award-list').eq(0).css('display', 'block');
  482. $('.no-award-data').eq(0).css('display', 'none');
  483. }
  484. let result = ''
  485. list.map((item, index) => {
  486. result += $('#awardRecord').text().replace(/{{(.*?)}}/g, function(node, key) {
  487. return item[key];
  488. })
  489. })
  490. $('.award-list-wrap').eq(0).append(result)
  491. }else{
  492. stopManyClick(() =>{
  493. toastr.error(res.msg)
  494. })
  495. }
  496. }
  497. })
  498. }
  499. //抽奖记录下拉加载
  500. $('.award-list-wrap')[0].addEventListener('scroll',function () {
  501. let scrollTop = $('.award-list-wrap')[0].scrollTop;
  502. let clientHeight = $('.award-list-wrap')[0].clientHeight;
  503. let scrollHeight = $('.award-list-wrap')[0].scrollHeight;
  504. if(scrollTop + clientHeight + 100 > scrollHeight){
  505. if(recordFlag && pageNum < pages && pages > 1){
  506. recordFlag = false;
  507. pageNum++;
  508. rewardList('down');
  509. }
  510. }
  511. });
  512. // 活动基础数据
  513. function goodsList(){
  514. if(!GetRequest().token){
  515. return
  516. }
  517. $.ajax({
  518. url: baseUrl + '/api/activity/gratis/goodsList',
  519. type: 'get',
  520. headers: {
  521. 'Authorization': GetRequest().token //id
  522. },
  523. contentType: "application/json",
  524. dataType: 'json',
  525. cache: false,
  526. success: function (res) {
  527. if(res.status === 0){
  528. let startTime = res.data.startTime
  529. let endTime = res.data.endTime
  530. $('.time-wrap').eq(0).text(`活动时间:${startTime.substring(0,4)}年${startTime.substring(5,7)}月${startTime.substring(8,10)}日-${endTime.substring(5,7)}月${endTime.substring(8,10)}日`);
  531. awardData = res.data.marquee
  532. let goodsInfos = res.data.goodsInfos
  533. lotteryCount = res.data.lotteryCount
  534. activityState = res.data.activityState
  535. awardNumber = goodsInfos.length
  536. let actRule = res.data.actRule
  537. let result = ''
  538. let resultDom = goodsInfos.length === 9 ? $('#award1') : $('#award2');
  539. if(goodsInfos.length === 9) {
  540. $(".top-bg-one").css({"display": "block"})
  541. $(".top-bg-two").css({"display": "none"})
  542. } else {
  543. $(".top-bg-one").css({"display": "none"})
  544. $(".top-bg-two").css({"display": "block"})
  545. }
  546. goodsInfos.map((item, index) => {
  547. item.index = index
  548. item.icon = `https://file.phone.androidscloud.com:8121/document/newFile/download/0/${uploadKey}?fileKey=${item.icon}`
  549. result += resultDom.text().replace(/{{(.*?)}}/g, function(node, key) {
  550. return item[key];
  551. })
  552. })
  553. if(lotteryCount !== 0) {
  554. $('.start-award')[0].src = '../static/img/awardActivity/start-award.png';
  555. }
  556. headerAward();
  557. $('.rule-point-wrap').eq(0).html(actRule)
  558. $('.times').eq(0).text(lotteryCount)
  559. $('.all-award-wrap').eq(0).append(result)
  560. }else{
  561. stopManyClick(() =>{
  562. toastr.error(res.msg)
  563. })
  564. }
  565. }
  566. })
  567. }
  568. //轮播
  569. function headerAward(){
  570. if(awardData.length === 0) {
  571. return
  572. }
  573. setInterval(() =>{
  574. awardHandle();
  575. },3000);
  576. }
  577. function awardHandle(){
  578. let index = (topVal/0.5) + 1,awardString;
  579. let awardLen = Array.from($('.award-text')).length;
  580. if(awardLen < awardData.length){
  581. let node = document.createElement('div');
  582. node.className = "award-text";
  583. $('.award-lists')[0].appendChild(node);
  584. }
  585. if(topVal < awardData.length/2 - 0.5){
  586. topVal+=0.5;
  587. }else{
  588. topVal = 0;
  589. $('.award-lists').eq(0).css('top','0.5rem');
  590. }
  591. let numberType = Math.floor(getRandom()/4);
  592. if(awardData && awardData[index] && topVal < awardData.length/2){
  593. awardString = `恭喜${awardData[index].phone}用户获得${['优惠券','激活码','云机时长','星币','云机套餐','谢谢惠顾'][awardData[index].goodsType]}奖品`;
  594. }
  595. // else{
  596. // awardString = `恭喜1${[3,5,7,8,3,5,7,8,3,5][getRandom()]}${getRandom()}****${getRandom()}${getRandom()}${getRandom()}${getRandom()}用户获得${['优惠券','激活码','云机时长','星币','云机套餐','谢谢惠顾'][numberType]}`
  597. // }
  598. $('.award-text').eq(index).text(awardString);
  599. $('.award-lists').eq(0).animate({top: -(topVal) + 'rem'},"fast");
  600. }
  601. // 获取一个随机数
  602. function getRandom(){
  603. return Math.floor(Math.random()*10);
  604. }
  605. // 分配云手机列表
  606. function allotTimeCardList(type){
  607. if(!GetRequest().token){
  608. return
  609. }
  610. $.ajax({
  611. url: baseUrl + '/api/activity/gratis/allotTimeCardList',
  612. type: 'get',
  613. headers: {
  614. 'Authorization': GetRequest().token //id
  615. },
  616. contentType: "application/json",
  617. dataType: 'json',
  618. cache: false,
  619. success: function (res) {
  620. if(res.status === 0){
  621. cardList = res.data.cardList
  622. unAllotTime = res.data.unAllotTime
  623. pageCardList()
  624. $('.all-times').eq(0).text(res.data.totalTime)
  625. $('.red').eq(0).text(res.data.totalTime)
  626. $('.red').eq(1).text(res.data.allotTime)
  627. $('.red').eq(2).text(res.data.unAllotTime)
  628. }else{
  629. stopManyClick(() =>{
  630. toastr.error(res.msg)
  631. })
  632. }
  633. }
  634. })
  635. }
  636. // 分页渲染数据
  637. function pageCardList() {
  638. let result = '';
  639. recordFlag1 = true;
  640. let list = cardList.slice(pageNum1 * 5, (pageNum1 * 5) + 5)
  641. list.map((item, index) => {
  642. item.index = index
  643. result += $('#distribution').text().replace(/{{(.*?)}}/g, function(node, key) {
  644. return item[key];
  645. })
  646. })
  647. $('.distribution-container').eq(0).append(result)
  648. }
  649. //抽奖记录下拉加载
  650. $('.distribution-container')[0].addEventListener('scroll',function () {
  651. let scrollTop = $('.distribution-container')[0].scrollTop;
  652. let clientHeight = $('.distribution-container')[0].clientHeight;
  653. let scrollHeight = $('.distribution-container')[0].scrollHeight;
  654. if(scrollTop + clientHeight + 100 > scrollHeight){
  655. if(recordFlag1 && pageNum1 < cardList.length && cardList.length > 1){
  656. recordFlag1 = false;
  657. pageNum1++;
  658. pageCardList();
  659. }
  660. }
  661. });
  662. // 分配时长记录
  663. function allotTimeRecord(){
  664. if(!GetRequest().token){
  665. return
  666. }
  667. $.ajax({
  668. url: baseUrl + '/api/activity/gratis/allotTimeRecord',
  669. type: 'get',
  670. headers: {
  671. 'Authorization': GetRequest().token //id
  672. },
  673. data: {
  674. pageNum: pageNum2,
  675. pageSize: 5
  676. },
  677. contentType: "application/json",
  678. dataType: 'json',
  679. cache: false,
  680. success: function (res) {
  681. if(res.status === 0){
  682. let list = res.data.list
  683. let result = ''
  684. pages2 = res.data.pages
  685. recordFlag2 = true;
  686. list.map(item => {
  687. result += $('#record').text().replace(/{{(.*?)}}/g, function(node, key) {
  688. return item[key];
  689. })
  690. })
  691. $('.award-record-list-wrap').eq(0).append(result)
  692. }else{
  693. stopManyClick(() =>{
  694. toastr.error(res.msg)
  695. })
  696. }
  697. }
  698. })
  699. }
  700. //分配时长记录下拉加载
  701. $('.award-record-list-wrap')[0].addEventListener('scroll',function () {
  702. let scrollTop = $('.award-record-list-wrap')[0].scrollTop;
  703. let clientHeight = $('.award-record-list-wrap')[0].clientHeight;
  704. let scrollHeight = $('.award-record-list-wrap')[0].scrollHeight;
  705. if(scrollTop + clientHeight + 100 > scrollHeight){
  706. if(recordFlag2 && pageNum2 < pages2 && pages2 > 1){
  707. recordFlag2 = false;
  708. pageNum2++;
  709. allotTimeRecord('down');
  710. }
  711. }
  712. });
  713. function getTimeHandle(type) {
  714. if(activityState == 0){
  715. stopManyClick(() =>{
  716. toastr.error('活动未开始!');
  717. })
  718. return
  719. }
  720. if(activityState == 2){
  721. stopManyClick(() =>{
  722. toastr.error('活动已结束!');
  723. })
  724. return
  725. }
  726. if(type != 'bug') {
  727. operate('mfhd_2022_h5_获取次数按钮');
  728. }
  729. stopManyClick(() =>{
  730. if (window.__wxjs_environment === 'miniprogram') { // 小程序
  731. if(phoneRemainQuantity > 0){
  732. wx.miniProgram.navigateTo({
  733. url: '/packageA/order/buy/index?type=activity'
  734. })
  735. } else {
  736. wx.miniProgram.navigateTo({
  737. url: '/packageA/order/renew/index?record=' + userCardId
  738. })
  739. }
  740. } else if (isAndroid && window.native) { // 安卓
  741. if(phoneRemainQuantity > 0){
  742. window.native.startPurchase('SVIP', 365);
  743. } else {
  744. window.native.startRenew();
  745. }
  746. } else if (isiOS) {
  747. try {
  748. if(phoneRemainQuantity > 0){
  749. window.webkit.messageHandlers.startPurchase.postMessage({ type: 1, day: 365 });
  750. } else {
  751. window.webkit.messageHandlers.startRenew.postMessage({ type: 1, day: 365 });
  752. }
  753. } catch(error) {
  754. if(phoneRemainQuantity > 0){
  755. uni.webView.navigateTo({
  756. url: '/pages/order/order'
  757. })
  758. } else {
  759. uni.webView.navigateTo({
  760. url: '/pages/order/renew?record=' + userCardId
  761. })
  762. }
  763. }
  764. }
  765. })
  766. }
  767. //点击加减号
  768. $('.distribution-container')[0].addEventListener('click',(e) => {
  769. if(e.target.className === 'add'){
  770. operate('mfhd_2022_h5_加号');
  771. const id = e.target.dataset.id;
  772. let index = e.target.dataset.index;
  773. let number = $('.num-ipt').eq(index).val();
  774. currTotalTime = 0;
  775. // 这一次操作
  776. if(number == 0){
  777. if(!distributionList.find((item) => item.userCardId == id)){
  778. distributionList.push({
  779. userCardId: id,
  780. allotTime: +number + 1
  781. });
  782. }else{
  783. distributionList.map(item => {
  784. if(item.userCardId == id){
  785. item.allotTime++;
  786. }
  787. })
  788. }
  789. }else{
  790. distributionList.map(item => {
  791. if(item.userCardId == id){
  792. item.allotTime++;
  793. }
  794. })
  795. }
  796. distributionList.map(item => { // 这一次的总数据
  797. currTotalTime += parseInt(item.allotTime);
  798. })
  799. if(currTotalTime <= unAllotTime){
  800. number++;
  801. $('.num-ipt').eq(index).val(number);
  802. }else{
  803. distributionList.map(item => {
  804. if(item.userCardId == id){
  805. item.allotTime = +number;
  806. }
  807. })
  808. stopManyClick(() => {
  809. toastr.error('分配时长不能大于未分配总时长');
  810. })
  811. }
  812. console.log(distributionList)
  813. }
  814. if(e.target.className === 'cut'){
  815. operate('mfhd_2022_h5_减号');
  816. const id = e.target.dataset.id;
  817. let index = e.target.dataset.index;
  818. let number = $('.num-ipt').eq(index).val();
  819. if(number > 0){
  820. distributionList.map(item => {
  821. if(item.userCardId == id){
  822. item.allotTime--;
  823. }
  824. })
  825. number--;
  826. if(number == 0){
  827. distributionList = distributionList.filter(item => item.userCardId != id);
  828. }
  829. currTotalTime--;
  830. $('.num-ipt').eq(index).val(number);
  831. }else{
  832. stopManyClick(() => {
  833. toastr.error('分配的时长不能小于0');
  834. })
  835. }
  836. console.log(distributionList)
  837. }
  838. });
  839. function distributionTime(e) {
  840. operate('mfhd_2022_h5_分配奖励');
  841. distributionList = distributionList.filter(item => item.duration != 0);
  842. if (distributionList.length === 0) {
  843. stopManyClick(() => {
  844. toastr.error('未选中任何云手机');
  845. })
  846. } else {
  847. $('.sure-distribution-wrap').eq(0).css('display', 'block');
  848. }
  849. }
  850. //点击分配时长取消按钮
  851. $('.sure-distribution-cannel')[0].addEventListener('click', (e) => {
  852. operate('mfhd_2022_h5_分配奖励_取消');
  853. $('.sure-distribution-wrap').eq(0).css('display', 'none');
  854. });
  855. //点击分配时长确定按钮
  856. $('.sure-distribution-sure')[0].addEventListener('click', (e) => {
  857. stopManyClick(() => {
  858. $.ajax({
  859. url: baseUrl + '/api/activity/gratis/allotTime',
  860. type: 'post',
  861. data: JSON.stringify(distributionList),
  862. headers: {
  863. 'Authorization': GetRequest().token //id
  864. },
  865. contentType: "application/json",
  866. dataType: 'json',
  867. cache: false,
  868. success: function (res) {
  869. if(res.status === 0){
  870. operate('mfhd_2022_h5_分配奖励_确定');
  871. $('.sure-distribution-wrap').eq(0).css('display', 'none');
  872. $('.slider-list').eq(0).text('');
  873. $('.page-number').eq(0).text('');
  874. init();
  875. pageNum2 = 1;
  876. pages2 = 0;
  877. allotTimeRecord();
  878. distributionPageNum = 1;
  879. $('.time-row-data').eq(0).text('');
  880. distributionList.map((val) => {
  881. cardList.map((item, indexs) => {
  882. if(val.userCardId == item.userCardId){
  883. $('.num-ipt').eq(indexs).val(0);
  884. }
  885. })
  886. })
  887. distributionList = [];
  888. cardList = [];
  889. stopManyClick(() => {
  890. toastr.error('分配成功,请前往云机列表查看');
  891. })
  892. } else {
  893. console.log(res.msg)
  894. $('.sure-distribution-wrap').eq(0).css('display', 'none');
  895. stopManyClick(() => {
  896. toastr.error(res.msg);
  897. })
  898. }
  899. },
  900. })
  901. })
  902. });
  903. function ruleHandle (e) {
  904. operate('mfhd_2022_h5_规则');
  905. $('.rule-result-dialog').animate({top: '3.86rem'},"fast");
  906. $('.rule-mask').show();
  907. document.documentElement.style.overflow='hidden';
  908. }
  909. function ruleClose (e) {
  910. operate('mfhd_2022_h5_关闭规则');
  911. $('.rule-result-dialog').animate({top: '-10.96rem'},"fast");
  912. $('.rule-mask').hide();
  913. document.documentElement.style.overflow='auto';
  914. }
  915. function cardClose (e) {
  916. operate('mfhd_2022_h5_关闭抽奖结果');
  917. $('.result-dialog').animate({top: '-10.96rem'},"fast");
  918. $('.result-mask').hide();
  919. document.documentElement.style.overflow='auto';
  920. }
  921. //获取云机数量
  922. function getPhoneNumber(){
  923. $.ajax({
  924. url: baseUrl + '/api/pay/v2/meal/info?phoneType=SVIP',
  925. type: 'get',
  926. headers: {
  927. 'Authorization': id //id
  928. },
  929. contentType: "application/json",
  930. dataType: 'json',
  931. cache: false,
  932. success: function (res) {
  933. if(res.status === 0){
  934. phoneRemainQuantity = res.data.list[0].phoneRemainQuantity;
  935. }else{
  936. stopManyClick(() =>{
  937. toastr.error(res.msg)
  938. })
  939. }
  940. },
  941. })
  942. }
  943. init();
  944. })(document);
  945. //埋点
  946. function operate(pointName){
  947. $.ajax({
  948. url: baseUrl + '/api/public/v1/systemBuriedPoint/stat',
  949. type: 'post',
  950. data:JSON.stringify({
  951. pointName: pointName
  952. }),
  953. contentType:"application/json",
  954. dataType: 'json',
  955. cache: false,
  956. success: function (res) {},
  957. })
  958. }
  959. //防止提示一秒内重复显示
  960. function stopManyClick(fn) {
  961. if (flag) {
  962. fn();
  963. }
  964. flag = false;
  965. if(timer){clearTimeout(timer);}
  966. timer = setTimeout(() => {flag = true}, 1500);
  967. }
  968. </script>
  969. </body>
  970. </html>