247e587ed63aaf9b441c81d03fd3750567af0b57.svn-base 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. var userId=$.urlParam("userId");
  2. var cname=$.urlParam("cName");
  3. var userType=$.urlParam("userType");
  4. var mySwiper;
  5. $(function () {
  6. if(isNull(userId)){
  7. myLayer.alert('获取不到用户UserId','2000');
  8. }else{
  9. myLayer.load("加载中,请稍后");
  10. initSubscribePage();
  11. }
  12. });
  13. function initSubscribe(){
  14. var url= jkzl.common.path+"/subscribe/querySubscribe";
  15. var param = {};
  16. param.userId=userId;
  17. sendPost(url,param, "json", "post", initSubscribeFailed, initSubscribeSuccesss);
  18. }
  19. //失败
  20. function initSubscribeFailed(res) {
  21. myLayer.clear();
  22. if (res && res.Message) {
  23. myLayer.alert(res.Message);
  24. return;
  25. } else {
  26. myLayer.alert("请求失败,请重新刷新页面");
  27. return;
  28. }
  29. }
  30. function initSubscribeSuccesss(res) {
  31. if (res.Code == 10000) {
  32. if(res.Result.result){
  33. var result=res.Result.result;
  34. var htmlstr ="<div class='swiper-slide'><ul class='inter-ul clearfix'>";
  35. var j=1;
  36. for(var i=0;i<result.length;i++){
  37. if((j == 18) && (i!=result.length-1)){
  38. j=1;
  39. htmlstr +="<li value="+result[i].categoryid+">"+result[i].categoryname+"</li></ul></div><div class='swiper-slide'><ul class='inter-ul clearfix'>";
  40. }else{
  41. htmlstr +="<li value="+result[i].categoryid+">"+result[i].categoryname+"</li>";
  42. j++;
  43. }
  44. }
  45. htmlstr +="</ul></div>";
  46. $("#subscribe_content").append(htmlstr);
  47. }
  48. myLayer.clear();
  49. } else {
  50. initSubscribeFailed(res);
  51. }
  52. }
  53. function initSubscribePage(){
  54. mySwiper = new Swiper ('.swiper-container', {
  55. loop: true,
  56. pagination: '.swiper-pagination',
  57. onInit:initSubscribe(),
  58. observer:true
  59. });
  60. }
  61. $('.c-main').on('click','.inter-ul li',function(){
  62. $(this).toggleClass('curr');
  63. var checked = $('.inter-ul').find('li').hasClass('curr');
  64. if(checked){
  65. $('.inter-btn').removeClass('disable').html('选好了!');
  66. }else{
  67. $('.inter-btn').addClass('disable').html('请选择');
  68. }
  69. });
  70. $('.c-main').on('click','.inter-btn',function(){
  71. var disable = $('.inter-btn').hasClass('disable');
  72. if(disable){
  73. myLayer.alert('请至少选择一个感兴趣的分类','2000');
  74. return;
  75. }else{
  76. var li = $(".inter-ul").find(".curr");
  77. if(li.length>0){
  78. var categoryIds="";
  79. var categoryNames="";
  80. li.each(function (i) {
  81. categoryIds +=li.eq(i).attr("value")+",";
  82. categoryNames +=li.eq(i).text()+",";
  83. });
  84. categoryIds =categoryIds.substring(0,categoryIds.length-1);
  85. categoryNames=categoryNames.substring(0,categoryNames.length-1);
  86. var url= jkzl.common.path+"/subscribe/saveSubscribe";
  87. var param = {};
  88. param.userId=userId;
  89. param.cname=cname;
  90. param.categoryIds=categoryIds;
  91. param.categoryNames=categoryNames;
  92. myLayer.load("保存中,请稍后");
  93. sendPost(url,param, "json", "post", saveSubscribeFailed, saveSubscribeSuccesss);
  94. }else{
  95. myLayer.alert('请至少选择一个感兴趣的分类','2000');
  96. return;
  97. }
  98. }
  99. });
  100. function saveSubscribeFailed(res) {
  101. myLayer.clear();
  102. if (res && res.Message) {
  103. myLayer.alert(res.Message);
  104. return;
  105. } else {
  106. myLayer.alert("请求失败,请重新刷新页面");
  107. return;
  108. }
  109. }
  110. function saveSubscribeSuccesss(res) {
  111. if (res.Code == 10000) {
  112. myLayer.clear();
  113. window.location.href='articleList.html?userId='+userId+"&cName="+cname+"&userType="+userType;
  114. } else {
  115. operateFailed(res);
  116. }
  117. }