INCOME_DETAIL={
    "num":[false,"序号","string"],
    "type":[true,"类别","string"],
    "name":[true,"名称","string"],
    "unit":[true,"单位","string"],
    "amount":[true,"数量","string"],
    "price":[true,"单价","price"],
    "taxRate":[true,"税率","number"],
    "totalTaxInclude":[true,"含税总金额","number"],
    "totalTaxExclude":[true,"不含税金额","number"]
};

COST_DETAIL={
    "num":[false,"序号","string"],
    "type":[true,"大类","string"],
    "category":[true,"类别","string"],
    "name":[true,"名称","string"],
    "unit":[true,"单位","string"],
    "amount":[true,"数量","string"],
    "price":[true,"单价","price"],
    "taxRate":[true,"税率","number"],
    "totalTaxInclude":[true,"含税总金额","number"],
    "totalTaxExclude":[true,"不含税金额","number"]
};

COST_PROJECT_MANAGE_DETAIL={
    "num":[false,"序号","string"],
    "type":[true,"财务费用类别","string"],
    "name1":[false,"业务项目","string"],
    "name2":[false,"业务项目","string"],
    "detail":[true,"项目明细","string"],
    "unit":[true,"单位","string"],
    "amount":[true,"数量","string"],
    "price":[true,"单价","price"],
    "total":[true,"总金额","number"],
    "predictMethod":[false,"预估计算方法","string"],
    "predictWhy":[false,"预估依据","string"],
    "remark":[false,"备注","string"],
    "deletable":[true,"是否可删除","string"]
};

BUDGET_PLAN_DETAIL={
    "month":[true,"月份"],
    "deviceCost":[true,"设备支出","number"],
    "engineerCost":[true,"工程支出","number"],
    "projectManageCost":[true,"经营性开支","number"],
    "earnestMoneyCost":[true,"保证金支出","number"],
    "totalCost":[true,"支出合计","number"],
    "saleIncome":[true,"销售收款","number"],
    "earnestMoneyIncome":[true,"保证金收款","number"],
    "totalIncome":[true,"收款合计","number"],
    "fundBalance":[true,"资金余额","number"],
    "capitalInterest":[true,"资金利息","number"],
    "underwrittenPlan":[true,"垫资计划","number"],
    "repaymentPlan":[true,"还款计划","number"]
};

var result = 0;

