gzdaIndex.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. $(function () {
  2. var zsIscrollHeight = $(".gzdaIscroll");
  3. var cententHeight = $(".gzdaIscroll div:first-child");
  4. heightvs(zsIscrollHeight,cententHeight);
  5. //初始化page
  6. if(localStorage.hasOwnProperty("gzIndexPage")) {
  7. $("#page").val(localStorage.getItem("gzIndexPage"));
  8. }
  9. //清除span为空的padding值
  10. $(".row div.col-xs-2.col-sm-2.col-md-2 span").each(function(){
  11. if($(this).html() === ""){
  12. $(this).css("padding","0");
  13. }
  14. });
  15. var mask = mui.createMask();//callback为用户点击蒙版时自动执行的回调;
  16. $(".xqck").on("tap", function() {
  17. var id = $(this).data("for");
  18. if (id != "") {
  19. haifm.loadMobilePage("haifm", "hvSjlrGzxx.htm?mcid=" + $("#mcid").val() + "&id=" + id + "&ztsl=" + $("#ztsl").val() + "&cxeph=" + $("#dweb").val());
  20. //haifm.loadMobilePage("haifm", "hvSjlrGzdaAdd.htm?mcid=" + $("#mcid").val() + "&dweb=" +$(this).data("dweb") + "&edit=" + "edit");
  21. }
  22. });
  23. //动物耳标查询、模糊查询键盘enter键事件
  24. $("input[type='search']").on('keypress',function(e) {
  25. var keycode = e.keyCode;
  26. if(keycode=='13') {
  27. e.preventDefault();
  28. //请求搜索接口
  29. haifm.loadMobilePage("haifm", "hvSjlrDaIndex.htm?mcid=" + $("#mcid").val() + "&cxeph=" + $("#dweb").val());
  30. clear();
  31. }
  32. });
  33. /* 单选和多选 复选框事件*/
  34. $(".mui-icon-checkmarkempty").bind("click", function () {
  35. var result1 = new Array();
  36. var resultId1 = new Array();
  37. var result2 = new Array();
  38. var resultId2 = new Array();
  39. resultId1.push(",");
  40. resultId2.push(",");
  41. //当前状态
  42. $("[name = dqztCheck]:checkbox").each(function () {
  43. if ($(this).is(":checked")) {
  44. result1.push($(this).parent().next().text());
  45. resultId1.push($(this).attr("data-for"));
  46. }
  47. });
  48. //舍栏
  49. $("[name = slCheck]:checkbox").each(function () {
  50. if ($(this).is(":checked")) {
  51. result2.push($(this).parent().next().text());
  52. resultId2.push($(this).attr("data-for"));
  53. }
  54. });
  55. var dqzt = "0";
  56. var sl = "0";
  57. if (result2.length > 0) {
  58. sl = "1";
  59. }
  60. if(result1.length > 0) {
  61. dqzt = "1";
  62. }
  63. haifm.loadMobilePage("haifm", "hvSjlrDaIndex.htm?mcid=" + $("#mcid").val() + "&dqzt=" + dqzt + "&dqztArray="+resultId1 + "&sl=" + sl + "&slArray=" + resultId2);
  64. clear();
  65. mask.close();//关闭遮罩
  66. });
  67. /**
  68. * 初始化滚动条
  69. * */
  70. var iscroll;
  71. iscroll = new IScroll(".gzdaIscroll",{
  72. scrollbars: true,
  73. fadeScrollbars:true,
  74. scrollbars: 'custom',
  75. shrinkScrollbars:'clip',
  76. probeType: 2,
  77. click:true
  78. });
  79. setTimeout(function(){
  80. iscroll.refresh();
  81. }, 600);
  82. /**
  83. * 分页器
  84. * */
  85. var mySwiper = new Swiper('.swiper-container', {
  86. scrollbar:'.swiper-scrollbar',
  87. scrollbarHide:false,
  88. observer:true,
  89. prevButton:'.swiper-button-prev',
  90. nextButton:'.swiper-button-next',
  91. onSlidePrevEnd: function(){
  92. $(".tabText1").show();
  93. $(".tabText2").hide();
  94. },
  95. onSlideNextEnd: function(){
  96. $(".tabText1").hide();
  97. $(".tabText2").show();
  98. }
  99. });
  100. $(".btn-group").on("tap",function(){
  101. mask.show();//显示遮罩
  102. $(".md-modal").show();
  103. mySwiper.update();
  104. });
  105. mui('body').on('tap', '.mui-backdrop', function(e) {
  106. $(".md-modal").hide();
  107. });
  108. /*公猪母猪舍切换*/
  109. $('.change').on("tap",function(){
  110. if ($(this).index() == 0){
  111. $(this).addClass("changeBg1").siblings(".change").removeClass("changeBg2");//removeClass就是删除当前其他类;只有当前对象有addClass("changeBg1");siblings()意思就是当前对象的同级元素,removeClass就是删除;
  112. haifmp.loadMobilePage("haifm", "hvSjlrDaIndex.htm?mcid=" + $("#mcid").val());
  113. } else if ($(this).index() == 3){
  114. $(this).addClass("changeBg2").siblings(".change").removeClass("changeBg1");
  115. haifmp.loadMobilePage("haifm", "hvSjlrMzDaIndex.htm?mcid=" + $("#mcid").val());
  116. }
  117. });
  118. /**
  119. * 滚动input以外失去焦点
  120. * */
  121. iscroll.on('scrollStart',function(e){
  122. var el = document.activeElement;
  123. if (el.nodeName.toLowerCase() == 'input') {
  124. el.blur();
  125. this.disable();
  126. this.enable();
  127. };
  128. return;
  129. });
  130. /**
  131. * 点击input以外失去焦点
  132. * */
  133. var beforeIpt=null;
  134. $("input").on("focus", function (e) {
  135. beforeIpt=this;
  136. });
  137. $(document).on("tap", function (e) {
  138. if(e.target.nodeName.toLowerCase()!="input") {
  139. if(beforeIpt) {
  140. beforeIpt.blur();
  141. beforeIpt=null;
  142. }
  143. }
  144. });
  145. /* *
  146. * 下拉刷新上拉加载数据
  147. * */
  148. var pullUp = $("#pullUp"),
  149. pullUpLabel = $(".pullUpLabel"),
  150. loadingStep = 0;//加载状态0默认,1显示加载状态,2执行加载数据,只有当为0时才能再次加载,这是防止过快拉动刷新
  151. //滚动时触发
  152. iscroll.on("scroll",function(){
  153. if(loadingStep == 0 && !pullUp.attr("class").match('refresh')){
  154. if(this.y < (this.maxScrollY - 14)){//上拉加载更多
  155. pullUp.addClass("refresh").show();
  156. pullUp.css({"background":"","background-size":""});
  157. pullUpLabel.text("松手开始加载...");
  158. loadingStep = 1;
  159. iscroll.refresh();
  160. }
  161. }
  162. });
  163. //滚动结束触发
  164. iscroll.on("scrollEnd",function(){
  165. if(loadingStep == 1){
  166. if( pullUp.attr("class").match("refresh") ){//上拉加载操作
  167. pullUp.removeClass("refresh").addClass("loading");
  168. pullUpLabel.text("");
  169. pullUp.css({"background":"#D7DFEA url(views/haifmv/img/pullUp.gif) no-repeat center","background-size":"12%"});
  170. loadingStep = 2;
  171. pullUpAction();
  172. iscroll.refresh();
  173. }
  174. }
  175. //定位
  176. var thisy = parseInt(this.y);
  177. localStorage.setItem("gzIndexY",thisy);
  178. });
  179. /**
  180. * 上拉加载方法
  181. * */
  182. function pullUpAction(){
  183. var page = parseInt($("#page").val())+1;
  184. var maxPages = $("#maxPages").val();
  185. if (page <= maxPages) {
  186. jQuery.ajax({
  187. type : "get",
  188. url : "addSjlrGzda.htm",
  189. data : {
  190. "mcid" : $("#mcid").val(),
  191. "ztsl" : $("#ztsl").val(),
  192. "cxeph": $("#dweb").val(),
  193. page : page
  194. },
  195. dataType : "json",
  196. async : true,
  197. success : function(data) {
  198. setTimeout(function() {
  199. var hc = localStorage.getItem("gzIndex");
  200. var something = "";
  201. for (var i = 0 ; i < data.length; i++) {
  202. var obj = data[i];
  203. something += "<li class='mui-table-view-cell xqck' data-sl="+obj.sl+" data-dqzt="+obj.dqzt+" data-for="+obj.id+" data-dweb="+obj.dweb+" onClick='viewGzxq("+obj.id+")';>"
  204. + "<div class='rowBox container-fluid'>"
  205. + "<div class='row'>"
  206. + "<div class='col-xs-12 col-sm-12 col-md-12 discenter'>"
  207. + "<p>"+obj.eph+"</p></div></div><div class='row'>"
  208. + "<div class='col-xs-2 col-sm-2 col-md-2 discenter'>"
  209. + "<span>"+obj.pzStr+"</span>"
  210. + "</div>"
  211. + "<div class='col-xs-2 col-sm-2 col-md-2 discenter'>"
  212. + "<span>"+obj.dqztStr+"</span>"
  213. + "</div>"
  214. + "</div>"
  215. + "<span class='jrBtn'></span>"
  216. + "</div>"
  217. + "</li>";
  218. }
  219. $(".gzdaIscroll ul").append($(something));
  220. pullUp.attr("class","");
  221. pullUpLabel.text("上拉加载更多");
  222. pullUp.css({"background":""});
  223. iscroll.refresh();
  224. loadingStep = 0;
  225. localStorage.setItem("gzIndex",hc+something);
  226. },1000);
  227. $("#page").val(page);
  228. //page 计入缓存
  229. localStorage.setItem("gzIndexPage",page);
  230. }
  231. });
  232. }else {
  233. pullUp.css({"background":"","background-size":""});
  234. pullUpLabel.text("没有数据了");
  235. iscroll.refresh();
  236. }
  237. }
  238. //加载缓存中的内容
  239. if (localStorage.hasOwnProperty("gzIndex")) {
  240. var sth = localStorage.getItem("gzIndex");
  241. $(".gzdaIscroll ul").append(sth.substring(4,sth.length));
  242. };
  243. //定位到上次离开的位置
  244. if (localStorage.hasOwnProperty("gzIndexY")) {
  245. var tall = localStorage.getItem("gzIndexY");
  246. iscroll.scrollTo(0,tall,1000, IScroll.utils.ease.elastic);
  247. iscroll.refresh();
  248. };
  249. });
  250. /**
  251. * 新增公猪档案
  252. */
  253. function addGzda() {
  254. haifm.loadMobilePage("haifm", "hvSjlrGzdaAdd.htm?mcid=" + $("#mcid").val());
  255. }
  256. /**
  257. * 返回
  258. */
  259. function backUrl() {
  260. clear();
  261. haifm.loadMobilePage("haifm", "haifmvMain.htm?uuid=" + $("#uuid").val() + "&mcid=" + $("#mcid").val() + "&qyid=" + $("#qyid").val() +"&toList=2");
  262. }
  263. function viewGzxq(id) {
  264. if (id != "") {
  265. haifm.loadMobilePage("haifm", "hvSjlrGzxx.htm?mcid=" + $("#mcid").val() + "&id=" + id + "&ztsl=" + $("#ztsl").val() + "&cxeph=" + $("#dweb").val());
  266. }
  267. }
  268. //滑动高度和内容高度对比
  269. function heightvs(zsIscrollHeight,cententHeight){
  270. if(zsIscrollHeight.height() > cententHeight.height()){
  271. $("#pullUp").hide();
  272. }else{
  273. $("#pullUp").show();
  274. }
  275. }
  276. //清除部分缓存
  277. function clear() {
  278. if (localStorage.hasOwnProperty("gzIndex")) {
  279. localStorage.removeItem("gzIndex");
  280. }
  281. if (localStorage.hasOwnProperty("gzIndexY")) {
  282. localStorage.removeItem("gzIndexY");
  283. }
  284. if (localStorage.hasOwnProperty("mzIndex")) {
  285. localStorage.removeItem("mzIndex");
  286. }
  287. if (localStorage.hasOwnProperty("mzIndexY")) {
  288. localStorage.removeItem("mzIndexY");
  289. }
  290. if (localStorage.hasOwnProperty("mzIndexPage")) {
  291. localStorage.removeItem("mzIndexPage");
  292. }
  293. if (localStorage.hasOwnProperty("gzIndexPage")) {
  294. localStorage.removeItem("gzIndexPage");
  295. }
  296. }