index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. function Index(){
  2. Common.call(this)
  3. }
  4. Index.prototype = new Common()
  5. Index.prototype.constructor = Index
  6. // 渲染默认的看点
  7. Index.prototype.renderCount = function(obj){
  8. var count = parseInt(obj.type)
  9. $('.count_item').removeClass('count_item_active').eq(count).addClass('count_item_active')
  10. }
  11. // 报名的接口处理
  12. Index.prototype.encroll = function(obj){
  13. var that = this
  14. $.ajax({
  15. type: 'get',
  16. url: '/api/campaign/checkIn',
  17. data: obj,
  18. success: function(data){
  19. console.log(obj)
  20. if(data.code == 0){
  21. // $('.clock_enter_success').show()
  22. // that.logClick({
  23. // module: 'read_change_index',
  24. // zone: 'baomingsuccess',
  25. // json: {
  26. // amount: obj.amount,
  27. // date: date
  28. // }
  29. // })
  30. }else{
  31. window.bookSotre.bookStoreClick('', '18', '', data.msg);
  32. }
  33. },
  34. error: function(){
  35. window.bookSotre.bookStoreClick('', '18', '', '请求失败');
  36. }
  37. })
  38. }
  39. // 所有的点击事件
  40. Index.prototype.triggerClick = function(){
  41. var that = this
  42. // 公用的点击事件
  43. that.handleClick()
  44. var data = {};
  45. // var clickKandian = $('.count_item_active div .kandian');
  46. // 点击切换看点
  47. $('body').on('click', '.count_item', function(){
  48. topCardShow($(this).index());
  49. if(!$(this).hasClass('count_item_active')){
  50. that.renderCount({
  51. type: $(this).index()
  52. })
  53. }
  54. })
  55. // 点击立即报名
  56. $('.now_btn_index').click(function(){
  57. var data = {};
  58. data.userKandian = $('.userKandian').val();
  59. data.cotegoryId = $('.userKandian').attr('good_cotegory');
  60. data.activeId = $(".count_item_active div .kandian").attr('data-id');
  61. data.matchDate = $(".count_item_active div .kandian").attr('data-date');
  62. data.matchId = $(".count_item_active div .kandian").attr('data-match');
  63. data.kandian = $(".count_item_active div .kandian").text();
  64. data.activeName = $(".userKandian").attr('active-name');
  65. data.readNumber = $('.userKandian').attr('read_number');
  66. if(data.userKandian < data.amount){
  67. // 余额不足
  68. $('.amount_null').show();
  69. return;
  70. }
  71. // toastSuccess(data);exit;
  72. console.log(data);
  73. $.ajax({
  74. type: 'post',
  75. url: '/api/campaign/checkIn',
  76. data: data,
  77. success: function(res){
  78. if(res.data.code == 200){
  79. toastSuccess(res.data.return);
  80. }else{
  81. alert(res.data.msg)
  82. }
  83. },
  84. error: function(err){
  85. alert("网络出错")
  86. }
  87. })
  88. })
  89. // 查看详细规则
  90. $('.enter_btn').click(function(){
  91. $('.charge_rule_pop').show()
  92. })
  93. $('.pop_close_index').click(function(){
  94. if($(this).parents('.clock_enter_success').length > 0){
  95. $(this).parents('.clock_enter_success').hide()
  96. window.location.reload()
  97. }
  98. })
  99. //挑战成功查看规则
  100. $('.clock_enter_success_rule_btn').click(function(){
  101. if($(this).parents('.clock_enter_success').length > 0){
  102. $(this).parents('.clock_enter_success').hide()
  103. }
  104. $('.charge_rule_pop').show();
  105. $('.pop_close').unbind();
  106. $('.pop_close').click(function(){
  107. $(this).parents('.common_pop').hide();
  108. window.location.reload()
  109. })
  110. })
  111. // 关闭余额不足
  112. $('.amount_null_close').click(function(){
  113. $('.amount_null').hide()
  114. })
  115. //报名成功跳转阅读
  116. $('body').on('click', '.clocl_enter_success_see_book', function(){
  117. var url = String($("#web_status").attr('channel-url'));
  118. window.location.href=url+"/index/user/recent?from=wechat";
  119. })
  120. }
  121. Index.prototype.init = function(){
  122. var level = $(".userKandian").attr('level');
  123. topCardShow(level);
  124. this.transitionFun()
  125. this.triggerClick()
  126. // this.renderPageCount()
  127. }
  128. var indexObj = new Index()
  129. function topCardShow( index ) {
  130. var kandian = [];
  131. kandian[0] = $('.kandian').eq(0).text();
  132. kandian[1] = $('.kandian').eq(1).text();
  133. kandian[2] = $('.kandian').eq(2).text();
  134. var userKandian = $('.userKandian').val();
  135. for (var i=0; i<3; i++){
  136. var cardId = "#top_card"+kandian[i];
  137. var participatorNum = "#participator_num"+kandian[i];
  138. if ( i != index ){
  139. $(cardId).hide();
  140. $(participatorNum).hide();
  141. $('.count_item').eq(i).removeClass('count_item_active');
  142. continue;
  143. }
  144. $(cardId).show();
  145. $(participatorNum).show();
  146. $('.count_item').eq(i).addClass('count_item_active');
  147. if ( kandian[i] - userKandian > 0 ){
  148. var money = $('.kandian').eq(i).attr('data-money');
  149. $('.now_btn_index').hide();
  150. $('.now_btn_chongzhi').text("仅需充值"+money+"元,即可参与活动");
  151. $('.now_btn_chongzhi').show();
  152. }else{
  153. $('.now_btn_index').show();
  154. $('.now_btn_chongzhi').hide();
  155. }
  156. }
  157. }
  158. function taskCallback(type){
  159. if(type == 1){
  160. indexObj.logClick({
  161. module: 'read_change_index',
  162. zone: 'chongzhisuccess',
  163. json: {
  164. date: date
  165. }
  166. })
  167. window.location.reload()
  168. }
  169. }
  170. function toastSuccess( res ){
  171. // console.log(res);
  172. $('.enter_title').text(res.kandian);
  173. $('.enter_tip').text("成功加入"+res.kandian+"书币挑战");
  174. $('.enter_which span').text(res.matchDate);
  175. $('.enter_tip_text').text("记得每日阅读"+res.readNumber+"章后,准时打卡哦~");
  176. $('.clock_enter_success').show();
  177. // window.location.reload()
  178. }
  179. // cpslog([703, {
  180. // map: {
  181. // cztype: 'wechat',
  182. // package: 1222,
  183. // result: 1,
  184. // book_id: 0,
  185. // chapter_id: 0,
  186. // money: 20,
  187. // res: {}
  188. // }
  189. // }, 'campagin_index']);
  190. indexObj.init()