$(function () {
    $("input[name='costCompanyManageTaxExclude']").change(function () {
        digitalSelf("costCompanyManageTaxExclude", "input[name='costCompanyManageTaxExclude']");
    });
    $("input[name='costOtherOtherTaxInclude']").change(function () {
        console.log("budget.js:costOtherOtherTaxInclude");
        digitalSelf("costOtherOtherTaxInclude", "input[name='costOtherOtherTaxInclude']");
    });
    $("input[name='costOtherOtherTaxExclude']").change(function () {
        console.log("budget.js:costOtherOtherTaxExclude");
        digitalSelf("costOtherOtherTaxExclude", "input[name='costOtherOtherTaxExclude']");
    });
    //绑定删除按钮删除当前行
    bindDeleteBtn();
    //绑定收入和采购成本的输入框【都有税率】
    bindChangeableInput();
    //绑定总计的输入框
    bindIncomeTotal();
    //绑定总计的输入框
    bindCostTotal();
    //绑定总计的输入框
    bindCostManageTotal();

    $("#saveDraft").click(function () {
        $("#saveDraft").attr('disabled', true);

        checkName();
        if (result == 1) {
            window.confirm('项目名称已存在');
            $("#saveDraft").attr('disabled', false);
            return;
        }

        var dataIncome = collectData("am-modal-prompt-input-income");
        if (dataIncome.length <= 0) {
            window.confirm('请填写收入明细表');
            $("#saveDraft").attr('disabled', false);
            return;
        }

        var dataIncomeCheck = convertDetailVerifyCheck(dataIncome, INCOME_DETAIL, "收入明细表");
        if (dataIncomeCheck == null) {
            $("#saveDraft").attr('disabled', false);
            return;
        }

        //如果没有提交则自动计算预算信息
        dataIncome = prepareAjaxDataVerify(dataIncome, INCOME_DETAIL, $("#id").val());
        if(dataIncome.details){
            postAjax(base+"/project/budgetEditSaveIncomeDetail", dataIncome);
        }
        updateIncomeDataUnsubmit(dataIncomeCheck);

        var dataCost = collectData("am-modal-prompt-input-cost");
        if (dataCost.length <= 0) {
            window.confirm('请填写采购成本明细表');
            $("#saveDraft").attr('disabled', false);
            return;
        }

        var dataCostCheck = convertDetailVerifyCheck(dataCost, COST_DETAIL, "采购成本明细表");
        if (dataCostCheck == null) {
            $("#saveDraft").attr('disabled', false);
            return;
        }

        //如果没有提交则自动计算预算信息
        dataCost = prepareAjaxDataVerify(dataCost, COST_DETAIL, $("#id").val());
        if(dataCost){
            postAjax(base+"/project/budgetEditSaveCostDetail", dataCost);
        }
        updateCostDataIfUnsubmit(dataCostCheck);

        var dataManage = collectData("am-modal-prompt-input-cost-project-manage");
        if (dataManage.length <= 0) {
            window.confirm('请填写项目管理成本表');
            $("#saveDraft").attr('disabled', false);
            return;
        }

        var dataManageCheck = convertDetailVerifyCheck(dataManage, COST_PROJECT_MANAGE_DETAIL, "项目管理成本表");
        if (dataManageCheck == null) {
            $("#saveDraft").attr('disabled', false);
            return;
        }

        dataManage = prepareAjaxDataVerify(dataManage, COST_PROJECT_MANAGE_DETAIL, $("#id").val());
        if(dataManage){
            postAjax(base+"/project/budgetEditSaveCostProjectManageDetail", dataManage);
        }
        updateCostProjectManageDataUnsubmit(dataManageCheck);

        var dataPlan = collectData("am-modal-prompt-input-budget-plan-detail");
        if (dataPlan.length <= 0) {
            window.confirm('请填写项目资金计划表');
            $("#saveDraft").attr('disabled', false);
            return;
        }

        var dataPlanCheck = convertDetailVerifyCheck(dataPlan, BUDGET_PLAN_DETAIL, "项目资金计划表");
        if (dataPlanCheck == null) {
            $("#saveDraft").attr('disabled', false);
            return;
        }

        //校验数据正确性
        var message = verifyBudgetPlan();
        if (message) {
            layuiAlert(message);
            $("#saveDraft").attr('disabled', false);
            return;
        }

        dataPlan = prepareAjaxDataVerify(dataPlan, BUDGET_PLAN_DETAIL, $("#id").val());
        if(dataPlan){
            postAjax(base+"/project/budgetEditSaveBudgetPlanDetail", dataPlan);
        }
        updateBudgetPlanDetailDataUnsubmit();

        var message = verifyProjectContributionProfitRate();
        if (message) {
            $("#saveDraft").attr('disabled', false);
            layuiAlert(message);
            return;
        }
        console.log(message);

        var startTime = $("#startDate").val();
        var endTime = $("#endDate").val();
        if (startTime > endTime) {
            $("#saveDraft").attr('disabled', false);
            window.confirm('开始日期应早于结束日期');
            return;
        }
        setTimeout(function () {
            $("#saveDraft").attr('disabled', false);
        }, 5000);
        $("#pmsForm").attr("action", base + "/project/budgetEditSave");
        $("#pmsForm").submit();
    });
    $("#saveApprove").click(function () {
        $("#saveApprove").attr('disabled', true);

        checkName();
        if (result == 1) {
            window.confirm('项目名称已存在');
            $("#saveApprove").attr('disabled', false);
            return;
        }

        var dataIncome = collectData("am-modal-prompt-input-income");
        if (dataIncome.length <= 0) {
            window.confirm('请填写收入明细表');
            $("#saveApprove").attr('disabled', false);
            return;
        }

        var dataIncomeCheck = convertDetailVerifyCheck(dataIncome, INCOME_DETAIL, "收入明细表");
        if (dataIncomeCheck == null) {
            $("#saveApprove").attr('disabled', false);
            return;
        }

        //如果没有提交则自动计算预算信息
        dataIncome = prepareAjaxDataVerify(dataIncome, INCOME_DETAIL, $("#id").val());
        if(dataIncome.details){
            postAjax(base+"/project/budgetEditSaveIncomeDetail", dataIncome);
        }
        updateIncomeDataUnsubmit(dataIncomeCheck);

        var dataCost = collectData("am-modal-prompt-input-cost");
        if (dataCost.length <= 0) {
            window.confirm('请填写采购成本明细表');
            $("#saveApprove").attr('disabled', false);
            return;
        }

        var dataCostCheck = convertDetailVerifyCheck(dataCost, COST_DETAIL, "采购成本明细表");
        if (dataCostCheck == null) {
            $("#saveApprove").attr('disabled', false);
            return;
        }

        //如果没有提交则自动计算预算信息
        dataCost = prepareAjaxDataVerify(dataCost, COST_DETAIL, $("#id").val());
        if(dataCost){
            postAjax(base+"/project/budgetEditSaveCostDetail", dataCost);
        }
        updateCostDataIfUnsubmit(dataCostCheck);

        var dataManage = collectData("am-modal-prompt-input-cost-project-manage");
        if (dataManage.length <= 0) {
            window.confirm('请填写项目管理成本表');
            $("#saveApprove").attr('disabled', false);
            return;
        }

        var dataManageCheck = convertDetailVerifyCheck(dataManage, COST_PROJECT_MANAGE_DETAIL, "项目管理成本表");
        if (dataManageCheck == null) {
            $("#saveApprove").attr('disabled', false);
            return;
        }

        dataManage = prepareAjaxDataVerify(dataManage, COST_PROJECT_MANAGE_DETAIL, $("#id").val());
        if(dataManage){
            postAjax(base+"/project/budgetEditSaveCostProjectManageDetail", dataManage);
        }
        updateCostProjectManageDataUnsubmit(dataManageCheck);

        var dataPlan = collectData("am-modal-prompt-input-budget-plan-detail");
        if (dataPlan.length <= 0) {
            window.confirm('请填写项目资金计划表');
            $("#saveApprove").attr('disabled', false);
            return;
        }

        var dataPlanCheck = convertDetailVerifyCheck(dataPlan, BUDGET_PLAN_DETAIL, "项目资金计划表");
        if (dataPlanCheck == null) {
            $("#saveApprove").attr('disabled', false);
            return;
        }

        //校验数据正确性
        var message = verifyBudgetPlan();
        if (message) {
            layuiAlert(message);
            $("#saveApprove").attr('disabled', false);
            return;
        }

        dataPlan = prepareAjaxDataVerify(dataPlan, BUDGET_PLAN_DETAIL, $("#id").val());
        if(dataPlan){
            postAjax(base+"/project/budgetEditSaveBudgetPlanDetail", dataPlan);
        }
        updateBudgetPlanDetailDataUnsubmit();

        var message = verifyProjectContributionProfitRate();
        if (message) {
            $("#saveApprove").attr('disabled', false);
            layuiAlert(message);
            return;
        }

        var startTime = $("#startDate").val();
        var endTime = $("#endDate").val();
        if (startTime > endTime) {
            $("#saveApprove").attr('disabled', false);
            window.confirm('开始日期应早于结束日期');
            return;
        }
        setTimeout(function () {
            $("#saveApprove").attr('disabled', false);
        }, 5000);
        $("#pmsForm").attr("action", base + "/project/budgetEditSaveAndApprove");
        $("#pmsForm").submit();
    });

    function checkName () {
        var name = $("#name").val();
        var id = $("#id").val();
        $.ajax({
            url: base + "/project/checkName",
            data: {name: name, id: id},
            type: "post",
            dataType: "json",
            async: false,
            success: function (data) {
                result = data.status;
            }
        });
    };
});

