
var layer;
layui.use(['form', 'laydate', 'layer'], function () {
    var form = layui.form;
    var laydate = layui.laydate;
    layer = layui.layer;

    initPage(form);
    initOrgType(form);
    //监听提交
    form.on('submit(submit)', function (data) {
        if(true){

            $.ajax({
                type: "post",
                data: JSON.stringify(data.field),
                url: '/jx/saveKpilib',
                timeout : 60000, //超时时间设置，单位毫秒
                dataType: "json",
                beforeSend: function() {
                    startloading();
                },
                success: function(d){
                    if (d.code=='0'){
                        layer.alert('保存成功',function (d1) {
                                window.location.href='/jx/toUpdateKpilib?kpilibId='+d.id;
                        });
                       // layer.alert('保存成功');
                    }else{
                        layer.alert("保存错误:"+d.msg);
                    }
                },
                error: function(e){
                     layer.alert("您可能已掉线，请刷新页面或关闭后重试！!");
                },
                complete: function(xhr, status) {
                    setTimeout(function() {
                        try{
                            stoploading();
                        }catch(e){

                        }
                    }, 500);
                }
            });
        }
        
    });

    form.on('select(kpilib_type)', function(data){
        initPage()
    });
    form.on('select(kpilib_orgtype)', function(data){
        initOrgType()
    });

});
function initOrgType(){
    var type = $("#kpilib_orgtype").val();
    if(type ==""){
        $("#kpilib_orgid").attr("lay-verify","required");
       // $("#kpilib_orgid").removeAttr("disabled");
    }else{
       // $("#kpilib_orgid").val("");
       // $("#kpilib_orgid").attr("disabled","disabled");
        $("#kpilib_orgid").removeAttr("lay-verify");
    }

}
//初始化页面  主要是根据类型控制页面元素的是否可编辑
function initPage(){


}
