| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- $(function () {
- var zsIscrollHeight = $(".mzdaIscroll");
- var cententHeight = $(".mzdaIscroll div:first-child");
- heightvs(zsIscrollHeight,cententHeight);
- //初始化page
- if(localStorage.hasOwnProperty("mzIndexPage")) {
- $("#page").val(localStorage.getItem("mzIndexPage"));
- }
- //清除span为空的padding值
- $(".row div.col-xs-2.col-sm-2.col-md-2 span").each(function(){
- if($(this).html() === ""){
- $(this).css("padding","0");
- }
- });
- var mask = mui.createMask();//callback为用户点击蒙版时自动执行的回调;
- $(".xqck").on("tap", function() {
- var id = $(this).data("for");
- if (id != "") {
- haifm.loadMobilePage("haifm", "hvSjlrMzxx.htm?mcid=" + $("#mcid").val() + "&id=" + id + "&ztsl=" + $("#ztsl").val()+ "&cxeph=" + $("#dweb").val());
- //haifm.loadMobilePage("haifm", "hvSjlrMzdaAdd.htm?mcid=" + $("#mcid").val() + "&dweb=" +$(this).data("dweb") + "&edit=" + "edit");
- }
- });
- //动物耳标查询、模糊查询键盘enter键事件
- $("input[type='search']").on('keypress',function(e) {
- var keycode = e.keyCode;
- if(keycode=='13') {
- e.preventDefault();
- //请求搜索接口
- haifm.loadMobilePage("haifm", "hvSjlrMzDaIndex.htm?mcid=" + $("#mcid").val() + "&cxeph=" + $("#dweb").val());
- clear();
- }
- });
- /* 单选和多选 复选框事件*/
- $(".mui-icon-checkmarkempty").bind("click", function () {
- var result1 = new Array();
- var resultId1 = new Array();
- var result2 = new Array();
- var resultId2 = new Array();
- resultId1.push(",");
- resultId2.push(",");
- //当前状态
- $("[name = dqztCheck]:checkbox").each(function () {
- if ($(this).is(":checked")) {
- result1.push($(this).parent().next().text());
- resultId1.push($(this).attr("data-for"));
- }
- });
- //舍栏
- $("[name = slCheck]:checkbox").each(function () {
- if ($(this).is(":checked")) {
- result2.push($(this).parent().next().text());
- resultId2.push($(this).attr("data-for"));
- }
- });
- var dqzt = "0";
- var sl = "0";
- if (result2.length > 0) {
- sl = "1";
- }
- if(result1.length > 0) {
- dqzt = "1";
- }
- haifm.loadMobilePage("haifm", "hvSjlrMzDaIndex.htm?mcid=" + $("#mcid").val() + "&dqzt=" + dqzt + "&dqztArray="+resultId1 + "&sl=" + sl + "&slArray=" + resultId2);
- mask.close();//关闭遮罩
- clear();
- });
- /**
- * 初始化滚动条
- * */
- var iscroll;
- iscroll = new IScroll(".mzdaIscroll",{
- scrollbars: true,
- fadeScrollbars:true,
- scrollbars: 'custom',
- shrinkScrollbars:'clip',
- probeType: 2,
- click:true,
- HWCompositing:true,
- });
- setTimeout(function(){
- iscroll.refresh();
- }, 600);
- /**
- * 分页器
- * */
- var mySwiper = new Swiper('.swiper-container', {
- scrollbar:'.swiper-scrollbar',
- scrollbarHide:false,
- observer:true,
- prevButton:'.swiper-button-prev',
- nextButton:'.swiper-button-next',
- onSlidePrevEnd: function(){
- $(".tabText1").show();
- $(".tabText2").hide();
- },
- onSlideNextEnd: function(){
- $(".tabText1").hide();
- $(".tabText2").show();
- }
- });
- $(".btn-group").on("tap",function(){
- mask.show();//显示遮罩
- $(".md-modal").show();
- mySwiper.update();
- });
- mui('body').on('tap', '.mui-backdrop', function(e) {
- $(".md-modal").hide();
- });
- /*公猪母猪舍切换*/
- $('.change').on("tap",function(){
- if ($(this).index() == 0){
- $(this).addClass("changeBg1").siblings(".change").removeClass("changeBg2");//removeClass就是删除当前其他类;只有当前对象有addClass("changeBg1");siblings()意思就是当前对象的同级元素,removeClass就是删除;
- haifm.loadMobilePage("haifm", "hvSjlrDaIndex.htm?mcid=" + $("#mcid").val());
- } else if ($(this).index() == 3){
- $(this).addClass("changeBg2").siblings(".change").removeClass("changeBg1");
- haifm.loadMobilePage("haifm", "hvSjlrMzDaIndex.htm?mcid=" + $("#mcid").val());
- }
- });
- /**
- * 滚动input以外失去焦点
- * */
- iscroll.on('scrollStart',function(e){
- var el = document.activeElement;
- if (el.nodeName.toLowerCase() == 'input') {
- el.blur();
- this.disable();
- this.enable();
- };
- return;
- });
- /**
- * 点击input以外失去焦点
- * */
- var beforeIpt=null;
- $("input").on("focus", function (e) {
- beforeIpt=this;
- });
- $(document).on("tap", function (e) {
- if(e.target.nodeName.toLowerCase()!="input") {
- if(beforeIpt) {
- beforeIpt.blur();
- beforeIpt=null;
- }
- }
- });
- /**
- *下拉刷新上拉加载数据
- **/
- var pullUp = $("#pullUp"),
- pullUpLabel = $(".pullUpLabel"),
- loadingStep = 0;//加载状态0默认,1显示加载状态,2执行加载数据,只有当为0时才能再次加载,这是防止过快拉动刷新
- //滚动时触发
- iscroll.on("scroll",function(){
- if(loadingStep == 0 && !pullUp.attr("class").match('refresh')){
- if(this.y < (this.maxScrollY - 14)){//上拉加载更多
- pullUp.addClass("refresh").show();
- pullUp.css({"background":"","background-size":""});
- pullUpLabel.text("松手开始加载...");
- loadingStep = 1;
- iscroll.refresh();
- }
- }
- });
- //滚动结束触发
- iscroll.on("scrollEnd",function(){
- if(loadingStep == 1){
- if( pullUp.attr("class").match("refresh") ){//上拉加载操作
- pullUp.removeClass("refresh").addClass("loading");
- pullUpLabel.text("");
- pullUp.css({"background":"#D7DFEA url(views/haifmv/img/pullUp.gif) no-repeat center","background-size":"12%"});
- loadingStep = 2;
- pullUpAction();
- iscroll.refresh();
- }
- }
- //定位
- var thisy = parseInt(this.y);
- localStorage.setItem("mzIndexY",thisy);
- });
- /**
- * 上拉加载方法
- * */
- function pullUpAction(){
- var page = parseInt($("#page").val())+1;
- var maxPages = $("#maxPages").val();
- if (page <= maxPages) {
- jQuery.ajax({
- type : "get",
- url : "addSjlrMzda.htm",
- data : {
- "mcid" : $("#mcid").val(),
- "ztsl" : $("#ztsl").val(),
- "cxeph": $("#dweb").val(),
- page : page
- },
- dataType : "json",
- async : true,
- success : function(data) {
- setTimeout(function() {
- var hc = localStorage.getItem("mzIndex");
- var something = "";
- for (var i = 0 ; i < data.length; i++) {
- var obj = data[i];
- 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+")';>"
- + "<div class='rowBox container-fluid'>"
- + "<div class='row'>"
- + "<div class='col-xs-12 col-sm-12 col-md-12 discenter'>"
- + "<p>"+obj.eph+"</p></div></div><div class='row'>"
- + "<div class='col-xs-2 col-sm-2 col-md-2 discenter'>"
- + "<span>"+obj.pzStr+"</span>"
- + "</div>"
- + "<div class='col-xs-2 col-sm-2 col-md-2 discenter'>"
- + "<span>"+obj.dqztStr+"</span>"
- + "</div>"
- + "</div>"
- + "<span class='jrBtn'></span>"
- + "</div>"
- + "</li>";
- }
- $(".mzdaIscroll ul").append($(something));
- pullUp.attr("class","");
- pullUpLabel.text("上拉加载更多");
- pullUp.css({"background":""});
- iscroll.refresh();
- loadingStep = 0;
- localStorage.setItem("mzIndex",hc + something);
- },1000);
- $("#page").val(page);
- //page 计入缓存
- localStorage.setItem("mzIndexPage",page);
- }
- });
- }else {
- pullUp.css({"background":"","background-size":""});
- pullUpLabel.text("没有数据了");
- iscroll.refresh();
- }
- }
-
- //加载缓存中的内容
- if (localStorage.hasOwnProperty("mzIndex")) {
- var sth = localStorage.getItem("mzIndex");
- $(".mzdaIscroll ul").append(sth.substring(4,sth.length));
- };
- //定位到上次离开的位置
- if (localStorage.hasOwnProperty("mzIndexY")) {
- var tall = localStorage.getItem("mzIndexY");
- iscroll.scrollTo(0,tall ,1000, IScroll.utils.ease.elastic);
- iscroll.refresh();
- };
-
- document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
- });
- /**
- * 新增母猪档案
- */
- function addMzda() {
- haifm.loadMobilePage("haifm", "hvSjlrMzdaAdd.htm?mcid=" + $("#mcid").val());
- }
- /**
- * 返回
- */
- function backUrl() {
- //清除部分缓存
- clear();
- haifm.loadMobilePage("haifm", "haifmvMain.htm?uuid=" + $("#uuid").val() + "&mcid=" + $("#mcid").val() + "&qyid=" + $("#qyid").val() +"&toList=2");
- }
- function viewMzxq(id) {
- if (id != "") {
- haifm.loadMobilePage("haifm", "hvSjlrMzxx.htm?mcid=" + $("#mcid").val() + "&id=" + id + "&ztsl=" + $("#ztsl").val() + "&cxeph=" + $("#dweb").val());
- }
- }
- //滑动高度和内容高度对比
- function heightvs(zsIscrollHeight,cententHeight){
- if(zsIscrollHeight.height() > cententHeight.height()){
- $("#pullUp").hide();
- }else{
- $("#pullUp").show();
- }
- }
- function clear() {
- if (localStorage.hasOwnProperty("gzIndex")) {
- localStorage.removeItem("gzIndex");
- }
- if (localStorage.hasOwnProperty("gzIndexY")) {
- localStorage.removeItem("gzIndexY");
- }
- if (localStorage.hasOwnProperty("mzIndex")) {
- localStorage.removeItem("mzIndex");
- }
- if (localStorage.hasOwnProperty("mzIndexY")) {
- localStorage.removeItem("mzIndexY");
- }
- if (localStorage.hasOwnProperty("mzIndexPage")) {
- localStorage.removeItem("mzIndexPage");
- }
- if (localStorage.hasOwnProperty("gzIndexPage")) {
- localStorage.removeItem("gzIndexPage");
- }
- }
|