/**
 * 一维数组变二维数组
 * @param list
 * @param elementsPerSubArray
 * @returns {Array}
 */
function arrayToMatrix(list, elementsPerSubArray) {
    var matrix = [], i, k;

    for (i = 0, k = -1; i < list.length; i++) {
        if (i % elementsPerSubArray === 0) {
            k++;
            matrix[k] = [];
        }

        matrix[k].push(list[i]);
    }

    return matrix;
}

/**
 * 根据映射关系将数组变为对象
 * @param arr 一行数据
 * @param mapArr 映射数组
 * @param keepBlank 如果有空的并且不保留空就返回空，废弃这一行
 * @returns {*}
 */
function arr2Object(arr, mapArr, keepBlank) {
    var obj = {};
    for (var i = 0; i < mapArr.length; i++) {
        if (!arr[i] && !keepBlank) {
            return null;
        }
        obj[mapArr[i]] = arr[i];
    }
    return obj;
}

function arr2ObjectVerify(line, arr, detailPropertyArr, detailProperty) {
    var obj = {};
    for (var i = 0; i < detailPropertyArr.length; i++) {
        var o = detailProperty[detailPropertyArr[i]];
        //空但是要求非空
        if (!arr[i] && o[0]) {
            layuiAlert("第 " + (line + 1) + " 行的 " + o[1] + " 不允许为空");
            return null;
        }
        //如果要求是数字类型的，进行转换
        var v = arr[i];
        if(o[2] === 'number' ){
            v = f2(v);
        } else if(o[2] === 'price' ){
            v = f5(v);
        }
        obj[detailPropertyArr[i]]=v;
    }
    return obj;
}

