gx_tieta/WebRoot/pages/js/mylayui.js
@@ -543,3 +543,98 @@
    }
};
//获取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)
   }
};