awardActivity.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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">{{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. 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. $('.award-title')[0].className = 'award-title';
  298. $('.award-title')[1].className = 'award-title active-title';
  299. $('.distribution-list-wrap').eq(0).css('display', 'block');
  300. $('.award-list').eq(0).css('display', 'none');
  301. $('.no-award-data').eq(0).css('display', 'none');
  302. if(cardList.length === 0) {
  303. $('.tab-bg2').eq(0).css('display', 'none');
  304. $('.tab-bg3').eq(0).css('display', 'none');
  305. $('.tab-bg4').eq(0).css('display', 'block');
  306. $('.tab-wrap').eq(0).css('height', '5.76rem');
  307. $('.distribution-list-wrap').eq(0).css('display', 'none');
  308. $('.no-distribution-data').eq(0).css('display', 'block');
  309. } else if(pages2 == 0) {
  310. $('.tab-bg4').eq(0).css('display', 'none');
  311. $('.tab-bg2').eq(0).css('display', 'none');
  312. $('.tab-bg3').eq(0).css('display', 'block');
  313. $('.tab-wrap').eq(0).css('height', '9.05rem');
  314. } else {
  315. $('.tab-bg4').eq(0).css('display', 'none');
  316. $('.tab-bg3').eq(0).css('display', 'none');
  317. $('.tab-bg2').eq(0).css('display', 'block');
  318. $('.award-record-list').eq(0).css('display', 'block');
  319. $('.tab-wrap').eq(0).css('height', '14.75rem');
  320. }
  321. }
  322. // 继续抽奖
  323. function nextLottery(e) {
  324. if(e.target.className === 'card-btn'){
  325. cardClose();
  326. stopManyClick(() =>{
  327. startLottery('next');
  328. })
  329. }
  330. }
  331. function animation(num, time, result) {
  332. if(num >= 0) {
  333. $('.curr-award-item').eq(num).css('background', '#ffffff');
  334. }
  335. num++;
  336. $('.curr-award-item').eq(num).css('background', '#FAE892');
  337. if(time < 160) {
  338. time += 30;
  339. } else if(num === flagNum - 5) {
  340. time += 50;
  341. } else if(num === flagNum - 4) {
  342. time += 100;
  343. } else if(num === flagNum - 3) {
  344. time += 200;
  345. } else if(num === flagNum - 2) {
  346. time += 300;
  347. } else if(num === flagNum - 1) {
  348. time += 300;
  349. } else if(num === flagNum) {
  350. time += 100;
  351. } else {
  352. time += 30;
  353. }
  354. let flag = $('.curr-award-id').eq(num).text();
  355. if(flag == lotteryResult.id){
  356. flagNum = num < 6 ? num + awardNumber : num;
  357. console.log('flagNum', flagNum)
  358. }
  359. timer = setTimeout(() => {
  360. if(num === awardNumber) {
  361. num = -1;
  362. animation(num, time);
  363. } else if(flag == lotteryResult.id && time > 500) {
  364. lotteryResultHandle();
  365. clearTimeout(timer);
  366. } else {
  367. animation(num, time)
  368. }
  369. }, time)
  370. }
  371. // 开始抽奖
  372. function startLottery(type){
  373. if(activityState == 0){
  374. stopManyClick(() =>{
  375. toastr.error('活动未开始!');
  376. })
  377. return
  378. }
  379. if(activityState == 2){
  380. stopManyClick(() =>{
  381. toastr.error('活动已结束!');
  382. })
  383. return
  384. }
  385. if(lotteryCount <= 0) {
  386. operate('mfhd_2022_h5_购买云机');
  387. getTimeHandle('buy');
  388. return
  389. } else if(type === 'next') {
  390. operate('mfhd_2022_h5_继续抽奖');
  391. } else {
  392. operate('mfhd_2022_h5_开始抽奖');
  393. }
  394. if(!lotteryFlag) {
  395. return
  396. }
  397. lotteryFlag = false;
  398. if(!GetRequest().token){
  399. return
  400. }
  401. let num = flagNum > awardNumber ? flagNum - awardNumber : flagNum;
  402. $('.curr-award-item').eq(num).css('background', '#ffffff');
  403. $.ajax({
  404. url: baseUrl + '/api/activity/gratis/startLottery',
  405. type: 'get',
  406. headers: {
  407. 'Authorization': GetRequest().token //id
  408. },
  409. data: {
  410. clientType: GetRequest().clientType
  411. },
  412. contentType: "application/json",
  413. dataType: 'json',
  414. cache: false,
  415. success: function (res) {
  416. if(res.status === 0){
  417. let time = 20;
  418. let num = -1;
  419. lotteryResult = res.data;
  420. animation(num, time, 3);
  421. }else{
  422. stopManyClick(() =>{
  423. toastr.error(res.msg)
  424. })
  425. lotteryFlag = true
  426. }
  427. }
  428. })
  429. }
  430. //抽奖结果展示
  431. function lotteryResultHandle() {
  432. $('.main-contain').eq(0).empty();
  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. let text = lotteryResult.lotteryCount != 0 ?'换个姿势,再抽一次' : '次数用完,点击获取';
  443. $('.result-title').eq(0).text(text)
  444. if(lotteryCount === 0) {
  445. $('.start-award')[0].src = '../static/img/awardActivity/bug-phone.png';
  446. }
  447. lotteryResult.icon = `https://file.phone.androidscloud.com:8121/document/newFile/download/0/${uploadKey}?fileKey=${lotteryResult.icon}`
  448. result = $('#card').text().replace(/{{(.*?)}}/g, function(node, key) {
  449. return lotteryResult[key];
  450. })
  451. goodsList();
  452. pageNum = 1;
  453. rewardList();
  454. allotTimeCardList();
  455. $('.main-contain').eq(0).append(result)
  456. $('.times').eq(0).text(lotteryResult.lotteryCount)
  457. }
  458. // 抽奖记录
  459. function rewardList(type){
  460. if(!GetRequest().token){
  461. return
  462. }
  463. $.ajax({
  464. url: baseUrl + '/api/activity/gratis/rewardList',
  465. type: 'get',
  466. headers: {
  467. 'Authorization': GetRequest().token //id
  468. },
  469. data: {
  470. page: pageNum,
  471. pageSize: 5
  472. },
  473. contentType: "application/json",
  474. dataType: 'json',
  475. cache: false,
  476. success: function (res) {
  477. if(res.status === 0){
  478. recordFlag = true;
  479. let list = res.data.list
  480. pages = res.data.pages;
  481. if(type != 'down'){
  482. $('.award-list-wrap').eq(0).empty();
  483. }
  484. if(pages === 0) {
  485. $('.no-award-data').eq(0).css('display', 'block');
  486. $('.award-list').eq(0).css('display', 'none');
  487. } else {
  488. $('.award-list').eq(0).css('display', 'block');
  489. $('.no-award-data').eq(0).css('display', 'none');
  490. }
  491. let result = ''
  492. list.map((item, index) => {
  493. item.createTime = `${item.createTime.substring(5, 7)}月${item.createTime.substring(8, 10)}日${item.createTime.substring(11)}`
  494. result += $('#awardRecord').text().replace(/{{(.*?)}}/g, function(node, key) {
  495. return item[key];
  496. })
  497. })
  498. $('.award-list-wrap').eq(0).append(result)
  499. }else{
  500. stopManyClick(() =>{
  501. toastr.error(res.msg)
  502. })
  503. }
  504. }
  505. })
  506. }
  507. //抽奖记录下拉加载
  508. $('.award-list-wrap')[0].addEventListener('scroll',function () {
  509. let scrollTop = $('.award-list-wrap')[0].scrollTop;
  510. let clientHeight = $('.award-list-wrap')[0].clientHeight;
  511. let scrollHeight = $('.award-list-wrap')[0].scrollHeight;
  512. if(scrollTop + clientHeight + 100 > scrollHeight){
  513. if(recordFlag && pageNum < pages && pages > 1){
  514. recordFlag = false;
  515. pageNum++;
  516. rewardList('down');
  517. }
  518. }
  519. });
  520. // 活动基础数据
  521. function goodsList(){
  522. if(!GetRequest().token){
  523. return
  524. }
  525. $.ajax({
  526. url: baseUrl + '/api/activity/gratis/goodsList',
  527. type: 'get',
  528. headers: {
  529. 'Authorization': GetRequest().token //id
  530. },
  531. contentType: "application/json",
  532. dataType: 'json',
  533. cache: false,
  534. success: function (res) {
  535. if(res.status === 0){
  536. let startTime = res.data.startTime
  537. let endTime = res.data.endTime
  538. $('.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)}日`);
  539. awardData = res.data.marquee
  540. let goodsInfos = res.data.goodsInfos
  541. lotteryCount = res.data.lotteryCount
  542. activityState = res.data.activityState
  543. awardNumber = goodsInfos.length
  544. let actRule = res.data.actRule
  545. let result = ''
  546. let resultDom = goodsInfos.length === 9 ? $('#award1') : $('#award2');
  547. if(goodsInfos.length === 9) {
  548. $(".top-bg-one").css({"display": "block"})
  549. $(".all-award-wrap").css({"marginLeft": "0.1rem"})
  550. $(".top-bg-two").css({"display": "none"})
  551. } else {
  552. $(".top-bg-one").css({"display": "none"})
  553. $(".all-award-wrap").css({"marginLeft": "0.14rem"})
  554. $(".top-bg-two").css({"display": "block"})
  555. }
  556. goodsInfos.map((item, index) => {
  557. item.index = index
  558. item.icon = `https://file.phone.androidscloud.com:8121/document/newFile/download/0/${uploadKey}?fileKey=${item.icon}`
  559. result += resultDom.text().replace(/{{(.*?)}}/g, function(node, key) {
  560. return item[key];
  561. })
  562. })
  563. if(lotteryCount > 0) {
  564. $('.start-award')[0].src = '../static/img/awardActivity/start-award.png';
  565. }
  566. clearInterval(awardTimer);
  567. headerAward();
  568. $('.rule-point-wrap').eq(0).html(actRule)
  569. $('.times').eq(0).text(lotteryCount)
  570. let content = $('.all-award-wrap').eq(0).text();
  571. if(!content){
  572. $('.all-award-wrap').eq(0).append(result)
  573. }
  574. }else{
  575. stopManyClick(() =>{
  576. toastr.error(res.msg)
  577. })
  578. }
  579. }
  580. })
  581. }
  582. //轮播
  583. function headerAward(){
  584. if(awardData.length === 0) {
  585. return
  586. }
  587. awardTimer = setInterval(() =>{
  588. awardHandle();
  589. },3000);
  590. }
  591. function awardHandle(){
  592. let index = (topVal/0.5) + 1,awardString;
  593. let awardLen = Array.from($('.award-text')).length;
  594. if(awardLen < awardData.length){
  595. let node = document.createElement('div');
  596. node.className = "award-text";
  597. $('.award-lists')[0].appendChild(node);
  598. }
  599. if(topVal < awardData.length/2 - 0.5){
  600. topVal+=0.5;
  601. }else{
  602. topVal = 0;
  603. $('.award-lists').eq(0).css('top','0.5rem');
  604. }
  605. let numberType = Math.floor(getRandom()/4);
  606. if(awardData && awardData[index] && topVal < awardData.length/2){
  607. awardString = `恭喜${awardData[index].phone}用户获得${['优惠券','激活码','云机时长','星币','云机套餐','谢谢惠顾'][awardData[index].goodsType]}奖品`;
  608. }
  609. // else{
  610. // awardString = `恭喜1${[3,5,7,8,3,5,7,8,3,5][getRandom()]}${getRandom()}****${getRandom()}${getRandom()}${getRandom()}${getRandom()}用户获得${['优惠券','激活码','云机时长','星币','云机套餐','谢谢惠顾'][numberType]}`
  611. // }
  612. $('.award-text').eq(index).text(awardString);
  613. $('.award-lists').eq(0).animate({top: -(topVal) + 'rem'},"fast");
  614. }
  615. // 获取一个随机数
  616. function getRandom(){
  617. return Math.floor(Math.random()*10);
  618. }
  619. // 分配云手机列表
  620. function allotTimeCardList(type){
  621. pageNum1 = 0;
  622. recordFlag1 = false;
  623. $('.distribution-container').eq(0).empty();
  624. if(!GetRequest().token){
  625. return
  626. }
  627. $.ajax({
  628. url: baseUrl + '/api/activity/gratis/allotTimeCardList',
  629. type: 'get',
  630. headers: {
  631. 'Authorization': GetRequest().token //id
  632. },
  633. contentType: "application/json",
  634. dataType: 'json',
  635. cache: false,
  636. success: function (res) {
  637. if(res.status === 0){
  638. cardList = res.data.cardList
  639. unAllotTime = res.data.unAllotTime
  640. userCardId = cardList[0].userCardId
  641. pageCardList()
  642. $('.all-times').eq(0).text(res.data.totalTime)
  643. $('.red').eq(0).text(res.data.totalTime)
  644. $('.red').eq(1).text(res.data.allotTime)
  645. $('.red').eq(2).text(res.data.unAllotTime)
  646. }else{
  647. stopManyClick(() =>{
  648. toastr.error(res.msg)
  649. })
  650. }
  651. }
  652. })
  653. }
  654. // 分页渲染数据
  655. function pageCardList() {
  656. let result = '';
  657. recordFlag1 = true;
  658. let list = cardList.slice(pageNum1 * 5, (pageNum1 * 5) + 5);
  659. let mealTypeObj = {
  660. VIP: 'card1.png',
  661. SVIP: 'card2.jpg',
  662. STAR: 'card3.png',
  663. STARPRO: 'card4.png'
  664. }
  665. list.map((item, index) => {
  666. item.index = pageNum1 * 5 + index
  667. item.icon = `../static/img/awardActivity/${mealTypeObj[item.buyVipType]}`
  668. result += $('#distribution').text().replace(/{{(.*?)}}/g, function(node, key) {
  669. return item[key];
  670. })
  671. })
  672. $('.distribution-container').eq(0).append(result);
  673. for (var i = 0; i < list.length; i++) {
  674. $('.num-ipt')[pageNum1 * 5 + i].oninput = function (e) {
  675. const id = e.target.dataset.id;
  676. let oldDuration = 0;
  677. let preTotalTime = 0;
  678. let index = e.target.dataset.index;
  679. let value = $('.num-ipt').eq(index).val();
  680. if(value.length >= 5){
  681. value = value.substr(0, 5);
  682. }
  683. var position = String(value).indexOf(".");//获取小数点的位置
  684. if(position != -1){
  685. value = value.substr(0, position);
  686. }
  687. distributionList.map(item => { // 上一次的总数据
  688. preTotalTime += parseInt(item.allotTime);
  689. })
  690. //这一次操作
  691. if(value == 0){
  692. if(!distributionList.find((item) => item.userCardId == id)){
  693. distributionList.push({
  694. userCardId: id,
  695. allotTime: +value
  696. });
  697. }else{
  698. distributionList = distributionList.filter(item => item.userCardId != id);
  699. }
  700. distributionList = distributionList.filter(item => item.allotTime != 0);
  701. }else{
  702. if(!distributionList.find((item) => item.userCardId == id)){
  703. distributionList.push({
  704. userCardId: id,
  705. allotTime: Math.abs(value)
  706. });
  707. }else{
  708. distributionList.map(item => {
  709. if (item.userCardId == id) {
  710. oldDuration = item.allotTime;
  711. item.allotTime = +value;
  712. }
  713. })
  714. }
  715. }
  716. currTotalTime = 0;
  717. distributionList.map(item => { // 这一次的总数据
  718. currTotalTime += parseInt(item.allotTime);
  719. })
  720. if(currTotalTime > unAllotTime){ // 当前已分配大于总分配时长
  721. let val = unAllotTime - preTotalTime + oldDuration;
  722. distributionList.map(item => {
  723. if (item.userCardId == id) {
  724. item.allotTime = val;
  725. }
  726. })
  727. $('.num-ipt').eq(index).val(val);
  728. stopManyClick(() => {
  729. toastr.error('分配时长不能大于未分配总时长');
  730. })
  731. return
  732. }
  733. if(value.length > 5) value = value.slice(0, 5);
  734. $('.num-ipt').eq(index).val(value);
  735. }
  736. }
  737. }
  738. //抽奖记录下拉加载
  739. $('.distribution-container')[0].addEventListener('scroll',function () {
  740. let scrollTop = $('.distribution-container')[0].scrollTop;
  741. let clientHeight = $('.distribution-container')[0].clientHeight;
  742. let scrollHeight = $('.distribution-container')[0].scrollHeight;
  743. if(scrollTop + clientHeight + 100 > scrollHeight){
  744. if(recordFlag1 && pageNum1 < (cardList.length/5) && (cardList.length/5) > 1){
  745. recordFlag1 = false;
  746. pageNum1++;
  747. pageCardList();
  748. }
  749. }
  750. });
  751. // 分配时长记录
  752. function allotTimeRecord(type){
  753. if(!GetRequest().token){
  754. return
  755. }
  756. $.ajax({
  757. url: baseUrl + '/api/activity/gratis/allotTimeRecord',
  758. type: 'get',
  759. headers: {
  760. 'Authorization': GetRequest().token //id
  761. },
  762. data: {
  763. page: pageNum2,
  764. pageSize: 5
  765. },
  766. contentType: "application/json",
  767. dataType: 'json',
  768. cache: false,
  769. success: function (res) {
  770. if(res.status === 0){
  771. let list = res.data.list
  772. let result = ''
  773. pages2 = res.data.pages
  774. recordFlag2 = true;
  775. if(type != 'down'){
  776. $('.award-record-list-wrap').eq(0).empty();
  777. }
  778. list.map(item => {
  779. item.createTime = `${item.createTime.substring(0, 4)}年${item.createTime.substring(5, 7)}月${item.createTime.substring(8, 10)}日${item.createTime.substring(11)}`
  780. result += $('#record').text().replace(/{{(.*?)}}/g, function(node, key) {
  781. return item[key];
  782. })
  783. })
  784. $('.award-record-list-wrap').eq(0).append(result)
  785. }else{
  786. stopManyClick(() =>{
  787. toastr.error(res.msg)
  788. })
  789. }
  790. }
  791. })
  792. }
  793. //分配时长记录下拉加载
  794. $('.award-record-list-wrap')[0].addEventListener('scroll',function () {
  795. let scrollTop = $('.award-record-list-wrap')[0].scrollTop;
  796. let clientHeight = $('.award-record-list-wrap')[0].clientHeight;
  797. let scrollHeight = $('.award-record-list-wrap')[0].scrollHeight;
  798. if(scrollTop + clientHeight + 100 > scrollHeight){
  799. if(recordFlag2 && pageNum2 < pages2 && pages2 > 1){
  800. recordFlag2 = false;
  801. pageNum2++;
  802. allotTimeRecord('down');
  803. }
  804. }
  805. });
  806. function getTimeHandle(type) {
  807. if(activityState == 0){
  808. stopManyClick(() =>{
  809. toastr.error('活动未开始!');
  810. })
  811. return
  812. }
  813. if(activityState == 2){
  814. stopManyClick(() =>{
  815. toastr.error('活动已结束!');
  816. })
  817. return
  818. }
  819. if(!lotteryFlag) {
  820. return
  821. }
  822. if(type != 'bug') {
  823. operate('mfhd_2022_h5_获取次数按钮');
  824. }
  825. stopManyClick(() =>{
  826. if (window.__wxjs_environment === 'miniprogram') { // 小程序
  827. if(phoneRemainQuantity > 0){
  828. wx.miniProgram.navigateTo({
  829. url: '/packageA/order/buy/index?type=activity'
  830. })
  831. } else {
  832. wx.miniProgram.navigateTo({
  833. url: '/packageA/order/renew/index?record=' + userCardId
  834. })
  835. }
  836. } else if (isAndroid && window.native) { // 安卓
  837. if(phoneRemainQuantity > 0){
  838. window.native.startPurchase('SVIP', 365);
  839. } else {
  840. window.native.startRenew();
  841. }
  842. } else if (isiOS) {
  843. try {
  844. if(phoneRemainQuantity > 0){
  845. window.webkit.messageHandlers.startPurchase.postMessage({ type: 1, day: 365 });
  846. } else {
  847. window.webkit.messageHandlers.startRenew.postMessage({ type: 1, day: 365 });
  848. }
  849. } catch(error) {
  850. if(phoneRemainQuantity > 0){
  851. uni.webView.navigateTo({
  852. url: '/pages/order/order'
  853. })
  854. } else {
  855. uni.webView.navigateTo({
  856. url: '/pages/order/renew?record=' + userCardId
  857. })
  858. }
  859. }
  860. }
  861. })
  862. }
  863. //点击加减号
  864. $('.distribution-container')[0].addEventListener('click',(e) => {
  865. if(!lotteryFlag) {
  866. return
  867. }
  868. if(e.target.className === 'add'){
  869. operate('mfhd_2022_h5_加号');
  870. const id = e.target.dataset.id;
  871. let index = e.target.dataset.index;
  872. let number = $('.num-ipt').eq(index).val();
  873. currTotalTime = 0;
  874. // 这一次操作
  875. if(number == 0){
  876. if(!distributionList.find((item) => item.userCardId == id)){
  877. distributionList.push({
  878. userCardId: id,
  879. allotTime: +number + 1
  880. });
  881. }else{
  882. distributionList.map(item => {
  883. if(item.userCardId == id){
  884. item.allotTime++;
  885. }
  886. })
  887. }
  888. }else{
  889. distributionList.map(item => {
  890. if(item.userCardId == id){
  891. item.allotTime++;
  892. }
  893. })
  894. }
  895. distributionList.map(item => { // 这一次的总数据
  896. currTotalTime += parseInt(item.allotTime);
  897. })
  898. if(currTotalTime <= unAllotTime){
  899. number++;
  900. $('.num-ipt').eq(index).val(number);
  901. }else{
  902. distributionList.map(item => {
  903. if(item.userCardId == id){
  904. item.allotTime = +number;
  905. }
  906. })
  907. stopManyClick(() => {
  908. toastr.error('分配时长不能大于未分配总时长');
  909. })
  910. }
  911. }
  912. if(e.target.className === 'cut'){
  913. operate('mfhd_2022_h5_减号');
  914. const id = e.target.dataset.id;
  915. let index = e.target.dataset.index;
  916. let number = $('.num-ipt').eq(index).val();
  917. if(number > 0){
  918. distributionList.map(item => {
  919. if(item.userCardId == id){
  920. item.allotTime--;
  921. }
  922. })
  923. number--;
  924. if(number == 0){
  925. distributionList = distributionList.filter(item => item.userCardId != id);
  926. }
  927. currTotalTime--;
  928. $('.num-ipt').eq(index).val(number);
  929. }else{
  930. stopManyClick(() => {
  931. toastr.error('分配的时长不能小于0');
  932. })
  933. }
  934. }
  935. });
  936. function distributionTime(e) {
  937. if(!lotteryFlag) {
  938. return
  939. }
  940. operate('mfhd_2022_h5_分配奖励');
  941. distributionList = distributionList.filter(item => item.allotTime != 0);
  942. if (distributionList.length === 0) {
  943. stopManyClick(() => {
  944. toastr.error('未选中任何云手机');
  945. })
  946. } else {
  947. $('.sure-distribution-wrap').eq(0).css('display', 'block');
  948. }
  949. }
  950. //点击分配时长取消按钮
  951. $('.sure-distribution-cannel')[0].addEventListener('click', (e) => {
  952. operate('mfhd_2022_h5_分配奖励_取消');
  953. $('.sure-distribution-wrap').eq(0).css('display', 'none');
  954. });
  955. //点击分配时长确定按钮
  956. $('.sure-distribution-sure')[0].addEventListener('click', (e) => {
  957. stopManyClick(() => {
  958. $.ajax({
  959. url: baseUrl + '/api/activity/gratis/allotTime',
  960. type: 'post',
  961. data: JSON.stringify(distributionList),
  962. headers: {
  963. 'Authorization': GetRequest().token //id
  964. },
  965. contentType: "application/json",
  966. dataType: 'json',
  967. cache: false,
  968. success: function (res) {
  969. if(res.status === 0){
  970. operate('mfhd_2022_h5_分配奖励_确定');
  971. $('.sure-distribution-wrap').eq(0).css('display', 'none');
  972. $('.slider-list').eq(0).text('');
  973. $('.page-number').eq(0).text('');
  974. init();
  975. pageNum2 = 1;
  976. pages2 = 0;
  977. allotTimeRecord();
  978. distributionPageNum = 1;
  979. $('.time-row-data').eq(0).text('');
  980. distributionList.map((val) => {
  981. cardList.map((item, indexs) => {
  982. if(val.userCardId == item.userCardId){
  983. $('.num-ipt').eq(indexs).val(0);
  984. }
  985. })
  986. })
  987. distributionList = [];
  988. cardList = [];
  989. $('.tab-bg4').eq(0).css('display', 'none');
  990. $('.tab-bg3').eq(0).css('display', 'none');
  991. $('.tab-bg2').eq(0).css('display', 'block');
  992. $('.award-record-list').eq(0).css('display', 'block');
  993. $('.tab-wrap').eq(0).css('height', '14.75rem');
  994. toastr.error('分配成功,请前往云机列表查看');
  995. } else {
  996. console.log(res.msg)
  997. $('.sure-distribution-wrap').eq(0).css('display', 'none');
  998. toastr.error(res.msg);
  999. }
  1000. },
  1001. })
  1002. })
  1003. });
  1004. function ruleHandle (e) {
  1005. operate('mfhd_2022_h5_规则');
  1006. $('.rule-result-dialog').animate({top: '3.86rem'},"fast");
  1007. $('.rule-mask').show();
  1008. document.documentElement.style.overflow='hidden';
  1009. }
  1010. function ruleClose (e) {
  1011. operate('mfhd_2022_h5_关闭规则');
  1012. $('.rule-result-dialog').animate({top: '-10.96rem'},"fast");
  1013. $('.rule-mask').hide();
  1014. document.documentElement.style.overflow='auto';
  1015. }
  1016. function cardClose (e) {
  1017. operate('mfhd_2022_h5_关闭抽奖结果');
  1018. $('.result-dialog').animate({top: '-10.96rem'},"fast");
  1019. $('.result-mask').hide();
  1020. document.documentElement.style.overflow='auto';
  1021. }
  1022. //获取云机数量
  1023. function getPhoneNumber(){
  1024. $.ajax({
  1025. url: baseUrl + '/api/pay/v2/meal/info?phoneType=SVIP',
  1026. type: 'get',
  1027. headers: {
  1028. 'Authorization': GetRequest().token //id
  1029. },
  1030. contentType: "application/json",
  1031. dataType: 'json',
  1032. cache: false,
  1033. success: function (res) {
  1034. if(res.status === 0){
  1035. phoneRemainQuantity = res.data.list[0].phoneRemainQuantity;
  1036. }else{
  1037. stopManyClick(() =>{
  1038. toastr.error(res.msg)
  1039. })
  1040. }
  1041. },
  1042. })
  1043. }
  1044. init();
  1045. })(document);
  1046. //埋点
  1047. function operate(pointName){
  1048. $.ajax({
  1049. url: baseUrl + '/api/public/v1/systemBuriedPoint/stat',
  1050. type: 'post',
  1051. data:JSON.stringify({
  1052. pointName: pointName
  1053. }),
  1054. contentType:"application/json",
  1055. dataType: 'json',
  1056. cache: false,
  1057. success: function (res) {},
  1058. })
  1059. }
  1060. //防止提示一秒内重复显示
  1061. function stopManyClick(fn) {
  1062. if (flag) {
  1063. fn();
  1064. }
  1065. flag = false;
  1066. if(timer){clearTimeout(timer);}
  1067. timer = setTimeout(() => {flag = true}, 1500);
  1068. }
  1069. </script>
  1070. </body>
  1071. </html>