function arr2ObjectVerifyCheck(line, arr, detailPropertyArr, detailProperty, s) {
    var obj = {};
    for (var i = 0; i < detailPropertyArr.length; i++) {
        var o = detailProperty[detailPropertyArr[i]];
        //空但是要求非空
        if (!arr[i] && o[0]) {
            layuiAlert(s + "第 " + (line + 1) + " 行的 " + o[1] + " 不允许为空");
            return null;
        }
        obj[detailPropertyArr[i]] = arr[i];
    }
    return obj;
}


/**
 * 收集收入明细的数据，因为动态添加的行modal无法识别，所以自己来收集
 * @returns {Array}
 */
function collectData(className) {
    var a = [];
    $("." + className).each(function (t) {
        a.push($(this).val());
    });
    return a;
}

/**
 * 绑定每一行的删除事件，删除当前的一行tr
 */
function bindDeleteBtn() {
    $(".am-modal-line-delete").click(function () {
        //删除自己对应的tr
        $(this).parent().parent().remove();
        bindNum();
    });
}

/**
 * 将页面收集到的数据转换为ajax请求的数据【一维数组转换为对象数组】
 * @param data
 * @param detailPropertyArr
 * @param keepBlank
 * @returns {Array}
 */
function convertDetail(data, detailPropertyArr, keepBlank) {
    var arr = arrayToMatrix(data, detailPropertyArr.length);

    var details = [];
    for (var i = 0; i < arr.length; i++) {
        var obj = arr2Object(arr[i], detailPropertyArr, keepBlank);
        if (obj) {
            details.push(obj);
        }

    }
    return details;
}

function convertDetailVerify(data, detailProperty) {
    var detailPropertyArr = Object.keys(detailProperty);
    var arr = arrayToMatrix(data, detailPropertyArr.length);
    var details = [];
    for (var i = 0; i < arr.length; i++) {
        if (i === arr.length - 1 && detailProperty !== BUDGET_PLAN_DETAIL) {
            continue;
        }
        var obj = arr2ObjectVerify(i, arr[i], detailPropertyArr, detailProperty);
        if (!obj) {
            return null;
        }
        details.push(obj);

    }
    return details;
}

function convertDetailVerifyCheck(data, detailProperty, s) {
    var detailPropertyArr = Object.keys(detailProperty);
    var arr = arrayToMatrix(data, detailPropertyArr.length);
    var details = [];
    for (var i = 0; i < arr.length; i++) {
        if (i === arr.length - 1 && s !== "项目资金计划表") {
            continue;
        }
        var obj = arr2ObjectVerifyCheck(i, arr[i], detailPropertyArr, detailProperty, s);
        if (!obj) {
            return null;
        }
        details.push(obj);

    }
    return details;
}

function prepareAjaxData(data, detailPropertyArr, projectId, keepBlank) {
    var details = convertDetail(data, detailPropertyArr, keepBlank);
    return {
        "details": details,
        "projectId": projectId
    };
}

function prepareAjaxDataVerify(data, detailProperty, projectId) {
    var details = convertDetailVerify(data, detailProperty);
    return {
        "details": details,
        "projectId": projectId
    };
}

