mzdaIndex.js 9.1 KB

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