freeCollection.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. function PageInit(url,session_id,bridge) {
  2. this.url = url;
  3. this.goodsItems = $('.goods-list .goods-item');
  4. this.refreshBtn = $('.refresh-btn');
  5. this.detailPopup = $('.detail-popup');
  6. this.eggsBtn = $('.eggs-btn');
  7. this.close = $('.close');
  8. this.goodsList = [];
  9. this.session_id = session_id;
  10. this.bridge = bridge;
  11. var self = this;
  12. this.goodsItems.on('click', function () {
  13. self.result($(this));
  14. });
  15. this.refreshBtn.on('click', function () {
  16. self.hidePopup();
  17. self.refresh();
  18. });
  19. this.detailPopup.on('touchmove', function (e) {
  20. e.preventDefault();
  21. });
  22. this.eggsBtn.on('click', function () {
  23. $('.mysterious-popup, .mysterious').fadeIn();
  24. });
  25. this.close.on('click', function () {
  26. $('.mysterious-popup, .mysterious').fadeOut();
  27. });
  28. $('.mysterious-popup, .mysterious').on('touchmove', function (e) {
  29. e.preventDefault();
  30. });
  31. }
  32. PageInit.prototype = {
  33. init: function () {
  34. this.getDatas();
  35. },
  36. getDatas: function () {
  37. var self = this;
  38. $.ajax({
  39. type: "get",
  40. url: self.url,
  41. data: {
  42. act: "festval",
  43. op: "ajax_freeCollection",
  44. client_type: "ajax"
  45. },
  46. success: function (res) {
  47. var res = JSON.parse(res)
  48. if (res.code == 200) {
  49. self.goodsList = res.datas.goods_list
  50. self.render();
  51. }
  52. else {
  53. alert(res.message);
  54. }
  55. },
  56. error: function () {
  57. alert('网络错误!');
  58. }
  59. });
  60. $.ajax({
  61. type: "get",
  62. url: self.url,
  63. data: {
  64. act: "member_bonus",
  65. op: "mine_bonus",
  66. client_type: "ajax"
  67. },
  68. success: function (res) {
  69. var res = JSON.parse(res);
  70. if (res.code == 200) {
  71. var usable_bonus = res.datas.usable_bonus;
  72. $('.bonus-price').html('¥ ' + usable_bonus);
  73. }
  74. }
  75. });
  76. },
  77. render: function() {
  78. if (!this.goodsList.length)return;
  79. var self = this;
  80. this.goodsItems.each(function(index, item) {
  81. var goods = self.goodsList[index];
  82. $(item).find('.bonus').html(goods.need_bonus);
  83. $(item).find('.goods-storage').html(goods.storage);
  84. $(item).attr('data-id', goods.goods);
  85. $(item).attr('data-state', goods.state);
  86. if (goods.state == 1) {
  87. $(item).addClass('over');
  88. }
  89. else if (goods.state == 2) {
  90. $(item).addClass('receive');
  91. }
  92. else if (goods.state == 3) {
  93. $(item).addClass('invite');
  94. }
  95. else if (goods.state == 4) {
  96. $(item).addClass('isReceived');
  97. }
  98. });
  99. },
  100. result: function (target) {
  101. if (!this.goodsList.length)return;
  102. var self = this;
  103. var state = target.attr('data-state');
  104. if (state == 2) {
  105. var id = target.attr('data-id');
  106. window.location.href = 'xmmz://p.lrlz.com/goods/goods?goodsId=' + id;
  107. setTimeout(function() {
  108. self.showPopup();
  109. }, 10);
  110. return;
  111. }
  112. else if (state == 3) {
  113. window.location.href = 'xmmz://p.lrlz.com/invite/invite';
  114. return;
  115. }
  116. },
  117. showPopup: function () {
  118. $('.detail-popup, .refresh-btn').fadeIn();
  119. },
  120. hidePopup: function () {
  121. $('.detail-popup, .refresh-btn').fadeOut('fast');
  122. },
  123. refresh: function() {
  124. this.init();
  125. }
  126. }