/**
 * 绑定每个可改变的输入框，修改后改变对应输入框的值
 */
function bindChangeableInput() {
    //数量改变
    $(".input-changeable-amount").change(function () {
        var amount = parseInt($(this).val());
        //找到对应的单价和税率
        var price = f5($(this).parent().parent().find(".input-changeable-price").val());
        var taxRate = f2($(this).parent().parent().find(".input-changeable-tax-rate").val());
        console.log(amount, price, taxRate);

        $(this).parent().parent().find(".input-changeable-total-tax-include").val(f2Fixed(amount * price));
        $(this).parent().parent().find(".input-changeable-total-tax-exclude").val(f2Fixed(amount * price / (1 + taxRate / 100)));
    });
    //单价改变
    $(".input-changeable-price").change(function () {
        var price = f5($(this).val());
        //找到对应的数量和税率
        var amount = parseInt($(this).parent().parent().find(".input-changeable-amount").val());
        var taxRate = f2($(this).parent().parent().find(".input-changeable-tax-rate").val());
        console.log(amount, price, taxRate);

        $(this).parent().parent().find(".input-changeable-total-tax-include").val(f2Fixed(amount * price));
        $(this).parent().parent().find(".input-changeable-total-tax-exclude").val(f2Fixed(amount * price / (1 + taxRate / 100)));
        $(this).val(f5Price(price));
        console.log("单价：" + $(this).val());
    });
    //税率改变
    $(".input-changeable-tax-rate").change(function () {
        var taxRate = f2($(this).val());
        //找到对应的数量和单价
        var amount = parseInt($(this).parent().parent().find(".input-changeable-amount").val());
        var price = f5($(this).parent().parent().find(".input-changeable-price").val());
        console.log(amount, price, taxRate);

        $(this).parent().parent().find(".input-changeable-total-tax-exclude").val(f2Fixed(amount * price / (1 + taxRate / 100)));
    });
}

/**
 * 每次更新数量，单价和税率时，更改总计中含税和不含税总金额
 * @param className
 * @param totalClassName
 */
function updateTotal(className, totalClassName) {
    var total = 0;
    //找到本列所有的
    $("."+className).each(function (t) {
        total += f2($(this).val());
        console.log("total2: " + total);
    });
    $("."+totalClassName).val(f2Fixed(total));
}

/**
 * 每次更新数量时，更新总计中数量
 * @param className
 * @param totalClassName
 */
function updateAmount(className, totalClassName) {
    var total = 0;
    //找到本列所有的
    $("."+className).each(function (t) {
        console.log(className + ": " + f2($(this).val()));
        total += f2($(this).val());
    });
    $("."+totalClassName).val(total);
}

/**
 * 绑定序号
 */
function bindNum() {
    $(".input-budget-num").each(function(t) {
        var prevIndex = $(this).parent().parent().prev("tr").find(".input-budget-num").val();
        $(this).val(f2(prevIndex) + 1);
    });
}

/**
 * 校验项目贡献利润率必须大于阀值
 * 低于阀值就返回提示信息，否则返回""
 */
function verifyProjectContributionProfitRate() {
    var projectContributionProfitRate = f2(inputVal("projectContributionProfitRate"));
    var projectContributionProfitRateThreshold = f2($("#projectContributionProfitRateThreshold").val());
    if (projectContributionProfitRate < projectContributionProfitRateThreshold) {
        return "项目贡献利润率[" + projectContributionProfitRate + "]低于阀值[" + projectContributionProfitRateThreshold + "]，请调整后重新提交";
    }

    return "";
}

/**
 * 更新
 * 毛利=收入总计（不含税）-成本总计（不含税）-财务费用总计（不含税）
 * 毛利率=毛利（不含税）/收入总计（不含税）
 * 贡献利润=项目毛利（不含税）-公司管理费用总计（不含税）
 * 贡献利润率=贡献利润（不含税）/收入总计（不含税）
 */
