D:/workspace/chenjingjing/git/gx_tieta/gx_tieta/.gitignore
2019-01-18 2fe250ece8de95b3f70172fe5b45793ab6a3084a
gx_tieta/WebRoot/pages/js/mylayui.js
@@ -543,3 +543,132 @@
    }
};
//获取layui的form表单的值(支持input和select)
var LayuiForm = function(ele) {
    this.ele = ele;
};
// 定义原型方法
LayuiForm.prototype = {
    get: function(callback) {
        var ele = $('#'+this.ele);
        var isGood = this._checkForm(ele);
        if(isGood) {
            var iptsVals = this._getIpts(ele);
            var selVals = this._getSels(ele);
            //  获取所有的form值
            var rs = $.extend({}, iptsVals, selVals);
            callback(rs);
        }
    }
    ,_getIpts: function(ele) {
        var ipts = ele.find('input');
        var iptVals = {};
        ipts.each(function() {
            var name = $(this).attr('name');
            if(name) {
                iptVals[name] = $(this).val();
            }
        });
        return iptVals;
    }
    ,_getSels: function(ele) {
        var sels = ele.find('select');
        var selVals = {};
        sels.each(function() {
            var name = $(this).attr('name');
            if(name) {
                selVals[name] = $(this).val();
            }
        });
        return selVals;
    }
    ,_checkForm: function(ele) {
        var isGood = true;
        var ipts = ele.find('input');
        var sels = ele.find('select');
        //  遍历所有的input查询是否有数据不正确的
        ipts.each(function() {
            if($(this).hasClass('layui-form-danger')) {
                isGood = false;
            }
        });
        //  遍历所有的select查询是否有数据不正确的
        sels.each(function() {
            if($(this).hasClass('layui-form-danger')) {
                isGood = false;
            }
        });
        // 返回结果
        return isGood;
    }
};
// 统计数据选中个数/总个数
var QuantNumber = function(ele) {
   this.ele = ele;
   this.mol = 0;
   this.den = 0;
   this._init();
}
// 设置原型方法
QuantNumber.prototype = {
   _init: function() {
      this._setEleTxt();
   }
   ,set: function(mol, den) {
      this.mol = mol;
      this.den = den;
      this._setEleTxt();
   }
   ,setMol: function(val) {
      this.mol = val;
      this._setEleTxt();
   }
   ,setDen: function(val) {
      this.den = val;
      this._setEleTxt();
   }
   ,_setEleTxt: function() {
      var str = this.mol+'/'+this.den;
      this.ele.text(str)
   }
};
//获取电池品牌列表
function getBattProducers() {
   let producers = [];
   // 请求后台查询电池品牌
   $.ajax({
      type: 'post'
      ,async: false
      ,url: 'BattInfAction!serchByBattProducer'
      ,data: null
      ,dataType: 'json'
      ,success: function(res) {
         let rs = JSON.parse(res.result);
         // 判断查询结果
         if(rs.code == 1) {
            let data = rs.data;
            // 遍历查询结果
            for(let i=0; i<data.length; i++) {
               let _data = data[i];
               if(_data.BattProducer) {      // 处理为空的品牌
                  producers.push(_data.BattProducer);
               }
            }
            producers.push('其他');
         }
      }
      ,complete: function() {
      }
   });
   return producers;
}