/** * 一个资金计划的字段 */ BUDGET_PLAN_DETAIL_ARR=["month","deviceCost","engineerCost","project_manageCost","earnestMoneyCost","totalCost","saleIncome","earnestMoneyIncome","totalIncome","fundBalance","capitalInterest","underwrittenPlan","repaymentPlan"]; $(function () { $(".budget-plan-detail").click(function () { $('#my-prompt-budget-plan-detail').modal({ relatedTarget: this, onConfirm: function(e) { //不能使用e.data,因为无法获取动态添加的 var data = collectData("am-modal-prompt-input-budget-plan-detail"); data = prepareAjaxData(data, BUDGET_PLAN_DETAIL_ARR, $("#id").val()); saveDetail("/fourcal/project/budgetEditSaveBudgetPlanDetail", data, updateBudgetPlanDetailData); }, onCancel: function(e) { } }); }); $("#budgetPlanDetailAddBtn").click(function () { appendTrBudgetPlan(); }); }); /** * 资金计划增加一行 */ function appendTrBudgetPlan() { var template = '\n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' '; $("#budgetPlanDetailTable").append(template); //重新绑定删除事件和input修改事件 bindBudgetPlanDeleteBtn(); bindChangeableInputBudgetPlanDetail(); } /** * 绑定删除删除按钮,不仅删除还需要重新计算统计的数据 */ function bindBudgetPlanDeleteBtn() { $(".am-modal-line-delete-budget-plan").click(function () { //删除自己对应的tr $(this).parent().parent().remove(); //还需要更新每一列的合计数据 updateBudgetPlanTotal("input-changeable-device-cost-budget-plan","input-total-device-cost-budget-plan"); updateBudgetPlanTotal("input-changeable-engineer-cost-budget-plan","input-total-engineer-cost-budget-plan"); updateBudgetPlanTotal("input-changeable-project-manage-cost-budget-plan","input-total-project-manage-cost-budget-plan"); updateBudgetPlanTotal("input-changeable-earnest-money-cost-budget-plan","input-total-earnest-money-cost-budget-plan"); updateBudgetPlanTotal("input-changeable-total-cost-budget-plan","input-total-total-cost-budget-plan"); updateBudgetPlanTotal("input-changeable-sale-income-budget-plan","input-total-sale-income-budget-plan"); updateBudgetPlanTotal("input-changeable-earnest-money-income-budget-plan","input-total-earnest-money-income-budget-plan"); updateBudgetPlanTotal("input-changeable-total-income-budget-plan","input-total-total-income-budget-plan"); updateBudgetPlanTotal("input-changeable-capital-interest-budget-plan","input-total-capital-interest-budget-plan"); updateBudgetPlanTotal("input-changeable-underwritten-plan-budget-plan","input-total-underwritten-plan-budget-plan"); updateBudgetPlanTotal("input-changeable-repayment-plan-budget-plan","input-total-repayment-plan-budget-plan"); /*updateBudgetPlanTotal("input-changeable-fund-balance-budget-plan","input-total-fund-balance-budget-plan");*/ //每个月的余额=本月收入-支出+上月余额 }); } function bindChangeableInputBudgetPlanDetail() { //设备支出改变 $(".input-changeable-device-cost-budget-plan").change(function () { var deviceCost = parseFloat($(this).val()); //找到对应的工程支出、经营性支出、保证金支出 var engineerCost = parseFloat($(this).parent().parent().find(".input-changeable-engineer-cost-budget-plan").val()); var projectManageCost = parseFloat($(this).parent().parent().find(".input-changeable-project-manage-cost-budget-plan").val()); var earnestMoneyCost = parseFloat($(this).parent().parent().find(".input-changeable-earnest-money-cost-budget-plan").val()); console.log(deviceCost,engineerCost,projectManageCost,earnestMoneyCost); //更新本月所有项支出 $(this).parent().parent().find(".input-changeable-total-cost-budget-plan").val(deviceCost+engineerCost+projectManageCost+earnestMoneyCost); //更新所有月设备支出总额 updateBudgetPlanTotal("input-changeable-device-cost-budget-plan","input-total-device-cost-budget-plan"); //更新所有月支出总额 updateBudgetPlanTotal("input-changeable-total-cost-budget-plan","input-total-total-cost-budget-plan"); }); //工程支出改变 $(".input-changeable-engineer-cost-budget-plan").change(function () { var engineerCost = parseFloat($(this).val()); //找到对应的设备支出、经营性支出、保证金支出 var deviceCost = parseFloat($(this).parent().parent().find(".input-changeable-device-cost-budget-plan").val()); var projectManageCost = parseFloat($(this).parent().parent().find(".input-changeable-project-manage-cost-budget-plan").val()); var earnestMoneyCost = parseFloat($(this).parent().parent().find(".input-changeable-earnest-money-cost-budget-plan").val()); console.log(deviceCost,engineerCost,projectManageCost,earnestMoneyCost); //更新本月所有项支出 $(this).parent().parent().find(".input-changeable-total-cost-budget-plan").val(deviceCost+engineerCost+projectManageCost+earnestMoneyCost); //更新所有月工程支出总额 updateBudgetPlanTotal("input-changeable-engineer-cost-budget-plan","input-total-engineer-cost-budget-plan"); //更新所有月支出总额 updateBudgetPlanTotal("input-changeable-total-cost-budget-plan","input-total-total-cost-budget-plan"); }); //经营性支出改变 $(".input-changeable-project-manage-cost-budget-plan").change(function () { var projectManageCost = parseFloat($(this).val()); //找到对应的设备支出、工程支出、保证金支出 var deviceCost = parseFloat($(this).parent().parent().find(".input-changeable-device-cost-budget-plan").val()); var engineerCost = parseFloat($(this).parent().parent().find(".input-changeable-engineer-cost-budget-plan").val()); var earnestMoneyCost = parseFloat($(this).parent().parent().find(".input-changeable-earnest-money-cost-budget-plan").val()); console.log(deviceCost,engineerCost,projectManageCost,earnestMoneyCost); //更新本月所有项支出 $(this).parent().parent().find(".input-changeable-total-cost-budget-plan").val(deviceCost+engineerCost+projectManageCost+earnestMoneyCost); //更新所有月经营性支出总额 updateBudgetPlanTotal("input-changeable-project-manage-cost-budget-plan","input-total-project-manage-cost-budget-plan"); //更新所有月支出总额 updateBudgetPlanTotal("input-changeable-total-cost-budget-plan","input-total-total-cost-budget-plan"); }); //保证金改变 $(".input-changeable-earnest-money-cost-budget-plan").change(function () { var earnestMoneyCost = parseFloat($(this).val()); //找到对应的设备支出、经营性支出、保证金支出 var deviceCost = parseFloat($(this).parent().parent().find(".input-changeable-device-cost-budget-plan").val()); var engineerCost = parseFloat($(this).parent().parent().find(".input-changeable-engineer-cost-budget-plan").val()); var projectManageCost = parseFloat($(this).parent().parent().find(".input-changeable-project-manage-cost-budget-plan").val()); console.log(deviceCost,engineerCost,projectManageCost,earnestMoneyCost); //更新本月所有项支出 $(this).parent().parent().find(".input-changeable-total-cost-budget-plan").val(deviceCost+engineerCost+projectManageCost+earnestMoneyCost); //更新所有月保证金支出总额 updateBudgetPlanTotal("input-changeable-earnest-money-cost-budget-plan","input-total-earnest-money-cost-budget-plan"); //更新所有月支出总额 updateBudgetPlanTotal("input-changeable-total-cost-budget-plan","input-total-total-cost-budget-plan"); }); //销售收款改变 $(".input-changeable-sale-income-budget-plan").change(function () { var saleIncome = parseFloat($(this).val()); //找到保证金收款 var earnestMoneyIncome = parseFloat($(this).parent().parent().find(".input-changeable-earnest-money-income-budget-plan").val()); console.log(saleIncome, earnestMoneyIncome); //更新本月所有项收入 $(this).parent().parent().find(".input-changeable-total-income-budget-plan").val(saleIncome+earnestMoneyIncome); //更新所有月销售收款总额 updateBudgetPlanTotal("input-changeable-sale-income-budget-plan","input-total-sale-income-budget-plan"); //更新所有月收入总额 updateBudgetPlanTotal("input-changeable-total-income-budget-plan","input-total-total-income-budget-plan"); }); //保证金收款改变 $(".input-changeable-earnest-money-income-budget-plan").change(function () { var earnestMoneyIncome = parseFloat($(this).val()); //找到保证金收款 var saleIncome = parseFloat($(this).parent().parent().find(".input-changeable-sale-income-budget-plan").val()); console.log(saleIncome, earnestMoneyIncome); //更新本月所有项收入 $(this).parent().parent().find(".input-changeable-total-income-budget-plan").val(saleIncome+earnestMoneyIncome); //更新所有月保证金收款总额 updateBudgetPlanTotal("input-changeable-earnest-money-income-budget-plan","input-total-earnest-money-income-budget-plan"); //更新所有月收入总额 updateBudgetPlanTotal("input-changeable-total-income-budget-plan","input-total-total-income-budget-plan"); }); /*//资金余额改变 $(".input-changeable-fund-balance-budget-plan").change(function () { updateBudgetPlanTotal("input-changeable-fund-balance-budget-plan","input-total-fund-balance-budget-plan"); });*/ //资金利息改变 $(".input-changeable-capital-interest-budget-plan").change(function () { updateBudgetPlanTotal("input-changeable-capital-interest-budget-plan","input-total-capital-interest-budget-plan"); }); //垫资计划改变 $(".input-changeable-underwritten-plan-budget-plan").change(function () { updateBudgetPlanTotal("input-changeable-underwritten-plan-budget-plan","input-total-underwritten-plan-budget-plan"); }); //还款计划改变 $(".input-changeable-repayment-plan-budget-plan").change(function () { updateBudgetPlanTotal("input-changeable-repayment-plan-budget-plan","input-total-repayment-plan-budget-plan"); }); } /** * 更新每列的总计 */ function updateBudgetPlanTotal(className, totalClassName) { var total = 0; //找到本列所有的 $("."+className).each(function (t) { total += parseFloat($(this).val()); }); $("."+totalClassName).val(total); } /** * 更新页面收入的数据 */ function updateBudgetPlanDetailData(details) { }