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

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


function bindEvent() {
    $("#save").click(function () {
        saveData("save");
    })
    $("#submit").click(function () {
        saveData("submit");
    })

    $("#close").click(function () {//关闭
        closeDispatchTabItem();
    })
}

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) {
    debugger
    var CostCenterDetail = getCostCenterDetail("submit");
    if (!CostCenterDetail) {
        return;
    }
    Public.ajax(web_app.name + '/monthlySettlementMethod/saveMonthlySettlementMethod.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();
}


