$(document).ready(function () {
    initializateUI();
    bindEvent();
});

function initializateUI() {
    UICtrl.layout("#layout", {leftWidth: 3});

    var isEnable = $("#isEnable").val();
    if (isEnable == "0"){
        UICtrl.setDisable($("#submitForm"));
        if (isApplyProcUnit()){
            UICtrl.enable($("#telePhone"))
            UICtrl.enable($("#reason"))
        }
        $(".subject").html("冻结成本中心")
    }
}

function bindEvent(){
    $('#khinr').treebox({
        name:'sapOrgDpt',
        searchName:'sapOrgDpt',
        searchType:'bsn',
        hasSearch :true,
        minWidth:500,
        param:{
            treeViewMappingType:"bsn",
            parentId:'ogn'
        },
        back:{
            //text:$('#queryDataManageName')
        },
        onChange:function(node,data){
            $('#khinr').val(data.id);
        }
    });
}

function getCostCenterDetail(CostCenterAction) {
    //采购订单保存时数据不进行必填验证，提交时数据才进行必填验证
    var op = {};
    var check = true;
    if (CostCenterAction == "save") {
        check = false;
    }
    op = {check: check};
    var costCenter = $('#submitForm').formToJSON(op);
    if (!costCenter) {
        return false;
    }
    return costCenter;
}

function saveData(action) {
    var CostCenterDetail = getCostCenterDetail("submit");
    if (!CostCenterDetail) {
        return;
    }
    Public.ajax(web_app.name + '/sapCostCenter/saveCostCenter.ajax?code=' + action,CostCenterDetail,
        function (data) {
            setId(data.id);
            Public.successTip("数据保存成功");
            // processGridManager.setParm('id', data.id);
            // processGridManager.loadData();
        }
    );
}

function closeDispatchTabItem() {
    UICtrl.closeCurrentTab();
}

function setId(value) {
    $('#id').val(value);
}

function getId() {
    return $("#id").val();
}

function getExtendedData(processAction) {
    var kostl = $("#kostl").val();
    if (kostl.length != 10){
        Public.tip("成本中心编码只能是10位数，请检查")
        return false;
    }
    return true;
}

function checkConstraints(){
    var kostl = $("#kostl").val();
    if (kostl.length != 10){
        Public.tip("成本中心编码只能是10位数，请检查")
        return false;
    }
    return true;
}