function updateProjectContributionProfitRate() {
    //收入总计不含税
    var incomeTotalTaxExclude = f2(inputVal("incomeTotalTaxExclude"));
    //成本总计不含税
    var costTotalTaxExclude = f2(inputVal("costTotalTaxExclude"));
    //资金使用成本不含税
    var costExpropriationTaxExclude = f2(inputVal("costExpropriationTaxExclude"));
    //公司管理费用
    var costCompanyManageTaxExclude = f2(inputVal("costCompanyManageTaxExclude"));

    var projectGrossProfit = f2Fixed(incomeTotalTaxExclude - costTotalTaxExclude - costExpropriationTaxExclude);
    var projectGrossProfitRate = f2Fixed(rate(f2(projectGrossProfit), incomeTotalTaxExclude));
    var projectContributionProfit = f2Fixed(f2(projectGrossProfit) - costCompanyManageTaxExclude);
    var projectContributionProfitRate = f2Fixed(rate(f2(projectContributionProfit), incomeTotalTaxExclude));

    $("input[name='projectGrossProfit']").val(projectGrossProfit);
    $("input[name='projectGrossProfitRate']").val(projectGrossProfitRate);
    $("input[name='projectContributionProfit']").val(projectContributionProfit);
    $("input[name='projectContributionProfitRate']").val(projectContributionProfitRate);
}


/**
 * 更新页面收入的数据【累加】
 */
function updateCostDataIfUnsubmit(details) {
    var deviceTaxInclude = 0;
    var deviceTaxExclude = 0;
    var buildTaxInclude = 0;
    var buildTaxExclude = 0;
    var serviceTaxInclude = 0;
    var serviceTaxExclude = 0;
    var otherTaxInclude = 0;
    var otherTaxExclude = 0;
    details.forEach(function (t, number, ts) {
        if(t["type"] == "1"){
            //设备类
            deviceTaxInclude += f2(t["totalTaxInclude"]);
            deviceTaxExclude += f2(t["totalTaxExclude"]);
        }else if(t["type"] == "2"){
            //施工类
            buildTaxInclude += f2(t["totalTaxInclude"]);
            buildTaxExclude += f2(t["totalTaxExclude"]);
        }else if(t["type"] == "3"){
            //服务类
            serviceTaxInclude += f2(t["totalTaxInclude"]);
            serviceTaxExclude += f2(t["totalTaxExclude"]);
        }else if(t["type"] == "4"){
            //其他类
            otherTaxInclude += f2(t["totalTaxInclude"]);
            otherTaxExclude += f2(t["totalTaxExclude"]);
        }
    });
    $("input[name='costPurchaseDeviceTaxInclude']").val(f2Fixed(deviceTaxInclude));
    $("input[name='costPurchaseDeviceTaxExclude']").val(f2Fixed(deviceTaxExclude));
    $("input[name='costPurchaseBuildTaxInclude']").val(f2Fixed(buildTaxInclude));
    $("input[name='costPurchaseBuildTaxExclude']").val(f2Fixed(buildTaxExclude));
    $("input[name='costPurchaseServiceTaxInclude']").val(f2Fixed(serviceTaxInclude));
    $("input[name='costPurchaseServiceTaxExclude']").val(f2Fixed(serviceTaxExclude));
    $("input[name='costPurchaseOtherTaxInclude']").val(f2Fixed(otherTaxInclude));
    $("input[name='costPurchaseOtherTaxExclude']").val(f2Fixed(otherTaxExclude));

    //资金计划表中的
    $(".input-total-title-device-cost-budget-plan").val(f2Fixed(deviceTaxInclude));
    $(".input-total-title-engineer-cost-budget-plan").val(f2Fixed(f2(serviceTaxInclude)+f2(buildTaxInclude)+f2(otherTaxInclude)));
    $(".input-total-title-total-cost-budget-plan").val(f2Fixed(f2(deviceTaxInclude)+f2(buildTaxInclude)+f2(serviceTaxInclude)+f2(otherTaxInclude)
        +f2($(".input-total-title-project-manage-cost-budget-plan").val())
        +f2($(".input-total-title-earnest-money-cost-budget-plan").val())));

    calCostExclude();
    calCostInclude();

    updateProjectContributionProfitRate();
}


/**
 * 更新页面收入的数据【累加】
 */
