awardActivity.html 36 KB

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