jqMethod.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. (function(window){
  2. var jqMethod = function(){
  3. };
  4. /**
  5. * [reward_id_3 description] 掌上大学四个碎片
  6. * [reward_id_4 description] 圣诞快乐四个碎片
  7. * @type {Array}
  8. */
  9. window.reward_id_3=[],window.reward_id_4=[];
  10. window.sum_num;
  11. jqMethod.fn = jqMethod.prototype = {
  12. game_Strategy:game_Strategy,
  13. game_Prize:game_Prize,
  14. messageBox_show:messageBox_show,
  15. game_exChange:game_exChange,
  16. bg_color_yellow:bg_color_yellow,
  17. bg_color_green:bg_color_green,
  18. bg_color_orange:bg_color_orange,
  19. messageBox_close:messageBox_close,
  20. toSpace:toSpace
  21. // unBindClick:unBindClick,
  22. // click_share:click_share
  23. }
  24. /**
  25. * [game_Strategy description] 游戏攻略
  26. * @return {[type]} [description]
  27. */
  28. function game_Strategy () {
  29. // $("body").css('background',"#cce099");
  30. bg_color_yellow ();
  31. $("#gl-con").addClass('gl-con-show');
  32. $("#btn_close").unbind('click').bind('click', function(event) {
  33. /* Act on the event */
  34. $("#gl-con").removeClass('gl-con-show');
  35. $("body").css('background',"#fff71a");
  36. event.stopPropagation();
  37. });
  38. }
  39. /**
  40. * [game_Prize description] 奖品兑换
  41. * @return {[type]} [description]
  42. */
  43. function game_Prize () {
  44. // window.reward_id_3=[],window.reward_id_4=[];
  45. bg_color_green ();
  46. $("#prize-con").addClass('gl-con-show');
  47. $("#close").unbind('click').bind('click', function(event) {
  48. window.reward_id_3=[],window.reward_id_4=[];
  49. $("#prize-con").removeClass('gl-con-show');
  50. bg_color_yellow ();
  51. // $("body").css('background',"#fff71a");
  52. event.stopPropagation();
  53. });
  54. user_reward ();
  55. $(".film").unbind('click').bind('click', function(event) {
  56. /* Act on the event */
  57. if(window.reward_id_3.length==4 && window.reward_id_4.length==4){
  58. game_exChange (3);
  59. }else if (window.reward_id_3.length<4 && window.reward_id_4.length<4) {
  60. messageBox_show(1);
  61. window.reward_id_3=[],window.reward_id_4=[];
  62. }else if(window.reward_id_3.length==4){
  63. game_exChange (3);
  64. }else if(window.reward_id_4.length==4){
  65. game_exChange (4);
  66. }else if (window.reward_id_3.length<4){
  67. messageBox_show(1);
  68. }else if (window.reward_id_4.length<4){
  69. messageBox_show(1);
  70. }
  71. event.stopPropagation();
  72. });
  73. $(".other").unbind('click').bind('click', function(event) {
  74. /* Act on the event */
  75. window.location.href="prizeList.html" + window.location.search;
  76. event.stopPropagation();
  77. });
  78. /**
  79. * [description] 关闭弹出层 --提示
  80. * @param {[type]} event [description]
  81. * @return {[type]} [description]
  82. */
  83. $("#a_btn_ok").unbind('click').bind('click', function(event) {
  84. /* Act on the event */
  85. messageBox_close ();
  86. event.stopPropagation();
  87. });
  88. /**
  89. * [description] 微信 奖品兑换提交
  90. * @param {[type]} event [description]
  91. * @return {[type]} [description]
  92. */
  93. $("#a_btn_prize").unbind('click').bind('click', function(event) {
  94. /* Act on the event */
  95. //TODO 微信 输入姓名和手机号
  96. var name = $("#names").val();
  97. var mobile = $("#phones").val();
  98. var phones_1 =$("#phones_1").val();
  99. if (name =="") {
  100. messageBox_close ();
  101. messageBox_show(9);
  102. return ;
  103. }
  104. if (mobile == "") {
  105. messageBox_close ();
  106. messageBox_show(9);
  107. return ;
  108. }
  109. if (phones_1=="") {
  110. messageBox_close ();
  111. messageBox_show(9);
  112. return ;
  113. }
  114. else if (phones_1!=mobile){
  115. messageBox_close ();
  116. L.alert('手机号码与确认号码不一致');
  117. return;
  118. }
  119. var url = WXDOMAIN + 'wxgame/ex';
  120. gamef.requestServerData(url, "GET", callback, "open_id="+gamef.open_id+"&type=" + gamef.gameid+"&reward_id="+window.sum_num+"&mobile="+mobile+"&name="+name);
  121. event.stopPropagation()
  122. function callback(method, url, data){
  123. var list = data;
  124. if (typeof data === "string") {
  125. list = JSON.parse(data);
  126. }
  127. if (list.status == 0) {
  128. user_reward ();
  129. Main.loadTime();
  130. if (list.response>0) {
  131. messageBox_close ();
  132. messageBox_show(5);
  133. }else if (list.response == 0){
  134. messageBox_close ();
  135. messageBox_show(4);
  136. }
  137. }else if (list.status == 6) {
  138. messageBox_close ();
  139. messageBox_show(9);
  140. }else if (list.status==2018){
  141. messageBox_close ();
  142. messageBox_show(1);
  143. }else if (list.status==2019){
  144. L.alert('本次输入号码和上次领奖号码不一致,请输入上次领奖号码');
  145. }
  146. }
  147. // e.stopPropagation();
  148. });
  149. /**
  150. * [description] 没有碎片
  151. * @param {[type]} event [description]
  152. * @return {[type]} [description]
  153. */
  154. $("#a_btn_null").unbind('click').bind('click', function(event) {
  155. messageBox_close ();
  156. event.stopPropagation();
  157. });
  158. /**
  159. * [description] 关闭弹出层
  160. * @param {[type]} event [description]
  161. * @return {[type]} [description]
  162. */
  163. $(".btn_a_close,.btn_a_close_1").unbind('click').bind('click',function(event) {
  164. messageBox_close () ;
  165. event.stopPropagation();
  166. });
  167. }
  168. //这里处理点击用户头像
  169. function toSpace(option){
  170. //alert(user_name + "," + user_id);
  171. L.loadSpace(option.user_id, option.user_name);
  172. }
  173. /**
  174. * [messageBox_show description] 弹出框
  175. * @param {[type]} num [description] 1.没有集齐 2.已经兑换了
  176. * @return {[type]} [description]
  177. */
  178. function messageBox_show (num) {
  179. var s_div=$(".s_div"),prize_div = $(".prize_div"),share_div=$(".share_div"),null_div=$(".null_div");
  180. var img_50 = $(".img_50"),img_52 = $(".img_52"),img_51= $(".img_51"),img_55= $(".img_55"),img_56= $(".img_56"),img_54= $(".img_54"),img_53= $(".img_53"),img_57= $(".img_57"),img_58= $(".img_58");
  181. // body...
  182. switch(num){
  183. case 1:
  184. //缺少碎片
  185. if (img_50.attr('num')==0) {
  186. img_50.attr('src',img_50.attr('alt')).show();
  187. img_50.attr('num','1');
  188. }else{
  189. img_50.show();
  190. }
  191. break;
  192. case 2:
  193. //已经领取
  194. if (img_52.attr('num')==0) {
  195. img_52.attr('src',img_52.attr('alt')).show();
  196. img_52.attr('num','1');
  197. }else{
  198. img_52.show();
  199. }
  200. break;
  201. case 3:
  202. //代金券编号
  203. $("#img_51").show();
  204. $("#span_51").show();
  205. if (img_51.attr('num')==0) {
  206. img_51.attr('src',img_51.attr('alt')).show();
  207. img_51.attr('num','1');
  208. }else{
  209. img_51.show();
  210. }
  211. break;
  212. case 4:
  213. //已注册班级云账号
  214. $("#down_href").show();
  215. if (img_56.attr('num')==0) {
  216. img_56.attr('src',img_56.attr('alt')).show();
  217. img_56.attr('num','1');
  218. }else{
  219. img_56.show();
  220. }
  221. break;
  222. case 5:
  223. //未注册班级云账号
  224. $("#down_href").show();
  225. if (img_55.attr('num')==0) {
  226. img_55.attr('src',img_55.attr('alt')).show();
  227. img_55.attr('num','1');
  228. }else{
  229. img_55.show();
  230. }
  231. break;
  232. case 6:
  233. //微信领奖
  234. if (img_54.attr('num')==0) {
  235. img_54.attr('src',img_54.attr('alt')).show();
  236. img_54.attr('num','1');
  237. }else{
  238. img_54.show();
  239. }
  240. break;
  241. case 7:
  242. //微信领奖
  243. if (img_53.attr('num')==0) {
  244. img_53.attr('src',img_53.attr('alt')).show();
  245. img_53.attr('num','1');
  246. }else{
  247. img_53.show();
  248. }
  249. break;
  250. case 8:
  251. //微信领奖
  252. // $("#a_btn_share").live
  253. if (img_57.attr('num')==0) {
  254. img_57.attr('src',img_57.attr('alt')).show();
  255. img_57.attr('num','1');
  256. }else{
  257. img_57.show();
  258. }
  259. break;
  260. case 9:
  261. //数据为空
  262. if (img_58.attr('num')==0) {
  263. img_58.attr('src',img_58.attr('alt')).show();
  264. img_58.attr('num','1');
  265. }else{
  266. img_58.show();
  267. }
  268. break;
  269. }
  270. if (num<=5) {
  271. s_div.show();
  272. }else if(num==6){
  273. prize_div.show();
  274. }else if(num>6&&num<9){
  275. share_div.show();
  276. }else{
  277. null_div.show();
  278. }
  279. $("#main-mask").show();
  280. }
  281. /**
  282. * [messageBox_close description] 关闭弹出框
  283. * @return {[type]} [description]
  284. */
  285. function messageBox_close () {
  286. // body...
  287. $("#main-mask,.img_50,.img_52,.img_56,.img_55,.img_51,#img_51,#span_51,.s_div,#down_href,.prize_div,.share_div,.img_53,.img_54,.img_57,.img_58,.share_div").hide();
  288. }
  289. /**
  290. * [bg_color_yellow description] 首页背景色
  291. * @return {[type]} [description]
  292. */
  293. function bg_color_yellow () {
  294. $("body").css('background',"#fff71a");
  295. }
  296. /**
  297. * [bg_color_green description] 攻略色
  298. * @return {[type]} [description]
  299. */
  300. function bg_color_green () {
  301. $("body").css('background',"#cce099");
  302. }
  303. /**
  304. * [bg_color_orange description] 游戏背景色
  305. * @return {[type]} [description]
  306. */
  307. function bg_color_orange (){
  308. $("body").css('background',"#E19825");
  309. }
  310. /**
  311. * [JQMethod description] 全局变量
  312. * @type {jqMethod}
  313. */
  314. var JQMethod = new jqMethod();
  315. jqMethod.prototype = JQMethod;
  316. window.JQMethod = JQMethod;
  317. /**
  318. * [user_reward description] 微信用户/用户获得的奖励字
  319. * @return {[type]} [description]
  320. */
  321. function user_reward () {
  322. $(".a_1,.a_2,.a_3,.a_4,.a_5,.a_6,.a_7,.a_8").removeClass('a_cloud').html('');
  323. function callback(method, url, data){
  324. var list = data;
  325. if (typeof data === "string") {
  326. list = JSON.parse(data);
  327. }
  328. if (list.status == 0) {
  329. var rewards = list.gameUserReward.rewards;
  330. if (!jQuery.isEmptyObject(rewards)) {
  331. window.reward_id_3=[],window.reward_id_4=[];
  332. for(var i in rewards){
  333. gameDebris(parseInt(i),parseInt(rewards[i]));
  334. }
  335. }else{
  336. $(".a_1,.a_2,.a_3,.a_4,.a_5,.a_6,.a_7,.a_8").removeClass('a_cloud').html('');
  337. }
  338. }else {
  339. L.alert('无法连接到网络,请检查网络设置后再试');
  340. }
  341. }
  342. if (gamef.platType == PLAT_BJY) {
  343. var url = "webgame/reward";
  344. gamef.requestServerData(url, "GET", callback, "type=" + gamef.gameid);
  345. }
  346. else if (gamef.platType == PLAT_WX) {
  347. var url = WXDOMAIN+"wxgame/wxreward";
  348. gamef.requestServerData(url, "GET", callback, "type=" + gamef.gameid + "&open_id=" + gamef.open_id);
  349. }
  350. }
  351. function gameDebris(num,count){
  352. switch(num){
  353. case 1:
  354. $(".a_1").addClass('a_cloud').html(count);
  355. window.reward_id_3.push(count);
  356. break;
  357. case 2:
  358. $(".a_2").addClass('a_cloud').html(count);
  359. window.reward_id_3.push(count);
  360. break;
  361. case 3:
  362. $(".a_3").addClass('a_cloud').html(count);
  363. window.reward_id_3.push(count);
  364. break;
  365. case 4:
  366. $(".a_4").addClass('a_cloud').html(count);
  367. window.reward_id_3.push(count);
  368. break;
  369. case 5:
  370. $(".a_5").addClass('a_cloud').html(count);
  371. window.reward_id_4.push(count);
  372. break;
  373. case 6:
  374. $(".a_6").addClass('a_cloud').html(count);
  375. window.reward_id_4.push(count);
  376. break;
  377. case 7:
  378. $(".a_7").addClass('a_cloud').html(count);
  379. window.reward_id_4.push(count);
  380. break;
  381. case 8:
  382. $(".a_8").addClass('a_cloud').html(count);
  383. window.reward_id_4.push(count);
  384. break;
  385. }
  386. }
  387. /**
  388. * [game_exChange description] 用户申请兑换奖品
  389. * @param {[type]} num [description]
  390. * 3:掌上大学
  391. * 4:圣诞快乐
  392. * @return {[type]} [description]
  393. */
  394. function game_exChange (num) {
  395. if (gamef.platType == PLAT_BJY) {
  396. var url = 'webgame/exchange';
  397. // alert(url);
  398. function callback(method, url, data){
  399. // alert(data+"==="+JSON.stringify(data));
  400. if (data == '401') {
  401. L.alert('先登陆在兑换!');
  402. return;
  403. }else if (data == '403') {
  404. L.alert('先绑定手机账号在领奖!');
  405. return;
  406. }else if (data == '-1'){
  407. L.alert('操作失败请重新操作!');
  408. return;
  409. }
  410. var list = data;
  411. if (typeof data === "string") {
  412. list = JSON.parse(data);
  413. }
  414. if (list.status == 0) {
  415. var gameTicketInfo = list.gameTicketInfo;
  416. $("#img_51").html(gameTicketInfo.text1);
  417. var time = new Date(gameTicketInfo.valid);
  418. var FullYear = time.getFullYear();
  419. var Month = time.getMonth()+1;
  420. var day = time.getDate();
  421. $("#span_51").html(FullYear+"-"+Month+"-"+day);
  422. //重新请求
  423. user_reward ();
  424. messageBox_show(3);
  425. }else if(list.status == 2021){
  426. messageBox_show(2);
  427. }else if(list.status == 2022){
  428. messageBox_show(2);
  429. }else if (list.status == 403){
  430. L.alert('先绑定手机账号在领奖!');
  431. }else {
  432. L.alert('无法连接到网络,请检查网络设置后再试');
  433. }
  434. }
  435. gamef.requestServerData(url, "POST", callback, "type=" + gamef.gameid+"&reward_id="+num);
  436. }else if (gamef.platType == PLAT_WX) {
  437. messageBox_show(6);
  438. window.sum_num = num;
  439. };
  440. }
  441. /**
  442. * [unBindClick description] 取消分享click事件
  443. * @return {[type]} [description]
  444. */
  445. function unBindClick () {
  446. $(".btn_a_share").unbind('click');
  447. }
  448. /**
  449. * [click_share description]分享click事件
  450. * @return {[type]} [description]
  451. */
  452. function click_share(){
  453. $(".btn_a_share").unbind('click').bind('click', function(event) {
  454. JQMethod.messageBox_close();
  455. gamef.share();
  456. event.stopPropagation();
  457. });
  458. }
  459. })(window);