index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. var ajaxData = {time:0,city:0}
  2. // 自定义下拉
  3. $(".dropdiv").click(function(e){
  4. var parentDiv = $(this).parent();
  5. if(parentDiv.hasClass('on')){
  6. parentDiv.removeClass('on');
  7. }else{
  8. parentDiv.addClass('on');
  9. }
  10. $(".chooseItems").slideUp(300);
  11. e.stopPropagation();
  12. var quest = $(this).parent();
  13. var questwidth = parseInt(quest.width())-2;
  14. var questheight = quest.height();
  15. var left = quest.position().left+parseInt(quest.css("margin-left"))+parseInt(quest.css("padding-left"));
  16. var top = parseInt(quest.position().top)+parseInt(questheight)+24;
  17. var attrs = quest.attr("quest");
  18. var selectsd = $('.chooseItems[answer='+attrs+']');
  19. var selectsdHeight = selectsd.height();
  20. if((top+selectsdHeight)>$(window).height()){
  21. top = top - selectsdHeight - questheight-7;
  22. }
  23. if($(selectsd).is(":visible")){
  24. $(selectsd).slideUp(300);
  25. }else{
  26. $(selectsd).css({"left":left+"px","top":top+"px","width":questwidth+"px"}).slideDown(300);
  27. }
  28. });
  29. $(".chooseItem").click(function(e){
  30. var parentDiv = $('.dropmiandiv');
  31. if(parentDiv.hasClass('on')){
  32. parentDiv.removeClass('on');
  33. }else{
  34. parentDiv.addClass('on');
  35. }
  36. var otype = $(this).attr('type');
  37. var oid = $(this).attr('displayMember');
  38. ajaxData[otype] = oid;
  39. information() //调数据
  40. e.stopPropagation();
  41. var divhtml = $(this);
  42. var displayMember,valueMember;
  43. displayMember = divhtml.attr("displayMember");
  44. valueMember = divhtml.attr("valueMember");
  45. var attrs =$(this).parent().attr("answer");
  46. var parent = $("#"+attrs);
  47. var olddisplayMember,oldvalueMember;
  48. olddisplayMember = parent.attr("displayMember");
  49. oldvalueMember = parent.attr("valueMember");
  50. if(olddisplayMember !=displayMember){
  51. parent.attr("displayMember",displayMember);
  52. parent.attr("valueMember",valueMember);
  53. parent.val(valueMember);
  54. parent.change();
  55. }
  56. $(this).parent().slideUp(300);
  57. });
  58. // 点击元素以外隐藏下拉
  59. $(document).click(function(e){
  60. var target = $(e.target);
  61. if(target.closest(".chooseItems").length == 0){
  62. $(".chooseItems").slideUp(300);
  63. }
  64. $('.dropmiandiv').removeClass('on'); // 删除
  65. });
  66. information(); //默认执行一次
  67. function information(){
  68. $.ajax({
  69. type: 'post',
  70. url: '/zt/specialdata',
  71. data:ajaxData,
  72. dataType: 'json',
  73. success: function(data){
  74. if(data.code == "200"){
  75. var _html = "";
  76. $.each(data.data,function(k,v){
  77. _html += '<li>';
  78. _html += '<div class="delegation-img">';
  79. if(v.is_push==2){
  80. _html += '<b>热门</b>';
  81. }
  82. _html += '<img src="'+v.img+'" alt="">';
  83. // _html += '<div class="delegation-font"><span>'+v.title+'</span></div>';
  84. _html += '</div>';
  85. _html += '<div class="delegation-tier"><a data-id="'+v.city+'" href="'+v.url+'">查看详情</a></div>';
  86. _html += '</li>';
  87. })
  88. _html +='<li>';
  89. _html +='<div class="delegation-img">';
  90. _html +='<img src="/zt/kaocatuan20190126/image/lpb.png" alt="">';
  91. _html +='<div class="tion-font">更多精彩<br/>敬请期待</div>';
  92. _html +='</div>';
  93. _html +='</li>';
  94. $('.delegation-box ul').html("");
  95. $('.delegation-box ul').html(_html);
  96. }
  97. }
  98. });
  99. }
  100. // 列表中查看详情 点击按钮
  101. $('.delegation-box ul').on('click','.delegation-tier a',function(){
  102. var that = $(this);
  103. var eid = that.attr('data-id');
  104. ajaxData.time = 0;
  105. ajaxData.city = eid;
  106. information(); //点击列表再次调用
  107. })