Keine Beschreibung

index.js 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. function parseQueryString(url) {
  2. var urlObj = {};
  3. var reg = /([^?=&]+)=([^?=&]+)/g;
  4. url.replace(reg, ($0, $1, $2) => {
  5. urlObj[$1] = decodeURIComponent($2);
  6. })
  7. return urlObj;
  8. }
  9. // [showMsg 提示各种错误信息,3s后消失]
  10. function showMsg(msg) {
  11. var msgBox = $('.alert-info');
  12. msgBox.children('p').text(msg);
  13. msgBox.show();
  14. setTimeout(function() {
  15. msgBox.hide();
  16. }, 3000);
  17. }
  18. var user_id = '';
  19. var appName = '钱多记账';
  20. var scrollTop = '';
  21. var scrollTop02 = '';
  22. var activityId = '';
  23. var jsons = {};
  24. var qs = parseQueryString(window.location.href);
  25. $().ready(function () {
  26. if(qs.activityId){
  27. activityId = qs.activityId
  28. }
  29. if(qs.userId && qs.userId != ' '){
  30. user_id = qs.userId;
  31. checkIsJoin();
  32. }else{
  33. showMsg('获取用户信息失败')
  34. }
  35. if(qs.appName){
  36. appName = qs.appName
  37. }
  38. jsons = {
  39. title:'【钱多记账】记账打卡赢现金!快到碗里来',
  40. desc:'每日记账打卡,投入1元,养成好习惯,还能赚到收益。',
  41. url:BASEURL + '/divide_red_envelopes/shareWechat.html?userId=' + user_id + '&appName=' + appName + "&time=" + new Date().getTime()
  42. };
  43. if(appName == '金牛记账' || appName == '金牛记账'){
  44. jsons = {
  45. title:'【金牛记账】记账打卡赢现金!快到碗里来',
  46. desc:'每日记账打卡,投入1元,养成好习惯,还能赚到收益。',
  47. url:BASEURL + '/divide_red_envelopes/shareWechat.html?userId=' + user_id + '&appName=' + appName + "&time=" + new Date().getTime()
  48. };
  49. }
  50. jsons = JSON.stringify(jsons);
  51. $(window).scroll(function(){
  52. scrollTop = $(this).scrollTop(); //scrollTop() 方法返回或设置匹配元素的滚动条的垂直位置
  53. })
  54. prohibitClosure();//点击内容 禁止关闭
  55. })
  56. function getDivideInfo (num) {
  57. // 获取瓜分新进活动首页信息
  58. $.ajax({
  59. type:"post",
  60. url:"/api/V2/getDivideInfo",
  61. dataType:'json',
  62. data:{
  63. user_id:user_id
  64. },
  65. success: function (res) {
  66. console.log(res)
  67. if(res && res.code == 0){
  68. var html = ''
  69. var is_divide_html = '';//是否已经报名参加活动
  70. var avatarHtml = ''//用户头像html
  71. var participate_nu_html = ''//当天瓜分现金参与人数html
  72. var account = res.res.account;//记账可随机瓜分金额
  73. var avatar = res.res.avatar//用户头像数据
  74. var participate_nu = res.res.participate_nu//当天瓜分现金参与人数
  75. var is_participate = res.res.is_participate//当前用户是否参加今日活动 0:未参与 1:参与且任务未完成 2:参与且任务完成
  76. var yesterday_finish = res.res.yesterday_finish//昨日挑战完成的人数
  77. var yesterday_failure = res.res.yesterday_failure//昨日挑战失败的人数
  78. var first = res.res.first//最早完成的用户信息
  79. var diligent = res.res.diligent//最勤奋完成的信息
  80. var is_participate_img = '';//当前用户是否参加今日活动 0:未参与 1:参与且任务未完成 2:参与且任务完成
  81. var is_participate_title = '';//当前用户是否参加今日活动 0:未参与 1:参与且任务未完成 2:参与且任务完成
  82. //判断是否已经报名参加活动
  83. if(num == 0){
  84. //为报名参加
  85. is_divide_html = `<div class="onePrice" onclick="wechatZhifu()">一元参与</div>`;
  86. }else if(num == 4004){
  87. //用户已经参加报名
  88. is_divide_html = `<div class="onePrice">已成功报名</div>`;
  89. }
  90. $(".banner .price").html(account)
  91. avatar.forEach(function (item, index){
  92. if(index < 8){
  93. avatarHtml += `<li><img src="${item}"/></li>`
  94. }
  95. })
  96. participate_nu = participate_nu.toString().split('');//当天瓜分现金参与人数转为数组
  97. participate_nu.forEach(function (item, index){
  98. if(index < 8){
  99. participate_nu_html += `<li>${item}</li>`
  100. }
  101. })
  102. if (is_participate == 0){
  103. //未参与
  104. is_participate_img = 'img/weicanjia.png';
  105. is_participate_title = '未报名参与今日记账活动';
  106. }else if (is_participate == 1){
  107. //参与且任务未完成
  108. is_participate_img = 'img/yicanjia.png';
  109. is_participate_title = '参与今日记账活动但任务未完成';
  110. }else if (is_participate == 2){
  111. //参与且任务完成
  112. is_participate_img = 'img/yicanjia.png';
  113. is_participate_title = '已经手动记账';
  114. }
  115. html += `<div class="content_01">
  116. <div class="number_people">
  117. <div class="title">当前参与人数</div>
  118. <div class="number">
  119. <ul>${participate_nu_html}</ul>
  120. <span>人</span>
  121. </div>
  122. <p>当前有 <em>${participate_nu}</em> 人参与明天记账打卡挑战</p>
  123. </div>
  124. <div class="operation">
  125. <div class="userImges">
  126. <ul>${avatarHtml}</ul>
  127. </div>
  128. ${is_divide_html}
  129. <div class="inviting_friends" onclick="invitingFriends()">邀请好友领现金</div>
  130. </div>
  131. </div>
  132. <!--今日个人状态-->
  133. <div class="content_02">
  134. <div class="title">今日个人状态</div>
  135. <div class="state_01">
  136. <img src="${is_participate_img}"/>
  137. <p>${is_participate_title}</p>
  138. </div>
  139. </div>
  140. <!--昨日记账挑战-->
  141. <div class="content_03">
  142. <div class="title">昨日记账挑战</div>
  143. <ul>
  144. <li class="first">
  145. <img src="img/success.png" />
  146. <span style="margin-left:-0.2rem;">${yesterday_finish}人成功</span>
  147. </li>
  148. <li class="last">
  149. <img src="img/shibai.png" />
  150. <span>${yesterday_failure}人失败</span>
  151. </li>
  152. </ul>
  153. </div>
  154. <!--参与用户状态-->
  155. <div class="content_04">
  156. <div class="title">参与用户状态</div>
  157. <ul>
  158. <li>
  159. <div class="left">
  160. <img src="${first.avatar}" />
  161. <div class="leftCon">
  162. <p>${first.name}</p>
  163. <span>${first.time}</span>
  164. </div>
  165. </div>
  166. <div class="right rightActive">
  167. <i class="icon" style="background:url(img/zuizao.png) no-repeat;background-size:100% 100%;"></i>
  168. <span>最早XXXX</span>
  169. </div>
  170. </li>
  171. <li>
  172. <div class="left">
  173. <img src="${diligent.avatar}" />
  174. <div class="leftCon">
  175. <p>${diligent.name}</p>
  176. <span>${diligent.time}</span>
  177. </div>
  178. </div>
  179. <div class="right">
  180. <i class="icon" style="background:url(img/zan.png) no-repeat;background-size:100% 100%;"></i>
  181. <span>连续${diligent.day_nu}天</span>
  182. </div>
  183. </li>
  184. </ul>
  185. </div>`
  186. $("#content").html(html);//参与瓜分用户头像展示 最多8个
  187. }
  188. }
  189. });
  190. }
  191. //查询用户是否参加了瓜分现金活动
  192. function checkIsJoin () {
  193. $.ajax({
  194. type:"post",
  195. url:"/api/V2/checkIsJoin",
  196. data:{
  197. user_id:user_id,
  198. activityId:activityId
  199. },
  200. dataType:'json',
  201. success:function (res) {
  202. if(res && res.code == 0){
  203. getDivideInfo(0)
  204. }else if(res && res.code == 4004){
  205. getDivideInfo(4004)
  206. }else{
  207. showMsg('获取用户信息失败')
  208. }
  209. }
  210. });
  211. }
  212. //去我的战绩
  213. function goMyRecord () {
  214. window.location.href="myRecord.html?userId=" + user_id + "&appName=" + appName
  215. }
  216. function prohibitClosure () {
  217. //点击内容 禁止关闭
  218. $(".invite_friends_zzc .content").click(function () {
  219. return false;
  220. })
  221. $(".wechat_zhifu_zzc .content").click(function () {
  222. return false;
  223. })
  224. }
  225. //唤起邀请好友弹窗
  226. function invitingFriends () {
  227. $(".invite_friends_zzc").show();
  228. scrollTop02 = scrollTop;
  229. $('body').css({'position':'fixed',"top":-scrollTop});
  230. }
  231. //关闭遮罩层弹窗
  232. function closeZzc () {
  233. $(".invite_friends_zzc").hide();
  234. $(".wechat_zhifu_zzc").hide();
  235. $("body").css({"position":"initial"});
  236. $(window).scrollTop(scrollTop02)
  237. }
  238. //微信支付弹层
  239. function wechatZhifu () {
  240. $(".wechat_zhifu_zzc").show();
  241. scrollTop02 = scrollTop;
  242. $('body').css({'position':'fixed',"top":-scrollTop});
  243. }
  244. //点击瓜分规则去瓜分规则页面
  245. function goDividingRules () {
  246. window.location.href = 'dividingRules.html'
  247. }
  248. //微信支付调取app的方法
  249. function wechatMoneyGo () {
  250. var jsonData = {
  251. activityId:activityId
  252. }
  253. jsonData = JSON.stringify(jsonData);
  254. console.log(jsonData)
  255. if(navigator.userAgent.indexOf('Android') != -1){
  256. messageHandlers.requestAliPay(jsonData)
  257. }else{
  258. window.webkit.messageHandlers.requestAliPay.postMessage(jsonData)
  259. }
  260. }
  261. //微信分享微信调取app的方法
  262. function shareWeixin () {
  263. if(navigator.userAgent.indexOf('Android') != -1){
  264. messageHandlers.shareWithWechatSession(jsons)
  265. }else{
  266. window.webkit.messageHandlers.shareWithWechatSession.postMessage(jsons)
  267. }
  268. }
  269. //微信分享微信朋友圈调取app的方法
  270. function sharePengyouquan () {
  271. if(navigator.userAgent.indexOf('Android') != -1){
  272. messageHandlers.shareWithWechatTimeline(jsons)
  273. }else{
  274. window.webkit.messageHandlers.shareWithWechatTimeline.postMessage(jsons)
  275. }
  276. }
  277. //微信分享QQ调取app的方法
  278. function shareQQ () {
  279. if(navigator.userAgent.indexOf('Android') != -1){
  280. messageHandlers.shareWithQQ(jsons)
  281. }else{
  282. window.webkit.messageHandlers.shareWithQQ.postMessage(jsons)
  283. }
  284. }