freeCollection.js 3.3 KB

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