mcsy.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. var iscroll,mciscroll,swiper;
  2. $(function () {
  3. /**
  4. * 初始化滚动条
  5. * */
  6. iscroll = new IScroll(".iscroll",{
  7. scrollbars: true,
  8. fadeScrollbars:true,
  9. scrollbars: 'custom',
  10. shrinkScrollbars:'clip',
  11. click:true
  12. });
  13. setTimeout(function(){
  14. iscroll.refresh();
  15. },100);
  16. /**
  17. * 选择的牧场名称滚动条
  18. * */
  19. var mcsize = $("#size").attr("value");
  20. if(mcsize>1){
  21. mciscroll = new IScroll(".mcIscroll",{
  22. scrollbars: true,
  23. fadeScrollbars:true,
  24. scrollbars: 'custom',
  25. shrinkScrollbars:'clip'
  26. });
  27. $(".middle button").on("tap",function(){
  28. setTimeout(function(){
  29. mciscroll.refresh();
  30. },100);
  31. });
  32. }
  33. /**
  34. * 轮播图
  35. * */
  36. swiper = new Swiper('.swiper-container',{
  37. pagination:'.swiper-pagination',
  38. prevButton:'.swiper-button-prev',//点击箭头
  39. nextButton:'.swiper-button-next',//点击箭头
  40. paginationClickable: true,//点击分页器
  41. touchMoveStopPropagation : false,
  42. followFinger: false,
  43. autoplay : 3000,//每3秒自动轮播
  44. autoplayDisableOnInteraction : false,
  45. loop : true,//环路
  46. //ajax动态循环生成当到第二页的时候始终滑动不起来的方法
  47. //分页器消失解决方法
  48. observer:true,//修改swiper自己或子元素时,自动初始化swiper
  49. observeParents:true,//修改swiper的父元素时,自动初始化swiper
  50. onSlideChangeEnd: function(swiper){
  51. swiper.update(); //swiper滑动的时候滑动到第3屏就滑动不了的解决办法
  52. }
  53. });
  54. /**
  55. * 每点击li初始化滚动条
  56. */
  57. $('#selectUl div').on("tap",function(){
  58. iscroll.refresh();
  59. });
  60. /**
  61. * 列表切换
  62. * */
  63. $(".sectionBtm .nav-pills li").click(function(){
  64. $(this).addClass("liborderBottom").siblings().removeClass("liborderBottom");
  65. $(this).children().addClass("liborderBottomColor").parent().siblings().children().removeClass("liborderBottomColor");
  66. $(".sectionBtm div ul").hide().eq($('.sectionBtm .nav-pills li').index(this)).show();
  67. if($('.sectionBtm .nav-pills li').index(this)==0){
  68. takeMcgk(0,iscroll);
  69. }else if($('.sectionBtm .nav-pills li').index(this)==1){
  70. takeMcgk(1,iscroll);
  71. }else if($('.sectionBtm .nav-pills li').index(this)==2){
  72. takeMcgk(2,iscroll);
  73. }
  74. iscroll.scrollTo(0, 0);
  75. iscroll.refresh();
  76. });
  77. //默认初始进入显示预警提示
  78. takeMcgk(1,iscroll);
  79. });
  80. /**
  81. * footer图标
  82. * */
  83. function pig(e) {
  84. $('.syfo .nav li').eq(0).find('span').css({'background-image':'url(views/haifmv/img/bai.png)'});
  85. $('.syfo .nav li').eq(1).find('span').css({'background-image':'url(views/haifmv/img/bai.png)'});
  86. $('.syfo .nav li').eq(2).find('span').css({'background-image':'url(views/haifmv/img/bai.png)'});
  87. $(".cbkz").css({'background-image':'url(views/haifmv/img/cbkz_an.jpg)'});
  88. $(".scxx").css({'background-image':'url(views/haifmv/img/scxx_an.jpg)'});
  89. $('.syfo .nav li a').eq(0).removeClass('textColor');
  90. $('.syfo .nav li a').eq(1).removeClass('textColor');
  91. $('.syfo .nav li a').eq(2).removeClass('textColor');
  92. $('.syfo .nav li a').eq(3).removeClass('textColor');
  93. $('.syfo .nav li a').eq(4).removeClass('textColor');
  94. switch(e) {
  95. case 0://牧场首页
  96. $(".mcsy").css({'background-image':'url(views/haifmv/img/ding.png)'});
  97. $(".mcsy").next().addClass('textColor');
  98. break;
  99. case 1:
  100. $(".sjlr").css({'background-image':'url(views/haifmv/img/ding.png)'});
  101. $(".sjlr").next().addClass('textColor');
  102. break;
  103. case 2:
  104. $(".jrmc").css({'background-image':'url(views/haifmv/img/ding.png)'});
  105. $(".jrmc").next().addClass('textColor');
  106. break;
  107. case 3:
  108. $(".cbkz").css({'background-image':'url(views/haifmv/img/cbkz_liang.jpg)'});
  109. $(".cbkz").next().addClass('textColor');
  110. break;
  111. case 4:
  112. $(".scxx").css({'background-image':'url(views/haifmv/img/scxx_liang.jpg)'});
  113. $(".scxx").next().addClass('textColor');
  114. break;
  115. }
  116. };
  117. //异步加载消息通知 默认打开牧场概况
  118. function takeMcgk(type,iscroll) {
  119. var li,curIndex;
  120. var jsonLength = 0;
  121. var val = 0;
  122. var url = "";
  123. curIndex = $(".liborderBottom").index();
  124. if (type == 0) {
  125. url = "syMcgk.htm";
  126. }else if(type == 1){
  127. url = "syYjts.htm";
  128. }
  129. else if(type == 2){
  130. url = "syScxx.htm";
  131. }
  132. $(".refinsh").show();
  133. jQuery.ajax({
  134. type : "get",
  135. url : url,
  136. data : {"mcid" : $("#mcid").val(),
  137. "type" : type,
  138. },
  139. dataType : "json",
  140. async : true,
  141. success : function(data) {
  142. //获得data长度
  143. for (var j in data) {
  144. jsonLength++;
  145. }
  146. setTimeout(function() {
  147. $(".refinsh").hide();
  148. $(".iscroll ul li").remove();
  149. if (jsonLength > 6) {
  150. jsonLength = 6;
  151. val = 7;
  152. }
  153. for (var i = 0 ; i < jsonLength ; i++) {
  154. li = document.createElement("li");
  155. if(curIndex == 0){
  156. li = $("<li id='"+data[i].id+"' style='justify-content:flex-start !important;text-align: left;padding-left:0.5rem;padding-right:0.5rem;' onclick = viewXxtsxx('"+data[i].id+"','sy')>" + data[i].title +"</li>");
  157. }else if(curIndex == 1){
  158. li = $("<li id='"+data[i].id+"' style='justify-content:flex-start !important;text-align: left;padding-left:0.5rem;padding-right:0.5rem;' onclick = viewXxtsxx('"+data[i].id+"','sy')>" + data[i].title +"</li>");
  159. }else if(curIndex == 2){
  160. li = $("<li id='"+data[i].id+"' style='justify-content:flex-start !important;text-align: left;padding-left:0.5rem;padding-right:0.5rem;' onclick = viewXxtsxx('"+data[i].id+"','sy')>" + data[i].title +"</li>");
  161. }
  162. $(".sectionBtm div ul").eq($(".liborderBottom").index()).append(li);
  163. }
  164. if (jsonLength==0 && curIndex == 0) {
  165. li = $("<li>暂无数据</li>");
  166. } else if (jsonLength==0 && curIndex == 1){
  167. li = $("<li>暂无数据</li>");
  168. } else if (jsonLength==0 && curIndex == 2){
  169. li = $("<li>暂无数据</li>");
  170. }
  171. if (val == 7 || jsonLength >0 ) {
  172. //var wdCount = data[6].context;
  173. var text = "点击查看详细信息";
  174. if (curIndex == 0) {
  175. li = $("<li onclick= viewXxlist('mcgk')>" + text +"</li>");
  176. } else if (curIndex == 1) {
  177. li = $("<li onclick= viewXxlist('sbxx')>" + text +"</li>");
  178. } else if (curIndex == 2) {
  179. li = $("<li onclick= viewXxlist('scxx')>" + text +"</li>");
  180. }
  181. }
  182. $(".sectionBtm div ul").eq($(".liborderBottom").index()).append(li);
  183. iscroll.refresh();
  184. },200);
  185. }
  186. });
  187. }
  188. /*//异步加载 更新未读信息
  189. function updateWdCount() {
  190. jQuery.ajax({
  191. type : "get",
  192. url : "updateWdCount.htm",
  193. data : {"mcid" : $("#mcid").val()},
  194. dataType : "json",
  195. success : function(data) {
  196. if (data[0] != 0) {
  197. $("#countMcgk").html(data[0]);
  198. }
  199. if (data[1] != 0) {
  200. $("#countMcgk").html(data[1]);
  201. }
  202. if (data[2] != 0) {
  203. $("#countMcgk").html(data[2]);
  204. }
  205. }
  206. });
  207. }*/
  208. function viewXxtsxx(id, from) {
  209. haifm.loadMobilePage("haifm", "viewHaifmvGtxxtsxx.htm?xxid=" + id + "&from=" + from );
  210. //window.location.href = "viewHaifmvGtxxtsxx.htm?xxid=" + id + "&from=" + from;
  211. }
  212. function viewXxlist(from) {
  213. haifm.loadMobilePage("haifm", "viewHaifmvXxlist.htm?from=" + from +"&mcid=" + $("#mcid").val());
  214. }