awardActivity.html 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  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" style="white-space: pre-line;">
  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 result-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 curr-award-img-one" 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. <img class="award-img" src="{{icon}}" />
  150. <div class="curr-award-name">{{goodsName}}</div>
  151. <div class="curr-award-id">{{id}}</div>
  152. </div>
  153. </script>
  154. <script type="text/html" id="awardRecord">
  155. <div class="award-list-item">
  156. <div class="award-list-content">{{createTime}}</div>
  157. <div class="award-list-content">{{goodsName}}</div>
  158. </div>
  159. </script>
  160. <script type="text/html" id="distribution">
  161. <div class="distribution-item">
  162. <div class="distribution-main-content">
  163. <img class="phone-logo" src="{{icon}}" />
  164. <div class="distribution-info">
  165. <div class="distribution-name">{{diskName}}</div>
  166. <div class="distribution-time">{{timeLeft}}</div>
  167. </div>
  168. </div>
  169. <div class="change-num-wrap">
  170. <div class="cut" data-id={{userCardId}} data-index={{index}}>-</div>
  171. <input class="num-ipt" type="number" onkeyup="this.value=this.value.replace(/-/g,'')" value="0" data-id={{userCardId}} data-index={{index}} />
  172. <div class="add" data-id={{userCardId}} data-index={{index}}>+</div>
  173. </div>
  174. </div>
  175. </script>
  176. <script type="text/html" id="record">
  177. <div class="award-record-list-item">
  178. <div class="award-record-list-content award-record-list-name">{{diskName}}</div>
  179. <div class="award-record-list-content award-record-list-time">{{createTime}}</div>
  180. <div class="award-record-list-content award-record-list-day">{{validTime}}</div>
  181. </div>
  182. </script>
  183. <script>
  184. toastr.options.positionClass = 'toast-center-center';
  185. toastr.options.timeOut = '1500';
  186. </script>
  187. <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
  188. <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
  189. <script type="text/javascript">
  190. // var baseUrl = 'http://gntest.phone.androidscloud.com:1280'
  191. const fileCenterApi = 'https://file.phone.androidscloud.com:8121';
  192. let uploadKey = ''
  193. if (window.location.origin.includes('client.phone.androidscloud.com')) {
  194. uploadKey = 'edv834e74a9c43eaac02'
  195. } else if (window.location.origin.includes('prese.phone.androidscloud')) {
  196. uploadKey = '347905r86eb745a1sc38'
  197. } else {
  198. uploadKey = '13d0arghebcc4cm49cf04'
  199. }
  200. let timer,flag = true;
  201. var url = window.location.href;
  202. url = url.split('/')
  203. var loc = window.location.search,
  204. n1 = loc.length,//地址的总长度
  205. n2 = loc.indexOf("="),//取得=号的位置
  206. id = loc.substr(n2 + 1, n1 - n2),//从=号后面的内容
  207. u = navigator.userAgent,
  208. ua = navigator.userAgent.toLowerCase(),
  209. awardData = [],
  210. distributionList = [],
  211. topVal = -0.5,
  212. unAllotTime = 0,
  213. recordFlag = true,
  214. pageNum = 1,
  215. pages = 0,
  216. recordFlag1 = true,
  217. pageNum1 = 0,
  218. recordFlag2 = true,
  219. pageNum2 = 1,
  220. pages2 = 0,
  221. cardList = [],
  222. lotteryCount = 0,
  223. lotteryResult = {},
  224. lotteryFlag = true,
  225. activityState = 0,
  226. awardNumber = 0,
  227. currTotalTime = 0,
  228. phoneRemainQuantity = 0,
  229. userCardId = 0,
  230. awardTimer = null,
  231. tab = 1,
  232. buyVipType = 'SVIP',
  233. flagNum = 1;
  234. isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
  235. isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
  236. (function(doc) {
  237. var init = function () {
  238. getPhoneNumber();
  239. bindEvent();
  240. goodsList();
  241. rewardList();
  242. allotTimeRecord();
  243. allotTimeCardList();
  244. }
  245. function bindEvent () {
  246. //点击开始抽奖
  247. $('.start-award')[0].addEventListener('click', startLottery, false);
  248. //点击继续抽奖
  249. $('.main-contain')[0].addEventListener('click', nextLottery, false);
  250. //点击抽奖结果关闭弹窗
  251. $('.card-close')[0].addEventListener('click', cardClose, false);
  252. //点击获取次数
  253. $('.get-time-btn')[0].addEventListener('click',getTimeHandle,false);
  254. //tab切换
  255. $('.award-title')[0].addEventListener('click', tabHandle1, false);
  256. $('.award-title')[1].addEventListener('click', tabHandle2, false);
  257. //点击分配时长按钮
  258. $('.distribution-award-btn')[0].addEventListener('click', distributionTime, false);
  259. //点击规则
  260. $('.rule-wrap')[0].addEventListener('click', ruleHandle, false);
  261. //关闭规则
  262. $('.rule-close')[0].addEventListener('click', ruleClose, false);
  263. }
  264. function tabHandle1 (e) {
  265. tab = 1;
  266. operate('mfhd_2022_h5_tab奖励一览');
  267. $('.tab-bg1').eq(0).css('display', 'block');
  268. $('.tab-bg2').eq(0).css('display', 'none');
  269. $('.tab-bg3').eq(0).css('display', 'none');
  270. $('.tab-bg4').eq(0).css('display', 'none');
  271. $('.tab-wrap').eq(0).css('height', '5.75rem');
  272. $('.award-title')[0].className = 'award-title active-title';
  273. $('.award-title')[1].className = 'award-title';
  274. $('.award-list').eq(0).css('display', 'block');
  275. $('.no-distribution-data').eq(0).css('display', 'none');
  276. $('.distribution-list-wrap').eq(0).css('display', 'none');
  277. if(pages === 0) {
  278. $('.no-award-data').eq(0).css('display', 'block');
  279. $('.award-list').eq(0).css('display', 'none');
  280. } else {
  281. $('.award-list').eq(0).css('display', 'block');
  282. $('.no-award-data').eq(0).css('display', 'none');
  283. }
  284. }
  285. function tabHandle2 (e) {
  286. tab = 2;
  287. if(activityState == 0){
  288. stopManyClick(() =>{
  289. toastr.error('活动未开始!');
  290. })
  291. return
  292. }
  293. operate('mfhd_2022_h5_tab分配奖励');
  294. $('.tab-bg1').eq(0).css('display', 'none');
  295. $('.award-title')[0].className = 'award-title';
  296. $('.award-title')[1].className = 'award-title active-title';
  297. $('.distribution-list-wrap').eq(0).css('display', 'block');
  298. $('.award-list').eq(0).css('display', 'none');
  299. $('.no-award-data').eq(0).css('display', 'none');
  300. if(cardList.length === 0) {
  301. $('.tab-bg2').eq(0).css('display', 'none');
  302. $('.tab-bg3').eq(0).css('display', 'none');
  303. $('.tab-bg4').eq(0).css('display', 'block');
  304. $('.tab-wrap').eq(0).css('height', '5.76rem');
  305. $('.distribution-list-wrap').eq(0).css('display', 'none');
  306. $('.no-distribution-data').eq(0).css('display', 'block');
  307. } else if(pages2 == 0) {
  308. $('.tab-bg4').eq(0).css('display', 'none');
  309. $('.tab-bg2').eq(0).css('display', 'none');
  310. $('.tab-bg3').eq(0).css('display', 'block');
  311. $('.tab-wrap').eq(0).css('height', '9.05rem');
  312. } else {
  313. $('.tab-bg4').eq(0).css('display', 'none');
  314. $('.tab-bg3').eq(0).css('display', 'none');
  315. $('.tab-bg2').eq(0).css('display', 'block');
  316. $('.award-record-list').eq(0).css('display', 'block');
  317. $('.tab-wrap').eq(0).css('height', '14.75rem');
  318. }
  319. }
  320. // 继续抽奖
  321. function nextLottery(e) {
  322. if(e.target.className === 'card-btn'){
  323. cardClose();
  324. stopManyClick(() =>{
  325. startLottery('next');
  326. })
  327. }
  328. }
  329. function animation(num, time, result) {
  330. if(num >= 0) {
  331. $('.curr-award-item').eq(num).css('background', '#ffffff');
  332. }
  333. num++;
  334. $('.curr-award-item').eq(num).css('background', '#FAE892');
  335. if(time < 160) {
  336. time += 30;
  337. } else if(num === flagNum - 5) {
  338. time += 50;
  339. } else if(num === flagNum - 4) {
  340. time += 100;
  341. } else if(num === flagNum - 3) {
  342. time += 200;
  343. } else if(num === flagNum - 2) {
  344. time += 300;
  345. } else if(num === flagNum - 1) {
  346. time += 300;
  347. } else if(num === flagNum) {
  348. time += 100;
  349. } else {
  350. time += 30;
  351. }
  352. let flag = $('.curr-award-id').eq(num).text();
  353. if(flag == lotteryResult.id){
  354. flagNum = num < 6 ? num + awardNumber : num;
  355. }
  356. timer = setTimeout(() => {
  357. if(num === awardNumber) {
  358. num = -1;
  359. animation(num, time);
  360. } else if(flag == lotteryResult.id && time > 500) {
  361. lotteryResultHandle();
  362. clearTimeout(timer);
  363. } else {
  364. animation(num, time)
  365. }
  366. }, time)
  367. }
  368. // 开始抽奖
  369. function startLottery(type){
  370. if(activityState == 0){
  371. stopManyClick(() =>{
  372. toastr.error('活动未开始!');
  373. })
  374. return
  375. }
  376. if(activityState == 2){
  377. stopManyClick(() =>{
  378. toastr.error('活动已结束!');
  379. })
  380. return
  381. }
  382. if(lotteryCount <= 0) {
  383. operate('mfhd_2022_h5_购买云机');
  384. getTimeHandle('buy');
  385. return
  386. } else if(type === 'next') {
  387. operate('mfhd_2022_h5_继续抽奖');
  388. } else {
  389. operate('mfhd_2022_h5_开始抽奖');
  390. }
  391. if(!lotteryFlag) {
  392. return
  393. }
  394. lotteryFlag = false;
  395. if(!GetRequest().token){
  396. return
  397. }
  398. let num = flagNum > awardNumber ? flagNum - awardNumber : flagNum;
  399. $('.curr-award-item').eq(num).css('background', '#ffffff');
  400. $.ajax({
  401. url: baseUrl + '/api/activity/gratis/startLottery',
  402. type: 'get',
  403. headers: {
  404. 'Authorization': GetRequest().token //id
  405. },
  406. data: {
  407. clientType: GetRequest().clientType
  408. },
  409. contentType: "application/json",
  410. dataType: 'json',
  411. cache: false,
  412. success: function (res) {
  413. if(res.status === 0){
  414. let time = 20;
  415. let num = -1;
  416. lotteryResult = res.data;
  417. animation(num, time, 3);
  418. }else{
  419. stopManyClick(() =>{
  420. toastr.error(res.msg)
  421. })
  422. lotteryFlag = true
  423. }
  424. }
  425. })
  426. }
  427. //抽奖结果展示
  428. function lotteryResultHandle() {
  429. $('.main-contain').eq(0).empty();
  430. $('.result-dialog').animate({top: '2.86rem'},"fast");
  431. $('.result-mask').show();
  432. document.documentElement.style.overflow='hidden';
  433. lotteryFlag = true;
  434. let result = '';
  435. lotteryCount--;
  436. lotteryResult.lotteryCount = lotteryCount;
  437. lotteryResult.tips = lotteryResult.goodsType != 5 ?'奖励已发送您的账户内,请注意查收' : '中奖不是最终的追求,重要的是开心咯';
  438. lotteryResult.cardBtn = lotteryResult.lotteryCount != 0 ?'继续抽奖' : '获取次数';
  439. let text = lotteryResult.lotteryCount != 0 ?'换个姿势,再抽一次' : '次数用完,点击获取';
  440. $('.result-title').eq(0).text(text)
  441. if(lotteryCount === 0) {
  442. $('.start-award')[0].src = '../static/img/awardActivity/bug-phone.png';
  443. }
  444. lotteryResult.icon = `https://file.phone.androidscloud.com:8121/document/newFile/download/0/${uploadKey}?fileKey=${lotteryResult.icon}`
  445. result = $('#card').text().replace(/{{(.*?)}}/g, function(node, key) {
  446. return lotteryResult[key];
  447. })
  448. goodsList();
  449. pageNum = 1;
  450. rewardList();
  451. allotTimeCardList();
  452. if (isAndroid && window.native) { // 安卓
  453. window.native.refreshPhoneList();
  454. }
  455. $('.main-contain').eq(0).append(result)
  456. if(awardNumber === 9) {
  457. $('.card-img')[0].className = 'card-img card-img1';
  458. } else {
  459. $('.card-img')[0].className = 'card-img card-img2';
  460. }
  461. $('.times').eq(0).text(lotteryResult.lotteryCount)
  462. }
  463. // 抽奖记录
  464. function rewardList(type){
  465. if(!GetRequest().token){
  466. return
  467. }
  468. $.ajax({
  469. url: baseUrl + '/api/activity/gratis/rewardList',
  470. type: 'get',
  471. headers: {
  472. 'Authorization': GetRequest().token //id
  473. },
  474. data: {
  475. page: pageNum,
  476. pageSize: 5
  477. },
  478. contentType: "application/json",
  479. dataType: 'json',
  480. cache: false,
  481. success: function (res) {
  482. if(res.status === 0){
  483. recordFlag = true;
  484. let list = res.data.list
  485. pages = res.data.pages;
  486. if(type != 'down'){
  487. $('.award-list-wrap').eq(0).empty();
  488. }
  489. if(pages === 0) {
  490. $('.no-award-data').eq(0).css('display', 'block');
  491. $('.award-list').eq(0).css('display', 'none');
  492. } else {
  493. $('.award-list').eq(0).css('display', 'block');
  494. $('.no-award-data').eq(0).css('display', 'none');
  495. }
  496. let result = ''
  497. list.map((item, index) => {
  498. item.createTime = `${item.createTime.substring(5, 7)}月${item.createTime.substring(8, 10)}日${item.createTime.substring(11)}`
  499. result += $('#awardRecord').text().replace(/{{(.*?)}}/g, function(node, key) {
  500. return item[key];
  501. })
  502. })
  503. $('.award-list-wrap').eq(0).append(result)
  504. if(tab === 2) {
  505. $('.award-list').eq(0).css('display', 'none');
  506. $('.no-award-data').eq(0).css('display', 'none');
  507. }
  508. }else{
  509. stopManyClick(() =>{
  510. toastr.error(res.msg)
  511. })
  512. }
  513. }
  514. })
  515. }
  516. //抽奖记录下拉加载
  517. $('.award-list-wrap')[0].addEventListener('scroll',function () {
  518. let scrollTop = $('.award-list-wrap')[0].scrollTop;
  519. let clientHeight = $('.award-list-wrap')[0].clientHeight;
  520. let scrollHeight = $('.award-list-wrap')[0].scrollHeight;
  521. if(scrollTop + clientHeight + 100 > scrollHeight){
  522. if(recordFlag && pageNum < pages && pages > 1){
  523. recordFlag = false;
  524. pageNum++;
  525. rewardList('down');
  526. }
  527. }
  528. });
  529. // 活动基础数据
  530. function goodsList(){
  531. if(!GetRequest().token){
  532. return
  533. }
  534. $.ajax({
  535. url: baseUrl + '/api/activity/gratis/goodsList',
  536. type: 'get',
  537. headers: {
  538. 'Authorization': GetRequest().token //id
  539. },
  540. contentType: "application/json",
  541. dataType: 'json',
  542. cache: false,
  543. success: function (res) {
  544. if(res.status === 0){
  545. let startTime = res.data.startTime
  546. let endTime = res.data.endTime
  547. $('.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)}日`);
  548. awardData = res.data.marquee
  549. let goodsInfos = res.data.goodsInfos
  550. lotteryCount = res.data.lotteryCount
  551. activityState = res.data.activityState
  552. awardNumber = goodsInfos.length
  553. let actRule = res.data.actRule
  554. let result = ''
  555. let resultDom = goodsInfos.length === 9 ? $('#award1') : $('#award2');
  556. if(goodsInfos.length === 9) {
  557. $(".top-bg-one").css({"display": "block"})
  558. $(".all-award-wrap").css({"marginLeft": "0.1rem"})
  559. $(".top-bg-two").css({"display": "none"})
  560. } else {
  561. $(".top-bg-one").css({"display": "none"})
  562. $(".all-award-wrap").css({"marginLeft": "0.14rem"})
  563. $(".top-bg-two").css({"display": "block"})
  564. }
  565. goodsInfos.map((item, index) => {
  566. item.index = index
  567. item.icon = `https://file.phone.androidscloud.com:8121/document/newFile/download/0/${uploadKey}?fileKey=${item.icon}`
  568. result += resultDom.text().replace(/{{(.*?)}}/g, function(node, key) {
  569. return item[key];
  570. })
  571. })
  572. if(lotteryCount > 0) {
  573. $('.start-award')[0].src = '../static/img/awardActivity/start-award.png';
  574. }
  575. clearInterval(awardTimer);
  576. headerAward();
  577. $('.rule-point-wrap').eq(0).html(actRule)
  578. $('.times').eq(0).text(lotteryCount)
  579. let content = $('.all-award-wrap').eq(0).text();
  580. if(!content){
  581. $('.all-award-wrap').eq(0).append(result)
  582. }
  583. }else{
  584. stopManyClick(() =>{
  585. toastr.error(res.msg)
  586. })
  587. }
  588. }
  589. })
  590. }
  591. //轮播
  592. function headerAward(){
  593. if(awardData.length === 0) {
  594. return
  595. }
  596. awardTimer = setInterval(() =>{
  597. awardHandle();
  598. },3000);
  599. }
  600. function awardHandle(){
  601. let index = (topVal/0.5) + 1,awardString;
  602. let awardLen = Array.from($('.award-text')).length;
  603. if(awardLen < awardData.length){
  604. let node = document.createElement('div');
  605. node.className = "award-text";
  606. $('.award-lists')[0].appendChild(node);
  607. }
  608. if(topVal < awardData.length/2 - 0.5){
  609. topVal+=0.5;
  610. }else{
  611. topVal = 0;
  612. $('.award-lists').eq(0).css('top','0.5rem');
  613. }
  614. let numberType = Math.floor(getRandom()/4);
  615. if(awardData && awardData[index] && topVal < awardData.length/2){
  616. awardString = `恭喜${awardData[index].phone}用户获得${awardData[index].goodsName}奖品`;
  617. }
  618. // else{
  619. // awardString = `恭喜1${[3,5,7,8,3,5,7,8,3,5][getRandom()]}${getRandom()}****${getRandom()}${getRandom()}${getRandom()}${getRandom()}用户获得${['优惠券','激活码','云机时长','星币','云机套餐','谢谢惠顾'][numberType]}`
  620. // }
  621. $('.award-text').eq(index).text(awardString);
  622. $('.award-lists').eq(0).animate({top: -(topVal) + 'rem'},"fast");
  623. }
  624. // 获取一个随机数
  625. function getRandom(){
  626. return Math.floor(Math.random()*10);
  627. }
  628. // 分配云手机列表
  629. function allotTimeCardList(type){
  630. pageNum1 = 0;
  631. recordFlag1 = false;
  632. $('.distribution-container').eq(0).empty();
  633. if(!GetRequest().token){
  634. return
  635. }
  636. $.ajax({
  637. url: baseUrl + '/api/activity/gratis/allotTimeCardList',
  638. type: 'get',
  639. headers: {
  640. 'Authorization': GetRequest().token //id
  641. },
  642. contentType: "application/json",
  643. dataType: 'json',
  644. cache: false,
  645. success: function (res) {
  646. if(res.status === 0){
  647. cardList = res.data.cardList
  648. unAllotTime = res.data.unAllotTime
  649. if(cardList && cardList.length > 0) {
  650. cardList.map(item => {
  651. if(item.buyVipType === 'SVIP') {
  652. userCardId = item.userCardId
  653. }
  654. })
  655. if(userCardId === 0) {
  656. buyVipType = cardList[0] && cardList[0].buyVipType || 'SVIP'
  657. userCardId = cardList[0] && cardList[0].userCardId || 0
  658. }
  659. }
  660. pageCardList()
  661. $('.all-times').eq(0).text(unAllotTime)
  662. $('.red').eq(0).text(res.data.totalTime)
  663. $('.red').eq(1).text(res.data.allotTime)
  664. $('.red').eq(2).text(unAllotTime)
  665. }else{
  666. stopManyClick(() =>{
  667. toastr.error(res.msg)
  668. })
  669. }
  670. }
  671. })
  672. }
  673. // 分页渲染数据
  674. function pageCardList() {
  675. let result = '';
  676. recordFlag1 = true;
  677. let list = cardList.slice(pageNum1 * 5, (pageNum1 * 5) + 5);
  678. let mealTypeObj = {
  679. VIP: 'card1.png',
  680. SVIP: 'card2.jpg',
  681. STAR: 'card3.png',
  682. STARPRO: 'card4.png'
  683. }
  684. list.map((item, index) => {
  685. item.index = pageNum1 * 5 + index
  686. item.icon = `../static/img/awardActivity/${mealTypeObj[item.buyVipType]}`
  687. result += $('#distribution').text().replace(/{{(.*?)}}/g, function(node, key) {
  688. return item[key];
  689. })
  690. })
  691. $('.distribution-container').eq(0).append(result);
  692. for (var i = 0; i < list.length; i++) {
  693. $('.num-ipt')[pageNum1 * 5 + i].oninput = function (e) {
  694. const id = e.target.dataset.id;
  695. let oldDuration = 0;
  696. let preTotalTime = 0;
  697. let index = e.target.dataset.index;
  698. let value = $('.num-ipt').eq(index).val();
  699. if(value.length >= 5){
  700. value = value.substr(0, 5);
  701. }
  702. var position = String(value).indexOf(".");//获取小数点的位置
  703. if(position != -1){
  704. value = value.substr(0, position);
  705. }
  706. distributionList.map(item => { // 上一次的总数据
  707. preTotalTime += parseInt(item.allotTime);
  708. })
  709. //这一次操作
  710. if(value == 0){
  711. if(!distributionList.find((item) => item.userCardId == id)){
  712. distributionList.push({
  713. userCardId: id,
  714. allotTime: +value
  715. });
  716. }else{
  717. distributionList = distributionList.filter(item => item.userCardId != id);
  718. }
  719. distributionList = distributionList.filter(item => item.allotTime != 0);
  720. }else{
  721. if(!distributionList.find((item) => item.userCardId == id)){
  722. distributionList.push({
  723. userCardId: id,
  724. allotTime: Math.abs(value)
  725. });
  726. }else{
  727. distributionList.map(item => {
  728. if (item.userCardId == id) {
  729. oldDuration = item.allotTime;
  730. item.allotTime = +value;
  731. }
  732. })
  733. }
  734. }
  735. currTotalTime = 0;
  736. distributionList.map(item => { // 这一次的总数据
  737. currTotalTime += parseInt(item.allotTime);
  738. })
  739. if(currTotalTime > unAllotTime){ // 当前已分配大于总分配时长
  740. let val = unAllotTime - preTotalTime + oldDuration;
  741. distributionList.map(item => {
  742. if (item.userCardId == id) {
  743. item.allotTime = val;
  744. }
  745. })
  746. $('.num-ipt').eq(index).val(val);
  747. if(!lotteryFlag) {
  748. return
  749. } else {
  750. stopManyClick(() => {
  751. toastr.error('分配时长不能大于未分配总时长');
  752. })
  753. return
  754. }
  755. }
  756. if(value.length > 5) value = value.slice(0, 5);
  757. $('.num-ipt').eq(index).val(value);
  758. }
  759. }
  760. }
  761. //抽奖记录下拉加载
  762. $('.distribution-container')[0].addEventListener('scroll',function () {
  763. let scrollTop = $('.distribution-container')[0].scrollTop;
  764. let clientHeight = $('.distribution-container')[0].clientHeight;
  765. let scrollHeight = $('.distribution-container')[0].scrollHeight;
  766. if(scrollTop + clientHeight + 100 > scrollHeight){
  767. if(recordFlag1 && pageNum1 < (cardList.length/5) && (cardList.length/5) > 1){
  768. recordFlag1 = false;
  769. pageNum1++;
  770. pageCardList();
  771. }
  772. }
  773. });
  774. // 分配时长记录
  775. function allotTimeRecord(type){
  776. if(!GetRequest().token){
  777. return
  778. }
  779. $.ajax({
  780. url: baseUrl + '/api/activity/gratis/allotTimeRecord',
  781. type: 'get',
  782. headers: {
  783. 'Authorization': GetRequest().token //id
  784. },
  785. data: {
  786. page: pageNum2,
  787. pageSize: 5
  788. },
  789. contentType: "application/json",
  790. dataType: 'json',
  791. cache: false,
  792. success: function (res) {
  793. if(res.status === 0){
  794. let list = res.data.list
  795. let result = ''
  796. pages2 = res.data.pages
  797. recordFlag2 = true;
  798. if(type != 'down'){
  799. $('.award-record-list-wrap').eq(0).empty();
  800. }
  801. list.map(item => {
  802. item.createTime = `${item.createTime.substring(0, 4)}年${item.createTime.substring(5, 7)}月${item.createTime.substring(8, 10)}日${item.createTime.substring(11)}`
  803. result += $('#record').text().replace(/{{(.*?)}}/g, function(node, key) {
  804. return item[key];
  805. })
  806. })
  807. $('.award-record-list-wrap').eq(0).append(result)
  808. }else{
  809. stopManyClick(() =>{
  810. toastr.error(res.msg)
  811. })
  812. }
  813. }
  814. })
  815. }
  816. //分配时长记录下拉加载
  817. $('.award-record-list-wrap')[0].addEventListener('scroll',function () {
  818. let scrollTop = $('.award-record-list-wrap')[0].scrollTop;
  819. let clientHeight = $('.award-record-list-wrap')[0].clientHeight;
  820. let scrollHeight = $('.award-record-list-wrap')[0].scrollHeight;
  821. if(scrollTop + clientHeight + 100 > scrollHeight){
  822. if(recordFlag2 && pageNum2 < pages2 && pages2 > 1){
  823. recordFlag2 = false;
  824. pageNum2++;
  825. allotTimeRecord('down');
  826. }
  827. }
  828. });
  829. function getTimeHandle(type) {
  830. if(activityState == 0){
  831. stopManyClick(() =>{
  832. toastr.error('活动未开始!');
  833. })
  834. return
  835. }
  836. if(activityState == 2){
  837. stopManyClick(() =>{
  838. toastr.error('活动已结束!');
  839. })
  840. return
  841. }
  842. if(!lotteryFlag) {
  843. return
  844. }
  845. if(type != 'bug') {
  846. operate('mfhd_2022_h5_获取次数按钮');
  847. }
  848. stopManyClick(() =>{
  849. if (window.__wxjs_environment === 'miniprogram') { // 小程序
  850. if(phoneRemainQuantity > 0){
  851. wx.miniProgram.navigateTo({
  852. url: '/packageA/order/buy/index?type=activity'
  853. })
  854. } else {
  855. if(buyVipType != 'SVIP') {
  856. toastr.error('请前往APP进行续费喔!');
  857. return
  858. }
  859. wx.miniProgram.navigateTo({
  860. url: `/packageA/order/renew/index?record=${userCardId}`
  861. })
  862. }
  863. } else if (isAndroid && window.native) { // 安卓
  864. if(phoneRemainQuantity > 0){
  865. window.native.startPurchase('SVIP', 365);
  866. } else {
  867. window.native.startRenew(buyVipType);
  868. }
  869. } else if (isiOS) {
  870. try {
  871. if(phoneRemainQuantity > 0){
  872. window.webkit.messageHandlers.startPurchase.postMessage({ type: 1, day: 365 });
  873. } else {
  874. let typeObj = {
  875. VIP: 0,
  876. SVIP: 1,
  877. STAR: 2,
  878. STARPRO: 3
  879. }
  880. window.webkit.messageHandlers.startRenew.postMessage({type: typeObj[buyVipType], day: 365 });
  881. }
  882. } catch(error) {
  883. if(phoneRemainQuantity > 0){
  884. uni.webView.navigateTo({
  885. url: '/pages/order/order'
  886. })
  887. } else {
  888. uni.webView.navigateTo({
  889. url: `/pages/order/renew?userCardId=${userCardId}&buyVipType=${buyVipType}`
  890. })
  891. }
  892. }
  893. }
  894. })
  895. }
  896. //点击加减号
  897. $('.distribution-container')[0].addEventListener('click',(e) => {
  898. if(!lotteryFlag) {
  899. return
  900. }
  901. console.log(e.target.className)
  902. if(e.target.className === 'add'){
  903. operate('mfhd_2022_h5_加号');
  904. const id = e.target.dataset.id;
  905. let index = e.target.dataset.index;
  906. let number = $('.num-ipt').eq(index).val();
  907. currTotalTime = 0;
  908. // 这一次操作
  909. if(number == 0){
  910. if(!distributionList.find((item) => item.userCardId == id)){
  911. distributionList.push({
  912. userCardId: id,
  913. allotTime: +number + 1
  914. });
  915. }else{
  916. distributionList.map(item => {
  917. if(item.userCardId == id){
  918. item.allotTime++;
  919. }
  920. })
  921. }
  922. }else{
  923. distributionList.map(item => {
  924. if(item.userCardId == id){
  925. item.allotTime++;
  926. }
  927. })
  928. }
  929. distributionList.map(item => { // 这一次的总数据
  930. currTotalTime += parseInt(item.allotTime);
  931. })
  932. if(currTotalTime <= unAllotTime){
  933. number++;
  934. $('.num-ipt').eq(index).val(number);
  935. }else{
  936. distributionList.map(item => {
  937. if(item.userCardId == id){
  938. item.allotTime = +number;
  939. }
  940. })
  941. stopManyClick(() => {
  942. toastr.error('分配时长不能大于未分配总时长');
  943. })
  944. }
  945. }
  946. if(e.target.className === 'cut'){
  947. operate('mfhd_2022_h5_减号');
  948. const id = e.target.dataset.id;
  949. let index = e.target.dataset.index;
  950. let number = $('.num-ipt').eq(index).val();
  951. if(number > 0){
  952. distributionList.map(item => {
  953. if(item.userCardId == id){
  954. item.allotTime--;
  955. }
  956. })
  957. number--;
  958. if(number == 0){
  959. distributionList = distributionList.filter(item => item.userCardId != id);
  960. }
  961. currTotalTime--;
  962. $('.num-ipt').eq(index).val(number);
  963. }else{
  964. stopManyClick(() => {
  965. toastr.error('分配的时长不能小于0');
  966. })
  967. }
  968. }
  969. });
  970. async function distributionTime(e) {
  971. if(!lotteryFlag) {
  972. return
  973. }
  974. let res = await isShow();
  975. if(res == 0) {
  976. stopManyClick(() =>{
  977. toastr.error('活动已结束!');
  978. })
  979. return
  980. }
  981. operate('mfhd_2022_h5_分配奖励');
  982. distributionList = distributionList.filter(item => item.allotTime != 0);
  983. if (distributionList.length === 0) {
  984. stopManyClick(() => {
  985. toastr.error('未选中任何云手机');
  986. })
  987. } else {
  988. $('.sure-distribution-wrap').eq(0).css('display', 'block');
  989. }
  990. }
  991. // 活动结束是否超过三天
  992. function isShow(){
  993. return new Promise((resolve, reject) => {
  994. $.ajax({
  995. url: baseUrl + '/api/activity/gratis/isShow',
  996. type: 'get',
  997. headers: {
  998. 'Authorization': GetRequest().token //id
  999. },
  1000. contentType:"application/json",
  1001. dataType: 'json',
  1002. cache: false,
  1003. success: function (res) {
  1004. resolve(res.data)
  1005. },
  1006. })
  1007. })
  1008. }
  1009. //点击分配时长取消按钮
  1010. $('.sure-distribution-cannel')[0].addEventListener('click', (e) => {
  1011. operate('mfhd_2022_h5_分配奖励_取消');
  1012. $('.sure-distribution-wrap').eq(0).css('display', 'none');
  1013. });
  1014. //点击分配时长确定按钮
  1015. $('.sure-distribution-sure')[0].addEventListener('click', (e) => {
  1016. stopManyClick(() => {
  1017. $.ajax({
  1018. url: baseUrl + '/api/activity/gratis/allotTime',
  1019. type: 'post',
  1020. data: JSON.stringify(distributionList),
  1021. headers: {
  1022. 'Authorization': GetRequest().token //id
  1023. },
  1024. contentType: "application/json",
  1025. dataType: 'json',
  1026. cache: false,
  1027. success: function (res) {
  1028. if(res.status === 0){
  1029. operate('mfhd_2022_h5_分配奖励_确定');
  1030. $('.sure-distribution-wrap').eq(0).css('display', 'none');
  1031. $('.slider-list').eq(0).text('');
  1032. $('.page-number').eq(0).text('');
  1033. init();
  1034. pageNum2 = 1;
  1035. pages2 = 0;
  1036. allotTimeRecord();
  1037. distributionPageNum = 1;
  1038. $('.time-row-data').eq(0).text('');
  1039. distributionList.map((val) => {
  1040. cardList.map((item, indexs) => {
  1041. if(val.userCardId == item.userCardId){
  1042. $('.num-ipt').eq(indexs).val(0);
  1043. }
  1044. })
  1045. })
  1046. distributionList = [];
  1047. cardList = [];
  1048. $('.tab-bg4').eq(0).css('display', 'none');
  1049. $('.tab-bg3').eq(0).css('display', 'none');
  1050. $('.tab-bg2').eq(0).css('display', 'block');
  1051. $('.award-record-list').eq(0).css('display', 'block');
  1052. $('.tab-wrap').eq(0).css('height', '14.75rem');
  1053. toastr.error('分配成功,请前往云机列表查看');
  1054. } else {
  1055. console.log(res.msg)
  1056. $('.sure-distribution-wrap').eq(0).css('display', 'none');
  1057. toastr.error(res.msg);
  1058. }
  1059. },
  1060. })
  1061. })
  1062. });
  1063. function ruleHandle (e) {
  1064. operate('mfhd_2022_h5_规则');
  1065. $('.rule-result-dialog').animate({top: '2.86rem'},"fast");
  1066. $('.rule-mask').show();
  1067. document.documentElement.style.overflow='hidden';
  1068. }
  1069. function ruleClose (e) {
  1070. operate('mfhd_2022_h5_关闭规则');
  1071. $('.rule-result-dialog').animate({top: '-10.96rem'},"fast");
  1072. $('.rule-mask').hide();
  1073. document.documentElement.style.overflow='auto';
  1074. }
  1075. function cardClose (e) {
  1076. operate('mfhd_2022_h5_关闭抽奖结果');
  1077. $('.result-dialog').animate({top: '-10.96rem'},"fast");
  1078. $('.result-mask').hide();
  1079. document.documentElement.style.overflow='auto';
  1080. }
  1081. //获取云机数量
  1082. function getPhoneNumber(){
  1083. $.ajax({
  1084. url: baseUrl + '/api/pay/v2/meal/info?phoneType=SVIP',
  1085. type: 'get',
  1086. headers: {
  1087. 'Authorization': GetRequest().token //id
  1088. },
  1089. contentType: "application/json",
  1090. dataType: 'json',
  1091. cache: false,
  1092. success: function (res) {
  1093. if(res.status === 0){
  1094. phoneRemainQuantity = res.data.list[0].phoneRemainQuantity;
  1095. }else{
  1096. stopManyClick(() =>{
  1097. toastr.error(res.msg)
  1098. })
  1099. }
  1100. },
  1101. })
  1102. }
  1103. init();
  1104. })(document);
  1105. //埋点
  1106. function operate(pointName){
  1107. $.ajax({
  1108. url: baseUrl + '/api/public/v1/systemBuriedPoint/stat',
  1109. type: 'post',
  1110. data:JSON.stringify({
  1111. pointName: pointName
  1112. }),
  1113. contentType:"application/json",
  1114. dataType: 'json',
  1115. cache: false,
  1116. success: function (res) {},
  1117. })
  1118. }
  1119. //防止提示一秒内重复显示
  1120. function stopManyClick(fn) {
  1121. if (flag) {
  1122. fn();
  1123. }
  1124. flag = false;
  1125. if(timer){clearTimeout(timer);}
  1126. timer = setTimeout(() => {flag = true}, 1500);
  1127. }
  1128. </script>
  1129. </body>
  1130. </html>