/** * 一个采购成本详情的字段 */ COST_DETAIL_ARR=["type","category","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"]; $(function () { $("#cost-detail").click(function () { $('#my-prompt-cost-detail').modal({ relatedTarget: this, onConfirm: function(e) { //不能使用e.data,因为无法获取动态添加的 var data = collectData("am-modal-prompt-input-cost"); data = prepareAjaxData(data, COST_DETAIL_ARR, $("#id").val()); saveDetail("/fourcal/project/budgetEditSaveCostDetail", data, updateCostData); }, onCancel: function(e) { } }); }); $("#costAddBtn").click(function () { appendTrCost(); }); }); /** * 采购成本增加一行 */ function appendTrCost() { var template = ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''; $("#costTable").append(template); //重新绑定删除事件和input修改事件 bindDeleteBtn(); bindChangeableInput(); } /** * 更新页面收入的数据【累加】 */ function updateCostData(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(deviceTaxInclude); $("input[name='costPurchaseDeviceTaxExclude']").val(deviceTaxExclude); $("input[name='costPurchaseBuildTaxInclude']").val(buildTaxInclude); $("input[name='costPurchaseBuildTaxExclude']").val(buildTaxExclude); $("input[name='costPurchaseServiceTaxInclude']").val(serviceTaxInclude); $("input[name='costPurchaseServiceTaxExclude']").val(serviceTaxExclude); $("input[name='costPurchaseOtherTaxInclude']").val(otherTaxInclude); $("input[name='costPurchaseOtherTaxExclude']").val(otherTaxExclude); var costOtherOtherTaxInclude = parseFloat($("input[name='costOtherOtherTaxInclude']").val()); var costOtherOtherTaxExclude = parseFloat($("input[name='costOtherOtherTaxExclude']").val()); var costProjectManageTaxExclude = parseFloat($("input[name='costProjectManageTaxExclude']").val()); $("input[name='costTotalTaxInclude']").val(deviceTaxInclude+buildTaxInclude+serviceTaxInclude+otherTaxInclude+costOtherOtherTaxInclude); $("input[name='costTotalTaxExclude']").val(deviceTaxExclude+buildTaxExclude+serviceTaxExclude+otherTaxExclude+costOtherOtherTaxExclude+costProjectManageTaxExclude); } function bindOtherOtherChangeable() { $("input[name='costOtherOtherTaxInclude']").change(function () { var costPurchaseDeviceTaxInclude = f2($("input[name='costPurchaseDeviceTaxInclude']").val()); var costPurchaseBuildTaxInclude = f2($("input[name='costPurchaseBuildTaxInclude']").val()); var costPurchaseServiceTaxInclude = f2($("input[name='costPurchaseServiceTaxInclude']").val()); var costPurchaseOtherTaxInclude = f2($("input[name='costPurchaseOtherTaxInclude']").val()); var costOtherOther = f2($(this).val()); $("input[name='costTotalTaxInclude']").val(costPurchaseDeviceTaxInclude+costPurchaseBuildTaxInclude+costPurchaseServiceTaxInclude+costPurchaseOtherTaxInclude+costOtherOther); }); $("input[name='costOtherOtherTaxExclude']").change(function () { var costPurchaseDeviceTaxExclude = f2($("input[name='costPurchaseDeviceTaxExclude']").val()); var costPurchaseBuildTaxExclude = f2($("input[name='costPurchaseBuildTaxExclude']").val()); var costPurchaseServiceTaxExclude = f2($("input[name='costPurchaseServiceTaxExclude']").val()); var costPurchaseOtherTaxExclude = f2($("input[name='costPurchaseOtherTaxExclude']").val()); var costProjectManageTaxExclude = f2($("input[name='costProjectManageTaxExclude']").val()); var costOtherOther = f2($(this).val()); $("input[name='costTotalTaxExclude']").val(costPurchaseDeviceTaxExclude+costPurchaseBuildTaxExclude+costPurchaseServiceTaxExclude+costPurchaseOtherTaxExclude+costProjectManageTaxExclude+costOtherOther); }); }