From 7ddb2aaf8527b92530b279e12fb9b46f6a67dc5f Mon Sep 17 00:00:00 2001
From: xxssyyyyssxx <xxssyyyyssxx@126.com>
Date: Wed, 3 Nov 2021 16:50:54 +0800
Subject: [PATCH] =?UTF-8?q?=E6=88=90=E6=9C=AC=E6=98=8E=E7=BB=86=E4=BF=9D?=
 =?UTF-8?q?=E5=AD=98=E4=B8=8E=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../controller/backend/ProjectController.java |  38 +--
 .../static/assets/js/project_budget.js        | 242 +++++++++++++-----
 .../templates/admin/project_budget_edit.ftl   | 133 ++++++++--
 3 files changed, 312 insertions(+), 101 deletions(-)

diff --git a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java
index 5cfdbee..fdd6736 100644
--- a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java
+++ b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java
@@ -176,17 +176,17 @@ public class ProjectController extends BaseController{
     @ResponseBody
     public ResponseMsg budgetEditSaveIncomeDetail(@RequestBody String body) {
         JSONObject jsonObject = JSON.parseObject(body);
-        JSONArray incomeDetails = jsonObject.getJSONArray("incomeDetails");
-        List<ProjectBudgetIncomeDetail> incomeDetailList = new ArrayList<>(incomeDetails.size());
-        for (int i = 0; i < incomeDetails.size(); i++) {
-            ProjectBudgetIncomeDetail incomeDetail = incomeDetails.getObject(i, ProjectBudgetIncomeDetail.class);
-            incomeDetailList.add(incomeDetail);
+        JSONArray details = jsonObject.getJSONArray("details");
+        List<ProjectBudgetIncomeDetail> detailList = new ArrayList<>(details.size());
+        for (int i = 0; i < details.size(); i++) {
+            ProjectBudgetIncomeDetail incomeDetail = details.getObject(i, ProjectBudgetIncomeDetail.class);
+            detailList.add(incomeDetail);
         }
 
         Project project = projectService.getProject(jsonObject.getInteger("projectId"));
 
         projectBudgetService.clearBudgetIncomeDetail(project);
-        projectBudgetService.saveBudgetIncomeDetail(project, incomeDetailList);
+        projectBudgetService.saveBudgetIncomeDetail(project, detailList);
 
         return ResponseMsg.buildSuccessMsg("成功");
     }
@@ -194,19 +194,20 @@ public class ProjectController extends BaseController{
      * 保存成本明细
      */
     @RequestMapping("/budgetEditSaveCostDetail")
+    @ResponseBody
     public ResponseMsg budgetEditSaveCostDetail(@RequestBody String body) {
         JSONObject jsonObject = JSON.parseObject(body);
-        JSONArray costDetails = jsonObject.getJSONArray("costDetails");
-        List<ProjectBudgetCostDetail> costDetailList = new ArrayList<>(costDetails.size());
-        for (int i = 0; i < costDetails.size(); i++) {
-            ProjectBudgetCostDetail costDetail = costDetails.getObject(i, ProjectBudgetCostDetail.class);
-            costDetailList.add(costDetail);
+        JSONArray details = jsonObject.getJSONArray("details");
+        List<ProjectBudgetCostDetail> detailList = new ArrayList<>(details.size());
+        for (int i = 0; i < details.size(); i++) {
+            ProjectBudgetCostDetail costDetail = details.getObject(i, ProjectBudgetCostDetail.class);
+            detailList.add(costDetail);
         }
 
         Project project = projectService.getProject(jsonObject.getInteger("projectId"));
 
         projectBudgetService.clearBudgetCostDetail(project);
-        projectBudgetService.saveBudgetCostDetail(project, costDetailList);
+        projectBudgetService.saveBudgetCostDetail(project, detailList);
 
         return ResponseMsg.buildSuccessMsg("成功");
     }
@@ -214,19 +215,20 @@ public class ProjectController extends BaseController{
      * 保存项目管理成本明细
      */
     @RequestMapping("/budgetEditSaveCostProjectManageDetail")
+    @ResponseBody
     public ResponseMsg budgetEditSaveCostProjectManageDetail(@RequestBody String body) {
         JSONObject jsonObject = JSON.parseObject(body);
-        JSONArray costDetails = jsonObject.getJSONArray("costProjectManageDetails");
-        List<ProjectBudgetCostProjectManageDetail> costDetailList = new ArrayList<>(costDetails.size());
-        for (int i = 0; i < costDetails.size(); i++) {
-            ProjectBudgetCostProjectManageDetail costDetail = costDetails.getObject(i, ProjectBudgetCostProjectManageDetail.class);
-            costDetailList.add(costDetail);
+        JSONArray details = jsonObject.getJSONArray("details");
+        List<ProjectBudgetCostProjectManageDetail> detailList = new ArrayList<>(details.size());
+        for (int i = 0; i < details.size(); i++) {
+            ProjectBudgetCostProjectManageDetail costDetail = details.getObject(i, ProjectBudgetCostProjectManageDetail.class);
+            detailList.add(costDetail);
         }
 
         Project project = projectService.getProject(jsonObject.getInteger("projectId"));
 
         projectBudgetService.clearBudgetCostProjectManageDetail(project);
-        projectBudgetService.saveBudgetCostProjectManageDetail(project, costDetailList);
+        projectBudgetService.saveBudgetCostProjectManageDetail(project, detailList);
 
         return ResponseMsg.buildSuccessMsg("成功");
     }
diff --git a/src/main/resources/static/assets/js/project_budget.js b/src/main/resources/static/assets/js/project_budget.js
index f204fc1..67cea2b 100644
--- a/src/main/resources/static/assets/js/project_budget.js
+++ b/src/main/resources/static/assets/js/project_budget.js
@@ -34,37 +34,81 @@ function arr2Object(arr, mapArr) {
     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();
+    });
+}
 /**
  * 一个收入详情的字段
  */
 INCOME_DETAIL_ARR=["type","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"];
+/**
+ * 一个采购成本详情的字段
+ */
+COST_DETAIL_ARR=["type","category","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"];
 
 /**
- * 保存收入明细数据
+ * 将页面收集到的数据转换为ajax请求的数据【一维数组转换为对象数组】
+ * @param data
+ * @param detailPropertyArr
+ * @returns {Array}
  */
-function saveIncomeDetail(url, data, projectId) {
-    if(Array.isArray(data) && data.length != 0){
-        var incomeDetails = convertIncomeDetail(data);
-        var da = {
-            "incomeDetails":incomeDetails,
-            "projectId":projectId
-        };
-        console.log(da);
-        $.ajax({
-            url: url,
-            data: JSON.stringify(da),
-            type: "post",
-            dataType: "json",
-            contentType:"application/json",
-            async: false,
-            success: function (d) {
-                console.log(d);
-                updateIncomeData(incomeDetails);
-            }
-        });
+function convertDetail(data,detailPropertyArr) {
+    var arr = arrayToMatrix(data,detailPropertyArr.length);
+
+    var details = [];
+    for (var i=0;i<arr.length;i++){
+        var obj = arr2Object(arr[i], detailPropertyArr);
+        if(obj){
+            details.push(obj);
+        }
+
     }
+    return details;
 }
 
+function prepareAjaxData(data,detailPropertyArr,projectId){
+    var details = convertDetail(data, detailPropertyArr);
+    return {
+        "details":details,
+        "projectId":projectId
+    };
+}
+
+function saveDetail(url, data, callback) {
+    $.ajax({
+        url: url,
+        data: JSON.stringify(data),
+        type: "post",
+        dataType: "json",
+        contentType:"application/json",
+        async: false,
+        success: function (d) {
+            console.log(d);
+            callback(data.details);
+        }
+    });
+}
+
+
 /**
  * 更新页面收入的数据【累加】
  */
@@ -102,51 +146,11 @@ function updateIncomeData(incomeDetails) {
 }
 
 
-/**
- * 将页面收集到的数据转换为ajax请求的数据【一维数组转换为对象数组】
- * @param data
- * @returns {Array}
- */
-function convertIncomeDetail(data) {
-    var arr = arrayToMatrix(data,INCOME_DETAIL_ARR.length);
-
-    var incomeDetails = [];
-    for (var i=0;i<arr.length;i++){
-        var obj = arr2Object(arr[i], INCOME_DETAIL_ARR);
-        if(obj){
-            incomeDetails.push(obj);
-        }
-
-    }
-    return incomeDetails;
-}
-
-/**
- * 收集收入明细的数据,因为动态添加的行modal无法识别,所以自己来收集
- * @returns {Array}
- */
-function collectIncomeData(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();
-    });
-}
 
 /**
  * 绑定每个可改变的输入框,修改后改变对应输入框的值
  */
-function bindIncomeChangeableInput() {
+function bindChangeableInput() {
     //数量改变
     $(".input-changeable-amount").change(function () {
         var amount = parseFloat($(this).val());
@@ -205,5 +209,117 @@ function appendTrIncome() {
     $("#incomeTable").append(template);
     //重新绑定删除事件和input修改事件
     bindDeleteBtn();
-    bindIncomeChangeableInput();
+    bindChangeableInput();
+}
+
+
+/**
+ * 采购成本增加一行
+ */
+function appendTrCost() {
+    var template = '<tr><td><select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost">'+
+        '<option value="1">设备</option>'+
+        '<option value="2">施工</option>'+
+        '<option value="3">服务</option>'+
+        '<option value="4">其他</option>'+
+        '</select>'+
+        '</td>'+
+        '<td>'+
+        '<select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost">'+
+        '<option value="1">华智产品</option>'+
+        '<option value="2">紫光其他产品</option>'+
+        '<option value="3">外购产品</option>'+
+        '<option value="4">外购工程</option>'+
+        '<option value="5">华智服务</option>'+
+        '<option value="6">紫光其他服务</option>'+
+        '<option value="7">外购服务</option>'+
+        '<option value="8">其他</option>'+
+        '</select>'+
+        '</td>'+
+        '<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost"></td>'+
+        '<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost""></td>'+
+        '<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-amount"></td>'+
+        '<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-price"></td>'+
+        '<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-tax-rate"></td>'+
+        '<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-total-tax-include" readonly></td>'+
+        '<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-total-tax-exclude" readonly></td>'+
+        '<td><button type="button" class="am-btn am-btn-warning am-btn-xs am-modal-line-delete"><span class="am-icon-minus"></span></button></td>'+
+    '</tr>';
+    $("#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 += parseFloat(t["totalTaxInclude"]);
+            deviceTaxExclude += parseFloat(t["totalTaxExclude"]);
+        }else if(t["type"] == "2"){
+            //施工类
+            buildTaxInclude += parseFloat(t["totalTaxInclude"]);
+            buildTaxExclude += parseFloat(t["totalTaxExclude"]);
+        }else if(t["type"] == "3"){
+            //服务类
+            serviceTaxInclude += parseFloat(t["totalTaxInclude"]);
+            serviceTaxExclude += parseFloat(t["totalTaxExclude"]);
+        }else if(t["type"] == "4"){
+            //其他类
+            otherTaxInclude += parseFloat(t["totalTaxInclude"]);
+            otherTaxExclude += parseFloat(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 = parseFloat($("input[name='costPurchaseDeviceTaxInclude']").val());
+        var costPurchaseBuildTaxInclude = parseFloat($("input[name='costPurchaseBuildTaxInclude']").val());
+        var costPurchaseServiceTaxInclude = parseFloat($("input[name='costPurchaseServiceTaxInclude']").val());
+        var costPurchaseOtherTaxInclude = parseFloat($("input[name='costPurchaseOtherTaxInclude']").val());
+
+        var costOtherOther = parseFloat($(this).val());
+
+        $("input[name='costTotalTaxInclude']").val(costPurchaseDeviceTaxInclude+costPurchaseBuildTaxInclude+costPurchaseServiceTaxInclude+costPurchaseOtherTaxInclude+costOtherOther);
+    });
+
+    $("input[name='costOtherOtherTaxExclude']").change(function () {
+        var costPurchaseDeviceTaxExclude = parseFloat($("input[name='costPurchaseDeviceTaxExclude']").val());
+        var costPurchaseBuildTaxExclude = parseFloat($("input[name='costPurchaseBuildTaxExclude']").val());
+        var costPurchaseServiceTaxExclude = parseFloat($("input[name='costPurchaseServiceTaxExclude']").val());
+        var costPurchaseOtherTaxExclude = parseFloat($("input[name='costPurchaseOtherTaxExclude']").val());
+
+        var costProjectManageTaxExclude = parseFloat($("input[name='costProjectManageTaxExclude']").val());
+        var costOtherOther = parseFloat($(this).val());
+
+        $("input[name='costTotalTaxExclude']").val(costPurchaseDeviceTaxExclude+costPurchaseBuildTaxExclude+costPurchaseServiceTaxExclude+costPurchaseOtherTaxExclude+costProjectManageTaxExclude+costOtherOther);
+    });
 }
\ No newline at end of file
diff --git a/src/main/resources/templates/admin/project_budget_edit.ftl b/src/main/resources/templates/admin/project_budget_edit.ftl
index 4a33a28..c02c01a 100644
--- a/src/main/resources/templates/admin/project_budget_edit.ftl
+++ b/src/main/resources/templates/admin/project_budget_edit.ftl
@@ -18,7 +18,7 @@
 <div class="admin-content">
     <div class="admin-content-body">
         <div class="am-cf am-padding">
-            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">项目概算表</strong> / <small>${project.name}</small></div>
+            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">项目预算表</strong> / <small>${project.name}</small></div>
         </div>
 
 <form method="post" class="am-form" id="pmsForm" action="${base}/project/budgetEditSave">
@@ -228,8 +228,8 @@
                     </tbody>
                 </table>
                 <span class="am-text-lg">成本</span>
-                <span class="am-text-primary"><a style="cursor: pointer">采购成本明细表</a></span>
-                <span class="am-text-primary"><a style="cursor: pointer">项目管理成本表</a></span>
+                <span class="am-text-primary"><a style="cursor: pointer"  id="cost-detail">采购成本明细表</a></span>
+                <span class="am-text-primary"><a style="cursor: pointer"  id="cost-project-manage-detail">项目管理成本表</a></span>
                 <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
                     <tbody>
                     <tr class="am-text-xl">
@@ -243,55 +243,55 @@
                         <td>成本</td>
                         <td>采购成本</td>
                         <td>设备</td>
-                        <td><input name="costPurchaseDeviceTaxInclude" value="${budgetBean.costPurchaseDeviceTaxInclude!9}" readonly required></td>
-                        <td><input name="costPurchaseDeviceTaxExclude" value="${budgetBean.costPurchaseDeviceTaxExclude!10}" readonly required></td>
+                        <td><input name="costPurchaseDeviceTaxInclude" value="${budgetBean.costPurchaseDeviceTaxInclude!0}" readonly required></td>
+                        <td><input name="costPurchaseDeviceTaxExclude" value="${budgetBean.costPurchaseDeviceTaxExclude!0}" readonly required></td>
                     </tr>
                     <tr>
                         <td>成本</td>
                         <td>采购成本</td>
                         <td>施工</td>
-                        <td><input name="costPurchaseBuildTaxInclude" value="${budgetBean.costPurchaseBuildTaxInclude!11}" readonly required></td>
-                        <td><input name="costPurchaseBuildTaxExclude" value="${budgetBean.costPurchaseBuildTaxExclude!12}" readonly required></td>
+                        <td><input name="costPurchaseBuildTaxInclude" value="${budgetBean.costPurchaseBuildTaxInclude!0}" readonly required></td>
+                        <td><input name="costPurchaseBuildTaxExclude" value="${budgetBean.costPurchaseBuildTaxExclude!0}" readonly required></td>
                     </tr>
                     <tr>
                         <td>成本</td>
                         <td>采购成本</td>
                         <td>服务</td>
-                        <td><input name="costPurchaseServiceTaxInclude" value="${budgetBean.costPurchaseServiceTaxInclude!13}" readonly required></td>
+                        <td><input name="costPurchaseServiceTaxInclude" value="${budgetBean.costPurchaseServiceTaxInclude!0}" readonly required></td>
                         <td><input name="costPurchaseServiceTaxExclude" value="${budgetBean.costPurchaseServiceTaxExclude!0}" readonly required></td>
                     </tr>
                     <tr>
                         <td>成本</td>
                         <td>采购成本</td>
                         <td>其他</td>
-                        <td><input name="costPurchaseOtherTaxInclude" value="${budgetBean.costPurchaseOtherTaxInclude!14}" readonly required></td>
-                        <td><input name="costPurchaseOtherTaxExclude" value="${budgetBean.costPurchaseOtherTaxExclude!15}" readonly required></td>
+                        <td><input name="costPurchaseOtherTaxInclude" value="${budgetBean.costPurchaseOtherTaxInclude!0}" readonly required></td>
+                        <td><input name="costPurchaseOtherTaxExclude" value="${budgetBean.costPurchaseOtherTaxExclude!0}" readonly required></td>
                     </tr>
                     <tr>
                         <td>成本</td>
                         <td>项目管理成本</td>
                         <td>项目管理成本</td>
                         <td><#--<input name="costProjectManageTaxInclude" value="${budgetBean.costProjectManageTaxInclude!}" readonly required>-->/</td>
-                        <td><input name="costProjectManageTaxExclude" value="${budgetBean.costProjectManageTaxExclude!17}" readonly required></td>
+                        <td><input name="costProjectManageTaxExclude" value="${budgetBean.costProjectManageTaxExclude!0}" readonly required></td>
                     </tr>
                     <tr>
                         <td>成本</td>
                         <td>其他</td>
                         <td>其他</td>
-                        <td><input name="costOtherOtherTaxInclude" value="${budgetBean.costOtherOtherTaxInclude!}" required></td>
-                        <td><input name="costOtherOtherTaxExclude" value="${budgetBean.costOtherOtherTaxExclude!}" required></td>
+                        <td><input name="costOtherOtherTaxInclude" value="${budgetBean.costOtherOtherTaxInclude!0}" required></td>
+                        <td><input name="costOtherOtherTaxExclude" value="${budgetBean.costOtherOtherTaxExclude!0}" required></td>
                     </tr>
                     <tr>
                         <td>合计</td>
                         <td></td>
                         <td></td>
-                        <td><input name="costTotalTaxInclude" value="${budgetBean.costTotalTaxInclude!18}" readonly required></td>
-                        <td><input name="costTotalTaxExclude" value="${budgetBean.costTotalTaxExclude!19}" readonly required></td>
+                        <td><input name="costTotalTaxInclude" value="${budgetBean.costTotalTaxInclude!0}" readonly required></td>
+                        <td><input name="costTotalTaxExclude" value="${budgetBean.costTotalTaxExclude!0}" readonly required></td>
                     </tr>
                     </tbody>
                 </table>
                 <span class="am-text-lg">管理</span>
-                <span class="am-text-primary"><a style="cursor: pointer">资金计划表</a></span>
+                <span class="am-text-primary"><a style="cursor: pointer" id="plan-detail">资金计划表</a></span>
                 <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
                     <tbody>
                     <tr class="am-text-xl">
@@ -406,6 +406,7 @@
     </div>
 
 
+    <#--收入明细表弹窗-->
     <div class="am-modal am-modal-prompt" style="width: 1200px;max-height:600px;overflow-y:auto;" tabindex="-1" id="my-prompt-income-detail">
         <div class="am-modal-dialog">
             <div class="am-modal-hd">新增销售收入明细表——${project.name}</div>
@@ -456,6 +457,77 @@
             </div>
         </div>
     </div>
+    <#--采购成本明细弹窗-->
+    <div class="am-modal am-modal-prompt" style="width: 1200px;max-height:600px;overflow-y:auto;" tabindex="-1" id="my-prompt-cost-detail">
+        <div class="am-modal-dialog">
+            <div class="am-modal-hd">新增采购成本明细表——${project.name}</div>
+            <div class="am-modal-bd">
+                <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;" id="costTable">
+                    <tbody>
+                    <tr>
+                        <td>大类</td>
+                        <td>类别</td>
+                        <td>名称</td>
+                        <td>单位</td>
+                        <td>数量</td>
+                        <td>单价</td>
+                        <td>税率(%)</td>
+                        <td>含税总金额(元)</td>
+                        <td>不含税金额(元)</td>
+                        <td>操作</td>
+                    </tr>
+
+                    <#if costDetails??>
+                        <#list costDetails as costDetail>
+                        <tr>
+                            <td>
+                                <select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost">
+                                    <option value="1" <#if costDetail.type == 1>selected</#if>>设备</option>
+                                    <option value="2" <#if costDetail.type == 2>selected</#if>>施工</option>
+                                    <option value="3" <#if costDetail.type == 3>selected</#if>>服务</option>
+                                    <option value="4" <#if costDetail.type == 4>selected</#if>>其他</option>
+                                </select>
+                            </td>
+                            <td>
+                                <select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost">
+                                    <option value="1" <#if costDetail.category == 1>selected</#if>>华智产品</option>
+                                    <option value="2" <#if costDetail.category == 2>selected</#if>>紫光其他产品</option>
+                                    <option value="3" <#if costDetail.category == 3>selected</#if>>外购产品</option>
+                                    <option value="4" <#if costDetail.category == 4>selected</#if>>外购工程</option>
+                                    <option value="5" <#if costDetail.category == 5>selected</#if>>华智服务</option>
+                                    <option value="6" <#if costDetail.category == 6>selected</#if>>紫光其他服务</option>
+                                    <option value="7" <#if costDetail.category == 7>selected</#if>>外购服务</option>
+                                    <option value="8" <#if costDetail.category == 8>selected</#if>>其他</option>
+                                </select>
+                            </td>
+                            <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost" value="${costDetail.name!}"></td>
+                            <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost" value="${costDetail.unit!}"></td>
+                            <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-amount" value="${costDetail.amount!}"></td>
+                            <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-price" value="${costDetail.price!}"></td>
+                            <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-tax-rate" value="${costDetail.taxRate!}"></td>
+                            <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-total-tax-include" value="${costDetail.totalTaxInclude!}" readonly></td>
+                            <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-total-tax-exclude" value="${costDetail.totalTaxExclude!}" readonly></td>
+                            <td><button type="button" class="am-btn am-btn-warning am-btn-xs am-modal-line-delete"><span class="am-icon-minus"></span></button></td>
+                        </tr>
+                        </#list>
+                    </#if>
+
+                    </tbody>
+                </table>
+                <button type="button" id="costAddBtn" class="am-btn am-btn-primary am-btn-xs"><span class="am-icon-plus"></span></button>
+            </div>
+            <div class="am-modal-footer">
+                <span class="am-modal-btn" data-am-modal-cancel>取消</span>
+                <span class="am-modal-btn" data-am-modal-confirm>保存</span>
+            </div>
+        </div>
+    </div>
+
+
+
+
+
+
 
 
 
@@ -473,6 +545,12 @@
 <script src="${base}/assets/js/project_budget.js"></script>
 <script>
     $(function () {
+
+        bindDeleteBtn();
+        bindChangeableInput();
+        bindOtherOtherChangeable();
+
+
         $("#saveDraft").click(function () {
             $("#pmsForm").attr("action","${base}/project/budgetEditSave");
             $("#pmsForm").submit();
@@ -487,8 +565,9 @@
                 relatedTarget: this,
                 onConfirm: function(e) {
                     //不能使用e.data,因为无法获取动态添加的
-                    var data = collectIncomeData("am-modal-prompt-input-income");
-                    saveIncomeDetail("${base}/project/budgetEditSaveIncomeDetail", data, $("#id").val());
+                    var data = collectData("am-modal-prompt-input-income");
+                    data = prepareAjaxData(data, INCOME_DETAIL_ARR, $("#id").val());
+                    saveDetail("${base}/project/budgetEditSaveIncomeDetail", data, updateIncomeData);
                 },
                 onCancel: function(e) {
                 }
@@ -498,8 +577,22 @@
             appendTrIncome();
         });
 
-        bindDeleteBtn();
-        bindIncomeChangeableInput();
+        $("#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("${base}/project/budgetEditSaveCostDetail", data, updateCostData);
+                },
+                onCancel: function(e) {
+                }
+            });
+        });
+        $("#costAddBtn").click(function () {
+            appendTrCost();
+        });
     });
 </script>
 </@defaultLayout.layout>