function updateIncomeDataUnsubmit(incomeDetails) {
    var deviceTaxInclude = 0;
    var deviceTaxExclude = 0;
    var engineerTaxInclude = 0;
    var engineerTaxExclude = 0;
    var serviceTaxInclude = 0;
    var serviceTaxExclude = 0;
    incomeDetails.forEach(function (t, number, ts) {
        if(t["type"] == "1"){
            //设备类
            deviceTaxInclude += f2(t["totalTaxInclude"]);
            deviceTaxExclude += f2(t["totalTaxExclude"]);
        }else if(t["type"] == "2"){
            //工程类
            engineerTaxInclude += f2(t["totalTaxInclude"]);
            engineerTaxExclude += f2(t["totalTaxExclude"]);
        }else if(t["type"] == "3"){
            //服务类
            serviceTaxInclude += f2(t["totalTaxInclude"]);
            serviceTaxExclude += f2(t["totalTaxExclude"]);
        }
    });
    $("input[name='incomeDeviceTaxInclude']").val(f2Fixed(deviceTaxInclude));
    $("input[name='incomeDeviceTaxExclude']").val(f2Fixed(deviceTaxExclude));
    $("input[name='incomeEngineerTaxInclude']").val(f2Fixed(engineerTaxInclude));
    $("input[name='incomeEngineerTaxExclude']").val(f2Fixed(engineerTaxExclude));
    $("input[name='incomeServiceTaxInclude']").val(f2Fixed(serviceTaxInclude));
    $("input[name='incomeServiceTaxExclude']").val(f2Fixed(serviceTaxExclude));

    $("input[name='incomeTotalTaxInclude']").val(f2Fixed(deviceTaxInclude+engineerTaxInclude+serviceTaxInclude));
    $("input[name='incomeTotalTaxExclude']").val(f2Fixed(deviceTaxExclude+engineerTaxExclude+serviceTaxExclude));


    $(".input-total-title-sale-income-budget-plan").val($("input[name='incomeTotalTaxInclude']").val());
    $(".input-total-title-total-income-budget-plan").val(f2Fixed(f2($("input[name='incomeTotalTaxInclude']").val())
        +f2($(".input-total-title-earnest-money-income-budget-plan").val())));


    updateProjectContributionProfitRate();
}

/**
 * 更新页面收入的数据【累加】
 */
function updateCostProjectManageDataUnsubmit(details) {
    var total = 0;
    details.forEach(function (t, number, ts) {
        total += f2(t["total"]);
    });

    total = f2(total);

    $("input[name='costProjectManageTaxExclude']").val(f2Fixed(total));
    $("input[name='costProjectManageTaxInclude']").val(f2Fixed(total));

    //资金计划表中的
    $(".input-total-title-project-manage-cost-budget-plan").val(f2Fixed(total));

    var deviceTaxExclude = $("input[name='costPurchaseDeviceTaxExclude']").val();
    var buildTaxExclude = $("input[name='costPurchaseBuildTaxExclude']").val();
    var serviceTaxExclude = $("input[name='costPurchaseServiceTaxExclude']").val();
    var otherTaxExclude = $("input[name='costPurchaseOtherTaxExclude']").val();

    var deviceTaxInclude = $("input[name='costPurchaseDeviceTaxInclude']").val();
    var buildTaxInclude = $("input[name='costPurchaseBuildTaxInclude']").val();
    var serviceTaxInclude = $("input[name='costPurchaseServiceTaxInclude']").val();
    var otherTaxInclude = $("input[name='costPurchaseOtherTaxInclude']").val();
    $(".input-total-title-total-cost-budget-plan").val(f2Fixed(f2(deviceTaxInclude)+f2(buildTaxInclude)+f2(serviceTaxInclude)+f2(otherTaxInclude)
        +total
        +f2($(".input-total-title-earnest-money-cost-budget-plan").val())));

    calCostExclude();
    calCostInclude();

    updateProjectContributionProfitRate();
}

/**
 * 更新页面收入的数据
 */
function updateBudgetPlanDetailDataUnsubmit(data,returnData) {
    //var details = data.details;
    //主页面上的财务费用
    $("input[name='costExpropriationTaxExclude']").val($(".input-underwritten-plan-statistic-capital-interest-budget-plan").val());
    //更新项目贡献率
    updateProjectContributionProfitRate();
    //更新现金流量
    updateCashFlow();
}
